[nRF24] Fixed issues found by cppcheck

This commit is contained in:
jgromes 2024-05-11 17:20:19 +01:00
parent 2f867153f9
commit e35689cbaa
2 changed files with 17 additions and 17 deletions

View file

@ -298,14 +298,14 @@ int16_t nRF24::setBitRate(float br) {
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set data rate // set data rate
uint16_t dataRate = (uint16_t)br; uint16_t bitRate = (uint16_t)br;
if(dataRate == 250) { if(bitRate == 250) {
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 5, 5); state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 5, 5);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 3, 3); state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 3, 3);
} else if(dataRate == 1000) { } else if(bitRate == 1000) {
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 5, 5); state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 5, 5);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 3, 3); state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 3, 3);
} else if(dataRate == 2000) { } else if(bitRate == 2000) {
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 5, 5); state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 5, 5);
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 3, 3); state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 3, 3);
} else { } else {
@ -313,7 +313,7 @@ int16_t nRF24::setBitRate(float br) {
} }
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
this->dataRate = dataRate; this->dataRate = bitRate;
} }

View file

@ -193,7 +193,7 @@ class nRF24: public PhysicalLayer {
\brief Default constructor. \brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio. \param mod Instance of Module that will be used to communicate with the radio.
*/ */
nRF24(Module* mod); nRF24(Module* mod); // cppcheck-suppress noExplicitConstructor
// basic methods // basic methods
@ -215,7 +215,7 @@ class nRF24: public PhysicalLayer {
\brief Sets the module to sleep mode. \brief Sets the module to sleep mode.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t sleep(); int16_t sleep() override;
/*! /*!
\brief Sets the module to standby mode. \brief Sets the module to standby mode.
@ -279,23 +279,23 @@ class nRF24: 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 Interrupt-driven binary transmit method. IRQ will be activated when full packet is transmitted. \brief Interrupt-driven binary transmit method. IRQ will be activated when full packet is transmitted.
@ -317,7 +317,7 @@ class nRF24: public PhysicalLayer {
\brief Interrupt-driven receive method. IRQ will be activated when full packet is received. \brief Interrupt-driven receive method. IRQ will be activated when full packet is received.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t startReceive(); int16_t startReceive() override;
/*! /*!
\brief Interrupt-driven receive method, implemented for compatibility with PhysicalLayer. \brief Interrupt-driven receive method, implemented for compatibility with PhysicalLayer.
@ -327,7 +327,7 @@ class nRF24: public PhysicalLayer {
\param len Ignored. \param len Ignored.
\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 received after calling startReceive method. When the packet length is not known in advance, \brief Reads data received after calling startReceive method. When the packet length is not known in advance,
@ -345,21 +345,21 @@ class nRF24: public PhysicalLayer {
\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 bit rate. Allowed values are 2000, 1000 or 250 kbps. \brief Sets bit rate. Allowed values are 2000, 1000 or 250 kbps.
\param br Bit rate to be set in kbps. \param br Bit rate to be set in kbps.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setBitRate(float br); int16_t setBitRate(float br) override;
/*! /*!
\brief Sets output power. Allowed values are -18, -12, -6 or 0 dBm. \brief Sets output power. Allowed values are -18, -12, -6 or 0 dBm.
\param pwr Output power to be set in dBm. \param pwr Output power to be set in dBm.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setOutputPower(int8_t pwr); int16_t setOutputPower(int8_t pwr) override;
/*! /*!
\brief Sets address width of transmit and receive pipes in bytes. Allowed values are 3, 4 or 5 bytes. \brief Sets address width of transmit and receive pipes in bytes. Allowed values are 3, 4 or 5 bytes.
@ -468,7 +468,7 @@ class nRF24: public PhysicalLayer {
#if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL #if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL
protected: protected:
#endif #endif
Module* getMod(); Module* getMod() override;
void SPIreadRxPayload(uint8_t* data, uint8_t numBytes); void SPIreadRxPayload(uint8_t* data, uint8_t numBytes);
void SPIwriteTxPayload(uint8_t* data, uint8_t numBytes); void SPIwriteTxPayload(uint8_t* data, uint8_t numBytes);