better handling of icoming Icom data

pull/5/head
Tom Early 7 years ago
parent ee0e62a2ca
commit bbb0c2a5d1

@ -190,7 +190,7 @@ REPLY_TYPE CQnetITAP::GetITAPData(unsigned char *buf)
while (offset < length) { while (offset < length) {
ret = ::read(serfd, buf + offset, length - offset); ret = ::read(serfd, buf + offset, length - offset);
if (ret < 0) { if (ret < 0) {
printf("Error when reading buffer from the Icom radio %d: %s", errno, strerror(errno)); printf("Error when reading buffer from the Icom radio %d: %s\n", errno, strerror(errno));
return RT_ERROR; return RT_ERROR;
} }
@ -207,9 +207,6 @@ REPLY_TYPE CQnetITAP::GetITAPData(unsigned char *buf)
case 0x10U: case 0x10U:
return RT_HEADER; return RT_HEADER;
case 0x12U: case 0x12U:
if ((buf[3U] & 0x40U) == 0x40U)
return RT_EOT;
else
return RT_DATA; return RT_DATA;
case 0x21U: case 0x21U:
return RT_HEADER_ACK; return RT_HEADER_ACK;
@ -315,7 +312,7 @@ void CQnetITAP::Run(const char *cfgfile)
if (rt != RT_NOTHING) { if (rt != RT_NOTHING) {
//printf("read %d bytes from ITAP\n", (int)buf[0]); //printf("read %d bytes from ITAP\n", (int)buf[0]);
if (RT_DATA==rt || RT_HEADER==rt || RT_EOT==rt) { if (RT_DATA==rt || RT_HEADER==rt) {
if (ProcessITAP(buf)) if (ProcessITAP(buf))
break; break;
} else { } else {
@ -422,7 +419,6 @@ bool CQnetITAP::ProcessGateway(const int len, const unsigned char *raw)
else if (dstr.vpkt.ctrl > 20) else if (dstr.vpkt.ctrl > 20)
printf("DEBUG: ProcessGateway: unexpected voice sequence number %d\n", itap.voice.sequence); printf("DEBUG: ProcessGateway: unexpected voice sequence number %d\n", itap.voice.sequence);
memcpy(itap.voice.ambe, dstr.vpkt.vasd.voice, 12); memcpy(itap.voice.ambe, dstr.vpkt.vasd.voice, 12);
itap.voice.end = 0xFFU;
int ret = SendTo(itap.length, &itap.length); int ret = SendTo(itap.length, &itap.length);
if (ret != 17) { if (ret != 17) {
printf("ERROR: ProcessGateway: Could not write AMBE ITAP packet\n"); printf("ERROR: ProcessGateway: Could not write AMBE ITAP packet\n");
@ -439,11 +435,9 @@ bool CQnetITAP::ProcessITAP(const unsigned char *buf)
{ {
static short stream_id = 0U; static short stream_id = 0U;
SITAP itap; SITAP itap;
unsigned int len = buf[0]; unsigned int len = (0x10U == buf[1]) ? 41 : 16;
if (len < 42) ::memcpy(&itap.length, buf, len); // transfer raw data to SITAP struct
::memcpy(&itap.length, buf, len); // transfer raw data to SDSRP struct
if (41==len || 16==len) {
// create a stream id if this is a header // create a stream id if this is a header
if (41 == len) if (41 == len)
stream_id = random.NewStreamID(); stream_id = random.NewStreamID();
@ -464,7 +458,7 @@ bool CQnetITAP::ProcessITAP(const unsigned char *buf)
if (41 == len) { // header if (41 == len) { // header
dstr.remaining = 0x30; dstr.remaining = 0x30;
dstr.vpkt.ctrl = 0x80; dstr.vpkt.ctrl = 0x80;
//memcpy(dstr.vpkt.hdr.flag, dsrp.header.flag, 41);
memcpy(dstr.vpkt.hdr.flag, itap.header.flag, 3); memcpy(dstr.vpkt.hdr.flag, itap.header.flag, 3);
memcpy(dstr.vpkt.hdr.r1, itap.header.r1, 8); memcpy(dstr.vpkt.hdr.r1, itap.header.r1, 8);
memcpy(dstr.vpkt.hdr.r2, itap.header.r2, 8); memcpy(dstr.vpkt.hdr.r2, itap.header.r2, 8);
@ -485,18 +479,15 @@ bool CQnetITAP::ProcessITAP(const unsigned char *buf)
dstr.vpkt.ctrl = itap.voice.sequence; dstr.vpkt.ctrl = itap.voice.sequence;
memcpy(dstr.vpkt.vasd.voice, itap.voice.ambe, 12); memcpy(dstr.vpkt.vasd.voice, itap.voice.ambe, 12);
int ret = SendTo(vsock, dstr.pkt_id, 29, G2_INTERNAL_IP, G2_IN_PORT); int ret = SendTo(vsock, dstr.pkt_id, 29, G2_INTERNAL_IP, G2_IN_PORT);
if (log_qso && dstr.vpkt.ctrl&0x40)
printf("Sent dstr end of streamid=%04x\n", ntohs(dstr.vpkt.streamid));
if (ret != 29) { if (ret != 29) {
printf("ERROR: ProcessMMDVM: Could not write gateway voice packet\n"); printf("ERROR: ProcessMMDVM: Could not write gateway voice packet\n");
return true; return true;
} }
if (log_qso && (dstr.vpkt.ctrl & 0x40))
printf("Sent dstr end of streamid=%04x\n", ntohs(dstr.vpkt.streamid));
} }
// } else if (len < 65 && dsrp.tag == 0xAU) {
// printf("MMDVM Poll: '%s'\n", (char *)mpkt.poll_msg);
} else
printf("DEBUG: ProcessMMDVM: unusual packet len=%d\n", (int)buf[0]);
return false; return false;
} }

@ -36,7 +36,6 @@ enum REPLY_TYPE {
RT_UNKNOWN, RT_UNKNOWN,
RT_HEADER, RT_HEADER,
RT_DATA, RT_DATA,
RT_EOT,
RT_HEADER_ACK, RT_HEADER_ACK,
RT_DATA_ACK, RT_DATA_ACK,
RT_PONG, RT_PONG,
@ -65,14 +64,12 @@ typedef struct itap_tag {
unsigned char ur[8]; unsigned char ur[8];
unsigned char my[8]; unsigned char my[8];
unsigned char nm[4]; unsigned char nm[4];
unsigned char end; // 0xFFU for writing
} header; } header;
struct { struct {
unsigned char counter; // ordinal counter is reset with each header unsigned char counter; // ordinal counter is reset with each header
unsigned char sequence; // is modulo 21 unsigned char sequence; // is modulo 21
unsigned char ambe[9]; unsigned char ambe[9];
unsigned char text[3]; unsigned char text[3];
unsigned char end; // 0xFFU for writing
} voice; } voice;
}; };
} SITAP; } SITAP;

Loading…
Cancel
Save

Powered by TurnKey Linux.