diff --git a/Debug.h b/Debug.h index 599fbfd..aebe101 100644 --- a/Debug.h +++ b/Debug.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017,2021 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ #define DEBUG3(a,b,c) serial.writeDebug((a),(b),(c)) #define DEBUG4(a,b,c,d) serial.writeDebug((a),(b),(c),(d)) #define DEBUG5(a,b,c,d,e) serial.writeDebug((a),(b),(c),(d),(e)) +#define DEBUG_DUMP(a,b) serial.writeDebugDump((a),(b)) #endif diff --git a/SerialPort.cpp b/SerialPort.cpp index 1a47d8e..021313e 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -94,6 +94,7 @@ const uint8_t MMDVM_DEBUG2 = 0xF2U; const uint8_t MMDVM_DEBUG3 = 0xF3U; const uint8_t MMDVM_DEBUG4 = 0xF4U; const uint8_t MMDVM_DEBUG5 = 0xF5U; +const uint8_t MMDVM_DEBUG_DUMP = 0xFAU; #if EXTERNAL_OSC == 12000000 #define TCXO "12.0000 MHz" @@ -2049,3 +2050,29 @@ void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n writeInt(1U, reply, count, true); } +void CSerialPort::writeDebugDump(const uint8_t* data, uint16_t length) +{ + uint8_t reply[512U]; + + reply[0U] = MMDVM_FRAME_START; + + if (length > 252U) { + reply[1U] = 0U; + reply[2U] = (length + 4U) - 255U; + reply[3U] = MMDVM_DEBUG_DUMP; + + for (uint8_t i = 0U; i < length; i++) + reply[i + 4U] = data[i]; + + writeInt(1U, reply, length + 4U); + } else { + reply[1U] = length + 3U; + reply[2U] = MMDVM_DEBUG_DUMP; + + for (uint8_t i = 0U; i < length; i++) + reply[i + 3U] = data[i]; + + writeInt(1U, reply, length + 3U); + } +} + diff --git a/SerialPort.h b/SerialPort.h index c8f1733..26b26f7 100644 --- a/SerialPort.h +++ b/SerialPort.h @@ -97,6 +97,7 @@ public: void writeDebug(const char* text, int16_t n1, int16_t n2); void writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3); void writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3, int16_t n4); + void writeDebugDump(const uint8_t* data, uint16_t length); private: uint8_t m_buffer[512U];