diff --git a/hal/src/main/native/athena/CANAPI.cpp b/hal/src/main/native/athena/CANAPI.cpp index bf60104640..3d4035fc63 100644 --- a/hal/src/main/native/athena/CANAPI.cpp +++ b/hal/src/main/native/athena/CANAPI.cpp @@ -196,6 +196,7 @@ void HAL_ReadCANPacketNew(HAL_CANHandle handle, int32_t apiId, uint8_t* data, auto& msg = can->receives[messageId]; msg.length = dataSize; msg.lastTimeStamp = timestamp; + // The NetComm call placed in data, copy into the msg std::memcpy(msg.data, data, dataSize); } *length = dataSize; @@ -226,11 +227,13 @@ void HAL_ReadCANPacketLatest(HAL_CANHandle handle, int32_t apiId, uint8_t* data, *length = dataSize; msg.lastTimeStamp = timestamp; *receivedTimestamp = timestamp; + // The NetComm call placed in data, copy into the msg std::memcpy(msg.data, data, dataSize); } else { auto i = can->receives.find(messageId); if (i != can->receives.end()) { - std::memcpy(i->second.data, data, i->second.length); + // Read the data from the stored message into the output + std::memcpy(data, i->second.data, i->second.length); *length = i->second.length; *receivedTimestamp = i->second.lastTimeStamp; *status = 0; @@ -263,6 +266,7 @@ void HAL_ReadCANPacketTimeout(HAL_CANHandle handle, int32_t apiId, *length = dataSize; msg.lastTimeStamp = timestamp; *receivedTimestamp = timestamp; + // The NetComm call placed in data, copy into the msg std::memcpy(msg.data, data, dataSize); } else { auto i = can->receives.find(messageId); @@ -275,7 +279,8 @@ void HAL_ReadCANPacketTimeout(HAL_CANHandle handle, int32_t apiId, *status = HAL_CAN_TIMEOUT; return; } - std::memcpy(i->second.data, data, i->second.length); + // Read the data from the stored message into the output + std::memcpy(data, i->second.data, i->second.length); *length = i->second.length; *receivedTimestamp = i->second.lastTimeStamp; *status = 0; @@ -304,9 +309,11 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId, if (now - i->second.lastTimeStamp < static_cast(periodMs) * 1000) { *status = 0; - std::memcpy(i->second.data, data, i->second.length); + // Read the data from the stored message into the output + std::memcpy(data, i->second.data, i->second.length); *length = i->second.length; *receivedTimestamp = i->second.lastTimeStamp; + return; } } } @@ -325,6 +332,7 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId, *length = dataSize; msg.lastTimeStamp = timestamp; *receivedTimestamp = timestamp; + // The NetComm call placed in data, copy into the msg std::memcpy(msg.data, data, dataSize); } else { auto i = can->receives.find(messageId); @@ -337,7 +345,8 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId, *status = HAL_CAN_TIMEOUT; return; } - std::memcpy(i->second.data, data, i->second.length); + // Read the data from the stored message into the output + std::memcpy(data, i->second.data, i->second.length); *length = i->second.length; *receivedTimestamp = i->second.lastTimeStamp; *status = 0; diff --git a/hal/src/main/native/sim/CANAPI.cpp b/hal/src/main/native/sim/CANAPI.cpp index 7c6e2111d5..3b1a00eba2 100644 --- a/hal/src/main/native/sim/CANAPI.cpp +++ b/hal/src/main/native/sim/CANAPI.cpp @@ -190,6 +190,7 @@ void HAL_ReadCANPacketNew(HAL_CANHandle handle, int32_t apiId, uint8_t* data, auto& msg = can->receives[messageId]; msg.length = dataSize; msg.lastTimeStamp = timestamp; + // The NetComm call placed in data, copy into the msg std::memcpy(msg.data, data, dataSize); } *length = dataSize; @@ -220,11 +221,13 @@ void HAL_ReadCANPacketLatest(HAL_CANHandle handle, int32_t apiId, uint8_t* data, *length = dataSize; msg.lastTimeStamp = timestamp; *receivedTimestamp = timestamp; + // The NetComm call placed in data, copy into the msg std::memcpy(msg.data, data, dataSize); } else { auto i = can->receives.find(messageId); if (i != can->receives.end()) { - std::memcpy(i->second.data, data, i->second.length); + // Read the data from the stored message into the output + std::memcpy(data, i->second.data, i->second.length); *length = i->second.length; *receivedTimestamp = i->second.lastTimeStamp; *status = 0; @@ -257,6 +260,7 @@ void HAL_ReadCANPacketTimeout(HAL_CANHandle handle, int32_t apiId, *length = dataSize; msg.lastTimeStamp = timestamp; *receivedTimestamp = timestamp; + // The NetComm call placed in data, copy into the msg std::memcpy(msg.data, data, dataSize); } else { auto i = can->receives.find(messageId); @@ -269,7 +273,8 @@ void HAL_ReadCANPacketTimeout(HAL_CANHandle handle, int32_t apiId, *status = HAL_CAN_TIMEOUT; return; } - std::memcpy(i->second.data, data, i->second.length); + // Read the data from the stored message into the output + std::memcpy(data, i->second.data, i->second.length); *length = i->second.length; *receivedTimestamp = i->second.lastTimeStamp; *status = 0; @@ -286,6 +291,7 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId, *status = HAL_HANDLE_ERROR; return; } + uint32_t messageId = CreateCANId(can.get(), apiId); { @@ -297,9 +303,11 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId, if (now - i->second.lastTimeStamp < static_cast(periodMs) * 1000) { *status = 0; - std::memcpy(i->second.data, data, i->second.length); + // Read the data from the stored message into the output + std::memcpy(data, i->second.data, i->second.length); *length = i->second.length; *receivedTimestamp = i->second.lastTimeStamp; + return; } } } @@ -318,6 +326,7 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId, *length = dataSize; msg.lastTimeStamp = timestamp; *receivedTimestamp = timestamp; + // The NetComm call placed in data, copy into the msg std::memcpy(msg.data, data, dataSize); } else { auto i = can->receives.find(messageId); @@ -330,7 +339,8 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId, *status = HAL_CAN_TIMEOUT; return; } - std::memcpy(i->second.data, data, i->second.length); + // Read the data from the stored message into the output + std::memcpy(data, i->second.data, i->second.length); *length = i->second.length; *receivedTimestamp = i->second.lastTimeStamp; *status = 0;