From cce03a4d2fd718d2495ccebd71c6f763ffb22b0c Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Mon, 26 Jun 2017 11:10:15 -0400 Subject: [PATCH] Adding Jonathan G4KLX run-time debugging option --- DMRDMORX.cpp | 2 -- DMRDMOTX.cpp | 2 -- DStarRX.cpp | 6 +----- DStarTX.cpp | 2 -- Debug.h | 16 +--------------- P25RX.cpp | 2 -- P25TX.cpp | 2 -- SerialPort.cpp | 50 +++++++++++++++++++------------------------------- SerialPort.h | 3 +-- YSFRX.cpp | 2 -- YSFTX.cpp | 2 -- 11 files changed, 22 insertions(+), 67 deletions(-) diff --git a/DMRDMORX.cpp b/DMRDMORX.cpp index ff099d2..1159216 100644 --- a/DMRDMORX.cpp +++ b/DMRDMORX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "DMRDMORX.h" diff --git a/DMRDMOTX.cpp b/DMRDMOTX.cpp index 88f06d3..ef0abab 100644 --- a/DMRDMOTX.cpp +++ b/DMRDMOTX.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" diff --git a/DStarRX.cpp b/DStarRX.cpp index 12bb276..5a8d170 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -//#define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "DStarRX.h" @@ -291,7 +289,6 @@ void CDStarRX::processNone(bool bit) // Fuzzy matching of the preamble sync sequence if (countBits32((m_patternBuffer & PREAMBLE_MASK) ^ PREAMBLE_DATA) <= PREAMBLE_ERRS) { - DEBUG1("DStarRX: preamble detected, fuzzy"); // Extend scan period in D-Star, once preamble is detected m_modeTimerCnt = 0; @@ -385,12 +382,11 @@ void CDStarRX::processData(bool bit) bool syncSeen = false; if (m_dataBits >= SYNC_SCAN_START && m_dataBits <= (SYNC_POS + 1U)) { if (countBits32((m_patternBuffer & DATA_SYNC_MASK) ^ DATA_SYNC_DATA) <= DATA_SYNC_ERRS) { -#if defined(WANT_DEBUG) if (m_dataBits < SYNC_POS) DEBUG2("DStarRX: found data sync in Data, early", SYNC_POS - m_dataBits); else DEBUG1("DStarRX: found data sync in Data"); -#endif + m_rxBufferBits = DSTAR_DATA_LENGTH_BITS; m_dataBits = 0U; syncSeen = true; diff --git a/DStarTX.cpp b/DStarTX.cpp index e5670f6..3cc5e00 100644 --- a/DStarTX.cpp +++ b/DStarTX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "DStarTX.h" diff --git a/Debug.h b/Debug.h index c056d6c..80ba786 100644 --- a/Debug.h +++ b/Debug.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017 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 @@ -19,8 +19,6 @@ #if !defined(DEBUG_H) #define DEBUG_H -#if defined(WANT_DEBUG) - #include "Globals.h" #define DEBUG1(a) serial.writeDebug((a)) @@ -28,18 +26,6 @@ #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 ASSERT(a) serial.writeAssert((a),#a,__FILE__,__LINE__) - -#else - -#define DEBUG1(a) -#define DEBUG2(a,b) -#define DEBUG3(a,b,c) -#define DEBUG4(a,b,c,d) -#define DEBUG5(a,b,c,d,e) -#define ASSERT(a) - -#endif #endif diff --git a/P25RX.cpp b/P25RX.cpp index 5fa244f..3a14a03 100644 --- a/P25RX.cpp +++ b/P25RX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "P25RX.h" diff --git a/P25TX.cpp b/P25TX.cpp index b1bff2e..5b2437c 100644 --- a/P25TX.cpp +++ b/P25TX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "P25TX.h" diff --git a/SerialPort.cpp b/SerialPort.cpp index 0f990f6..9acfc52 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" @@ -91,7 +89,8 @@ const uint8_t PROTOCOL_VERSION = 1U; CSerialPort::CSerialPort() : m_buffer(), m_ptr(0U), -m_len(0U) +m_len(0U), +m_debug(false) { } @@ -203,6 +202,8 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) bool ysfLoDev = (data[0U] & 0x08U) == 0x08U; bool simplex = (data[0U] & 0x80U) == 0x80U; + + m_debug = (data[0U] & 0x10U) == 0x10U; bool dstarEnable = (data[1U] & 0x01U) == 0x01U; bool dmrEnable = (data[1U] & 0x02U) == 0x02U; @@ -784,6 +785,9 @@ void CSerialPort::writeP25Lost() void CSerialPort::writeDebug(const char* text) { + if (!m_debug) + return; + uint8_t reply[130U]; reply[0U] = MMDVM_FRAME_START; @@ -801,6 +805,9 @@ void CSerialPort::writeDebug(const char* text) void CSerialPort::writeDebug(const char* text, int16_t n1) { + if (!m_debug) + return; + uint8_t reply[130U]; reply[0U] = MMDVM_FRAME_START; @@ -821,6 +828,9 @@ void CSerialPort::writeDebug(const char* text, int16_t n1) void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2) { + if (!m_debug) + return; + uint8_t reply[130U]; reply[0U] = MMDVM_FRAME_START; @@ -844,6 +854,9 @@ void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2) void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3) { + if (!m_debug) + return; + uint8_t reply[130U]; reply[0U] = MMDVM_FRAME_START; @@ -870,6 +883,9 @@ void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3, int16_t n4) { + if (!m_debug) + return; + uint8_t reply[130U]; reply[0U] = MMDVM_FRAME_START; @@ -897,31 +913,3 @@ void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n writeInt(1U, reply, count, true); } -void CSerialPort::writeAssert(bool cond, const char* text, const char* file, long line) -{ - if (cond) - return; - - uint8_t reply[200U]; - - reply[0U] = MMDVM_FRAME_START; - reply[1U] = 0U; - reply[2U] = MMDVM_DEBUG2; - - uint8_t count = 3U; - for (uint8_t i = 0U; text[i] != '\0'; i++, count++) - reply[count] = text[i]; - - reply[count++] = ' '; - - for (uint8_t i = 0U; file[i] != '\0'; i++, count++) - reply[count] = file[i]; - - reply[count++] = (line >> 8) & 0xFF; - reply[count++] = (line >> 0) & 0xFF; - - reply[1U] = count; - - writeInt(1U, reply, count, true); -} - diff --git a/SerialPort.h b/SerialPort.h index 233c44c..920b220 100644 --- a/SerialPort.h +++ b/SerialPort.h @@ -50,12 +50,11 @@ public: 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 writeAssert(bool cond, const char* text, const char* file, long line); - private: uint8_t m_buffer[256U]; uint8_t m_ptr; uint8_t m_len; + bool m_debug; void sendACK(); void sendNAK(uint8_t err); diff --git a/YSFRX.cpp b/YSFRX.cpp index 23388c0..f35c238 100644 --- a/YSFRX.cpp +++ b/YSFRX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "YSFRX.h" diff --git a/YSFTX.cpp b/YSFTX.cpp index 92829c1..5e047a2 100644 --- a/YSFTX.cpp +++ b/YSFTX.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG - #include "Config.h" #include "Globals.h" #include "YSFTX.h"