diff --git a/CMakeCache.txt b/CMakeCache.txt index c273c5e..106e661 100644 --- a/CMakeCache.txt +++ b/CMakeCache.txt @@ -209,6 +209,9 @@ CMAKE_STRIP:FILEPATH=/usr/bin/strip // Studio IDE projects all commands are done without /nologo. CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE +//No help, variable specified on the command line. +EXPORT_COMPILE_COMMANDs:UNINITIALIZED=ON + //Value Computed by CMake dbc_example_BINARY_DIR:STATIC=/home/coventry/Documents/7166CEM diff --git a/bin/main b/bin/main new file mode 100755 index 0000000..c546fe5 Binary files /dev/null and b/bin/main differ diff --git a/bin/main_test b/bin/main_test new file mode 100755 index 0000000..9d3a824 Binary files /dev/null and b/bin/main_test differ diff --git a/include/signal.h b/include/signal.h index b35297e..43018e2 100644 --- a/include/signal.h +++ b/include/signal.h @@ -19,6 +19,8 @@ struct candata_motor_current_t Curr_value; uint16_t Max_Front_RPM; uint16_t Max_Rear_RPM; + + bool RPM_FRAME_FLAG; bool TRQ_FRAME_FLAG; bool VOLT_FRAME_FLAG; diff --git a/src_autogen/candata.c b/src_autogen/candata.c new file mode 100644 index 0000000..603874b --- /dev/null +++ b/src_autogen/candata.c @@ -0,0 +1,439 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2018-2019 Erik Moqvist + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * This file was generated by cantools version 39.4.0 Sun Dec 17 18:38:47 2023. + */ + +#include + +#include "candata.h" + +static inline uint8_t pack_left_shift_u16( + uint16_t value, + uint8_t shift, + uint8_t mask) +{ + return (uint8_t)((uint8_t)(value << shift) & mask); +} + +static inline uint8_t pack_right_shift_u16( + uint16_t value, + uint8_t shift, + uint8_t mask) +{ + return (uint8_t)((uint8_t)(value >> shift) & mask); +} + +static inline uint16_t unpack_left_shift_u16( + uint8_t value, + uint8_t shift, + uint8_t mask) +{ + return (uint16_t)((uint16_t)(value & mask) << shift); +} + +static inline uint16_t unpack_right_shift_u16( + uint8_t value, + uint8_t shift, + uint8_t mask) +{ + return (uint16_t)((uint16_t)(value & mask) >> shift); +} + +int candata_ai_drive_request_pack( + uint8_t *dst_p, + const struct candata_ai_drive_request_t *src_p, + size_t size) +{ + uint16_t front_trq_request; + uint16_t rear_trq_request; + uint16_t steering_request; + + if (size < 6u) { + return (-EINVAL); + } + + memset(&dst_p[0], 0, 6); + + front_trq_request = (uint16_t)src_p->front_trq_request; + dst_p[0] |= pack_left_shift_u16(front_trq_request, 0u, 0xffu); + dst_p[1] |= pack_right_shift_u16(front_trq_request, 8u, 0xffu); + steering_request = (uint16_t)src_p->steering_request; + dst_p[2] |= pack_left_shift_u16(steering_request, 0u, 0xffu); + dst_p[3] |= pack_right_shift_u16(steering_request, 8u, 0xffu); + rear_trq_request = (uint16_t)src_p->rear_trq_request; + dst_p[4] |= pack_left_shift_u16(rear_trq_request, 0u, 0xffu); + dst_p[5] |= pack_right_shift_u16(rear_trq_request, 8u, 0xffu); + + return (6); +} + +int candata_ai_drive_request_unpack( + struct candata_ai_drive_request_t *dst_p, + const uint8_t *src_p, + size_t size) +{ + uint16_t front_trq_request; + uint16_t rear_trq_request; + uint16_t steering_request; + + if (size < 6u) { + return (-EINVAL); + } + + front_trq_request = unpack_right_shift_u16(src_p[0], 0u, 0xffu); + front_trq_request |= unpack_left_shift_u16(src_p[1], 8u, 0xffu); + dst_p->front_trq_request = (int16_t)front_trq_request; + steering_request = unpack_right_shift_u16(src_p[2], 0u, 0xffu); + steering_request |= unpack_left_shift_u16(src_p[3], 8u, 0xffu); + dst_p->steering_request = (int16_t)steering_request; + rear_trq_request = unpack_right_shift_u16(src_p[4], 0u, 0xffu); + rear_trq_request |= unpack_left_shift_u16(src_p[5], 8u, 0xffu); + dst_p->rear_trq_request = (int16_t)rear_trq_request; + + return (0); +} + +int candata_ai_drive_request_init(struct candata_ai_drive_request_t *msg_p) +{ + if (msg_p == NULL) return -1; + + memset(msg_p, 0, sizeof(struct candata_ai_drive_request_t)); + + return 0; +} + +int16_t candata_ai_drive_request_front_trq_request_encode(double value) +{ + return (int16_t)(value); +} + +double candata_ai_drive_request_front_trq_request_decode(int16_t value) +{ + return ((double)value); +} + +bool candata_ai_drive_request_front_trq_request_is_in_range(int16_t value) +{ + (void)value; + + return (true); +} + +int16_t candata_ai_drive_request_steering_request_encode(double value) +{ + return (int16_t)(value / 0.01); +} + +double candata_ai_drive_request_steering_request_decode(int16_t value) +{ + return ((double)value * 0.01); +} + +bool candata_ai_drive_request_steering_request_is_in_range(int16_t value) +{ + return ((value >= -35) && (value <= 35)); +} + +int16_t candata_ai_drive_request_rear_trq_request_encode(double value) +{ + return (int16_t)(value); +} + +double candata_ai_drive_request_rear_trq_request_decode(int16_t value) +{ + return ((double)value); +} + +bool candata_ai_drive_request_rear_trq_request_is_in_range(int16_t value) +{ + (void)value; + + return (true); +} + +int candata_vcu_wheel_speeds_pack( + uint8_t *dst_p, + const struct candata_vcu_wheel_speeds_t *src_p, + size_t size) +{ + if (size < 8u) { + return (-EINVAL); + } + + memset(&dst_p[0], 0, 8); + + dst_p[0] |= pack_left_shift_u16(src_p->fl_wheel_speed, 0u, 0xffu); + dst_p[1] |= pack_right_shift_u16(src_p->fl_wheel_speed, 8u, 0xffu); + dst_p[2] |= pack_left_shift_u16(src_p->fr_wheel_speed, 0u, 0xffu); + dst_p[3] |= pack_right_shift_u16(src_p->fr_wheel_speed, 8u, 0xffu); + dst_p[4] |= pack_left_shift_u16(src_p->rl_wheel_speed, 0u, 0xffu); + dst_p[5] |= pack_right_shift_u16(src_p->rl_wheel_speed, 8u, 0xffu); + dst_p[6] |= pack_left_shift_u16(src_p->rr_wheel_speed, 0u, 0xffu); + dst_p[7] |= pack_right_shift_u16(src_p->rr_wheel_speed, 8u, 0xffu); + + return (8); +} + +int candata_vcu_wheel_speeds_unpack( + struct candata_vcu_wheel_speeds_t *dst_p, + const uint8_t *src_p, + size_t size) +{ + if (size < 8u) { + return (-EINVAL); + } + + dst_p->fl_wheel_speed = unpack_right_shift_u16(src_p[0], 0u, 0xffu); + dst_p->fl_wheel_speed |= unpack_left_shift_u16(src_p[1], 8u, 0xffu); + dst_p->fr_wheel_speed = unpack_right_shift_u16(src_p[2], 0u, 0xffu); + dst_p->fr_wheel_speed |= unpack_left_shift_u16(src_p[3], 8u, 0xffu); + dst_p->rl_wheel_speed = unpack_right_shift_u16(src_p[4], 0u, 0xffu); + dst_p->rl_wheel_speed |= unpack_left_shift_u16(src_p[5], 8u, 0xffu); + dst_p->rr_wheel_speed = unpack_right_shift_u16(src_p[6], 0u, 0xffu); + dst_p->rr_wheel_speed |= unpack_left_shift_u16(src_p[7], 8u, 0xffu); + + return (0); +} + +int candata_vcu_wheel_speeds_init(struct candata_vcu_wheel_speeds_t *msg_p) +{ + if (msg_p == NULL) return -1; + + memset(msg_p, 0, sizeof(struct candata_vcu_wheel_speeds_t)); + + return 0; +} + +uint16_t candata_vcu_wheel_speeds_fl_wheel_speed_encode(double value) +{ + return (uint16_t)(value / 0.1); +} + +double candata_vcu_wheel_speeds_fl_wheel_speed_decode(uint16_t value) +{ + return ((double)value * 0.1); +} + +bool candata_vcu_wheel_speeds_fl_wheel_speed_is_in_range(uint16_t value) +{ + (void)value; + + return (true); +} + +uint16_t candata_vcu_wheel_speeds_fr_wheel_speed_encode(double value) +{ + return (uint16_t)(value / 0.1); +} + +double candata_vcu_wheel_speeds_fr_wheel_speed_decode(uint16_t value) +{ + return ((double)value * 0.1); +} + +bool candata_vcu_wheel_speeds_fr_wheel_speed_is_in_range(uint16_t value) +{ + (void)value; + + return (true); +} + +uint16_t candata_vcu_wheel_speeds_rl_wheel_speed_encode(double value) +{ + return (uint16_t)(value / 0.1); +} + +double candata_vcu_wheel_speeds_rl_wheel_speed_decode(uint16_t value) +{ + return ((double)value * 0.1); +} + +bool candata_vcu_wheel_speeds_rl_wheel_speed_is_in_range(uint16_t value) +{ + (void)value; + + return (true); +} + +uint16_t candata_vcu_wheel_speeds_rr_wheel_speed_encode(double value) +{ + return (uint16_t)(value / 0.1); +} + +double candata_vcu_wheel_speeds_rr_wheel_speed_decode(uint16_t value) +{ + return ((double)value * 0.1); +} + +bool candata_vcu_wheel_speeds_rr_wheel_speed_is_in_range(uint16_t value) +{ + (void)value; + + return (true); +} + +int candata_vcu_battery_pack( + uint8_t *dst_p, + const struct candata_vcu_battery_t *src_p, + size_t size) +{ + if (size < 2u) { + return (-EINVAL); + } + + memset(&dst_p[0], 0, 2); + + dst_p[0] |= pack_left_shift_u16(src_p->voltage, 0u, 0xffu); + dst_p[1] |= pack_right_shift_u16(src_p->voltage, 8u, 0xffu); + + return (2); +} + +int candata_vcu_battery_unpack( + struct candata_vcu_battery_t *dst_p, + const uint8_t *src_p, + size_t size) +{ + if (size < 2u) { + return (-EINVAL); + } + + dst_p->voltage = unpack_right_shift_u16(src_p[0], 0u, 0xffu); + dst_p->voltage |= unpack_left_shift_u16(src_p[1], 8u, 0xffu); + + return (0); +} + +int candata_vcu_battery_init(struct candata_vcu_battery_t *msg_p) +{ + if (msg_p == NULL) return -1; + + memset(msg_p, 0, sizeof(struct candata_vcu_battery_t)); + + return 0; +} + +uint16_t candata_vcu_battery_voltage_encode(double value) +{ + return (uint16_t)(value / 0.001); +} + +double candata_vcu_battery_voltage_decode(uint16_t value) +{ + return ((double)value * 0.001); +} + +bool candata_vcu_battery_voltage_is_in_range(uint16_t value) +{ + return (value <= 13000u); +} + +int candata_motor_current_pack( + uint8_t *dst_p, + const struct candata_motor_current_t *src_p, + size_t size) +{ + uint16_t front_current; + uint16_t rear_current; + + if (size < 4u) { + return (-EINVAL); + } + + memset(&dst_p[0], 0, 4); + + front_current = (uint16_t)src_p->front_current; + dst_p[0] |= pack_left_shift_u16(front_current, 0u, 0xffu); + dst_p[1] |= pack_right_shift_u16(front_current, 8u, 0xffu); + rear_current = (uint16_t)src_p->rear_current; + dst_p[2] |= pack_left_shift_u16(rear_current, 0u, 0xffu); + dst_p[3] |= pack_right_shift_u16(rear_current, 8u, 0xffu); + + return (4); +} + +int candata_motor_current_unpack( + struct candata_motor_current_t *dst_p, + const uint8_t *src_p, + size_t size) +{ + uint16_t front_current; + uint16_t rear_current; + + if (size < 4u) { + return (-EINVAL); + } + + front_current = unpack_right_shift_u16(src_p[0], 0u, 0xffu); + front_current |= unpack_left_shift_u16(src_p[1], 8u, 0xffu); + dst_p->front_current = (int16_t)front_current; + rear_current = unpack_right_shift_u16(src_p[2], 0u, 0xffu); + rear_current |= unpack_left_shift_u16(src_p[3], 8u, 0xffu); + dst_p->rear_current = (int16_t)rear_current; + + return (0); +} + +int candata_motor_current_init(struct candata_motor_current_t *msg_p) +{ + if (msg_p == NULL) return -1; + + memset(msg_p, 0, sizeof(struct candata_motor_current_t)); + + return 0; +} + +int16_t candata_motor_current_front_current_encode(double value) +{ + return (int16_t)(value); +} + +double candata_motor_current_front_current_decode(int16_t value) +{ + return ((double)value); +} + +bool candata_motor_current_front_current_is_in_range(int16_t value) +{ + return ((value >= -30000) && (value <= 30000)); +} + +int16_t candata_motor_current_rear_current_encode(double value) +{ + return (int16_t)(value); +} + +double candata_motor_current_rear_current_decode(int16_t value) +{ + return ((double)value); +} + +bool candata_motor_current_rear_current_is_in_range(int16_t value) +{ + return ((value >= -30000) && (value <= 30000)); +} diff --git a/src_autogen/candata.h b/src_autogen/candata.h new file mode 100644 index 0000000..e74e53e --- /dev/null +++ b/src_autogen/candata.h @@ -0,0 +1,609 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2018-2019 Erik Moqvist + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * This file was generated by cantools version 39.4.0 Sun Dec 17 18:38:47 2023. + */ + +#ifndef CANDATA_H +#define CANDATA_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#ifndef EINVAL +# define EINVAL 22 +#endif + +/* Frame ids. */ +#define CANDATA_AI_DRIVE_REQUEST_FRAME_ID (0x521u) +#define CANDATA_VCU_WHEEL_SPEEDS_FRAME_ID (0x525u) +#define CANDATA_VCU_BATTERY_FRAME_ID (0x526u) +#define CANDATA_MOTOR_CURRENT_FRAME_ID (0x320u) + +/* Frame lengths in bytes. */ +#define CANDATA_AI_DRIVE_REQUEST_LENGTH (6u) +#define CANDATA_VCU_WHEEL_SPEEDS_LENGTH (8u) +#define CANDATA_VCU_BATTERY_LENGTH (2u) +#define CANDATA_MOTOR_CURRENT_LENGTH (4u) + +/* Extended or standard frame types. */ +#define CANDATA_AI_DRIVE_REQUEST_IS_EXTENDED (0) +#define CANDATA_VCU_WHEEL_SPEEDS_IS_EXTENDED (0) +#define CANDATA_VCU_BATTERY_IS_EXTENDED (0) +#define CANDATA_MOTOR_CURRENT_IS_EXTENDED (0) + +/* Frame cycle times in milliseconds. */ + + +/* Signal choices. */ + + +/* Frame Names. */ +#define CANDATA_AI_DRIVE_REQUEST_NAME "AI_DRIVE_REQUEST" +#define CANDATA_VCU_WHEEL_SPEEDS_NAME "VCU_WHEEL_SPEEDS" +#define CANDATA_VCU_BATTERY_NAME "VCU_BATTERY" +#define CANDATA_MOTOR_CURRENT_NAME "MOTOR_CURRENT" + +/* Signal Names. */ +#define CANDATA_AI_DRIVE_REQUEST_FRONT_TRQ_REQUEST_NAME "FRONT_TRQ_REQUEST" +#define CANDATA_AI_DRIVE_REQUEST_STEERING_REQUEST_NAME "STEERING_REQUEST" +#define CANDATA_AI_DRIVE_REQUEST_REAR_TRQ_REQUEST_NAME "REAR_TRQ_REQUEST" +#define CANDATA_VCU_WHEEL_SPEEDS_FL_WHEEL_SPEED_NAME "FL_WHEEL_SPEED" +#define CANDATA_VCU_WHEEL_SPEEDS_FR_WHEEL_SPEED_NAME "FR_WHEEL_SPEED" +#define CANDATA_VCU_WHEEL_SPEEDS_RL_WHEEL_SPEED_NAME "RL_WHEEL_SPEED" +#define CANDATA_VCU_WHEEL_SPEEDS_RR_WHEEL_SPEED_NAME "RR_WHEEL_SPEED" +#define CANDATA_VCU_BATTERY_VOLTAGE_NAME "VOLTAGE" +#define CANDATA_MOTOR_CURRENT_FRONT_CURRENT_NAME "FRONT_CURRENT" +#define CANDATA_MOTOR_CURRENT_REAR_CURRENT_NAME "REAR_CURRENT" + +/** + * Signals in message AI_DRIVE_REQUEST. + * + * All signal values are as on the CAN bus. + */ +struct candata_ai_drive_request_t { + /** + * Range: -32768..32767 (-32768..32767 Nm) + * Scale: 1 + * Offset: 0 + */ + int16_t front_trq_request; + + /** + * Range: -35..35 (-0.35..0.35 rad) + * Scale: 0.01 + * Offset: 0 + */ + int16_t steering_request; + + /** + * Range: -32768..32767 (-32768..32767 Nm) + * Scale: 1 + * Offset: 0 + */ + int16_t rear_trq_request; +}; + +/** + * Signals in message VCU_WHEEL_SPEEDS. + * + * All signal values are as on the CAN bus. + */ +struct candata_vcu_wheel_speeds_t { + /** + * Range: 0..655350 (0..65535 rpm) + * Scale: 0.1 + * Offset: 0 + */ + uint16_t fl_wheel_speed; + + /** + * Range: 0..655350 (0..65535 rpm) + * Scale: 0.1 + * Offset: 0 + */ + uint16_t fr_wheel_speed; + + /** + * Range: 0..655350 (0..65535 rpm) + * Scale: 0.1 + * Offset: 0 + */ + uint16_t rl_wheel_speed; + + /** + * Range: 0..655350 (0..65535 rpm) + * Scale: 0.1 + * Offset: 0 + */ + uint16_t rr_wheel_speed; +}; + +/** + * Signals in message VCU_BATTERY. + * + * All signal values are as on the CAN bus. + */ +struct candata_vcu_battery_t { + /** + * Range: 0..13000 (0..13 V) + * Scale: 0.001 + * Offset: 0 + */ + uint16_t voltage; +}; + +/** + * Signals in message MOTOR_CURRENT. + * + * All signal values are as on the CAN bus. + */ +struct candata_motor_current_t { + /** + * Range: -30000..30000 (-30000..30000 mA) + * Scale: 1 + * Offset: 0 + */ + int16_t front_current; + + /** + * Range: -30000..30000 (-30000..30000 mA) + * Scale: 1 + * Offset: 0 + */ + int16_t rear_current; +}; + +/** + * Pack message AI_DRIVE_REQUEST. + * + * @param[out] dst_p Buffer to pack the message into. + * @param[in] src_p Data to pack. + * @param[in] size Size of dst_p. + * + * @return Size of packed data, or negative error code. + */ +int candata_ai_drive_request_pack( + uint8_t *dst_p, + const struct candata_ai_drive_request_t *src_p, + size_t size); + +/** + * Unpack message AI_DRIVE_REQUEST. + * + * @param[out] dst_p Object to unpack the message into. + * @param[in] src_p Message to unpack. + * @param[in] size Size of src_p. + * + * @return zero(0) or negative error code. + */ +int candata_ai_drive_request_unpack( + struct candata_ai_drive_request_t *dst_p, + const uint8_t *src_p, + size_t size); + +/** + * Init message fields to default values from AI_DRIVE_REQUEST. + * + * @param[in] msg_p Message to init. + * + * @return zero(0) on success or (-1) in case of nullptr argument. + */ +int candata_ai_drive_request_init(struct candata_ai_drive_request_t *msg_p); + +/** + * Encode given signal by applying scaling and offset. + * + * @param[in] value Signal to encode. + * + * @return Encoded signal. + */ +int16_t candata_ai_drive_request_front_trq_request_encode(double value); + +/** + * Decode given signal by applying scaling and offset. + * + * @param[in] value Signal to decode. + * + * @return Decoded signal. + */ +double candata_ai_drive_request_front_trq_request_decode(int16_t value); + +/** + * Check that given signal is in allowed range. + * + * @param[in] value Signal to check. + * + * @return true if in range, false otherwise. + */ +bool candata_ai_drive_request_front_trq_request_is_in_range(int16_t value); + +/** + * Encode given signal by applying scaling and offset. + * + * @param[in] value Signal to encode. + * + * @return Encoded signal. + */ +int16_t candata_ai_drive_request_steering_request_encode(double value); + +/** + * Decode given signal by applying scaling and offset. + * + * @param[in] value Signal to decode. + * + * @return Decoded signal. + */ +double candata_ai_drive_request_steering_request_decode(int16_t value); + +/** + * Check that given signal is in allowed range. + * + * @param[in] value Signal to check. + * + * @return true if in range, false otherwise. + */ +bool candata_ai_drive_request_steering_request_is_in_range(int16_t value); + +/** + * Encode given signal by applying scaling and offset. + * + * @param[in] value Signal to encode. + * + * @return Encoded signal. + */ +int16_t candata_ai_drive_request_rear_trq_request_encode(double value); + +/** + * Decode given signal by applying scaling and offset. + * + * @param[in] value Signal to decode. + * + * @return Decoded signal. + */ +double candata_ai_drive_request_rear_trq_request_decode(int16_t value); + +/** + * Check that given signal is in allowed range. + * + * @param[in] value Signal to check. + * + * @return true if in range, false otherwise. + */ +bool candata_ai_drive_request_rear_trq_request_is_in_range(int16_t value); + +/** + * Pack message VCU_WHEEL_SPEEDS. + * + * @param[out] dst_p Buffer to pack the message into. + * @param[in] src_p Data to pack. + * @param[in] size Size of dst_p. + * + * @return Size of packed data, or negative error code. + */ +int candata_vcu_wheel_speeds_pack( + uint8_t *dst_p, + const struct candata_vcu_wheel_speeds_t *src_p, + size_t size); + +/** + * Unpack message VCU_WHEEL_SPEEDS. + * + * @param[out] dst_p Object to unpack the message into. + * @param[in] src_p Message to unpack. + * @param[in] size Size of src_p. + * + * @return zero(0) or negative error code. + */ +int candata_vcu_wheel_speeds_unpack( + struct candata_vcu_wheel_speeds_t *dst_p, + const uint8_t *src_p, + size_t size); + +/** + * Init message fields to default values from VCU_WHEEL_SPEEDS. + * + * @param[in] msg_p Message to init. + * + * @return zero(0) on success or (-1) in case of nullptr argument. + */ +int candata_vcu_wheel_speeds_init(struct candata_vcu_wheel_speeds_t *msg_p); + +/** + * Encode given signal by applying scaling and offset. + * + * @param[in] value Signal to encode. + * + * @return Encoded signal. + */ +uint16_t candata_vcu_wheel_speeds_fl_wheel_speed_encode(double value); + +/** + * Decode given signal by applying scaling and offset. + * + * @param[in] value Signal to decode. + * + * @return Decoded signal. + */ +double candata_vcu_wheel_speeds_fl_wheel_speed_decode(uint16_t value); + +/** + * Check that given signal is in allowed range. + * + * @param[in] value Signal to check. + * + * @return true if in range, false otherwise. + */ +bool candata_vcu_wheel_speeds_fl_wheel_speed_is_in_range(uint16_t value); + +/** + * Encode given signal by applying scaling and offset. + * + * @param[in] value Signal to encode. + * + * @return Encoded signal. + */ +uint16_t candata_vcu_wheel_speeds_fr_wheel_speed_encode(double value); + +/** + * Decode given signal by applying scaling and offset. + * + * @param[in] value Signal to decode. + * + * @return Decoded signal. + */ +double candata_vcu_wheel_speeds_fr_wheel_speed_decode(uint16_t value); + +/** + * Check that given signal is in allowed range. + * + * @param[in] value Signal to check. + * + * @return true if in range, false otherwise. + */ +bool candata_vcu_wheel_speeds_fr_wheel_speed_is_in_range(uint16_t value); + +/** + * Encode given signal by applying scaling and offset. + * + * @param[in] value Signal to encode. + * + * @return Encoded signal. + */ +uint16_t candata_vcu_wheel_speeds_rl_wheel_speed_encode(double value); + +/** + * Decode given signal by applying scaling and offset. + * + * @param[in] value Signal to decode. + * + * @return Decoded signal. + */ +double candata_vcu_wheel_speeds_rl_wheel_speed_decode(uint16_t value); + +/** + * Check that given signal is in allowed range. + * + * @param[in] value Signal to check. + * + * @return true if in range, false otherwise. + */ +bool candata_vcu_wheel_speeds_rl_wheel_speed_is_in_range(uint16_t value); + +/** + * Encode given signal by applying scaling and offset. + * + * @param[in] value Signal to encode. + * + * @return Encoded signal. + */ +uint16_t candata_vcu_wheel_speeds_rr_wheel_speed_encode(double value); + +/** + * Decode given signal by applying scaling and offset. + * + * @param[in] value Signal to decode. + * + * @return Decoded signal. + */ +double candata_vcu_wheel_speeds_rr_wheel_speed_decode(uint16_t value); + +/** + * Check that given signal is in allowed range. + * + * @param[in] value Signal to check. + * + * @return true if in range, false otherwise. + */ +bool candata_vcu_wheel_speeds_rr_wheel_speed_is_in_range(uint16_t value); + +/** + * Pack message VCU_BATTERY. + * + * @param[out] dst_p Buffer to pack the message into. + * @param[in] src_p Data to pack. + * @param[in] size Size of dst_p. + * + * @return Size of packed data, or negative error code. + */ +int candata_vcu_battery_pack( + uint8_t *dst_p, + const struct candata_vcu_battery_t *src_p, + size_t size); + +/** + * Unpack message VCU_BATTERY. + * + * @param[out] dst_p Object to unpack the message into. + * @param[in] src_p Message to unpack. + * @param[in] size Size of src_p. + * + * @return zero(0) or negative error code. + */ +int candata_vcu_battery_unpack( + struct candata_vcu_battery_t *dst_p, + const uint8_t *src_p, + size_t size); + +/** + * Init message fields to default values from VCU_BATTERY. + * + * @param[in] msg_p Message to init. + * + * @return zero(0) on success or (-1) in case of nullptr argument. + */ +int candata_vcu_battery_init(struct candata_vcu_battery_t *msg_p); + +/** + * Encode given signal by applying scaling and offset. + * + * @param[in] value Signal to encode. + * + * @return Encoded signal. + */ +uint16_t candata_vcu_battery_voltage_encode(double value); + +/** + * Decode given signal by applying scaling and offset. + * + * @param[in] value Signal to decode. + * + * @return Decoded signal. + */ +double candata_vcu_battery_voltage_decode(uint16_t value); + +/** + * Check that given signal is in allowed range. + * + * @param[in] value Signal to check. + * + * @return true if in range, false otherwise. + */ +bool candata_vcu_battery_voltage_is_in_range(uint16_t value); + +/** + * Pack message MOTOR_CURRENT. + * + * @param[out] dst_p Buffer to pack the message into. + * @param[in] src_p Data to pack. + * @param[in] size Size of dst_p. + * + * @return Size of packed data, or negative error code. + */ +int candata_motor_current_pack( + uint8_t *dst_p, + const struct candata_motor_current_t *src_p, + size_t size); + +/** + * Unpack message MOTOR_CURRENT. + * + * @param[out] dst_p Object to unpack the message into. + * @param[in] src_p Message to unpack. + * @param[in] size Size of src_p. + * + * @return zero(0) or negative error code. + */ +int candata_motor_current_unpack( + struct candata_motor_current_t *dst_p, + const uint8_t *src_p, + size_t size); + +/** + * Init message fields to default values from MOTOR_CURRENT. + * + * @param[in] msg_p Message to init. + * + * @return zero(0) on success or (-1) in case of nullptr argument. + */ +int candata_motor_current_init(struct candata_motor_current_t *msg_p); + +/** + * Encode given signal by applying scaling and offset. + * + * @param[in] value Signal to encode. + * + * @return Encoded signal. + */ +int16_t candata_motor_current_front_current_encode(double value); + +/** + * Decode given signal by applying scaling and offset. + * + * @param[in] value Signal to decode. + * + * @return Decoded signal. + */ +double candata_motor_current_front_current_decode(int16_t value); + +/** + * Check that given signal is in allowed range. + * + * @param[in] value Signal to check. + * + * @return true if in range, false otherwise. + */ +bool candata_motor_current_front_current_is_in_range(int16_t value); + +/** + * Encode given signal by applying scaling and offset. + * + * @param[in] value Signal to encode. + * + * @return Encoded signal. + */ +int16_t candata_motor_current_rear_current_encode(double value); + +/** + * Decode given signal by applying scaling and offset. + * + * @param[in] value Signal to decode. + * + * @return Decoded signal. + */ +double candata_motor_current_rear_current_decode(int16_t value); + +/** + * Check that given signal is in allowed range. + * + * @param[in] value Signal to check. + * + * @return true if in range, false otherwise. + */ +bool candata_motor_current_rear_current_is_in_range(int16_t value); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tidy-output.log b/tidy-output.log new file mode 100644 index 0000000..443c96f --- /dev/null +++ b/tidy-output.log @@ -0,0 +1,184 @@ +/home/coventry/Documents/7166CEM/src/main.c:1:1: warning: system include math.h not allowed [llvmlibc-restrict-system-libc-headers] +#include +^~~~~~~~~~~~~~~~~ +/home/coventry/Documents/7166CEM/src/main.c:2:1: warning: system include stdio.h not allowed [llvmlibc-restrict-system-libc-headers] +#include +^~~~~~~~~~~~~~~~~~ +/home/coventry/Documents/7166CEM/src/main.c:3:1: warning: system include stdlib.h not allowed [llvmlibc-restrict-system-libc-headers] +#include +^~~~~~~~~~~~~~~~~~~ +/home/coventry/Documents/7166CEM/src/main.c:4:1: warning: system include string.h not allowed [llvmlibc-restrict-system-libc-headers] +#include +^~~~~~~~~~~~~~~~~~~ +/home/coventry/Documents/7166CEM/src/main.c:5:1: warning: system include unistd.h not allowed [llvmlibc-restrict-system-libc-headers] +#include +^~~~~~~~~~~~~~~~~~~ +/home/coventry/Documents/7166CEM/src/main.c:7:1: warning: system include linux/can.h not allowed [llvmlibc-restrict-system-libc-headers] +#include +^~~~~~~~~~~~~~~~~~~~~~ +/home/coventry/Documents/7166CEM/src/main.c:8:1: warning: system include linux/can/raw.h not allowed [llvmlibc-restrict-system-libc-headers] +#include +^~~~~~~~~~~~~~~~~~~~~~~~~~ +/home/coventry/Documents/7166CEM/src/main.c:10:10: error: 'can_wrap.h' file not found [clang-diagnostic-error] +#include "can_wrap.h" + ^~~~~~~~~~~~ +/home/coventry/Documents/7166CEM/src/main.c:12:1: warning: system include signal.h not allowed [llvmlibc-restrict-system-libc-headers] +#include "signal.h" +^~~~~~~~~~~~~~~~~~~ +/home/coventry/Documents/7166CEM/src/main.c:17:3: warning: if with identical then and else branches [bugprone-branch-clone] + if (rpm.fl_wheel_speed > rpm.fr_wheel_speed) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:24:3: note: else branch starts here + else { + ^ +/home/coventry/Documents/7166CEM/src/main.c:30:3: warning: if with identical then and else branches [bugprone-branch-clone] + if (rpm.rl_wheel_speed > rpm.rr_wheel_speed) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:37:3: note: else branch starts here + else { + ^ +/home/coventry/Documents/7166CEM/src/main.c:56:16: warning: variable 'Front_Req' is not initialized [cppcoreguidelines-init-variables] + const float Front_Req = Initilize; + ^ + = NAN +/home/coventry/Documents/7166CEM/src/main.c:57:16: warning: variable 'Steer_Req' is not initialized [cppcoreguidelines-init-variables] + const float Steer_Req = Initilize; + ^ + = NAN +/home/coventry/Documents/7166CEM/src/main.c:58:17: warning: variable 'Rear_req' is not initialized [cppcoreguidelines-init-variables] + const float Rear_req = Initilize; + ^ + = NAN +/home/coventry/Documents/7166CEM/src/main.c:82:16: warning: variable 'Bat_Value' is not initialized [cppcoreguidelines-init-variables] + const double Bat_Value = + ^ + = NAN +/home/coventry/Documents/7166CEM/src/main.c:95:6: warning: function 'RPM_Battery_LIMITER' has cognitive complexity of 68 (threshold 25) [readability-function-cognitive-complexity] +void RPM_Battery_LIMITER() { + ^ +/home/coventry/Documents/7166CEM/src/main.c:98:3: note: +1, including nesting penalty of 0, nesting level increased to 1 + if (Vol_value.voltage >= 2.8) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:100:5: note: +2, including nesting penalty of 1, nesting level increased to 2 + if (Trq_Req.front_trq_request > 0) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:101:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Front_RPM > 700) && (Trq_Req.front_trq_request > 50)) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:104:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Front_RPM <= 700) && (Max_Front_RPM > 600) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:108:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Front_RPM <= 600) && (Max_Front_RPM > 500) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:113:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Front_RPM <= 500) && (Max_Front_RPM > 400) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:117:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Front_RPM <= 400) && (Max_Front_RPM > 300) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:124:5: note: +1, nesting level increased to 2 + else { + ^ +/home/coventry/Documents/7166CEM/src/main.c:126:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Front_RPM > 700) && (abs(Trq_Req.front_trq_request) > 50)) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:129:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Front_RPM <= 700) && (Max_Front_RPM > 600) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:133:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Front_RPM <= 600) && (Max_Front_RPM > 500) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:138:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Front_RPM <= 500) && (Max_Front_RPM > 400) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:142:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Front_RPM <= 400) && (Max_Front_RPM > 300) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:150:5: note: +2, including nesting penalty of 1, nesting level increased to 2 + if (Trq_Req.rear_trq_request > 0) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:151:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Rear_RPM > 700) && (Trq_Req.rear_trq_request > 50)) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:154:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Rear_RPM <= 700) && (Max_Rear_RPM > 600) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:158:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Rear_RPM <= 600) && (Max_Rear_RPM > 500) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:163:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Rear_RPM <= 500) && (Max_Rear_RPM > 400) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:167:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Rear_RPM <= 400) && (Max_Rear_RPM > 300) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:174:5: note: +1, nesting level increased to 2 + else { + ^ +/home/coventry/Documents/7166CEM/src/main.c:176:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Rear_RPM > 700) && (abs(Trq_Req.rear_trq_request) > 50)) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:179:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Rear_RPM <= 700) && (Max_Rear_RPM > 600) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:183:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Rear_RPM <= 600) && (Max_Rear_RPM > 500) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:188:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Rear_RPM <= 500) && (Max_Rear_RPM > 400) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:192:7: note: +3, including nesting penalty of 2, nesting level increased to 3 + if ((Max_Rear_RPM <= 400) && (Max_Rear_RPM > 300) && + ^ +/home/coventry/Documents/7166CEM/src/main.c:197:5: note: +1, nesting level increased to 1 + } else { + ^ +/home/coventry/Documents/7166CEM/src/main.c:100:5: warning: if with identical then and else branches [bugprone-branch-clone] + if (Trq_Req.front_trq_request > 0) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:124:5: note: else branch starts here + else { + ^ +/home/coventry/Documents/7166CEM/src/main.c:150:5: warning: if with identical then and else branches [bugprone-branch-clone] + if (Trq_Req.rear_trq_request > 0) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:174:5: note: else branch starts here + else { + ^ +/home/coventry/Documents/7166CEM/src/main.c:210:16: warning: variable 'Front_Motor' is not initialized [cppcoreguidelines-init-variables] + const double Front_Motor = + ^ + = NAN +/home/coventry/Documents/7166CEM/src/main.c:215:16: warning: variable 'Rear_Motor' is not initialized [cppcoreguidelines-init-variables] + const double Rear_Motor = + ^ + = NAN +/home/coventry/Documents/7166CEM/src/main.c:226:13: warning: variable 'canSocket' is not initialized [cppcoreguidelines-init-variables] + const int canSocket = can_connect(canChannel, false); + ^ + = 0 +/home/coventry/Documents/7166CEM/src/main.c:241:3: warning: kernel performance could be improved by unrolling this loop with a '#pragma unroll' directive [altera-unroll-loops] + for (int i = 0; i < frame0.can_dlc; ++i) + ^ +/home/coventry/Documents/7166CEM/src/main.c:241:43: warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements] + for (int i = 0; i < frame0.can_dlc; ++i) + ^ + { +/home/coventry/Documents/7166CEM/src/main.c:245:38: warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements] + if (!can_write(canSocket, &frame0)) + ^ + { +/home/coventry/Documents/7166CEM/src/main.c:247:3: warning: function is not thread safe [concurrency-mt-unsafe] + sleep(1); + ^ +/home/coventry/Documents/7166CEM/src/main.c:272:14: warning: parameter 'argc' is unused [misc-unused-parameters] +int main(int argc, char *argv[]) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:272:26: warning: parameter 'argv' is unused [misc-unused-parameters] +int main(int argc, char *argv[]) { + ^ +/home/coventry/Documents/7166CEM/src/main.c:275:13: warning: variable 'canSocket' is not initialized [cppcoreguidelines-init-variables] + const int canSocket = can_connect(canChannel, false); + ^ + = 0