Closed HamzaHajeir closed 3 years ago
You're right that the configuration for SF6 will indeeded ingore CRC configuration and always enable it. However, I don't see what's wrong with the second line, could you elaborate?
EDIT: Ah, both of them are actually wrong in the code - @HamzaHajeir you can insert links to actual files in the repository, this is the corresponding code section in the current revision:
Fixed in 8438aa93ef40d7df9529f9e978564ea6ca2fe6f4, thanks for reporting. Let me know if you find anything else.
Oh Great! I'm glad for the contribution
Thanks for the great library :)
Hi @jgromes ,
While trying the changes, the following fragments turned out to be problematic:
SX1272_HEADER_IMPL_MODE | SX127x::_crcEnabled ? SX1272_RX_CRC_MODE_ON : SX1272_RX_CRC_MODE_OFF,
SX127X_TX_MODE_SINGLE | SX127x::_crcEnabled ? SX1278_RX_CRC_MODE_ON : SX1278_RX_CRC_MODE_OFF,
Surrounding the ternary conditionals with parentheses will fix the _..._RX_CRCMODE..._ from becoming the actual register value:
SX1272_HEADER_IMPL_MODE | (SX127x::_crcEnabled ? SX1272_RX_CRC_MODE_ON : SX1272_RX_CRC_MODE_OFF),
SX127X_TX_MODE_SINGLE | (SX127x::_crcEnabled ? SX1278_RX_CRC_MODE_ON : SX1278_RX_CRC_MODE_OFF),
@zhgzhg thanks, reminds me why I dislike ternary so much. It's way too easy to forget about operator priority.
It's a new thing to me :
For other people to evaluate : run this under any compiler, as cpp.sh :
// Example program
#include <iostream>
#include <string>
#define EIGHT 0x8
#define FOUR 0x4
#define TWO 0x2
#define ZERO 0x0
int main()
{
std::string name;
bool two = true;
std::cout << (EIGHT | FOUR | (two ? TWO : ZERO) ) << std::endl;
}
Hi
I'm reading the library to make a compatibility to STM32 HAL library I use.
I've came across this line, Which I expect it's a bug :
in SX1278.cpp L496 :
Shouldn't the two lines pointed to previously be :
state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_2, SX127X_SF_6 | SX127X_TX_MODE_SINGLE | SX127x::_crcEnabled ? SX1278_RX_CRC_MODE_ON : SX1278_RX_CRC_MODE_OFF , 7, 2);
and
state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | SX127X_TX_MODE_SINGLE | SX127x::_crcEnabled ? SX1278_RX_CRC_MODE_ON : SX1278_RX_CRC_MODE_OFF , 7, 2);
respectively ?
Because It will skip the CRC in case of being at
OFF
state.Thanks