Updated debug output

This commit is contained in:
Jan Gromeš 2018-04-19 18:50:42 +02:00
parent 2d9f4a3f46
commit b32130d18c
6 changed files with 49 additions and 95 deletions

View file

@ -78,28 +78,20 @@ bool Module::ATgetResponse() {
while (millis() - start < _ATtimeout) { while (millis() - start < _ATtimeout) {
while(ModuleSerial->available() > 0) { while(ModuleSerial->available() > 0) {
char c = ModuleSerial->read(); char c = ModuleSerial->read();
#ifdef DEBUG DEBUG_PRINT(c);
Serial.print(c);
#endif
data += c; data += c;
} }
if(data.indexOf("OK") != -1) { if(data.indexOf("OK") != -1) {
#ifdef DEBUG DEBUG_PRINTLN();
Serial.println();
#endif
return(true); return(true);
} else if (data.indexOf("ERROR") != -1) { } else if (data.indexOf("ERROR") != -1) {
#ifdef DEBUG DEBUG_PRINTLN();
Serial.println();
#endif
return(false); return(false);
} }
} }
#ifdef DEBUG DEBUG_PRINTLN();
Serial.println();
#endif
return(false); return(false);
} }

View file

@ -9,6 +9,22 @@
//#define DEBUG //#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(x) Serial.print (x)
#define DEBUG_PRINT_DEC(x) Serial.print (x, DEC)
#define DEBUG_PRINT_HEX(x) Serial.print (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))
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINT_DEC(x)
#define DEBUG_PRINT_HEX(x)
#define DEBUG_PRINTLN(x)
#define DEBUG_PRINT_STR(x)
#define DEBUG_PRINTLN_STR(x)
#endif
// Shield configuration // Shield configuration
#define USE_SPI 0x00 #define USE_SPI 0x00
#define USE_UART 0x01 #define USE_UART 0x01

View file

@ -32,17 +32,12 @@ uint8_t RF69::begin() {
} }
if(!flagFound) { if(!flagFound) {
#ifdef DEBUG DEBUG_PRINTLN_STR("No RF69 found!");
Serial.println("No RF69 found!");
#endif
SPI.end(); SPI.end();
return(ERR_CHIP_NOT_FOUND); return(ERR_CHIP_NOT_FOUND);
} else {
DEBUG_PRINTLN_STR("Found RF69! (match by RF69_REG_VERSION == 0x12)");
} }
#ifdef DEBUG
else {
Serial.println("Found RF69! (match by RF69_REG_VERSION == 0x12)");
}
#endif
return(config()); return(config());
} }
@ -86,9 +81,7 @@ uint8_t RF69::transmit(Packet& pack) {
// wait for transmission end // wait for transmission end
while(!_mod->getInt0State()) { while(!_mod->getInt0State()) {
#ifdef DEBUG DEBUG_PRINT('.');
Serial.print('.');
#endif
} }
// clear interrupt flags // clear interrupt flags

View file

@ -13,9 +13,7 @@ uint8_t SX1272::begin(Bandwidth bw, SpreadingFactor sf, CodingRate cr, uint16_t
// ESP32-only: initialize EEPROM // ESP32-only: initialize EEPROM
#ifdef ESP32 #ifdef ESP32
if(!EEPROM.begin(9)) { if(!EEPROM.begin(9)) {
#ifdef DEBUG DEBUG_PRINTLN_STR("Unable to initialize EEPROM");
Serial.println("Unable to initialize EEPROM");
#endif
return(ERR_EEPROM_NOT_INITIALIZED); return(ERR_EEPROM_NOT_INITIALIZED);
} }
#endif #endif
@ -80,17 +78,12 @@ uint8_t SX1272::begin(Bandwidth bw, SpreadingFactor sf, CodingRate cr, uint16_t
} }
if(!flagFound) { if(!flagFound) {
#ifdef DEBUG DEBUG_PRINTLN_STR("No SX1272 found!");
Serial.println("No SX1272 found!");
#endif
SPI.end(); SPI.end();
return(ERR_CHIP_NOT_FOUND); return(ERR_CHIP_NOT_FOUND);
} else {
DEBUG_PRINTLN_STR("Found SX1272! (match by SX1272_REG_VERSION == 0x12)");
} }
#ifdef DEBUG
else {
Serial.println("Found SX1272! (match by SX1272_REG_VERSION == 0x12)");
}
#endif
// configure LoRa modem // configure LoRa modem
return(config(_bw, _sf, _cr)); return(config(_bw, _sf, _cr));
@ -137,9 +130,7 @@ uint8_t SX1272::transmit(Packet& pack) {
// wait for transmission end // wait for transmission end
unsigned long start = millis(); unsigned long start = millis();
while(!_mod->getInt0State()) { while(!_mod->getInt0State()) {
#ifdef DEBUG DEBUG_PRINT('.');
Serial.print('.');
#endif
} }
// clear interrupt flags // clear interrupt flags

View file

@ -13,9 +13,7 @@ uint8_t SX1278::begin(Bandwidth bw, SpreadingFactor sf, CodingRate cr, uint16_t
// ESP32-only: initialize EEPROM // ESP32-only: initialize EEPROM
#ifdef ESP32 #ifdef ESP32
if(!EEPROM.begin(9)) { if(!EEPROM.begin(9)) {
#ifdef DEBUG DEBUG_PRINTLN_STR("Unable to initialize EEPROM");
Serial.println("Unable to initialize EEPROM");
#endif
return(ERR_EEPROM_NOT_INITIALIZED); return(ERR_EEPROM_NOT_INITIALIZED);
} }
#endif #endif
@ -38,9 +36,7 @@ uint8_t SX1278::begin(Bandwidth bw, SpreadingFactor sf, CodingRate cr, uint16_t
generateLoRaAdress(); generateLoRaAdress();
} }
#ifdef DEBUG DEBUG_PRINTLN_STR("LoRa node address string: ");
Serial.print("LoRa node address string: ");
#endif
for(uint8_t i = 0; i < 8; i++) { for(uint8_t i = 0; i < 8; i++) {
_address[i] = EEPROM.read(i); _address[i] = EEPROM.read(i);
#ifdef DEBUG #ifdef DEBUG
@ -80,17 +76,12 @@ uint8_t SX1278::begin(Bandwidth bw, SpreadingFactor sf, CodingRate cr, uint16_t
} }
if(!flagFound) { if(!flagFound) {
#ifdef DEBUG DEBUG_PRINTLN_STR("No SX1278 found!");
Serial.println("No SX1278 found!");
#endif
SPI.end(); SPI.end();
return(ERR_CHIP_NOT_FOUND); return(ERR_CHIP_NOT_FOUND);
} else {
DEBUG_PRINTLN_STR("Found SX1278! (match by SX1278_REG_VERSION == 0x12)");
} }
#ifdef DEBUG
else {
Serial.println("Found SX1278! (match by SX1278_REG_VERSION == 0x12)");
}
#endif
// configure LoRa modem // configure LoRa modem
return(config(_bw, _sf, _cr)); return(config(_bw, _sf, _cr));
@ -136,9 +127,7 @@ uint8_t SX1278::transmit(Packet& pack) {
// wait for transmission end // wait for transmission end
unsigned long start = millis(); unsigned long start = millis();
while(!_mod->getInt0State()) { while(!_mod->getInt0State()) {
#ifdef DEBUG DEBUG_PRINT('.');
Serial.print('.');
#endif
} }
// clear interrupt flags // clear interrupt flags

View file

@ -27,25 +27,19 @@ uint8_t XBee::begin(long speed) {
_mod->ATemptyBuffer(); _mod->ATemptyBuffer();
// enter command mode // enter command mode
#ifdef DEBUG DEBUG_PRINTLN_STR("Entering command mode ...");
Serial.println("Entering command mode ...");
#endif
if(!enterCmdMode()) { if(!enterCmdMode()) {
return(ERR_CMD_MODE_FAILED); return(ERR_CMD_MODE_FAILED);
} }
// test AT setup // test AT setup
#ifdef DEBUG DEBUG_PRINTLN_STR("Sending test command ...");
Serial.println("Sending test command ...");
#endif
if(!_mod->ATsendCommand("AT")) { if(!_mod->ATsendCommand("AT")) {
return(ERR_AT_FAILED); return(ERR_AT_FAILED);
} }
// exit command mode // exit command mode
#ifdef DEBUG DEBUG_PRINTLN_STR("Exiting command mode ...");
Serial.println("Exiting command mode ...");
#endif
if(!_mod->ATsendCommand("ATCN")) { if(!_mod->ATsendCommand("ATCN")) {
return(ERR_AT_FAILED); return(ERR_AT_FAILED);
} }
@ -57,17 +51,13 @@ uint8_t XBee::begin(long speed) {
uint8_t XBee::setDestinationAddress(const char destinationAddressHigh[], const char destinationAddressLow[]) { uint8_t XBee::setDestinationAddress(const char destinationAddressHigh[], const char destinationAddressLow[]) {
// enter command mode // enter command mode
#ifdef DEBUG DEBUG_PRINTLN_STR("Entering command mode ...");
Serial.println("Entering command mode ...");
#endif
if(!enterCmdMode()) { if(!enterCmdMode()) {
return(ERR_CMD_MODE_FAILED); return(ERR_CMD_MODE_FAILED);
} }
// set higher address bytes // set higher address bytes
#ifdef DEBUG DEBUG_PRINTLN_STR("Setting address (high) ...");
Serial.println("Setting address (high) ...");
#endif
String addressHigh = "ATDH"; String addressHigh = "ATDH";
addressHigh += destinationAddressHigh; addressHigh += destinationAddressHigh;
if(!_mod->ATsendCommand(addressHigh)) { if(!_mod->ATsendCommand(addressHigh)) {
@ -75,9 +65,7 @@ uint8_t XBee::setDestinationAddress(const char destinationAddressHigh[], const c
} }
// set lower address bytes // set lower address bytes
#ifdef DEBUG DEBUG_PRINTLN_STR("Setting address (low) ...");
Serial.println("Setting address (low) ...");
#endif
String addressLow = "ATDL"; String addressLow = "ATDL";
addressLow += destinationAddressLow; addressLow += destinationAddressLow;
if(!_mod->ATsendCommand(addressLow)) { if(!_mod->ATsendCommand(addressLow)) {
@ -85,9 +73,7 @@ uint8_t XBee::setDestinationAddress(const char destinationAddressHigh[], const c
} }
// exit command mode // exit command mode
#ifdef DEBUG DEBUG_PRINTLN_STR("Exiting command mode ...");
Serial.println("Exiting command mode ...");
#endif
if(!_mod->ATsendCommand("ATCN")) { if(!_mod->ATsendCommand("ATCN")) {
return(ERR_AT_FAILED); return(ERR_AT_FAILED);
} }
@ -97,17 +83,13 @@ uint8_t XBee::setDestinationAddress(const char destinationAddressHigh[], const c
uint8_t XBee::setPanId(const char panId[]) { uint8_t XBee::setPanId(const char panId[]) {
// enter command mode // enter command mode
#ifdef DEBUG DEBUG_PRINTLN_STR("Entering command mode ...");
Serial.println("Entering command mode ...");
#endif
if(!enterCmdMode()) { if(!enterCmdMode()) {
return(ERR_CMD_MODE_FAILED); return(ERR_CMD_MODE_FAILED);
} }
// set PAN ID // set PAN ID
#ifdef DEBUG DEBUG_PRINTLN_STR("Setting PAN ID ...");
Serial.println("Setting PAN ID ...");
#endif
String panIdCmd = "ATID"; String panIdCmd = "ATID";
panIdCmd += panId; panIdCmd += panId;
if(!_mod->ATsendCommand(panIdCmd)) { if(!_mod->ATsendCommand(panIdCmd)) {
@ -115,9 +97,7 @@ uint8_t XBee::setPanId(const char panId[]) {
} }
// exit command mode // exit command mode
#ifdef DEBUG DEBUG_PRINTLN_STR("Exiting command mode ...");
Serial.println("Exiting command mode ...");
#endif
if(!_mod->ATsendCommand("ATCN")) { if(!_mod->ATsendCommand("ATCN")) {
return(ERR_AT_FAILED); return(ERR_AT_FAILED);
} }
@ -127,25 +107,20 @@ uint8_t XBee::setPanId(const char panId[]) {
bool XBee::enterCmdMode() { bool XBee::enterCmdMode() {
for(uint8_t i = 0; i < 10; i++) { for(uint8_t i = 0; i < 10; i++) {
//guard time silence
delay(1000); delay(1000);
//command sequence
_mod->ModuleSerial->write('+'); _mod->ModuleSerial->write('+');
_mod->ModuleSerial->write('+'); _mod->ModuleSerial->write('+');
_mod->ModuleSerial->write('+'); _mod->ModuleSerial->write('+');
//guard time silence
delay(1000); delay(1000);
if(_mod->ATgetResponse()) { if(_mod->ATgetResponse()) {
return(true); return(true);
} else { } else {
#ifdef DEBUG DEBUG_PRINT_STR("Unable to enter command mode! (");
Serial.print("Unable to enter command mode! ("); DEBUG_PRINT(i + 1);
Serial.print(i + 1); DEBUG_PRINTLN_STR(" of 10 tries)");
Serial.println(" of 10 tries)");
#endif
pinMode(3, OUTPUT); pinMode(3, OUTPUT);
delay(10); delay(10);
@ -159,9 +134,7 @@ bool XBee::enterCmdMode() {
_mod->ATsendCommand("ATCN"); _mod->ATsendCommand("ATCN");
if(i == 9) { if(i == 9) {
#ifdef DEBUG DEBUG_PRINTLN_STR("Terminated, check your wiring. Is AT FW uploaded?");
Serial.println("Terminated, check your wiring. Is AT FW uploaded?");
#endif
return(false); return(false);
} }
} }