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

Where can I find a list of BLE event codes?

For example, I get logs like this, and I want to know what these events are:

ble_cts_c: BLE event handler called with event 0x57

I also see 0x36, 0x12, etc. when the CTS is operating.

This post did not point to a list of numbers & corresponding event types. 

I know that Bluetooth status codes are here and error codes in general are here, from this post.

This post pointed to a list of EVT enums and bases, which is the closest to answering this Q I have seen, but I am not clear how you can take say, 0x57 and know which enums / base codes are added together to get this 0x57. And maybe adding isn't even the right operation here. 

In short -- if I know the event code the BLE event handler is called with, how can I translate that number into the actual event that occurred, so I know what events are happening?

Parents
  • Hello,

    There isn't a single list containing all of these, but if you open the file ble_ranges.h (search for BLE_SVC_BASE in one of the ble_app_... projects), you will see a list of the bases for the events. Let us say you want to find out what event the 0x12 event is. In that case, look in the ble_ranges.h file, and you will see that there are these defines:

    #define BLE_<something>_BASE
    #define BLE_<something>_LAST

    Check which one of them that wraps around the value you are looking for. In this case, that would be:

    #define BLE_GAP_EVT_BASE 0x10
    #define BLE_GAP_EVT_LAST 0x2F

    Then search for BLE_GAP_EVT_BASE in your project, and you will see a lot of occurrences in the file ble_gap.h.

    The enum BLE_GAP_EVTS contains all the events between BLE_GAP_EVT_BASE and BLE_GAP_EVT_LAST. In this case:

    BLE_GAP_EVT_CONN_PARAM_UPDATE           = BLE_GAP_EVT_BASE + 2 = 0x10 + 2 = 0x12.

    Likewise, 0x36 refers to BLE_GATTC_EVT_READ_RSP and 0x57 refers to BLE_GATTS_EVT_HVN_TX_COMPLETE.

    This method is not 100% perfect, because in ble_ranges, you have e.g.

    #define BLE_GATT_OPT_BASE      0x40       /**< GATT BLE Option base. */
    #define BLE_GATT_OPT_LAST      0x5F       /**< GATT BLE Option last. */

    and 

    #define BLE_GATTS_EVT_BASE     0x50       /**< GATTS BLE Event base. */
    #define BLE_GATTS_EVT_LAST     0x6F       /**< GATTS BLE Event last. */

    so 0x57 could be in both of them. However, BLE_GATT_OPT_BASE is not used in this project (and I am not sure it is used anywhere). But you should be able to find the events you are looking for.

    Best regards,

    Edvin

  • Thank you Edvin! This was quite helpful.

    I notice that for the above codes you helped me translate, the enums listing the specific evt offset from the base live in files corresponding to the event base name. E.g., from highlighted section below, BLE_GAP_EVT_BASE --> ble_gap.h --> BLE_GAP_EVTS

    However, the enum corresponding to some of these other bases are not as findable. For example, BLE_EVT_BASE --> searching for BLE_EVT in "Entire Solution" does not seem to yield any equivalent results.
    Q: how to find the corresponding enum for BLE_EVT?

    Searching for BLE_L2CAP_SVC doesn't yield any results, on the other hand (aside from this file) -- safe to say if there are no results, this means it is not being used? 

  • Not all of these are used. As I mentioned in the previous reply, I don't think BLE_GATT_OPT_BASE is used either. I guess some of them are only for peripherals, and some are only for centrals. And some may only be there because they were used in earlier versions of the SDK/Softdevice.  I wouldn't worry about the ones that aren't used in your project. 

     

    nordev said:
    For example, BLE_EVT_BASE --> searching for BLE_EVT in "Entire Solution" does not seem to yield any equivalent results.

     Do you not get any results when you search for BLE_EVT, or none other than the ones in ble_ranges.h?

    The reason I ask is that it looks like you are using Segger Embedded Studio, and sometimes I see some issues when searching in certain projects. 

     

    nordev said:
    safe to say if there are no results, this means it is not being used? 

     Yes. I would say that is safe to assume. But let me know if you find any event IDs that you can't find in the SDK, and I can see if I can help you. But I think all the ones that are used should be present in the SDK. 

    Best regards,

    Edvin

  • Thanks again Edvin. 

    I get these results for BLE_EVT, but none of them seem quite right (no enum in results):
    and yes, I am using Segger. Let me know if I should be searching in a different way, I use the "ctl + shift + f" method.

    If I make a new service with new events that I would like to be recognized / handled by my custom service's event handler, should I add a new range to ble_ranges.h? I have an enum with a list of events for my service, but...

    A) I am not sure if it is ok to leave them as an enum indexed from zero (probably not because 0x00 overlaps with BLE_EVT_INVALID?? and my events would overlap with the regular BLE_EVT range -- is that a problem?), or

    B) if I make a new range and use an offset, how do I generate the events with the right code? (Perhaps more fundamentally... how do I generate the events, period?)

    Thank you!

Reply
  • Thanks again Edvin. 

    I get these results for BLE_EVT, but none of them seem quite right (no enum in results):
    and yes, I am using Segger. Let me know if I should be searching in a different way, I use the "ctl + shift + f" method.

    If I make a new service with new events that I would like to be recognized / handled by my custom service's event handler, should I add a new range to ble_ranges.h? I have an enum with a list of events for my service, but...

    A) I am not sure if it is ok to leave them as an enum indexed from zero (probably not because 0x00 overlaps with BLE_EVT_INVALID?? and my events would overlap with the regular BLE_EVT range -- is that a problem?), or

    B) if I make a new range and use an offset, how do I generate the events with the right code? (Perhaps more fundamentally... how do I generate the events, period?)

    Thank you!

Children
  • Make sure that you have ticked of the correct boxes in the ctrl + shift + f window:

    If you create your own service, it will use the already existing events. Look at how this is done in e.g. the ble_app_uart example. This uses a custom service, and has it's own events in the nus_data_handler() in main.c, such as the BLE_NUS_EVT_RX_DATA event. This is an enum (0 indexed), but you can see how the BLE_NUS_EVT_RX_DATA event is generated in ble_nus.c's on_write() function, which is called in the ble_nus_on_ble_evt() callback whenever the BLE_GATTS_EVT_WRITE event occurs. The BLE_GATTS_EVT_WRITE event is a softdevice event (=BLE_GATTS_EVT_BASE = 0x50). 

    Best regards,

    Edvin

Related