Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 2 months ago.
HIDS HOGP BLE_API Service
I'm implementing the ble_hids nrf example in mbed. I'm using the ble_hids source from the nrf sdk examples untouched for the moment. I Have a working version merging the ble_api instead of direct nrf soft device access. Note, I could rearchitect the ble_hids include (and presumably well need to due to licensing) but for now its working and I want it to stay that way. Im now trying to make an mbed 'service' but I could use some help from maintainers.
First, the onDataSent callback needs more data for the ble_hids example, presumably a GattCharacteristicWriteCBParams *params object with len, data, and ble_gatts_evt_write_t.handle. Im currently using something like this and its working.. any objections?
in nrf51gattserver.cpp void nRF51GattServer::hwCallback(ble_evt_t *p_ble_evt)
case BLE_EVT_TX_COMPLETE: { GattCharacteristicWriteCBParams cbParams = { .charHandle = gattsEventP->params.write.handle, .op = static_cast<GattCharacteristicWriteCBParams::Type>(gattsEventP->params.write.op), .offset = gattsEventP->params.write.offset, .len = gattsEventP->params.write.len, .data = gattsEventP->params.write.data }; handleDataSentEvent(&cbParams, p_ble_evt->evt.common_evt.params.tx_complete.count); return; }
Next, I need an onConnection and onDisconnection event but I've noticed that these dont have callback chains so I can't safely put these in my 'service' and know that anyone could use them in main.cpp or in another service.. I think we need chains on all four 'on' callbacks. Any objections? Here I could definitely use some help.
Question relating to:
1 Answer
10 years, 2 months ago.
I got this back from Nordic:
Quote:
BLE_EVT_TX_COMPLETE won’t give you any more data than the number of packets transmitted. If the user needs to know what operations and characteristics this corresponded to, they need to queue them up themselves in user space. One option would be to do it inside the mbed BLE API. What the user did in this case to interpret the internals of the ble_evt_t as a ble_gatts_evt_t is not legal; the user is simply getting back cached results from the last valid gatts event, and it's not going to be useful or stable. The soft-device gives handle, op, offset and len for GATTS *incoming* ops (write request, write command) whereas a TX_COMPLETE is the acknowledgment that an *outgoing* op (in this case notification) has been completed.
here are the key things to take away:
- TX_COMPLETE is generated only for Notifications.
- TX_COMPLETE event will only contain the connection handle and the repeat-count.
- The order of TX_COMPLETEs is guaranteed to be the same as the order in which notification-enabled characteristics are changed. So you could maintain a small queue of requested updates to notification-enabled characteristics and co-relate these updates to the TX_COMPLETE events.
Please let me know if you still need help with setting up callback-chains for other callbacks.
Ah yes. It looks like while porting I crossed ondatasent and ondatawritten callbacks.
I definitely do still need to be able to chain especially ondisconnection and onconnection, though I dont see why ondatasent shouldnt get the treatment too. Ill take another look now that I know arguments wont be changing.
My current problem on chaining onconnect and onDisconnect is they have 2 arguments
I've managed to fork and push here http://developer.mbed.org/users/jjrosent/code/BLE_API/
Im trying: CallChainOfFunctionPointersWithContext<Handle_t, const ConnectionParams_t *> onConnection; CallChainOfFunctionPointersWithContext<Handle_t, DisconnectionReason_t> onDisconnection;
but getting:
In file included from ./BLE_API/public/BLEDevice.h:22:0, from main.cpp:24: ./BLE_API/public/Gap.h:150:80: error: wrong number of template arguments (2, should be 1) In file included from ./BLE_API/public/Gap.h:25:0, from ./BLE_API/public/BLEDevice.h:22, from main.cpp:24: ./BLE_API/public/CallChainOfFunctionPointersWithContext.h:61:7: error: provided for 'template<class ContextType> class mbed::CallChainOfFunctionPointersWithContext' In file included from ./BLE_API/public/BLEDevice.h:22:0, from main.cpp:24: ./BLE_API/public/Gap.h:151:75: error: wrong number of template arguments (2, should be 1) In file included from ./BLE_API/public/Gap.h:25:0, from ./BLE_API/public/BLEDevice.h:22, from main.cpp:24: ./BLE_API/public/CallChainOfFunctionPointersWithContext.h:61:7: error: provided for 'template<class ContextType> class mbed::CallChainOfFunctionPointersWithContext' In file included from ./BLE_API/public/BLEDevice.h:22:0, from main.cpp:24: ./BLE_API/public/Gap.h: In member function 'void Gap::setOnConnection(void (*)(Gap::Handle_t, const Gap::ConnectionParams_t*))': ./BLE_API/public/Gap.h:96:22: error: request for member 'add' in '((Gap*)this)->Gap::onConnection', which is of non-class type 'int' ./BLE_API/public/Gap.h: In member function 'void Gap::setOnConnection(T*, void (T::*)(Gap::Handle_t, const Gap::ConnectionParams_t*))': ./BLE_API/public/Gap.h:100:22: error: request for member 'add' in '((Gap*)this)->Gap::onConnection', which is of non-class type 'int' ./BLE_API/public/Gap.h: In member function 'void Gap::setOnDisconnection(void (*)(Gap::Handle_t, Gap::DisconnectionReason_t))': ./BLE_API/public/Gap.h:104:25: error: request for member 'add' in '((Gap*)this)->Gap::onDisconnection', which is of non-class type 'int' ./BLE_API/public/Gap.h: In member function 'void Gap::setOnDisconnection(T*, void (T::*)(Gap::Handle_t, Gap::DisconnectionReason_t))': ./BLE_API/public/Gap.h:108:25: error: request for member 'add' in '((Gap*)this)->Gap::onDisconnection', which is of non-class type 'int' ./BLE_API/public/Gap.h: In member function 'void Gap::processConnectionEvent(Gap::Handle_t, const Gap::ConnectionParams_t*)': ./BLE_API/public/Gap.h:113:26: error: request for member 'hasCallbacksAttached' in '((Gap*)this)->Gap::onConnection', which is of non-class type 'int' ./BLE_API/public/Gap.h:114:26: error: request for member 'call' in '((Gap*)this)->Gap::onConnection', which is of non-class type 'int' ./BLE_API/public/Gap.h: In member function 'void Gap::processDisconnectionEvent(Gap::Handle_t, Gap::DisconnectionReason_t)': ./BLE_API/public/Gap.h:120:29: error: request for member 'hasCallbacksAttached' in '((Gap*)this)->Gap::onDisconnection', which is of non-class type 'int' ./BLE_API/public/Gap.h:121:29: error: request for member 'call' in '((Gap*)this)->Gap::onDisconnection', which is of non-class type 'int' ./BLE_API/public/Gap.h: In member function 'void Gap::processEvent(GapEvents::gapEvent_e)': ./BLE_API/public/Gap.h:126:16: warning: enumeration value 'GAP_EVENT_CONNECTED' not handled in switch [-Wswitch] ./BLE_API/public/Gap.h:126:16: warning: enumeration value 'GAP_EVENT_DISCONNECTED' not handled in switch [-Wswitch] In file included from ./BLE_API/public/BLEDevice.h:23:0, from main.cpp:24: ./BLE_API/public/GattServer.h: In member function 'void GattServer::handleEvent(GattServerEvents::gattEvent_e, uint16_t)': ./BLE_API/public/GattServer.h:78:16: warning: enumeration value 'GATT_EVENT_DATA_SENT' not handled in switch [-Wswitch] ./BLE_API/public/GattServer.h:78:16: warning: enumeration value 'GATT_EVENT_DATA_WRITTEN' not handled in switch [-Wswitch] In file included from ./nRF51822/nordic/nrf-sdk/s110/ble.h:23:0, from ./nRF51822/nordic/nrf-sdk/ble/ble_services/ble_hids.h:44, from ./BLE_API/services/HIDService.h:21, from main.cpp:26: ./nRF51822/nordic/nrf-sdk/s110/ble_gap.h: In function 'uint32_t sd_ble_gap_address_set(uint8_t, const ble_gap_addr_t*)': ./nRF51822/nordic/nrf-sdk/s110/ble_gap.h:720:1: warning: no return statement in function returning non-void [-Wreturn-type] make: * [main.o] Error 1 jacob:BLE_Hids jacobrosenthal$
posted by 08 Oct 2014BTW Rohit, could you ask your contacts in Nordic whether they'd consider contributing ble_hids.c to the BLE_API repository? It would be great to use HID services in mbed (I have a neat key fob remote project that I'd open source in mbed if possible, current code here: https://github.com/janekm/keyfob-firmware ) but to my mind too much hassle to re-implement.
posted by 09 Oct 2014
Hi, thanks for taking up this exercise. I'd like to see it come through. I'm not yet sure if we can interpret the internals of the ble_evt_t as a ble_gatts_evt_t for the case of BLE_EVT_TX_COMPLETE. I've posed this question to an expert from Nordic; and hope to hear back soon. I'll update shortly.
posted by Rohit Grover 08 Oct 2014Ping Rohit. Its been a few weeks. I assure you Im still interested in this :) Can you comment on Nordics stance on the license of dev kit examples? What about my alterations in my branch below? Thanks, Jacob
posted by Jacob Rosenthal 23 Oct 2014Is BLE_API being worked on github somewhere like mbed and nrf? I really dislike this system.
posted by Jacob Rosenthal 23 Oct 2014