[SX126x] Fixed issues found by cppcheck

This commit is contained in:
jgromes 2024-05-05 20:11:02 +01:00
parent 4f52738ed4
commit 3b62c88a2e
7 changed files with 46 additions and 44 deletions

View file

@ -87,6 +87,7 @@ int16_t STM32WLx::setOutputPower(int8_t power) {
return(RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
RADIOLIB_ASSERT(state);
// Apply workaround for HP only
state = SX126x::fixPaClamping(use_hp);

View file

@ -39,7 +39,7 @@ class STM32WLx : public SX1262 {
\brief Default constructor.
\param mod Instance of STM32WLx_Module that will be used to communicate with the radio.
*/
STM32WLx(STM32WLx_Module* mod);
STM32WLx(STM32WLx_Module* mod); // cppcheck-suppress noExplicitConstructor
/*!
\brief Custom operation modes for STMWLx.
@ -124,34 +124,34 @@ class STM32WLx : public SX1262 {
\brief Sets interrupt service routine to call when a packet is received.
\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.
*/
void clearPacketReceivedAction();
void clearPacketReceivedAction() override;
/*!
\brief Sets interrupt service routine to call when a packet is sent.
\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.
*/
void clearPacketSentAction();
void clearPacketSentAction() override;
/*!
\brief Sets interrupt service routine to call when a channel scan is finished.
\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.
*/
void clearChannelScanAction();
void clearChannelScanAction() override;
#if !RADIOLIB_GODMODE
protected:

View file

@ -25,14 +25,14 @@ class SX1261 : public SX1262 {
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
SX1261(Module* mod);
SX1261(Module* mod); // cppcheck-suppress noExplicitConstructor
/*!
\brief Sets output power. Allowed values are in range from -17 to 14 dBm.
\param power Output power to be set in dBm.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power);
int16_t setOutputPower(int8_t power) override;
/*!
\brief Check if output power is configurable.
@ -40,7 +40,7 @@ class SX1261 : public SX1262 {
\param clipped Clipped output power value to what is possible within the module's range.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped);
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
#if !RADIOLIB_GODMODE
private:

View file

@ -25,7 +25,7 @@ class SX1262: public SX126x {
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
SX1262(Module* mod);
SX1262(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
@ -69,7 +69,7 @@ class SX1262: public SX126x {
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
int16_t setFrequency(float freq) override;
/*!
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz.
@ -85,7 +85,7 @@ class SX1262: public SX126x {
\param power Output power to be set in dBm.
\returns \ref status_codes
*/
virtual int16_t setOutputPower(int8_t power);
virtual int16_t setOutputPower(int8_t power) override;
/*!
\brief Check if output power is configurable.
@ -93,7 +93,7 @@ class SX1262: public SX126x {
\param clipped Clipped output power value to what is possible within the module's range.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped);
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
#if !RADIOLIB_GODMODE
private:

View file

@ -24,7 +24,7 @@ class SX1268: public SX126x {
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
SX1268(Module* mod);
SX1268(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods
@ -68,7 +68,7 @@ class SX1268: public SX126x {
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
int16_t setFrequency(float freq) override;
/*!
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz.
@ -83,7 +83,7 @@ class SX1268: public SX126x {
\param power Output power to be set in dBm.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power);
int16_t setOutputPower(int8_t power) override;
/*!
\brief Check if output power is configurable.
@ -91,7 +91,7 @@ class SX1268: public SX126x {
\param clipped Clipped output power value to what is possible within the module's range.
\returns \ref status_codes
*/
int16_t checkOutputPower(int8_t power, int8_t* clipped);
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
#if !RADIOLIB_GODMODE
private:

View file

@ -76,10 +76,11 @@ int16_t SX126x::begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, flo
RADIOLIB_ASSERT(state);
if (useRegulatorLDO) {
state = setRegulatorLDO();
state = setRegulatorLDO();
} else {
state = setRegulatorDCDC();
state = setRegulatorDCDC();
}
RADIOLIB_ASSERT(state);
// set publicly accessible settings that are not a part of begin method
state = setCurrentLimit(60.0);
@ -1577,7 +1578,7 @@ int16_t SX126x::uploadPatch(const uint32_t* patch, size_t len, bool nonvolatile)
// check the version
#if RADIOLIB_DEBUG_BASIC
char ver_pre[16];
this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)ver_pre);
this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, reinterpret_cast<uint8_t*>(ver_pre));
RADIOLIB_DEBUG_BASIC_PRINTLN("Pre-update version string: %s", ver_pre);
#endif
@ -1609,7 +1610,7 @@ int16_t SX126x::uploadPatch(const uint32_t* patch, size_t len, bool nonvolatile)
// check the version again
#if RADIOLIB_DEBUG_BASIC
char ver_post[16];
this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)ver_post);
this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, reinterpret_cast<uint8_t*>(ver_post));
RADIOLIB_DEBUG_BASIC_PRINTLN("Post-update version string: %s", ver_post);
#endif
@ -1736,7 +1737,7 @@ int16_t SX126x::setRx(uint32_t timeout) {
int16_t SX126x::setCad(uint8_t symbolNum, uint8_t detPeak, uint8_t detMin) {
// default CAD parameters are shown in Semtech AN1200.48, page 41.
uint8_t detPeakValues[6] = { 22, 22, 24, 25, 26, 30};
const uint8_t detPeakValues[6] = { 22, 22, 24, 25, 26, 30};
// CAD parameters aren't available for SF-6. Just to be safe.
if(this->spreadingFactor < 7) {
@ -2163,18 +2164,18 @@ bool SX126x::findChip(const char* verStr) {
// read the version string
char version[16];
this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)version);
this->mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, reinterpret_cast<uint8_t*>(version));
// check version register
if(strncmp(verStr, version, 6) == 0) {
RADIOLIB_DEBUG_BASIC_PRINTLN("Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:");
RADIOLIB_DEBUG_BASIC_HEXDUMP((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING);
RADIOLIB_DEBUG_BASIC_HEXDUMP(reinterpret_cast<uint8_t*>(version), 16, RADIOLIB_SX126X_REG_VERSION_STRING);
RADIOLIB_DEBUG_BASIC_PRINTLN();
flagFound = true;
} else {
#if RADIOLIB_DEBUG_BASIC
RADIOLIB_DEBUG_BASIC_PRINTLN("SX126x not found! (%d of 10 tries) RADIOLIB_SX126X_REG_VERSION_STRING:", i + 1);
RADIOLIB_DEBUG_BASIC_HEXDUMP((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING);
RADIOLIB_DEBUG_BASIC_HEXDUMP(reinterpret_cast<uint8_t*>(version), 16, RADIOLIB_SX126X_REG_VERSION_STRING);
RADIOLIB_DEBUG_BASIC_PRINTLN("Expected string: %s", verStr);
#endif
this->mod->hal->delay(10);

View file

@ -452,7 +452,7 @@ class SX126x: public PhysicalLayer {
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
SX126x(Module* mod);
SX126x(Module* mod); // cppcheck-suppress noExplicitConstructor
/*!
\brief Whether the module has an XTAL (true) or TCXO (false). Defaults to false.
@ -586,34 +586,34 @@ class SX126x: public PhysicalLayer {
\brief Sets interrupt service routine to call when a packet is received.
\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.
*/
void clearPacketReceivedAction();
void clearPacketReceivedAction() override;
/*!
\brief Sets interrupt service routine to call when a packet is sent.
\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.
*/
void clearPacketSentAction();
void clearPacketSentAction() override;
/*!
\brief Sets interrupt service routine to call when a channel scan is finished.
\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.
*/
void clearChannelScanAction();
void clearChannelScanAction() override;
/*!
\brief Interrupt-driven binary transmit method.
@ -637,7 +637,7 @@ class SX126x: public PhysicalLayer {
\returns \ref status_codes
*/
int16_t startReceive();
int16_t startReceive() override;
/*!
\brief Interrupt-driven receive method. DIO1 will be activated when full packet is received.
@ -786,7 +786,7 @@ class SX126x: public PhysicalLayer {
\param br FSK bit rate to be set in kbps.
\returns \ref status_codes
*/
int16_t setBitRate(float br);
int16_t setBitRate(float br) override;
/*!
\brief Set data.
@ -920,7 +920,7 @@ class SX126x: public PhysicalLayer {
\brief Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem.
\returns SNR of the last received packet in dB.
*/
float getSNR();
float getSNR() override;
/*!
\brief Gets frequency error of the latest received packet.
@ -964,7 +964,7 @@ class SX126x: public PhysicalLayer {
\param timeoutUs Timeout in microseconds to listen for
\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
@ -972,13 +972,13 @@ class SX126x: public PhysicalLayer {
\param irqMask Mask indicating which IRQ triggers a DIO
\returns \ref status_codes
*/
int16_t irqRxDoneRxTimeout(uint16_t &irqFlags, uint16_t &irqMask);
int16_t irqRxDoneRxTimeout(uint16_t &irqFlags, uint16_t &irqMask) override;
/*!
\brief Check whether the IRQ bit for RxTimeout is set
\returns Whether RxTimeout IRQ is set
*/
bool isRxTimeout();
bool isRxTimeout() override;
/*!
\brief Set implicit header mode for future reception/transmission.
@ -1040,7 +1040,7 @@ class SX126x: public PhysicalLayer {
\brief Get one truly random byte from RSSI noise.
\returns TRNG byte.
*/
uint8_t randomByte();
uint8_t randomByte() override;
/*!
\brief Enable/disable inversion of the I and Q signals
@ -1054,13 +1054,13 @@ class SX126x: public PhysicalLayer {
\brief Set interrupt service routine function to call when data bit is received in direct mode.
\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.
\param pin Pin on which to read.
*/
void readBit(uint32_t pin);
void readBit(uint32_t pin) override;
#endif
/*!
@ -1132,7 +1132,7 @@ class SX126x: public PhysicalLayer {
#if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL
protected:
#endif
Module* getMod();
Module* getMod() override;
// SX126x SPI command implementations
int16_t setFs();
@ -1163,7 +1163,7 @@ class SX126x: public PhysicalLayer {
#if !RADIOLIB_GODMODE
protected:
#endif
const char* chipType;
const char* chipType = NULL;
uint8_t bandwidth = 0;
// Allow subclasses to define different TX modes