diff --git a/QnetGateway.cpp b/QnetGateway.cpp index b3764f6..51fa356 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -107,7 +107,7 @@ void CQnetGateway::PrintCallsigns(const std::string &key, const std::setreceiveUser(user, rptr, gateway, ipaddr); if (!user.empty()) { if (!rptr.empty() && !gateway.empty() && !ipaddr.empty()) { - if (bool_irc_debug) + if (LOG_IRC) printf("C-u:%s,%s,%s,%s\n", user.c_str(), rptr.c_str(), gateway.c_str(), ipaddr.c_str()); pthread_mutex_lock(&irc_data_mutex); @@ -482,7 +483,7 @@ void CQnetGateway::GetIRCDataThread() ii->receiveRepeater(rptr, gateway, ipaddr, proto); if (!rptr.empty()) { if (!gateway.empty() && !ipaddr.empty()) { - if (bool_irc_debug) + if (LOG_IRC) printf("C-r:%s,%s,%s\n", rptr.c_str(), gateway.c_str(), ipaddr.c_str()); pthread_mutex_lock(&irc_data_mutex); @@ -499,7 +500,7 @@ void CQnetGateway::GetIRCDataThread() } else if (type == IDRT_GATEWAY) { ii->receiveGateway(gateway, ipaddr, proto); if (!gateway.empty() && !ipaddr.empty()) { - if (bool_irc_debug) + if (LOG_IRC) printf("C-g:%s,%s\n", gateway.c_str(),ipaddr.c_str()); pthread_mutex_lock(&irc_data_mutex); @@ -631,7 +632,7 @@ void CQnetGateway::ProcessTimeouts() /* echotest recording timed out? */ if (recd[i].last_time != 0) { time(&t_now); - if ((t_now - recd[i].last_time) > echotest_rec_timeout) { + if ((t_now - recd[i].last_time) > TIMING_TIMEOUT_ECHO) { printf("Inactivity on echotest recording module %c, removing stream id=%04x\n", 'A'+i, ntohs(recd[i].streamid)); recd[i].streamid = 0; @@ -656,7 +657,7 @@ void CQnetGateway::ProcessTimeouts() /* voicemail recording timed out? */ if (vm[i].last_time != 0) { time(&t_now); - if ((t_now - vm[i].last_time) > voicemail_rec_timeout) { + if ((t_now - vm[i].last_time) > TIMING_TIMEOUT_VOICEMAIL) { printf("Inactivity on voicemail recording module %c, removing stream id=%04x\n", 'A'+i, ntohs(vm[i].streamid)); vm[i].streamid = 0; @@ -673,7 +674,7 @@ void CQnetGateway::ProcessTimeouts() // The stream can be from a cross-band, or from a remote system, // so we could use either FROM_LOCAL_RPTR_TIMEOUT or FROM_REMOTE_G2_TIMEOUT // but FROM_REMOTE_G2_TIMEOUT makes more sense, probably is a bigger number - if ((t_now - toRptr[i].last_time) > from_remote_g2_timeout) { + if ((t_now - toRptr[i].last_time) > TIMING_TIMEOUT_REMOTE_G2) { printf("Inactivity to local rptr module %c, removing stream id %04x\n", 'A'+i, ntohs(toRptr[i].streamid)); // Send end_of_audio to local repeater. @@ -701,7 +702,7 @@ void CQnetGateway::ProcessTimeouts() /* any stream coming from local repeater timed out ? */ if (band_txt[i].last_time != 0) { time(&t_now); - if ((t_now - band_txt[i].last_time) > from_local_rptr_timeout) { + if ((t_now - band_txt[i].last_time) > TIMING_TIMEOUT_LOCAL_RPTR) { /* This local stream never went to a remote system, so trace the timeout */ if (to_remote_g2[i].toDst4.sin_addr.s_addr == 0) printf("Inactivity from local rptr module %c, removing stream id %04x\n", 'A'+i, ntohs(band_txt[i].streamID)); @@ -730,7 +731,7 @@ void CQnetGateway::ProcessTimeouts() /* any stream from local repeater to a remote gateway timed out ? */ if (to_remote_g2[i].toDst4.sin_addr.s_addr != 0) { time(&t_now); - if ((t_now - to_remote_g2[i].last_time) > from_local_rptr_timeout) { + if ((t_now - to_remote_g2[i].last_time) > TIMING_TIMEOUT_LOCAL_RPTR) { printf("Inactivity from local rptr mod %d, removing stream id %04x\n", i, to_remote_g2[i].streamid); memset(&(to_remote_g2[i].toDst4),0,sizeof(struct sockaddr_in)); @@ -807,7 +808,7 @@ void CQnetGateway::ProcessSlowData(unsigned char *data, unsigned short sid) } else if (band_txt[i].temp_line[0] != '$') { memcpy(band_txt[i].gpid, band_txt[i].temp_line, band_txt[i].temp_line_cnt); band_txt[i].gpid[band_txt[i].temp_line_cnt] = '\0'; - if (bool_send_aprs && !band_txt[i].is_gps_sent) + if (APRS_ENABLE && !band_txt[i].is_gps_sent) gps_send(i); } band_txt[i].temp_line[0] = '\0'; @@ -838,7 +839,7 @@ void CQnetGateway::ProcessSlowData(unsigned char *data, unsigned short sid) } else if (band_txt[i].temp_line[0] != '$') { memcpy(band_txt[i].gpid, band_txt[i].temp_line, band_txt[i].temp_line_cnt); band_txt[i].gpid[band_txt[i].temp_line_cnt] = '\0'; - if (bool_send_aprs && !band_txt[i].is_gps_sent) + if (APRS_ENABLE && !band_txt[i].is_gps_sent) gps_send(i); } band_txt[i].temp_line[0] = '\0'; @@ -962,7 +963,7 @@ void CQnetGateway::ProcessSlowData(unsigned char *data, unsigned short sid) } else if (band_txt[i].temp_line[0] != '$') { memcpy(band_txt[i].gpid, band_txt[i].temp_line, band_txt[i].temp_line_cnt); band_txt[i].gpid[band_txt[i].temp_line_cnt] = '\0'; - if (bool_send_aprs && !band_txt[i].is_gps_sent) + if (APRS_ENABLE && !band_txt[i].is_gps_sent) gps_send(i); } band_txt[i].temp_line[0] = '\0'; @@ -998,7 +999,7 @@ void CQnetGateway::ProcessSlowData(unsigned char *data, unsigned short sid) } else if (band_txt[i].temp_line[0] != '$') { memcpy(band_txt[i].gpid, band_txt[i].temp_line, band_txt[i].temp_line_cnt); band_txt[i].gpid[band_txt[i].temp_line_cnt] = '\0'; - if (bool_send_aprs && !band_txt[i].is_gps_sent) + if (APRS_ENABLE && !band_txt[i].is_gps_sent) gps_send(i); } band_txt[i].temp_line[0] = '\0'; @@ -1028,7 +1029,7 @@ void CQnetGateway::ProcessSlowData(unsigned char *data, unsigned short sid) } else if (band_txt[i].temp_line[0] != '$') { memcpy(band_txt[i].gpid, band_txt[i].temp_line, band_txt[i].temp_line_cnt); band_txt[i].gpid[band_txt[i].temp_line_cnt] = '\0'; - if (bool_send_aprs && !band_txt[i].is_gps_sent) + if (APRS_ENABLE && !band_txt[i].is_gps_sent) gps_send(i); } band_txt[i].temp_line[0] = '\0'; @@ -1062,7 +1063,7 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const b // toRptr[i] is active if a remote system is talking to it or // toRptr[i] is receiving data from a cross-band if (0==toRptr[i].last_time && 0==band_txt[i].last_time && (Flag_is_ok(g2buf.hdr.flag[0]) || 0x01U==g2buf.hdr.flag[0] || 0x40U==g2buf.hdr.flag[0])) { - if (bool_qso_details) { + if (LOG_QSO) { printf("id=%04x flags=%02x:%02x:%02x ur=%.8s r1=%.8s r2=%.8s my=%.8s/%.4s ", ntohs(g2buf.streamid), g2buf.hdr.flag[0], g2buf.hdr.flag[1], g2buf.hdr.flag[2], g2buf.hdr.urcall, g2buf.hdr.rpt1, g2buf.hdr.rpt2, g2buf.hdr.mycall, g2buf.hdr.sfx); if (is_from_g2) printf("IP=%s:%u\n", inet_ntoa(fromDst4.sin_addr), ntohs(fromDst4.sin_port)); @@ -1143,7 +1144,7 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const b toRptr[i].last_time = 0; toRptr[i].streamid = 0; toRptr[i].adr = 0; - if (bool_qso_details) + if (LOG_QSO) printf("id=%04x END\n", ntohs(g2buf.streamid)); } break; // we're done @@ -1152,7 +1153,7 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const b } /* no match ? */ - if ((i == 3) && bool_regen_header) { + if ((i == 3) && GATEWAY_HEADER_REGEN) { /* check if this a continuation of audio that timed out */ if (g2buf.ctrl & 0x40) @@ -1227,7 +1228,7 @@ void CQnetGateway::ProcessModem() if (recvlen == 58) { vPacketCount = 0U; - if (bool_qso_details) + if (LOG_QSO) printf("id=%04x cntr=%04x start RPTR flag=%02x:%02x:%02x ur=%.8s r1=%.8s r2=%.8s my=%.8s/%.4s\n", ntohs(dstr.vpkt.streamid), ntohs(dstr.counter), dstr.vpkt.hdr.flag[0], dstr.vpkt.hdr.flag[1], dstr.vpkt.hdr.flag[2], dstr.vpkt.hdr.ur, dstr.vpkt.hdr.r1, dstr.vpkt.hdr.r2, dstr.vpkt.hdr.my, dstr.vpkt.hdr.nm); if (0==memcmp(dstr.vpkt.hdr.r1, OWNER.c_str(), 7) && Flag_is_ok(dstr.vpkt.hdr.flag[0])) { @@ -1235,7 +1236,7 @@ void CQnetGateway::ProcessModem() int i = dstr.vpkt.hdr.r1[7] - 'A'; if (i>=0 && i<3) { - if (bool_dtmf_debug) + if (LOG_DTMF) printf("resetting dtmf[%d] (got a header)\n", i); dtmf_last_frame[i] = 0; dtmf_counter[i] = 0; @@ -1288,7 +1289,7 @@ void CQnetGateway::ProcessModem() band_txt[i].num_bit_errors = 0; /* select the band for aprs processing, and lock on the stream ID */ - if (bool_send_aprs) + if (APRS_ENABLE) aprs->SelectBand(i, ntohs(dstr.vpkt.streamid)); } } @@ -1566,7 +1567,7 @@ void CQnetGateway::ProcessModem() printf("Already recording for voicemail on mod %d\n", i); else { memset(tempfile, '\0', sizeof(tempfile)); - snprintf(tempfile, FILENAME_MAX, "%s/%c_%s", echotest_dir.c_str(), dstr.vpkt.hdr. r1[7], "voicemail.dat"); + snprintf(tempfile, FILENAME_MAX, "%s/%c_%s", FILE_ECHOTEST.c_str(), dstr.vpkt.hdr. r1[7], "voicemail.dat"); vm[i].fd = open(tempfile, O_CREAT | O_WRONLY | O_TRUNC | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (vm[i].fd < 0) @@ -1609,7 +1610,7 @@ void CQnetGateway::ProcessModem() printf("Already recording for echotest on mod %d\n", i); else { memset(tempfile, '\0', sizeof(tempfile)); - snprintf(tempfile, FILENAME_MAX, "%s/%c_%s", echotest_dir.c_str(), dstr.vpkt.hdr.r1[7], "echotest.dat"); + snprintf(tempfile, FILENAME_MAX, "%s/%c_%s", FILE_ECHOTEST.c_str(), dstr.vpkt.hdr.r1[7], "echotest.dat"); recd[i].fd = open(tempfile, O_CREAT | O_WRONLY | O_EXCL | O_TRUNC | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (recd[i].fd < 0) @@ -1696,11 +1697,11 @@ void CQnetGateway::ProcessModem() if (dstr.vpkt.ctrl & 0x40) { // end of voice data if (dtmf_buf_count[i] > 0) { - dtmf_file = dtmf_dir; + std::string dtmf_file(FILE_DTMF); dtmf_file.push_back('/'); dtmf_file.push_back('A'+i); dtmf_file += "_mod_DTMF_NOTIFY"; - if (bool_dtmf_debug) + if (LOG_DTMF) printf("Saving dtmfs=[%s] into file: [%s]\n", dtmf_buf[i], dtmf_file.c_str()); FILE *dtmf_fp = fopen(dtmf_file.c_str(), "w"); if (dtmf_fp) { @@ -1710,7 +1711,7 @@ void CQnetGateway::ProcessModem() printf("Failed to create dtmf file %s\n", dtmf_file.c_str()); - if (bool_dtmf_debug) + if (LOG_DTMF) printf("resetting dtmf[%d] (printed dtmf code %s from %s)\n", i, dtmf_buf[i], band_txt[i].lh_mycall); memset(dtmf_buf[i], 0, sizeof(dtmf_buf[i])); dtmf_buf_count[i] = 0; @@ -1733,7 +1734,7 @@ void CQnetGateway::ProcessModem() if (playNotInCache) { // Not in cache, please try again! - FILE *fp = fopen(qnvoicefile.c_str(), "w"); + FILE *fp = fopen(FILE_QNVOICE_FILE.c_str(), "w"); if (fp) { fprintf(fp, "%c_notincache.dat_NOT_IN_CACHE\n", band_txt[i].lh_rpt1[7]); fclose(fp); @@ -1806,7 +1807,7 @@ void CQnetGateway::ProcessModem() Gate2Link.Write(dstr.pkt_id, recvlen); /* aprs processing */ - if (bool_send_aprs) + if (APRS_ENABLE) // streamID seq audio+text aprs->ProcessText(ntohs(dstr.vpkt.streamid), dstr.vpkt.ctrl, dstr.vpkt.vasd.voice); @@ -1903,7 +1904,7 @@ void CQnetGateway::ProcessModem() } } - if (bool_qso_details && dstr.vpkt.ctrl&0x40U) + if (LOG_QSO && dstr.vpkt.ctrl&0x40U) printf("id=%04x cntr=%04x END RPTR\n", ntohs(dstr.vpkt.streamid), ntohs(dstr.counter)); } } @@ -1931,7 +1932,7 @@ void CQnetGateway::Process() dstar_dv_init(); std::future aprs_future, irc_data_future; - if (bool_send_aprs) { // start the beacon thread + if (APRS_ENABLE) { // start the beacon thread try { aprs_future = std::async(std::launch::async, &CQnetGateway::APRSBeaconThread, this); } catch (const std::exception &e) { @@ -2003,7 +2004,7 @@ void CQnetGateway::Process() } // thread clean-up - if (bool_send_aprs) { + if (APRS_ENABLE) { if (aprs_future.valid()) aprs_future.get(); } @@ -2272,7 +2273,7 @@ void CQnetGateway::PlayFileThread(SECHO &edata) return; } - sleep(play_wait); + sleep(TIMING_PLAY_WAIT); // reformat the header and send it memcpy(dstr.pkt_id, "DSTR", 4); @@ -2359,7 +2360,7 @@ void CQnetGateway::PlayFileThread(SECHO &edata) Gate2Modem[mod].Write(dstr.pkt_id, 29); - std::this_thread::sleep_for(std::chrono::milliseconds(play_delay)); + std::this_thread::sleep_for(std::chrono::milliseconds(TIMING_PLAY_DELAY)); } } fclose(fp); @@ -2422,7 +2423,7 @@ bool CQnetGateway::Init(char *cfgfile) memset(&band_txt[0], 0, sizeof(SBANDTXT)); /* process configuration file */ - if ( read_config(cfgfile) ) { + if ( ReadConfig(cfgfile) ) { printf("Failed to process config file %s\n", cfgfile); return true; } @@ -2477,18 +2478,18 @@ bool CQnetGateway::Init(char *cfgfile) } - if (bool_send_aprs) { + if (APRS_ENABLE) { aprs = new CAPRS(&rptr); if (aprs) aprs->Init(); else { printf("aprs class init failed!\nAPRS will be turned off"); - bool_send_aprs = false; + APRS_ENABLE = false; } } compute_aprs_hash(); - ii = new CIRCDDB(ircddb.ip, ircddb.port, owner, irc_pass, IRCDDB_VERSION, local_irc_ip); + ii = new CIRCDDB(ircddb.ip, ircddb.port, owner, IRCDDB_PASSWORD, IRCDDB_VERSION, GATEWAY_LOCAL_IRC_IP); bool ok = ii->open(); if (!ok) { printf("irc open failed\n"); @@ -2546,7 +2547,7 @@ bool CQnetGateway::Init(char *cfgfile) vm[i].fd = -1; memset(vm[i].file, 0, sizeof(vm[i].file)); - snprintf(vm[i].file, FILENAME_MAX, "%s/%c_%s", echotest_dir.c_str(), 'A'+i, "voicemail.dat"); + snprintf(vm[i].file, FILENAME_MAX, "%s/%c_%s", FILE_ECHOTEST.c_str(), 'A'+i, "voicemail.dat"); if (access(vm[i].file, F_OK) != 0) memset(vm[i].file, 0, sizeof(vm[i].file)); @@ -2598,7 +2599,7 @@ bool CQnetGateway::Init(char *cfgfile) printf("QnetGateway...entering processing loop\n"); - if (bool_send_qrgs) + if (GATEWAY_SEND_QRGS_MAP) qrgs_and_maps(); return false; } @@ -2617,7 +2618,7 @@ CQnetGateway::~CQnetGateway() printf("Closed G2_EXTERNAL_PORT\n"); } - if (bool_send_aprs) { + if (APRS_ENABLE) { if (aprs->GetSock() != -1) { close(aprs->GetSock()); printf("Closed APRS\n"); diff --git a/QnetGateway.h b/QnetGateway.h index 3104019..501ec45 100644 --- a/QnetGateway.h +++ b/QnetGateway.h @@ -98,11 +98,12 @@ private: std::string gate2link, link2gate, gate2modem[3], modem2gate; - std::string OWNER, owner, local_irc_ip, status_file, dtmf_dir, dtmf_file, echotest_dir, irc_pass, qnvoicefile; + std::string OWNER, owner, GATEWAY_LOCAL_IRC_IP, FILE_STATUS, FILE_DTMF, FILE_ECHOTEST, IRCDDB_PASSWORD, FILE_QNVOICE_FILE; - bool bool_send_qrgs, bool_irc_debug, bool_dtmf_debug, bool_regen_header, bool_qso_details, bool_send_aprs, playNotInCache; + bool GATEWAY_SEND_QRGS_MAP, GATEWAY_HEADER_REGEN, APRS_ENABLE, playNotInCache; + bool LOG_DEBUG, LOG_IRC, LOG_DTMF, LOG_QSO; - int play_wait, play_delay, echotest_rec_timeout, voicemail_rec_timeout, from_remote_g2_timeout, from_local_rptr_timeout, dtmf_digit; + int TIMING_PLAY_WAIT, TIMING_PLAY_DELAY, TIMING_TIMEOUT_ECHO, TIMING_TIMEOUT_VOICEMAIL, TIMING_TIMEOUT_REMOTE_G2, TIMING_TIMEOUT_LOCAL_RPTR, dtmf_digit; unsigned int vPacketCount; @@ -176,7 +177,7 @@ private: void PrintCallsigns(const std::string &key, const std::set &set); // read configuration file - bool read_config(char *); + bool ReadConfig(char *); /* aprs functions, borrowed from my retired IRLP node 4201 */ void gps_send(short int rptr_idx);