LoRaRF-Arduino
LoRaRF-Arduino copied to clipboard
suspicious uint8_t shift
Hi,
the getStatus method isn't working due to wrong shift operation.
void sx126x_getStats(uint16_t* nbPktReceived, uint16_t* nbPktCrcError, uint16_t* nbPktHeaderErr)
{
uint8_t buf[7];
sx126x_transfer(0x10, buf, 7);
*nbPktReceived = (buf[1] >> 8) | buf[2];
*nbPktCrcError = (buf[3] >> 8) | buf[4];
*nbPktHeaderErr = (buf[5] >> 8) | buf[6];
}
"(buf[x] >> 8)" always equals to zero and it's maybe also in the wrong direction.
Should be like: *nbPktReceived = buf[1]; *nbPktReceived <<= 8; *nbPktReceived += buf[2];
Yeah, it is a bug. It should be left shift instead right shift. Your suggestion is correct. Another solution to write correct code in one line is like the follow
*nbPktReceived = (uint16_t) buf[1] << 8 + buf[2];
You are welcome to create a pull request for this fix.