Re: Tx power is always advertised as 0dBm on nrf51

2016-06-10 Thread Christopher Collins
Hi Simon,

On Thu, Jun 09, 2016 at 02:53:14PM -0700, Simon Ratner wrote:
[...]
> The above doesn't seem to have an effect on the contents of the advertising
> packet; it still advertises 0dBm. The comment in
> https://github.com/apache/incubator-mynewt-core/blob/master/net/nimble/host/src/ble_hs_adv.c#L188
> implies that this should be handled automatically, and the provided value
> is ignored. Is this implemented as described, or am I doing something wrong?
> 
> The actual tx power does change, for what it's worth - I see the expected
> difference in received signal between +4, 0, -12, -20.

As currently implemented, the nimble controller always indicates an
advertising power of 0.  I don't want to speak for Will who is more
familiar with this part of the code, but I believe this is intentional,
as the nimble link layer does not expect the transmit power to be
changed "behind its back." Apps are not expected to make direct calls to
the BLE drivers.  Rather, the intended client is the BLE link layer.
Since an interface into the transmit power has not been added to the
Nimble API yet, I don't blame you for trying!  I imagine that when
a transmit power interface is added to nimble, the adverising power
setting will get reported as configured.

Chris


Tx power is always advertised as 0dBm on nrf51

2016-06-09 Thread Simon Ratner
Here's some code to get started:

  /* Set tx power level. */
  rc = ble_phy_txpwr_set(tx_pwr_lvl);  // tx_pwr_lvl == 4
  if (rc != 0) {
BLEPRPH_LOG(ERROR, "error setting tx power level; rc=%d\n", rc);
return;
  } else {
BLEPRPH_LOG(DEBUG, "tx_pwr_lvl=%d\n", ble_phy_txpwr_get());  // prints
'4' as expected
  }

  /* Set the data included in advertisement packet. */
  memset(, 0, sizeof(fields));
  fields.tx_pwr_lvl = (uint8_t) tx_pwr_lvl;
  fields.tx_pwr_lvl_is_present = 1;
  /* ... */
  rc = ble_gap_adv_set_fields();
  if (rc != 0) {
BLEPRPH_LOG(ERROR, "error setting advertisement data; rc=%d\n", rc);
return;
  }

The above doesn't seem to have an effect on the contents of the advertising
packet; it still advertises 0dBm. The comment in
https://github.com/apache/incubator-mynewt-core/blob/master/net/nimble/host/src/ble_hs_adv.c#L188
implies that this should be handled automatically, and the provided value
is ignored. Is this implemented as described, or am I doing something wrong?

The actual tx power does change, for what it's worth - I see the expected
difference in received signal between +4, 0, -12, -20.

Cheers,
simon.