From 4e6c36ff6294d0c864cd7a6c8dfca6f19183dec7 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Mon, 30 Mar 2020 18:32:12 -0700 Subject: [PATCH] better dashboard --- QnetDB.cpp | 15 +++++++++------ QnetDB.h | 2 +- QnetGateway.cpp | 31 +++++++++++++++++++------------ QnetGateway.h | 2 +- index.php | 7 +++---- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/QnetDB.cpp b/QnetDB.cpp index 149cc70..af7a72f 100644 --- a/QnetDB.cpp +++ b/QnetDB.cpp @@ -40,9 +40,10 @@ bool CQnetDB::Init() } sql.assign("CREATE TABLE LHEARD(" - "mycall TEXT PRIMARY KEY, " + "callsign TEXT PRIMARY KEY, " "sfx TEXT, " - "urcall TEXT, " + "module TEXT, " + "reflector TEXT, " "lasttime INT NOT NULL" ") WITHOUT ROWID;"); @@ -77,16 +78,18 @@ bool CQnetDB::Init() return false; } -bool CQnetDB::UpdateLH(const char *mycall, const char *sfx, const char *urcall) +bool CQnetDB::UpdateLH(const char *callsign, const char *sfx, const char module, const char *reflector) { if (NULL == db) return false; - std::string sql("REPLACE INTO LHEARD (mycall,sfx,urcall,lasttime) VALUES ('"); - sql.append(mycall); + std::string sql("REPLACE INTO LHEARD (callsign,sfx,module,reflector,lasttime) VALUES ('"); + sql.append(callsign); sql.append("','"); sql.append(sfx); sql.append("','"); - sql.append(urcall); + sql.append(1, module); + sql.append("','"); + sql.append(reflector); sql.append("',"); sql.append("strftime('%s','now'));"); diff --git a/QnetDB.h b/QnetDB.h index 3e4f6a4..4e3ffd5 100644 --- a/QnetDB.h +++ b/QnetDB.h @@ -53,7 +53,7 @@ public: ~CQnetDB() { if (db) sqlite3_close(db); } bool Open(const char *name); bool Init(); - bool UpdateLH(const char *mycall, const char *sfx, const char *urcall); + bool UpdateLH(const char *callsign, const char *sfx, const char module, const char *reflector); bool UpdateLS(const char *address, const char from_mod, const char *to_callsign, const char to_mod, time_t connect_time); bool DeleteLS(const char *address); bool FindLS(const char mod, std::list &linklist); diff --git a/QnetGateway.cpp b/QnetGateway.cpp index 2952b4f..8567439 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -635,7 +635,7 @@ void CQnetGateway::ProcessTimeouts() } } -void CQnetGateway::ProcessG2Msg(const unsigned char *data, const int mod) +bool CQnetGateway::ProcessG2Msg(const unsigned char *data, const int mod, std::string &smrtgrp) { static unsigned int part[3] = { 0 }; static char txt[3][21]; @@ -652,8 +652,10 @@ void CQnetGateway::ProcessG2Msg(const unsigned char *data, const int mod) memcpy(txt[mod]+(5u*(part[mod]/2u)+2u), c, 3); if (++part[mod] > 7) { // we've got everything! - printf("Msg = '%s'\n", txt[mod]); + if (0 == strncmp(txt[mod], "VIA SMARTGP ", 12)) + smrtgrp.assign(txt[mod]+12); part[mod] = 0; // now we can start over + return true; } } else { // we'll get here when part[mod] = 2, 4 or 6 unsigned int sequence = part[mod]++ / 2; // this is the sequency we are expecting, 1, 2 or 3 @@ -672,6 +674,7 @@ void CQnetGateway::ProcessG2Msg(const unsigned char *data, const int mod) } else { part[mod] = 0; // messages will never be spread across a superframe } + return false; } // new_group is true if we are processing the first voice packet of a 2-voice packet pair. The high order nibble of the first byte of @@ -971,6 +974,7 @@ void CQnetGateway::ProcessSlowData(unsigned char *data, const unsigned short sid void CQnetGateway::ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const int source_sock) // source_sock is the socket number of the incoming data, or -1 if it's a unix socket { + static std::string lhcallsign, lhsfx; static unsigned char lastctrl = 20U; static std::string superframe[3]; if ( (g2buflen==56 || g2buflen==27) && 0==memcmp(g2buf.title, "DSVT", 4) && (g2buf.config==0x10 || g2buf.config==0x20) && g2buf.id==0x20) { @@ -990,14 +994,13 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const i else printf("UnixSock=%s\n", link2gate.c_str()); } - - std::string mycall((const char *)g2buf.hdr.mycall, 8); - if (showLastHeard && memcmp(g2buf.hdr.sfx, "RPTR", 4) && std::regex_match(mycall.c_str(), preg)) { - std::string sfx((const char *)g2buf.hdr.sfx, 4); - std::string urcall((const char *)g2buf.hdr.urcall, 8); - rtrim(mycall); - rtrim(sfx); - qnDB.UpdateLH(mycall.c_str(), sfx.c_str(), urcall.c_str()); + lhcallsign.assign((const char *)g2buf.hdr.mycall, 8); + if (showLastHeard && memcmp(g2buf.hdr.sfx, "RPTR", 4) && std::regex_match(lhcallsign.c_str(), preg)) { + lhsfx.assign((const char *)g2buf.hdr.sfx, 4); + std::string reflector((const char *)g2buf.hdr.urcall, 8); + if (0 == reflector.compare("CQCQCQ ")) + set_dest_rptr('A'+i, reflector); + qnDB.UpdateLH(lhcallsign.c_str(), lhsfx.c_str(), 'A'+i, reflector.c_str()); } Gate2Modem[i].Write(g2buf.title, 56); @@ -1079,8 +1082,12 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const i // no matter what, we will send this on if it is the closing frame lastctrl = (0x3FU & g2buf.ctrl); Gate2Modem[i].Write(g2buf.title, 27); - if (source_sock >= 0) - ProcessG2Msg(g2buf.vasd.text, i); + if (source_sock >= 0) { + std::string smartgroup; + if(ProcessG2Msg(g2buf.vasd.text, i, smartgroup)) { + qnDB.UpdateLH(lhcallsign.c_str(), lhsfx.c_str(), 'A'+i, smartgroup.c_str()); + } + } } else { if (LOG_DEBUG) fprintf(stderr, "Warning: Ignoring packet because its ctrl=0x%02xU and lastctrl=0x%02xU\n", g2buf.ctrl, lastctrl); diff --git a/QnetGateway.h b/QnetGateway.h index ad6cdc6..a3eb540 100644 --- a/QnetGateway.h +++ b/QnetGateway.h @@ -174,7 +174,7 @@ private: void APRSBeaconThread(); void ProcessTimeouts(); void ProcessSlowData(unsigned char *data, const unsigned short sid); - void ProcessG2Msg(const unsigned char *data, const int mod); + bool ProcessG2Msg(const unsigned char *data, const int mod, std::string &smrtgrp); void ProcessG2(const ssize_t g2buflen, const SDSVT &g2buf, const int sock_source); void ProcessModem(); bool Flag_is_ok(unsigned char flag); diff --git a/index.php b/index.php index 194a7b4..9d0ecfc 100644 --- a/index.php +++ b/index.php @@ -149,16 +149,15 @@ foreach($showlist as $section) { break; case 'LH': echo 'Last Heard:
', "\n"; - $rstr = 'MyCall/Sfx Source Last Time
'; + $rstr = 'MyCall/Sfx Mod From Last Time
'; echo str_replace(' ', ' ', $rstr), "\n"; $dbname = $cfgdir.'/'.GetCFGValue('dash_sql_filename'); $db = new SQLite3($dbname, SQLITE3_OPEN_READONLY); - $ss = 'SELECT mycall,sfx,urcall,strftime("%s","now")-lasttime FROM LHEARD ORDER BY 4 LIMIT '.GetCFGValue('dash_lastheard_count').' '; + $ss = 'SELECT callsign,sfx,module,reflector,strftime("%s","now")-lasttime FROM LHEARD ORDER BY 4 LIMIT '.GetCFGValue('dash_lastheard_count').' '; if ($stmnt = $db->prepare($ss)) { if ($result = $stmnt->execute()) { while ($row = $result->FetchArray(SQLITE3_NUM)) { - $source = ("CQCQCQ " == $row[2]) ? "Linking" : "Routing"; - $rstr = MyAndSfxToQrz($row[0], $row[1]).' '.$source.' '.SecToString(intval($row[3])).'
'; + $rstr = MyAndSfxToQrz($row[0], $row[1]).' '.$row[2].' '.$row[3].' '.SecToString(intval($row[4])).'
'; echo str_replace('*', ' ', str_replace(' ', ' ', $rstr)), "\n"; } $result->finalize();