Updated debug macros
This commit is contained in:
parent
c4d9fe3a37
commit
c093d34c91
13 changed files with 207 additions and 196 deletions
|
@ -120,20 +120,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();
|
||||||
DEBUG_PRINT(c);
|
RADIOLIB_VERBOSE_PRINT(c);
|
||||||
data += c;
|
data += c;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data.indexOf("OK") != -1) {
|
if(data.indexOf("OK") != -1) {
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_VERBOSE_PRINTLN();
|
||||||
return(true);
|
return(true);
|
||||||
} else if (data.indexOf("ERROR") != -1) {
|
} else if (data.indexOf("ERROR") != -1) {
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_VERBOSE_PRINTLN();
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_VERBOSE_PRINTLN();
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,24 +170,24 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t
|
||||||
}
|
}
|
||||||
|
|
||||||
// check failed, print debug info
|
// check failed, print debug info
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_DEBUG_PRINTLN();
|
||||||
DEBUG_PRINT(F("address:\t0x"));
|
RADIOLIB_DEBUG_PRINT(F("address:\t0x"));
|
||||||
DEBUG_PRINTLN(reg, HEX);
|
RADIOLIB_DEBUG_PRINTLN(reg, HEX);
|
||||||
DEBUG_PRINT(F("bits:\t\t"));
|
RADIOLIB_DEBUG_PRINT(F("bits:\t\t"));
|
||||||
DEBUG_PRINT(msb);
|
RADIOLIB_DEBUG_PRINT(msb);
|
||||||
DEBUG_PRINT(' ');
|
RADIOLIB_DEBUG_PRINT(' ');
|
||||||
DEBUG_PRINTLN(lsb);
|
RADIOLIB_DEBUG_PRINTLN(lsb);
|
||||||
DEBUG_PRINT(F("value:\t\t0b"));
|
RADIOLIB_DEBUG_PRINT(F("value:\t\t0b"));
|
||||||
DEBUG_PRINTLN(value, BIN);
|
RADIOLIB_DEBUG_PRINTLN(value, BIN);
|
||||||
DEBUG_PRINT(F("current:\t0b"));
|
RADIOLIB_DEBUG_PRINT(F("current:\t0b"));
|
||||||
DEBUG_PRINTLN(currentValue, BIN);
|
RADIOLIB_DEBUG_PRINTLN(currentValue, BIN);
|
||||||
DEBUG_PRINT(F("mask:\t\t0b"));
|
RADIOLIB_DEBUG_PRINT(F("mask:\t\t0b"));
|
||||||
DEBUG_PRINTLN(mask, BIN);
|
RADIOLIB_DEBUG_PRINTLN(mask, BIN);
|
||||||
DEBUG_PRINT(F("new:\t\t0b"));
|
RADIOLIB_DEBUG_PRINT(F("new:\t\t0b"));
|
||||||
DEBUG_PRINTLN(newValue, BIN);
|
RADIOLIB_DEBUG_PRINTLN(newValue, BIN);
|
||||||
DEBUG_PRINT(F("read:\t\t0b"));
|
RADIOLIB_DEBUG_PRINT(F("read:\t\t0b"));
|
||||||
DEBUG_PRINTLN(readValue, BIN);
|
RADIOLIB_DEBUG_PRINTLN(readValue, BIN);
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_DEBUG_PRINTLN();
|
||||||
|
|
||||||
return(ERR_SPI_WRITE_FAILED);
|
return(ERR_SPI_WRITE_FAILED);
|
||||||
}
|
}
|
||||||
|
@ -219,30 +219,30 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da
|
||||||
|
|
||||||
// send SPI register address with access command
|
// send SPI register address with access command
|
||||||
_spi->transfer(reg | cmd);
|
_spi->transfer(reg | cmd);
|
||||||
DEBUG_PRINT(reg | cmd, HEX);
|
RADIOLIB_VERBOSE_PRINT(reg | cmd, HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
DEBUG_PRINT(reg | cmd, BIN);
|
RADIOLIB_VERBOSE_PRINT(reg | cmd, BIN);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
|
|
||||||
// send data or get response
|
// send data or get response
|
||||||
if(cmd == SPIwriteCommand) {
|
if(cmd == SPIwriteCommand) {
|
||||||
for(size_t n = 0; n < numBytes; n++) {
|
for(size_t n = 0; n < numBytes; n++) {
|
||||||
_spi->transfer(dataOut[n]);
|
_spi->transfer(dataOut[n]);
|
||||||
DEBUG_PRINT(dataOut[n], HEX);
|
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
DEBUG_PRINT(dataOut[n], BIN);
|
RADIOLIB_VERBOSE_PRINT(dataOut[n], BIN);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
}
|
}
|
||||||
} else if (cmd == SPIreadCommand) {
|
} else if (cmd == SPIreadCommand) {
|
||||||
for(size_t n = 0; n < numBytes; n++) {
|
for(size_t n = 0; n < numBytes; n++) {
|
||||||
dataIn[n] = _spi->transfer(0x00);
|
dataIn[n] = _spi->transfer(0x00);
|
||||||
DEBUG_PRINT(dataIn[n], HEX);
|
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
DEBUG_PRINT(dataIn[n], BIN);
|
RADIOLIB_VERBOSE_PRINT(dataIn[n], BIN);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_VERBOSE_PRINTLN();
|
||||||
|
|
||||||
// release CS
|
// release CS
|
||||||
digitalWrite(_cs, HIGH);
|
digitalWrite(_cs, HIGH);
|
||||||
|
|
|
@ -7,14 +7,25 @@
|
||||||
#error "Unsupported Arduino version (< 1.0.0)"
|
#error "Unsupported Arduino version (< 1.0.0)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define RADIOLIB_DEBUG_PORT Serial
|
||||||
|
|
||||||
//#define RADIOLIB_DEBUG
|
//#define RADIOLIB_DEBUG
|
||||||
|
//#define RADIOLIB_VERBOSE
|
||||||
|
|
||||||
#ifdef RADIOLIB_DEBUG
|
#ifdef RADIOLIB_DEBUG
|
||||||
#define DEBUG_PRINT(...) { Serial.print(__VA_ARGS__); }
|
#define RADIOLIB_DEBUG_PRINT(...) { RADIOLIB_DEBUG_PORT.print(__VA_ARGS__); }
|
||||||
#define DEBUG_PRINTLN(...) { Serial.println(__VA_ARGS__); }
|
#define RADIOLIB_DEBUG_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); }
|
||||||
#else
|
#else
|
||||||
#define DEBUG_PRINT(...) {}
|
#define RADIOLIB_DEBUG_PRINT(...) {}
|
||||||
#define DEBUG_PRINTLN(...) {}
|
#define RADIOLIB_DEBUG_PRINTLN(...) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RADIOLIB_VERBOSE
|
||||||
|
#define RADIOLIB_VERBOSE_PRINT(...) { RADIOLIB_DEBUG_PORT.print(__VA_ARGS__); }
|
||||||
|
#define RADIOLIB_VERBOSE_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); }
|
||||||
|
#else
|
||||||
|
#define RADIOLIB_VERBOSE_PRINT(...) {}
|
||||||
|
#define RADIOLIB_VERBOSE_PRINTLN(...) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -36,11 +36,11 @@ int16_t CC1101::begin(float freq, float br, float rxBw, float freqDev, int8_t po
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!flagFound) {
|
if(!flagFound) {
|
||||||
DEBUG_PRINTLN(F("No CC1101 found!"));
|
RADIOLIB_DEBUG_PRINTLN(F("No CC1101 found!"));
|
||||||
SPI.end();
|
SPI.end();
|
||||||
return(ERR_CHIP_NOT_FOUND);
|
return(ERR_CHIP_NOT_FOUND);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTLN(F("Found CC1101! (match by CC1101_REG_VERSION == 0x14)"));
|
RADIOLIB_DEBUG_PRINTLN(F("Found CC1101! (match by CC1101_REG_VERSION == 0x14)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure settings not accessible by API
|
// configure settings not accessible by API
|
||||||
|
|
|
@ -173,7 +173,7 @@ size_t ESP8266::receive(uint8_t* data, size_t len, uint32_t timeout) {
|
||||||
while((millis() - start < timeout) && (i < len)) {
|
while((millis() - start < timeout) && (i < len)) {
|
||||||
while(_mod->ModuleSerial->available() > 0) {
|
while(_mod->ModuleSerial->available() > 0) {
|
||||||
uint8_t b = _mod->ModuleSerial->read();
|
uint8_t b = _mod->ModuleSerial->read();
|
||||||
DEBUG_PRINT(b);
|
RADIOLIB_DEBUG_PRINT(b);
|
||||||
data[i] = b;
|
data[i] = b;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,11 @@ int16_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t powe
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!flagFound) {
|
if(!flagFound) {
|
||||||
DEBUG_PRINTLN(F("No RF69 found!"));
|
RADIOLIB_DEBUG_PRINTLN(F("No RF69 found!"));
|
||||||
SPI.end();
|
SPI.end();
|
||||||
return(ERR_CHIP_NOT_FOUND);
|
return(ERR_CHIP_NOT_FOUND);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTLN(F("Found RF69! (match by RF69_REG_VERSION == 0x24)"));
|
RADIOLIB_DEBUG_PRINTLN(F("Found RF69! (match by RF69_REG_VERSION == 0x24)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure settings not accessible by API
|
// configure settings not accessible by API
|
||||||
|
|
|
@ -34,11 +34,11 @@ int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!flagFound) {
|
if(!flagFound) {
|
||||||
DEBUG_PRINTLN(F("No SX1231 found!"));
|
RADIOLIB_DEBUG_PRINTLN(F("No SX1231 found!"));
|
||||||
SPI.end();
|
SPI.end();
|
||||||
return(ERR_CHIP_NOT_FOUND);
|
return(ERR_CHIP_NOT_FOUND);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTLN(F("Found SX1231!"));
|
RADIOLIB_DEBUG_PRINTLN(F("Found SX1231!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure settings not accessible by API
|
// configure settings not accessible by API
|
||||||
|
|
|
@ -172,9 +172,9 @@ int16_t SX126x::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||||
return(ERR_UNKNOWN);
|
return(ERR_UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINT(F("Timeout in "));
|
RADIOLIB_DEBUG_PRINT(F("Timeout in "));
|
||||||
DEBUG_PRINT(timeout);
|
RADIOLIB_DEBUG_PRINT(timeout);
|
||||||
DEBUG_PRINTLN(F(" us"));
|
RADIOLIB_DEBUG_PRINTLN(F(" us"));
|
||||||
|
|
||||||
// start transmission
|
// start transmission
|
||||||
state = startTransmit(data, len, addr);
|
state = startTransmit(data, len, addr);
|
||||||
|
@ -236,9 +236,9 @@ int16_t SX126x::receive(uint8_t* data, size_t len) {
|
||||||
return(ERR_UNKNOWN);
|
return(ERR_UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINT(F("Timeout in "));
|
RADIOLIB_DEBUG_PRINT(F("Timeout in "));
|
||||||
DEBUG_PRINT(timeout);
|
RADIOLIB_DEBUG_PRINT(timeout);
|
||||||
DEBUG_PRINTLN(F(" us"));
|
RADIOLIB_DEBUG_PRINTLN(F(" us"));
|
||||||
|
|
||||||
// start reception
|
// start reception
|
||||||
uint32_t timeoutValue = (uint32_t)((float)timeout / 15.625);
|
uint32_t timeoutValue = (uint32_t)((float)timeout / 15.625);
|
||||||
|
@ -1107,9 +1107,9 @@ int16_t SX126x::setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t
|
||||||
// calculate symbol length and enable low data rate optimization, if needed
|
// calculate symbol length and enable low data rate optimization, if needed
|
||||||
if(ldro == 0xFF) {
|
if(ldro == 0xFF) {
|
||||||
float symbolLength = (float)(uint32_t(1) << _sf) / (float)_bwKhz;
|
float symbolLength = (float)(uint32_t(1) << _sf) / (float)_bwKhz;
|
||||||
DEBUG_PRINT("Symbol length: ");
|
RADIOLIB_DEBUG_PRINT("Symbol length: ");
|
||||||
DEBUG_PRINT(symbolLength);
|
RADIOLIB_DEBUG_PRINT(symbolLength);
|
||||||
DEBUG_PRINTLN(" ms");
|
RADIOLIB_DEBUG_PRINTLN(" ms");
|
||||||
if(symbolLength >= 16.0) {
|
if(symbolLength >= 16.0) {
|
||||||
_ldro = SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON;
|
_ldro = SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1277,8 +1277,8 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d
|
||||||
// send command byte(s)
|
// send command byte(s)
|
||||||
for(uint8_t n = 0; n < cmdLen; n++) {
|
for(uint8_t n = 0; n < cmdLen; n++) {
|
||||||
spi->transfer(cmd[n]);
|
spi->transfer(cmd[n]);
|
||||||
DEBUG_PRINT(cmd[n], HEX);
|
RADIOLIB_VERBOSE_PRINT(cmd[n], HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
}
|
}
|
||||||
|
|
||||||
// variable to save error during SPI transfer
|
// variable to save error during SPI transfer
|
||||||
|
@ -1289,10 +1289,10 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d
|
||||||
for(uint8_t n = 0; n < numBytes; n++) {
|
for(uint8_t n = 0; n < numBytes; n++) {
|
||||||
// send byte
|
// send byte
|
||||||
uint8_t in = spi->transfer(dataOut[n]);
|
uint8_t in = spi->transfer(dataOut[n]);
|
||||||
DEBUG_PRINT(dataOut[n], HEX);
|
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
DEBUG_PRINT(in, HEX);
|
RADIOLIB_VERBOSE_PRINT(in, HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
|
|
||||||
// check status
|
// check status
|
||||||
if(((in & 0b00001110) == SX126X_STATUS_CMD_TIMEOUT) ||
|
if(((in & 0b00001110) == SX126X_STATUS_CMD_TIMEOUT) ||
|
||||||
|
@ -1302,14 +1302,14 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d
|
||||||
status = in;
|
status = in;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_VERBOSE_PRINT();
|
||||||
} else {
|
} else {
|
||||||
// skip the first byte for read-type commands (status-only)
|
// skip the first byte for read-type commands (status-only)
|
||||||
uint8_t in = spi->transfer(SX126X_CMD_NOP);
|
uint8_t in = spi->transfer(SX126X_CMD_NOP);
|
||||||
DEBUG_PRINT(SX126X_CMD_NOP, HEX);
|
RADIOLIB_VERBOSE_PRINT(SX126X_CMD_NOP, HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
DEBUG_PRINT(in, HEX);
|
RADIOLIB_VERBOSE_PRINT(in, HEX);
|
||||||
DEBUG_PRINT('\t')
|
RADIOLIB_VERBOSE_PRINT('\t')
|
||||||
|
|
||||||
// check status
|
// check status
|
||||||
if(((in & 0b00001110) == SX126X_STATUS_CMD_TIMEOUT) ||
|
if(((in & 0b00001110) == SX126X_STATUS_CMD_TIMEOUT) ||
|
||||||
|
@ -1320,12 +1320,12 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d
|
||||||
}
|
}
|
||||||
for(uint8_t n = 0; n < numBytes; n++) {
|
for(uint8_t n = 0; n < numBytes; n++) {
|
||||||
dataIn[n] = spi->transfer(SX126X_CMD_NOP);
|
dataIn[n] = spi->transfer(SX126X_CMD_NOP);
|
||||||
DEBUG_PRINT(SX126X_CMD_NOP, HEX);
|
RADIOLIB_VERBOSE_PRINT(SX126X_CMD_NOP, HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
DEBUG_PRINT(dataIn[n], HEX);
|
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
}
|
}
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_VERBOSE_PRINT();
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop transfer
|
// stop transfer
|
||||||
|
|
|
@ -125,9 +125,9 @@ int16_t SX1272::setBandwidth(float bw) {
|
||||||
|
|
||||||
// calculate symbol length and set low data rate optimization, if needed
|
// calculate symbol length and set low data rate optimization, if needed
|
||||||
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
||||||
DEBUG_PRINT("Symbol length: ");
|
RADIOLIB_DEBUG_PRINT("Symbol length: ");
|
||||||
DEBUG_PRINT(symbolLength);
|
RADIOLIB_DEBUG_PRINT(symbolLength);
|
||||||
DEBUG_PRINTLN(" ms");
|
RADIOLIB_DEBUG_PRINTLN(" ms");
|
||||||
if(symbolLength >= 16.0) {
|
if(symbolLength >= 16.0) {
|
||||||
state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
|
state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -179,9 +179,9 @@ int16_t SX1272::setSpreadingFactor(uint8_t sf) {
|
||||||
|
|
||||||
// calculate symbol length and set low data rate optimization, if needed
|
// calculate symbol length and set low data rate optimization, if needed
|
||||||
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
||||||
DEBUG_PRINT("Symbol length: ");
|
RADIOLIB_DEBUG_PRINT("Symbol length: ");
|
||||||
DEBUG_PRINT(symbolLength);
|
RADIOLIB_DEBUG_PRINT(symbolLength);
|
||||||
DEBUG_PRINTLN(" ms");
|
RADIOLIB_DEBUG_PRINTLN(" ms");
|
||||||
if(symbolLength >= 16.0) {
|
if(symbolLength >= 16.0) {
|
||||||
state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
|
state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -195,9 +195,9 @@ int16_t SX1278::setBandwidth(float bw) {
|
||||||
|
|
||||||
// calculate symbol length and set low data rate optimization, if needed
|
// calculate symbol length and set low data rate optimization, if needed
|
||||||
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
||||||
DEBUG_PRINT("Symbol length: ");
|
RADIOLIB_DEBUG_PRINT("Symbol length: ");
|
||||||
DEBUG_PRINT(symbolLength);
|
RADIOLIB_DEBUG_PRINT(symbolLength);
|
||||||
DEBUG_PRINTLN(" ms");
|
RADIOLIB_DEBUG_PRINTLN(" ms");
|
||||||
if(symbolLength >= 16.0) {
|
if(symbolLength >= 16.0) {
|
||||||
state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
|
state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
|
||||||
} else {
|
} else {
|
||||||
|
@ -249,9 +249,9 @@ int16_t SX1278::setSpreadingFactor(uint8_t sf) {
|
||||||
|
|
||||||
// calculate symbol length and set low data rate optimization, if needed
|
// calculate symbol length and set low data rate optimization, if needed
|
||||||
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
||||||
DEBUG_PRINT("Symbol length: ");
|
RADIOLIB_DEBUG_PRINT("Symbol length: ");
|
||||||
DEBUG_PRINT(symbolLength);
|
RADIOLIB_DEBUG_PRINT(symbolLength);
|
||||||
DEBUG_PRINTLN(" ms");
|
RADIOLIB_DEBUG_PRINTLN(" ms");
|
||||||
if(symbolLength >= 16.0) {
|
if(symbolLength >= 16.0) {
|
||||||
state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
|
state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -11,11 +11,11 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi
|
||||||
|
|
||||||
// try to find the SX127x chip
|
// try to find the SX127x chip
|
||||||
if(!SX127x::findChip(chipVersion)) {
|
if(!SX127x::findChip(chipVersion)) {
|
||||||
DEBUG_PRINTLN(F("No SX127x found!"));
|
RADIOLIB_DEBUG_PRINTLN(F("No SX127x found!"));
|
||||||
_mod->term();
|
_mod->term();
|
||||||
return(ERR_CHIP_NOT_FOUND);
|
return(ERR_CHIP_NOT_FOUND);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTLN(F("Found SX127x!"));
|
RADIOLIB_DEBUG_PRINTLN(F("Found SX127x!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check active modem
|
// check active modem
|
||||||
|
@ -55,11 +55,11 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB
|
||||||
|
|
||||||
// try to find the SX127x chip
|
// try to find the SX127x chip
|
||||||
if(!SX127x::findChip(chipVersion)) {
|
if(!SX127x::findChip(chipVersion)) {
|
||||||
DEBUG_PRINTLN(F("No SX127x found!"));
|
RADIOLIB_DEBUG_PRINTLN(F("No SX127x found!"));
|
||||||
_mod->term();
|
_mod->term();
|
||||||
return(ERR_CHIP_NOT_FOUND);
|
return(ERR_CHIP_NOT_FOUND);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTLN(F("Found SX127x!"));
|
RADIOLIB_DEBUG_PRINTLN(F("Found SX127x!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check currently active modem
|
// check currently active modem
|
||||||
|
|
|
@ -30,11 +30,11 @@ int16_t XBee::begin(long speed) {
|
||||||
if(state == ERR_NONE) {
|
if(state == ERR_NONE) {
|
||||||
flagFound = true;
|
flagFound = true;
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINT(F("XBee not found! ("));
|
RADIOLIB_DEBUG_PRINT(F("XBee not found! ("));
|
||||||
DEBUG_PRINT(i + 1);
|
RADIOLIB_DEBUG_PRINT(i + 1);
|
||||||
DEBUG_PRINT(F(" of 10 tries) STATE == "));
|
RADIOLIB_DEBUG_PRINT(F(" of 10 tries) STATE == "));
|
||||||
DEBUG_PRINTLN(state);
|
RADIOLIB_DEBUG_PRINTLN(state);
|
||||||
DEBUG_PRINTLN(F("Resetting ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Resetting ..."));
|
||||||
reset();
|
reset();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
_mod->ATemptyBuffer();
|
_mod->ATemptyBuffer();
|
||||||
|
@ -43,10 +43,10 @@ int16_t XBee::begin(long speed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!flagFound) {
|
if(!flagFound) {
|
||||||
DEBUG_PRINTLN(F("No XBee found!"));
|
RADIOLIB_DEBUG_PRINTLN(F("No XBee found!"));
|
||||||
return(ERR_CMD_MODE_FAILED);
|
return(ERR_CMD_MODE_FAILED);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTLN(F("Found XBee!"));
|
RADIOLIB_DEBUG_PRINTLN(F("Found XBee!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return(ERR_NONE);
|
return(ERR_NONE);
|
||||||
|
@ -182,19 +182,19 @@ int16_t XBeeSerial::begin(long speed) {
|
||||||
_mod->ATemptyBuffer();
|
_mod->ATemptyBuffer();
|
||||||
|
|
||||||
// enter command mode
|
// enter command mode
|
||||||
DEBUG_PRINTLN(F("Entering command mode ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Entering command mode ..."));
|
||||||
if(!enterCmdMode()) {
|
if(!enterCmdMode()) {
|
||||||
return(ERR_CMD_MODE_FAILED);
|
return(ERR_CMD_MODE_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test AT setup
|
// test AT setup
|
||||||
DEBUG_PRINTLN(F("Sending test command ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Sending test command ..."));
|
||||||
if(!_mod->ATsendCommand("AT")) {
|
if(!_mod->ATsendCommand("AT")) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// exit command mode
|
// exit command mode
|
||||||
DEBUG_PRINTLN(F("Exiting command mode ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Exiting command mode ..."));
|
||||||
if(!_mod->ATsendCommand("ATCN")) {
|
if(!_mod->ATsendCommand("ATCN")) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
|
@ -212,13 +212,13 @@ void XBeeSerial::reset() {
|
||||||
|
|
||||||
int16_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow) {
|
int16_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow) {
|
||||||
// enter command mode
|
// enter command mode
|
||||||
DEBUG_PRINTLN(F("Entering command mode ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Entering command mode ..."));
|
||||||
if(!enterCmdMode()) {
|
if(!enterCmdMode()) {
|
||||||
return(ERR_CMD_MODE_FAILED);
|
return(ERR_CMD_MODE_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set higher address bytes
|
// set higher address bytes
|
||||||
DEBUG_PRINTLN(F("Setting address (high) ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Setting address (high) ..."));
|
||||||
char* addressHigh = new char[strlen(destinationAddressHigh) + 4];
|
char* addressHigh = new char[strlen(destinationAddressHigh) + 4];
|
||||||
strcpy(addressHigh, "ATDH");
|
strcpy(addressHigh, "ATDH");
|
||||||
strcat(addressHigh, destinationAddressHigh);
|
strcat(addressHigh, destinationAddressHigh);
|
||||||
|
@ -229,7 +229,7 @@ int16_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, co
|
||||||
}
|
}
|
||||||
|
|
||||||
// set lower address bytes
|
// set lower address bytes
|
||||||
DEBUG_PRINTLN(F("Setting address (low) ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Setting address (low) ..."));
|
||||||
char* addressLow = new char[strlen(destinationAddressLow) + 4];
|
char* addressLow = new char[strlen(destinationAddressLow) + 4];
|
||||||
strcpy(addressLow, "ATDL");
|
strcpy(addressLow, "ATDL");
|
||||||
strcat(addressLow, destinationAddressLow);
|
strcat(addressLow, destinationAddressLow);
|
||||||
|
@ -240,7 +240,7 @@ int16_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, co
|
||||||
}
|
}
|
||||||
|
|
||||||
// exit command mode
|
// exit command mode
|
||||||
DEBUG_PRINTLN(F("Exiting command mode ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Exiting command mode ..."));
|
||||||
if(!_mod->ATsendCommand("ATCN")) {
|
if(!_mod->ATsendCommand("ATCN")) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
|
@ -250,13 +250,13 @@ int16_t XBeeSerial::setDestinationAddress(const char* destinationAddressHigh, co
|
||||||
|
|
||||||
int16_t XBeeSerial::setPanId(const char* panId) {
|
int16_t XBeeSerial::setPanId(const char* panId) {
|
||||||
// enter command mode
|
// enter command mode
|
||||||
DEBUG_PRINTLN(F("Entering command mode ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Entering command mode ..."));
|
||||||
if(!enterCmdMode()) {
|
if(!enterCmdMode()) {
|
||||||
return(ERR_CMD_MODE_FAILED);
|
return(ERR_CMD_MODE_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set PAN ID
|
// set PAN ID
|
||||||
DEBUG_PRINTLN(F("Setting PAN ID ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Setting PAN ID ..."));
|
||||||
char* cmd = new char[strlen(panId) + 4];
|
char* cmd = new char[strlen(panId) + 4];
|
||||||
strcpy(cmd, "ATID");
|
strcpy(cmd, "ATID");
|
||||||
strcat(cmd, panId);
|
strcat(cmd, panId);
|
||||||
|
@ -267,7 +267,7 @@ int16_t XBeeSerial::setPanId(const char* panId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// exit command mode
|
// exit command mode
|
||||||
DEBUG_PRINTLN(F("Exiting command mode ..."));
|
RADIOLIB_DEBUG_PRINTLN(F("Exiting command mode ..."));
|
||||||
if(!_mod->ATsendCommand("ATCN")) {
|
if(!_mod->ATsendCommand("ATCN")) {
|
||||||
return(ERR_AT_FAILED);
|
return(ERR_AT_FAILED);
|
||||||
}
|
}
|
||||||
|
@ -288,9 +288,9 @@ bool XBeeSerial::enterCmdMode() {
|
||||||
if(_mod->ATgetResponse()) {
|
if(_mod->ATgetResponse()) {
|
||||||
return(true);
|
return(true);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINT(F("Unable to enter command mode! ("));
|
RADIOLIB_DEBUG_PRINT(F("Unable to enter command mode! ("));
|
||||||
DEBUG_PRINT(i + 1);
|
RADIOLIB_DEBUG_PRINT(i + 1);
|
||||||
DEBUG_PRINTLN(F(" of 10 tries)"));
|
RADIOLIB_DEBUG_PRINTLN(F(" of 10 tries)"));
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ bool XBeeSerial::enterCmdMode() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINTLN(F("Terminated, check your wiring. Is AT FW uploaded?"));
|
RADIOLIB_DEBUG_PRINTLN(F("Terminated, check your wiring. Is AT FW uploaded?"));
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,8 +377,8 @@ int16_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout) {
|
||||||
return(ERR_FRAME_MALFORMED);
|
return(ERR_FRAME_MALFORMED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DEBUG_PRINT(F("frame data field length: "));
|
RADIOLIB_DEBUG_PRINT(F("frame data field length: "));
|
||||||
DEBUG_PRINTLN(numBytes);
|
RADIOLIB_DEBUG_PRINTLN(numBytes);
|
||||||
|
|
||||||
// read the response
|
// read the response
|
||||||
uint8_t* resp = new uint8_t[numBytes];
|
uint8_t* resp = new uint8_t[numBytes];
|
||||||
|
@ -389,22 +389,22 @@ int16_t XBee::readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout) {
|
||||||
// verify checksum
|
// verify checksum
|
||||||
uint8_t checksum = 0;
|
uint8_t checksum = 0;
|
||||||
for(uint16_t i = 0; i < numBytes; i++) {
|
for(uint16_t i = 0; i < numBytes; i++) {
|
||||||
DEBUG_PRINT(resp[i], HEX);
|
RADIOLIB_DEBUG_PRINT(resp[i], HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_DEBUG_PRINT('\t');
|
||||||
checksum += resp[i];
|
checksum += resp[i];
|
||||||
}
|
}
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_DEBUG_PRINTLN();
|
||||||
if(checksum != 0xFF) {
|
if(checksum != 0xFF) {
|
||||||
DEBUG_PRINTLN(checksum, HEX);
|
RADIOLIB_DEBUG_PRINTLN(checksum, HEX);
|
||||||
return(ERR_FRAME_INCORRECT_CHECKSUM);
|
return(ERR_FRAME_INCORRECT_CHECKSUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check frame ID
|
// check frame ID
|
||||||
if(resp[1] != frameID) {
|
if(resp[1] != frameID) {
|
||||||
DEBUG_PRINT(F("received frame ID: "));
|
RADIOLIB_DEBUG_PRINT(F("received frame ID: "));
|
||||||
DEBUG_PRINTLN(resp[1]);
|
RADIOLIB_DEBUG_PRINTLN(resp[1]);
|
||||||
DEBUG_PRINT(F("expected frame ID: "));
|
RADIOLIB_DEBUG_PRINT(F("expected frame ID: "));
|
||||||
DEBUG_PRINTLN(frameID);
|
RADIOLIB_DEBUG_PRINTLN(frameID);
|
||||||
return(ERR_FRAME_UNEXPECTED_ID);
|
return(ERR_FRAME_UNEXPECTED_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,17 +426,17 @@ uint16_t XBee::getNumBytes(uint32_t timeout, size_t minBytes) {
|
||||||
// read response
|
// read response
|
||||||
uint8_t resp[3];
|
uint8_t resp[3];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
DEBUG_PRINT(F("reading frame length: "));
|
RADIOLIB_DEBUG_PRINT(F("reading frame length: "));
|
||||||
while(_mod->ModuleSerial->available() > 0) {
|
while(_mod->ModuleSerial->available() > 0) {
|
||||||
uint8_t b = _mod->ModuleSerial->read();
|
uint8_t b = _mod->ModuleSerial->read();
|
||||||
DEBUG_PRINT(b, HEX);
|
RADIOLIB_DEBUG_PRINT(b, HEX);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_DEBUG_PRINT('\t');
|
||||||
resp[i++] = b;
|
resp[i++] = b;
|
||||||
if(i == 3) {
|
if(i == 3) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_DEBUG_PRINTLN();
|
||||||
|
|
||||||
return((resp[1] << 8) | resp[2]);
|
return((resp[1] << 8) | resp[2]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW
|
||||||
// check SPI connection
|
// check SPI connection
|
||||||
int16_t val = _mod->SPIgetRegValue(NRF24_REG_SETUP_AW);
|
int16_t val = _mod->SPIgetRegValue(NRF24_REG_SETUP_AW);
|
||||||
if(!((val >= 1) && (val <= 3))) {
|
if(!((val >= 1) && (val <= 3))) {
|
||||||
DEBUG_PRINTLN(F("No nRF24 found!"));
|
RADIOLIB_DEBUG_PRINTLN(F("No nRF24 found!"));
|
||||||
_mod->term();
|
_mod->term();
|
||||||
return(ERR_CHIP_NOT_FOUND);
|
return(ERR_CHIP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,9 +119,9 @@ size_t MorseClient::write(uint8_t b) {
|
||||||
|
|
||||||
// check if the requested code was found in the array
|
// check if the requested code was found in the array
|
||||||
if(found) {
|
if(found) {
|
||||||
DEBUG_PRINT(mc.c);
|
RADIOLIB_DEBUG_PRINT(mc.c);
|
||||||
DEBUG_PRINT('\t');
|
RADIOLIB_DEBUG_PRINT('\t');
|
||||||
DEBUG_PRINTLN(mc.m);
|
RADIOLIB_DEBUG_PRINTLN(mc.m);
|
||||||
|
|
||||||
// iterate over Morse code representation and output appropriate tones
|
// iterate over Morse code representation and output appropriate tones
|
||||||
for(uint8_t i = 0; i < strlen(mc.m); i++) {
|
for(uint8_t i = 0; i < strlen(mc.m); i++) {
|
||||||
|
@ -145,7 +145,7 @@ size_t MorseClient::write(uint8_t b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// letter space
|
// letter space
|
||||||
DEBUG_PRINTLN();
|
RADIOLIB_DEBUG_PRINTLN();
|
||||||
delay(_dotLength * 3);
|
delay(_dotLength * 3);
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue