Skip to content

Commit

Permalink
Fix reinterpret_cast from uint8_t to *uint32_t
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmuskleist committed Aug 9, 2023
1 parent 9dab1a0 commit 4c9246f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions examples/nucleo_g474re/sx128x_lora/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// ----------------------------------------------------------------------------

#include <atomic>
#include <cstring>

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

/// TODO: read frequency error indicator (FEI) from register 0x0954 (MSB) 0x0955, 0x0956 (LSB).

MODM_LOG_DEBUG << "Received Message" << modm::endl;
MODM_LOG_DEBUG << "Counter: " << reinterpret_cast<uint32_t*>(buffer)[0] << modm::endl;
MODM_LOG_DEBUG << modm::endl;
if (rxBufferStatus.rxPayloadLength > 0)
{
uint32_t counter;
std::memcpy((uint8_t *) &counter, buffer, sizeof(counter));
MODM_LOG_DEBUG << "Received Message" << modm::endl;
MODM_LOG_DEBUG << "Counter: " << counter << modm::endl;
}
}
}

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

private:
static constexpr uint8_t bufferSize = 256;
static constexpr size_t bufferSize = 256;
uint8_t buffer[bufferSize];
} rxThread;

Expand Down Expand Up @@ -228,7 +231,6 @@ class TxThread : public modm::sx128x, public modm::pt::Protothread
{
PT_CALL(radio.clearIrqStatus(Irq::RxTxTimeout));
irqStatus.reset(Irq::RxTxTimeout);

MODM_LOG_DEBUG << "Received a timeout" << modm::endl;
}
}
Expand Down

0 comments on commit 4c9246f

Please sign in to comment.