This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

missing header in peripheral.h



Hello,

for BLE Stack 2.1 in peripheral.h there seems to be a missing header. If you include peripheral.h in a C file with just an include statement to include the "peripheral.h" header, you get errors, complaining about undefined types unit16_t.

I would recommend to include the header that contains the prototypes for a C file as first include statement. This is an easy check to see if the header compiles on its own.

Kind regards,

Torsten

  • In addition, I wonder why peripheral.h is using two approaches to provide callbacks:
    - The first is GAPRole_StartDevice() where a pointer to a structure with exactly one function pointer is given. Which structure is used can not be changed, but the callback used can be changed changing the passed structure later.
    - The second callback can be given with GAPRole_RegisterAppCBs(), which takes a pointer to a function pointer and stores the pointer to the function pointer. So, to call the function, the user first, have to allocate a function pointer, have to initialize it with function to be call and than pass a pointer to that function pointer.

    Both approaches seem a little bit complicated to me. Passing just a function pointer should be sufficient.
  • Hi Torsten,

    Thanks for your suggestions and link to your GATT server lib. As you can see from peripheral.c, other #include files are required using peripheral.h.

    Best wishes
  • Hi,

    yes, I know how to find the missing headers, but don't you agree that a header should contain all necessary declarations and includes to compiler on its own?

    What if you are using a compiler that ships with a string.h header and when you include that header the compiler would complain about missing declarations and the compiler vendor would say: "off cause you have to include <stdlib.h> too" ;-)

    Regarding the GAPRole_RegisterAppCBs()-API: Can you spot the bug in the following lines of code? :

    static void callback(
            uint16_t interval,
            uint16_t slave_latency,
            uint16_t timeout )
    {
    }
    
    static void init()
    {
        gapRolesParamUpdateCB_t cb = &callback;
        GAPRole_RegisterAppCBs( &cb );
    }

    cheers,

    Torsten

  • Hi Torsten,

    Using addresses of auto variables as a pointer argument is in general a very bad idea :/ Do we have this in the GapRole API?

    Header files should ideally be self-contained though they in many cases are not (since they were only included in one file together with other files while development were done)

    Regarding the two other points you have:

    GAPRole_StartDevice():

    After storing the pointer it is of course possible to change it, but I would be careful with that :/

    The current implementation makes it easy to extend the callback structure with future callbacks. The alternative sol  ution would also cost more flash space. (De-reference the pointer and store same struct locally peripheral.c

    GAPRole_RegisterAppCBs:

    I agree it looks strange providing a pointer to a function pointer, my best guess is that it is to be able to update it dynamically without going through the API again.

    Regards,

    Svend