CANRxFrame pack/unpack

This commit is contained in:
andreika-git 2023-10-17 17:49:52 +03:00 committed by rusefillc
parent cfed081ba7
commit 2e6e2ec852
2 changed files with 12 additions and 7 deletions

View File

@ -106,14 +106,13 @@ public class SimulatorFunctionalTest {
private byte [] getCanFrameData(int eid, byte [] msg) {
byte [] packet = {
0, 0, 0, 0,
8, // DLC
0, 0, 0,
0, // FMI
0, 0, // TIME
(1 << 5) | 8, // bitfields: 0..3: DLC=8, 4: RTR=0, 5: IDE=1
(byte)(eid & 0xff),
(byte)((eid >> 8) & 0xff),
(byte)((eid >> 16) & 0xff),
0,
0, 0, 0, 0,
(byte)((eid >> 24) & 0xff),
// data (reserve space for arraycopy)
0, 0, 0, 0, 0, 0, 0, 0
};

View File

@ -269,9 +269,15 @@ void handleWrapCan(TsChannelBase* tsChannel, char *data, int incomingPacketSize)
printf("------ numPackets=%d\n", numPackets);
#endif
for (int i = 0; i < numPackets && incomingPacketSize >= (int)sizeof(CANRxFrame); i++) {
for (int i = 0; i < numPackets && incomingPacketSize >= 16; i++) {
CANRxFrame rxFrame;
memcpy(&rxFrame, data, sizeof(rxFrame));
rxFrame.FMI = data[0];
rxFrame.TIME = (data[1] << 8) | data[2];
rxFrame.DLC = data[3] & 0xf;
rxFrame.RTR = (data[3] >> 4) & 1;
rxFrame.IDE = (data[3] >> 5) & 1;
rxFrame.EID = (data[7] << 24) | (data[6] << 16) | (data[5] << 8) | (data[4]);
memcpy(rxFrame.data8, data + 8, sizeof(rxFrame.data8));
#ifdef DEBUG_BENCH
printf(" * EID=%08x\n", rxFrame.EID);