Я хочу создать приложение терминала, которое подключается к устройству Bluetooth и выводит любые команды, отправляемые устройством Bluetooth. Пока я могу сканировать и выводить список доступных устройств.
Любое направление будет высоко оценено - возможно ли это? На что мне сейчас смотреть? Я пытался использовать BluetoothDeviceAddress и IOBluetoothL2CAPChannelGetDevice, но пока безуспешно.
Вот мой код:
#include <Foundation/Foundation.h>
#include <Cocoa/Cocoa.h>
#include <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
#include <IOBluetoothUI/IOBluetoothUI.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"start bluetooth search");
IOBluetoothDeviceInquiry *d = [[IOBluetoothDeviceInquiry new] init];
[d setInquiryLength: 5];
[d setUpdateNewDeviceNames: TRUE];
[d start];
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 7]];
[d stop];
NSArray *deviceList = [d foundDevices];
NSLog(@"found %d devices", [deviceList count]);
for(int i=0;i < [deviceList count]; i++) {
NSScanner *theScanner = [NSScanner scannerWithString:[NSString stringWithFormat:@"%@", [deviceList objectAtIndex:i]]];
NSString *tagDeviceName = @"mName - ";
NSString *tagEndLine = @"\n";
NSString *currentDeviceName;
// extract the mName from the current array value
while ([theScanner isAtEnd] == NO) {
[theScanner scanUpToString:tagDeviceName intoString:NULL];
[theScanner scanString:tagDeviceName intoString:NULL];
[theScanner scanUpToString:tagEndLine intoString:¤tDeviceName];
} // end [theScanner isAtEnd]
NSLog(@"device name: %@", currentDeviceName);
}
[pool release];
return 0;
}