코드 정리
- 주석 영문으로 변경 - Allman 스타일로 통일
This commit is contained in:
@@ -19,9 +19,8 @@
|
||||
* Request: [TAG 4B "msq?"] [val 2B BE] [CRC 2B]
|
||||
* Response: [TAG 4B "rsq:"] [val 2B BE] [CRC 2B]
|
||||
*
|
||||
* Sends BLE response first; the actual power-off is performed from the main
|
||||
* loop. Powering off immediately would prevent the response from reaching
|
||||
* the host, so a flag + timer pattern is used instead.
|
||||
* Sends BLE response first; the actual power-off is performed from the main loop.
|
||||
* Powering off immediately would prevent the response from reaching the host, so a flag + timer pattern is used instead.
|
||||
*============================================================================*/
|
||||
int Cmd_msq(const ParsedCmd *cmd)
|
||||
{
|
||||
@@ -44,8 +43,7 @@ int Cmd_msq(const ParsedCmd *cmd)
|
||||
* Request: [TAG 4B "mss?"] [val 2B BE] [CRC 2B]
|
||||
* Response: [TAG 4B "rss:"] [val 2B BE] [CRC 2B]
|
||||
*
|
||||
* Resets without erasing bond information. Reset status code is persisted
|
||||
* to FDS so the boot path can identify the cause.
|
||||
* Resets without erasing bond information. Reset status code is persisted to FDS so the boot path can identify the cause.
|
||||
*============================================================================*/
|
||||
int Cmd_mss(const ParsedCmd *cmd)
|
||||
{
|
||||
@@ -118,9 +116,18 @@ int Cmd_cmd(const ParsedCmd *cmd)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!dr_get_u16(cmd, 0, &v1)) v1 = 0;
|
||||
if (!dr_get_u16(cmd, 1, &v2)) v2 = 0;
|
||||
if (!dr_get_u16(cmd, 2, &v3)) v3 = 0;
|
||||
if (!dr_get_u16(cmd, 0, &v1))
|
||||
{
|
||||
v1 = 0;
|
||||
}
|
||||
if (!dr_get_u16(cmd, 1, &v2))
|
||||
{
|
||||
v2 = 0;
|
||||
}
|
||||
if (!dr_get_u16(cmd, 2, &v3))
|
||||
{
|
||||
v3 = 0;
|
||||
}
|
||||
|
||||
pin_number = NRF_GPIO_PIN_MAP(v1, v2);
|
||||
nrf_gpio_cfg_output(pin_number);
|
||||
@@ -142,15 +149,15 @@ int Cmd_cmd(const ParsedCmd *cmd)
|
||||
* mls? -> rls: Set LED state (app -> device)
|
||||
*
|
||||
* Request: [TAG 4B "mls?"] [state 2B BE] [CRC 2B]
|
||||
* state: led_state_t enum value
|
||||
* 0=OFF, 4=DETACH_WARNING, 5=ALIGN_SEARCHING, 6=ALIGN_COMPLETE
|
||||
* state: led_state_t enum value: 0=OFF, 4=DETACH_WARNING, 5=ALIGN_SEARCHING, 6=ALIGN_COMPLETE
|
||||
* Response: [TAG 4B "rls:"] [state 2B] [CRC 2B]
|
||||
* Error: rls: + 0xFFFF (insufficient data)
|
||||
* rls: + 0xFFFE (state out of range)
|
||||
*============================================================================*/
|
||||
int Cmd_mls(const ParsedCmd *cmd)
|
||||
{
|
||||
if (cmd->data_len < 2) {
|
||||
if (cmd->data_len < 2)
|
||||
{
|
||||
dr_ble_return_1("rls:", 0xFFFF);
|
||||
return 1;
|
||||
}
|
||||
@@ -158,7 +165,8 @@ int Cmd_mls(const ParsedCmd *cmd)
|
||||
uint16_t state;
|
||||
dr_get_u16(cmd, 0, &state);
|
||||
|
||||
if (state > LED_STATE_ERROR) {
|
||||
if (state > LED_STATE_ERROR)
|
||||
{
|
||||
dr_ble_return_1("rls:", 0xFFFE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,8 @@ int Cmd_mwh(const ParsedCmd *cmd)
|
||||
{
|
||||
char buf[13];
|
||||
|
||||
if (cmd->data_len < 12) {
|
||||
if (cmd->data_len < 12)
|
||||
{
|
||||
dr_ble_return_1("rwh:", 0xFFFF);
|
||||
return 1;
|
||||
}
|
||||
@@ -83,7 +84,8 @@ int Cmd_mws(const ParsedCmd *cmd)
|
||||
{
|
||||
char buf[13];
|
||||
|
||||
if (cmd->data_len < 12) {
|
||||
if (cmd->data_len < 12)
|
||||
{
|
||||
dr_ble_return_1("rws:", 0xFFFF);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -22,15 +22,14 @@
|
||||
*
|
||||
* Request: [TAG 4B "mpa?"] [CRC 2B]
|
||||
* Response: [TAG 4B "rpa:"] [1 2B] [CRC 2B]
|
||||
*
|
||||
* Must be called before mec? / maa?.
|
||||
*============================================================================*/
|
||||
int Cmd_mpa(const ParsedCmd *cmd)
|
||||
{
|
||||
(void)cmd;
|
||||
dr_piezo_power_on();
|
||||
|
||||
if (g_plat.tx_bin) {
|
||||
if (g_plat.tx_bin)
|
||||
{
|
||||
single_format_data(ble_bin_buffer, "rpa:", 1);
|
||||
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||
}
|
||||
@@ -50,7 +49,8 @@ int Cmd_mpb(const ParsedCmd *cmd)
|
||||
(void)cmd;
|
||||
dr_piezo_power_off();
|
||||
|
||||
if (g_plat.tx_bin) {
|
||||
if (g_plat.tx_bin)
|
||||
{
|
||||
single_format_data(ble_bin_buffer, "rpb:", 1);
|
||||
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||
}
|
||||
@@ -79,22 +79,36 @@ int Cmd_mpc(const ParsedCmd *cmd)
|
||||
(void)dr_get_u16(cmd, 1, &freq_option);
|
||||
(void)dr_get_u16(cmd, 2, &piezo_ch);
|
||||
|
||||
if (piezo_ch >= MAA_NUM_CHANNELS) piezo_ch = 0;
|
||||
if (piezo_ch >= MAA_NUM_CHANNELS)
|
||||
{
|
||||
piezo_ch = 0;
|
||||
}
|
||||
|
||||
if (cycles < 3 || cycles > 7) {
|
||||
if (cycles < 3 || cycles > 7)
|
||||
{
|
||||
dr_ble_return_1("rpc:", 2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dr_piezo_select_channel((uint8_t)piezo_ch);
|
||||
|
||||
switch (freq_option) {
|
||||
case 0: dr_piezo_burst_sw_18mhz((uint8_t)cycles); break;
|
||||
case 2: dr_piezo_burst_sw_20mhz((uint8_t)cycles); break;
|
||||
case 3: dr_piezo_burst_sw_17mhz((uint8_t)cycles); break;
|
||||
case 4: dr_piezo_burst_sw_22mhz((uint8_t)cycles); break;
|
||||
case 1:
|
||||
default: dr_piezo_burst_sw((uint8_t)cycles); break;
|
||||
switch (freq_option)
|
||||
{
|
||||
case 0:
|
||||
dr_piezo_burst_sw_18mhz((uint8_t)cycles);
|
||||
break;
|
||||
case 2:
|
||||
dr_piezo_burst_sw_20mhz((uint8_t)cycles);
|
||||
break;
|
||||
case 3:
|
||||
dr_piezo_burst_sw_17mhz((uint8_t)cycles);
|
||||
break;
|
||||
case 4:
|
||||
dr_piezo_burst_sw_22mhz((uint8_t)cycles);
|
||||
break;
|
||||
default:
|
||||
dr_piezo_burst_sw((uint8_t)cycles);
|
||||
break;
|
||||
}
|
||||
|
||||
dr_ble_return_1("rpc:", (uint8_t)cycles);
|
||||
@@ -121,7 +135,8 @@ int Cmd_mec(const ParsedCmd *cmd)
|
||||
uint16_t averaging = 1;
|
||||
uint16_t piezo_ch = 0;
|
||||
|
||||
if (!dr_piezo_is_power_on()) {
|
||||
if (!dr_piezo_is_power_on())
|
||||
{
|
||||
dr_piezo_power_on();
|
||||
}
|
||||
|
||||
@@ -132,15 +147,25 @@ int Cmd_mec(const ParsedCmd *cmd)
|
||||
(void)dr_get_u16(cmd, 4, &averaging);
|
||||
(void)dr_get_u16(cmd, 5, &piezo_ch);
|
||||
|
||||
if (averaging == 0) averaging = 1;
|
||||
if (averaging > 1000) averaging = 1000;
|
||||
if (piezo_ch >= MAA_NUM_CHANNELS) piezo_ch = 0;
|
||||
if (averaging == 0)
|
||||
{
|
||||
averaging = 1;
|
||||
}
|
||||
if (averaging > 1000)
|
||||
{
|
||||
averaging = 1000;
|
||||
}
|
||||
if (piezo_ch >= MAA_NUM_CHANNELS)
|
||||
{
|
||||
piezo_ch = 0;
|
||||
}
|
||||
|
||||
dr_adc_err_t err = dr_adc_burst_capture_transmit(
|
||||
(uint8_t)freq_option, delay_us, num_samples, (uint8_t)cycles,
|
||||
(uint16_t)averaging, (uint8_t)piezo_ch, ble_bin_buffer, 0);
|
||||
|
||||
if (err != DR_ADC_OK) {
|
||||
if (err != DR_ADC_OK)
|
||||
{
|
||||
dr_ble_return_2("rer:", 0xEE00 | (uint16_t)err, num_samples);
|
||||
}
|
||||
|
||||
@@ -165,12 +190,14 @@ int Cmd_maa(const ParsedCmd *cmd)
|
||||
dr_adc_err_t err;
|
||||
(void)cmd;
|
||||
|
||||
if (maa_async_is_busy()) {
|
||||
if (maa_async_is_busy())
|
||||
{
|
||||
dr_ble_return_1("raa:", 0xFFFE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!dr_piezo_is_power_on()) {
|
||||
if (!dr_piezo_is_power_on())
|
||||
{
|
||||
dr_piezo_power_on();
|
||||
}
|
||||
|
||||
@@ -183,8 +210,12 @@ int Cmd_maa(const ParsedCmd *cmd)
|
||||
ble_bin_buffer
|
||||
);
|
||||
|
||||
if (err != DR_ADC_OK) {
|
||||
if (g_plat.log) g_plat.log("[Cmd_maa] start failed err=%d\r\n", err);
|
||||
if (err != DR_ADC_OK)
|
||||
{
|
||||
if (g_plat.log)
|
||||
{
|
||||
g_plat.log("[Cmd_maa] start failed err=%d\r\n", err);
|
||||
}
|
||||
single_format_data(ble_bin_buffer, "raa:", (uint16_t)(0xFF00 | err));
|
||||
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||
dr_piezo_power_off();
|
||||
@@ -214,7 +245,8 @@ int Cmd_mbb(const ParsedCmd *cmd)
|
||||
|
||||
all_sensors();
|
||||
|
||||
if (maa_async_is_busy()) {
|
||||
if (maa_async_is_busy())
|
||||
{
|
||||
dr_ble_return_1("raa:", 0xFFFE);
|
||||
return 1;
|
||||
}
|
||||
@@ -230,8 +262,12 @@ int Cmd_mbb(const ParsedCmd *cmd)
|
||||
ble_bin_buffer
|
||||
);
|
||||
|
||||
if (err != DR_ADC_OK) {
|
||||
if (g_plat.log) g_plat.log("[Cmd_mbb] start failed err=%d\r\n", err);
|
||||
if (err != DR_ADC_OK)
|
||||
{
|
||||
if (g_plat.log)
|
||||
{
|
||||
g_plat.log("[Cmd_mbb] start failed err=%d\r\n", err);
|
||||
}
|
||||
single_format_data(ble_bin_buffer, "raa:", (uint16_t)(0xFF00 | err));
|
||||
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||
dr_piezo_power_off();
|
||||
@@ -245,8 +281,7 @@ int Cmd_mbb(const ParsedCmd *cmd)
|
||||
* mcf? -> rcf: Read piezo parameters from FDS
|
||||
*
|
||||
* Request: [TAG 4B "mcf?"] [CRC 2B]
|
||||
* Response: [TAG 4B "rcf:"] [freq 2B] [cycles 2B] [avg 2B]
|
||||
* [delay_us 2B] [num_samples 2B] [CRC 2B]
|
||||
* Response: [TAG 4B "rcf:"] [freq 2B] [cycles 2B] [avg 2B] [delay_us 2B] [num_samples 2B] [CRC 2B]
|
||||
*============================================================================*/
|
||||
int Cmd_mcf(const ParsedCmd *cmd)
|
||||
{
|
||||
@@ -266,15 +301,18 @@ int Cmd_mcf(const ParsedCmd *cmd)
|
||||
/*==============================================================================
|
||||
* mcs? -> rcs: Write piezo parameters to FDS
|
||||
*
|
||||
* Request: [TAG 4B "mcs?"] [freq 2B] [cycles 2B] [avg 2B]
|
||||
* [delay_us 2B] [num_samples 2B] [CRC 2B]
|
||||
* Request: [TAG 4B "mcs?"] [freq 2B] [cycles 2B] [avg 2B] [delay_us 2B] [num_samples 2B] [CRC 2B]
|
||||
* Response: [TAG 4B "rcs:"] [stored 5 values] [CRC 2B]
|
||||
* Error: rcs: + 0xFFFF (insufficient data)
|
||||
*============================================================================*/
|
||||
int Cmd_mcs(const ParsedCmd *cmd)
|
||||
{
|
||||
if (cmd->data_len < 10) {
|
||||
if (g_plat.log) g_plat.log("[Cmd_mcs] missing params (data_len=%u)\r\n", cmd->data_len);
|
||||
if (cmd->data_len < 10)
|
||||
{
|
||||
if (g_plat.log)
|
||||
{
|
||||
g_plat.log("[Cmd_mcs] missing params (data_len=%u)\r\n", cmd->data_len);
|
||||
}
|
||||
dr_ble_return_1("rcs:", 0xFFFF);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -69,9 +69,12 @@ int Cmd_msi(const ParsedCmd *cmd)
|
||||
motion_raw_data_enabled = true;
|
||||
ble_got_new_data = false;
|
||||
|
||||
if (cmd->data_len > 0 && (char)cmd->data[0] == 'c') {
|
||||
if (cmd->data_len > 0 && (char)cmd->data[0] == 'c')
|
||||
{
|
||||
motion_data_once = false;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
motion_data_once = true;
|
||||
}
|
||||
|
||||
@@ -99,7 +102,8 @@ void all_sensors(void)
|
||||
/* 1. Battery voltage -> info_batt */
|
||||
battery_saadc_done = false;
|
||||
battery_level_meas();
|
||||
for (timeout_cnt = 0; !battery_saadc_done && timeout_cnt < 100; timeout_cnt++) {
|
||||
for (timeout_cnt = 0; !battery_saadc_done && timeout_cnt < 100; timeout_cnt++)
|
||||
{
|
||||
dr_sd_delay_ms(1);
|
||||
}
|
||||
|
||||
@@ -108,13 +112,15 @@ void all_sensors(void)
|
||||
imu_read_direct();
|
||||
|
||||
/* 3. Temperature -> info_temp (TMP235 needs Piezo TX/RX power) */
|
||||
if (!dr_piezo_is_power_on()) {
|
||||
if (!dr_piezo_is_power_on())
|
||||
{
|
||||
dr_piezo_power_on();
|
||||
}
|
||||
|
||||
tmp235_saadc_done = false;
|
||||
tmp235_voltage_level_meas();
|
||||
for (timeout_cnt = 0; !tmp235_saadc_done && timeout_cnt < 100; timeout_cnt++) {
|
||||
for (timeout_cnt = 0; !tmp235_saadc_done && timeout_cnt < 100; timeout_cnt++)
|
||||
{
|
||||
dr_sd_delay_ms(1);
|
||||
}
|
||||
|
||||
@@ -126,7 +132,8 @@ void all_sensors(void)
|
||||
buf[4] = (uint8_t)(info_batt >> 8);
|
||||
buf[5] = (uint8_t)(info_batt & 0xFF);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
buf[6 + i * 2] = (uint8_t)(info_imu[i] >> 8);
|
||||
buf[6 + i * 2 + 1] = (uint8_t)(info_imu[i] & 0xFF);
|
||||
}
|
||||
|
||||
@@ -11,9 +11,8 @@ int Cmd_mso(const ParsedCmd *cmd); /* mso? -> rso: TMP235 temperature reading
|
||||
int Cmd_msp(const ParsedCmd *cmd); /* msp? -> rsp: IMU 6-axis single read */
|
||||
int Cmd_msi(const ParsedCmd *cmd); /* msi? -> rsi: IMU streaming start */
|
||||
|
||||
/* Helper for the mbb? handler: sequentially measures battery / IMU /
|
||||
* temperature, then emits a single rbb: response. Called from
|
||||
* Cmd_mbb() in cmd_piezo.c. */
|
||||
/* Helper for the mbb? handler: sequentially measures battery / IMU / temperature, then emits a single rbb: response.
|
||||
* Called from Cmd_mbb() in cmd_piezo.c. */
|
||||
void all_sensors(void);
|
||||
|
||||
#endif /* CMD_SENSOR_H */
|
||||
|
||||
Reference in New Issue
Block a user