From 9d7e9040cfbbd25e4827bf92bafdab29fdb5df3c Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 23 Feb 2019 09:36:56 +0100 Subject: [PATCH] Updated debug macros --- src/Module.cpp | 26 ++++++++++---------- src/TypeDef.h | 33 +++++++++----------------- src/modules/CC1101.cpp | 4 ++-- src/modules/RF69.cpp | 4 ++-- src/modules/SX1231.cpp | 4 ++-- src/modules/SX127x.cpp | 8 +++---- src/modules/XBee.cpp | 54 +++++++++++++++++++++--------------------- 7 files changed, 61 insertions(+), 72 deletions(-) diff --git a/src/Module.cpp b/src/Module.cpp index b5853300..ba51d06f 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -141,22 +141,22 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t // check failed, print debug info DEBUG_PRINTLN(); - DEBUG_PRINT_STR("address:\t0x"); - DEBUG_PRINTLN_HEX(reg); - DEBUG_PRINT_STR("bits:\t\t"); + DEBUG_PRINT(F("address:\t0x")); + DEBUG_PRINTLN(reg, HEX); + DEBUG_PRINT(F("bits:\t\t")); DEBUG_PRINT(msb); DEBUG_PRINT(' '); DEBUG_PRINTLN(lsb); - DEBUG_PRINT_STR("value:\t\t0b"); - DEBUG_PRINTLN_BIN(value); - DEBUG_PRINT_STR("current:\t0b"); - DEBUG_PRINTLN_BIN(currentValue); - DEBUG_PRINT_STR("mask:\t\t0b"); - DEBUG_PRINTLN_BIN(mask); - DEBUG_PRINT_STR("new:\t\t0b"); - DEBUG_PRINTLN_BIN(newValue); - DEBUG_PRINT_STR("read:\t\t0b"); - DEBUG_PRINTLN_BIN(readValue); + DEBUG_PRINT(F("value:\t\t0b")); + DEBUG_PRINTLN(value, BIN); + DEBUG_PRINT(F("current:\t0b")); + DEBUG_PRINTLN(currentValue, BIN); + DEBUG_PRINT(F("mask:\t\t0b")); + DEBUG_PRINTLN(mask, BIN); + DEBUG_PRINT(F("new:\t\t0b")); + DEBUG_PRINTLN(newValue, BIN); + DEBUG_PRINT(F("read:\t\t0b")); + DEBUG_PRINTLN(readValue, BIN); DEBUG_PRINTLN(); return(ERR_SPI_WRITE_FAILED); diff --git a/src/TypeDef.h b/src/TypeDef.h index c9f2cc8d..8f731564 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -10,29 +10,13 @@ //#define RADIOLIB_DEBUG #ifdef RADIOLIB_DEBUG - #define DEBUG_BEGIN(x) Serial.begin (x) - #define DEBUG_PRINT(x) Serial.print (x) - #define DEBUG_PRINT_BIN(x) Serial.print (x, BIN) - #define DEBUG_PRINTLN_BIN(x) Serial.println (x, BIN) - #define DEBUG_PRINT_DEC(x) Serial.print (x, DEC) - #define DEBUG_PRINTLN_DEC(x) Serial.println (x, DEC) - #define DEBUG_PRINT_HEX(x) Serial.print (x, HEX) - #define DEBUG_PRINTLN_HEX(x) Serial.println (x, HEX) - #define DEBUG_PRINTLN(x) Serial.println (x) - #define DEBUG_PRINT_STR(x) Serial.print (F(x)) - #define DEBUG_PRINTLN_STR(x) Serial.println (F(x)) + #define DEBUG_BEGIN(...) { Serial.begin(__VA_ARGS__); } + #define DEBUG_PRINT(...) { Serial.print(__VA_ARGS__); } + #define DEBUG_PRINTLN(...) { Serial.println(__VA_ARGS__); } #else - #define DEBUG_BEGIN(x) - #define DEBUG_PRINT(x) - #define DEBUG_PRINT_BIN(x) - #define DEBUG_PRINTLN_BIN(x) - #define DEBUG_PRINT_DEC(x) - #define DEBUG_PRINTLN_DEC(x) - #define DEBUG_PRINT_HEX(x) - #define DEBUG_PRINTLN_HEX(x) - #define DEBUG_PRINTLN(x) - #define DEBUG_PRINT_STR(x) - #define DEBUG_PRINTLN_STR(x) + #define DEBUG_BEGIN(...) {} + #define DEBUG_PRINT(...) {} + #define DEBUG_PRINTLN(...) {} #endif // Shield configuration @@ -117,6 +101,11 @@ #define ERR_INVALID_RTTY_SHIFT -401 #define ERR_UNSUPPORTED_ENCODING -402 +// nRF24 status codes +#define ERR_INVALID_DATA_RATE -501 +#define ERR_INVALID_ADDRESS_WIDTH -502 +#define ERR_INVALID_PIPE_NUMBER -503 + // CC1101-specific status codes #define ERR_INVALID_NUM_BROAD_ADDRS -601 diff --git a/src/modules/CC1101.cpp b/src/modules/CC1101.cpp index 9cc8d00d..02e7cc72 100644 --- a/src/modules/CC1101.cpp +++ b/src/modules/CC1101.cpp @@ -35,11 +35,11 @@ int16_t CC1101::begin(float freq, float br, float rxBw, float freqDev, int8_t po } if(!flagFound) { - DEBUG_PRINTLN_STR("No CC1101 found!"); + DEBUG_PRINTLN(F("No CC1101 found!")); SPI.end(); return(ERR_CHIP_NOT_FOUND); } else { - DEBUG_PRINTLN_STR("Found CC1101! (match by CC1101_REG_VERSION == 0x14)"); + DEBUG_PRINTLN(F("Found CC1101! (match by CC1101_REG_VERSION == 0x14)")); } // configure settings not accessible by API diff --git a/src/modules/RF69.cpp b/src/modules/RF69.cpp index 0345e0e6..80ef0f98 100644 --- a/src/modules/RF69.cpp +++ b/src/modules/RF69.cpp @@ -34,11 +34,11 @@ int16_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t powe } if(!flagFound) { - DEBUG_PRINTLN_STR("No RF69 found!"); + DEBUG_PRINTLN(F("No RF69 found!")); SPI.end(); return(ERR_CHIP_NOT_FOUND); } else { - DEBUG_PRINTLN_STR("Found RF69! (match by RF69_REG_VERSION == 0x24)"); + DEBUG_PRINTLN(F("Found RF69! (match by RF69_REG_VERSION == 0x24)")); } // configure settings not accessible by API diff --git a/src/modules/SX1231.cpp b/src/modules/SX1231.cpp index 6a4778ad..23c15cd4 100644 --- a/src/modules/SX1231.cpp +++ b/src/modules/SX1231.cpp @@ -34,11 +34,11 @@ int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po } if(!flagFound) { - DEBUG_PRINTLN_STR("No SX1231 found!"); + DEBUG_PRINTLN(F("No SX1231 found!")); SPI.end(); return(ERR_CHIP_NOT_FOUND); } else { - DEBUG_PRINTLN_STR("Found SX1231!"); + DEBUG_PRINTLN(F("Found SX1231!")); } // configure settings not accessible by API diff --git a/src/modules/SX127x.cpp b/src/modules/SX127x.cpp index fc393198..5b3d9745 100644 --- a/src/modules/SX127x.cpp +++ b/src/modules/SX127x.cpp @@ -10,11 +10,11 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi // try to find the SX127x chip if(!SX127x::findChip(chipVersion)) { - DEBUG_PRINTLN_STR("No SX127x found!"); + DEBUG_PRINTLN(F("No SX127x found!")); SPI.end(); return(ERR_CHIP_NOT_FOUND); } else { - DEBUG_PRINTLN_STR("Found SX127x!"); + DEBUG_PRINTLN(F("Found SX127x!")); } // check active modem @@ -54,11 +54,11 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB // try to find the SX127x chip if(!SX127x::findChip(chipVersion)) { - DEBUG_PRINTLN_STR("No SX127x found!"); + DEBUG_PRINTLN(F("No SX127x found!")); SPI.end(); return(ERR_CHIP_NOT_FOUND); } else { - DEBUG_PRINTLN_STR("Found SX127x!"); + DEBUG_PRINTLN(F("Found SX127x!")); } // check currently active modem diff --git a/src/modules/XBee.cpp b/src/modules/XBee.cpp index 4d43841d..7c31a588 100644 --- a/src/modules/XBee.cpp +++ b/src/modules/XBee.cpp @@ -30,11 +30,11 @@ int16_t XBee::begin(long speed) { if(state == ERR_NONE) { flagFound = true; } else { - DEBUG_PRINT_STR("XBee not found! ("); + DEBUG_PRINT(F("XBee not found! (")); DEBUG_PRINT(i + 1); - DEBUG_PRINT_STR(" of 10 tries) STATE == "); + DEBUG_PRINT(F(" of 10 tries) STATE == ")); DEBUG_PRINTLN(state); - DEBUG_PRINTLN_STR("Resetting ..."); + DEBUG_PRINTLN(F("Resetting ...")); reset(); delay(1000); _mod->ATemptyBuffer(); @@ -43,10 +43,10 @@ int16_t XBee::begin(long speed) { } if(!flagFound) { - DEBUG_PRINTLN_STR("No XBee found!"); + DEBUG_PRINTLN(F("No XBee found!")); return(ERR_CMD_MODE_FAILED); } else { - DEBUG_PRINTLN_STR("Found XBee!"); + DEBUG_PRINTLN(F("Found XBee!")); } return(ERR_NONE); @@ -182,19 +182,19 @@ int16_t XBeeSerial::begin(long speed) { _mod->ATemptyBuffer(); // enter command mode - DEBUG_PRINTLN_STR("Entering command mode ..."); + DEBUG_PRINTLN(F("Entering command mode ...")); if(!enterCmdMode()) { return(ERR_CMD_MODE_FAILED); } // test AT setup - DEBUG_PRINTLN_STR("Sending test command ..."); + DEBUG_PRINTLN(F("Sending test command ...")); if(!_mod->ATsendCommand("AT")) { return(ERR_AT_FAILED); } // exit command mode - DEBUG_PRINTLN_STR("Exiting command mode ..."); + DEBUG_PRINTLN(F("Exiting command mode ...")); if(!_mod->ATsendCommand("ATCN")) { return(ERR_AT_FAILED); } @@ -212,13 +212,13 @@ void XBeeSerial::reset() { int16_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow) { // enter command mode - DEBUG_PRINTLN_STR("Entering command mode ..."); + DEBUG_PRINTLN(F("Entering command mode ...")); if(!enterCmdMode()) { return(ERR_CMD_MODE_FAILED); } // set higher address bytes - DEBUG_PRINTLN_STR("Setting address (high) ..."); + DEBUG_PRINTLN(F("Setting address (high) ...")); char* addressHigh = new char[strlen(destinationAddressHigh) + 4]; strcpy(addressHigh, "ATDH"); strcat(addressHigh, destinationAddressHigh); @@ -229,7 +229,7 @@ int16_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, co } // set lower address bytes - DEBUG_PRINTLN_STR("Setting address (low) ..."); + DEBUG_PRINTLN(F("Setting address (low) ...")); char* addressLow = new char[strlen(destinationAddressLow) + 4]; strcpy(addressLow, "ATDL"); strcat(addressLow, destinationAddressLow); @@ -240,7 +240,7 @@ int16_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, co } // exit command mode - DEBUG_PRINTLN_STR("Exiting command mode ..."); + DEBUG_PRINTLN(F("Exiting command mode ...")); if(!_mod->ATsendCommand("ATCN")) { return(ERR_AT_FAILED); } @@ -250,13 +250,13 @@ int16_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, co int16_t XBeeSerial::setPanId(const char* panId) { // enter command mode - DEBUG_PRINTLN_STR("Entering command mode ..."); + DEBUG_PRINTLN(F("Entering command mode ...")); if(!enterCmdMode()) { return(ERR_CMD_MODE_FAILED); } // set PAN ID - DEBUG_PRINTLN_STR("Setting PAN ID ..."); + DEBUG_PRINTLN(F("Setting PAN ID ...")); char* cmd = new char[strlen(panId) + 4]; strcpy(cmd, "ATID"); strcat(cmd, panId); @@ -267,7 +267,7 @@ int16_t XBeeSerial::setPanId(const char* panId) { } // exit command mode - DEBUG_PRINTLN_STR("Exiting command mode ..."); + DEBUG_PRINTLN(F("Exiting command mode ...")); if(!_mod->ATsendCommand("ATCN")) { return(ERR_AT_FAILED); } @@ -288,9 +288,9 @@ bool XBeeSerial::enterCmdMode() { if(_mod->ATgetResponse()) { return(true); } else { - DEBUG_PRINT_STR("Unable to enter command mode! ("); + DEBUG_PRINT(F("Unable to enter command mode! (")); DEBUG_PRINT(i + 1); - DEBUG_PRINTLN_STR(" of 10 tries)"); + DEBUG_PRINTLN(F(" of 10 tries)")); reset(); @@ -298,7 +298,7 @@ bool XBeeSerial::enterCmdMode() { } } - DEBUG_PRINTLN_STR("Terminated, check your wiring. Is AT FW uploaded?"); + DEBUG_PRINTLN(F("Terminated, check your wiring. Is AT FW uploaded?")); return(false); } @@ -377,7 +377,7 @@ int16_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout) { return(ERR_FRAME_MALFORMED); } } - DEBUG_PRINT_STR("frame data field length: "); + DEBUG_PRINT(F("frame data field length: ")); DEBUG_PRINTLN(numBytes); // read the response @@ -389,21 +389,21 @@ int16_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout) { // verify checksum uint8_t checksum = 0; for(uint16_t i = 0; i < numBytes; i++) { - DEBUG_PRINT_HEX(resp[i]); - DEBUG_PRINT_STR("\t"); + DEBUG_PRINT(resp[i], HEX); + DEBUG_PRINT('\t'); checksum += resp[i]; } DEBUG_PRINTLN(); if(checksum != 0xFF) { - DEBUG_PRINTLN_HEX(checksum); + DEBUG_PRINTLN(checksum, HEX); return(ERR_FRAME_INCORRECT_CHECKSUM); } // check frame ID if(resp[1] != frameID) { - DEBUG_PRINT_STR("received frame ID: "); + DEBUG_PRINT(F("received frame ID: ")); DEBUG_PRINTLN(resp[1]); - DEBUG_PRINT_STR("expected frame ID: "); + DEBUG_PRINT(F("expected frame ID: ")); DEBUG_PRINTLN(frameID); return(ERR_FRAME_UNEXPECTED_ID); } @@ -426,11 +426,11 @@ uint16_t XBee::getNumBytes(uint32_t timeout, size_t minBytes) { // read response uint8_t resp[3]; uint8_t i = 0; - DEBUG_PRINT_STR("reading frame length: "); + DEBUG_PRINT(F("reading frame length: ")); while(_mod->ModuleSerial->available() > 0) { uint8_t b = _mod->ModuleSerial->read(); - DEBUG_PRINT_HEX(b); - DEBUG_PRINT_STR("\t"); + DEBUG_PRINT(b, HEX); + DEBUG_PRINT('\t'); resp[i++] = b; if(i == 3) { break;