[SX127x] Fixed issues found by cppcheck

This commit is contained in:
jgromes 2024-05-11 16:49:51 +01:00
parent dec7265f72
commit c641099e9f
8 changed files with 49 additions and 43 deletions

View file

@ -100,7 +100,7 @@ class SX1272: public SX127x {
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance. \brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip. \param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/ */
SX1272(Module* mod); SX1272(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods // basic methods
@ -146,7 +146,7 @@ class SX1272: public SX127x {
\param freq Carrier frequency to be set in MHz. \param freq Carrier frequency to be set in MHz.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setFrequency(float freq); int16_t setFrequency(float freq) override;
/*! /*!
\brief Sets %LoRa link bandwidth. Allowed values are 125, 250 and 500 kHz. Only available in %LoRa mode. \brief Sets %LoRa link bandwidth. Allowed values are 125, 250 and 500 kHz. Only available in %LoRa mode.
@ -254,7 +254,7 @@ class SX1272: public SX127x {
Overload with packet mode enabled for PhysicalLayer compatibility. Overload with packet mode enabled for PhysicalLayer compatibility.
\returns RSSI value in dBm. \returns RSSI value in dBm.
*/ */
float getRSSI(); float getRSSI() override;
/*! /*!
\brief Gets recorded signal strength indicator. \brief Gets recorded signal strength indicator.
@ -311,7 +311,7 @@ class SX1272: public SX127x {
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF); int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
int16_t configFSK(); int16_t configFSK();
void errataFix(bool rx); void errataFix(bool rx) override;
#if !RADIOLIB_GODMODE #if !RADIOLIB_GODMODE
private: private:

View file

@ -20,7 +20,7 @@ class SX1273: public SX1272 {
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance. \brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip. \param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/ */
SX1273(Module* mod); SX1273(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods // basic methods

View file

@ -20,7 +20,7 @@ class SX1276: public SX1278 {
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance. \brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip. \param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/ */
SX1276(Module* mod); SX1276(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods // basic methods
@ -61,7 +61,7 @@ class SX1276: public SX1278 {
\param freq Carrier frequency to be set in MHz. \param freq Carrier frequency to be set in MHz.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setFrequency(float freq); int16_t setFrequency(float freq) override;
#if !RADIOLIB_GODMODE #if !RADIOLIB_GODMODE
private: private:

View file

@ -20,7 +20,7 @@ class SX1277: public SX1278 {
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance. \brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip. \param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/ */
SX1277(Module* mod); SX1277(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods // basic methods
@ -61,7 +61,7 @@ class SX1277: public SX1278 {
\param freq Carrier frequency to be set in MHz. \param freq Carrier frequency to be set in MHz.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setFrequency(float freq); int16_t setFrequency(float freq) override;
/*! /*!
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode. \brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode.

View file

@ -111,7 +111,7 @@ class SX1278: public SX127x {
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance. \brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip. \param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/ */
SX1278(Module* mod); SX1278(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods // basic methods
@ -157,7 +157,7 @@ class SX1278: public SX127x {
\param freq Carrier frequency to be set in MHz. \param freq Carrier frequency to be set in MHz.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setFrequency(float freq); int16_t setFrequency(float freq) override;
/*! /*!
\brief Sets %LoRa link bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. Only available in %LoRa mode. \brief Sets %LoRa link bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. Only available in %LoRa mode.
@ -266,7 +266,7 @@ class SX1278: public SX127x {
Overload with packet mode enabled for PhysicalLayer compatibility. Overload with packet mode enabled for PhysicalLayer compatibility.
\returns RSSI value in dBm. \returns RSSI value in dBm.
*/ */
float getRSSI(); float getRSSI() override;
/*! /*!
\brief Gets recorded signal strength indicator. \brief Gets recorded signal strength indicator.
@ -323,7 +323,7 @@ class SX1278: public SX127x {
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF); int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
int16_t configFSK(); int16_t configFSK();
void errataFix(bool rx); void errataFix(bool rx) override;
#if !RADIOLIB_GODMODE #if !RADIOLIB_GODMODE
private: private:

View file

@ -20,7 +20,7 @@ class SX1279: public SX1278 {
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance. \brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip. \param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/ */
SX1279(Module* mod); SX1279(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods // basic methods
@ -61,7 +61,7 @@ class SX1279: public SX1278 {
\param freq Carrier frequency to be set in MHz. \param freq Carrier frequency to be set in MHz.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setFrequency(float freq); int16_t setFrequency(float freq) override;
#if !RADIOLIB_GODMODE #if !RADIOLIB_GODMODE
private: private:

View file

@ -905,13 +905,13 @@ int16_t SX127x::setBitRateCommon(float br, uint8_t fracRegAddr) {
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set bit rate // set bit rate
uint16_t bitRate = (RADIOLIB_SX127X_CRYSTAL_FREQ * 1000.0) / br; uint16_t bitRateRaw = (RADIOLIB_SX127X_CRYSTAL_FREQ * 1000.0) / br;
state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0); state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_MSB, (bitRateRaw & 0xFF00) >> 8, 7, 0);
state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0); state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_BITRATE_LSB, bitRateRaw & 0x00FF, 7, 0);
// set fractional part of bit rate // set fractional part of bit rate
if(!ookEnabled) { if(!ookEnabled) {
float bitRateRem = ((RADIOLIB_SX127X_CRYSTAL_FREQ * 1000.0) / (float)br) - (float)bitRate; float bitRateRem = ((RADIOLIB_SX127X_CRYSTAL_FREQ * 1000.0) / (float)br) - (float)bitRateRaw;
uint8_t bitRateFrac = bitRateRem * 16; uint8_t bitRateFrac = bitRateRem * 16;
state |= this->mod->SPIsetRegValue(fracRegAddr, bitRateFrac, 7, 0); state |= this->mod->SPIsetRegValue(fracRegAddr, bitRateFrac, 7, 0);
} }
@ -1335,8 +1335,14 @@ int16_t SX127x::setRSSIConfig(uint8_t smoothingSamples, int8_t offset) {
RADIOLIB_CHECK_RANGE(offset, -16, 15, RADIOLIB_ERR_INVALID_RSSI_OFFSET); RADIOLIB_CHECK_RANGE(offset, -16, 15, RADIOLIB_ERR_INVALID_RSSI_OFFSET);
// calculate the two's complement
uint8_t offsetRaw = RADIOLIB_ABS(offset);
offsetRaw ^= 0x1F;
offsetRaw += 1;
offsetRaw &= 0x1F;
// set new register values // set new register values
state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_CONFIG, offset << 3, 7, 3); state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_CONFIG, offsetRaw << 3, 7, 3);
state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_CONFIG, smoothingSamples, 2, 0); state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_CONFIG, smoothingSamples, 2, 0);
return(state); return(state);
} }
@ -1538,7 +1544,7 @@ int16_t SX127x::setPacketMode(uint8_t mode, uint8_t len) {
return(state); return(state);
} }
bool SX127x::findChip(uint8_t* vers, uint8_t num) { bool SX127x::findChip(const uint8_t* vers, uint8_t num) {
uint8_t i = 0; uint8_t i = 0;
bool flagFound = false; bool flagFound = false;
while((i < 10) && !flagFound) { while((i < 10) && !flagFound) {
@ -1547,8 +1553,8 @@ bool SX127x::findChip(uint8_t* vers, uint8_t num) {
// check version register // check version register
int16_t version = getChipVersion(); int16_t version = getChipVersion();
for(uint8_t i = 0; i < num; i++) { for(uint8_t j = 0; j < num; j++) {
if(version == vers[i]) { if(version == vers[j]) {
flagFound = true; flagFound = true;
break; break;
} }

View file

@ -594,7 +594,7 @@ class SX127x: public PhysicalLayer {
\brief Default constructor. Called internally when creating new LoRa instance. \brief Default constructor. Called internally when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip. \param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/ */
SX127x(Module* mod); SX127x(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods // basic methods
@ -655,7 +655,7 @@ class SX127x: public PhysicalLayer {
%Module will wake up automatically when methods like transmit or receive are called. %Module will wake up automatically when methods like transmit or receive are called.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t sleep(); int16_t sleep() override;
/*! /*!
\brief Sets the %LoRa module to standby. \brief Sets the %LoRa module to standby.
@ -721,34 +721,34 @@ class SX127x: public PhysicalLayer {
\brief Sets interrupt service routine to call when a packet is received. \brief Sets interrupt service routine to call when a packet is received.
\param func ISR to call. \param func ISR to call.
*/ */
void setPacketReceivedAction(void (*func)(void)); void setPacketReceivedAction(void (*func)(void)) override;
/*! /*!
\brief Clears interrupt service routine to call when a packet is received. \brief Clears interrupt service routine to call when a packet is received.
*/ */
void clearPacketReceivedAction(); void clearPacketReceivedAction() override;
/*! /*!
\brief Sets interrupt service routine to call when a packet is sent. \brief Sets interrupt service routine to call when a packet is sent.
\param func ISR to call. \param func ISR to call.
*/ */
void setPacketSentAction(void (*func)(void)); void setPacketSentAction(void (*func)(void)) override;
/*! /*!
\brief Clears interrupt service routine to call when a packet is sent. \brief Clears interrupt service routine to call when a packet is sent.
*/ */
void clearPacketSentAction(); void clearPacketSentAction() override;
/*! /*!
\brief Sets interrupt service routine to call when a channel scan is finished. \brief Sets interrupt service routine to call when a channel scan is finished.
\param func ISR to call. \param func ISR to call.
*/ */
void setChannelScanAction(void (*func)(void)); void setChannelScanAction(void (*func)(void)) override;
/*! /*!
\brief Clears interrupt service routine to call when a channel scan is finished. \brief Clears interrupt service routine to call when a channel scan is finished.
*/ */
void clearChannelScanAction(); void clearChannelScanAction() override;
/*! /*!
\brief Set interrupt service routine function to call when FIFO is empty. \brief Set interrupt service routine function to call when FIFO is empty.
@ -810,7 +810,7 @@ class SX127x: public PhysicalLayer {
Implemented for compatibility with PhysicalLayer. Implemented for compatibility with PhysicalLayer.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t startReceive(); int16_t startReceive() override;
/*! /*!
\brief Interrupt-driven receive method. DIO0 will be activated when full valid packet is received. \brief Interrupt-driven receive method. DIO0 will be activated when full valid packet is received.
@ -832,7 +832,7 @@ class SX127x: public PhysicalLayer {
\param len Expected length of packet to be received. Required for LoRa spreading factor 6. \param len Expected length of packet to be received. Required for LoRa spreading factor 6.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len); int16_t startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) override;
/*! /*!
\brief Reads data that was received after calling startReceive method. When the packet length is not known in advance, \brief Reads data that was received after calling startReceive method. When the packet length is not known in advance,
@ -904,7 +904,7 @@ class SX127x: public PhysicalLayer {
\brief Gets signal-to-noise ratio of the latest received packet. Only available in LoRa mode. \brief Gets signal-to-noise ratio of the latest received packet. Only available in LoRa mode.
\returns Last packet signal-to-noise ratio (SNR). \returns Last packet signal-to-noise ratio (SNR).
*/ */
float getSNR(); float getSNR() override;
/*! /*!
\brief Get data rate of the latest transmitted packet. \brief Get data rate of the latest transmitted packet.
@ -1062,7 +1062,7 @@ class SX127x: public PhysicalLayer {
\param timeoutUs Timeout in microseconds to listen for \param timeoutUs Timeout in microseconds to listen for
\returns Timeout value in a unit that is specific for the used module \returns Timeout value in a unit that is specific for the used module
*/ */
RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs); RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs) override;
/*! /*!
\brief Create the flags that make up RxDone and RxTimeout used for receiving downlinks \brief Create the flags that make up RxDone and RxTimeout used for receiving downlinks
@ -1070,13 +1070,13 @@ class SX127x: public PhysicalLayer {
\param irqMask Mask indicating which IRQ triggers a DIO \param irqMask Mask indicating which IRQ triggers a DIO
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t irqRxDoneRxTimeout(uint32_t &irqFlags, uint32_t &irqMask); int16_t irqRxDoneRxTimeout(uint32_t &irqFlags, uint32_t &irqMask) override;
/*! /*!
\brief Check whether the IRQ bit for RxTimeout is set \brief Check whether the IRQ bit for RxTimeout is set
\returns Whether RxTimeout IRQ is set \returns Whether RxTimeout IRQ is set
*/ */
bool isRxTimeout(); bool isRxTimeout() override;
/*! /*!
\brief Enable CRC filtering and generation. \brief Enable CRC filtering and generation.
@ -1133,7 +1133,7 @@ class SX127x: public PhysicalLayer {
\brief Get one truly random byte from RSSI noise. \brief Get one truly random byte from RSSI noise.
\returns TRNG byte. \returns TRNG byte.
*/ */
uint8_t randomByte(); uint8_t randomByte() override;
/*! /*!
\brief Read version SPI register. Should return SX1278_CHIP_VERSION (0x12) or SX1272_CHIP_VERSION (0x22) if SX127x is connected and working. \brief Read version SPI register. Should return SX1278_CHIP_VERSION (0x12) or SX1272_CHIP_VERSION (0x22) if SX127x is connected and working.
@ -1153,13 +1153,13 @@ class SX127x: public PhysicalLayer {
\brief Set interrupt service routine function to call when data bit is received in direct mode. \brief Set interrupt service routine function to call when data bit is received in direct mode.
\param func Pointer to interrupt service routine. \param func Pointer to interrupt service routine.
*/ */
void setDirectAction(void (*func)(void)); void setDirectAction(void (*func)(void)) override;
/*! /*!
\brief Function to read and process data bit in direct reception mode. \brief Function to read and process data bit in direct reception mode.
\param pin Pin on which to read. \param pin Pin on which to read.
*/ */
void readBit(uint32_t pin); void readBit(uint32_t pin) override;
#endif #endif
/*! /*!
@ -1192,7 +1192,7 @@ class SX127x: public PhysicalLayer {
\param value The value that indicates which function to place on that pin. See chip datasheet for details. \param value The value that indicates which function to place on that pin. See chip datasheet for details.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setDIOMapping(uint32_t pin, uint32_t value); int16_t setDIOMapping(uint32_t pin, uint32_t value) override;
/*! /*!
\brief Configure DIO mapping to use RSSI or Preamble Detect for pins that support it. \brief Configure DIO mapping to use RSSI or Preamble Detect for pins that support it.
@ -1221,7 +1221,7 @@ class SX127x: public PhysicalLayer {
#if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL #if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL
protected: protected:
#endif #endif
Module* getMod(); Module* getMod() override;
#if !RADIOLIB_GODMODE #if !RADIOLIB_GODMODE
protected: protected:
@ -1254,7 +1254,7 @@ class SX127x: public PhysicalLayer {
int16_t config(); int16_t config();
int16_t directMode(); int16_t directMode();
int16_t setPacketMode(uint8_t mode, uint8_t len); int16_t setPacketMode(uint8_t mode, uint8_t len);
bool findChip(uint8_t* vers, uint8_t num); bool findChip(const uint8_t* vers, uint8_t num);
int16_t setMode(uint8_t mode); int16_t setMode(uint8_t mode);
int16_t setActiveModem(uint8_t modem); int16_t setActiveModem(uint8_t modem);
void clearIRQFlags(); void clearIRQFlags();