diff --git a/YSFControl.cpp b/YSFControl.cpp index 0ab0264..71f4d76 100644 --- a/YSFControl.cpp +++ b/YSFControl.cpp @@ -998,18 +998,13 @@ void CYSFControl::writeNetwork() if (end) return; - if (::memcmp(data + 14U, " ", YSF_CALLSIGN_LENGTH) != 0) - ::memcpy(m_netSource, data + 14U, YSF_CALLSIGN_LENGTH); - else - ::memcpy(m_netSource, "??????????", YSF_CALLSIGN_LENGTH); + ::memcpy(m_netSource, data + 14U, YSF_CALLSIGN_LENGTH); + ::memcpy(m_netDest, data + 24U, YSF_CALLSIGN_LENGTH); - if (::memcmp(data + 24U, " ", YSF_CALLSIGN_LENGTH) != 0) - ::memcpy(m_netDest, data + 24U, YSF_CALLSIGN_LENGTH); - else - ::memcpy(m_netDest, "??????????", YSF_CALLSIGN_LENGTH); - - m_display->writeFusion((char*)m_netSource, (char*)m_netDest, "N", (char*)(data + 4U)); - LogMessage("YSF, received network data from %10.10s to %10.10s at %10.10s", m_netSource, m_netDest, data + 4U); + if (::memcmp(m_netSource, " ", 10U) != 0 && ::memcmp(m_netDest, " ", 10U) != 0) { + m_display->writeFusion((char*)m_netSource, (char*)m_netDest, "N", (char*)(data + 4U)); + LogMessage("YSF, received network data from %10.10s to %10.10s at %10.10s", m_netSource, m_netDest, data + 4U); + } m_netTimeoutTimer.start(); m_netPayload.reset(); @@ -1025,23 +1020,6 @@ void CYSFControl::writeNetwork() // Check for duplicate frames, if we can if (m_netN == n) return; - - bool changed = false; - - if (::memcmp(data + 14U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(m_netSource, "??????????", YSF_CALLSIGN_LENGTH) == 0) { - ::memcpy(m_netSource, data + 14U, YSF_CALLSIGN_LENGTH); - changed = true; - } - - if (::memcmp(data + 24U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(m_netDest, "??????????", YSF_CALLSIGN_LENGTH) == 0) { - ::memcpy(m_netDest, data + 24U, YSF_CALLSIGN_LENGTH); - changed = true; - } - - if (changed) { - m_display->writeFusion((char*)m_netSource, (char*)m_netDest, "N", (char*)(data + 4U)); - LogMessage("YSF, received network data from %10.10s to %10.10s at %10.10s", m_netSource, m_netDest, data + 4U); - } } data[33U] = end ? TAG_EOT : TAG_DATA; @@ -1054,6 +1032,12 @@ void CYSFControl::writeNetwork() unsigned char fn = fich.getFN(); unsigned char ft = fich.getFT(); unsigned char fi = fich.getFI(); + unsigned char cm = fich.getCM(); + + if (::memcmp(m_netDest, " ", YSF_CALLSIGN_LENGTH) == 0) { + if (cm == YSF_CM_GROUP1 || cm == YSF_CM_GROUP2) + ::memcpy(m_netDest, "ALL ", YSF_CALLSIGN_LENGTH); + } // Add any DSQ information fich.setSQL(m_sqlEnabled); @@ -1066,15 +1050,10 @@ void CYSFControl::writeNetwork() // Set the downlink callsign switch (fi) { - case YSF_FI_HEADER: - m_netPayload.processHeaderData(data + 35U); - if (::memcmp(m_netSource, "??????????", YSF_CALLSIGN_LENGTH) == 0) { - unsigned char* source = m_netPayload.getSource(); - if (source != NULL) { - ::memcpy(m_netSource, source, YSF_CALLSIGN_LENGTH); - m_display->writeFusion((char*)m_netSource, (char*)m_netDest, "N", (char*)(data + 4U)); - LogMessage("YSF, received network data from %10.10s to %10.10s at %10.10s", m_netSource, m_netDest, data + 4U); - } + case YSF_FI_HEADER: { + bool ok = m_netPayload.processHeaderData(data + 35U); + if (ok) + processNetCallsigns(data); } break; @@ -1085,36 +1064,24 @@ void CYSFControl::writeNetwork() case YSF_FI_COMMUNICATIONS: switch (dt) { case YSF_DT_VD_MODE1: { - m_netPayload.processVDMode1Data(data + 35U, fn, gateway); + bool ok = m_netPayload.processVDMode1Data(data + 35U, fn, gateway); + if (ok) + processNetCallsigns(data); + unsigned int errors = m_netPayload.processVDMode1Audio(data + 35U); m_netErrs += errors; m_netBits += 235U; - - if (::memcmp(m_netSource, "??????????", YSF_CALLSIGN_LENGTH) == 0) { - unsigned char* source = m_netPayload.getSource(); - if (source != NULL) { - ::memcpy(m_netSource, source, YSF_CALLSIGN_LENGTH); - m_display->writeFusion((char*)m_netSource, (char*)m_netDest, "N", (char*)(data + 4U)); - LogMessage("YSF, received network data from %10.10s to %10.10s at %10.10s", m_netSource, m_netDest, data + 4U); - } - } } break; case YSF_DT_VD_MODE2: { - m_netPayload.processVDMode2Data(data + 35U, fn, gateway); + bool ok = m_netPayload.processVDMode2Data(data + 35U, fn, gateway); + if (ok) + processNetCallsigns(data); + unsigned int errors = m_netPayload.processVDMode2Audio(data + 35U); m_netErrs += errors; m_netBits += 135U; - - if (::memcmp(m_netSource, "??????????", YSF_CALLSIGN_LENGTH) == 0) { - unsigned char* source = m_netPayload.getSource(); - if (source != NULL) { - ::memcpy(m_netSource, source, YSF_CALLSIGN_LENGTH); - m_display->writeFusion((char*)m_netSource, (char*)m_netDest, "N", (char*)(data + 4U)); - LogMessage("YSF, received network data from %10.10s to %10.10s at %10.10s", m_netSource, m_netDest, data + 4U); - } - } } break; @@ -1271,3 +1238,27 @@ bool CYSFControl::checkCallsign(const unsigned char* callsign) const { return ::memcmp(callsign, m_selfCallsign, ::strlen((char*)m_selfCallsign)) == 0; } + +void CYSFControl::processNetCallsigns(const unsigned char* data) +{ + assert(data != NULL); + + if (::memcmp(m_netSource, " ", 10U) == 0 || ::memcmp(m_netDest, " ", 10U) == 0) { + if (::memcmp(m_netSource, " ", YSF_CALLSIGN_LENGTH) == 0) { + unsigned char* source = m_netPayload.getSource(); + if (source != NULL) + ::memcpy(m_netSource, source, YSF_CALLSIGN_LENGTH); + } + + if (::memcmp(m_netDest, " ", YSF_CALLSIGN_LENGTH) == 0) { + unsigned char* dest = m_netPayload.getDest(); + if (dest != NULL) + ::memcpy(m_netDest, dest, YSF_CALLSIGN_LENGTH); + } + + if (::memcmp(m_netSource, " ", 10U) != 0 && ::memcmp(m_netDest, " ", 10U) != 0) { + m_display->writeFusion((char*)m_netSource, (char*)m_netDest, "N", (char*)(data + 4U)); + LogMessage("YSF, received network data from %10.10s to %10.10s at %10.10s", m_netSource, m_netDest, data + 4U); + } + } +} diff --git a/YSFControl.h b/YSFControl.h index a188006..3f09a76 100644 --- a/YSFControl.h +++ b/YSFControl.h @@ -105,6 +105,7 @@ private: void closeFile(); bool checkCallsign(const unsigned char* callsign) const; + void processNetCallsigns(const unsigned char* data); }; #endif