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

Adapter passed to ble_evt_dispatch does not match adapter passed to sd_rpc_open

I'm using pc-ble-driver to talk to the nRF52840 dev-dongle from a Windows PC.
I started with examples\heart_rate_collector\main.c
I receive events in a function 'ble_evt_dispatch' (that function is the third argument to 'sd_rpc_open').
I expect the first argument to 'ble_evt_dispatch', which has type 'adapter_t*' to be equal to the 'adapter_t*' argument that I pass in to 'sd_rpc_open' but it is not. Why is this?

I'm trying to match up events received in'ble_evt_dispatch with the adapter I previously created.

  • Hi,

    adapter_t is a struct with a void pointer to an internal data structure, and so if the internal data structure gets reallocated in memory you can no longer compare it like that. I have not found any API for comparing adapter values, and the engineers who knows more about this are currently out-of-office. I can come back to you with a better answer when they are back.

    Are you using several adapters from the same pc-ble-driver application?

    A workaround for now may be to register a different function for each adapter used, and that way keep track of the adapter (since the adapter will always be the same in that specific callback function.)

    Regards,
    Terje

  • I wanted to avoid implementing my code as a singleton that could only support one pc-ble-driver adapter at a time.

    I looked at the adapter_t and saw that its implementation was a void pointer to an internal data structure. But that doesn't explain why the 'adapter_t*' that is passed to me should ever change - the internal 'void*' should change if needed.

    For now I'll make my code a singleton, but I'd prefer not to, if you can suggest any workaround.

Related