aboutsummaryrefslogtreecommitdiff
path: root/mycan.c
diff options
context:
space:
mode:
Diffstat (limited to 'mycan.c')
-rw-r--r--mycan.c317
1 files changed, 208 insertions, 109 deletions
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<CAN_VOLT_LEN;i++)
{
rfilter[i].can_id = rfilter[i-1].can_id+1;
rfilter[i].can_mask = CAN_SFF_MASK;
}
- for(int i=25;i<36;i++)
+ for(int i=CAN_VOLT_LEN+1;i<CAN_VOLT_LEN+CAN_TEMP_LEN;i++)
{
rfilter[i].can_id = rfilter[i-1].can_id+1;
rfilter[i].can_mask = CAN_SFF_MASK;
@@ -127,7 +130,7 @@ int main(int argc, char **argv)
nbytes = read(s, &frame, sizeof(frame));
if(nbytes > 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);