Add new parser commands and FDS reliability fix
- HW Number Read/Write (mwh?, mrh?) - Serial Number Read/Write (mws?, mrs?) - FW Version Read (mfv?) - Piezo TX/RX Deactivate (mpb?) - Fix config_save() to wait for previous FDS operation instead of skipping - Disable legacy s-prefix commands (ssz, srz, siz, shz, ssv) in cmd_parse.c Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
160
pc_firm/parser.c
160
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;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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 )
|
||||
|
||||
Reference in New Issue
Block a user