From 0a6ebedd845928aa4800022a9ca9fcb8542dc1aa Mon Sep 17 00:00:00 2001 From: RowanC Date: Mon, 6 Apr 2026 17:33:15 +0100 Subject: [PATCH] Update doc --- README.md | 24 ++++++++++++++++++++++++ nrai_CAN_API.h | 12 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e69de29..a8fb20d 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,24 @@ += nrai_ADS-DV_CAN-API +This is the Newcastle Racing AI (nrai) implementation of the ADS-DV software +interface specification (including all other sensors accessed via CAN e.g. GPS). +it aims to be as minimal as possible, facilitating on the bare minimum to pack +and unpack CAN frames, only implementing checks where required for the packing +of frames (e.g. stat clamping). All data sanity checks are expected to be +implemented by the calling program. + +== Usage +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 +received from the VCU and data to write to the VCU respectively. +This API provides functions for the AI to pack data into CAN frames, named in +the format +`int32_t nrai_can_mkframe_(struct nrai_can_ai_write *, struct can_frame *);` +and function for the AI to unpack CAN frames, named in the format +`int32_t nrai_can_unpack_(struct nrai_can_ai_read *, struct can_frame *);`. +This API also provides an enum for translating CAN message names into their ID, +all entry's are named in the format `NRAI_CAN_ID_` + +== Notes +This API makes use of limited use of C23 extensions for the purpose of either +improving clarity or simplifying code. While all C23 extensions used are +supported by GCC and Clang, not all compilers support them. diff --git a/nrai_CAN_API.h b/nrai_CAN_API.h index b10ccd9..4be8cfe 100644 --- a/nrai_CAN_API.h +++ b/nrai_CAN_API.h @@ -30,7 +30,9 @@ #include -#define NRAI_FT +#ifndef NRAI_FT +#define NRAI_FT +#endif //NRAI)FT enum{ NRAI_CAN_ID_NMT = 0, @@ -553,6 +555,14 @@ struct nrai_can_ai_read { uint8_t Acc_StartFastCalib; // 24|1@1+ (1,0) [0|1] }; +/* + * The following funcitons ALL unpack the data from the CAN frame corresponding + * to their name into the nrai_can_ai_read struct. + * All functions return: + * -1 on error + * 0 on success + * On error the struct nrai_can_ai_read AND the can_frame are not modified. + */ NRAI_FT int32_t nrai_can_unpack_VCU2AI_Status (struct nrai_can_ai_read *, struct can_frame *); NRAI_FT int32_t nrai_can_unpack_VCU2AI_Steer (struct nrai_can_ai_read *, struct can_frame *); NRAI_FT int32_t nrai_can_unpack_VCU2AI_Speeds (struct nrai_can_ai_read *, struct can_frame *);