/*********************************************** EEPROM ADDRESS HW_NO[12] SERIAL_NO[12] v1.17 p1,p2 parssurer ***********************************************/ #include #include "debug_print.h" #define DEVICE_VERSION "FW25LIT2B102" #define DEVICE_NAME "MEDIDEV_2004" #define err_code1 65535 //length #define err_code2 65534 //activate #define err_code3 65533 //param #define err_code4 65532 //? missing #define err_code5 65531 //CMD wrong #define err_code6 65530 //CRC wrong #define SERIAL_NO_LENGTH 12 #define LED_NUM 24 //25/10/28 cj chun ==tag[i] = (char)buffer[i]; } cmd_out->tag[4] = '\0'; // Null-terminate // Extract 16-bit value (little-endian) cmd_out->value0 = (uint16_t)buffer[5] | ((uint16_t)buffer[4] << 8); cmd_out->value1 = (uint16_t)buffer[7] | ((uint16_t)buffer[6] << 8); cmd_out->value2 = (uint16_t)buffer[9] | ((uint16_t)buffer[8] << 8); cmd_out->value3 = (uint16_t)buffer[11] | ((uint16_t)buffer[10] << 8); cmd_out->value4 = (uint16_t)buffer[13] | ((uint16_t)buffer[12] << 8); for (int i = 0; i < length; i++) { cmd_out->values[i] = buffer[i]; } for (int i = 0; i < 12; i++) { cmd_out->value_ascii[i] = (char)buffer[i+4]; } cmd_out->value_ascii[12]= '\0'; // Null-terminate return true; // You could return false on validation failure } bool length_error(const char *cmd , uint8_t target_length, uint8_t length) { if (target_length == length) { return true; } else { char resp_error[4]; resp_error[0] = 'r'; resp_error[1] = cmd[1]; // 2nd letter (index 1) resp_error[2] = cmd[2]; // 3rd letter (index 2) resp_error[3] = '!'; single_format_data(ble_bin_buffer, resp_error, err_code1); binary_tx_handler(ble_bin_buffer,3); return false; } } bool activate_error(const char *cmd , bool device_status) { if (device_status == true) { return true; } else { char resp_error[4]; resp_error[0] = 'r'; resp_error[1] = cmd[1]; // 2nd letter (index 1) resp_error[2] = cmd[2]; // 3rd letter (index 2) resp_error[3] = '!'; single_format_data(ble_bin_buffer, resp_error, err_code2); binary_tx_handler(ble_bin_buffer,3); return false; } } void param_error(const char *cmd ) { char resp_error[4]; resp_error[0] = 'r'; resp_error[1] = cmd[1]; // 2nd letter (index 1) resp_error[2] = cmd[2]; // 3rd letter (index 2) resp_error[3] = '!'; single_format_data(ble_bin_buffer, resp_error, err_code3); binary_tx_handler(ble_bin_buffer,3); } void quest_error(const char *cmd ) { char resp_error[4]; const char pass_init[6] = "123456"; if( (cmd[0] == '*') && (cmd[1] == '*') && (cmd[2] == '*') && (cmd[3] == '*')){ if(eeprom_write_encrypted(0x0020, (uint8_t *)pass_init, 6)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_passkey 6\r\n\r\n");; } resp_error[0] = '*'; resp_error[1] = cmd[1]; // 2nd letter (index 1) resp_error[2] = cmd[2]; // 3rd letter (index 2) resp_error[3] = '*'; single_format_data(ble_bin_buffer, resp_error, err_code4); binary_tx_handler(ble_bin_buffer,3); } else{ resp_error[0] = 'r'; resp_error[1] = cmd[1]; // 2nd letter (index 1) resp_error[2] = cmd[2]; // 3rd letter (index 2) resp_error[3] = '!'; single_format_data(ble_bin_buffer, resp_error, err_code4); binary_tx_handler(ble_bin_buffer,3); } } //uint32_t serial_to_passkey_hash(const char *input) //{ // uint32_t hash = 1026; // while (*input) // { // hash = ((hash << 5) + hash) + (uint8_t)(*input++); // hash * 33 + c // } // return hash % 1000000; // 6-digit range //} //void test_eeprom_page_rw(void) //{ // uint8_t tx_data[EEPROM_PAGE_SIZE]; // uint8_t rx_data[EEPROM_PAGE_SIZE]; // // Fill tx_data with example values // for (int i = 0; i < EEPROM_PAGE_SIZE; i++) { // tx_data[i] = i*10; // } // uint16_t test_address = 0x0000; // if (eeprom_write_page(test_address, tx_data) == NRF_SUCCESS) { // DBG_PRINTF("Write OK\r\n"); // } // if (eeprom_read_page(test_address, rx_data) == NRF_SUCCESS) { // DBG_PRINTF("Read OK\n"); // } // // Verify // for (int i = 0; i < EEPROM_PAGE_SIZE; i++) { // if (rx_data[i] != tx_data[i]) { // DBG_PRINTF("Mismatch at %d: wrote %02X, read %02X\n", i, tx_data[i], rx_data[i]); // } // } //} ret_code_t eeprom_read_bool(uint16_t mem_address, bool *value_out) { uint8_t raw; ret_code_t ret = eeprom_read_byte(mem_address, &raw); if (ret != NRF_SUCCESS) { return ret; } *value_out = (raw != 0); return NRF_SUCCESS; } ret_code_t eeprom_init_values_read(void) { ret_code_t err_code; //uint8_t *data_bond; // Read 11 bytes from EEPROM err_code = eeprom_read_decrypted(0x0030, (uint8_t *)SERIAL_NO, 12); if (err_code != NRF_SUCCESS) { return err_code; } else { DBG_PRINTF("\r\n SN:%s \r\n", SERIAL_NO); } err_code = eeprom_read_decrypted(0x0020, (uint8_t *)m_static_passkey, 6); if (err_code != NRF_SUCCESS) { return err_code; } else { DBG_PRINTF("\r\n passkey-0 :%s \n", m_static_passkey); } eeprom_read_uint16_array(0x0480, led_pd_dac_v, 48); //AGC_Gain int16(48ea) // DBG_PRINTF("Firth Tagc,"); // for(uint16_t j = 0; j < LED_NUM; j++){ // DBG_PRINTF("%d, ", led_pd_dac_v[j]); // } if (err_code != NRF_SUCCESS) { DBG_PRINTF("AGC Gain Read data fail! \r\n"); return err_code; } //DBG_PRINTF("AGC_Gain Read data \r\n"); //SERIAL_NO[12] = '\0'; // Ensure null-terminated if using as string //err_code = eeprom_read_bytes(0x0060, data_bond,16); err_code = eeprom_read_bool(0x0060, &bond_data_delete); if (err_code != NRF_SUCCESS) { return err_code; } else { // bond_data_delete = data_bond[0]; DBG_PRINTF("\r\n bond_data_delete :%d \n", bond_data_delete); } err_code = eeprom_read_byte(0x0065, &m_reset_status); if (err_code != NRF_SUCCESS) { return err_code; } else { if(m_reset_status){ //DBG_PRINTF("\r\n status :%d \n", m_reset_status); } } err_code = eeprom_read_byte(0x0070, &m_pd_adc_cnt); if (err_code != NRF_SUCCESS) { return err_code; } else { if(m_pd_adc_cnt){ if(m_pd_adc_cnt>=255) { m_pd_adc_cnt=8; } } } err_code = eeprom_read_word(0x0080, &m_pd_delay_us); if (err_code != NRF_SUCCESS) { return err_code; } else { if(m_pd_delay_us<5000){ m_pd_delay_us=8000; DBG_PRINTF("\r\n m_pd_delay :%d \n", m_pd_delay_us); } } DBG_PRINTF("m_life_cycle eprom read\n"); //ad cj err_code = eeprom_read_uint32(0x0090, &m_life_cycle); if (err_code != NRF_SUCCESS) { return err_code; } else { if(m_life_cycle){ DBG_PRINTF("\r\n m_life_cycle :%1u,m_pd_delay_us :%1u,m_pd_adc_cnt :%1u \r\n", m_life_cycle,m_pd_delay_us,m_pd_adc_cnt); } } return NRF_SUCCESS; } static void log_printf(const char *fmt, ...) { va_list args; va_start(args, fmt); vprintf(fmt, args); va_end(args); } void received_command_process (uint8_t const *data_array, which_cmd_t cmd_t, uint8_t length ) { uint8_t r_data[BLE_NUS_MAX_DATA_LEN]={0,}; uint8_t led_index = 0, pd_index = 0; uint16_t result = 0; uint16_t result_data[BLE_NUS_MAX_DATA_LEN]; uint16_t led_power = 0, dac_value = 0; int parser_result; // ? ?? ble_got_new_data = true; memset( ble_tx_buffer, 0, BLE_NUS_MAX_DATA_LEN); for( uint16_t i = 0; i < length ; i++ ) { r_data[i] = data_array[i]; } DBG_PRINTF("data : %s\r\n",r_data); DBG_PRINTF("Length : %d\r\n",length); // ======================================== // Initialize parser (once) // ======================================== static bool parser_initialized = false; if (!parser_initialized) { // Setup platform interface g_plat.log = log_printf; // printf g_plat.tx_bin = binary_tx_handler; g_plat.crc_check = true; // CRC g_log_enable = true; parser_initialized = true; DBG_PRINTF(">>> NEW parser initialized\r\n"); } // ======================================== // NEW PARSER: Try first // ======================================== parser_result = dr_cmd_parser(r_data, length); if (parser_result > 0) { // Success - handled by new parser DBG_PRINTF(">>> Handled by NEW parser\r\n"); return; } // parse_cmd(r_data, &scmd,length); DBG_PRINTF("parsed.tag ? %s,%d,%d,%d\r\n",scmd.tag,scmd.value0,scmd.value1,scmd.value2); if(scmd.tag[3] != '?' ) { quest_error(scmd.tag ); return; } else if(!crc16_check_packet(data_array , length)){ char resp_error[4]; resp_error[0] = 'c'; resp_error[1] = 'r'; // 2nd letter (index 1) resp_error[2] = 'c'; // 3rd letter (index 2) resp_error[3] = '!'; single_format_data(ble_bin_buffer, resp_error, err_code6); binary_tx_handler(ble_bin_buffer,3); return ; } else if(processing == true) { // DBG_PRINTF("mmm....\r\n"); uint32_t now = app_timer_cnt_get(); if (processing_start_tick == 0) { processing_start_tick = now; } // if (app_timer_cnt_diff_compute(now, processing_start_tick) > APP_TIMER_TICKS(5000)) //add cj { processing = false; processing_start_tick = 0; DBG_PRINTF("processing timeout -> force reset to false\r\n"); } else { DBG_PRINTF("mmm....\r\n"); } return; } else { #if 0 //spas // if((data_array[0] == 'p')&&(data_array[1] == 'a')&&(data_array[2] == 's')&&(data_array[3] == 's')&&(data_array[4] == 'k')&&(data_array[5] == 'e')&&(data_array[6] == 'y')) { // Write, Passkey // // if(data_array[7] == '='){ // // // // if ((data_array[8] >=0x30 && data_array[8] <=0x39) //only number is available // &&(data_array[9] >=0x30 && data_array[9] <=0x39) // &&(data_array[10] >=0x30 && data_array[10] <=0x39) // &&(data_array[11] >=0x30 && data_array[11] <=0x39) // &&(data_array[12] >=0x30 && data_array[12] <=0x39) // &&(data_array[13] >=0x30 && data_array[13] <=0x39)) // // { // memcpy(m_config.static_passkey, data_array+8, 6); // // DBG_PRINTF("m_config.static_passkey = %s\r\n", m_config.static_passkey); // // if(cmd_t == CMD_UART) { // DBG_PRINTF("Passkey Ok\r\n"); // } else if(cmd_t == CMD_BLE) { // sprintf(ble_tx_buffer, "Passkey Ok\r\n"); // data_tx_handler(ble_tx_buffer); // } // } // else{ DBG_PRINTF("Nondigit!! \r\n"); // // } // // }else if(data_array[7] == '?'){ // if(cmd_t == CMD_UART) { // DBG_PRINTF("Passkey: %s\r\n", m_config.static_passkey); // } else if(cmd_t == CMD_BLE) { // sprintf(ble_tx_buffer, "Passkey: %s\r\n", m_config.static_passkey); // data_tx_handler(ble_tx_buffer); // } // }else { // if(cmd_t == CMD_UART) { // DBG_PRINTF("ERR!!! Passkey failed!\r\n\r\n"); // } else if(cmd_t == CMD_BLE) { // sprintf(ble_tx_buffer, "ERR!!! Passkey failed!\r\n\r\n"); // data_tx_handler(ble_tx_buffer); // } // } // } else //if((data_array[0] == 's')&&(data_array[1] == 't')&&(data_array[2] == 'a')&&(data_array[3] == '?')) { #endif //sta sta ` // sta if((scmd.tag[0] == 's')&&(scmd.tag[1] == 't')&&(scmd.tag[2] == 'a')&&(scmd.tag[3] == '?')) { //sta sta sta sta resetCount=0; //reset hear cj chun if(length_error(scmd.tag,8,length)==false) { return; } if(scmd.value0 == 1) { if(device_activated() == 0) { device_status = true; } }else if(scmd.value0 == 0) { if(device_status == true) { if(device_sleep_mode() == 0) { device_status = false; } } }else if(data_array[6] == '?') { /* Nothing to do */ }else { if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! Status failed!\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } if(cmd_t == CMD_UART) { DBG_PRINTF("Return%d\r\n\r\n", device_status); } else if(cmd_t == CMD_BLE) { single_format_data(ble_bin_buffer, "rta:", scmd.value0); binary_tx_handler(ble_bin_buffer,3); } } // str else if((scmd.tag[0] == 's')&&(scmd.tag[1] == 't')&&(scmd.tag[2] == 'r')&&(scmd.tag[3] == '?')) { if(length_error(scmd.tag,6,length)==false) { return; } // else { // if(cmd_t == CMD_UART) { // DBG_PRINTF("ERR!!! Status failed!\r\n\r\n"); // } else if(cmd_t == CMD_BLE) { // param_error(scmd.tag ); // } // } if(cmd_t == CMD_UART) { DBG_PRINTF("Return%d\r\n\r\n", device_status); } else if(cmd_t == CMD_BLE) { single_format_data(ble_bin_buffer, "rtr:", (uint8_t)device_status); binary_tx_handler(ble_bin_buffer,3); } } // sag else if((scmd.tag[0] == 's')&&(scmd.tag[1] == 'a')&&(scmd.tag[2] == 'g')) { if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } processing = true ; DBG_PRINTF("full_agc_mesurement start \r\n"); full_agc_mesurement_start(); } // sar else if((scmd.tag[0] == 's')&&(scmd.tag[1] == 'a')&&(scmd.tag[2] == 'r')) { if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } // processing = true ; // led_pd_gain_array_printout(); else if(cmd_t == CMD_UART) { DBG_PRINTF("\r\nLED-PD Gain Array =\r\n"); // for(uint16_t i = 0; i < PD_NUM; i++){ for(uint16_t j = 0; j < LED_NUM; j++){ DBG_PRINTF("%d,\t", led_pd_dac_v[j]); } DBG_PRINTF("\r\n"); //CJ ADD sw_i2c_init_once(); eeprom_read_uint16_array(0x0480, led_pd_dac_v, 48); //AGC_Gain int16(48ea) DBG_PRINTF("\r\n"); DBG_PRINTF("Tagc :"); for(uint16_t j = 0; j < LED_NUM; j++){ DBG_PRINTF("%d, ", led_pd_dac_v[j]); } DBG_PRINTF("AGC_Gain EEPROM Read Done\r\n"); } else if(cmd_t == CMD_BLE) { format_data(ble_bin_buffer, "rar:", led_pd_dac_v, 96); binary_tx_handler(ble_bin_buffer,50); } else{ param_error(scmd.tag ); } }else if(scmd.tag[0] == 's') { // ssa if((scmd.tag[1] == 's') && (scmd.tag[2] == 'a')){ // ssa LED Power(DP Value) Reading, LED index = 0~23, Power "00"~"FF" m_config.pd_delay_us //ssa // led_index = (uint8_t)scmd.value0; if(length_error(scmd.tag,8,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else if(led_index <= 47) { led_power = led_power_read(led_index); if(led_power <= 255){ if(cmd_t == CMD_UART) { DBG_PRINTF("Ta%d,%d\r\n\r\n", led_index, led_power); } else if(cmd_t == CMD_BLE) { //ble_tx_buffer[8]= {0}; //led_index16 = (int16_t)led_index; result_data[0] = scmd.value0; result_data[1] = (int16_t)led_power; format_data(ble_bin_buffer, "rsa:", result_data,4); binary_tx_handler(ble_bin_buffer,4); } } }else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! led_index failed!\r\n\r\n"); } else if(cmd_t == CMD_BLE) { // param_error(scmd.tag); } } } // sab else if((scmd.tag[1] == 'a') && (scmd.tag[2] == 'b')){ if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else if(m_pd_delay_us>= 1) { uint16_t pre_data[98]; uint16_t led_read_all[48]={0,}; led_power_read_48(led_read_all); if(m_pd_delay_us>= 1) { if(cmd_t == CMD_UART) { } else if(cmd_t == CMD_BLE) { // pre_data[0]= m_pd_adc_cnt; pre_data[1]= m_pd_delay_us; // DBG_PRINTF("m_pd_adc_cnt=%d\r\n", m_pd_adc_cnt); //// DBG_PRINTF("m_pd_delay_us=%d\r\n", m_pd_delay_us); //// #if 0 //48 cout // for(uint8_t i=0; i<48 ; i++){ // pre_data[i+2] = led_pd_dac_v[i]; // } // for(uint8_t i=0; i<48 ; i++){ // pre_data[i+50] = led_read_all[i]; // } #endif //48 ocut for(uint8_t i=0; i<48 ; i++){ pre_data[i+2] = led_pd_dac_v[i]; } for(uint8_t i=0; i<48 ; i++){ pre_data[i+50] = led_read_all[i]; } format_data(ble_bin_buffer, "rab:", pre_data,98); DBG_PRINTF("Tb%s\r\n\r\n", ble_bin_buffer); binary_tx_handler(ble_bin_buffer,100); } } }else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! led_index and(or) led_power failed!\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // ssb else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'b')){ // LED Power(DP Value) Setting, LED index = 01~24, Power "000"~"3FF" led_index = (uint8_t)scmd.value0; led_power = (uint8_t)scmd.value1; DBG_PRINTF("Tb%d\r\n\r\n", led_index); if(length_error(scmd.tag,10,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else if((led_index <= 47)&&(led_power <= 255)) { DBG_PRINTF("Tb%d\r\n\r\n", led_index); hw_i2c_init_once(); if(NRF_SUCCESS == led_power_save_mem(led_index, led_power)) { if(cmd_t == CMD_UART) { DBG_PRINTF("Tb%d\r\n\r\n", led_index); } else if(cmd_t == CMD_BLE) { // sprintf(ble_tx_buffer, "Tb%d\r\n", led_index); // data_tx_handler(ble_tx_buffer); result_data[0] = scmd.value0; result_data[1] = scmd.value1; format_data(ble_bin_buffer, "rsb:", result_data, 4); DBG_PRINTF("Tb%s\r\n\r\n", ble_bin_buffer); binary_tx_handler(ble_bin_buffer,4); } } }else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! led_index and(or) led_power failed!\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // srb else if((scmd.tag[1] == 'r') && (scmd.tag[2] == 'b')){ //read current all LED DP Values // LED Power(DP Value) Setting, LED index = 01~24, Power "000"~"3FF" if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } uint16_t led_read_all[48]={0,}; led_power_read_48(led_read_all); if(led_read_all[47]<=255) { format_data(ble_bin_buffer, "rrb:", led_read_all, 48); DBG_PRINTF("Tb%s\r\n\r\n", ble_bin_buffer); binary_tx_handler(ble_bin_buffer,50); } else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! led_index and(or) led_power failed!\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // ssc else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'c')){ // LED On/Off, LED index = 01~24, Off = 99 // if(device_status == false) { // DBG_PRINTF("ERR!!! Status = 0\r\n"); // return; // } led_index = (uint8_t)scmd.value0; if(length_error(scmd.tag,8,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else if(led_index <= 47){ if(NRF_SUCCESS == led_on(led_index)) { if(cmd_t == CMD_UART) { DBG_PRINTF("Tc%d\r\n\r\n", led_index); } else if(cmd_t == CMD_BLE) { result = scmd.value0; //DBG_PRINTF("Tc%d\r\n\r\n", led_index); single_format_data(ble_bin_buffer, "rsc:", result); binary_tx_handler(ble_bin_buffer,3); } } }else if(led_index == 99 || led_index == 98 ){ if(NRF_SUCCESS == led_off(led_index)) { if(cmd_t == CMD_UART) { DBG_PRINTF("Tc%d\r\n\r\n", led_index); } else if(cmd_t == CMD_BLE) { result = 99; single_format_data(ble_bin_buffer, "rsc:", result); binary_tx_handler(ble_bin_buffer,3); // sprintf(ble_tx_buffer, "Tc%d\r\n", led_index); // data_tx_handler(ble_tx_buffer); } } }else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! led_index_ failed!\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // ssd else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'd')){ // AGC mode On/Off, On:1, Off:0 if(length_error(scmd.tag,8,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else if( scmd.value0 == 0) { AGC_GAIN_SW(false); if(cmd_t == CMD_UART) { DBG_PRINTF("Td0\r\n\r\n"); } else if(cmd_t == CMD_BLE) { result = 0; single_format_data(ble_bin_buffer, "rsd:", result); binary_tx_handler(ble_bin_buffer,3); } }else if(scmd.value0 == 1) { AGC_GAIN_SW(true); if(cmd_t == CMD_UART) { DBG_PRINTF("Td1\r\n\r\n"); } else if(cmd_t == CMD_BLE) { result = 1; single_format_data(ble_bin_buffer, "rsd:", result); binary_tx_handler(ble_bin_buffer,3); } }else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! adc_mode_on/off failed!\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // sse else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'e')){ // Measure GAIN: ADC_GAIN Voltage Measuring, LED index = 01~24, PD:1~20 if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } mcp4725_voltage_level_meas(); } // ssf else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'f')){ // Writing GAIN: VGA_DP Voltage setting to DAC ssf led_index = (uint8_t)scmd.value0; //pd_index = strtol(end, &end, 10); dac_value = scmd.value1; if(length_error(scmd.tag,10,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else if((led_index <= 47)&&(dac_value<= 1360)&&(dac_value>= 125)) { led_pd_dac_v[led_index] = dac_value; led_pd_matching_value_set(led_index); if(cmd_t == CMD_UART) { DBG_PRINTF("Tf\r\n\r\n"); } else if(cmd_t == CMD_BLE) { result_data[0] = scmd.value0; result_data[1] = scmd.value1; format_data(ble_bin_buffer, "rsf:", result_data, 4); DBG_PRINTF("Tb%s\r\n\r\n", ble_bin_buffer); binary_tx_handler(ble_bin_buffer,4); } }else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!!led_index and(or) pd_index and(or) dac_value failed! %d %d %d\r\n\r\n", led_index, pd_index, dac_value); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // sif else if((scmd.tag[1] == 'i') && (scmd.tag[2] == 'f')){ // Writing GAIN: VGA_DP Voltage setting to DAC sif dac_value = scmd.value0; if(length_error(scmd.tag,8,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else if((dac_value<= 1360)&&(dac_value>= 125)) { sw_i2c_init_once(); imm_gain_set(dac_value); if(cmd_t == CMD_UART) { DBG_PRINTF("rif\r\n\r\n"); } else if(cmd_t == CMD_BLE) { single_format_data(ble_bin_buffer, "rif:", dac_value); DBG_PRINTF("rif%s\r\n\r\n", ble_bin_buffer); binary_tx_handler(ble_bin_buffer,3); } }else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!!led_index and(or) pd_index and(or) dac_value failed! %d %d %d\r\n\r\n", led_index, pd_index, dac_value); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // ssg else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'g')){ // Setting PD, PD : 1~20 pd_index = (uint8_t)scmd.value0; if(length_error(scmd.tag,8,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else if(pd_index <= 3) { if(NRF_SUCCESS == pd_on(pd_index)) { //2: mod signal 3: off if(cmd_t == CMD_UART) { DBG_PRINTF("Tg%d\r\n\r\n", pd_index); } else if(cmd_t == CMD_BLE) { single_format_data(ble_bin_buffer, "rsg:", scmd.value0); binary_tx_handler(ble_bin_buffer,3); } } }else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! pd_index failed!\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // ssh else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'h')){ // PD_ADC simple, Measuring PD for above PD if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ simple_samples_in_buffer = m_pd_adc_cnt; con_single=false; lock_check = false; simple_mesurement_start(); } } // scj else if((scmd.tag[1] == 'c') && (scmd.tag[2] == 'j')){ // PD_ADC Full, Loop for Sector 1,2,3,4,5,6,7,8 scj if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ ADC_PD_MODE = 2; info4 = true; //true ad edit ble_got_new_data =false; processing = true ; pressure_all_level_meas(); // pressure1 + pressure2 AGC_GAIN_SW(false); m48_samples_in_buffer = m_pd_adc_cnt; //DBG_PRINTF("scj m_pd_adc_cnt= %d\r\n",m_pd_adc_cnt); pd_adc_m48_start = true; battery_timer_stop(); go_batt = true;// BATT.TEMP IMU motion_data_once = true; main_timer_start(); } } // sdj else if((scmd.tag[1] == 'd') && (scmd.tag[2] == 'j')){ // PD_ADC Full, Loop for Sector 1,2,3,4,5,6,7,8 if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ ADC_PD_MODE = 3; info4 = false; ble_got_new_data =false; processing = true ; AGC_GAIN_SW(false); m48_samples_in_buffer = m_pd_adc_cnt; pd_adc_m48_start = true; battery_timer_stop(); // motion_raw_data_enabled = true;//IMU // go_batt = true;// BATT.TEMP IMU // go_temp = true; // motion_data_once = true; // motion_raw_data_enabled = true;// // main_timer_start(); m48_adc_start_init(); // } } // sej else if((scmd.tag[1] == 'e') && (scmd.tag[2] == 'j')){ // PD_ADC Full, Loop for Sector 1,2,3,4,5,6,7,8 sej if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ ADC_PD_MODE = 4; info4 = true; ble_got_new_data =false; processing = true ; AGC_GAIN_SW(false); m48_samples_in_buffer = m_pd_adc_cnt; pd_adc_m48_start = true; battery_timer_stop(); // motion_raw_data_enabled = true;//IMU go_batt = true;// BATT.TEMP IMU // go_temp = true; // motion_data_once = true; // motion_raw_data_enabled = true;// main_timer_start(); } } // sfj else if((scmd.tag[1] == 'f') && (scmd.tag[2] == 'j')){ // PD_ADC Full, Loop for Sector 1,2,3,4,5,6,7,8 if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ ADC_PD_MODE = 5; info4 = false; ble_got_new_data =false; processing = true ; AGC_GAIN_SW(false); m48_samples_in_buffer = m_pd_adc_cnt; pd_adc_m48_start = true; battery_timer_stop(); // motion_raw_data_enabled = true;//IMU // go_batt = true;// BATT.TEMP IMU // go_temp = true; // motion_data_once = true; // motion_raw_data_enabled = true;// // main_timer_start(); m48_adc_start_init(); } } // ssj else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'j')){ // PD_ADC Full, Loop for Sector 1,2,3,4,5,6,7,8 if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ ADC_PD_MODE = 0; info4 = true; ble_got_new_data =false; processing = true ; AGC_GAIN_SW(false); m48_samples_in_buffer = m_pd_adc_cnt; pd_adc_m48_start = true; battery_timer_stop(); // motion_raw_data_enabled = true;//IMU go_batt = true;// BATT.TEMP IMU // go_temp = true; motion_data_once = true; // motion_raw_data_enabled = true; main_timer_start(); } } // szj else if((scmd.tag[1] == 'z') && (scmd.tag[2] == 'j')){ // use FAST mode at 99 state if(length_error(scmd.tag,10,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ led_off_dac_v = scmd.value0; // use FAST mode at 99 state led_off_pd = (uint8_t)scmd.value1; if(cmd_t == CMD_UART) { DBG_PRINTF("rzj0\r\n\r\n"); } else if(cmd_t == CMD_BLE) { result_data[0] = scmd.value0; result_data[1] = scmd.value1; format_data(ble_bin_buffer, "rzj:", result_data, 4); binary_tx_handler(ble_bin_buffer,4); } } } // saj else if((scmd.tag[1] == 'a') && (scmd.tag[2] == 'j')){ // PD_ADC Full, Loop for Sector 1,2,3,4,5,6,7,8 saj saj saj if(length_error(scmd.tag,14,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else { sel_led_index0 = scmd.value0; sel_led_index1 = scmd.value1; sel_led_index2 = scmd.value2; sel_led_index3 = scmd.value3; processing = true ; battery_timer_stop(); AGC_GAIN_SW(false); pd_adc_imm_start = true; ble_got_new_data =false; imm_adc_start_init(); } } // ssk else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'k')){ // Set the number of times of PD_ADC //ret_code_t err_code; if(length_error(scmd.tag,8,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ imsi_value = scmd.value0; for(uint8_t i = 0; i <= 4; i++ ) { if(i == 4) { DBG_PRINTF("ERR!!! pd_adc_cnt failed!\r\n\r\n"); break; } if(pd_adc_counts[i] == imsi_value) { m_pd_adc_cnt = imsi_value; if(cmd_t == CMD_UART) { DBG_PRINTF("Tk0\r\n\r\n"); } else if(cmd_t == CMD_BLE) { result = scmd.value0; single_format_data(ble_bin_buffer, "rsk:", scmd.value0); binary_tx_handler(ble_bin_buffer,3); //err_code = eeprom_write_byte(0x0070, m_pd_adc_cnt); } break; } } } } // srk else if((scmd.tag[1] == 'r') && (scmd.tag[2] == 'k')){ // Set the number of times of PD_ADC if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ //imsi_value = scmd.value0; uint16_t rk_value; rk_value = (uint16_t)m_pd_adc_cnt; if(cmd_t == CMD_UART) { DBG_PRINTF("Tk0\r\n\r\n"); } else if(cmd_t == CMD_BLE) { result = scmd.value0; single_format_data(ble_bin_buffer, "rrk:", rk_value); binary_tx_handler(ble_bin_buffer,3); } } } // ssl else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'l')){ // Set the delay for PD stabilization. 0µs ~ FFFF(65535)µs // ret_code_t err_code; imsi_value = scmd.value0; if(length_error(scmd.tag,8,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else if((imsi_value >= 1)&&(imsi_value <= 65535)) { m_pd_delay_us = imsi_value; if(cmd_t == CMD_UART) { DBG_PRINTF("Tl0\r\n\r\n"); } else if(cmd_t == CMD_BLE) { eeprom_write_word(0x0080, m_pd_delay_us); DBG_PRINTF("m_pd_delay_us=%d\r\n",m_pd_delay_us); single_format_data(ble_bin_buffer, "rsl:", scmd.value0); binary_tx_handler(ble_bin_buffer,3); } }else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! pd_delay_us failed!\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // srl else if((scmd.tag[1] == 'r') && (scmd.tag[2] == 'l')){ // Set the delay for PD stabilization. 0µs ~ FFFF(65535)µs if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else { uint16_t rl_value; rl_value = m_pd_delay_us; if(cmd_t == CMD_UART) { DBG_PRINTF("rrl:\r\n\r\n"); } else if(cmd_t == CMD_BLE) { single_format_data(ble_bin_buffer, "rrl:", rl_value); binary_tx_handler(ble_bin_buffer,3); } } } // ssn else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'n')){ // Measuring the Battery level battery_level_meas(); } // spn else if((scmd.tag[1] == 'p') && (scmd.tag[2] == 'n')){ // Measuring the pressure1 level read pressure_all_level_meas(); // pressure1 + pressure2 } // sso else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'o')){ // Measuring the Temperature of LED if(length_error(scmd.tag,6,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ tmp235_voltage_level_meas(); } } // ssp else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'p')){ // Measuring the raw data of 6-axis motion sensor hw_i2c_init_once(); motion_raw_data_enabled = true; hw_i2c_init_once(); ble_got_new_data =false; if(data_array[2] == 'c') { motion_data_once = false; } else { motion_data_once = true; } main_timer_start(); // }else if((scmd.tag[1] == 'P') && (scmd.tag[2] == 'p')){ // Measuring the raw data of 6-axis motion sensor // motion_raw_data_enabled = true; // ble_got_new_data =false; // // // motion_data_once = false; // // main_timer_start(); } // ssq else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'q')){ // Device power off if(cmd_t == CMD_UART) { DBG_PRINTF("Tq\r\n\r\n"); } else if(cmd_t == CMD_BLE) { single_format_data(ble_bin_buffer, "rsq:", scmd.value0); binary_tx_handler(ble_bin_buffer,2); // sprintf(ble_tx_buffer, "Tq\r\n"); // data_tx_handler(ble_tx_buffer); } go_device_power_off = true; main_timer_start(); #if FEATURE_SECURE_CONNECTION } // ssr else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'r')){ // Bond Info Delete // ret_code_t err_code; if(cmd_t == CMD_UART) { DBG_PRINTF("Tr\r\n\r\n"); } else if(cmd_t == CMD_BLE) { single_format_data(ble_bin_buffer, "rsr:", scmd.value0); binary_tx_handler(ble_bin_buffer,2); } bond_data_delete = true; eeprom_write_byte(0x0060, (uint8_t)bond_data_delete); //m_config.reset_status = 2; m_reset_status = 2; eeprom_write_byte(0x0065, m_reset_status); //config_save(); nrf_delay_ms(5); go_NVIC_SystemReset = true; main_timer_start(); #endif } // sss else if((scmd.tag[1] == 's') && (scmd.tag[2] == 's')){ //Device reset(Reboot) // ret_code_t err_code; // err_code = eeprom_write_byte(0x0060, 0x00); //ret_code_t err_code; if(cmd_t == CMD_UART) { DBG_PRINTF("Ts\r\n\r\n"); } else if(cmd_t == CMD_BLE) { single_format_data(ble_bin_buffer, "rss:", scmd.value0); binary_tx_handler(ble_bin_buffer,2); } go_NVIC_SystemReset = true; //m_config.reset_status = 2; m_reset_status = 2; eeprom_write_byte(0x0065, m_reset_status); // config_save(); nrf_delay_ms(5); go_NVIC_SystemReset = true; main_timer_start(); } // sst else if((scmd.tag[1] == 's') && (scmd.tag[2] == 't')){ // Auto Gain Control if(cmd_t == CMD_UART) { DBG_PRINTF("Ready\r\n\r\nREADY\r\n"); } else if(cmd_t == CMD_BLE) { single_format_data(ble_bin_buffer, "rst:", scmd.value0); binary_tx_handler(ble_bin_buffer,2); } } // ssv else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'v')){ // Auto Gain Control if(cmd_t == CMD_UART) { DBG_PRINTF("%s\r\n",DEVICE_VERSION); } else if(cmd_t == CMD_BLE) { ascii_format_data(ble_bin_buffer, "rsv:", DEVICE_VERSION,12); binary_tx_handler(ble_bin_buffer,8); //test_eeprom_page_rw(); } } // ssz else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'z')){ //Write, Serial Number if(length_error(scmd.tag,18,length)==false) { return; } uint8_t tx_data[EEPROM_PAGE_SIZE]; uint8_t rx_data[EEPROM_PAGE_SIZE]; uint8_t raw_data[EEPROM_PAGE_SIZE]; if(cmd_t == CMD_UART) { DBG_PRINTF("Tz0\r\n\r\n"); } else if(cmd_t == CMD_BLE) { //eeprom_write_encrypted(0x0000, secret_data, strlen((char *)secret_data)); //eeprom_read_decrypted(0x0000, decrypted, strlen((char *)secret_data)); //DBG_PRINTF("Decrypted: %s\n", decrypted); memcpy(SERIAL_NO, scmd.value_ascii, 12); //eeprom_write_bytes(uint16_t mem_address, const uint8_t *data, size_t length) for (uint8_t i=0 ; i<12 ;i++) { tx_data[i] = (uint8_t)(scmd.value_ascii[i]); } // if (eeprom_write_bytes(0x0030 , tx_data ,12) !=NRF_SUCCESS) // { // DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n"); // } if(eeprom_write_encrypted(0x0030, tx_data, 12)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");; } if(eeprom_read_bytes(0x0030, raw_data, 12)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");; } nrf_delay_ms(10); DBG_PRINTF("encrypted: %s\n", raw_data); if(eeprom_read_decrypted(0x0030, rx_data, 12)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");; } DBG_PRINTF("Decrypted: %s\n", rx_data); ascii_format_data(ble_bin_buffer, "rsz:", scmd.value_ascii,12); binary_tx_handler(ble_bin_buffer,8); } else{ DBG_PRINTF("ERR!!! Serial_number 12\r\n\r\n"); if(cmd_t == CMD_UART) { DBG_PRINTF("Tz0FF\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // spz else if((scmd.tag[1] == 'p') && (scmd.tag[2] == 'z')){ //Write, passkey if(length_error(scmd.tag,12,length)==false) { return; } uint8_t tx_data[EEPROM_PAGE_SIZE]; uint8_t rx_data[EEPROM_PAGE_SIZE]; uint8_t raw_data[EEPROM_PAGE_SIZE]; if(cmd_t == CMD_UART) { DBG_PRINTF("Tz0\r\n\r\n"); } else if(cmd_t == CMD_BLE) { //memcpy(SERIAL_NO, scmd.value_ascii, 6); //eeprom_write_bytes(uint16_t mem_address, const uint8_t *data, size_t length) for (uint8_t i=0 ; i<6 ;i++) { tx_data[i] = (uint8_t)(scmd.value_ascii[i]); } if(eeprom_write_encrypted(0x0020, tx_data, 6)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_passkey 6\r\n\r\n");; } if(eeprom_read_bytes(0x0020, raw_data, 6)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_passkey 6\r\n\r\n");; } nrf_delay_ms(10); DBG_PRINTF("encrypted: %s\n", raw_data); if(eeprom_read_decrypted(0x0020, rx_data, 6)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_passkey 6\r\n\r\n");; } DBG_PRINTF("Decrypted: %s\n", rx_data); ascii_format_data(ble_bin_buffer, "rpz:", scmd.value_ascii,6); binary_tx_handler(ble_bin_buffer,5); } else{ DBG_PRINTF("ERR!!! passkey 6\r\n\r\n"); if(cmd_t == CMD_UART) { DBG_PRINTF("Tpz0FF\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // sqz else if((scmd.tag[1] == 'q') && (scmd.tag[2] == 'z')){ // Read, Serial Number uint8_t rx_data[EEPROM_PAGE_SIZE]; if(cmd_t == CMD_UART) { DBG_PRINTF("Tz1,%s\r\n\r\n", SERIAL_NO); } else if(cmd_t == CMD_BLE) { hw_i2c_init_once(); if(eeprom_read_decrypted(0x0020, rx_data, 6)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");; } DBG_PRINTF("Decrypted: %s\n", rx_data); // if (eeprom_read_bytes(0x0030 , rx_data ,12) !=NRF_SUCCESS) // { // DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n"); // } // sprintf(ble_tx_buffer, "Tz1,%s\r\n", m_config.serial_number); // data_tx_handler(ble_tx_buffer); for (uint8_t i=0 ; i<6 ;i++) { (m_static_passkey[i]) = (char)rx_data[i] ; } ascii_format_data(ble_bin_buffer, "rqz:", m_static_passkey,6); binary_tx_handler(ble_bin_buffer,5); } } // srz else if((scmd.tag[1] == 'r') && (scmd.tag[2] == 'z')){ // Read, Serial Number uint8_t rx_data[EEPROM_PAGE_SIZE]; if(cmd_t == CMD_UART) { DBG_PRINTF("Tz1,%s\r\n\r\n", SERIAL_NO); } else if(cmd_t == CMD_BLE) { if(eeprom_read_decrypted(0x0030, rx_data, 12)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");; } DBG_PRINTF("Decrypted: %s\n", rx_data); // if (eeprom_read_bytes(0x0030 , rx_data ,12) !=NRF_SUCCESS) // { // DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n"); // } // sprintf(ble_tx_buffer, "Tz1,%s\r\n", m_config.serial_number); // data_tx_handler(ble_tx_buffer); for (uint8_t i=0 ; i<12 ;i++) { (SERIAL_NO[i]) = (char)rx_data[i] ; } ascii_format_data(ble_bin_buffer, "rrz:", SERIAL_NO,12); binary_tx_handler(ble_bin_buffer,8); } #if 0 // ===== EEPROM start block ===== // }else if((scmd.tag[1] == 'a') && (scmd.tag[2] == 'z')){ // write bytes // // // uint8_t write_data[64]; // // memcpy(write_data,scmd.value_ascii,12); // eeprom_write_bytes(scmd.value0,write_data,12); // if(cmd_t == CMD_UART) { // DBG_PRINTF("Tz2,%s\r\n\r\n",write_data); // } else if(cmd_t == CMD_BLE) { // sprintf(ble_tx_buffer, "Tz22,%s\r\n", write_data); // data_tx_handler(ble_tx_buffer); // } // }else if((scmd.tag[1] == 'b') && (scmd.tag[2] == 'z')){ // // unsigned char *read_data; // // eeprom_read_bytes(scmd.value0,read_data,12); // // if(cmd_t == CMD_UART) { // DBG_PRINTF("Tz3,%s,%s\r\n\r\n", read_data,read_data); // } else if(cmd_t == CMD_BLE) { // sprintf(ble_tx_buffer, "Tz3,%s\r\n",read_data); // data_tx_handler(ble_tx_buffer); // } // }else if((scmd.tag[1] == 'c') && (scmd.tag[2] == 'z')){ // write page // // //unsigned char read_data[EEPROM_PAGE_SIZE]; // uint8_t write_data[64]; // for(uint8_t i=0 ; i<64 ;i++){ // write_data[i] = scmd.values[i+6]; // } // // //memcpy(write_data,scmd.value_ascii,12); // eeprom_write_page (scmd.value0,write_data); // // if(cmd_t == CMD_UART) { // DBG_PRINTF("Tz3,%s\r\n\r\n", write_data); // } else if(cmd_t == CMD_BLE) { //// sprintf(ble_tx_buffer, "Tz3,%s\r\n",read_data // ascii_format_data(ble_bin_buffer, "rcz:", "ok",3); // binary_tx_handler(ble_bin_buffer,5); //// data_tx_handler(ble_tx_buffer); // } // // // // // // }else if((scmd.tag[1] == 'd') && (scmd.tag[2] == 'z')){ // Read page // // uint8_t read_data[64]; // eeprom_read_page (scmd.value0,read_data); // // if(cmd_t == CMD_UART) { // // DBG_PRINTF("Tz3,%s,%s\r\n\r\n", read_data,read_data); // } else if(cmd_t == CMD_BLE) { // for (int i = 0; i < EEPROM_PAGE_SIZE; i++) { // // DBG_PRINTF("%02X,", read_data[i]); // } // // // format_data_byte(ble_bin_buffer, "rdz:", read_data,64); // binary_tx_handler(ble_bin_buffer,34); // } //ret_code_t eeprom_write_uint16_array(uint16_t start_address, const uint16_t *data, size_t count) #endif // ===== EEPROM block End ===== } // sez else if((scmd.tag[1] == 'e') && (scmd.tag[2] == 'z')){ // Read, Serial Number hw_i2c_init_once(); uint16_t write_data[64]; for (int i = 0; i < 48; i++) { write_data[i]= (uint16_t)(scmd.values[i*2+7] | (uint16_t)(scmd.values[i*2+6] << 8)); } eeprom_write_uint16_array(scmd.value0,write_data,48); if(cmd_t == CMD_UART) { DBG_PRINTF("rez,%s\r\n\r\n", scmd.value_ascii); } else if(cmd_t == CMD_BLE) { format_data(ble_bin_buffer, "rez:", write_data,48); binary_tx_handler(ble_bin_buffer,50); } } // sfz else if((scmd.tag[1] == 'f') && (scmd.tag[2] == 'z')){ // Read, Serial Number sfz arry eeprom read if(length_error(scmd.tag,8,length)==false) { return; } // else if(activate_error(scmd.tag,device_status)==false) // { // return; // } else{ hw_i2c_init_once(); uint16_t read_data[64]; //uint8_t EEPread_data[64]; eeprom_read_uint16_array(scmd.value0,read_data,48); //int16(48ea) DP Preset 0~6 // for (int i = 0; i < 48; i++) { // EEPread_data[i]= (uint8_t)(read_data[i]); // } if(cmd_t == CMD_UART) { DBG_PRINTF("ref,%s\r\n\r\n", scmd.value_ascii); } else if(cmd_t == CMD_BLE) { format_data(ble_bin_buffer, "rfz:", read_data,48); binary_tx_handler(ble_bin_buffer,50); } } } // sgz else if((scmd.tag[1] == 'g') && (scmd.tag[2] == 'z')){ // Read, DCP r sgz if(length_error(scmd.tag,8,length)==false) { return; } else if(activate_error(scmd.tag,device_status)==false) { return; } else{ hw_i2c_init_once(); uint16_t read_data[64]; uint8_t EEPread_data[64]; eeprom_read_uint16_array(scmd.value0,read_data,48); for (int i = 0; i < 48; i++) { EEPread_data[i]= (uint8_t)(read_data[i]); } if(cmd_t == CMD_UART) { DBG_PRINTF("ref,%s\r\n\r\n", scmd.value_ascii); } else if(cmd_t == CMD_BLE) { if(led_power_save_mem_48( EEPread_data)){ DBG_PRINTF("error,%s\r\n\r\n", scmd.value_ascii); } format_data(ble_bin_buffer, "rgz:", read_data,48); binary_tx_handler(ble_bin_buffer,50); } } } // siz else if((scmd.tag[1] == 'i') && (scmd.tag[2] == 'z')){ // Read, HW hw_i2c_init_once(); uint8_t rx_data[EEPROM_PAGE_SIZE]; if(cmd_t == CMD_UART) { DBG_PRINTF("Tz1,%s\r\n\r\n", HW_NO); } else if(cmd_t == CMD_BLE) { if(eeprom_read_decrypted(0x0010, rx_data, 12)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");; } DBG_PRINTF("Decrypted: %s\n", rx_data); // if (eeprom_read_bytes(0x0030 , rx_data ,12) !=NRF_SUCCESS) // { // DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n"); // } // sprintf(ble_tx_buffer, "Tz1,%s\r\n", m_config.serial_number); // data_tx_handler(ble_tx_buffer); for (uint8_t i=0 ; i<12 ;i++) { (HW_NO[i]) = (char)rx_data[i] ; } ascii_format_data(ble_bin_buffer, "riz:", HW_NO,12); binary_tx_handler(ble_bin_buffer,8); } } // shz else if((scmd.tag[1] == 'h') && (scmd.tag[2] == 'z')){ //Write, HW if(length_error(scmd.tag,18,length)==false) { return; } hw_i2c_init_once(); uint8_t tx_data[EEPROM_PAGE_SIZE]; uint8_t rx_data[EEPROM_PAGE_SIZE]; uint8_t raw_data[EEPROM_PAGE_SIZE]; if(cmd_t == CMD_UART) { DBG_PRINTF("Tz0\r\n\r\n"); } else if(cmd_t == CMD_BLE) { memcpy(HW_NO, scmd.value_ascii, 12); //eeprom_write_bytes(uint16_t mem_address, const uint8_t *data, size_t length) for (uint8_t i=0 ; i<12 ;i++) { tx_data[i] = (uint8_t)(scmd.value_ascii[i]); } if(eeprom_write_encrypted(0x0010, tx_data, 12)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");; } if(eeprom_read_bytes(0x0010, raw_data, 12)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");; } nrf_delay_ms(10); DBG_PRINTF("encrypted: %s\n", raw_data); if(eeprom_read_decrypted(0x0010, rx_data, 12)!= NRF_SUCCESS) { DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");; } DBG_PRINTF("Decrypted: %s\n", rx_data); ascii_format_data(ble_bin_buffer, "rhz:", scmd.value_ascii,12); binary_tx_handler(ble_bin_buffer,8); } else{ DBG_PRINTF("ERR!!! passkey 6\r\n\r\n"); if(cmd_t == CMD_UART) { DBG_PRINTF("Tpz0FF\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // sxz else if((scmd.tag[1] == 'x') && (scmd.tag[2] == 'z')){ // Set the delay for PD stabilization. 0µs ~ FFFF(65535)µs m_life_cycle = ((uint16_t)scmd.value0 << 16) | ((uint16_t)scmd.value1 & 0xFFFF); result_data[0] = scmd.value0; result_data[1] = scmd.value1; if(length_error(scmd.tag,10,length)==false) { return; } else if((m_life_cycle > 0)||(m_life_cycle <= 99999999)) { if(cmd_t == CMD_UART) { DBG_PRINTF("rxz\r\n\r\n"); } else if(cmd_t == CMD_BLE) { hw_i2c_init_once(); eeprom_write_uint32(0x0090, m_life_cycle); format_data(ble_bin_buffer, "rxz:", result_data,2); binary_tx_handler(ble_bin_buffer,4); } }else{ if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! pd_delay_us failed!\r\n\r\n"); } else if(cmd_t == CMD_BLE) { param_error(scmd.tag ); } } } // syz else if((scmd.tag[1] == 'y') && (scmd.tag[2] == 'z')){ // if(length_error(scmd.tag,6,length)==false) { return; } else { eeprom_read_uint32(0x0090, &m_life_cycle); //thnk cj result_data[0] = (uint16_t)(m_life_cycle >> 16); result_data[1] = (uint16_t)(m_life_cycle & 0xFFFF); if(cmd_t == CMD_UART) { DBG_PRINTF("ryz:\r\n\r\n"); } else if(cmd_t == CMD_BLE) { format_data(ble_bin_buffer, "ryz:", result_data,4); binary_tx_handler(ble_bin_buffer,4); } } //ret_code_t eeprom_write_uint32(uint16_t mem_address, uint32_t data); }else { if(cmd_t == CMD_UART) { DBG_PRINTF("ERR!!! UART Command Failed, %c%c%c%c\r\n",data_array[0], data_array[1], data_array[2], data_array[3]); } else if(cmd_t == CMD_BLE) { single_format_data(ble_bin_buffer, "err!", err_code5); binary_tx_handler(ble_bin_buffer,3); } } } } } /** * @} */ //0x0A