This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

bugfix request: implement "set tx power" according note in eddystone configuration spec

There is a note in the eddystone configuration service specs (https://github.com/google/eddystone/tree/master/configuration-service) in characteristic 4:

Note: if a power is selected that is not supported by the radio, the beacon should select the next highest power supported, or else the maximum power.

this was partly done with "Ranging Data" (= calibrated tx power at 0m) but not for the tx power itself. They are related but not the same. I propose the following changes in components/ble/ble_services/eddystone/es_slot.c:

 static void set_ranging_data_for_slot(uint8_t slot_no, nrf_ble_escs_radio_tx_pwr_t tx_power)
 {
     int8_t ranging_data_array[ESCS_NUM_OF_SUPPORTED_TX_POWER] = APP_CONFIG_CALIBRATED_RANGING_DATA;
     nrf_ble_escs_radio_tx_pwr_t supported_tx[ESCS_NUM_OF_SUPPORTED_TX_POWER] =
         ESCS_SUPPORTED_TX_POWER;

     int8_t ranging_data = 0;

     if (m_reg.slots[slot_no].adv_custom_tx_power)
     {
         ranging_data = m_reg.slots[slot_no].custom_tx_power;
     }
-
     else
     {
-        for (uint32_t i = 0; i < ESCS_NUM_OF_SUPPORTED_TX_POWER; ++i)
+        if (tx_power >= supported_tx[ESCS_NUM_OF_SUPPORTED_TX_POWER-1])
+        {
+            ranging_data = ranging_data_array[ESCS_NUM_OF_SUPPORTED_TX_POWER-1];
+        }
+        else
         {
-            if (supported_tx[i] >= tx_power)
+            for (uint32_t i = 0; i < ESCS_NUM_OF_SUPPORTED_TX_POWER; ++i)
             {
-                ranging_data = ranging_data_array[i];
-                break;
+                if (supported_tx[i] >= tx_power)
+                {
+                    ranging_data = ranging_data_array[i];
+                    break;
+                }
             }
         }
     }
 void es_slot_radio_tx_pwr_set(uint8_t slot_no, nrf_ble_escs_radio_tx_pwr_t radio_tx_pwr)
 {
     slot_boundary_check(&slot_no);
 
+    nrf_ble_escs_radio_tx_pwr_t supported_tx_power[ESCS_NUM_OF_SUPPORTED_TX_POWER] = ESCS_SUPPORTED_TX_POWER;
+    if (radio_tx_pwr > supported_tx_power[ESCS_NUM_OF_SUPPORTED_TX_POWER-1])
+    {
+        radio_tx_pwr = supported_tx_power[ESCS_NUM_OF_SUPPORTED_TX_POWER-1];
+    }
+    else
+    {
+        for (int i = 0; i < ESCS_NUM_OF_SUPPORTED_TX_POWER; i++)
+        {
+            if (supported_tx_power[i] >= radio_tx_pwr)
+            {
+                radio_tx_pwr = supported_tx_power[i];
+                break;
+            }
+        }
+    }

    m_reg.slots[slot_no].radio_tx_pwr = radio_tx_pwr;
Related