Создать монитор на основе терминала в XCode? - PullRequest
1 голос
/ 24 ноября 2010

Я хочу создать приложение терминала, которое подключается к устройству 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:&currentDeviceName];           
        } // end [theScanner isAtEnd]

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

    }


    [pool release]; 
    return 0; 
}

1 Ответ

0 голосов
/ 28 ноября 2010

Следующим шагом будет: 1. Найти сервисы, доступные на устройстве через SDP 2. Подключиться к сервису и прочитать данные.

Вы можете использовать профиль SPP для отправки / получения данных - при условиичто устройство, к которому вы подключаетесь, использует этот профиль для отправки данных.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...