finally finished rough mmdvm_modem

pull/1/head
Tom Early 9 years ago
parent 7f87579c6a
commit f8b801fc5a

@ -930,13 +930,12 @@ static void ReadDVAPThread()
/* send the S packet if needed */ /* send the S packet if needed */
if ((tnow - S_ctrl_msg_time) > 60) { if ((tnow - S_ctrl_msg_time) > 60) {
spack.counter = C_COUNTER; spack.counter = C_COUNTER++;
memcpy(spack.spkt.mycall, OWNER, 7); memcpy(spack.spkt.mycall, OWNER, 7);
spack.spkt.mycall[7] = 'S'; spack.spkt.mycall[7] = 'S';
memcpy(spack.spkt.rpt, OWNER, 7); memcpy(spack.spkt.rpt, OWNER, 7);
spack.spkt.rpt[7] = 'S'; spack.spkt.rpt[7] = 'S';
sendto(insock, spack.pkt_id, 26, 0, (struct sockaddr *)&outaddr, sizeof(outaddr)); sendto(insock, spack.pkt_id, 26, 0, (struct sockaddr *)&outaddr, sizeof(outaddr));
C_COUNTER++;
S_ctrl_msg_time = tnow; S_ctrl_msg_time = tnow;
} }
@ -1086,12 +1085,11 @@ static void ReadDVAPThread()
net_buf.vpkt.hdr.flag[1] = net_buf.vpkt.hdr.flag[2] = 0x00; net_buf.vpkt.hdr.flag[1] = net_buf.vpkt.hdr.flag[2] = 0x00;
/* for icom g2 */ /* for icom g2 */
spack.counter = C_COUNTER; spack.counter = C_COUNTER++;
memcpy(spack.spkt.mycall, net_buf.vpkt.hdr.mycall, 8); memcpy(spack.spkt.mycall, net_buf.vpkt.hdr.mycall, 8);
memcpy(spack.spkt.rpt, OWNER, 7); memcpy(spack.spkt.rpt, OWNER, 7);
spack.spkt.rpt[7] = RPTR_MOD; spack.spkt.rpt[7] = RPTR_MOD;
sendto(insock, spack.pkt_id, 26, 0, (struct sockaddr *)&outaddr, sizeof(outaddr)); sendto(insock, spack.pkt_id, 26, 0, (struct sockaddr *)&outaddr, sizeof(outaddr));
C_COUNTER++;
// Before we send the data to the local gateway, // Before we send the data to the local gateway,
// set RPT1, RPT2 to be the local gateway // set RPT1, RPT2 to be the local gateway
@ -1100,7 +1098,7 @@ static void ReadDVAPThread()
memcpy(net_buf.vpkt.hdr.rpt1, OWNER, 7); memcpy(net_buf.vpkt.hdr.rpt1, OWNER, 7);
memcpy(net_buf.pkt_id, "DSTR", 4); memcpy(net_buf.pkt_id, "DSTR", 4);
net_buf.counter = C_COUNTER; net_buf.counter = C_COUNTER++;
net_buf.flag[0] = 0x73; net_buf.flag[0] = 0x73;
net_buf.flag[1] = 0x12; net_buf.flag[1] = 0x12;
net_buf.flag[2] = 0x00; net_buf.flag[2] = 0x00;
@ -1115,7 +1113,6 @@ static void ReadDVAPThread()
sequence = 0; sequence = 0;
calcPFCS((unsigned char *)&(net_buf.vpkt.hdr), net_buf.vpkt.hdr.pfcs); calcPFCS((unsigned char *)&(net_buf.vpkt.hdr), net_buf.vpkt.hdr.pfcs);
sendto(insock, &net_buf, 58, 0, (struct sockaddr *)&outaddr, sizeof(outaddr)); sendto(insock, &net_buf, 58, 0, (struct sockaddr *)&outaddr, sizeof(outaddr));
C_COUNTER ++;
// local RF user keying up, start timer // local RF user keying up, start timer
dvap_busy = true; dvap_busy = true;
@ -1130,7 +1127,7 @@ static void ReadDVAPThread()
if (dvap_busy) { if (dvap_busy) {
the_end = ((dr.frame.framepos & 0x40) == 0x40); the_end = ((dr.frame.framepos & 0x40) == 0x40);
net_buf.counter = C_COUNTER; net_buf.counter = C_COUNTER++;
net_buf.remaining = 0x13; net_buf.remaining = 0x13;
net_buf.vpkt.ctrl = sequence++; net_buf.vpkt.ctrl = sequence++;
if (the_end) if (the_end)
@ -1145,7 +1142,6 @@ static void ReadDVAPThread()
num_dv_frames++; num_dv_frames++;
} }
C_COUNTER++;
if (sequence > 0x14) if (sequence > 0x14)
sequence = 0; sequence = 0;

@ -22,6 +22,7 @@
#include <cstring> #include <cstring>
#include <csignal> #include <csignal>
#include <ctime> #include <ctime>
#include <cstdlib>
#include "versions.h" #include "versions.h"
#include "mmdvm_modem.h" #include "mmdvm_modem.h"
@ -30,7 +31,9 @@
std::atomic<bool> CMMDVMModem::keep_running(true); std::atomic<bool> CMMDVMModem::keep_running(true);
CMMDVMModem::CMMDVMModem() CMMDVMModem::CMMDVMModem() :
seed(time(NULL)),
COUNTER(0)
{ {
} }
@ -149,6 +152,7 @@ void CMMDVMModem::ProcessGateway(CUDPSocket &gsock, CUDPSocket &msock)
void CMMDVMModem::ProcessMMDVM(CUDPSocket &gsock, CUDPSocket &msock) void CMMDVMModem::ProcessMMDVM(CUDPSocket &gsock, CUDPSocket &msock)
{ {
SMMDVMPKT mpkt; SMMDVMPKT mpkt;
static SPKT gpkt; // retain some header values for voice data
unsigned int mmdvm_port = MMDVM_PORT; unsigned int mmdvm_port = MMDVM_PORT;
in_addr addr; in_addr addr;
addr.s_addr = mmdvm_addr.s_addr; addr.s_addr = mmdvm_addr.s_addr;
@ -166,23 +170,33 @@ void CMMDVMModem::ProcessMMDVM(CUDPSocket &gsock, CUDPSocket &msock)
} }
// if there is data, translate it and send it to the Gateway // if there is data, translate it and send it to the Gateway
if (21==len || 49==len) { if (49 == len) {
unsigned int g2_internal_port = G2_INTERNAL_PORT; // sets most of the params with the header
SPKT gpkt;
memcpy(gpkt.pkt_id, "DSTR", 4); memcpy(gpkt.pkt_id, "DSTR", 4);
gpkt.counter = 0; gpkt.counter = COUNTER++;
gpkt.flag[0] = 0x72; gpkt.flag[0] = 0x72;
gpkt.flag[1] = 0x12; gpkt.flag[1] = 0x12;
gpkt.flag[2] = 0x0; gpkt.flag[2] = 0x0;
gpkt.remaining = (21 == len) ? 0x16 : 0x30; gpkt.remaining = 0x30;
gpkt.vpkt.icm_id = 0x20; gpkt.vpkt.icm_id = 0x20;
gpkt.vpkt.dst_rptr_id = 0x0; gpkt.vpkt.dst_rptr_id = 0x0;
gpkt.vpkt.snd_rptr_id = 0x1; gpkt.vpkt.snd_rptr_id = 0x1;
gpkt.vpkt.snd_term_id = ('B'==RPTR_MOD) ? 0x1 : (('C'==RPTR_MOD) ? 0x2 : 0x3); gpkt.vpkt.snd_term_id = ('B'==RPTR_MOD) ? 0x1 : (('C'==RPTR_MOD) ? 0x2 : 0x3);
gpkt.vpkt.streamid = (rand_r(&seed) % 65535U) + 1U;
if (false == gsock.write(gpkt.pkt_id, (21==len) ? 29 : 58, g2_internal_addr, g2_internal_port)) { gpkt.vpkt.ctrl = mpkt.header.seq;
printf("ERROR: ProcessMMDVM: Could not write gateway packet\n"); memcpy(gpkt.vpkt.hdr.flag, mpkt.header.flag, 41);
if (false == gsock.write(gpkt.pkt_id, 58, g2_internal_addr, (unsigned int)G2_INTERNAL_PORT)) {
printf("ERROR: ProcessMMDVM: Could not write gateway header packet\n");
keep_running = false;
}
} else if (21 == len) {
// just a few need updating in a voice data frame
gpkt.counter = COUNTER++;
gpkt.remaining = 0x16;
gpkt.vpkt.ctrl = mpkt.voice.seq;
memcpy(gpkt.vpkt.vasd.text, mpkt.voice.ambe, 12);
if (false == gsock.write(gpkt.pkt_id, 29, g2_internal_addr, (unsigned int)G2_INTERNAL_PORT)) {
printf("ERROR: ProcessMMDVM: Could not write gateway header packet\n");
keep_running = false; keep_running = false;
} }
} else } else

@ -68,4 +68,6 @@ private:
// parameters // parameters
int gateway_sock, mmdvm_sock; int gateway_sock, mmdvm_sock;
unsigned int seed;
unsigned short COUNTER;
}; };

Loading…
Cancel
Save

Powered by TurnKey Linux.