created separate function for hex to char
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of SS_SensePOC2P0_11Dec2017_USERPID by
Revision 76:611154b3b597, committed 2017-12-12
- Comitter:
- rashmivenkataramaiah
- Date:
- Tue Dec 12 11:13:10 2017 +0000
- Parent:
- 75:0feb6f993562
- Commit message:
- made separate function for hex to char
Changed in this revision
--- a/bt.cpp Mon Dec 11 12:24:19 2017 +0000 +++ b/bt.cpp Tue Dec 12 11:13:10 2017 +0000 @@ -27,8 +27,9 @@ }poc2p0_bluetooth_msg_request; poc2p0_bluetooth_msg_request poc2p0_bt_msg_req = {0}; -static void poc2p0_ascii_to_hex(const uint8_t input_buffer[], uint8_t len); -static void poc2p0_ascii_to_hex123(const uint8_t input_buf[], uint8_t len, uint8_t output_buf[], uint8_t size_of_o_p); +//static void poc2p0_ascii_to_hex(const uint8_t input_buffer[], uint8_t len); +static void poc2p0_ascii_to_hex(const uint8_t input_buf[], uint8_t len_ip_buf, uint8_t output_buf[], uint8_t len_op_buf); +static void hex_to_char(const char input_buffer[]); BLEMsg_info *bt_file; @@ -496,50 +497,52 @@ uint8_t poc2p0_bt_receive (uint8_t curr_touch_state) { uint8_t bt_rx_buffer[31] = {0}; - uint8_t bfff[15] = {0}; + uint8_t usr_pid_hex[15] = {0}; uint8_t cal_chksum = 0xFFu; uint8_t touch_state = 0x00u; char user_pid_char[20]; - const char *ptr = user_pid_char; - unsigned int ch; - uint8_t n = 0; - uint8_t i=0; - uint8_t bt_chksum = 0; + //const char *ptr = user_pid_char; + //uint8_t ch = 0 ; + //uint8_t n = 0; + //uint8_t buff_index = 0; + uint8_t usr_pid_chksum = 0; - if (mc.readable()!= NULL) // reading string from putty - //if (blue.readable()!= NULL) // reading string from bluetooth + //if (mc.readable()!= NULL) // reading string from putty + if (blue.readable()!= NULL) // reading string from bluetooth { //wait_ms(50); //commented on 16-NOV rashmi - //blue.scanf("%31s",bt_rx_buffer); - mc.scanf("%31s",bt_rx_buffer); + blue.scanf("%31s",bt_rx_buffer); + //mc.scanf("%31s",bt_rx_buffer); mc.printf("\n\r Command ="); mc.printf("%s\r\n", bt_rx_buffer); //poc2p0_ascii_to_hex ((uint8_t *)bt_rx_buffer, sizeof(bt_rx_buffer)); - poc2p0_ascii_to_hex123((uint8_t *)bt_rx_buffer, sizeof(bt_rx_buffer), (uint8_t *)&poc2p0_bt_msg_req, sizeof(poc2p0_bt_msg_req)); + poc2p0_ascii_to_hex((uint8_t *)bt_rx_buffer, sizeof(bt_rx_buffer), (uint8_t *)&poc2p0_bt_msg_req, sizeof(poc2p0_bt_msg_req)); } if(poc2p0_bt_msg_req.cmd == TEST_SCREEN_REQ) { memcpy(user_pid_char,bt_rx_buffer+6,20); + hex_to_char((const char *)user_pid_char); mc.printf("User pid = %s\n",user_pid_char); - while ( *ptr ) + /*while ( *ptr ) { if ( sscanf(ptr, "%2x%n", &ch, &n) != 1 ) //ch -> holds data ; n-> no. of characters read { break; } ptr += n; - user_pid[i++] = char(ch); + user_pid[buff_index++] = char(ch); } mc.printf("User pid after copy = %s\n",user_pid); + */ - poc2p0_ascii_to_hex123((uint8_t *)bt_rx_buffer, sizeof(bt_rx_buffer), (uint8_t *)bfff, sizeof(bfff)); - bt_chksum = bfff[14]; - mc.printf("bt_chksum = %02x\n",bt_chksum); - cal_chksum = checksum_struct((uint8_t *)bfff+1, (sizeof(bfff)-1)); + poc2p0_ascii_to_hex((uint8_t *)bt_rx_buffer, sizeof(bt_rx_buffer), (uint8_t *)usr_pid_hex, sizeof(usr_pid_hex)); + usr_pid_chksum = usr_pid_hex[14]; + mc.printf("usr_pid_chksumksum = %02x\n",usr_pid_chksum); + cal_chksum = checksum_struct((uint8_t *)usr_pid_hex+1, (sizeof(usr_pid_hex)-1)); } else @@ -547,8 +550,8 @@ cal_chksum = checksum_struct((uint8_t *)&poc2p0_bt_msg_req.cmd, (sizeof(poc2p0_bt_msg_req)-1)); } - if (cal_chksum == poc2p0_bt_msg_req.chksum || cal_chksum == bt_chksum) - { + //if ((cal_chksum == poc2p0_bt_msg_req.chksum) || (cal_chksum == usr_pid_chksum)) + //{ switch (poc2p0_bt_msg_req.cmd) { case STRT_BP_TEST_REQ: @@ -615,15 +618,15 @@ default: break; } - }// + //} memset((void *)bt_rx_buffer,0x00,sizeof(bt_rx_buffer)); - memset((void *)&poc2p0_bt_msg_req,0x00,sizeof(bt_rx_buffer)); //to clear the structure else the command would be in the loop + memset((void *)&poc2p0_bt_msg_req,0x00,sizeof(poc2p0_bt_msg_req)); //to clear the structure else the command would be in the loop return touch_state; } // this function use to convert data from ascii to hex -static void poc2p0_ascii_to_hex(const uint8_t input_buf[], uint8_t len) +/*static void poc2p0_ascii_to_hex(const uint8_t input_buf[], uint8_t len) { uint8_t i = 0; uint8_t j = 0; @@ -642,7 +645,7 @@ memcpy(&poc2p0_bt_msg_req, &temp_buf, sizeof(poc2p0_bt_msg_req)); return; -} +} */ char* get_userpid(void) @@ -653,15 +656,15 @@ -static void poc2p0_ascii_to_hex123(const uint8_t input_buf[], uint8_t len, uint8_t output_buf[], uint8_t size_of_o_p) +static void poc2p0_ascii_to_hex(const uint8_t input_buf[], uint8_t len_ip_buf, uint8_t output_buf[], uint8_t len_op_buf) { uint8_t i = 0; uint8_t j = 0; uint8_t temp_ms_nibble = 0; uint8_t temp_ls_nibble = 0; - uint8_t temp_buf[len]; + uint8_t temp_buf[len_ip_buf]; - for (i = 0,j = 0; i < len; i+=2, ++j) + for (i = 0,j = 0; i < len_ip_buf; i+=2, ++j) { temp_ms_nibble = input_buf[i] > '9' ? (input_buf[i]|32) - 'a' + 10 : input_buf[i] - '0'; temp_ls_nibble = input_buf[i+1] > '9' ? (input_buf[i+1]|32) - 'a' + 10 : input_buf[i+1] - '0'; @@ -669,13 +672,31 @@ //mc.printf("\n\r msg_SOS = %2x", temp_buf[j]); } - memcpy(output_buf, &temp_buf, size_of_o_p); + memcpy(output_buf, &temp_buf, len_op_buf); return; } - +static void hex_to_char(const char input_buffer[]) +{ + const char *ptr = input_buffer; + uint8_t ch = 0 ; + uint8_t n = 0; + uint8_t buff_index = 0; + + while ( *ptr ) + { + if ( sscanf(ptr, "%2x%n", &ch, &n) != 1 ) //ch -> holds data ; n-> no. of characters read + { //sscanf returns 1 when the format matches,there is no data + break; + } + ptr += n; + user_pid[buff_index++] = char(ch); + } + mc.printf("User pid after copy = %s\n",user_pid); + +}
--- a/main.cpp Mon Dec 11 12:24:19 2017 +0000 +++ b/main.cpp Tue Dec 12 11:13:10 2017 +0000 @@ -87,7 +87,6 @@ static void battery_status_monitoring(); //bluetooth status pin uint8_t touch(uint8_t state); // touch state uint8_t display(uint8_t state1); // display state -static void set_userpid(char *user_pid); static void ecg_bp_countdown(void); static void read_device_id(void); void sd_card_status(void); @@ -391,14 +390,12 @@ static uint8_t state=0; static uint8_t ecg_flag=0; // ecg_flag to indicate the ecg test is already done for the same pid static uint8_t glc_flag=0; // glc_flag to indicate the glc test is already done for the same pid - //uint16_t heart_rate=0; switch(state1) // state for display screens { case 1: - //DisableTouch(); //screen_main(); // main screen state1=0; state=1; @@ -409,17 +406,14 @@ //battery_status_display(); //Display battery status on LCD pid = get_filepid() + 1; state_touch = TOUCH_STATE_HOME_SCREEN; //added on 16-Nov rashmi - //EnableTouch(); break; case 2: - //DisableTouch(); //screen_main_1(); // System configration screen state1=0; state=2; nstate=state; //battery_status_display(); //Display battery status on LCD - //EnableTouch(); // timer_debug.stop(); break; @@ -432,11 +426,9 @@ nstate=state; //battery_status_display(); state_touch = TOUCH_STATE_TEST_SCREEN; //added on 16-Nov rashmi - //EnableTouch(); break; case 4: - //DisableTouch(); if (glc_flag==1) // glc_flag=1 when already the reading has been taken { //screen_again(); @@ -450,14 +442,11 @@ state1=0; state=4; nstate=state; - } - //EnableTouch(); - + } break; case 5: - // DisableTouch(); if (ecg_flag==1) { //screen_again(); @@ -473,37 +462,29 @@ state=5; nstate=state; } - //EnableTouch(); break; case 6: - //DisableTouch(); //screen_bp(); // bp main screen state1=0; state=8; - nstate=state; - //EnableTouch(); + nstate=state; break; - case 7: - //DisableTouch(); + case 7: glc(pid); // glc measurement glc_flag=1; state1=0; - //screen_glc_2(); state=6; eprom_write_8(30,0); - nstate=state; - //wait(2); //added on 16-NOV rashmi - //screen_main_2(pid); //added on 20-NOV rashmi - state_touch = TOUCH_STATE_TEST_SCREEN; //added on 16-Nov rashmi - //EnableTouch(); + nstate=state; + state_touch = TOUCH_STATE_TEST_SCREEN; + break; - case 8: // DisableTouch(); + case 8: // send ECG test in progress messages to mobile application poc2p0_send_device_msg_res(ECG_TEST_IN_PROGRESS_RES); - //ecg_countdown(); // countdown before ecg capture ecg_bp_countdown(); ecg(pid); // capturing ecg state1=0; @@ -511,31 +492,20 @@ state=6; eprom_write_8(30,1); nstate=state; - //screen_ecg_bp(); - //wait(2); //added on 16-NOV rashmi - //screen_main_2(pid); //added on 20-NOV rashmi - state_touch = TOUCH_STATE_TEST_SCREEN; //added on 16-Nov rashmi - //EnableTouch(); + state_touch = TOUCH_STATE_TEST_SCREEN; break; - case 9: - //DisableTouch(); - //screen_bp2(); // bp main screen - + case 9: // send BP test in progress response to mobile application poc2p0_send_device_msg_res(BP_TEST_IN_PROGRESS_RES); - - //bp_countdown(); // countdown for bp - ecg_bp_countdown(); + + ecg_bp_countdown(); // countdown for bp bp(pid); // measuring bp earlier bp() changed to bp(pid) 28/4/2017 state1=0; state=6; eprom_write_8(30,2); - nstate=state; - //wait(2); //added on 16-NOV rashmi - //screen_main_2(pid); //added on 20-NOV rashmi - state_touch = TOUCH_STATE_TEST_SCREEN; //added on 16-Nov rashmi - //EnableTouch(); + nstate=state; + state_touch = TOUCH_STATE_TEST_SCREEN; break; @@ -546,42 +516,31 @@ break; case 11 : - //DisableTouch(); //screen_patient_info(get_filepid(), get_btpid()); state1=0; state=12; - //EnableTouch(); break; case 13 : //display screen for debug - // DisableTouch(); - //screen_debug(); state1=0; state=13; nstate=state; - // EnableTouch(); break; - case 14 : - //DisableTouch(); //state to delete SD card - delete_sdcard(); - //screen_sdcard_delete(); + case 14 : + delete_sdcard(); // delete SD card state1=0; state= 12; nstate=state; - //EnableTouch(); break; case 15 : - // DisableTouch(); gc.printf("Total Patients' data available : %d\n",get_filepid()); //state to read SD card gc.printf("Enter the PID number"); read_sdcard_file(); - //screen_sdcard_read(); state1=0; state= 12; nstate=state; - // EnableTouch(); break; default : @@ -592,8 +551,6 @@ } - - return state; } @@ -617,20 +574,13 @@ void increment_filepid (void) //increment pid if a test is completed { - //uint32_t filepid_btpid[2] = {}; - - //set_filecreated_status(); //set it to make it append mode sd_read(filepid_btpid); //read pid from sd card filepid_btpid[0] = filepid_btpid[0] + 1; //increment it by 1 - sd_write(filepid_btpid); //write it back to sd card - + sd_write(filepid_btpid); //write it back to sd card } -void increment_btpid (void) //increment pid if a test is completed +void increment_btpid (void) //increment pid if a test is completed { - //uint32_t filepid_btpid[2] = {}; - - //set_filecreated_status(); //set it to make it append mode sd_read(filepid_btpid); //read pid from sd card filepid_btpid[1] = filepid_btpid[1] + 1; //increment it by 1 sd_write(filepid_btpid); //write it back to sd card @@ -638,8 +588,7 @@ } uint32_t get_filepid(void) -{ - //uint32_t filepid_btpid[2] = {}; +{ uint32_t filepid = 0; sd_read(filepid_btpid); //read pid from sd card @@ -650,32 +599,26 @@ void store_filepid(uint32_t pid) { - //uint32_t filepid_btpid[2] = {}; - sd_read(filepid_btpid); //read pid from sd card - filepid_btpid[0] = pid; - sd_write(filepid_btpid); //write it back to sd card + sd_read(filepid_btpid); //read pid from sd card + filepid_btpid[0] = pid; + sd_write(filepid_btpid); //write it back to sd card } uint32_t get_btpid(void) { - //uint32_t filepid_btpid[2] = {}; uint32_t btpid = 0; sd_read(filepid_btpid); //read pid from sd card btpid = filepid_btpid[1]; - return btpid; - + return btpid; } void store_btpid(uint32_t bt_pid) -{ - //uint32_t filepid_btpid[2] = {}; - - sd_read(filepid_btpid); //read pid from sd card - filepid_btpid[1] = bt_pid; - sd_write(filepid_btpid); //write it back to sd card - +{ + sd_read(filepid_btpid); //read pid from sd card + filepid_btpid[1] = bt_pid; + sd_write(filepid_btpid); //write it back to sd card } @@ -715,7 +658,7 @@ if (strcmp(debug_message_rx, debug_message) == 0) // compare the message with the required one { - debug_mode = true; // enable the debug mode status + debug_mode = true; // enable the debug mode status gc.printf("entered into debug mode\n"); timer_debug.reset(); timer_debug.start(); // timer is started in orede @@ -724,7 +667,7 @@ } -uint32_t get_timer_debug() // timer for enabling debug option +uint32_t get_timer_debug() // timer for enabling debug option { if(timer_debug.read_ms()>TIMER_ENABLE_DEBUG_MODE) { @@ -784,9 +727,7 @@ // patient ID if (curr_touch_state == TOUCH_STATE_TEST_SCREEN) { - memcpy(poc2p0_device_heartbeat_res.pid,get_userpid(),sizeof(poc2p0_device_heartbeat_res.pid)); - //gc.printf("poc2p0_device_heartbeat_res.pid = %s\n",poc2p0_device_heartbeat_res.pid); - + memcpy(poc2p0_device_heartbeat_res.pid,get_userpid(),sizeof(poc2p0_device_heartbeat_res.pid)); } else { @@ -899,59 +840,6 @@ gc.printf("\n"); } - -void set_userpid(char *user_pid) -{ - char pid_buffer[20]; - char test_screen_chk[3]; - - //char user_pid_buffer[10] = {0}; - if (gc.readable()!= '\n') // reading string from putty - //if (blue.readable()!= NULL) // reading string from bluetooth - { - //blue.scanf("%10s",user_pid); - gc.scanf("%20s",pid_buffer); - } - memcpy(test_screen_chk,pid_buffer+1,2); - //if(test_screen_chk == "73") - memcpy(user_pid,pid_buffer+6,10); - //else - // gc.printf("Not a valid PID\n"); -} - - - - - - -void ascii_to_hex(const char *input_buf, uint8_t len) -{ - uint8_t i = 0; - uint8_t j = 0; - uint8_t temp_ms_nibble = 0; - uint8_t temp_ls_nibble = 0; - uint8_t temp_buf[len]; - gc.printf("\n\r len = %d", len); - for (i = 0,j = 0; i < len; i+=1, ++j) - { - temp_ms_nibble = input_buf[i] > '9' ? (input_buf[i]|32) - 'a' + 10 : input_buf[i] - '0'; - - //gc.printf("\n\r temp_ms_nibble = %2x", temp_ms_nibble); - - //temp_ls_nibble = input_buf[i+1] > '9' ? (input_buf[i+1]|32) - 'a' + 10 : input_buf[i+1] - '0'; - //gc.printf("\n\r temp_ls_nibble = %2x", temp_ls_nibble); - - //temp_buf[j] = ((temp_ms_nibble << 4)) | temp_ls_nibble; - temp_buf[j] = temp_ms_nibble ; - //gc.printf("\n\r msg_SOS = %02x", temp_buf[j]); - } - - memcpy((void *)input_buf,&temp_buf, len); - - - return; -} - static void ecg_bp_countdown(void) { for(uint8_t i = 5; i <= 0; i--) @@ -963,8 +851,8 @@ static void read_device_id(void) // reading device id from eeprom { - device_id = eprom_read_8(12); // reading from eeprom location - gc.printf("device_id = %d\n", device_id); //read did from eeprom + device_id = eprom_read_8(12); // reading did from eeprom location + gc.printf("device_id = %d\n", device_id); if((get_Error()!= 0) || (device_id == 0xFF)) // checking for error { device_id = eprom_read_8(12) ; @@ -982,7 +870,7 @@ return device_id; } -void sd_card_status(void) // checking the status of the sd card initialization +void sd_card_status(void) // checking the status of the sd card initialization { uint8_t error_sd= 0; error_sd = dummy_file_create_delete(); // creating the dummy file
--- a/main.h Mon Dec 11 12:24:19 2017 +0000 +++ b/main.h Tue Dec 12 11:13:10 2017 +0000 @@ -85,7 +85,5 @@ uint8_t get_did(void); //get device ID -void ascii_to_hex(const char *input_buf, uint8_t len); - #endif