Hi Chris,

I think it needs to be a signed int right, as txpwer can be negative, does
that sound right?

Cheers
James


On Thu, May 19, 2016 at 11:10 AM, Christopher Collins <[email protected]>
wrote:

> On Thu, May 19, 2016 at 11:03:22AM -0700, Christopher Collins wrote:
> > > > On May 19, 2016, at 10:11 AM, James Howarth <
> [email protected]> wrote:
> > [...]
> > > > static int txpwer_to_set[1] ;
> > > > memcpy(txpwer_to_set, ctxt->chr_access.data,
> > > >         sizeof txpwer_to_set);
> > > >
> > > > ble_phy_txpwr_set(*txpwer_to_set);
>
> > ctxt->chr_access.data is a void*, so James has it right :).  If
> > txpwer_to_set is a single byte, then I don't see any issues.  If it is
> > larger than one byte, then you will need to worry about endianness.
>
> Oops, now I understand the cause of (my) confusion.  James, you probably
> don't want to declare txpwer_to_set as a single-element array of int.
> Instead, I would just make it a single byte:
>
>     static uint8_t txpwer_to_set;
>     memcpy(&txpwer_to_set, ctxt->chr_access.data, sizeof txpwer_to_set);
>
> Assuming the tx power is indeed a single byte.  If its size is larger
> than one, you will probably want to think about endianness issues, as I
> mentioned in the previous email (in practice it will work, since BLE and
> your host processor both use little-endian).
>
> One more thing: you should verify the length of the data being written
> to the characteristic.  Something like:
>
>     static uint8_t txpwer_to_set;
>     if (ctxt->chr_access.len != sizeof txpwer_to_set) {
>         return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
>     }
>     memcpy(&txpwer_to_set, ctxt->chr_access.data, sizeof txpwer_to_set);
>
> Without that check, the peripheral will accept a write that contains too
> much data.
>
> Chris
>

Reply via email to