在X code。创建一个基于终端的蓝牙监视器? [英] Create a Terminal-Based Bluetooth Monitor in XCode?

查看:175
本文介绍了在X code。创建一个基于终端的蓝牙监视器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个连接到蓝牙设备,输出由蓝牙设备发出的任何命令终端应用程序。到目前为止,我能够扫描并输出可用设备的列表。

任何方向将大大AP preciated - 这甚至可能?我应该怎么看呢?我试图用BluetoothDeviceAddress和IOBluetoothL2CAPChannelGetDevice但没有成功呢。

下面是我的code迄今:

 的#include<基金会/ Foundation.h>
#包括LT与可可/ Cocoa.h>
#包括LT&; IOBluetooth / objc / IOBluetoothDeviceInquiry.h>
#包括LT&; IOBluetoothUI / IOBluetoothUI.h>INT主(INT ARGC,为const char * argv的[]){
    NSAutoreleasePool *池= [[NSAutoreleasePool的alloc]初始化];
    的NSLog(@开始搜索蓝牙);    IOBluetoothDeviceInquiry * D = [[IOBluetoothDeviceInquiry新] INIT]
        并[d setInquiryLength:5];
        并〔d setUpdateNewDeviceNames:TRUE];
        研究[D开始]。    [NSThread sleepUntilDate:[的NSDate dateWithTimeIntervalSinceNow:7];
        [D停止]
        NSArray的* DEVICELIST = [ÐfoundDevices]    的NSLog(@发现%d个设备,[DEVICELIST计数]);    的for(int i = 0; I< D​​EVICELIST计数];我++){        NSScanner * theScanner = [NSScanner scannerWithString:[的NSString stringWithFormat:@%@,[DEVICELIST objectAtIndex:i]]];
        * NSString的tagDeviceName = @MNAME - ;
        * NSString的tagEndLine = @\\ n;        * NSString的currentDeviceName;        //从目前的数组值提取MNAME
        而([theScanner isAtEnd] == NO){
            [theScanner scanUpToString:tagDeviceName intoString:NULL];
            [theScanner scanString:tagDeviceName intoString:NULL];
            [theScanner scanUpToString:tagEndLine intoString:放大器; currentDeviceName]。
        } //结束[theScanner isAtEnd]        的NSLog(@设备名称:%@,currentDeviceName);    }
    [池释放];
    返回0;
}


解决方案

接下来的步骤将是:
1.发现通过SDP设备上可用的服务
2.连接到服务并读取数据。

有关数据发送/接收您可以使用SPP配置文件 - 假设你正在连接的设备正在使用此配置文件发送的数据

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; 
}

解决方案

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.

这篇关于在X code。创建一个基于终端的蓝牙监视器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆