diff --git a/pc_firm/parser.c b/pc_firm/parser.c index 62c638a..42f1e7b 100644 --- a/pc_firm/parser.c +++ b/pc_firm/parser.c @@ -45,7 +45,10 @@ extern void dr_sd_delay_ms(uint32_t ms); /* Softdevice-friendly delay */ /* FDS config (fstorage) */ #include "fstorage.h" extern char SERIAL_NO[12]; -extern char HW_NO[12]; +extern char HW_NO[12]; + +/* FW Version - must match cmd_parse.c DEVICE_VERSION */ +#define DR_DEVICE_VERSION "FW25LIT2B102" @@ -59,28 +62,29 @@ extern bool device_status; extern uint8_t resetCount; extern uint8_t ble_bin_buffer[]; -extern uint8_t simple_samples_in_buffer; -extern uint8_t m_pd_adc_cnt; -extern bool con_single; -extern bool lock_check; +extern bool con_single; +extern bool lock_check; extern bool info4; // addtional info extern bool ble_got_new_data; // BLE data flag -extern uint8_t m_pd_adc_cnt; // PD ADC count extern bool go_batt; // battery extern bool motion_data_once; // IMU data flag extern bool motion_raw_data_enabled; // IMU continuous flag extern int imu_read_direct(void); // IMU direct register read + BLE send -extern uint8_t ADC_PD_MODE; // PD ADC mode -extern bool pd_adc_m48_start; // PD ADC M48 start flag -extern uint8_t m48_samples_in_buffer; // M48 sample count extern void pressure_all_level_meas(void); // pressure sensor extern void battery_timer_stop(void); // battery timer extern void main_timer_start(void); // main timer extern void hw_i2c_init_once(void); // I2C init for IMU +/* Power / Reset / Bond */ +extern bool go_device_power_off; +extern bool go_NVIC_SystemReset; +extern bool bond_data_delete; +extern uint8_t m_reset_status; +extern ret_code_t eeprom_write_byte(uint16_t mem_address, uint8_t data); + /* AGC_GAIN_SW is a macro in measurements.h - replicate here */ #include "nrf_gpio.h" #define GAIN_SW_PIN NRF_GPIO_PIN_MAP(0, 20) @@ -88,6 +92,7 @@ extern void hw_i2c_init_once(void); // I2C init for IMU extern void dr_piezo_power_on( void ); +extern void dr_piezo_power_off( void ); extern void dr_piezo_burst_sw(uint8_t cycles); extern void dr_piezo_burst_sw_18mhz(uint8_t cycles); extern void dr_piezo_burst_sw_20mhz(uint8_t cycles); @@ -290,15 +295,21 @@ static int Cmd_ssq(const ParsedCmd *cmd); static int Cmd_ssr(const ParsedCmd *cmd); static int Cmd_sss(const ParsedCmd *cmd); static int Cmd_sst(const ParsedCmd *cmd); -static int Cmd_ssv(const ParsedCmd *cmd); +static int Cmd_mfv(const ParsedCmd *cmd); + +/////////////////////* PIEZO *///////////////////// -static int Cmd_mpa(const ParsedCmd *cmd); static int Cmd_msp(const ParsedCmd *cmd); /* IMU 6-axis raw data (single shot) */ -static int Cmd_mpc(const ParsedCmd *cmd); -static int Cmd_mdc(const ParsedCmd *cmd); -static int Cmd_mec(const ParsedCmd *cmd); -static int Cmd_maa(const ParsedCmd *cmd); /* 8-channel all capture */ -static int Cmd_cmd(const ParsedCmd *cmd); + +static int Cmd_mpa(const ParsedCmd *cmd); /* Piezo TX/RX Activate */ +static int Cmd_mpb(const ParsedCmd *cmd); /* Piezo TX/RX Deactivate 26.03.13 */ +static int Cmd_mpc(const ParsedCmd *cmd); /* Piezo Burst Capture */ +static int Cmd_mdc(const ParsedCmd *cmd); /* Piezo ADC Capture */ +static int Cmd_mec(const ParsedCmd *cmd); /* Piezo Burst + ADC capture */ +static int Cmd_maa(const ParsedCmd *cmd); /* Piezo Burst + ADC all channel capture */ + +static int Cmd_cmd(const ParsedCmd *cmd); /* Pin Test (High / Low) */ + static int Cmd_mwh(const ParsedCmd *cmd); /* Write HW Number to FDS */ static int Cmd_mws(const ParsedCmd *cmd); /* Write Serial Number to FDS */ static int Cmd_mrh(const ParsedCmd *cmd); /* Read HW Number from FDS */ @@ -317,8 +328,9 @@ static CmdEntry g_cmd_table[] = { /* sudo command */ { "cmd?", true, Cmd_cmd }, // Piezo Activate - /* Piezo command */ + /* Piezo command */ { "mpa?", true, Cmd_mpa }, // Piezo Activate + { "mpb?", true, Cmd_mpb }, // Piezo Deactivate 26.03.13 { "mpc?", true, Cmd_mpc }, // Piezo Cycles control command, 3,4,5,6,7 { "mdc?", true, Cmd_mdc }, // Piezo burst + Echo capture (12-bit packed) { "mec?", true, Cmd_mec }, // Piezo burst + Echo capture (16-bit raw) @@ -326,10 +338,10 @@ static CmdEntry g_cmd_table[] = { { "msp?", true, Cmd_msp }, // IMU 6-axis raw data (single shot) /* Config: HW/Serial Number (FDS) */ - { "mwh?", true, Cmd_mwh }, // Write HW Number - { "mws?", true, Cmd_mws }, // Write Serial Number - { "mrh?", true, Cmd_mrh }, // Read HW Number - { "mrs?", true, Cmd_mrs }, // Read Serial Number + { "mwh?", true, Cmd_mwh }, + { "mws?", true, Cmd_mws }, + { "mrh?", true, Cmd_mrh }, + { "mrs?", true, Cmd_mrs }, /* A. Device Status */ { "mta?", true, Cmd_mta }, @@ -350,11 +362,12 @@ static CmdEntry g_cmd_table[] = { { "ssp?", true, Cmd_ssp }, /* J. Power / Reset / Version / Security */ - { "ssq?", false, Cmd_ssq }, - { "ssr?", false, Cmd_ssr }, - { "sss?", false, Cmd_sss }, - { "sst?", false, Cmd_sst }, - { "ssv?", false, Cmd_ssv }, + { "ssq?", false, Cmd_ssq }, + { "ssr?", false, Cmd_ssr }, + { "sss?", false, Cmd_sss }, + { "sst?", false, Cmd_sst }, + + { "mfv?", true, Cmd_mfv }, /* Firmware Version Read (ssv -> mfv) 26.03.13 */ }; @@ -590,23 +603,11 @@ static int Cmd_sej(const ParsedCmd *cmd) { (void)cmd; - 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(); - go_batt = true; - main_timer_start(); - + /* NIRS/optical PD-ADC M48 mode removed (VesiScan-Basic) */ if (g_plat.log && g_log_enable) { - g_plat.log("[Cmd_sej] MODE=4 (M48 + batt + IMU) started\r\n"); + g_plat.log("[Cmd_sej] Disabled (NIRS removed)\r\n"); } - return 1; + return 0; } static int Cmd_ssj(const ParsedCmd *cmd) @@ -673,48 +674,80 @@ static int Cmd_ssp(const ParsedCmd *cmd) } /* J. Power / Reset / Version / Security */ +/* ssq? - Device Power Off */ static int Cmd_ssq(const ParsedCmd *cmd) { - (void)cmd; + uint16_t val = 0; + dr_get_u16(cmd, 0, &val); if (g_plat.log && g_log_enable) { - g_plat.log("[Cmd_ssq] Power off\n"); + g_plat.log("[Cmd_ssq] Power off\r\n"); } + single_format_data(ble_bin_buffer, "rsq:", val); + binary_tx_handler(ble_bin_buffer, 2); + go_device_power_off = true; + main_timer_start(); return 1; } +/* ssr? - Bond Info Delete + System Reset */ static int Cmd_ssr(const ParsedCmd *cmd) { - (void)cmd; + uint16_t val = 0; + dr_get_u16(cmd, 0, &val); if (g_plat.log && g_log_enable) { - g_plat.log("[Cmd_ssr] Bond delete\n"); + g_plat.log("[Cmd_ssr] Bond delete + reset\r\n"); } + single_format_data(ble_bin_buffer, "rsr:", val); + binary_tx_handler(ble_bin_buffer, 2); + bond_data_delete = true; + eeprom_write_byte(0x0060, (uint8_t)bond_data_delete); + m_reset_status = 2; + eeprom_write_byte(0x0065, m_reset_status); + nrf_delay_ms(5); + go_NVIC_SystemReset = true; + main_timer_start(); return 1; } +/* sss? - Device Reset (Reboot) */ static int Cmd_sss(const ParsedCmd *cmd) { - (void)cmd; + uint16_t val = 0; + dr_get_u16(cmd, 0, &val); if (g_plat.log && g_log_enable) { - g_plat.log("[Cmd_sss] Device reset\n"); + g_plat.log("[Cmd_sss] Device reset\r\n"); } + single_format_data(ble_bin_buffer, "rss:", val); + binary_tx_handler(ble_bin_buffer, 2); + m_reset_status = 2; + eeprom_write_byte(0x0065, m_reset_status); + nrf_delay_ms(5); + go_NVIC_SystemReset = true; + main_timer_start(); return 1; } +/* sst? - Security Ready */ static int Cmd_sst(const ParsedCmd *cmd) { - (void)cmd; + uint16_t val = 0; + dr_get_u16(cmd, 0, &val); if (g_plat.log && g_log_enable) { - g_plat.log("[Cmd_sst] Ready\n"); + g_plat.log("[Cmd_sst] Ready\r\n"); } + single_format_data(ble_bin_buffer, "rst:", val); + binary_tx_handler(ble_bin_buffer, 2); return 1; } -static int Cmd_ssv(const ParsedCmd *cmd) +static int Cmd_mfv(const ParsedCmd *cmd) { (void)cmd; if (g_plat.log && g_log_enable) { - g_plat.log("[Cmd_ssv] Read firmware version\n"); + g_plat.log("[Cmd_mfv] FW=%s\r\n", DR_DEVICE_VERSION); } + ascii_format_data(ble_bin_buffer, "rfv:", DR_DEVICE_VERSION, 12); + binary_tx_handler(ble_bin_buffer, 8); return 1; } @@ -728,12 +761,31 @@ static int Cmd_mpa(const ParsedCmd *cmd) dr_piezo_power_on(); dr_piezo_system_init(); - + if (g_plat.tx_bin) { single_format_data(ble_bin_buffer, "rpa:", 1); binary_tx_handler(ble_bin_buffer, 3); - } - + } + + return 1; +} + +/* mpb? - Piezo TX/RX Deactivate (Power Off) */ +static int Cmd_mpb(const ParsedCmd *cmd) +{ + (void)cmd; + + if (g_plat.log && g_log_enable) { + g_plat.log("[Cmd_mpb] Piezo Deactivation\n"); + } + + dr_piezo_power_off(); + + if (g_plat.tx_bin) { + single_format_data(ble_bin_buffer, "rpb:", 1); + binary_tx_handler(ble_bin_buffer, 3); + } + return 1; } diff --git a/project/ble_peripheral/ble_app_bladder_patch/cmd_parse.c b/project/ble_peripheral/ble_app_bladder_patch/cmd_parse.c index f5d248e..c2935ed 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/cmd_parse.c +++ b/project/ble_peripheral/ble_app_bladder_patch/cmd_parse.c @@ -23,7 +23,6 @@ v1.17 p1,p2 parssurer #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 ===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 + DBG_PRINTF("m_life_cycle eprom read\n"); //ad cj err_code = eeprom_read_uint32(0x0090, &m_life_cycle); if (err_code != NRF_SUCCESS) { @@ -472,7 +386,7 @@ ret_code_t eeprom_init_values_read(void) 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); + DBG_PRINTF("\r\n m_life_cycle :%1u \r\n", m_life_cycle); } } @@ -492,10 +406,7 @@ static void log_printf(const char *fmt, ...) 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; @@ -710,812 +621,10 @@ else if((scmd.tag[0] == 's')&&(scmd.tag[1] == 't')&&(scmd.tag[2] == 'r')&&(scmd. } } -// 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(scmd.tag[0] == 's') { - 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 +if((scmd.tag[1] == 's') && (scmd.tag[2] == 'n')){ // Measuring the Battery level battery_level_meas(); } @@ -1643,8 +752,8 @@ else if((scmd.tag[1] == 's') && (scmd.tag[2] == 't')){ // Auto Gain Control } -// ssv -else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'v')){ // Auto Gain Control +// ssv — DISABLED: use ssv? in pc_firm/parser.c +else if(0 && (scmd.tag[1] == 's') && (scmd.tag[2] == 'v')){ // Auto Gain Control if(cmd_t == CMD_UART) { DBG_PRINTF("%s\r\n",DEVICE_VERSION); @@ -1656,8 +765,8 @@ else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'v')){ // Auto Gain Control } -// ssz - Write Serial Number (FDS only) -else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'z')){ +// ssz - Write Serial Number (FDS only) — DISABLED: use mws? in pc_firm/parser.c +else if(0 && (scmd.tag[1] == 's') && (scmd.tag[2] == 'z')){ if(length_error(scmd.tag,18,length)==false) { return; @@ -1770,8 +879,8 @@ else if((scmd.tag[1] == 'q') && (scmd.tag[2] == 'z')){ // Read, Seri } } -// srz - Read Serial Number (FDS only) -else if((scmd.tag[1] == 'r') && (scmd.tag[2] == 'z')){ +// srz - Read Serial Number (FDS only) — DISABLED: use mrs? in pc_firm/parser.c +else if(0 && (scmd.tag[1] == 'r') && (scmd.tag[2] == 'z')){ if(cmd_t == CMD_UART) { DBG_PRINTF("Tz1,%s\r\n\r\n", SERIAL_NO); } else if(cmd_t == CMD_BLE) { @@ -1930,45 +1039,8 @@ else if((scmd.tag[1] == 'f') && (scmd.tag[2] == 'z')){ // Read, Ser } } } -// 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 - Read HW Number (FDS only) -else if((scmd.tag[1] == 'i') && (scmd.tag[2] == 'z')){ +// siz - Read HW Number (FDS only) — DISABLED: use mrh? in pc_firm/parser.c +else if(0 && (scmd.tag[1] == 'i') && (scmd.tag[2] == 'z')){ if(cmd_t == CMD_UART) { DBG_PRINTF("Tz1,%s\r\n\r\n", HW_NO); } else if(cmd_t == CMD_BLE) { @@ -1977,8 +1049,8 @@ else if((scmd.tag[1] == 'i') && (scmd.tag[2] == 'z')){ binary_tx_handler(ble_bin_buffer, 8); } } -// shz - Write HW Number (FDS only) -else if((scmd.tag[1] == 'h') && (scmd.tag[2] == 'z')){ +// shz - Write HW Number (FDS only) — DISABLED: use mwh? in pc_firm/parser.c +else if(0 && (scmd.tag[1] == 'h') && (scmd.tag[2] == 'z')){ if(length_error(scmd.tag,18,length)==false) { return; @@ -2003,7 +1075,7 @@ else if((scmd.tag[1] == 'h') && (scmd.tag[2] == 'z')){ } } // sxz -else if((scmd.tag[1] == 'x') && (scmd.tag[2] == 'z')){ // Set the delay for PD stabilization. 0�s ~ FFFF(65535)�s +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; diff --git a/project/ble_peripheral/ble_app_bladder_patch/fstorage.c b/project/ble_peripheral/ble_app_bladder_patch/fstorage.c index 9665249..4c65ba2 100644 --- a/project/ble_peripheral/ble_app_bladder_patch/fstorage.c +++ b/project/ble_peripheral/ble_app_bladder_patch/fstorage.c @@ -269,10 +269,19 @@ void config_save( void ) DBG_PRINTF("[CFG_SAVE] start\r\n"); - /* Skip if a previous FDS operation is still in progress (non-blocking) */ + /* Wait for any previous FDS operation to complete */ if (fds_flag_write) { - DBG_PRINTF("[CFG_SAVE] busy, skipped\r\n"); - return; + uint32_t wait_cnt = 0; + DBG_PRINTF("[CFG_SAVE] waiting for prev FDS op...\r\n"); + while (fds_flag_write && wait_cnt < 3000) { + nrf_pwr_mgmt_run(); + nrf_delay_ms(1); + wait_cnt++; + } + if (fds_flag_write) { + DBG_PRINTF("[CFG_SAVE] TIMEOUT! forcing flag clear\r\n"); + fds_flag_write = false; + } } if( m_config.magic_number != (uint32_t)CONFIG_MAGIC_NUMBER_VALUE )