Skip to content

Commit 4c9246f

Browse files
committed
Fix reinterpret_cast from uint8_t to *uint32_t
1 parent 9dab1a0 commit 4c9246f

File tree

1 file changed

+9
-7
lines changed
  • examples/nucleo_g474re/sx128x_lora

1 file changed

+9
-7
lines changed

examples/nucleo_g474re/sx128x_lora/main.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// ----------------------------------------------------------------------------
1212

1313
#include <atomic>
14+
#include <cstring>
1415

1516
#include <modm/board.hpp>
1617
#include <modm/debug/logger/logger.hpp>
@@ -119,11 +120,13 @@ class RxThread : public modm::sx128x, public modm::pt::Protothread
119120
PT_CALL(radio.getPacketStatus(&packetStatus));
120121
PT_CALL(radio.readBuffer(rxBufferStatus.rxStartBufferPointer, std::span{buffer, rxBufferStatus.rxPayloadLength}));
121122

122-
/// TODO: read frequency error indicator (FEI) from register 0x0954 (MSB) 0x0955, 0x0956 (LSB).
123-
124-
MODM_LOG_DEBUG << "Received Message" << modm::endl;
125-
MODM_LOG_DEBUG << "Counter: " << reinterpret_cast<uint32_t*>(buffer)[0] << modm::endl;
126-
MODM_LOG_DEBUG << modm::endl;
123+
if (rxBufferStatus.rxPayloadLength > 0)
124+
{
125+
uint32_t counter;
126+
std::memcpy((uint8_t *) &counter, buffer, sizeof(counter));
127+
MODM_LOG_DEBUG << "Received Message" << modm::endl;
128+
MODM_LOG_DEBUG << "Counter: " << counter << modm::endl;
129+
}
127130
}
128131
}
129132

@@ -152,7 +155,7 @@ class RxThread : public modm::sx128x, public modm::pt::Protothread
152155
modm::Sx128x< Transport, Reset, Busy > radio;
153156

154157
private:
155-
static constexpr uint8_t bufferSize = 256;
158+
static constexpr size_t bufferSize = 256;
156159
uint8_t buffer[bufferSize];
157160
} rxThread;
158161

@@ -228,7 +231,6 @@ class TxThread : public modm::sx128x, public modm::pt::Protothread
228231
{
229232
PT_CALL(radio.clearIrqStatus(Irq::RxTxTimeout));
230233
irqStatus.reset(Irq::RxTxTimeout);
231-
232234
MODM_LOG_DEBUG << "Received a timeout" << modm::endl;
233235
}
234236
}

0 commit comments

Comments
 (0)