andrzej-kaczmarek closed pull request #202: Beacon's Measured Power as an 
argument
URL: https://github.com/apache/mynewt-nimble/pull/202
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/apps/btshell/src/cmd.c b/apps/btshell/src/cmd.c
index 9ca66713..91cf83d9 100644
--- a/apps/btshell/src/cmd.c
+++ b/apps/btshell/src/cmd.c
@@ -1511,6 +1511,7 @@ cmd_set_adv_data_or_scan_rsp(int argc, char **argv, bool 
scan_rsp)
     uint8_t eddystone_url_body_len;
     uint8_t eddystone_url_suffix;
     uint8_t eddystone_url_scheme;
+    int8_t eddystone_measured_power = 0;
     char eddystone_url_body[BLE_EDDYSTONE_URL_MAX_LEN];
     char *eddystone_url_full;
     int svc_data_uuid16_len;
@@ -1752,6 +1753,14 @@ cmd_set_adv_data_or_scan_rsp(int argc, char **argv, bool 
scan_rsp)
         return rc;
     }
 
+    tmp = parse_arg_long_bounds("eddystone_measured_power", -100, 20, &rc);
+    if (rc == 0) {
+        eddystone_measured_power = tmp;
+    } else if (rc != ENOENT) {
+        console_printf("invalid 'eddystone_measured_power' parameter\n");
+        return rc;
+    }
+
     eddystone_url_full = parse_arg_extract("eddystone_url");
     if (eddystone_url_full != NULL) {
         rc = parse_eddystone_url(eddystone_url_full, &eddystone_url_scheme,
@@ -1765,7 +1774,8 @@ cmd_set_adv_data_or_scan_rsp(int argc, char **argv, bool 
scan_rsp)
         rc = ble_eddystone_set_adv_data_url(&adv_fields, eddystone_url_scheme,
                                             eddystone_url_body,
                                             eddystone_url_body_len,
-                                            eddystone_url_suffix);
+                                            eddystone_url_suffix,
+                                            eddystone_measured_power);
     } else {
 #if MYNEWT_VAL(BLE_EXT_ADV)
         /* Default to legacy PDUs size, mbuf chain will be increased if needed
@@ -1851,6 +1861,7 @@ static const struct shell_param set_adv_data_params[] = {
     {"service_data_uuid128", "usage: =[XX:XX...]"},
     {"uri", "usage: =[XX:XX...]"},
     {"mfg_data", "usage: =[XX:XX...]"},
+    {"measured_power", "usage: =[-100-20]"},
     {"eddystone_url", "usage: =[string]"},
 #if MYNEWT_VAL(BLE_EXT_ADV)
     {"extra_data_len", "usage: =[UINT16]"},
diff --git a/nimble/host/include/host/ble_eddystone.h 
b/nimble/host/include/host/ble_eddystone.h
index b028a4aa..76b7e2b0 100644
--- a/nimble/host/include/host/ble_eddystone.h
+++ b/nimble/host/include/host/ble_eddystone.h
@@ -66,6 +66,7 @@ struct ble_hs_adv_fields;
  *                                  are preserved; you probably want to clear
  *                                  this struct before calling this function.
  * @param uid                   The 16-byte UID to advertise.
+ * @param measured_power        The Measured Power (RSSI value at 0 Meter).
  *
  * @return                      0 on success;
  *                              BLE_HS_EBUSY if advertising is in progress;
@@ -74,7 +75,7 @@ struct ble_hs_adv_fields;
  *                              Other nonzero on failure.
  */
 int ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields *adv_fields,
-                                   void *uid);
+                                   void *uid, int8_t measured_power);
 
 /**
  * Configures the device to advertise Eddystone URL beacons.
@@ -92,6 +93,7 @@ int ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields 
*adv_fields,
  *                                  BLE_EDDYSTONE_URL_SUFFIX values; use
  *                                  BLE_EDDYSTONE_URL_SUFFIX_NONE if the suffix
  *                                  is embedded in the body argument.
+ * @param measured_power        The Measured Power (RSSI value at 0 Meter).
  *
  * @return                      0 on success;
  *                              BLE_HS_EBUSY if advertising is in progress;
@@ -101,7 +103,8 @@ int ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields 
*adv_fields,
  */
 int ble_eddystone_set_adv_data_url(struct ble_hs_adv_fields *adv_fields,
                                    uint8_t url_scheme, char *url_body,
-                                   uint8_t url_body_len, uint8_t suffix);
+                                   uint8_t url_body_len, uint8_t suffix,
+                                   int8_t measured_power);
 
 #ifdef __cplusplus
 }
diff --git a/nimble/host/include/host/ble_ibeacon.h 
b/nimble/host/include/host/ble_ibeacon.h
index d1207835..fff7c57a 100644
--- a/nimble/host/include/host/ble_ibeacon.h
+++ b/nimble/host/include/host/ble_ibeacon.h
@@ -24,7 +24,8 @@
 extern "C" {
 #endif
 
-int ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, uint16_t minor);
+int ble_ibeacon_set_adv_data(void *uuid128, uint16_t major,
+                             uint16_t minor, int8_t measured_power);
 
 #ifdef __cplusplus
 }
diff --git a/nimble/host/src/ble_eddystone.c b/nimble/host/src/ble_eddystone.c
index 9f90ed4e..ec54d133 100644
--- a/nimble/host/src/ble_eddystone.c
+++ b/nimble/host/src/ble_eddystone.c
@@ -106,21 +106,20 @@ ble_eddystone_set_adv_data_gen(struct ble_hs_adv_fields 
*adv_fields,
 }
 
 int
-ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields *adv_fields, void *uid)
+ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields *adv_fields,
+                               void *uid, int8_t measured_power)
 {
     uint8_t *svc_data;
-    int8_t tx_pwr;
     int rc;
 
     /* Eddystone UUID and frame type (0). */
     svc_data = ble_eddystone_set_svc_data_base(BLE_EDDYSTONE_FRAME_TYPE_UID);
 
-    /* Ranging data (Calibrated tx power at 0 meters). */
-    rc = ble_hs_hci_util_read_adv_tx_pwr(&tx_pwr);
-    if (rc != 0) {
-        return rc;
+    /* Measured Power ranging data (Calibrated tx power at 0 meters). */
+    if (measured_power < -100 || measured_power > 20) {
+        return BLE_HS_EINVAL;
     }
-    svc_data[0] = tx_pwr;
+    svc_data[0] = measured_power;
 
     /* UID. */
     memcpy(svc_data + 1, uid, 16);
@@ -140,10 +139,10 @@ ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields 
*adv_fields, void *uid)
 int
 ble_eddystone_set_adv_data_url(struct ble_hs_adv_fields *adv_fields,
                                uint8_t url_scheme, char *url_body,
-                               uint8_t url_body_len, uint8_t url_suffix)
+                               uint8_t url_body_len, uint8_t url_suffix,
+                               int8_t measured_power)
 {
     uint8_t *svc_data;
-    int8_t tx_pwr;
     int url_len;
     int rc;
 
@@ -157,11 +156,12 @@ ble_eddystone_set_adv_data_url(struct ble_hs_adv_fields 
*adv_fields,
 
     svc_data = ble_eddystone_set_svc_data_base(BLE_EDDYSTONE_FRAME_TYPE_URL);
 
-    rc = ble_hs_hci_util_read_adv_tx_pwr(&tx_pwr);
-    if (rc != 0) {
-        return rc;
+    /* Measured Power ranging data (Calibrated tx power at 0 meters). */
+    if (measured_power < -100 || measured_power > 20) {
+        return BLE_HS_EINVAL;
     }
-    svc_data[0] = tx_pwr;
+    svc_data[0] = measured_power;
+
     svc_data[1] = url_scheme;
     memcpy(svc_data + 2, url_body, url_body_len);
     if (url_suffix != BLE_EDDYSTONE_URL_SUFFIX_NONE) {
diff --git a/nimble/host/src/ble_ibeacon.c b/nimble/host/src/ble_ibeacon.c
index 62060c78..0c6ef99d 100644
--- a/nimble/host/src/ble_ibeacon.c
+++ b/nimble/host/src/ble_ibeacon.c
@@ -31,17 +31,18 @@
  *                                  iBeacons.
  * @param minor                 The minor version number to include in
  *                                  iBeacons.
+ * @param measured_power        The Measured Power (RSSI value at 1 Meter).
  *
  * @return                      0 on success;
  *                              BLE_HS_EBUSY if advertising is in progress;
  *                              Other nonzero on failure.
  */
 int
-ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, uint16_t minor)
+ble_ibeacon_set_adv_data(void *uuid128, uint16_t major,
+                         uint16_t minor, int8_t measured_power)
 {
     struct ble_hs_adv_fields fields;
     uint8_t buf[BLE_IBEACON_MFG_DATA_SIZE];
-    int8_t tx_pwr;
     int rc;
 
     /** Company identifier (Apple). */
@@ -59,13 +60,11 @@ ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, 
uint16_t minor)
     put_be16(buf + 20, major);
     put_be16(buf + 22, minor);
 
-    /** Last byte (tx power level) filled in after HCI exchange. */
-
-    rc = ble_hs_hci_util_read_adv_tx_pwr(&tx_pwr);
-    if (rc != 0) {
-        return rc;
+    /* Measured Power ranging data (Calibrated tx power at 1 meters). */
+    if (measured_power < -126 || measured_power > 20) {
+        return BLE_HS_EINVAL;
     }
-    buf[24] = tx_pwr;
+    buf[24] = measured_power;
 
     memset(&fields, 0, sizeof fields);
     fields.mfg_data = buf;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to