From 1a6b3291f7b2dbea5ce13e6d693bb112cc78c5dc Mon Sep 17 00:00:00 2001 From: Tom Early Date: Tue, 14 Dec 2021 11:05:05 -0700 Subject: [PATCH] M17 Packet sending a DEBUG help --- reflector/M17Protocol.cpp | 3 +++ reflector/Protocol.cpp | 43 +++++++++++++++++++++++++++++++++++++++ reflector/Protocol.h | 4 ++++ 3 files changed, 50 insertions(+) diff --git a/reflector/M17Protocol.cpp b/reflector/M17Protocol.cpp index 4a18800..e2cc569 100644 --- a/reflector/M17Protocol.cpp +++ b/reflector/M17Protocol.cpp @@ -248,6 +248,9 @@ void CM17Protocol::HandleQueue(void) else if ( packet->IsDvFrame() ) { EncodeM17Packet(frame, m_StreamsCache[module].m_dvHeader, (CDvFramePacket &)*packet.get(), m_StreamsCache[module].m_iSeqCounter++); +#ifdef DEBUG + Dump("Last M17 Packet:", frame.magic, sizeof(SM17Frame)); +#endif } // push it to all our clients linked to the module and who are not streaming in diff --git a/reflector/Protocol.cpp b/reflector/Protocol.cpp index 04b6825..4af5e84 100644 --- a/reflector/Protocol.cpp +++ b/reflector/Protocol.cpp @@ -336,3 +336,46 @@ void CProtocol::Send(const char *buf, const CIp &Ip, uint16_t port) const break; } } + +#ifdef DEBUG +void CProtocol::Dump(const char *title, const uint8_t *data, int length) +{ + std::cout << title << std::endl; + + unsigned int offset = 0U; + + while (length > 0) { + + unsigned int bytes = (length > 16) ? 16U : length; + + for (unsigned i = 0U; i < bytes; i++) { + if (i) + std::cout << " "; + std::cout << std::hex << std::setw(2) << std::right << std::setfill('0') << int(data[offset + i]); + } + + for (unsigned int i = bytes; i < 16U; i++) + std::cout << " "; + + std::cout << " *"; + + for (unsigned i = 0U; i < bytes; i++) { + unsigned char c = data[offset + i]; + + if (::isprint(c)) + std::cout << c; + else + std::cout << '.'; + } + + std::cout << '*' << std::endl; + + offset += 16U; + + if (length >= 16) + length -= 16; + else + length = 0; + } +} +#endif diff --git a/reflector/Protocol.h b/reflector/Protocol.h index 3bbe718..719f53e 100644 --- a/reflector/Protocol.h +++ b/reflector/Protocol.h @@ -133,4 +133,8 @@ protected: // debug CTimer m_DebugTimer; + +#ifdef DEBUG + void Dump(const char *title, const uint8_t *pointer, int length); +#endif };