Skip to content

Commit 1c3ecfa

Browse files
committed
add IVT to the DBC
1 parent 7ddab26 commit 1c3ecfa

15 files changed

Lines changed: 74 additions & 66 deletions

File tree

BMS/Core/User/Inc/FEB_CAN_IVT.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
* - 0x524: Voltage 3
1111
* - 0x525: Temperature
1212
*
13+
* The frame IDs and byte layout live in the shared CAN library
14+
* (common/FEB_CAN_Library_SN4, message defs IVTCurrent / IVTVoltage1-3 /
15+
* IVTTemperature) and are consumed here via the generated FEB_CAN_IVT_*_FRAME_ID
16+
* macros and feb_can_ivt_*_unpack() functions from feb_can.h.
17+
*
1318
* The IVT sensor provides high-accuracy current and voltage measurements
1419
* for battery management and motor control systems.
1520
*/
@@ -20,22 +25,6 @@
2025
#include <stdint.h>
2126
#include <stdbool.h>
2227

23-
/* ============================================================================
24-
* IVT CAN Message IDs (Isabellenhutte IVT-S standard)
25-
* ============================================================================ */
26-
27-
#define FEB_CAN_ID_IVT_COMMAND 0x411
28-
#define FEB_CAN_ID_IVT_DEBUG 0x510
29-
#define FEB_CAN_ID_IVT_RESPONSE 0x511
30-
#define FEB_CAN_ID_IVT_CURRENT 0x521
31-
#define FEB_CAN_ID_IVT_VOLTAGE_1 0x522
32-
#define FEB_CAN_ID_IVT_VOLTAGE_2 0x523
33-
#define FEB_CAN_ID_IVT_VOLTAGE_3 0x524
34-
#define FEB_CAN_ID_IVT_TEMPERATURE 0x525
35-
#define FEB_CAN_ID_IVT_POWER 0x526
36-
#define FEB_CAN_ID_IVT_CURRENT_COUNTER 0x527
37-
#define FEB_CAN_ID_IVT_ENERGY_COUNTER 0x528
38-
3928
/* ============================================================================
4029
* IVT Data Structure
4130
* ============================================================================ */

BMS/Core/User/Src/FEB_CAN_IVT.c

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "FEB_CAN_IVT.h"
1111
#include "feb_can_lib.h"
12+
#include "feb_can.h"
1213
#include "stm32f4xx_hal.h"
1314
#include "cmsis_compiler.h"
1415
#include <stddef.h>
@@ -33,23 +34,13 @@ static FEB_CAN_IVT_Data_t ivt_data = {0};
3334
* CAN Callback
3435
* ============================================================================ */
3536

36-
/**
37-
* @brief Parse IVT CAN message data
38-
* @param data CAN message data (6 bytes for IVT messages)
39-
* @return Signed 32-bit value from bytes 2-5 (big-endian)
40-
*
41-
* IVT message format:
42-
* - Bytes 0-1: Message counter/ID
43-
* - Bytes 2-5: Signed 32-bit value (big-endian)
44-
*/
45-
static int32_t parse_ivt_value(const uint8_t *data)
46-
{
47-
/* Big-endian to native conversion */
48-
return ((int32_t)data[2] << 24) | ((int32_t)data[3] << 16) | ((int32_t)data[4] << 8) | ((int32_t)data[5]);
49-
}
50-
5137
/**
5238
* @brief IVT CAN RX callback
39+
*
40+
* The IVT-S frames are defined in the shared CAN library
41+
* (common/FEB_CAN_Library_SN4, message defs IVTCurrent / IVTVoltage1-3 /
42+
* IVTTemperature). Decoding is delegated to the generated unpack functions;
43+
* the raw int32 value is then scaled into engineering units below.
5344
*/
5445
static void FEB_CAN_IVT_Callback(FEB_CAN_Instance_t instance, uint32_t can_id, FEB_CAN_ID_Type_t id_type,
5546
const uint8_t *data, uint8_t length, void *user_data)
@@ -58,47 +49,75 @@ static void FEB_CAN_IVT_Callback(FEB_CAN_Instance_t instance, uint32_t can_id, F
5849
(void)id_type;
5950
(void)user_data;
6051

61-
if (length < 6)
62-
{
63-
return; /* IVT messages are 6+ bytes */
64-
}
65-
66-
int32_t raw_value = parse_ivt_value(data);
67-
6852
switch (can_id)
6953
{
70-
case FEB_CAN_ID_IVT_CURRENT:
54+
case FEB_CAN_IVT_CURRENT_FRAME_ID:
55+
{
56+
struct feb_can_ivt_current_t msg;
57+
if (feb_can_ivt_current_unpack(&msg, data, length) < 0)
58+
{
59+
return;
60+
}
7161
/* Current in mA, negate for reversed direction */
72-
ivt_data.current_mA = (float)raw_value * (-0.001f) * 1000.0f;
62+
ivt_data.current_mA = (float)msg.current * (-0.001f) * 1000.0f;
7363
__DMB(); /* Memory barrier to ensure data write completes before timestamp */
7464
ivt_data.last_rx_tick = HAL_GetTick();
7565
break;
66+
}
7667

77-
case FEB_CAN_ID_IVT_VOLTAGE_1:
68+
case FEB_CAN_IVT_VOLTAGE1_FRAME_ID:
69+
{
70+
struct feb_can_ivt_voltage1_t msg;
71+
if (feb_can_ivt_voltage1_unpack(&msg, data, length) < 0)
72+
{
73+
return;
74+
}
7875
/* Voltage 1 (pack voltage) in mV */
79-
ivt_data.voltage_1_mV = (float)raw_value;
76+
ivt_data.voltage_1_mV = (float)msg.voltage1;
8077
__DMB();
8178
ivt_data.last_rx_tick = HAL_GetTick();
8279
break;
80+
}
8381

84-
case FEB_CAN_ID_IVT_VOLTAGE_2:
85-
ivt_data.voltage_2_mV = (float)raw_value;
82+
case FEB_CAN_IVT_VOLTAGE2_FRAME_ID:
83+
{
84+
struct feb_can_ivt_voltage2_t msg;
85+
if (feb_can_ivt_voltage2_unpack(&msg, data, length) < 0)
86+
{
87+
return;
88+
}
89+
ivt_data.voltage_2_mV = (float)msg.voltage2;
8690
__DMB();
8791
ivt_data.last_rx_tick = HAL_GetTick();
8892
break;
93+
}
8994

90-
case FEB_CAN_ID_IVT_VOLTAGE_3:
91-
ivt_data.voltage_3_mV = (float)raw_value;
95+
case FEB_CAN_IVT_VOLTAGE3_FRAME_ID:
96+
{
97+
struct feb_can_ivt_voltage3_t msg;
98+
if (feb_can_ivt_voltage3_unpack(&msg, data, length) < 0)
99+
{
100+
return;
101+
}
102+
ivt_data.voltage_3_mV = (float)msg.voltage3;
92103
__DMB();
93104
ivt_data.last_rx_tick = HAL_GetTick();
94105
break;
106+
}
95107

96-
case FEB_CAN_ID_IVT_TEMPERATURE:
108+
case FEB_CAN_IVT_TEMPERATURE_FRAME_ID:
109+
{
110+
struct feb_can_ivt_temperature_t msg;
111+
if (feb_can_ivt_temperature_unpack(&msg, data, length) < 0)
112+
{
113+
return;
114+
}
97115
/* Temperature in 0.1 degrees C */
98-
ivt_data.temperature_C = (float)raw_value * 0.1f;
116+
ivt_data.temperature_C = (float)msg.temperature * 0.1f;
99117
__DMB();
100118
ivt_data.last_rx_tick = HAL_GetTick();
101119
break;
120+
}
102121

103122
default:
104123
break;
@@ -122,7 +141,7 @@ void FEB_CAN_IVT_Init(void)
122141
/* Register for IVT current message */
123142
FEB_CAN_RX_Params_t rx_params = {
124143
.instance = FEB_CAN_INSTANCE_1,
125-
.can_id = FEB_CAN_ID_IVT_CURRENT,
144+
.can_id = FEB_CAN_IVT_CURRENT_FRAME_ID,
126145
.id_type = FEB_CAN_ID_STD,
127146
.filter_type = FEB_CAN_FILTER_EXACT,
128147
.mask = 0,
@@ -133,19 +152,19 @@ void FEB_CAN_IVT_Init(void)
133152
FEB_CAN_RX_Register(&rx_params);
134153

135154
/* Register for IVT voltage 1 message */
136-
rx_params.can_id = FEB_CAN_ID_IVT_VOLTAGE_1;
155+
rx_params.can_id = FEB_CAN_IVT_VOLTAGE1_FRAME_ID;
137156
FEB_CAN_RX_Register(&rx_params);
138157

139158
/* Register for IVT voltage 2 message */
140-
rx_params.can_id = FEB_CAN_ID_IVT_VOLTAGE_2;
159+
rx_params.can_id = FEB_CAN_IVT_VOLTAGE2_FRAME_ID;
141160
FEB_CAN_RX_Register(&rx_params);
142161

143162
/* Register for IVT voltage 3 message */
144-
rx_params.can_id = FEB_CAN_ID_IVT_VOLTAGE_3;
163+
rx_params.can_id = FEB_CAN_IVT_VOLTAGE3_FRAME_ID;
145164
FEB_CAN_RX_Register(&rx_params);
146165

147166
/* Register for IVT temperature message */
148-
rx_params.can_id = FEB_CAN_ID_IVT_TEMPERATURE;
167+
rx_params.can_id = FEB_CAN_IVT_TEMPERATURE_FRAME_ID;
149168
FEB_CAN_RX_Register(&rx_params);
150169
}
151170

BMS/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.5
1+
1.7.6

DART/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.4
1+
1.7.5

DASH/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.6
1+
1.7.7

DCU/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.4
1+
1.7.5

DCU_Receiver/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.2
1+
1.6.3

LVPDB/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.6
1+
1.7.7

PCU/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.15
1+
1.7.16

Sensor_Nodes/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.5
1+
1.7.6

0 commit comments

Comments
 (0)