mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-03 20:54:18 +00:00
allow to cancel both an ongoing inquiry or remote name request
This commit is contained in:
parent
d2be1af7a2
commit
a836342cf7
@ -63,7 +63,9 @@ typedef enum {
|
||||
// hacks
|
||||
bool stopRemoteNameGathering;
|
||||
bool restartInquiry;
|
||||
BTDevice *remoteNameDevice; // device for which remote name request is pending
|
||||
BTDevice *remoteDevice;
|
||||
bool notifyDelegateOnInquiryStopped;
|
||||
}
|
||||
|
||||
- (void) startInquiry;
|
||||
@ -79,4 +81,5 @@ typedef enum {
|
||||
@protocol BTInquiryDelegate
|
||||
- (void) deviceChoosen:(BTInquiryViewController *) inqView device:(BTDevice*) device;
|
||||
- (void) deviceDetected:(BTInquiryViewController *) inqView device:(BTDevice*) device;
|
||||
- (void) inquiryStopped;
|
||||
@end
|
||||
|
@ -49,7 +49,7 @@ static uint8_t remoteNameIndex;
|
||||
@interface BTInquiryViewController (private)
|
||||
- (void) handlePacket:(uint8_t) packet_type channel:(uint16_t) channel packet:(uint8_t*) packet size:(uint16_t) size;
|
||||
- (BTDevice *) getDeviceForAddress:(bd_addr_t *)addr;
|
||||
- (bool) getNextRemoteName;
|
||||
- (void) getNextRemoteName;
|
||||
- (void) startInquiry;
|
||||
@end
|
||||
|
||||
@ -72,6 +72,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
allowSelection = false;
|
||||
remoteDevice = nil;
|
||||
restartInquiry = true;
|
||||
notifyDelegateOnInquiryStopped = false;
|
||||
|
||||
macAddressFont = [UIFont fontWithName:@"Courier New" size:[UIFont labelFontSize]];
|
||||
deviceNameFont = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
|
||||
@ -176,19 +177,42 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
break;
|
||||
|
||||
case HCI_EVENT_COMMAND_COMPLETE:
|
||||
if (COMMAND_COMPLETE_EVENT(packet, hci_inquiry_cancel)){
|
||||
// inquiry canceled
|
||||
NSLog(@"Inquiry cancelled successfully");
|
||||
inquiryState = kInquiryInactive;
|
||||
[[self tableView] reloadData];
|
||||
if (notifyDelegateOnInquiryStopped){
|
||||
notifyDelegateOnInquiryStopped = false;
|
||||
if (delegate) {
|
||||
[delegate inquiryStopped];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (COMMAND_COMPLETE_EVENT(packet, hci_remote_name_request_cancel)){
|
||||
// inquiry canceled
|
||||
NSLog(@"Remote name request cancelled successfully");
|
||||
inquiryState = kInquiryInactive;
|
||||
[[self tableView] reloadData];
|
||||
if (notifyDelegateOnInquiryStopped){
|
||||
notifyDelegateOnInquiryStopped = false;
|
||||
if (delegate) {
|
||||
[delegate inquiryStopped];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HCI_EVENT_INQUIRY_COMPLETE:
|
||||
NSLog(@"Inquiry complete");
|
||||
// reset name check
|
||||
remoteNameIndex = 0;
|
||||
[self getNextRemoteName];
|
||||
break;
|
||||
|
||||
default:
|
||||
// Inquiry done
|
||||
if (packet[0] == HCI_EVENT_INQUIRY_COMPLETE || COMMAND_COMPLETE_EVENT(packet, hci_inquiry_cancel)){
|
||||
NSLog(@"Inquiry stopped");
|
||||
if (inquiryState == kInquiryActive){
|
||||
remoteNameIndex = 0;
|
||||
stopRemoteNameGathering = false;
|
||||
[self getNextRemoteName];
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
// hexdump(packet, size);
|
||||
break;
|
||||
@ -212,20 +236,35 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (bool) getNextRemoteName{
|
||||
BTDevice *remoteDev = nil;
|
||||
- (void) getNextRemoteName{
|
||||
|
||||
for (remoteNameIndex = 0; !stopRemoteNameGathering && remoteNameIndex < [devices count]; remoteNameIndex++){
|
||||
// stopped?
|
||||
if (stopRemoteNameGathering) {
|
||||
inquiryState = kInquiryInactive;
|
||||
[[self tableView] reloadData];
|
||||
|
||||
if (notifyDelegateOnInquiryStopped){
|
||||
notifyDelegateOnInquiryStopped = false;
|
||||
if (delegate) {
|
||||
[delegate inquiryStopped];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
remoteNameDevice = nil;
|
||||
|
||||
for (remoteNameIndex = 0; remoteNameIndex < [devices count]; remoteNameIndex++){
|
||||
BTDevice *dev = [devices objectAtIndex:remoteNameIndex];
|
||||
if (![dev name]){
|
||||
remoteDev = dev;
|
||||
remoteNameDevice = dev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (remoteDev) {
|
||||
if (remoteNameDevice) {
|
||||
inquiryState = kInquiryRemoteName;
|
||||
[remoteDev setConnectionState:kBluetoothConnectionRemoteName];
|
||||
bt_send_cmd(&hci_remote_name_request, [remoteDev address], [remoteDev pageScanRepetitionMode], 0, [remoteDev clockOffset] | 0x8000);
|
||||
[remoteNameDevice setConnectionState:kBluetoothConnectionRemoteName];
|
||||
bt_send_cmd(&hci_remote_name_request, [remoteNameDevice address], [remoteNameDevice pageScanRepetitionMode], 0, [remoteNameDevice clockOffset] | 0x8000);
|
||||
} else {
|
||||
inquiryState = kInquiryInactive;
|
||||
// inquiry done.
|
||||
@ -234,8 +273,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
}
|
||||
}
|
||||
[[self tableView] reloadData];
|
||||
|
||||
return remoteDev;
|
||||
}
|
||||
|
||||
- (void) startInquiry {
|
||||
@ -247,25 +284,43 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
bluetoothState = HCI_STATE_INITIALIZING;
|
||||
[[self tableView] reloadData];
|
||||
|
||||
stopRemoteNameGathering = false;
|
||||
restartInquiry = true;
|
||||
|
||||
bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
|
||||
}
|
||||
|
||||
- (void) stopInquiry {
|
||||
|
||||
NSLog(@"stop inquiry called, state %u", inquiryState);
|
||||
restartInquiry = false;
|
||||
stopRemoteNameGathering = true;
|
||||
bool immediateNotify = true;
|
||||
|
||||
switch (inquiryState) {
|
||||
case kInquiryActive:
|
||||
// just stop inquiry
|
||||
immediateNotify = false;
|
||||
bt_send_cmd(&hci_inquiry_cancel);
|
||||
break;
|
||||
case kInquiryInactive:
|
||||
NSLog(@"stop inquiry called although inquiry inactive?");
|
||||
break;
|
||||
case kInquiryRemoteName:
|
||||
stopRemoteNameGathering = true;
|
||||
restartInquiry = false;
|
||||
if (remoteNameDevice) {
|
||||
// just stop remote name request
|
||||
immediateNotify = false;
|
||||
bt_send_cmd(&hci_remote_name_request_cancel, [remoteNameDevice address]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (immediateNotify && delegate){
|
||||
[delegate inquiryStopped];
|
||||
} else {
|
||||
notifyDelegateOnInquiryStopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) showConnecting:(BTDevice *) device {
|
||||
@ -429,8 +484,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
|
||||
// valid selection?
|
||||
int idx = [indexPath indexAtPosition:1];
|
||||
if (bluetoothState == HCI_STATE_WORKING && inquiryState == kInquiryInactive && idx < [devices count]){
|
||||
// if (delegate && [delegate conformsTo:@protocol(BTInquiryDelegate)]){
|
||||
if (bluetoothState == HCI_STATE_WORKING && idx < [devices count]){
|
||||
if (delegate) {
|
||||
[delegate deviceChoosen:self device:[devices objectAtIndex:idx]];
|
||||
}
|
||||
|
15
TODO.txt
15
TODO.txt
@ -1,21 +1,10 @@
|
||||
/* new todo file for BTstack */
|
||||
|
||||
2009-11-08: Release 0.1
|
||||
|
||||
NEXT:
|
||||
- WiiMote Demo
|
||||
- implement roll
|
||||
- video for YouTube
|
||||
|
||||
- check/fix BTstack for iPhone 2G
|
||||
|
||||
- figure out how to add BTstack logo to Cydia repository list
|
||||
- sign BTstack repository
|
||||
|
||||
- add news coverage on wiki
|
||||
- release notes (features and limits)
|
||||
- install instructions with Cydia usage screenshots
|
||||
|
||||
== Release Version 0.1
|
||||
|
||||
- figure out how to receive iPhone System Power IONotifications (in BTdaemon) to detect,
|
||||
when phone gets locked
|
||||
- some trick
|
||||
|
@ -344,6 +344,10 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
}
|
||||
}
|
||||
|
||||
- (void) inquiryStopped{
|
||||
NSLog(@"inquiryStopped");
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
// disconnect
|
||||
if (wiiMoteConHandle) {
|
||||
|
@ -16,7 +16,7 @@
|
||||
9C0D06391091035200FC3BBA /* BTDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C0D06361091035200FC3BBA /* BTDevice.m */; };
|
||||
9C0D063A1091035200FC3BBA /* BTInquiryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C0D06381091035200FC3BBA /* BTInquiryViewController.m */; };
|
||||
9C0D070D1092316D00FC3BBA /* EAGLViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C0D070C1092316D00FC3BBA /* EAGLViewController.m */; };
|
||||
9C180042108B95B000824BE7 /* libBTstack.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C180041108B95B000824BE7 /* libBTstack.dylib */; };
|
||||
9C3BBA8310ACAEE9003464E1 /* libBTstack.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C3BBA8210ACAEE9003464E1 /* libBTstack.dylib */; };
|
||||
9C6BB62E1027911E00A0BCB0 /* wiimote_texture.png in Resources */ = {isa = PBXBuildFile; fileRef = 9C6BB62D1027911E00A0BCB0 /* wiimote_texture.png */; };
|
||||
9CB96E9810278945002663D0 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9CB96E9710278945002663D0 /* CoreGraphics.framework */; };
|
||||
9CB96EEF10278D8D002663D0 /* EAGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 28FD14FD0DC6FC130079059D /* EAGLView.m */; };
|
||||
@ -47,7 +47,7 @@
|
||||
9C18001D108B94FB00824BE7 /* linked_list.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = linked_list.h; sourceTree = "<group>"; };
|
||||
9C18001E108B94FB00824BE7 /* run_loop.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = run_loop.h; sourceTree = "<group>"; };
|
||||
9C18001F108B94FB00824BE7 /* utils.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = utils.h; sourceTree = "<group>"; };
|
||||
9C180041108B95B000824BE7 /* libBTstack.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libBTstack.dylib; path = ../../src/libBTstack.dylib; sourceTree = SOURCE_ROOT; };
|
||||
9C3BBA8210ACAEE9003464E1 /* libBTstack.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libBTstack.dylib; path = /usr/local/lib/libBTstack.dylib; sourceTree = "<absolute>"; };
|
||||
9C6BB62D1027911E00A0BCB0 /* wiimote_texture.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = wiimote_texture.png; sourceTree = "<group>"; };
|
||||
9CB96E9710278945002663D0 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
|
||||
9CC8B5E41093727700BCBA1F /* wiimote_logo_55px.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = wiimote_logo_55px.png; sourceTree = "<group>"; };
|
||||
@ -63,7 +63,7 @@
|
||||
28FD15000DC6FC520079059D /* OpenGLES.framework in Frameworks */,
|
||||
28FD15080DC6FC5B0079059D /* QuartzCore.framework in Frameworks */,
|
||||
9CB96E9810278945002663D0 /* CoreGraphics.framework in Frameworks */,
|
||||
9C180042108B95B000824BE7 /* libBTstack.dylib in Frameworks */,
|
||||
9C3BBA8310ACAEE9003464E1 /* libBTstack.dylib in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -94,7 +94,7 @@
|
||||
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9C180041108B95B000824BE7 /* libBTstack.dylib */,
|
||||
9C3BBA8210ACAEE9003464E1 /* libBTstack.dylib */,
|
||||
9C18001A108B94FB00824BE7 /* btstack */,
|
||||
9CCE6DC71025E0A600FCE9F4 /* BTstack */,
|
||||
080E96DDFE201D6D7F000001 /* Classes */,
|
||||
@ -241,11 +241,7 @@
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = WiiMoteOpenGLDemo_Prefix.pch;
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
LIBRARY_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"\"$(SRCROOT)/../btstack/src\"",
|
||||
"\"$(SRCROOT)/../../src\"",
|
||||
);
|
||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||
PRODUCT_NAME = WiiMoteOpenGLDemo;
|
||||
};
|
||||
name = Debug;
|
||||
@ -282,6 +278,7 @@
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
OTHER_CFLAGS = "-I/Projects/iPhone/btstack/include";
|
||||
OTHER_CPLUSPLUSFLAGS = "";
|
||||
OTHER_LDFLAGS = "-L/usr/local/lib";
|
||||
PREBINDING = NO;
|
||||
SDKROOT = iphoneos2.0;
|
||||
USER_HEADER_SEARCH_PATHS = "";
|
||||
@ -298,6 +295,7 @@
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
OTHER_CFLAGS = "-I/Projects/iPhone/btstack/include";
|
||||
OTHER_CPLUSPLUSFLAGS = "";
|
||||
OTHER_LDFLAGS = "-L/usr/local/lib";
|
||||
PREBINDING = NO;
|
||||
SDKROOT = iphoneos2.0;
|
||||
USER_HEADER_SEARCH_PATHS = "";
|
||||
|
@ -28,6 +28,7 @@
|
||||
9C7ECB840FCC85650085DAC5 /* bt_control_iphone.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7ECB820FCC85650085DAC5 /* bt_control_iphone.c */; };
|
||||
9C7ECBB50FCC95DD0085DAC5 /* hci_dump.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7ECBB40FCC95DD0085DAC5 /* hci_dump.c */; };
|
||||
9C88500E0FBF6702004980E4 /* l2cap.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C88500C0FBF6702004980E4 /* l2cap.c */; };
|
||||
9CAA573710A5D87400D0E1A9 /* inquiry.c in Sources */ = {isa = PBXBuildFile; fileRef = 9CAA573610A5D87400D0E1A9 /* inquiry.c */; };
|
||||
9CC813A20FFC0774002816F9 /* btstack.c in Sources */ = {isa = PBXBuildFile; fileRef = 9CC813A10FFC0774002816F9 /* btstack.c */; };
|
||||
9CC813A50FFC0A51002816F9 /* daemon.c in Sources */ = {isa = PBXBuildFile; fileRef = 9CC813A40FFC0A51002816F9 /* daemon.c */; };
|
||||
9CCE6CEA1025BD0000FCE9F4 /* hci.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC340FA906F700ABEF05 /* hci.c */; };
|
||||
@ -94,6 +95,7 @@
|
||||
9C88500D0FBF6702004980E4 /* l2cap.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = l2cap.h; path = src/l2cap.h; sourceTree = "<group>"; };
|
||||
9C994B8E106BEEB700C70311 /* rfcomm.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = rfcomm.c; path = example/rfcomm.c; sourceTree = "<group>"; };
|
||||
9CA3C0900FB8B3C4005F48DE /* TODO.txt */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = TODO.txt; sourceTree = "<group>"; };
|
||||
9CAA573610A5D87400D0E1A9 /* inquiry.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = inquiry.c; path = example/inquiry.c; sourceTree = "<group>"; };
|
||||
9CBE154810A354FF00597802 /* package.sh */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text.script.sh; path = package.sh; sourceTree = "<group>"; };
|
||||
9CC152C61009052100223347 /* config.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
|
||||
9CC813A10FFC0774002816F9 /* btstack.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = btstack.c; path = src/btstack.c; sourceTree = "<group>"; };
|
||||
@ -235,6 +237,7 @@
|
||||
9C7B5B81100D04520065D87E /* Example */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9CAA573610A5D87400D0E1A9 /* inquiry.c */,
|
||||
9C994B8E106BEEB700C70311 /* rfcomm.c */,
|
||||
9C1813F71042FCCA00C68F09 /* mitm.c */,
|
||||
9C7B5B7E100D04450065D87E /* test.c */,
|
||||
@ -338,6 +341,7 @@
|
||||
9CEB4F17107AAAEF00DD5720 /* run_loop_posix.c in Sources */,
|
||||
9C04B826107D1CED002A63D0 /* run_loop.c in Sources */,
|
||||
9C04B876107D2B7C002A63D0 /* run_loop_cocoa.m in Sources */,
|
||||
9CAA573710A5D87400D0E1A9 /* inquiry.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user