split off icom exe

pull/12/head
Tom Early 7 years ago
parent ed6acf6b22
commit b5fa2eca2e

1
.gitignore vendored

@ -6,6 +6,7 @@ qndvap
qndvrptr
qnlink
qngateway
qnigateway
qnremote
qnvoice
qnrelay

@ -37,12 +37,12 @@ SRCS = $(wildcard *.cpp) $(wildcard $(IRC)/*.cpp)
OBJS = $(SRCS:.cpp=.o)
DEPS = $(SRCS:.cpp=.d)
ALL_PROGRAMS=qngateway qnlink qnremote qnvoice qnrelay qndvap qndvrptr qnitap
ALL_PROGRAMS=qnigateway qngateway qnlink qnremote qnvoice qnrelay qndvap qndvrptr qnitap
MDV_PROGRAMS=qngateway qnlink qnremote qnvoice qnrelay
DVP_PROGRAMS=qngateway qnlink qnremote qnvoice qndvap
DVR_PROGRAMS=qngateway qnlink qnremote qnvoice qndvrptr
TAP_PROGRAMS=qngateway qnlink qnremote qnvoice qnitap
ICM_PROGRAMS=qngateway qnlink qnremote qnvoice
ICM_PROGRAMS=qnigateway qnlink qnremote qnvoice
all : $(ALL_PROGRAMS)
mmdvm : $(MDV_PROGRAMS)
@ -51,6 +51,9 @@ dvrptr : $(DVR_PROGRAMS)
icom : $(ICM_PROGRAMS)
itap : $(TAP_PROGRAMS)
qnigateway : $(IRCOBJS) QnetIcomGateway.o aprs.o
g++ $(CPPFLAGS) -o qnigateway QnetIcomGateway.o aprs.o $(IRCOBJS) $(LDFLAGS) -pthread
qngateway : $(IRCOBJS) QnetGateway.o aprs.o
g++ $(CPPFLAGS) -o qngateway QnetGateway.o aprs.o $(IRCOBJS) $(LDFLAGS) -pthread
@ -137,13 +140,13 @@ installitap : $(TAP_PROGRAMS) gwys.txt qn.cfg
installicom : $(ICM_PROGRAMS) gwys.txt qn.cfg
######### QnetGateway #########
/bin/cp -f qngateway $(BINDIR)
/bin/cp -f qnicomgateway $(BINDIR)
/bin/cp -f qnremote qnvoice $(BINDIR)
/bin/ln -s $(shell pwd)/qn.cfg $(CFGDIR)
/bin/cp -f system/qngateway.service $(SYSDIR)
systemctl enable qngateway.service
/bin/cp -f system/qnigateway.service $(SYSDIR)
systemctl enable qnigateway.service
systemctl daemon-reload
systemctl start qngateway.service
systemctl start qnigateway.service
######### QnetLink #########
/bin/cp -f qnlink $(BINDIR)
/bin/cp -f announce/*.dat $(CFGDIR)
@ -281,10 +284,10 @@ uninstallitap :
uninstallicom :
######### QnetGateway #########
systemctl stop qngateway.service
systemctl disable qngateway.service
/bin/rm -f $(SYSDIR)/qngateway.service
/bin/rm -f $(BINDIR)/qngateway
systemctl stop qnigateway.service
systemctl disable qnigateway.service
/bin/rm -f $(SYSDIR)/qnigateway.service
/bin/rm -f $(BINDIR)/qnigateway
/bin/rm -f $(BINDIR)/qnremote
/bin/rm -f $(BINDIR)/qnvoice
/bin/rm -f $(CFGDIR)/qn.cfg

@ -63,9 +63,6 @@ extern void dstar_dv_init();
extern int dstar_dv_decode(const unsigned char *d, int data[3]);
static std::atomic<bool> keep_running(true);
static std::atomic<unsigned short> G2_COUNTER_OUT(0);
static unsigned short OLD_REPLY_SEQ = 0;
static unsigned short NEW_REPLY_SEQ = 0;
/* signal catching function */
static void sigCatch(int signum)
@ -254,8 +251,7 @@ bool CQnetGateway::read_config(char *cfgFile)
if(! get_value(cfg, path+"password", irc_pass, 0, 512, "1111111111111111"))
return true;
// modules
is_icom = is_not_icom = false;
// module
for (short int m=0; m<3; m++) {
std::string path = "module.";
path += m + 'a';
@ -263,34 +259,26 @@ bool CQnetGateway::read_config(char *cfgFile)
std::string type;
if (cfg.lookupValue(std::string(path+".type").c_str(), type)) {
printf("%s = [%s]\n", std::string(path+"type").c_str(), type.c_str());
rptr.mod[m].defined = true;
if (0 == type.compare("icom")) {
rptr.mod[m].package_version = ICOM_VERSION;
is_icom = true;
} else if (0 == type.compare("dvap")) {
if (0 == type.compare("dvap")) {
rptr.mod[m].package_version = DVAP_VERSION;
is_not_icom = true;
rptr.mod[m].defined = true;
} else if (0 == type.compare("dvrptr")) {
rptr.mod[m].package_version = DVRPTR_VERSION;
is_not_icom = true;
rptr.mod[m].defined = true;
} else if (0 == type.compare("mmdvm")) {
rptr.mod[m].package_version = MMDVM_VERSION;
is_not_icom = true;
rptr.mod[m].defined = true;
} else if (0 == type.compare("itap")) {
rptr.mod[m].package_version = ITAP_VERSION;
is_not_icom = true;
rptr.mod[m].defined = true;
} else {
printf("module type '%s' is invalid\n", type.c_str());
return true;
}
if (is_icom && is_not_icom) {
printf("cannot define both icom and non-icom modules\n");
return true;
}
if (! get_value(cfg, std::string(path+"ip").c_str(), rptr.mod[m].portip.ip, 7, IP_SIZE, is_icom ? "172.16.0.1" : "127.0.0.1"))
if (! get_value(cfg, std::string(path+"ip").c_str(), rptr.mod[m].portip.ip, 7, IP_SIZE, "127.0.0.1"))
return true;
get_value(cfg, std::string(path+"port").c_str(), rptr.mod[m].portip.port, 16000, 65535, is_icom ? 20000 : 19998+m);
get_value(cfg, std::string(path+"port").c_str(), rptr.mod[m].portip.port, 16000, 65535, 19998+m);
get_value(cfg, std::string(path+"frequency").c_str(), rptr.mod[m].frequency, 0.0, 1.0e12, 0.0);
get_value(cfg, std::string(path+"offset").c_str(), rptr.mod[m].offset, -1.0e12, 1.0e12, 0.0);
get_value(cfg, std::string(path+"range").c_str(), rptr.mod[m].range, 0.0, 1609344.0, 0.0);
@ -315,31 +303,9 @@ bool CQnetGateway::read_config(char *cfgFile)
} else
rptr.mod[m].defined = false;
}
if (! is_icom && ! is_not_icom) {
if (! (rptr.mod[0].defined || rptr.mod[1].defined || rptr.mod[2].defined)) {
printf("No modules defined!\n");
return true;
} else if (is_icom) { // make sure all ICOM modules have the same IP and port number
std::string addr;
int port;
for (int i=0; i<3; i++) {
if (rptr.mod[i].defined) {
if (addr.size()) {
if (addr.compare(rptr.mod[i].portip.ip) || port!=rptr.mod[i].portip.port) {
printf("all defined ICOM modules must have the same IP and port number!\n");
return true;
}
} else {
addr = rptr.mod[i].portip.ip;
port = rptr.mod[i].portip.port;
}
}
}
for (int i=0; i<3; i++) {
if (! rptr.mod[i].defined) {
rptr.mod[i].portip.ip = addr;
rptr.mod[i].portip.port = port;
}
}
}
// gateway
@ -352,10 +318,10 @@ bool CQnetGateway::read_config(char *cfgFile)
get_value(cfg, path+"external.port", g2_external.port, 1024, 65535, 40000);
if (! get_value(cfg, path+"internal.ip", g2_internal.ip, 7, IP_SIZE, is_icom ? "172.16.0.20" : "0.0.0.0"))
if (! get_value(cfg, path+"internal.ip", g2_internal.ip, 7, IP_SIZE, "0.0.0.0"))
return true;
get_value(cfg, path+"internal.port", g2_internal.port, 16000, 65535, is_icom ? 20000 : 19000);
get_value(cfg, path+"internal.port", g2_internal.port, 16000, 65535, 19000);
get_value(cfg, path+"regen_header", bool_regen_header, true);
@ -755,7 +721,7 @@ void CQnetGateway::ProcessTimeouts()
// Send end_of_audio to local repeater.
// Let the repeater re-initialize
end_of_audio.counter = is_icom ? G2_COUNTER_OUT++ :toRptr[i].G2_COUNTER++;
end_of_audio.counter = toRptr[i].G2_COUNTER++;
if (i == 0)
end_of_audio.vpkt.snd_term_id = 0x03;
else if (i == 1)
@ -1165,35 +1131,6 @@ void CQnetGateway::Process()
ii->kickWatchdog(IRCDDB_VERSION);
if (is_icom) {
// send INIT to Icom Stack
unsigned char buf[500];
memset(buf, 0, 10);
memcpy(buf, "INIT", 4);
buf[6] = 0x73U;
// we can use the module a band_addr for INIT
sendto(srv_sock, buf, 10, 0, (struct sockaddr *)&toRptr[0].band_addr, sizeof(struct sockaddr_in));
printf("Waiting for ICOM controller...\n");
// get the acknowledgement from the ICOM Stack
while (keep_running) {
socklen_t fromlength = sizeof(struct sockaddr_in);
int recvlen = recvfrom(srv_sock, buf, 500, 0, (struct sockaddr *)&fromRptr, &fromlength);
if (10==recvlen && 0==memcmp(buf, "INIT", 4) && 0x72U==buf[6] && 0x0U==buf[7]) {
OLD_REPLY_SEQ = 256U * buf[4] + buf[5];
NEW_REPLY_SEQ = OLD_REPLY_SEQ + 1;
G2_COUNTER_OUT = NEW_REPLY_SEQ;
unsigned int ui = G2_COUNTER_OUT;
printf("SYNC: old=%u, new=%u out=%u\n", OLD_REPLY_SEQ, NEW_REPLY_SEQ, ui);
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
printf("Detected ICOM controller!\n");
} else
printf("Skipping ICOM initialization\n");
while (keep_running) {
ProcessTimeouts();
@ -1239,7 +1176,7 @@ void CQnetGateway::Process()
printf("id=%04x G2 start, ur=%.8s r1=%.8s r2=%.8s my=%.8s/%.4s IP=%s:%u\n", ntohs(g2buf.streamid), g2buf.hdr.urcall, g2buf.hdr.rpt1, g2buf.hdr.rpt2, g2buf.hdr.mycall, g2buf.hdr.sfx, inet_ntoa(fromDst4.sin_addr), ntohs(fromDst4.sin_port));
memcpy(rptrbuf.pkt_id, "DSTR", 4);
rptrbuf.counter = htons(is_icom ? G2_COUNTER_OUT++ : toRptr[i].G2_COUNTER++); // bump the counter
rptrbuf.counter = htons(toRptr[i].G2_COUNTER++); // bump the counter
rptrbuf.flag[0] = 0x73;
rptrbuf.flag[1] = 0x12;
rptrbuf.flag[2] = 0x00;
@ -1285,7 +1222,7 @@ void CQnetGateway::Process()
/* streamid match ? */
if (toRptr[i].streamid==g2buf.streamid && toRptr[i].adr==fromDst4.sin_addr.s_addr) {
memcpy(rptrbuf.pkt_id, "DSTR", 4);
rptrbuf.counter = htons(is_icom ? G2_COUNTER_OUT++ : toRptr[i].G2_COUNTER++);
rptrbuf.counter = htons(toRptr[i].G2_COUNTER++);
rptrbuf.flag[0] = 0x73;
rptrbuf.flag[1] = 0x12;
rptrbuf.flag[2] = 0x00;
@ -1329,15 +1266,15 @@ void CQnetGateway::Process()
if (toRptr[i].last_time==0 && band_txt[i].last_time==0) {
printf("Re-generating header for streamID=%04x\n", g2buf.streamid);
toRptr[i].saved_hdr[4] = (unsigned char)(((is_icom ? G2_COUNTER_OUT : toRptr[i].G2_COUNTER) >> 8) & 0xff);
toRptr[i].saved_hdr[5] = (unsigned char)((is_icom ? G2_COUNTER_OUT++ : toRptr[i].G2_COUNTER++) & 0xff);
toRptr[i].saved_hdr[4] = (unsigned char)((toRptr[i].G2_COUNTER >> 8) & 0xff);
toRptr[i].saved_hdr[5] = (unsigned char)((toRptr[i].G2_COUNTER++) & 0xff);
/* re-generate/send the header */
sendto(srv_sock, toRptr[i].saved_hdr, 58, 0, (struct sockaddr *)&toRptr[i].band_addr, sizeof(struct sockaddr_in));
/* send this audio packet to repeater */
memcpy(rptrbuf.pkt_id, "DSTR", 4);
rptrbuf.counter = htons(is_icom ? G2_COUNTER_OUT++ : toRptr[i].G2_COUNTER++);
rptrbuf.counter = htons(toRptr[i].G2_COUNTER++);
rptrbuf.flag[0] = 0x73;
rptrbuf.flag[1] = 0x12;
rptrbuf.flag[2] = 0x00;
@ -1384,30 +1321,7 @@ void CQnetGateway::Process()
int recvlen = recvfrom(srv_sock, rptrbuf.pkt_id, 58, 0, (struct sockaddr *)&fromRptr, &fromlen);
if (0 == memcmp(rptrbuf.pkt_id, "DSTR", 4)) {
/////////////////////////////////////////////////////////////////////
// some ICOM handshaking...
if (is_icom && 10==recvlen && 0x72==rptrbuf.flag[0]) { // ACK from rptr
NEW_REPLY_SEQ = ntohs(rptrbuf.counter);
if (NEW_REPLY_SEQ == OLD_REPLY_SEQ) {
G2_COUNTER_OUT = NEW_REPLY_SEQ;
OLD_REPLY_SEQ = NEW_REPLY_SEQ - 1;
} else
OLD_REPLY_SEQ = NEW_REPLY_SEQ;
} else if (is_icom && 0x73U==rptrbuf.flag[0] && (0x21U==rptrbuf.flag[1] || 0x11U==rptrbuf.flag[1] || 0x0U==rptrbuf.flag[1])) {
rptrbuf.flag[0] = 0x72U;
memset(rptrbuf.flag+1, 0x0U, 3);
sendto(srv_sock, rptrbuf.pkt_id, 10, 0, (struct sockaddr *)&toRptr[0].band_addr, sizeof(struct sockaddr_in));
// end of ICOM handshaking
/////////////////////////////////////////////////////////////////////
} else if ( (recvlen==58 || recvlen==29 || recvlen==32) && rptrbuf.flag[0]==0x73 && rptrbuf.flag[1]==0x12 && rptrbuf.flag[2]==0x0 && rptrbuf.vpkt.icm_id==0x20 && (rptrbuf.remaining==0x30 || rptrbuf.remaining==0x13 || rptrbuf.remaining==0x16) ) {
if (is_icom) { // acknowledge packet to ICOM
SDSTR reply;
memcpy(reply.pkt_id, "DSTR", 4);
reply.counter = rptrbuf.counter;
reply.flag[0] = 0x72U;
memset(reply.flag+1, 0, 3);
sendto(srv_sock, reply.pkt_id, 10, 0, (struct sockaddr *)&toRptr[0].band_addr, sizeof(struct sockaddr_in));
}
if ( (recvlen==58 || recvlen==29 || recvlen==32) && rptrbuf.flag[0]==0x73 && rptrbuf.flag[1]==0x12 && rptrbuf.flag[2]==0x0 && rptrbuf.vpkt.icm_id==0x20 && (rptrbuf.remaining==0x30 || rptrbuf.remaining==0x13 || rptrbuf.remaining==0x16) ) {
if (recvlen == 58) {
vPacketCount = 0U;
@ -1696,9 +1610,6 @@ void CQnetGateway::Process()
time(&toRptr[i].last_time);
/* bump the G2 counter */
if (is_icom)
G2_COUNTER_OUT++;
else
toRptr[i].G2_COUNTER++;
toRptr[i].sequence = rptrbuf.vpkt.ctrl;
@ -1870,9 +1781,6 @@ void CQnetGateway::Process()
time(&toRptr[i].last_time);
/* bump the G2 counter */
if (is_icom)
G2_COUNTER_OUT++;
else
toRptr[i].G2_COUNTER ++;
toRptr[i].sequence = rptrbuf.vpkt.ctrl;
@ -2109,9 +2017,6 @@ void CQnetGateway::Process()
time(&toRptr[i].last_time);
/* bump G2 counter */
if (is_icom)
G2_COUNTER_OUT++;
else
toRptr[i].G2_COUNTER ++;
toRptr[i].sequence = rptrbuf.vpkt.ctrl;
@ -2409,7 +2314,7 @@ void CQnetGateway::PlayFileThread(SECHO &edata)
// reformat the header and send it
memcpy(dstr.pkt_id, "DSTR", 4);
dstr.counter = htons(is_icom ? G2_COUNTER_OUT++ : toRptr[mod].G2_COUNTER++);
dstr.counter = htons(toRptr[mod].G2_COUNTER++);
dstr.flag[0] = 0x73;
dstr.flag[1] = 0x12;
dstr.flag[2] = 0x00;
@ -2436,7 +2341,7 @@ void CQnetGateway::PlayFileThread(SECHO &edata)
int nread = fread(dstr.vpkt.vasd.voice, 9, 1, fp);
if (nread == 1) {
dstr.counter = htons(is_icom ? G2_COUNTER_OUT++ : toRptr[mod].G2_COUNTER++);
dstr.counter = htons(toRptr[mod].G2_COUNTER++);
dstr.vpkt.ctrl = (unsigned char)(i % 21);
if (0x0U == dstr.vpkt.ctrl) {
memcpy(dstr.vpkt.vasd.text, sdsync, 3);

@ -96,7 +96,6 @@ private:
std::string OWNER, owner, local_irc_ip, status_file, dtmf_dir, dtmf_file, echotest_dir, irc_pass, qnvoicefile;
bool bool_send_qrgs, bool_irc_debug, bool_dtmf_debug, bool_regen_header, bool_qso_details, bool_send_aprs, playNotInCache;
bool is_icom, is_not_icom;
int play_wait, play_delay, echotest_rec_timeout, voicemail_rec_timeout, from_remote_g2_timeout, from_local_rptr_timeout, dtmf_digit;

File diff suppressed because it is too large Load Diff

@ -0,0 +1,12 @@
[Unit]
Description=QnetIcomGateway
Requires=network.target
After=systemd-user-session.service network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/qnigateway /usr/local/etc/qn.cfg
Restart=always
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save

Powered by TurnKey Linux.