Scan BLE devices with C / C ++

from the Guide to Accessing Bluetooth Devices , I read that the Bluetooth API must be accessible from C or C ++. I found some C-headers (IOBluetoothUserLib.h, Bluetooth.h) in the IOBluetooth structure that are Bluetooth related and contain listings and data structured to define search creteria, but I can not find any function that accepts such Numbering or data structure as a parameter. According to the documentation, I would have to create a CBCentralManager, but I could not find a way to do this with C or C ++.

Reference Information. We use OS / X as a development platform to develop microcontrollers with BLE support. To update the firmware on these microcontrollers, I want to write a BLE bootloader, and I want the command line client to update the firmware. All code is written in C ++, and I would not want to learn objectiv-C for this small task.

Any pointers, documentation, examples?

Thank you

Thorsten

+5
source share
2 answers

According to the documentation, I will need to create a CBCentralManager, but I cannot find a way to do this with C or C ++.

The documentation you refer to refers to classic Bluetooth, for which the IOBluetooth interface has some features. CBCentralManager is a CoreBluetooth manager that is designed for Bluetooth LE only.

For the classic Bluetooth manager you want is the HID manager from the IOKit framework, the documentation for which you can find here . If you search, you will find many examples of using C ++ IOKit and IOHIDManager ( 1 , 2 ).

IOKit can actually provide you with all the functionality you need, but IOBluetooth provides some specific Bluetooth features. From Bluetooth Application Development :

Although you do not need to use the Bluetooth API to access the HID class device, you can use the functions or methods from the Bluetooth structure to enhance the user experience. For example, your application may provide Bluetooth-specific information that allows the user to find out if the device supports a particular service.

+3
source

I agreed with Henrik , you will need glue. Look The RedBearLab guys work and are accurate for the class.

ofxBLE. h/mm // C++ interface // // (Obj-C may be a superset of C, but this just makes interopability // easier with oF) class ofxBLE { protected: ofxBLEDelegate *btDelegate; public: ofxBLE(); ~ofxBLE(); void scanPeripherals(); void sendPosition(uint8_t x, uint8_t y); bool isConnected(); }; ... - (void)bleDidDisconnect { NSLog(@"->Disconnected"); } - (void)bleDidReceiveData:(unsigned char *)data length:(int)length { } @end // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = //= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = // C++ class implementation ofxBLE::ofxBLE() { btDelegate = [[ofxBLEDelegate alloc] init]; } ofxBLE::~ofxBLE() { } void ofxBLE::scanPeripherals(){ [btDelegate scanForPeripherals]; } void ofxBLE::sendPosition(uint8_t x, uint8_t y) { // position should be NORMALIZED to between 0 and 255 BEFORE // passing into this method! [btDelegate sendPositionX:x withY:y]; } 
+2
source

Source: https://habr.com/ru/post/1211491/


All Articles