![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
BMS
Diff: main.cpp
- Revision:
- 4:47d6a0b63e38
- Parent:
- 2:e0ec3ed506ea
- Child:
- 5:4c6c92733561
diff -r c66a74795705 -r 47d6a0b63e38 main.cpp --- a/main.cpp Fri Nov 17 09:03:11 2017 +0000 +++ b/main.cpp Sun Nov 19 07:24:11 2017 +0000 @@ -124,7 +124,7 @@ { uint32_t user_command; user_command = read_int(); // Read the user command - pc.printf("%d",user_command); + pc.printf("%d\n",user_command); run_command(user_command); } } @@ -165,7 +165,7 @@ pc.printf("cell conversion completed in:"); pc.printf("%.1f",((float)conv_time/1000)); pc.printf("mS"); - pc.printf("\r"); + pc.printf("\n\r"); break; case 4: // Read Cell Voltage Registers @@ -180,7 +180,7 @@ LTC681x_adax(ADC_CONVERSION_MODE , AUX_CH_TO_CONVERT); LTC681x_pollAdc(); pc.printf("aux conversion completed"); - pc.printf("\r"); + pc.printf("\n\r"); break; case 6: // Read AUX Voltage Registers @@ -195,7 +195,7 @@ LTC681x_adstat(ADC_CONVERSION_MODE, STAT_CH_TO_CONVERT); LTC681x_pollAdc(); pc.printf("stat conversion completed"); - pc.printf("\r"); + pc.printf("\n\r"); break; case 8: // Read Status registers @@ -271,7 +271,7 @@ LTC681x_clrcell(); LTC681x_clraux(); LTC681x_clrstat(); - pc.printf("All Registers Cleared"); + pc.printf("All Registers Cleared\n"); break; case 16: // Run the Mux Decoder Self Test @@ -337,7 +337,7 @@ break; default: - pc.printf("Incorrect Option"); + pc.printf("Incorrect Option\n"); break; } } @@ -407,19 +407,19 @@ ***********************************/ void print_menu() { - pc.printf("Please enter LTC6811 Command"); - pc.printf("Write Configuration: 1 | Reset PEC Counter: 11 "); - pc.printf("Read Configuration: 2 | Run ADC Self Test: 12"); - pc.printf("Start Cell Voltage Conversion: 3 | Set Discharge: 13"); - pc.printf("Read Cell Voltages: 4 | Clear Discharge: 14"); - pc.printf("Start Aux Voltage Conversion: 5 | Clear Registers: 15"); - pc.printf("Read Aux Voltages: 6 | Run Mux Self Test: 16"); - pc.printf("Start Stat Voltage Conversion: 7 | Run ADC overlap Test: 17"); - pc.printf("Read Stat Voltages: 8 | Run Digital Redundancy Test: 18"); - pc.printf("loop Measurements: 9 | Run Open Wire Test: 19"); - pc.printf("Read PEC Errors: 10 | Loop measurements with datalog output: 20"); + pc.printf("Please enter LTC6811 Command\n"); + pc.printf("Write Configuration: 1 | Reset PEC Counter: 11\n"); + pc.printf("Read Configuration: 2 | Run ADC Self Test: 12\n"); + pc.printf("Start Cell Voltage Conversion: 3 | Set Discharge: 13\n"); + pc.printf("Read Cell Voltages: 4 | Clear Discharge: 14\n"); + pc.printf("Start Aux Voltage Conversion: 5 | Clear Registers: 15\n"); + pc.printf("Read Aux Voltages: 6 | Run Mux Self Test: 16\n"); + pc.printf("Start Stat Voltage Conversion: 7 | Run ADC overlap Test: 17\n"); + pc.printf("Read Stat Voltages: 8 | Run Digital Redundancy Test: 18\n"); + pc.printf("loop Measurements: 9 | Run Open Wire Test: 19\n"); + pc.printf("Read PEC Errors: 10 | Loop measurements with datalog output: 20\n"); pc.printf("\r"); - pc.printf("Please enter command: "); + pc.printf("Please enter command: \n"); pc.printf("\r"); } @@ -428,8 +428,6 @@ *************************************************************/ void print_cells(uint8_t datalog_en) { - - for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++) { if (datalog_en == 0) @@ -459,7 +457,7 @@ } } - pc.printf("\r"); + pc.printf("\n\r"); } /*!**************************************************************************** @@ -489,6 +487,7 @@ } } } + pc.printf("\n\r"); } /*!**************************************************************************** @@ -496,7 +495,6 @@ *****************************************************************************/ void print_aux(uint8_t datalog_en) { - for (int current_ic =0 ; current_ic < TOTAL_IC; current_ic++) { if (datalog_en == 0) @@ -514,7 +512,7 @@ pc.printf(" Vref2"); pc.printf(":"); pc.printf("%.4f",bms_ic[current_ic].aux.a_codes[5]*0.0001); - pc.printf("\r"); + pc.printf("\n\r"); } else { @@ -527,7 +525,7 @@ } } } - pc.printf("\r"); + pc.printf("\n\r"); } /*!**************************************************************************** @@ -535,7 +533,6 @@ *****************************************************************************/ void print_stat() { - for (int current_ic =0 ; current_ic < TOTAL_IC; current_ic++) { pc.printf(" IC "); @@ -553,8 +550,7 @@ pc.printf("%.4f",bms_ic[current_ic].stat.stat_codes[3]*0.0001); pc.printf("\r"); } - - pc.printf("\r"); + pc.printf("\n\r"); } /*!****************************************************************************** @@ -590,7 +586,7 @@ serial_print_hex((uint8_t)(cfg_pec)); pc.printf("\r"); } - pc.printf("\r"); + pc.printf("\n\r"); } /*!***************************************************************** @@ -599,30 +595,30 @@ *******************************************************************/ void print_rxconfig() { - pc.printf("Received Configuration "); - for (int current_ic=0; current_ic<TOTAL_IC; current_ic++) - { - pc.printf(" IC "); - pc.printf("%d",current_ic+1); - pc.printf(": 0x"); - serial_print_hex(bms_ic[current_ic].config.rx_data[0]); - pc.printf(", 0x"); - serial_print_hex(bms_ic[current_ic].config.rx_data[1]); - pc.printf(", 0x"); - serial_print_hex(bms_ic[current_ic].config.rx_data[2]); - pc.printf(", 0x"); - serial_print_hex(bms_ic[current_ic].config.rx_data[3]); - pc.printf(", 0x"); - serial_print_hex(bms_ic[current_ic].config.rx_data[4]); - pc.printf(", 0x"); - serial_print_hex(bms_ic[current_ic].config.rx_data[5]); - pc.printf(", Received PEC: 0x"); - serial_print_hex(bms_ic[current_ic].config.rx_data[6]); - pc.printf(", 0x"); - serial_print_hex(bms_ic[current_ic].config.rx_data[7]); - pc.printf("\r"); - } - pc.printf("\r"); + pc.printf("Received Configuration "); + for (int current_ic=0; current_ic<TOTAL_IC; current_ic++) + { + pc.printf(" IC "); + pc.printf("%d",current_ic+1); + pc.printf(": 0x"); + serial_print_hex(bms_ic[current_ic].config.rx_data[0]); + pc.printf(", 0x"); + serial_print_hex(bms_ic[current_ic].config.rx_data[1]); + pc.printf(", 0x"); + serial_print_hex(bms_ic[current_ic].config.rx_data[2]); + pc.printf(", 0x"); + serial_print_hex(bms_ic[current_ic].config.rx_data[3]); + pc.printf(", 0x"); + serial_print_hex(bms_ic[current_ic].config.rx_data[4]); + pc.printf(", 0x"); + serial_print_hex(bms_ic[current_ic].config.rx_data[5]); + pc.printf(", Received PEC: 0x"); + serial_print_hex(bms_ic[current_ic].config.rx_data[6]); + pc.printf(", 0x"); + serial_print_hex(bms_ic[current_ic].config.rx_data[7]); + pc.printf("\r"); + } + pc.printf("\n\r"); } void print_pec() @@ -634,6 +630,7 @@ pc.printf(" : PEC Errors Detected on IC"); pc.printf("%d",current_ic+1); } + pc.printf("\n\r"); } @@ -653,46 +650,6 @@ { if (error == -1) { - pc.printf("A PEC error was detected in the received data"); + pc.printf("A PEC error was detected in the received data\n"); } } - - -//// hex conversion constants -//char hex_digits[16]= -//{ -// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' -//}; -// -//// global variables -// -//char hex_to_byte_buffer[5]= -//{ -// '0', 'x', '0', '0', '\0' -//}; // buffer for ASCII hex to byte conversion -//char byte_to_hex_buffer[3]= -//{ -// '\0','\0','\0' -//}; -// -//char read_hex() -//// read 2 hex characters from the pc buffer and convert -//// them to a byte -//{ -// byte data; -// hex_to_byte_buffer[2]=get_char(); -// hex_to_byte_buffer[3]=get_char(); -// get_char(); -// get_char(); -// data = strtol(hex_to_byte_buffer, NULL, 0); -// return(data); -//} -// -//char get_char() -//{ -// // read a command from the pc port -// while (pc.readable() <= 0); -// return(pc.read()); -//} - -