mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-21 02:02:23 +00:00
Fix #4911 : Partially rework some code to remove warnings about potential non-aligned memory accesses (#4912)
* * Adding the -Wcast-align compilation flag for the rp2040. * * Some rework to use a struct to access radio data * Buffer will not be accessed by arithmetic pointer anymore * * Remplace arithmetic pointer to avoid Warning * * Avoid 2 little artitmetic pointer --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
@@ -387,7 +387,7 @@ void RadioLibInterface::handleReceiveInterrupt()
|
||||
}
|
||||
#endif
|
||||
|
||||
int state = iface->readData(radiobuf, length);
|
||||
int state = iface->readData((uint8_t*)&radioBuffer, length);
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
LOG_ERROR("ignoring received packet due to error=%d\n", state);
|
||||
rxBad++;
|
||||
@@ -397,7 +397,6 @@ void RadioLibInterface::handleReceiveInterrupt()
|
||||
} else {
|
||||
// Skip the 4 headers that are at the beginning of the rxBuf
|
||||
int32_t payloadLen = length - sizeof(PacketHeader);
|
||||
const uint8_t *payload = radiobuf + sizeof(PacketHeader);
|
||||
|
||||
// check for short packets
|
||||
if (payloadLen < 0) {
|
||||
@@ -405,10 +404,9 @@ void RadioLibInterface::handleReceiveInterrupt()
|
||||
rxBad++;
|
||||
airTime->logAirtime(RX_ALL_LOG, xmitMsec);
|
||||
} else {
|
||||
const PacketHeader *h = (PacketHeader *)radiobuf;
|
||||
rxGood++;
|
||||
// altered packet with "from == 0" can do Remote Node Administration without permission
|
||||
if (h->from == 0) {
|
||||
if (radioBuffer.header.from == 0) {
|
||||
LOG_WARN("ignoring received packet without sender\n");
|
||||
return;
|
||||
}
|
||||
@@ -418,22 +416,22 @@ void RadioLibInterface::handleReceiveInterrupt()
|
||||
// nodes.
|
||||
meshtastic_MeshPacket *mp = packetPool.allocZeroed();
|
||||
|
||||
mp->from = h->from;
|
||||
mp->to = h->to;
|
||||
mp->id = h->id;
|
||||
mp->channel = h->channel;
|
||||
mp->from = radioBuffer.header.from;
|
||||
mp->to = radioBuffer.header.to;
|
||||
mp->id = radioBuffer.header.id;
|
||||
mp->channel = radioBuffer.header.channel;
|
||||
assert(HOP_MAX <= PACKET_FLAGS_HOP_LIMIT_MASK); // If hopmax changes, carefully check this code
|
||||
mp->hop_limit = h->flags & PACKET_FLAGS_HOP_LIMIT_MASK;
|
||||
mp->hop_start = (h->flags & PACKET_FLAGS_HOP_START_MASK) >> PACKET_FLAGS_HOP_START_SHIFT;
|
||||
mp->want_ack = !!(h->flags & PACKET_FLAGS_WANT_ACK_MASK);
|
||||
mp->via_mqtt = !!(h->flags & PACKET_FLAGS_VIA_MQTT_MASK);
|
||||
mp->hop_limit = radioBuffer.header.flags & PACKET_FLAGS_HOP_LIMIT_MASK;
|
||||
mp->hop_start = (radioBuffer.header.flags & PACKET_FLAGS_HOP_START_MASK) >> PACKET_FLAGS_HOP_START_SHIFT;
|
||||
mp->want_ack = !!(radioBuffer.header.flags & PACKET_FLAGS_WANT_ACK_MASK);
|
||||
mp->via_mqtt = !!(radioBuffer.header.flags & PACKET_FLAGS_VIA_MQTT_MASK);
|
||||
|
||||
addReceiveMetadata(mp);
|
||||
|
||||
mp->which_payload_variant =
|
||||
meshtastic_MeshPacket_encrypted_tag; // Mark that the payload is still encrypted at this point
|
||||
assert(((uint32_t)payloadLen) <= sizeof(mp->encrypted.bytes));
|
||||
memcpy(mp->encrypted.bytes, payload, payloadLen);
|
||||
memcpy(mp->encrypted.bytes, radioBuffer.payload, payloadLen);
|
||||
mp->encrypted.size = payloadLen;
|
||||
|
||||
printPacket("Lora RX", mp);
|
||||
@@ -475,7 +473,7 @@ void RadioLibInterface::startSend(meshtastic_MeshPacket *txp)
|
||||
|
||||
size_t numbytes = beginSending(txp);
|
||||
|
||||
int res = iface->startTransmit(radiobuf, numbytes);
|
||||
int res = iface->startTransmit((uint8_t*)&radioBuffer, numbytes);
|
||||
if (res != RADIOLIB_ERR_NONE) {
|
||||
LOG_ERROR("startTransmit failed, error=%d\n", res);
|
||||
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
|
||||
|
||||
Reference in New Issue
Block a user