Fixes from cppcheck scan

This commit is contained in:
jgromes 2020-07-04 13:43:39 +02:00
parent d066f616b1
commit 7e62dbd1d8
3 changed files with 35 additions and 27 deletions

View file

@ -15,7 +15,7 @@
*/
class ISerial {
public:
ISerial(Module* mod);
explicit ISerial(Module* mod);
void begin(long);
bool listen();

View file

@ -9,6 +9,7 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs
_spi = &RADIOLIB_DEFAULT_SPI;
_spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0);
_initInterface = true;
ModuleSerial = NULL;
}
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio) {
@ -20,9 +21,10 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs
_spi = &RADIOLIB_DEFAULT_SPI;
_spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0);
_initInterface = true;
ModuleSerial = NULL;
}
Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* useSer, RADIOLIB_PIN_TYPE rst) {
Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial, RADIOLIB_PIN_TYPE rst) {
_cs = RADIOLIB_NC;
_rx = rx;
_tx = tx;
@ -31,10 +33,10 @@ Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* useSe
_initInterface = true;
#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
ModuleSerial = useSer;
ModuleSerial = serial;
#else
ModuleSerial = new SoftwareSerial(_rx, _tx);
(void)useSer;
(void)serial;
#endif
}
@ -47,6 +49,7 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs
_spi = &spi;
_spiSettings = spiSettings;
_initInterface = false;
ModuleSerial = NULL;
}
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings) {
@ -58,9 +61,10 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs
_spi = &spi;
_spiSettings = spiSettings;
_initInterface = false;
ModuleSerial = NULL;
}
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* useSer) {
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* serial) {
_cs = cs;
_rx = rx;
_tx = tx;
@ -71,10 +75,10 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs
_initInterface = false;
#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
ModuleSerial = useSer;
ModuleSerial = serial;
#else
ModuleSerial = new SoftwareSerial(_rx, _tx);
(void)useSer;
(void)serial;
#endif
}
@ -259,16 +263,20 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da
// send data or get response
if(cmd == SPIwriteCommand) {
for(size_t n = 0; n < numBytes; n++) {
_spi->transfer(dataOut[n]);
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
RADIOLIB_VERBOSE_PRINT('\t');
if(dataOut != NULL) {
for(size_t n = 0; n < numBytes; n++) {
_spi->transfer(dataOut[n]);
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
RADIOLIB_VERBOSE_PRINT('\t');
}
}
} else if (cmd == SPIreadCommand) {
for(size_t n = 0; n < numBytes; n++) {
dataIn[n] = _spi->transfer(0x00);
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
RADIOLIB_VERBOSE_PRINT('\t');
if(dataIn != NULL) {
for(size_t n = 0; n < numBytes; n++) {
dataIn[n] = _spi->transfer(0x00);
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
RADIOLIB_VERBOSE_PRINT('\t');
}
}
}
RADIOLIB_VERBOSE_PRINTLN();

View file

@ -21,18 +21,18 @@ class Module {
/*!
\brief UART-based module constructor.
\param tx Arduino pin to be used as Tx pin for SoftwareSerial communication.
\param rx Arduino pin to be used as Rx pin for SoftwareSerial communication.
\param tx Arduino pin to be used as Tx pin for SoftwareSerial communication.
\param serial HardwareSerial to be used on platforms that do not support SoftwareSerial. Defaults to Serial1.
\param rst Arduino pin to be used as hardware reset for the module. Defaults to NC (unused).
*/
#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
Module(RADIOLIB_PIN_TYPE tx, RADIOLIB_PIN_TYPE rx, HardwareSerial* serial = &RADIOLIB_HARDWARE_SERIAL_PORT, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC);
Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial = &RADIOLIB_HARDWARE_SERIAL_PORT, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC);
#else
Module(RADIOLIB_PIN_TYPE tx, RADIOLIB_PIN_TYPE rx, HardwareSerial* serial = nullptr, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC);
Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial = nullptr, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC);
#endif
/*!
@ -408,18 +408,18 @@ class Module {
#ifndef RADIOLIB_GODMODE
private:
#endif
RADIOLIB_PIN_TYPE _cs;
RADIOLIB_PIN_TYPE _tx;
RADIOLIB_PIN_TYPE _rx;
RADIOLIB_PIN_TYPE _irq;
RADIOLIB_PIN_TYPE _rst;
RADIOLIB_PIN_TYPE _cs = RADIOLIB_NC;
RADIOLIB_PIN_TYPE _tx = RADIOLIB_NC;
RADIOLIB_PIN_TYPE _rx = RADIOLIB_NC;
RADIOLIB_PIN_TYPE _irq = RADIOLIB_NC;
RADIOLIB_PIN_TYPE _rst = RADIOLIB_NC;
bool _initInterface;
SPIClass* _spi;
bool _initInterface = false;
SPIClass* _spi = NULL;
SPISettings _spiSettings;
bool _useRfSwitch = false;
RADIOLIB_PIN_TYPE _rxEn, _txEn;
RADIOLIB_PIN_TYPE _rxEn = RADIOLIB_NC, _txEn = RADIOLIB_NC;
uint32_t _ATtimeout = 15000;
};