From db19a82342b2e961477f5aa5bc14e542ac711f3b Mon Sep 17 00:00:00 2001 From: Xiao Pan Date: Sun, 4 May 2025 15:31:15 -0700 Subject: Using new SR16-CustomBMS repo .dbc file https://github.com/spartanracingelectric/SR16-CustomBMS/blob/main/SR-16%20Custom%20BMS.dbc Edited some lines at the .dbc file head to make dbcc work, maybe wrong. --- mycan.c | 317 ++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 208 insertions(+), 109 deletions(-) (limited to 'mycan.c') diff --git a/mycan.c b/mycan.c index 99063f7..3747efb 100644 --- a/mycan.c +++ b/mycan.c @@ -34,6 +34,9 @@ cansend vcan0 680#00.FF.02.00.02.00.02.00 #include "all_SRE_edited.h" +#define CAN_VOLT_LEN 24 +#define CAN_TEMP_LEN 16 + // https://github.com/howerj/dbcc MIT static uint64_t u64_from_can_msg(const uint8_t m[8]) { return ((uint64_t)m[7] << 56) | ((uint64_t)m[6] << 48) | ((uint64_t)m[5] << 40) | ((uint64_t)m[4] << 32) @@ -103,18 +106,18 @@ int main(int argc, char **argv) } //4.Define receive rules - // 24 (voltage) + 12 (temp) - struct can_filter rfilter[36]; + // 24 (voltage) + 16 (temp) + struct can_filter rfilter[CAN_VOLT_LEN+CAN_TEMP_LEN]; rfilter[0].can_id = 0x630; rfilter[0].can_mask = CAN_SFF_MASK; - rfilter[24].can_id = 0x680; - rfilter[24].can_mask = CAN_SFF_MASK; - for(int i=1;i<24;i++) + rfilter[CAN_VOLT_LEN].can_id = 0x680; + rfilter[CAN_VOLT_LEN].can_mask = CAN_SFF_MASK; + for(int i=1;i 0) { double out; - uint16_t iout; + uint8_t iout; FILE * fp; // try FIFO, socket and other file types maybe better, not sure @@ -137,15 +140,15 @@ int main(int argc, char **argv) exit(1); } - //printf("can_id = 0x%X\r\ncan_dlc = %d \r\n", frame.can_id, frame.can_dlc); - //for(int i = 0; i < 8; i++) - // printf("data[%d] = %d\r\n", i, frame.data[i]); + printf("can_id = 0x%X\r\ncan_dlc = %d \r\n", frame.can_id, frame.can_dlc); + for(int i = 0; i < 8; i++) + printf("data[%d] = %d\r\n", i, frame.data[i]); can_message_u64 = u64_from_can_msg(frame.data); t=time(NULL); unpack_message(&obj,frame.can_id,can_message_u64,frame.can_dlc,t); - //printf("my prints:\n"); - //print_message(&obj, frame.can_id, stdout); - //printf("my timestamp: %u\n", t); + printf("my prints:\n"); + print_message(&obj, frame.can_id, stdout); + printf("my timestamp: %u\n", t); if(t>t_before) { t_before=t; @@ -343,102 +346,198 @@ int main(int argc, char **argv) fprintf(fp,",%6.4f",out); decode_can_0x647_BMS_M8_Cell_12_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); - decode_can_0x680_BMS_M1_Cell_1_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x680_BMS_M1_Cell_2_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x680_BMS_M1_Cell_3_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x680_BMS_M1_Cell_4_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x681_BMS_M1_Cell_5_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x681_BMS_M1_Cell_6_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x681_BMS_M1_Cell_7_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x681_BMS_M1_Cell_8_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x682_BMS_M1_Cell_9_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x682_BMS_M1_Cell_10_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x682_BMS_M1_Cell_11_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x682_BMS_M1_Cell_12_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x683_BMS_M2_Cell_1_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x683_BMS_M2_Cell_2_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x683_BMS_M2_Cell_3_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x683_BMS_M2_Cell_4_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x684_BMS_M2_Cell_5_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x684_BMS_M2_Cell_6_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x684_BMS_M2_Cell_7_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x684_BMS_M2_Cell_8_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x685_BMS_M2_Cell_9_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x685_BMS_M2_Cell_10_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x685_BMS_M2_Cell_11_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x685_BMS_M2_Cell_12_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x686_BMS_M3_Cell_1_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x686_BMS_M3_Cell_2_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x686_BMS_M3_Cell_3_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x686_BMS_M3_Cell_4_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x687_BMS_M3_Cell_5_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x687_BMS_M3_Cell_6_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x687_BMS_M3_Cell_7_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x687_BMS_M3_Cell_8_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x688_BMS_M3_Cell_9_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x688_BMS_M3_Cell_10_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x688_BMS_M3_Cell_11_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x688_BMS_M3_Cell_12_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x689_BMS_M4_Cell_1_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x689_BMS_M4_Cell_2_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x689_BMS_M4_Cell_3_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x689_BMS_M4_Cell_4_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x68a_BMS_M4_Cell_5_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x68a_BMS_M4_Cell_6_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x68a_BMS_M4_Cell_7_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x68a_BMS_M4_Cell_8_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x68b_BMS_M4_Cell_9_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x68b_BMS_M4_Cell_10_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x68b_BMS_M4_Cell_11_Temperature(&obj,&iout); - fprintf(fp,",%3hu",iout); - decode_can_0x68b_BMS_M4_Cell_12_Temperature(&obj,&iout); - fprintf(fp,",%3hu\n",iout); + decode_can_0x680_BMS_M1_Cell_1_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x680_BMS_M1_Cell_2_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x680_BMS_M1_Cell_3_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x680_BMS_M1_Cell_4_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x680_BMS_M1_Cell_5_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x680_BMS_M1_Cell_6_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x680_BMS_M1_Cell_7_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x680_BMS_M1_Cell_8_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x681_BMS_M1_Cell_9_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x681_BMS_M1_Cell_10_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x681_BMS_M1_Cell_11_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x681_BMS_M1_Cell_12_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x682_BMS_M2_Cell_1_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x682_BMS_M2_Cell_2_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x682_BMS_M2_Cell_3_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x682_BMS_M2_Cell_4_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x682_BMS_M2_Cell_5_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x682_BMS_M2_Cell_6_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x682_BMS_M2_Cell_7_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x682_BMS_M2_Cell_8_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x683_BMS_M2_Cell_9_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x683_BMS_M2_Cell_10_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x683_BMS_M2_Cell_11_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x683_BMS_M2_Cell_12_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x684_BMS_M3_Cell_1_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x684_BMS_M3_Cell_2_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x684_BMS_M3_Cell_3_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x684_BMS_M3_Cell_4_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x684_BMS_M3_Cell_5_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x684_BMS_M3_Cell_6_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x684_BMS_M3_Cell_7_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x684_BMS_M3_Cell_8_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x685_BMS_M3_Cell_9_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x685_BMS_M3_Cell_10_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x685_BMS_M3_Cell_11_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x685_BMS_M3_Cell_12_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x686_BMS_M4_Cell_1_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x686_BMS_M4_Cell_2_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x686_BMS_M4_Cell_3_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x686_BMS_M4_Cell_4_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x686_BMS_M4_Cell_5_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x686_BMS_M4_Cell_6_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x686_BMS_M4_Cell_7_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x686_BMS_M4_Cell_8_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x687_BMS_M4_Cell_9_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x687_BMS_M4_Cell_10_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x687_BMS_M4_Cell_11_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x687_BMS_M4_Cell_12_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x688_BMS_M5_Cell_1_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x688_BMS_M5_Cell_2_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x688_BMS_M5_Cell_3_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x688_BMS_M5_Cell_4_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x688_BMS_M5_Cell_5_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x688_BMS_M5_Cell_6_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x688_BMS_M5_Cell_7_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x688_BMS_M5_Cell_8_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x689_BMS_M5_Cell_9_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x689_BMS_M5_Cell_10_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x689_BMS_M5_Cell_11_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x689_BMS_M5_Cell_12_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68a_BMS_M6_Cell_1_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68a_BMS_M6_Cell_2_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68a_BMS_M6_Cell_3_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68a_BMS_M6_Cell_4_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68a_BMS_M6_Cell_5_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68a_BMS_M6_Cell_6_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68a_BMS_M6_Cell_7_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68a_BMS_M6_Cell_8_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68b_BMS_M6_Cell_9_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68b_BMS_M6_Cell_10_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68b_BMS_M6_Cell_11_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68b_BMS_M6_Cell_12_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68c_BMS_M7_Cell_1_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68c_BMS_M7_Cell_2_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68c_BMS_M7_Cell_3_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68c_BMS_M7_Cell_4_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68c_BMS_M7_Cell_5_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68c_BMS_M7_Cell_6_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68c_BMS_M7_Cell_7_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68c_BMS_M7_Cell_8_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68d_BMS_M7_Cell_9_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68d_BMS_M7_Cell_10_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68d_BMS_M7_Cell_11_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68d_BMS_M7_Cell_12_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68e_BMS_M8_Cell_1_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68e_BMS_M8_Cell_2_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68e_BMS_M8_Cell_3_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68e_BMS_M8_Cell_4_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68e_BMS_M8_Cell_5_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68e_BMS_M8_Cell_6_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68e_BMS_M8_Cell_7_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68e_BMS_M8_Cell_8_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68f_BMS_M8_Cell_9_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68f_BMS_M8_Cell_10_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68f_BMS_M8_Cell_11_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu",iout); + decode_can_0x68f_BMS_M8_Cell_12_Thermistor(&obj,&iout); + fprintf(fp,",%3hhu\n",iout); } fclose(fp); -- cgit v1.2.3-70-g09d2