Getting RSSIValue from IOBluetoothHostController
Posted
by
Tanner Ezell
on Stack Overflow
See other posts from Stack Overflow
or by Tanner Ezell
Published on 2010-10-19T05:49:11Z
Indexed on
2010/12/27
21:54 UTC
Read the original article
Hit count: 321
objective-c
|osx
I'm trying to write a simple application that gathers the RSSIValue and displays it via NSLog, my code is as follows:
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
#import <IOBluetooth/objc/IOBluetoothDevice.h>
#import <IOBluetooth/objc/IOBluetoothHostController.h>
#import <IOBluetooth/IOBluetoothUtilities.h>
@interface getRSSI: NSObject {}
-(void) readRSSIForDeviceComplete:(id)controller device:(IOBluetoothDevice*)device
info:(BluetoothHCIRSSIInfo*)info error:(IOReturn)error;
@end
@implementation getRSSI
- (void) readRSSIForDeviceComplete:(id)controller device:(IOBluetoothDevice*)device
info:(BluetoothHCIRSSIInfo*)info error:(IOReturn)error
{
if (error != kIOReturnSuccess) {
NSLog(@"readRSSIForDeviceComplete return error");
CFRunLoopStop(CFRunLoopGetCurrent());
}
if (info->handle == kBluetoothConnectionHandleNone) {
NSLog(@"readRSSIForDeviceComplete no handle");
CFRunLoopStop(CFRunLoopGetCurrent());
}
NSLog(@"RSSI = %i dBm ", info->RSSIValue);
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 5]];
[device closeConnection];
[device openConnection];
[controller readRSSIForDevice:device];
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"start");
IOBluetoothHostController *hci = [IOBluetoothHostController defaultController];
NSString *addrStr = @"xx:xx:xx:xx:xx:xx";
BluetoothDeviceAddress addr;
IOBluetoothNSStringToDeviceAddress(addrStr, &addr);
IOBluetoothDevice *device = [[IOBluetoothDevice alloc] init];
device = [IOBluetoothDevice withAddress:&addr];
[device retain];
[device openConnection];
getRSSI *rssi = [[getRSSI alloc] init];
[hci setDelegate:rssi];
[hci readRSSIForDevice:device];
CFRunLoopRun();
[hci release];
[rssi release];
[pool release];
return 0;
}
The problem I am facing is that the readRSSIForDeviceComplete seems to work just fine, info passes along a value. The problem is that the RSSI value is drastically different from the one I can view from OS X via option clicking the bluetooth icon at the top. It is typical for my application to print off 1,2,-1,-8,etc while the menu displays -64 dBm, -66, -70, -42, etc.
I would really appreciate some guidance.
© Stack Overflow or respective owner