Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: INA226
main.cpp
00001 00002 #include "mbed.h" 00003 #include "bms.h" 00004 #include "LTC681x.h" 00005 #include "LTC6811.h" 00006 #include "CAN.h" 00007 #include "INA226.hpp" 00008 00009 00010 00011 #define UI_BUFFER_SIZE 64 00012 #define SERIAL_TERMINATOR '\n' 00013 00014 #define ENABLED 1 00015 #define DISABLED 0 00016 00017 #define DATALOG_ENABLED 1 00018 #define DATALOG_DISABLED 0 00019 00020 00021 00022 DigitalOut led1(LED1); 00023 Serial pc(USBTX, USBRX); 00024 CAN can1(p9,p10); 00025 CAN can2(p30,p29); 00026 I2C i2c(p28,p27); 00027 DigitalOut BAT_MIN_safty(p21); 00028 DigitalOut BAT_MAX_safty(p22); 00029 INA226 VCmonitor(i2c); 00030 00031 00032 00033 void run_command(uint32_t cmd); 00034 void measurement_loop(uint8_t datalog_en); 00035 //void print_menu(); 00036 void print_cells(uint8_t datalog_en); 00037 void print_open(); 00038 void print_aux(uint8_t datalog_en); 00039 void print_stat(); 00040 void print_config(); 00041 void print_rxconfig(); 00042 void print_pec(void); 00043 void serial_print_hex(uint8_t data); 00044 void check_error(int error); 00045 void wakeup(); 00046 void cell_read(); 00047 void spi_error(); 00048 void ic_check(); 00049 void spi_check(); 00050 void print_CAN(uint8_t datalog_en); 00051 void print_math(); 00052 void can_sent1(); 00053 void can_sent2(); 00054 void can_sent3(); 00055 void can_sent4(); 00056 //void can_set(); 00057 void can_wait(); 00058 void ic_set(); 00059 00060 00061 //char get_char(); 00062 //void read_config_data(uint8_t cfg_data[][6], uint8_t nIC); 00063 00064 const uint8_t TOTAL_IC = 3;//!<number of ICs in the daisy chain 00065 char ui_buffer[UI_BUFFER_SIZE]; 00066 00067 00068 //ADC Command Configurations 00069 //const uint8_t ADC_OPT = ADC_OPT_DISABLED; // See LTC6811_daisy.h for Options 00070 const uint8_t ADC_CONVERSION_MODE = MD_7KHZ_3KHZ;//MD_7KHZ_3KHZ; //MD_26HZ_2KHZ;//MD_7KHZ_3KHZ; // See LTC6811_daisy.h for Options 00071 const uint8_t ADC_DCP = DCP_DISABLED; // See LTC6811_daisy.h for Options 00072 const uint8_t CELL_CH_TO_CONVERT = CELL_CH_ALL; // See LTC6811_daisy.h for Options 00073 const uint8_t AUX_CH_TO_CONVERT = AUX_CH_ALL; // See LTC6811_daisy.h for Options 00074 const uint8_t STAT_CH_TO_CONVERT = STAT_CH_ALL; // See LTC6811_daisy.h for Options 00075 00076 const uint16_t MEASUREMENT_LOOP_TIME = 100;//milliseconds(mS) 00077 00078 //Under Voltage and Over Voltage Thresholds 00079 const uint16_t OV_THRESHOLD = 41000; // 00080 const uint16_t UV_THRESHOLD = 30000; // 00081 00082 //Loop Measurement Setup These Variables are ENABLED or DISABLED Remember ALL CAPS 00083 const uint8_t WRITE_CONFIG = DISABLED; // This is ENABLED or DISABLED 00084 const uint8_t READ_CONFIG = DISABLED; // This is ENABLED or DISABLED 00085 const uint8_t MEASURE_CELL = ENABLED; // This is ENABLED or DISABLED 00086 const uint8_t MEASURE_AUX = DISABLED; // This is ENABLED or DISABLED 00087 const uint8_t MEASURE_STAT = DISABLED; //This is ENABLED or DISABLED 00088 const uint8_t PRINT_PEC = DISABLED; //This is ENABLED or DISABLED 00089 short n =0; 00090 00091 uint8_t read_data(); 00092 00093 float read_float(); 00094 00095 00096 int32_t read_int(); 00097 00098 int BAT_MIN, BAT_MAX, BAT_AVG; 00099 double BAT_Current; 00100 long BAT_SUM; 00101 unsigned short BAT_CELL[27]; 00102 00103 char *read_string(); 00104 int8_t read_char(); 00105 00106 cell_asic bms_ic[TOTAL_IC]; 00107 00108 int main(void) 00109 { 00110 uint32_t user_command; 00111 00112 pc.baud(115200); 00113 00114 while(1) { 00115 BAT_MIN = 0; 00116 BAT_MAX = 0; // 0にする 00117 ic_set(); 00118 } 00119 } 00120 00121 00122 00123 void ic_set(){ 00124 00125 //__disable_irq(); 00126 ic_check(); 00127 spi_check(); 00128 spi_error(); 00129 wakeup(); 00130 cell_read(); 00131 00132 } 00133 00134 void ic_check(){ //1 00135 00136 //__disable_irq(); 00137 pc.baud(115200); 00138 spi_enable(); 00139 LTC681x_init_cfg(TOTAL_IC, bms_ic); 00140 LTC6811_reset_crc_count(TOTAL_IC,bms_ic); 00141 LTC6811_init_reg_limits(TOTAL_IC,bms_ic); 00142 wakeup_sleep(TOTAL_IC); 00143 LTC6811_wrcfg(TOTAL_IC,bms_ic); 00144 print_config(); 00145 //printf("1"); 00146 //spi_check(); 00147 00148 } 00149 00150 void spi_check(){ //2 00151 00152 __disable_irq(); 00153 int countup; 00154 int8_t error = 0; 00155 00156 wakeup_sleep(TOTAL_IC); 00157 error = LTC6811_rdcfg(TOTAL_IC,bms_ic); 00158 check_error(error); 00159 print_rxconfig(); 00160 //printf("2"); 00161 //spi_error(); 00162 } 00163 00164 00165 void wakeup(){ //3 00166 00167 __disable_irq(); 00168 int countup; 00169 int8_t error = 0; 00170 uint32_t conv_time = 0; 00171 00172 00173 wakeup_sleep(TOTAL_IC); 00174 LTC6811_adcv(ADC_CONVERSION_MODE,ADC_DCP,CELL_CH_TO_CONVERT); 00175 conv_time = LTC6811_pollAdc(); 00176 //printf("3"); 00177 //cell_read(); 00178 } 00179 00180 00181 void spi_error(){ 00182 00183 //__disable_irq(); 00184 00185 int8_t error = 0; 00186 int countup; 00187 /* 00188 if(error = -1 ){ 00189 for(countup = 0; countup <= 2; countup++){ 00190 spi_check(); 00191 if(error =1){ 00192 break; 00193 } 00194 } 00195 } 00196 if(error = 1){ 00197 wakeup(); 00198 } 00199 */ 00200 00201 //wakeup(); 00202 00203 00204 } 00205 00206 void cell_read(){ //4 電圧読み取り 00207 00208 __disable_irq(); 00209 int8_t error = 0; 00210 uint32_t conv_time = 0; 00211 int8_t readIC=0; 00212 00213 wakeup_sleep(TOTAL_IC); 00214 error = LTC6811_rdcv(0, TOTAL_IC,bms_ic); 00215 check_error(error); 00216 //print_cells(DATALOG_DISABLED); 00217 print_CAN(DATALOG_DISABLED); 00218 //printf("4"); 00219 00220 } 00221 00222 00223 00224 00225 void print_CAN(uint8_t datalog_en){ 00226 00227 __disable_irq(); 00228 short n =0; 00229 int BAT_SUM = 0; // 0にする 00230 int BAT_MIN = 55876; 00231 double V,C; 00232 int BTA_MAX = 0; 00233 float tempC, sum, sum_2, ave, ave_2; 00234 int i, j, k, l; //平均化処理に使用 00235 int r = 5; //平均する値の個数 00236 00237 for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++) { 00238 00239 //if (datalog_en == 0) { 00240 //pc.printf("IC%d, ", current_ic+1); 00241 //for(n = 0; n <= 12; n++){ 00242 for (int i=0; i < bms_ic[0].ic_reg.cell_channels; i++) { 00243 00244 //BAT_CELL[n] = bms_ic[current_ic].cells.c_codes[i]; 00245 00246 00247 pc.printf("C%d:", i+1); 00248 pc.printf("%.4f, ",bms_ic[current_ic].cells.c_codes[i]*0.0001); 00249 BAT_SUM = bms_ic[current_ic].cells.c_codes[i] + BAT_SUM; 00250 00251 if(bms_ic[current_ic].cells.c_codes[i] > 10000){ 00252 if(bms_ic[current_ic].cells.c_codes[i] < BAT_MIN){ 00253 BAT_MIN = bms_ic[current_ic].cells.c_codes[i]; 00254 } 00255 } 00256 00257 if( bms_ic[current_ic].cells.c_codes[i] > BAT_MAX){ 00258 BAT_MAX = bms_ic[current_ic].cells.c_codes[i]; 00259 00260 } 00261 00262 /* 00263 00264 //平均化処理 00265 00266 sum = 0; 00267 ave = 0; 00268 i = 0; 00269 for( i = 0; i < r; i++) 00270 { 00271 float temp = max.read_temp(); 00272 sum += temp; 00273 } 00274 00275 ave = sum / r; 00276 printf("\n\rT: %f",ave ); 00277 00278 00279 00280 max.deselect(); 00281 max_2.select_2(); 00282 00283 //平均化処理 00284 sum_2 = 0; 00285 ave_2 = 0; 00286 j = 0; 00287 for( j = 0; j < r; j++) 00288 { 00289 float temp_2 = max_2.read_temp_2(); 00290 sum_2 += temp_2; 00291 } 00292 00293 ave_2 = sum_2 / r; 00294 printf("\n\rT: %f",ave_2 ); 00295 00296 00297 00298 max.deselect(); 00299 max_2.deselect_2(); 00300 00301 00302 00303 max.deselect(); 00304 max_2.deselect_2(); 00305 00306 00307 00308 00309 //BAT_Current = C; 00310 00311 */ 00312 00313 00314 } 00315 00316 } 00317 00318 00319 pc.printf("\n"); 00320 pc.printf("SUM"); 00321 pc.printf("%.4f, ",BAT_SUM*0.0001); 00322 BAT_AVG = BAT_SUM / 27; 00323 pc.printf("AVG"); 00324 pc.printf("%.4f, ",BAT_AVG*0.0001); 00325 pc.printf("MIN"); 00326 pc.printf("%.4f, ",BAT_MIN*0.0001); 00327 pc.printf("MAX"); 00328 pc.printf("%.4f, ",BAT_MAX*0.0001); 00329 //pc.printf("BAT_Current"); 00330 if((VCmonitor.getVoltage(&V) == 0) && (VCmonitor.getCurrent(&C) == 0)){ 00331 printf("V,%f,C,%f\n",V,C); 00332 BAT_Current = C; 00333 00334 } 00335 pc.printf("%f, ",BAT_Current); 00336 pc.printf("\n"); 00337 pc.printf("\n"); 00338 printf("\n\rT: %f",ave ); 00339 pc.printf("\n"); 00340 printf("\n\rT: %f",ave_2 ); 00341 pc.printf("\n"); 00342 00343 if( BAT_MIN < 25000 ){ 00344 BAT_MIN_safty = 1 ; 00345 wait(1); 00346 BAT_MIN_safty = 0 ; 00347 } 00348 if( BAT_MAX > 42000){ 00349 BAT_MAX_safty = 1; 00350 wait(1); 00351 BAT_MAX_safty = 0; 00352 00353 } 00354 } 00355 00356 00357 /* 00358 void can_sent4(){ 00359 00360 if(can1.write(CANMessage(271,&BAT_MAX2))){ 00361 pc.printf("10CANMessage:%d\n",BAT_MAX2); 00362 } 00363 if(can1.write(CANMessage(272,&BAT_MAX3))){ 00364 pc.printf("11CANMessage:%d\n",BAT_MAX3); 00365 } 00366 if(can1.write(CANMessage(273,&BAT_MAX4))){ 00367 pc.printf("12CANMessage:%d\n",BAT_MAX4); 00368 } 00369 00370 }*/ 00371 /* 00372 void can_set(){ 00373 00374 //NVIC_SetPriority(TIMER3_IRQn, 0); 00375 //printf("aaaaa"); 00376 00377 BAT_SUM1 = 0; 00378 BAT_SUM2 = 0; 00379 BAT_SUM3 = 0; 00380 BAT_SUM4 = 0; 00381 BAT_MIN1 = 0; 00382 BAT_MIN2 = 0; 00383 BAT_MIN3 = 0; 00384 BAT_MIN4 = 0; 00385 BAT_MAX1 = 0; 00386 BAT_MAX2 = 0; 00387 BAT_MAX3 = 0; 00388 BAT_MAX4 = 0; 00389 BAT_Current1 = 0; 00390 BAT_Current2 = 0; 00391 00392 00393 int data1 = 0; //BAT_SUM 00394 int data2 = 0; 00395 int data3 = 0; //BAT_MAX 00396 int data4 = 0; //BAT_Current 00397 00398 00399 BAT_SUM = data1; 00400 data2 = BAT_MIN; 00401 data3 = BAT_MAX; 00402 data4 = BAT_Current; 00403 00404 BAT_SUM1 = data1 / 1000; //114 00405 BAT_SUM2 = data1 % 1000; //755 00406 BAT_SUM3 = BAT_SUM2 / 10; //75 00407 BAT_SUM4 = BAT_SUM2 % 10; // 5 00408 00409 BAT_MIN1 = data2 / 1000; 00410 BAT_MIN2 = data2 % 1000; 00411 BAT_MIN3 = BAT_MIN2 / 10; 00412 BAT_MIN4 = BAT_MIN2 % 10; 00413 00414 BAT_MAX = data3 / 1000; 00415 BAT_MAX2 = data3 % 1000; 00416 BAT_MAX3 = BAT_MAX2 / 10; 00417 BAT_MAX4 = BAT_MAX2 % 10; 00418 00419 BAT_Current1 = data4 / 100; 00420 BAT_Current2 = data4 % 100; 00421 printf("can_set\n"); 00422 printf("aaaa%f",BAT_SUM); 00423 } 00424 */ 00425 00426 void measurement_loop(uint8_t datalog_en) 00427 { 00428 int8_t error = 0; 00429 if (WRITE_CONFIG == ENABLED) { 00430 wakeup_sleep(TOTAL_IC); 00431 LTC6811_wrcfg(TOTAL_IC,bms_ic); 00432 print_config(); 00433 } 00434 00435 if (READ_CONFIG == ENABLED) { 00436 wakeup_sleep(TOTAL_IC); 00437 error = LTC6811_rdcfg(TOTAL_IC,bms_ic); 00438 check_error(error); 00439 print_rxconfig(); 00440 } 00441 00442 if (MEASURE_CELL == ENABLED) { 00443 wakeup_idle(TOTAL_IC); 00444 LTC6811_adcv(ADC_CONVERSION_MODE,ADC_DCP,CELL_CH_TO_CONVERT); 00445 LTC6811_pollAdc(); 00446 wakeup_idle(TOTAL_IC); 00447 error = LTC6811_rdcv(0, TOTAL_IC,bms_ic); 00448 check_error(error); 00449 print_cells(datalog_en); 00450 00451 } 00452 00453 if (MEASURE_AUX == ENABLED) { 00454 wakeup_idle(TOTAL_IC); 00455 LTC6811_adax(ADC_CONVERSION_MODE , AUX_CH_ALL); 00456 LTC6811_pollAdc(); 00457 wakeup_idle(TOTAL_IC); 00458 error = LTC6811_rdaux(0,TOTAL_IC,bms_ic); // Set to read back all aux registers 00459 check_error(error); 00460 print_aux(datalog_en); 00461 } 00462 00463 if (MEASURE_STAT == ENABLED) { 00464 wakeup_idle(TOTAL_IC); 00465 LTC6811_adstat(ADC_CONVERSION_MODE, STAT_CH_ALL); 00466 LTC6811_pollAdc(); 00467 wakeup_idle(TOTAL_IC); 00468 error = LTC6811_rdstat(0,TOTAL_IC,bms_ic); // Set to read back all aux registers 00469 check_error(error); 00470 print_stat(); 00471 } 00472 00473 if (PRINT_PEC == ENABLED) { 00474 print_pec(); 00475 } 00476 00477 } 00478 00479 00480 00481 void print_cells(uint8_t datalog_en) 00482 { 00483 for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++) { 00484 00485 if (datalog_en == 0) { 00486 pc.printf("IC%d, ", current_ic+1); 00487 for (int i=0; i < bms_ic[0].ic_reg.cell_channels; i++) { 00488 pc.printf("C%d:", i+1); 00489 pc.printf("%.4f, ", bms_ic[current_ic].cells.c_codes[i]*0.0001); 00490 } 00491 00492 pc.printf("\n"); 00493 } 00494 00495 else { 00496 pc.printf("Cells, "); 00497 for (int i=0; i<bms_ic[0].ic_reg.cell_channels; i++) { 00498 pc.printf("%.4f, ",bms_ic[current_ic].cells.c_codes[i]*0.0001); 00499 00500 } 00501 } 00502 00503 } 00504 pc.printf("\n"); 00505 } 00506 00507 void print_open() 00508 { 00509 for (int current_ic =0 ; current_ic < TOTAL_IC; current_ic++) { 00510 if (bms_ic[current_ic].system_open_wire == 0) { 00511 pc.printf("No Opens Detected on IC%d\n", current_ic+1); 00512 } else { 00513 for (int cell=0; cell<bms_ic[0].ic_reg.cell_channels+1; cell++) { 00514 if ((bms_ic[current_ic].system_open_wire &(1<<cell))>0) { 00515 pc.printf("There is an open wire on IC%d Channel: %d\n", current_ic + 1, cell); 00516 } 00517 } 00518 } 00519 } 00520 } 00521 00522 00523 void print_aux(uint8_t datalog_en) 00524 { 00525 00526 for (int current_ic =0 ; current_ic < TOTAL_IC; current_ic++) { 00527 if (datalog_en == 0) { 00528 pc.printf(" IC%d", current_ic+1); 00529 for (int i=0; i < 5; i++) { 00530 pc.printf(" GPIO-%d:%.4f,", i+1, bms_ic[current_ic].aux.a_codes[i]*0.0001); 00531 } 00532 pc.printf("Vref2:%.4f\n", bms_ic[current_ic].aux.a_codes[5]*0.0001); 00533 } else { 00534 pc.printf("AUX, "); 00535 for (int i=0; i < 6; i++) { 00536 pc.printf("%.4f,", bms_ic[current_ic].aux.a_codes[i]*0.0001); 00537 } 00538 } 00539 } 00540 pc.printf("\n"); 00541 } 00542 00543 00544 void print_stat() 00545 { 00546 00547 for (int current_ic =0 ; current_ic < TOTAL_IC; current_ic++) { 00548 pc.printf("IC%d", current_ic+1); 00549 pc.printf(" SOC:%.4f,", bms_ic[current_ic].stat.stat_codes[0]*0.0001*20); 00550 pc.printf(" Itemp:%.4f,", bms_ic[current_ic].stat.stat_codes[1]*0.0001); 00551 pc.printf(" VregA:%.4f,", bms_ic[current_ic].stat.stat_codes[2]*0.0001); 00552 pc.printf(" VregD:%.4f\n", bms_ic[current_ic].stat.stat_codes[3]*0.0001); 00553 } 00554 00555 pc.printf("\n"); 00556 } 00557 00558 00559 void print_config() 00560 { 00561 int cfg_pec; 00562 00563 //pc.printf("Written Configuration: \n"); 00564 for (int current_ic = 0; current_ic<TOTAL_IC; current_ic++) { 00565 //pc.printf(" IC "); 00566 //pc.printf("%d", current_ic+1); 00567 // pc.printf(": "); 00568 //pc.printf("0x"); 00569 serial_print_hex(bms_ic[current_ic].config.tx_data[0]); 00570 // pc.printf(", 0x"); 00571 serial_print_hex(bms_ic[current_ic].config.tx_data[1]); 00572 //pc.printf(", 0x"); 00573 serial_print_hex(bms_ic[current_ic].config.tx_data[2]); 00574 //pc.printf(", 0x"); 00575 serial_print_hex(bms_ic[current_ic].config.tx_data[3]); 00576 // pc.printf(", 0x"); 00577 serial_print_hex(bms_ic[current_ic].config.tx_data[4]); 00578 // pc.printf(", 0x"); 00579 serial_print_hex(bms_ic[current_ic].config.tx_data[5]); 00580 //pc.printf(", Calculated PEC: 0x"); 00581 cfg_pec = pec15_calc(6,&bms_ic[current_ic].config.tx_data[0]); 00582 serial_print_hex((uint8_t)(cfg_pec>>8)); 00583 //pc.printf(", 0x"); 00584 serial_print_hex((uint8_t)(cfg_pec)); 00585 // pc.printf("\n"); 00586 } 00587 // pc.printf("\n"); 00588 } 00589 00590 00591 void print_rxconfig() 00592 { 00593 //pc.printf("Received Configuration "); 00594 for (int current_ic=0; current_ic<TOTAL_IC; current_ic++) { 00595 // pc.printf(" IC "); 00596 // pc.printf("%d", current_ic+1); 00597 //pc.printf(": 0x"); 00598 serial_print_hex(bms_ic[current_ic].config.rx_data[0]); 00599 //pc.printf(", 0x"); 00600 serial_print_hex(bms_ic[current_ic].config.rx_data[1]); 00601 //pc.printf(", 0x"); 00602 serial_print_hex(bms_ic[current_ic].config.rx_data[2]); 00603 //pc.printf(", 0x"); 00604 serial_print_hex(bms_ic[current_ic].config.rx_data[3]); 00605 //pc.printf(", 0x"); 00606 serial_print_hex(bms_ic[current_ic].config.rx_data[4]); 00607 // pc.printf(", 0x"); 00608 serial_print_hex(bms_ic[current_ic].config.rx_data[5]); 00609 //pc.printf(", Received PEC: 0x"); 00610 serial_print_hex(bms_ic[current_ic].config.rx_data[6]); 00611 //pc.printf(", 0x"); 00612 serial_print_hex(bms_ic[current_ic].config.rx_data[7]); 00613 // pc.printf("\n"); 00614 } 00615 pc.printf("\n"); 00616 } 00617 00618 void print_pec() 00619 { 00620 for (int current_ic=0; current_ic<TOTAL_IC; current_ic++) { 00621 pc.printf("\n%d", bms_ic[current_ic].crc_count.pec_count); 00622 pc.printf(" : PEC Errors Detected on IC"); 00623 pc.printf("%d\n", current_ic+1); 00624 } 00625 } 00626 00627 00628 void serial_print_hex(uint8_t data) 00629 { 00630 /* 00631 if (data < 16) { 00632 //pc.printf("0x0%X", data); 00633 } else 00634 pc.printf("0x%X", data); 00635 */ 00636 } 00637 00638 //Function to check error flag and print PEC error message 00639 void check_error(int error) 00640 { 00641 if (error == -1) { 00642 pc.printf("A PEC error was detected in the received data"); 00643 } 00644 } 00645 00646 00647 00648 char hex_digits[16]= { 00649 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' 00650 }; 00651 00652 00653 00654 char hex_to_byte_buffer[5]= { 00655 '0', 'x', '0', '0', '\0' 00656 }; // buffer for ASCII hex to byte conversion 00657 char byte_to_hex_buffer[3]= { 00658 '\0','\0','\0' 00659 }; 00660 00661 // シリアル インターフェイスから ui_バッファへのデータの読み取り 00662 uint8_t read_data() 00663 { 00664 uint8_t index = 0; // 内の現在の場所を保持するインデックス 00665 int c; // 着信キーストロークの格納に使用される単一の文字 00666 //pc.printf("check 1\n"); 00667 while (index < UI_BUFFER_SIZE-1) { 00668 //pc.printf("check 2\n"); 00669 c = pc.getc(); 00670 //return c; 00671 //pc.printf("check 3\n"); 00672 00673 if (((char) c == '\r') || ((char) c == '\n')) break; 00674 if ( ((char) c == '\x7F') || ((char) c == '\x08') ) { 00675 if (index > 0) index--; 00676 } else if (c >= 0) { 00677 ui_buffer[index++]=(char) c; 00678 } 00679 //pc.printf("check 4\n"); 00680 00681 } 00682 ui_buffer[index]='\0'; 00683 00684 if ((char) c == '\r') { 00685 wait_ms(1); 00686 //pc.printf("check 5\n"); 00687 00688 if (pc.readable()==1) { 00689 //pc.printf("check 6\n"); 00690 pc.getc(); 00691 } 00692 00693 00694 } 00695 00696 00697 return index; 00698 } 00699 00700 00701 float read_float() 00702 { 00703 float data; 00704 read_data(); 00705 data = atof(ui_buffer); 00706 return(data); 00707 } 00708 00709 00710 int32_t read_int() 00711 { 00712 int32_t data; 00713 read_data(); 00714 if (ui_buffer[0] == 'm') 00715 return('m'); 00716 if ((ui_buffer[0] == 'B') || (ui_buffer[0] == 'b')) { 00717 data = strtol(ui_buffer+1, NULL, 2); 00718 } else 00719 data = strtol(ui_buffer, NULL, 0); 00720 return(data); 00721 } 00722 00723 char *read_string() 00724 { 00725 read_data(); 00726 return(ui_buffer); 00727 } 00728 00729 00730 int8_t read_char() 00731 { 00732 read_data(); 00733 return(ui_buffer[0]); 00734 }
Generated on Sat Jul 16 2022 17:26:48 by
