diff --git a/Display.h b/Display.h index 4f6fc59..1344bf2 100644 --- a/Display.h +++ b/Display.h @@ -39,7 +39,7 @@ public: virtual void clearDMR(unsigned int slotNo) = 0; virtual void setFusion() = 0; - virtual void writeFusion(const std::string& callsign) = 0; + virtual void writeFusion(const char* source, const char* dest) = 0; virtual void clearFusion() = 0; virtual void close() = 0; diff --git a/NullDisplay.cpp b/NullDisplay.cpp index fc5ce61..3b51959 100644 --- a/NullDisplay.cpp +++ b/NullDisplay.cpp @@ -63,7 +63,7 @@ void CNullDisplay::setFusion() { } -void CNullDisplay::writeFusion(const std::string& callsign) +void CNullDisplay::writeFusion(const char* source, const char* dest) { } diff --git a/NullDisplay.h b/NullDisplay.h index d546158..f35df00 100644 --- a/NullDisplay.h +++ b/NullDisplay.h @@ -42,7 +42,7 @@ public: virtual void clearDMR(unsigned int slotNo); virtual void setFusion(); - virtual void writeFusion(const std::string& callsign); + virtual void writeFusion(const char* source, const char* dest); virtual void clearFusion(); virtual void close(); diff --git a/TFTSerial.cpp b/TFTSerial.cpp index b92e511..0bc87a2 100644 --- a/TFTSerial.cpp +++ b/TFTSerial.cpp @@ -104,7 +104,7 @@ void CTFTSerial::writeDStar(const char* my1, const char* my2, const char* your) assert(my2 != NULL); assert(your != NULL); - char text[20U]; + char text[30U]; ::sprintf(text, "%8.8s/%4.4s -> %8.8s", my1, my2, your); gotoPosText(0U, 8U); @@ -146,12 +146,12 @@ void CTFTSerial::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, u assert(type != NULL); if (slotNo == 1U) { - char text[20U]; + char text[30U]; ::sprintf(text, "1: %s %u -> %s%u", type, srcId, group ? "TG" : "", dstId); gotoPosText(0U, 8U); displayText(text); } else { - char text[20U]; + char text[30U]; ::sprintf(text, "2: %s %u -> %s%u", type, srcId, group ? "TG" : "", dstId); gotoPosText(0U, 9U); displayText(text); @@ -184,10 +184,13 @@ void CTFTSerial::setFusion() displayText("Listening"); } -void CTFTSerial::writeFusion(const std::string& callsign) +void CTFTSerial::writeFusion(const char* source, const char* dest) { - char text[20U]; - ::sprintf(text, "%s", callsign.c_str()); + assert(source != NULL); + assert(dest != NULL); + + char text[30U]; + ::sprintf(text, "%s -> %s", source, dest); gotoPosText(0U, 8U); displayText(text); diff --git a/TFTSerial.h b/TFTSerial.h index 918fb9e..f457303 100644 --- a/TFTSerial.h +++ b/TFTSerial.h @@ -43,7 +43,7 @@ public: virtual void clearDMR(unsigned int slotNo); virtual void setFusion(); - virtual void writeFusion(const std::string& callsign); + virtual void writeFusion(const char* source, const char* dest); virtual void clearFusion(); virtual void close(); diff --git a/YSFControl.cpp b/YSFControl.cpp index 21a9797..e1bbf27 100644 --- a/YSFControl.cpp +++ b/YSFControl.cpp @@ -36,6 +36,8 @@ m_state(RS_RF_LISTENING), m_timeoutTimer(1000U, timeout), m_frames(0U), m_fich(), +m_source(NULL), +m_dest(NULL), m_payload(), m_parrot(NULL), m_fp(NULL) @@ -78,9 +80,8 @@ bool CYSFControl::writeModem(unsigned char *data) if (type == TAG_DATA && valid && m_state == RS_RF_LISTENING) { m_frames = 0U; m_timeoutTimer.start(); - m_display->writeFusion("XXXXXX"); + m_payload.reset(); m_state = RS_RF_AUDIO; - LogMessage("YSF, received RF header"); #if defined(DUMP_YSF) openFile(); #endif @@ -92,23 +93,22 @@ bool CYSFControl::writeModem(unsigned char *data) if (type == TAG_EOT) { CSync::addYSFSync(data + 2U); - CYSFFICH fich; - fich.decode(data + 2U); + m_fich.decode(data + 2U); - unsigned char fi = fich.getFI(); - unsigned char fn = fich.getFN(); - unsigned char dt = fich.getDT(); + unsigned char fi = m_fich.getFI(); + unsigned char fn = m_fich.getFN(); + unsigned char dt = m_fich.getDT(); LogMessage("YSF, EOT, FI=%X FN=%u DT=%X", fi, fn, dt); m_payload.decode(data + 2U, fi, fn, dt); - // m_payload.encode(data + 2U); + // m_payload.encode(data + 2U); XXX m_frames++; if (m_duplex) { - fich.setMR(YSF_MR_BUSY); - fich.encode(data + 2U); + m_fich.setMR(YSF_MR_BUSY); + m_fich.encode(data + 2U); data[0U] = TAG_EOT; data[1U] = 0x00U; @@ -116,8 +116,8 @@ bool CYSFControl::writeModem(unsigned char *data) } if (m_parrot != NULL) { - fich.setMR(YSF_MR_NOT_BUSY); - fich.encode(data + 2U); + m_fich.setMR(YSF_MR_NOT_BUSY); + m_fich.encode(data + 2U); data[0U] = TAG_EOT; data[1U] = 0x00U; @@ -140,13 +140,42 @@ bool CYSFControl::writeModem(unsigned char *data) assert(ret); unsigned char fi = m_fich.getFI(); + unsigned char cm = m_fich.getCM(); unsigned char fn = m_fich.getFN(); unsigned char dt = m_fich.getDT(); LogMessage("YSF, Valid FICH, FI=%X FN=%u DT=%X", m_fich.getFI(), m_fich.getFN(), m_fich.getDT()); m_payload.decode(data + 2U, fi, fn, dt); - // payload.encode(data + 2U); + // payload.encode(data + 2U); XXX + + bool change = false; + + if (cm == 0x00U && m_dest == NULL) { + m_dest = (unsigned char*)"CQCQCQ"; + change = true; + } + + if (m_source == NULL) { + m_source = m_payload.getSource(); + if (m_source != NULL) + change = true; + } + + if (m_dest == NULL) { + m_dest = m_payload.getDest(); + if (m_dest != NULL) + change = true; + } + + if (change) { + if (m_source != NULL && m_dest != NULL) + m_display->writeFusion((char*)m_source, (char*)m_dest); + if (m_source != NULL && m_dest == NULL) + m_display->writeFusion((char*)m_source, "??????"); + if (m_source == NULL && m_dest != NULL) + m_display->writeFusion("??????", (char*)m_dest); + } } else { LogMessage("YSF, invalid FICH"); @@ -201,8 +230,14 @@ void CYSFControl::writeEndOfTransmission() m_timeoutTimer.stop(); + m_payload.reset(); + m_display->clearFusion(); + // These variables are free'd by YSFPayload + m_source = NULL; + m_dest = NULL; + #if defined(DUMP_YSF) closeFile(); #endif diff --git a/YSFControl.h b/YSFControl.h index 960c68e..ffa61e3 100644 --- a/YSFControl.h +++ b/YSFControl.h @@ -50,6 +50,8 @@ private: CTimer m_timeoutTimer; unsigned int m_frames; CYSFFICH m_fich; + unsigned char* m_source; + unsigned char* m_dest; CYSFPayload m_payload; CYSFParrot* m_parrot; FILE* m_fp; diff --git a/YSFPayload.cpp b/YSFPayload.cpp index 8a6fc06..1b622e7 100644 --- a/YSFPayload.cpp +++ b/YSFPayload.cpp @@ -89,6 +89,8 @@ CYSFPayload::~CYSFPayload() delete[] m_data; delete[] m_uplink; delete[] m_downlink; + delete[] m_source; + delete[] m_dest; } bool CYSFPayload::decode(const unsigned char* bytes, unsigned char fi, unsigned char fn, unsigned char dt) @@ -159,13 +161,15 @@ bool CYSFPayload::decodeHeader() CUtils::dump("Header/Trailer, Source", output + 0U, 10U); CUtils::dump("Header/Trailer, Destination", output + 10U, 10U); - if (m_source == NULL) + if (m_source == NULL) { m_source = new unsigned char[10U]; - if (m_dest == NULL) - m_dest = new unsigned char[10U]; + ::memcpy(m_source, output + 0U, 10U); + } - ::memcpy(m_source, output + 0U, 10U); - ::memcpy(m_dest, output + 10U, 10U); + if (m_dest == NULL) { + m_dest = new unsigned char[10U]; + ::memcpy(m_dest, output + 10U, 10U); + } for (unsigned int i = 0U; i < 20U; i++) output[i] ^= WHITENING_DATA[i]; @@ -278,17 +282,24 @@ bool CYSFPayload::decodeVDMode1(unsigned char fn) case 0U: CUtils::dump("V/D Mode 1, Destination", output + 0U, 10U); CUtils::dump("V/D Mode 1, Source", output + 10U, 10U); - if (m_dest == NULL) + + if (m_dest == NULL) { m_dest = new unsigned char[10U]; - if (m_source == NULL) + ::memcpy(m_dest, output + 0U, 10U); + } + + if (m_source == NULL) { m_source = new unsigned char[10U]; - ::memcpy(m_dest, output, 10U); - ::memcpy(m_source, output, 10U); + ::memcpy(m_source, output + 10U, 10U); + } + break; + case 2U: CUtils::dump("V/D Mode 1, Rem 1+2", output + 0U, 10U); CUtils::dump("V/D Mode 1, Rem 3+4", output + 10U, 10U); break; + default: break; } @@ -382,15 +393,17 @@ bool CYSFPayload::decodeVDMode2(unsigned char fn) switch (fn) { case 0U: CUtils::dump("V/D Mode 2, Destination", output, 10U); - if (m_dest == NULL) + if (m_dest == NULL) { m_dest = new unsigned char[10U]; - ::memcpy(m_dest, output, 10U); + ::memcpy(m_dest, output, 10U); + } break; case 1U: CUtils::dump("V/D Mode 2, Source", output, 10U); - if (m_source == NULL) + if (m_source == NULL) { m_source = new unsigned char[10U]; - ::memcpy(m_source, output, 10U); + ::memcpy(m_source, output, 10U); + } break; case 4U: CUtils::dump("V/D Mode 2, Rem 1+2", output, 10U); @@ -496,13 +509,19 @@ bool CYSFPayload::decodeDataFRMode(unsigned char fn) case 0U: CUtils::dump("Data FR Mode, Destination", output + 0U, 10U); CUtils::dump("Data FR Mode, Source", output + 10U, 10U); - if (m_dest == NULL) + + if (m_dest == NULL) { m_dest = new unsigned char[10U]; - if (m_source == NULL) + ::memcpy(m_dest, output + 0U, 10U); + } + + if (m_source == NULL) { m_source = new unsigned char[10U]; - ::memcpy(m_dest, output, 10U); - ::memcpy(m_source, output, 10U); + ::memcpy(m_source, output + 10U, 10U); + } + break; + case 1U: CUtils::dump("Data FR Mode, Rem 1+2", output + 0U, 10U); CUtils::dump("Data FR Mode, Rem 3+4", output + 10U, 10U); @@ -643,32 +662,21 @@ void CYSFPayload::setDownlink(const std::string& callsign) m_downlink[i] = downlink.at(i); } -bool CYSFPayload::getSource(unsigned char* callsign) +unsigned char* CYSFPayload::getSource() { - assert(callsign != NULL); + return m_source; +} - if (m_source == NULL) - return false; - - ::memcpy(callsign, m_source, 10U); +unsigned char* CYSFPayload::getDest() +{ + return m_dest; +} +void CYSFPayload::reset() +{ delete[] m_source; - m_source = NULL; - - return true; -} - -bool CYSFPayload::getDest(unsigned char* callsign) -{ - assert(callsign != NULL); - - if (m_dest == NULL) - return false; - - ::memcpy(callsign, m_dest, 10U); - delete[] m_dest; - m_dest = NULL; - return true; + m_source = NULL; + m_dest = NULL; } diff --git a/YSFPayload.h b/YSFPayload.h index b2ee229..535473c 100644 --- a/YSFPayload.h +++ b/YSFPayload.h @@ -30,12 +30,14 @@ public: void encode(unsigned char* bytes); - bool getSource(unsigned char* callsign); - bool getDest(unsigned char* callsign); + unsigned char* getSource(); + unsigned char* getDest(); void setUplink(const std::string& callsign); void setDownlink(const std::string& callsign); + void reset(); + private: unsigned char* m_data; unsigned char* m_uplink;