// SPDX-License-Identifier: GPL-3.0-or-later // references: // https://www.waveshare.com/wiki/RS485_CAN_HAT // https://files.waveshare.com/upload/4/4e/RS485_CAN_HAT_Code.zip // https://github.com/howerj/dbcc MIT /* build: cc -Wall -c all_SRETest.c cc -Wall -c mycan.c cc -Wall mycan.o all_SRETest.o -o mycan */ /* test: sudo ip link add type vcan sudo ip link set dev vcan0 type vcan sudo ip link set dev vcan0 up cansend vcan0 630#02.00.02.00.02.00.02.00 cansend vcan0 680#02.00.02.00.02.00.02.00 # if cell temperature is signed (can be negative), 00.FF sends -256 cansend vcan0 680#00.FF.02.00.02.00.02.00 */ #include #include #include #include // LGPL-2.1-or-later #include #include #include // (GPL-2.0-only WITH Linux-syscall-note) OR BSD-3-Clause #include #include // time() #include #include "all_SRE_edited.h" #define CAN_VOLT_LEN 24 #define CAN_TEMP_LEN 16 // max wire unsigned number is 65535 // max wire signed number maybe is -32768 to 32767 // voltage max format 7 bytes ,6.5535 // temp max format 4 bytes ,255 // timestamp max 10 bytes 1745742182 // 1 timestamp, 96 voltage, 48 temp, 1 \n // 10+96*7+96*4+1=1067 bytes #define ENTRY_SIZE 1067 // Convert can message to uint64_t // 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) | ((uint64_t)m[3] << 24) | ((uint64_t)m[2] << 16) | ((uint64_t)m[1] << 8) | ((uint64_t)m[0] << 0); } int main(int argc, char **argv) { int ret; int s, nbytes; struct sockaddr_can addr; struct ifreq ifr; struct can_frame frame; char *filename; // Initialize filename to $XDG_DATA_HOME/mycan.csv. If no XDG_DATA_HOME // environment variable, then initialize to $HOME/.local/share/mycan.csv { // usually ~/.local/share const char *dir=getenv("XDG_DATA_HOME"); const char *str; if(dir != NULL) str="/mycan.csv"; else { str="/.local/share/mycan.csv"; dir=getenv("HOME"); } filename=malloc((strlen(dir)+strlen(str)+1)*sizeof(char)); sprintf(filename,"%s%s",dir,str); } can_obj_all_sre_edited_h_t obj; dbcc_time_stamp_t t, t_before; uint64_t can_message_u64; //memset(&obj, 0, sizeof(can_obj_all_sretest_h_t)); memset(&frame, 0, sizeof(struct can_frame)); // No need any more because I use systemd unit to autostart configure CAN network interface //system("sudo ip link set can0 type can bitrate 500000"); //system("sudo ifconfig can0 up"); // Check and fix corrupted .csv file due to power failure. for(FILE *fp;(fp=fopen(filename,"r"))!=NULL;) { char ch; uint32_t offset; int remain; fseek(fp,-1L,SEEK_END); fscanf(fp,"%c",&ch); fseek(fp,0L,SEEK_END); offset=ftell(fp); //printf("csv file end offset: %d\n",offset); fclose(fp); remain=offset%ENTRY_SIZE; if(remain) { printf("Corrupted .csv file not a multiple of %d, removing last line\n",ENTRY_SIZE); truncate(filename,offset-remain); } else if(ch != '\n') { printf("Corrupted .csv file last character not \\n, removing last %d bytes of data\n",ENTRY_SIZE); truncate(filename,offset-ENTRY_SIZE); } else break; } // need fflush for systemd to log my stdout // without fflush, fprintf stderr works, printf not work, fprintf stdout not work // maybe other ways to flush buffers or disable buffering (with setbuf and setvbuf) also works // https://unix.stackexchange.com/questions/725331#comment1376185_725331 // https://stackoverflow.com/a/7876743 // https://unix.stackexchange.com/questions/785686#comment1505589_785686 fflush(stdout); // https://www.waveshare.com/wiki/RS485_CAN_HAT // Using Linux kernel's SocketCAN // https://docs.kernel.org/networking/can.html //1.Create socket s = socket(PF_CAN, SOCK_RAW, CAN_RAW); if (s < 0) { perror("socket PF_CAN failed"); return 1; } //2.Specify can0 device if(argc>1) strcpy(ifr.ifr_name, argv[1]); else strcpy(ifr.ifr_name, "can0"); ret = ioctl(s, SIOCGIFINDEX, &ifr); if (ret < 0) { perror("ioctl failed"); return 1; } //3.Bind the socket to can0 addr.can_family = PF_CAN; addr.can_ifindex = ifr.ifr_ifindex; ret = bind(s, (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) { perror("bind failed"); return 1; } //4.Define receive rules // Adding masks to the socket, to only read CAN ids I want. // 24 (voltage) + 16 (temp) can ids struct can_filter rfilter[CAN_VOLT_LEN+CAN_TEMP_LEN]; rfilter[0].can_id = 0x630; rfilter[0].can_mask = CAN_SFF_MASK; rfilter[CAN_VOLT_LEN].can_id = 0x680; rfilter[CAN_VOLT_LEN].can_mask = CAN_SFF_MASK; for(int i=1;i 0) { double out; uint8_t iout; FILE * fp; if((fp=fopen(filename,"a"))==NULL) { fprintf(stderr,"Can't open file \"%s\".\n",filename); 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]); can_message_u64 = u64_from_can_msg(frame.data); t=time(NULL); // Unpack CAN message and save to obj. This function is automatically generated using dbcc. 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); // Decode CAN message and write to file, using decode functions generated automatically using dbcc. if(t>t_before) { t_before=t; // Maybe better if concat strings and print all at once, but it would be more complicated, I tried, see commit a4dcf5ba5a fprintf(fp,"%u",t); decode_can_0x630_BMS_M1_Cell_1_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x630_BMS_M1_Cell_2_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x630_BMS_M1_Cell_3_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x630_BMS_M1_Cell_4_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x631_BMS_M1_Cell_5_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x631_BMS_M1_Cell_6_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x631_BMS_M1_Cell_7_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x631_BMS_M1_Cell_8_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x632_BMS_M1_Cell_9_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x632_BMS_M1_Cell_10_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x632_BMS_M1_Cell_11_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x632_BMS_M1_Cell_12_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x633_BMS_M2_Cell_1_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x633_BMS_M2_Cell_2_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x633_BMS_M2_Cell_3_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x633_BMS_M2_Cell_4_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x634_BMS_M2_Cell_5_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x634_BMS_M2_Cell_6_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x634_BMS_M2_Cell_7_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x634_BMS_M2_Cell_8_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x635_BMS_M2_Cell_9_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x635_BMS_M2_Cell_10_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x635_BMS_M2_Cell_11_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x635_BMS_M2_Cell_12_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x636_BMS_M3_Cell_1_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x636_BMS_M3_Cell_2_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x636_BMS_M3_Cell_3_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x636_BMS_M3_Cell_4_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x637_BMS_M3_Cell_5_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x637_BMS_M3_Cell_6_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x637_BMS_M3_Cell_7_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x637_BMS_M3_Cell_8_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x638_BMS_M3_Cell_9_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x638_BMS_M3_Cell_10_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x638_BMS_M3_Cell_11_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x638_BMS_M3_Cell_12_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x639_BMS_M4_Cell_1_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x639_BMS_M4_Cell_2_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x639_BMS_M4_Cell_3_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x639_BMS_M4_Cell_4_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63a_BMS_M4_Cell_5_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63a_BMS_M4_Cell_6_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63a_BMS_M4_Cell_7_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63a_BMS_M4_Cell_8_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63b_BMS_M4_Cell_9_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63b_BMS_M4_Cell_10_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63b_BMS_M4_Cell_11_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63b_BMS_M4_Cell_12_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63c_BMS_M5_Cell_1_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63c_BMS_M5_Cell_2_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63c_BMS_M5_Cell_3_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63c_BMS_M5_Cell_4_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63d_BMS_M5_Cell_5_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63d_BMS_M5_Cell_6_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63d_BMS_M5_Cell_7_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63d_BMS_M5_Cell_8_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63e_BMS_M5_Cell_9_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63e_BMS_M5_Cell_10_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63e_BMS_M5_Cell_11_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63e_BMS_M5_Cell_12_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63f_BMS_M6_Cell_1_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63f_BMS_M6_Cell_2_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63f_BMS_M6_Cell_3_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x63f_BMS_M6_Cell_4_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x640_BMS_M6_Cell_5_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x640_BMS_M6_Cell_6_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x640_BMS_M6_Cell_7_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x640_BMS_M6_Cell_8_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x641_BMS_M6_Cell_9_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x641_BMS_M6_Cell_10_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x641_BMS_M6_Cell_11_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x641_BMS_M6_Cell_12_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x642_BMS_M7_Cell_1_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x642_BMS_M7_Cell_2_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x642_BMS_M7_Cell_3_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x642_BMS_M7_Cell_4_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x643_BMS_M7_Cell_5_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x643_BMS_M7_Cell_6_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x643_BMS_M7_Cell_7_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x643_BMS_M7_Cell_8_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x644_BMS_M7_Cell_9_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x644_BMS_M7_Cell_10_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x644_BMS_M7_Cell_11_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x644_BMS_M7_Cell_12_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x645_BMS_M8_Cell_1_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x645_BMS_M8_Cell_2_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x645_BMS_M8_Cell_3_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x645_BMS_M8_Cell_4_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x646_BMS_M8_Cell_5_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x646_BMS_M8_Cell_6_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x646_BMS_M8_Cell_7_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x646_BMS_M8_Cell_8_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x647_BMS_M8_Cell_9_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x647_BMS_M8_Cell_10_Voltage(&obj,&out); fprintf(fp,",%6.4f",out); decode_can_0x647_BMS_M8_Cell_11_Voltage(&obj,&out); 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_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); } } //6.Close the socket and can0 close(s); //system("sudo ifconfig can0 down"); free(filename); return 0; }