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(ModuleSerial->available() > 0) {
char c = ModuleSerial->read();
#ifdef DEBUG
Serial.print(c);
#endif
DEBUG_PRINT(c);
data += c;
}
if(data.indexOf("OK") != -1) {
#ifdef DEBUG
Serial.println();
#endif
DEBUG_PRINTLN();
return(true);
} else if (data.indexOf("ERROR") != -1) {
#ifdef DEBUG
Serial.println();
#endif
DEBUG_PRINTLN();
return(false);
}
}
#ifdef DEBUG
Serial.println();
#endif
DEBUG_PRINTLN();
return(false);
}

View file

@ -9,6 +9,22 @@
//#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
#define USE_SPI 0x00
#define USE_UART 0x01

View file

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

View file

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