开发者

Create a Terminal-Based Bluetooth Monitor in XCode?

I want to create a Terminal application that connects to a Bluetooth Device and outputs any commands that are sent out by the bluetooth device. So far, I am able to scan and output a list of available devices.

Any direction would be greatly appreciated - is this even possible? What should I be looking at now? I tried to use BluetoothDeviceAddress and IOBluetoothL2CAPChannelGetDevice but haven't had any success yet.

Here is my code so far:

#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 *curr开发者_如何学PythonentDeviceName;

        // 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:&currentDeviceName];           
        } // end [theScanner isAtEnd]

        NSLog(@"device name: %@", currentDeviceName);

    }


    [pool release]; 
    return 0; 
}


The next step will be : 1. Discover the services available on the device via SDP 2. Connect to the service and read the data.

You can use the SPP profile for data send / receive - assuming that the device you are connecting to is using this profile to send the data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜