Create a Terminal-Based Bluetooth Monitor in XCode?

谁说我不能喝 提交于 2019-12-08 07:27:05

问题


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

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

    }


    [pool release]; 
    return 0; 
}

回答1:


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.



来源:https://stackoverflow.com/questions/4271014/create-a-terminal-based-bluetooth-monitor-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!