Skip to content

Commit

Permalink
Updated debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Apr 19, 2018
1 parent 2d9f4a3 commit b32130d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 95 deletions.
16 changes: 4 additions & 12 deletions src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 16 additions & 0 deletions src/TypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 4 additions & 11 deletions src/modules/RF69.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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
Expand Down
19 changes: 5 additions & 14 deletions src/modules/SX1272.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down
23 changes: 6 additions & 17 deletions src/modules/SX1278.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down
55 changes: 14 additions & 41 deletions src/modules/XBee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -57,37 +51,29 @@ 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)) {
return(ERR_AT_FAILED);
}

// 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)) {
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);
}
Expand All @@ -97,27 +83,21 @@ 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)) {
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);
}
Expand All @@ -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);
Expand All @@ -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);
}
}
Expand Down

0 comments on commit b32130d

Please sign in to comment.