Compare commits

..

1 commit

Author SHA1 Message Date
Ernesto Casablanca
f45416ab7f
ref: use macro to avoid repetitions and to ensure consistency 2026-06-23 20:21:49 +01:00
5 changed files with 97 additions and 354 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
*.ignore *.ignore
testbuild.sh testbuild.sh
*.so a.so

View file

@ -10,16 +10,15 @@ implemented by the calling program.
This API provides 2 structs for storing data to be written to, and received from This API provides 2 structs for storing data to be written to, and received from
the VCU over CAN. They are `nrai_can_ai_read` and `nrai_can_ai_write` for data the VCU over CAN. They are `nrai_can_ai_read` and `nrai_can_ai_write` for data
received from the VCU and data to write to the VCU respectively. received from the VCU and data to write to the VCU respectively.
This API provides functions for the client to pack data into CAN frames, named in This API provides functions for the AI to pack data into CAN frames, named in
the format the format
`int32_t nrai_can_mkframe_<frame_name>(struct nrai_can_ai_write *, struct can_frame *);` `int32_t nrai_can_mkframe_<frame_name>(struct nrai_can_ai_write *, struct can_frame *);`
and functions for the client to unpack CAN frames, named in the format and function for the AI to unpack CAN frames, named in the format
`int32_t nrai_can_unpack_<frame_name>(struct nrai_can_ai_read *, struct can_frame *);`. `int32_t nrai_can_unpack_<frame_name>(struct nrai_can_ai_read *, struct can_frame *);`.
This API also provides an enum for translating CAN message names into their ID, This API also provides an enum for translating CAN message names into their ID,
all entries are named in the format `NRAI_CAN_ID_<frame_name>`, As well as enums all entry's are named in the format `NRAI_CAN_ID_<frame_name>`
for values contained within frames (see header file).
## Notes ## Notes
This API makes use of limited use of C23 extensions where their use either This API makes use of limited use of C23 extensions for the purpose of either
improves clarity or simplifies code. While all C23 extensions used are improving clarity or simplifying code. While all C23 extensions used are
supported by GCC and Clang, not all compilers support them. supported by GCC and Clang, not all compilers support them.

View file

@ -1,8 +0,0 @@
project('nrai_CAN_API', 'C')
lib = static_library('nrai_CAN_API','nrai_CAN_API.c', install : true)
pkg = import('pkgconfig')
install_headers('nrai_CAN_API.h')
pkg.generate(lib,
# version : '1.1',
description : 'the nrai api to pack and unpack CAN frames from the ADS-DV Software Interface Specification into simpler data structures ')

View file

@ -18,6 +18,27 @@
#include "nrai_CAN_API.h" #include "nrai_CAN_API.h"
#define NRAI_CAN_UNPACK(name, ...) \
NRAI_FT int32_t nrai_can_unpack_##name(struct nrai_can_ai_read* s, struct can_frame* f) { \
if ((s == NULL) || (f == NULL)) \
return -1; \
if (f->can_id != NRAI_CAN_ID_##name) \
return -1; \
\
__VA_ARGS__ \
return 0; \
}
#define NRAI_CAN_MKFRAME(name, ...) \
NRAI_FT int32_t nrai_can_mkframe_##name(struct nrai_can_ai_write* s, struct can_frame* f) { \
if ((s == NULL) || (f == NULL)) \
return -1; \
f->can_id = NRAI_CAN_ID_##name; \
\
__VA_ARGS__ \
return 0; \
}
static inline int32_t static inline int32_t
CLAMP(int32_t value, int32_t min, int32_t max) CLAMP(int32_t value, int32_t min, int32_t max)
{ {
@ -29,14 +50,7 @@ CLAMP(int32_t value, int32_t min, int32_t max)
return value; return value;
} }
NRAI_FT int32_t NRAI_CAN_UNPACK(VCU2AI_Status,
nrai_can_unpack_VCU2AI_Status(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_VCU2AI_Status)
return -1;
s->HANDSHAKE = (f->data[0] & 0b00000001); s->HANDSHAKE = (f->data[0] & 0b00000001);
s->OP_STATE = (f->data[0] & 0b11110000) >> 4; s->OP_STATE = (f->data[0] & 0b11110000) >> 4;
s->SHUTDOWN_REQUEST = (f->data[1] & 0b00000001); s->SHUTDOWN_REQUEST = (f->data[1] & 0b00000001);
@ -64,183 +78,87 @@ nrai_can_unpack_VCU2AI_Status(struct nrai_can_ai_read * s, struct can_frame * f)
s->BMS_FAULT = (f->data[6] & 0b00000010) >> 1; s->BMS_FAULT = (f->data[6] & 0b00000010) >> 1;
s->BRAKE_PLAUSIBILITY_FAULT = (f->data[6] & 0b00000100) >> 2; s->BRAKE_PLAUSIBILITY_FAULT = (f->data[6] & 0b00000100) >> 2;
s->SHUTDOWN_CAUSE = (f->data[7]); s->SHUTDOWN_CAUSE = (f->data[7]);
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_VCU2AI_Steer(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_VCU2AI_Steer)
return -1;
NRAI_CAN_UNPACK(VCU2AI_Steer,
s->ANGLE = ((uint16_t)f->data[1] << 8) | f->data[0]; s->ANGLE = ((uint16_t)f->data[1] << 8) | f->data[0];
s->ANGLE_MAX = ((uint16_t)f->data[3] << 8) | f->data[2]; s->ANGLE_MAX = ((uint16_t)f->data[3] << 8) | f->data[2];
s->ANGLE_REQUEST = ((uint16_t)f->data[5] << 8) | f->data[4]; s->ANGLE_REQUEST = ((uint16_t)f->data[5] << 8) | f->data[4];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_VCU2AI_Speeds(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_VCU2AI_Speeds)
return -1;
NRAI_CAN_UNPACK(VCU2AI_Speeds,
s->FL_WHEEL_SPEED = ((uint16_t)f->data[1] << 8) | f->data[0]; s->FL_WHEEL_SPEED = ((uint16_t)f->data[1] << 8) | f->data[0];
s->FR_WHEEL_SPEED = ((uint16_t)f->data[3] << 8) | f->data[2]; s->FR_WHEEL_SPEED = ((uint16_t)f->data[3] << 8) | f->data[2];
s->RL_WHEEL_SPEED = ((uint16_t)f->data[5] << 8) | f->data[4]; s->RL_WHEEL_SPEED = ((uint16_t)f->data[5] << 8) | f->data[4];
s->RR_WHEEL_SPEED = ((uint16_t)f->data[7] << 8) | f->data[6]; s->RR_WHEEL_SPEED = ((uint16_t)f->data[7] << 8) | f->data[6];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_VCU2AI_Brake(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_VCU2AI_Brake)
return -1;
NRAI_CAN_UNPACK(VCU2AI_Brake,
s->HYD_PRESS_F_pct = f->data[0]; s->HYD_PRESS_F_pct = f->data[0];
s->HYD_PRESS_F_REQ_pct = f->data[1]; s->HYD_PRESS_F_REQ_pct = f->data[1];
s->HYD_PRESS_R_pct = f->data[2]; s->HYD_PRESS_R_pct = f->data[2];
s->HYD_PRESS_R_REQ_pct = f->data[3]; s->HYD_PRESS_R_REQ_pct = f->data[3];
s->STATUS_BRK = (f->data[4] & 0b00001111); s->STATUS_BRK = (f->data[4] & 0b00001111);
s->STATUS_EBS = (f->data[4] & 0b11110000) >> 4; s->STATUS_EBS = (f->data[4] & 0b11110000) >> 4;
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_VCU2AI_Drive_F(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_VCU2AI_Drive_F)
return -1;
NRAI_CAN_UNPACK(VCU2AI_Drive_F,
s->FRONT_AXLE_TRQ = ((uint16_t)f->data[1] << 8) | f->data[0]; s->FRONT_AXLE_TRQ = ((uint16_t)f->data[1] << 8) | f->data[0];
s->FRONT_AXLE_TRQ_REQUEST = ((uint16_t)f->data[3] << 8) | f->data[2]; s->FRONT_AXLE_TRQ_REQUEST = ((uint16_t)f->data[3] << 8) | f->data[2];
s->FRONT_AXLE_TRQ_MAX = ((uint16_t)f->data[5] << 8) | f->data[4]; s->FRONT_AXLE_TRQ_MAX = ((uint16_t)f->data[5] << 8) | f->data[4];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_VCU2AI_Drive_R(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_VCU2AI_Drive_R)
return -1;
NRAI_CAN_UNPACK(VCU2AI_Drive_R,
s->REAR_AXLE_TRQ_Nm = ((uint16_t)f->data[1] << 8) | f->data[0]; s->REAR_AXLE_TRQ_Nm = ((uint16_t)f->data[1] << 8) | f->data[0];
s->REAR_AXLE_TRQ_REQUEST_Nm = ((uint16_t)f->data[3] << 8) | f->data[2]; s->REAR_AXLE_TRQ_REQUEST_Nm = ((uint16_t)f->data[3] << 8) | f->data[2];
s->REAR_AXLE_TRQ_MAX_Nm = ((uint16_t)f->data[5] << 8) | f->data[4]; s->REAR_AXLE_TRQ_MAX_Nm = ((uint16_t)f->data[5] << 8) | f->data[4];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_VCU2AI_Wheel_counts(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_VCU2AI_Wheel_counts)
return -1;
NRAI_CAN_UNPACK(VCU2AI_Wheel_counts,
s->FL_PULSE_COUNT = ((uint16_t)f->data[1] << 8) | f->data[0]; s->FL_PULSE_COUNT = ((uint16_t)f->data[1] << 8) | f->data[0];
s->FR_PULSE_COUNT = ((uint16_t)f->data[3] << 8) | f->data[2]; s->FR_PULSE_COUNT = ((uint16_t)f->data[3] << 8) | f->data[2];
s->RL_PULSE_COUNT = ((uint16_t)f->data[5] << 8) | f->data[4]; s->RL_PULSE_COUNT = ((uint16_t)f->data[5] << 8) | f->data[4];
s->RR_PULSE_COUNT = ((uint16_t)f->data[7] << 8) | f->data[6]; s->RR_PULSE_COUNT = ((uint16_t)f->data[7] << 8) | f->data[6];
return 0; )
}
NRAI_FT int32_t NRAI_CAN_UNPACK(BMC_Acceleration,
nrai_can_unpack_BMC_Acceleration(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_BMC_Acceleration)
return -1;
s->Acceleration_X = ((uint16_t)f->data[1] << 8) | f->data[0]; s->Acceleration_X = ((uint16_t)f->data[1] << 8) | f->data[0];
s->Acceleration_Y = ((uint16_t)f->data[3] << 8) | f->data[2]; s->Acceleration_Y = ((uint16_t)f->data[3] << 8) | f->data[2];
s->Acceleration_Z = ((uint16_t)f->data[5] << 8) | f->data[4]; s->Acceleration_Z = ((uint16_t)f->data[5] << 8) | f->data[4];
s->Temperature = f->data[6]; s->Temperature = f->data[6];
s->VerticalAxis = (f->data[7] & 0b00000011); s->VerticalAxis = (f->data[7] & 0b00000011);
s->Orientation = (f->data[7] & 0b00011100) >> 2; s->Orientation = (f->data[7] & 0b00011100) >> 2;
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_BMC_MagneticField(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_BMC_MagneticField)
return -1;
NRAI_CAN_UNPACK(BMC_MagneticField,
s->MagneticField_X = ((uint16_t)f->data[1] << 8) | f->data[0]; s->MagneticField_X = ((uint16_t)f->data[1] << 8) | f->data[0];
s->MagneticField_Y = ((uint16_t)f->data[3] << 8) | f->data[2]; s->MagneticField_Y = ((uint16_t)f->data[3] << 8) | f->data[2];
s->MagneticField_Z = ((uint16_t)f->data[5] << 8) | f->data[4]; s->MagneticField_Z = ((uint16_t)f->data[5] << 8) | f->data[4];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_L3GD20_Rotation_A(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_L3GD20_Rotation_A)
return -1;
NRAI_CAN_UNPACK(L3GD20_Rotation_A,
s->Rotation_X = ((uint32_t)f->data[3] << 24) | s->Rotation_X = ((uint32_t)f->data[3] << 24) |
((uint32_t)f->data[2] << 16) | ((uint32_t)f->data[2] << 16) |
((uint16_t)f->data[1] << 8) | f->data[0]; ((uint16_t)f->data[1] << 8) | f->data[0];
s->Rotation_Y = ((uint32_t)f->data[7] << 24) | s->Rotation_Y = ((uint32_t)f->data[7] << 24) |
((uint32_t)f->data[6] << 16) | ((uint32_t)f->data[6] << 16) |
((uint16_t)f->data[5] << 8) | f->data[4]; ((uint16_t)f->data[5] << 8) | f->data[4];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_L3GD20_Rotation_B(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_L3GD20_Rotation_B)
return -1;
NRAI_CAN_UNPACK(L3GD20_Rotation_B,
s->Rotation_Z = ((uint32_t)f->data[3] << 24) | s->Rotation_Z = ((uint32_t)f->data[3] << 24) |
((uint32_t)f->data[2] << 16) | ((uint32_t)f->data[2] << 16) |
((uint16_t)f->data[1] << 8) | f->data[0]; ((uint16_t)f->data[1] << 8) | f->data[0];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_GPS_Status(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_GPS_Status)
return -1;
NRAI_CAN_UNPACK(GPS_Status,
s->GPS_AntennaStatus = f->data[0]; s->GPS_AntennaStatus = f->data[0];
s->GPS_NumSatellites = f->data[1]; s->GPS_NumSatellites = f->data[1];
s->GPS_NavigationMethod = f->data[2]; s->GPS_NavigationMethod = f->data[2];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_GPS_CourseSpeed(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_GPS_CourseSpeed)
return -1;
NRAI_CAN_UNPACK(GPS_CourseSpeed,
s->GPS_Course = ((uint32_t)f->data[3] << 24) | s->GPS_Course = ((uint32_t)f->data[3] << 24) |
((uint32_t)f->data[2] << 16) | ((uint32_t)f->data[2] << 16) |
((uint16_t)f->data[1] << 8) | f->data[0]; ((uint16_t)f->data[1] << 8) | f->data[0];
@ -249,63 +167,31 @@ nrai_can_unpack_GPS_CourseSpeed(struct nrai_can_ai_read * s, struct can_frame *
((uint32_t)f->data[6] << 16) | ((uint32_t)f->data[6] << 16) |
((uint16_t)f->data[5] << 8) | f->data[4]; ((uint16_t)f->data[5] << 8) | f->data[4];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_GPS_PositionLongitude(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_GPS_PositionLongitude)
return -1;
NRAI_CAN_UNPACK(GPS_PositionLongitude,
s->GPS_Longitude_Minutes = ((uint32_t)f->data[3] << 24) | s->GPS_Longitude_Minutes = ((uint32_t)f->data[3] << 24) |
((uint32_t)f->data[2] << 16) | ((uint32_t)f->data[2] << 16) |
((uint16_t)f->data[1] << 8) | f->data[0]; ((uint16_t)f->data[1] << 8) | f->data[0];
s->GPS_Longitude_Degree = ((uint16_t)f->data[5] << 8) | f->data[4]; s->GPS_Longitude_Degree = ((uint16_t)f->data[5] << 8) | f->data[4];
s->GPS_IndicatorEW = f->data[6]; s->GPS_IndicatorEW = f->data[6];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_GPS_PositionLatitude(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_GPS_PositionLatitude)
return -1;
NRAI_CAN_UNPACK(GPS_PositionLatitude,
s->GPS_Latitude_Minutes = ((uint32_t)f->data[3] << 24) | s->GPS_Latitude_Minutes = ((uint32_t)f->data[3] << 24) |
((uint32_t)f->data[2] << 16) | ((uint32_t)f->data[2] << 16) |
((uint16_t)f->data[1] << 8) | f->data[0]; ((uint16_t)f->data[1] << 8) | f->data[0];
s->GPS_Latitude_Degree = ((uint16_t)f->data[5] << 8) | f->data[4]; s->GPS_Latitude_Degree = ((uint16_t)f->data[5] << 8) | f->data[4];
s->GPS_IndicatorNS = f->data[6]; s->GPS_IndicatorNS = f->data[6];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_GPS_PositionAltitude(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_GPS_PositionAltitude)
return -1;
NRAI_CAN_UNPACK(GPS_PositionAltitude,
s->GPS_Altitude = ((uint32_t)f->data[3] << 24) | s->GPS_Altitude = ((uint32_t)f->data[3] << 24) |
((uint32_t)f->data[2] << 16) | ((uint32_t)f->data[2] << 16) |
((uint16_t)f->data[1] << 8) | f->data[0]; ((uint16_t)f->data[1] << 8) | f->data[0];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_GPS_Delusions_A(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_GPS_Delusions_A)
return -1;
NRAI_CAN_UNPACK(GPS_Delusions_A,
s->GPS_PDOP = ((uint32_t)f->data[3] << 24) | s->GPS_PDOP = ((uint32_t)f->data[3] << 24) |
((uint32_t)f->data[2] << 16) | ((uint32_t)f->data[2] << 16) |
((uint16_t)f->data[1] << 8) | f->data[0]; ((uint16_t)f->data[1] << 8) | f->data[0];
@ -313,65 +199,33 @@ nrai_can_unpack_GPS_Delusions_A(struct nrai_can_ai_read * s, struct can_frame *
s->GPS_HDOP = ((uint32_t)f->data[7] << 24) | s->GPS_HDOP = ((uint32_t)f->data[7] << 24) |
((uint32_t)f->data[6] << 16) | ((uint32_t)f->data[6] << 16) |
((uint16_t)f->data[5] << 8) | f->data[4]; ((uint16_t)f->data[5] << 8) | f->data[4];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_GPS_Delusions_B(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_GPS_Delusions_B)
return -1;
NRAI_CAN_UNPACK(GPS_Delusions_B,
s->GPS_VDOP = ((uint32_t)f->data[3] << 24) | s->GPS_VDOP = ((uint32_t)f->data[3] << 24) |
((uint32_t)f->data[2] << 16) | ((uint32_t)f->data[2] << 16) |
((uint16_t)f->data[1] << 8) | f->data[0]; ((uint16_t)f->data[1] << 8) | f->data[0];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_GPS_DateTime(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_GPS_DateTime)
return -1;
NRAI_CAN_UNPACK(GPS_DateTime,
s->UTC_Year = f->data[0]; s->UTC_Year = f->data[0];
s->UTC_Month = f->data[1]; s->UTC_Month = f->data[1];
s->UTC_DayOfMonth = f->data[2]; s->UTC_DayOfMonth = f->data[2];
s->UTC_Hour = f->data[3]; s->UTC_Hour = f->data[3];
s->UTC_Minute = f->data[4]; s->UTC_Minute = f->data[4];
s->UTC_Second = f->data[5]; s->UTC_Second = f->data[5];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_IO(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_IO)
return -1;
NRAI_CAN_UNPACK(IO,
s->Din1_Status = (f->data[0] & 0b00000001); s->Din1_Status = (f->data[0] & 0b00000001);
s->Din2_Status = (f->data[0] & 0b00000010) >> 1; s->Din2_Status = (f->data[0] & 0b00000010) >> 1;
s->Dout_Status = (f->data[0] & 0b00000100) >> 2; s->Dout_Status = (f->data[0] & 0b00000100) >> 2;
s->SD_Present = (f->data[0] & 0b00001000) >> 3; s->SD_Present = (f->data[0] & 0b00001000) >> 3;
s->GPS_PowerStatus = (f->data[0] & 0b00010000) >> 4; s->GPS_PowerStatus = (f->data[0] & 0b00010000) >> 4;
s->Device_ID = (f->data[0] & 0b11100000) >> 5; s->Device_ID = (f->data[0] & 0b11100000) >> 5;
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_RTC_DateTime(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_RTC_DateTime)
return -1;
NRAI_CAN_UNPACK(RTC_DateTime,
s->RTC_Sec = f->data[0]; s->RTC_Sec = f->data[0];
s->RTC_Min = f->data[1]; s->RTC_Min = f->data[1];
s->RTC_Hour = f->data[2]; s->RTC_Hour = f->data[2];
@ -379,78 +233,30 @@ nrai_can_unpack_RTC_DateTime(struct nrai_can_ai_read * s, struct can_frame * f)
s->RTC_DayOfMonth = f->data[4]; s->RTC_DayOfMonth = f->data[4];
s->RTC_Month = f->data[5]; s->RTC_Month = f->data[5];
s->RTC_Year = ((uint16_t)f->data[7] << 8) | f->data[6]; s->RTC_Year = ((uint16_t)f->data[7] << 8) | f->data[6];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_Out_IO(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_Out_IO)
return -1;
NRAI_CAN_UNPACK(Out_IO,
s->Dout_Set = (f->data[0] & 0b00000001); s->Dout_Set = (f->data[0] & 0b00000001);
s->GPS_SetPower = (f->data[0] & 0b00000010) >> 2; s->GPS_SetPower = (f->data[0] & 0b00000010) >> 2;
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_Out_PowerOff(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_Out_PowerOff)
return -1;
NRAI_CAN_UNPACK(Out_PowerOff,
s->Device_PowerOff = (f->data[0] & 0b00000001); s->Device_PowerOff = (f->data[0] & 0b00000001);
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_Out_Gyro(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_Out_Gyro)
return -1;
NRAI_CAN_UNPACK(Out_Gyro,
s->Gyro_SetScale = (f->data[0] & 0b00000011); s->Gyro_SetScale = (f->data[0] & 0b00000011);
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_Out_BMC_AccScale(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_Out_BMC_AccScale)
return -1;
NRAI_CAN_UNPACK(Out_BMC_AccScale,
s->Acc_SetScale = (f->data[0] & 0b00000111); s->Acc_SetScale = (f->data[0] & 0b00000111);
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_Out_SaveConfig(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_Out_SaveConfig)
return -1;
NRAI_CAN_UNPACK(Out_SaveConfig,
s->Config_SaveToEEPROM = (f->data[0] & 0b00000001); s->Config_SaveToEEPROM = (f->data[0] & 0b00000001);
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_Out_RTC_SetTime(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_Out_RTC_SetTime)
return -1;
NRAI_CAN_UNPACK(Out_RTC_SetTime,
s->RTC_SetSec = f->data[0]; s->RTC_SetSec = f->data[0];
s->RTC_SetMin = f->data[1]; s->RTC_SetMin = f->data[1];
s->RTC_SetHour = f->data[2]; s->RTC_SetHour = f->data[2];
@ -458,46 +264,23 @@ nrai_can_unpack_Out_RTC_SetTime(struct nrai_can_ai_read * s, struct can_frame *
s->RTC_SetDayOfMonth = f->data[4]; s->RTC_SetDayOfMonth = f->data[4];
s->RTC_SetMonth = f->data[5]; s->RTC_SetMonth = f->data[5];
s->RTC_SetYear = ((uint16_t)f->data[7] << 8) | f->data[6]; s->RTC_SetYear = ((uint16_t)f->data[7] << 8) | f->data[6];
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_Out_RTC_TimeFromGPS(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_Out_RTC_TimeFromGPS)
return -1;
NRAI_CAN_UNPACK(Out_RTC_TimeFromGPS,
s->RTC_SetTimeFromGPS = (f->data[0] & 0b00000001); s->RTC_SetTimeFromGPS = (f->data[0] & 0b00000001);
return 0; )
}
NRAI_FT int32_t
nrai_can_unpack_Out_Acc_FastCalibration(struct nrai_can_ai_read * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
if (f->can_id != NRAI_CAN_ID_Out_Acc_FastCalibration)
return -1;
NRAI_CAN_UNPACK(Out_Acc_FastCalibration,
s->Acc_SetCalibTarget_X = (f->data[0] & 0b00000011); s->Acc_SetCalibTarget_X = (f->data[0] & 0b00000011);
s->Acc_SetCalibTarget_Y = (f->data[1] & 0b00000011); s->Acc_SetCalibTarget_Y = (f->data[1] & 0b00000011);
s->Acc_SetCalibTarget_Z = (f->data[2] & 0b00000011); s->Acc_SetCalibTarget_Z = (f->data[2] & 0b00000011);
s->Acc_StartFastCalib = (f->data[3] & 0b00000001); s->Acc_StartFastCalib = (f->data[3] & 0b00000001);
return 0; )
}
NRAI_FT int32_t NRAI_CAN_MKFRAME(AI2VCU_Status,
nrai_can_mkframe_AI2VCU_Status(struct nrai_can_ai_write * s, struct can_frame * f)
{
if ((s == NULL) || (f == NULL))
return -1;
f->can_id = NRAI_CAN_ID_AI2VCU_Status;
f->len = 8; f->len = 8;
f->data[0] = (s->HANDSHAKE & 0b00000001); f->data[0] = (s->HANDSHAKE & 0b00000001);
@ -510,35 +293,20 @@ nrai_can_mkframe_AI2VCU_Status(struct nrai_can_ai_write * s, struct can_frame *
f->data[5] = ((s->CONES_COUNT_ALL >> 8) & 0x00FF); f->data[5] = ((s->CONES_COUNT_ALL >> 8) & 0x00FF);
f->data[6] = s->VEH_SPEED_ACTUAL; f->data[6] = s->VEH_SPEED_ACTUAL;
f->data[7] = s->VEH_SPEED_DEMAND; f->data[7] = s->VEH_SPEED_DEMAND;
return 0; )
}
NRAI_FT int32_t NRAI_CAN_MKFRAME(AI2VCU_Steer,
nrai_can_mkframe_AI2VCU_Steer( struct nrai_can_ai_write * s, struct can_frame * f) uint32_t tmp;
{
int32_t tmp;
if ((s == NULL) || (f == NULL))
return -1;
f->can_id = NRAI_CAN_ID_AI2VCU_Steer;
f->len = 2; f->len = 2;
tmp = s->STEER_REQUEST; tmp = s->STEER_REQUEST;
tmp = CLAMP(tmp,-210,210); tmp = CLAMP(tmp,-210,210);
f->data[0] = (tmp & 0x00FF); f->data[0] = (tmp & 0x00FF);
f->data[1] = (((uint16_t)tmp >> 8) & 0x00FF); f->data[1] = (((uint16_t)tmp >> 8) & 0x00FF);
return 0; )
}
NRAI_FT int32_t NRAI_CAN_MKFRAME(AI2VCU_Brake,
nrai_can_mkframe_AI2VCU_Brake(struct nrai_can_ai_write * s, struct can_frame * f)
{
uint32_t tmp; uint32_t tmp;
if ((s == NULL) || (f == NULL))
return -1;
f->can_id = NRAI_CAN_ID_AI2VCU_Brake;
f->len = 2; f->len = 2;
tmp = s->HYD_PRESS_F_REQ_pct; tmp = s->HYD_PRESS_F_REQ_pct;
@ -548,17 +316,10 @@ nrai_can_mkframe_AI2VCU_Brake(struct nrai_can_ai_write * s, struct can_frame * f
tmp = s->HYD_PRESS_R_REQ_pct; tmp = s->HYD_PRESS_R_REQ_pct;
tmp = CLAMP(tmp,0,200); tmp = CLAMP(tmp,0,200);
f->data[1] = tmp; f->data[1] = tmp;
return 0; )
}
NRAI_FT int32_t NRAI_CAN_MKFRAME(AI2VCU_Drive_F,
nrai_can_mkframe_AI2VCU_Drive_F(struct nrai_can_ai_write * s, struct can_frame * f)
{
uint32_t tmp; uint32_t tmp;
if ((s == NULL) || (f == NULL))
return -1;
f->can_id = NRAI_CAN_ID_AI2VCU_Drive_F;
f->len = 4; f->len = 4;
tmp = s->FRONT_AXLE_TRQ_REQUEST; tmp = s->FRONT_AXLE_TRQ_REQUEST;
@ -570,17 +331,10 @@ nrai_can_mkframe_AI2VCU_Drive_F(struct nrai_can_ai_write * s, struct can_frame *
tmp = CLAMP(tmp,0,4000); tmp = CLAMP(tmp,0,4000);
f->data[2] = (tmp & 0xFF); f->data[2] = (tmp & 0xFF);
f->data[3] = ((tmp >> 8) & 0xFF); f->data[3] = ((tmp >> 8) & 0xFF);
return 0; )
}
NRAI_FT int32_t NRAI_CAN_MKFRAME(AI2VCU_Drive_R,
nrai_can_mkframe_AI2VCU_Drive_R(struct nrai_can_ai_write * s, struct can_frame * f)
{
uint32_t tmp; uint32_t tmp;
if ((s == NULL) || (f == NULL))
return -1;
f->can_id = NRAI_CAN_ID_AI2VCU_Drive_R;
f->len = 4; f->len = 4;
tmp = s->REAR_AXLE_TRQ_REQUEST; tmp = s->REAR_AXLE_TRQ_REQUEST;
@ -592,5 +346,4 @@ nrai_can_mkframe_AI2VCU_Drive_R(struct nrai_can_ai_write * s, struct can_frame *
tmp = CLAMP(tmp,0,4000); tmp = CLAMP(tmp,0,4000);
f->data[2] = (tmp & 0xFF); f->data[2] = (tmp & 0xFF);
f->data[3] = ((tmp >> 8) & 0xFF); f->data[3] = ((tmp >> 8) & 0xFF);
return 0; )
}

View file

@ -165,7 +165,6 @@ enum{
/* VCU2AI_Status: AS_STATE*/ /* VCU2AI_Status: AS_STATE*/
enum{ enum{
AS_STATE_AS_INIT = 0,
AS_STATE_AS_OFF = 1, AS_STATE_AS_OFF = 1,
AS_STATE_AS_READY = 2, AS_STATE_AS_READY = 2,
AS_STATE_AS_DRIVING = 3, AS_STATE_AS_DRIVING = 3,