I'm building a gateway for vehicle CAN.
Almost all of the signals are being translated as expected, with one exception.
I'm not sure what is causing the issue, but it seems one of the bytes from the Rx message is modified unexpectedly.
Troubleshooting so far:
Using CANalyzer, I am feeding in a CAN log and monitoring the gateway output.
The translated value for just ONE signal wasn't making any sense (steering angle in this case).
I checked the scaling and offset, and that part seems to be correct.
By selectively commenting things out, re-compiling, re-flashing and monitoring each time, I managed to narrow the source of the issue to where the input msg is copied over to a variable in a struct.
I disabled all normal outputs and added a new debug message which should basically only mirror bytes 4 and 5 of the received message.
HOWEVER, while debug byte 4 is the same as RxMsg byte 4, debug byte 5 is DIFFERENT than RxMsg byte5...
I'm thinking this might be some general C language mistake, but after much time I still have no clue why this is happening.
Here are the relevant code snippets:
Here is the definition of my vcan signals struct. All values are initialized to 0.
Code: Select all
typedef struct
{
u8_t gear;
double vehicleSpeed;
double wheelSpeedFR;
double wheelSpeedFL;
double wheelSpeedRR;
double wheelSpeedRL;
double yawRate;
double steeringAngle;
u16_t debug_u16;
u32_t debug_u32;
u8_t debug_u8_1;
u8_t debug_u8_2;
}vcanSignals;
Code: Select all
// process messages from CAN1: VCAN input
if (CAN_UserRead (CAN_BUS1, &RxMsg) != 0)
{
// parse and save vcan signals
processInputs_xxxx(&RxMsg, &signals);
}
Code: Select all
void processInputs_xxxx (CANMsg_t *RxMsg, vcanSignals *signals)
{
// yaw rate, steering angle
if (RxMsg->Id == 0xAB) //VDC_A6
{
u16_t tmp;
signals->debug_u8_1 = RxMsg->Data8[4];
signals->debug_u8_2 = RxMsg->Data8[5];
signals->debug_u16 = RxMsg->Data16[2];
signals->debug_u32 = RxMsg->Data32[1];
tmp = ((u16_t)(RxMsg->Data8[4] & 0xFF) << 8) + ((u16_t)(RxMsg->Data8[5] & 0xFE) >> 1);
signals->steeringAngle = (((double)tmp * 0.1) - 1080) * 0.0174532925199433;
}
}
Code: Select all
void output_xxxx (vcanSignals *signals)
{
CANMsg_t DebugMsg;
DebugMsg.Id = 0x3;
DebugMsg.Len = 8;
DebugMsg.Type = CAN_MSG_STANDARD;
DebugMsg.Data8[0] = signals->debug_u8_1;
DebugMsg.Data8[1] = signals->debug_u8_2;
DebugMsg.Data16[1] = signals->debug_u16;
DebugMsg.Data32[1] = signals->debug_u32;
CAN_UserWrite (CAN_BUS2, &DebugMsg);
}