From 607e873404d746c692c38482f03c54ed3edce26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=8F?= Date: Wed, 7 Jul 2021 00:23:59 +0300 Subject: [PATCH] BLE: fix incorrect RSSI calculation. Firmware: don't mark system as tainted on test releases. (#567) * BLE: correct RSSI calculation routine. * Firmware: only guard boot on production releases. * BLE: proper float formatting in cli * BLE: faster RSSI refresh --- applications/bt/bt_cli.c | 8 ++++---- firmware/targets/f5/api-hal/api-hal-boot.c | 2 ++ firmware/targets/f5/api-hal/api-hal-bt.c | 7 +++++-- firmware/targets/f6/api-hal/api-hal-boot.c | 2 ++ firmware/targets/f6/api-hal/api-hal-bt.c | 7 +++++-- 5 files changed, 18 insertions(+), 8 deletions(-) mode change 100755 => 100644 applications/bt/bt_cli.c diff --git a/applications/bt/bt_cli.c b/applications/bt/bt_cli.c old mode 100755 new mode 100644 index 815e48f6..29d8d6a6 --- a/applications/bt/bt_cli.c +++ b/applications/bt/bt_cli.c @@ -63,15 +63,15 @@ void bt_cli_command_carrier_rx(Cli* cli, string_t args, void* context) { } printf("Receiving carrier at %hu channel\r\n", channel); printf("Press CTRL+C to stop\r\n"); + api_hal_bt_start_packet_rx(channel, 1); - float rssi_raw = 0; while(!cli_cmd_interrupt_received(cli)) { - osDelay(250); - rssi_raw = api_hal_bt_get_rssi(); - printf("RSSI: %03.1f dB\r", rssi_raw); + osDelay(1024 / 4); + printf("RSSI: %6.1f dB\r", api_hal_bt_get_rssi()); fflush(stdout); } + api_hal_bt_stop_packet_test(); } diff --git a/firmware/targets/f5/api-hal/api-hal-boot.c b/firmware/targets/f5/api-hal/api-hal-boot.c index 16e92a93..320e2b6b 100644 --- a/firmware/targets/f5/api-hal/api-hal-boot.c +++ b/firmware/targets/f5/api-hal/api-hal-boot.c @@ -7,7 +7,9 @@ #define BOOT_REQUEST_DFU 0xDF00B000 void api_hal_boot_init() { +#ifndef DEBUG LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED); +#endif } void api_hal_boot_set_mode(ApiHalBootMode mode) { diff --git a/firmware/targets/f5/api-hal/api-hal-bt.c b/firmware/targets/f5/api-hal/api-hal-bt.c index 3fec19d0..bf432530 100644 --- a/firmware/targets/f5/api-hal/api-hal-bt.c +++ b/firmware/targets/f5/api-hal/api-hal-bt.c @@ -112,11 +112,14 @@ void api_hal_bt_start_rx(uint8_t channel) { float api_hal_bt_get_rssi() { float val; uint8_t rssi_raw[3]; - aci_hal_read_raw_rssi(rssi_raw); + + if (aci_hal_read_raw_rssi(rssi_raw) != BLE_STATUS_SUCCESS) { + return 0.0f; + } // Some ST magic with rssi uint8_t agc = rssi_raw[2] & 0xFF; - int rssi = (rssi_raw[1] << 8 & 0xFF00) + (rssi_raw[1] & 0xFF); + int rssi = (((int)rssi_raw[1] << 8) & 0xFF00) + (rssi_raw[0] & 0xFF); if(rssi == 0 || agc > 11) { val = -127.0; } else { diff --git a/firmware/targets/f6/api-hal/api-hal-boot.c b/firmware/targets/f6/api-hal/api-hal-boot.c index 16e92a93..320e2b6b 100644 --- a/firmware/targets/f6/api-hal/api-hal-boot.c +++ b/firmware/targets/f6/api-hal/api-hal-boot.c @@ -7,7 +7,9 @@ #define BOOT_REQUEST_DFU 0xDF00B000 void api_hal_boot_init() { +#ifndef DEBUG LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED); +#endif } void api_hal_boot_set_mode(ApiHalBootMode mode) { diff --git a/firmware/targets/f6/api-hal/api-hal-bt.c b/firmware/targets/f6/api-hal/api-hal-bt.c index 3fec19d0..bf432530 100644 --- a/firmware/targets/f6/api-hal/api-hal-bt.c +++ b/firmware/targets/f6/api-hal/api-hal-bt.c @@ -112,11 +112,14 @@ void api_hal_bt_start_rx(uint8_t channel) { float api_hal_bt_get_rssi() { float val; uint8_t rssi_raw[3]; - aci_hal_read_raw_rssi(rssi_raw); + + if (aci_hal_read_raw_rssi(rssi_raw) != BLE_STATUS_SUCCESS) { + return 0.0f; + } // Some ST magic with rssi uint8_t agc = rssi_raw[2] & 0xFF; - int rssi = (rssi_raw[1] << 8 & 0xFF00) + (rssi_raw[1] & 0xFF); + int rssi = (((int)rssi_raw[1] << 8) & 0xFF00) + (rssi_raw[0] & 0xFF); if(rssi == 0 || agc > 11) { val = -127.0; } else {