mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-20 01:21:12 +00:00
checked in commented work in progress code
This commit is contained in:
parent
c0b99c8eb4
commit
3bdb147ffa
@ -35,7 +35,7 @@
|
||||
#import <stdint.h>
|
||||
#import <btstack/btstack.h>
|
||||
|
||||
#define PREFS_REMOTE_NAME @"RemoteName"
|
||||
#define PREFS_REMOTE_NAME @"RemoteName"
|
||||
#define PREFS_LINK_KEY @"LinkKey"
|
||||
#define BTstackManagerID @"ch.ringwald.btstack"
|
||||
|
||||
@ -56,7 +56,11 @@ typedef enum {
|
||||
kW4SysBTDisabled,
|
||||
kW4Activated,
|
||||
kActivated,
|
||||
kW4Deactivated
|
||||
kW4Deactivated,
|
||||
#if 0
|
||||
kW4DisoveryStopped,
|
||||
kW4AuthenticationEnableCommand
|
||||
#endif
|
||||
} ManagerState;
|
||||
|
||||
typedef enum {
|
||||
@ -83,6 +87,14 @@ typedef enum {
|
||||
ManagerState state;
|
||||
DiscoveryState discoveryState;
|
||||
int discoveryDeviceIndex;
|
||||
#if 0
|
||||
// current connection - kind a ugly
|
||||
uint8_t connType; // 0 = L2CAP, 1 = RFCOMM
|
||||
bd_addr_t connAddr;
|
||||
uint16_t connPSM;
|
||||
uint16_t connChan;
|
||||
uint8_t connAuth;
|
||||
#endif
|
||||
}
|
||||
|
||||
// shared instance
|
||||
@ -106,11 +118,11 @@ typedef enum {
|
||||
-(BOOL) isDiscoveryActive;
|
||||
|
||||
// Connections
|
||||
-(BTstackError) createL2CAPChannelAtAddress:(bd_addr_t) address withPSM:(uint16_t)psm authenticated:(BOOL)authentication;
|
||||
-(BTstackError) createL2CAPChannelAtAddress:(bd_addr_t*) address withPSM:(uint16_t)psm authenticated:(BOOL)authentication;
|
||||
-(BTstackError) closeL2CAPChannelWithID:(uint16_t) channelID;
|
||||
-(BTstackError) sendL2CAPPacketForChannelID:(uint16_t)channelID;
|
||||
|
||||
-(BTstackError) createRFCOMMConnectionAtAddress:(bd_addr_t) address withChannel:(uint16_t)psm authenticated:(BOOL)authentication;
|
||||
-(BTstackError) createRFCOMMConnectionAtAddress:(bd_addr_t*) address withChannel:(uint16_t)channel authenticated:(BOOL)authentication;
|
||||
-(BTstackError) closeRFCOMMConnectionWithID:(uint16_t) connectionID;
|
||||
-(BTstackError) sendRFCOMMPacketForChannelID:(uint16_t)connectionID;
|
||||
|
||||
|
@ -100,7 +100,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
|
||||
// read device database
|
||||
[self readDeviceInfo];
|
||||
[self storeDeviceInfo];
|
||||
|
||||
// Use Cocoa run loop
|
||||
run_loop_init(RUN_LOOP_COCOA);
|
||||
@ -127,6 +126,31 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
[listeners removeObject:listener];
|
||||
}
|
||||
|
||||
// Device info
|
||||
-(void)readDeviceInfo {
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
NSDictionary * dict = [defaults persistentDomainForName:BTstackManagerID];
|
||||
[self setDeviceInfo:[NSMutableDictionary dictionaryWithCapacity:([dict count]+5)]];
|
||||
|
||||
// copy entries
|
||||
for (id key in dict) {
|
||||
NSDictionary *value = [dict objectForKey:key];
|
||||
NSMutableDictionary *deviceEntry = [NSMutableDictionary dictionaryWithCapacity:[value count]];
|
||||
[deviceEntry addEntriesFromDictionary:value];
|
||||
[deviceInfo setObject:deviceEntry forKey:key];
|
||||
}
|
||||
// NSLog(@"read prefs %@", deviceInfo );
|
||||
}
|
||||
|
||||
-(void)storeDeviceInfo{
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults setPersistentDomain:deviceInfo forName:BTstackManagerID];
|
||||
[defaults synchronize];
|
||||
// NSLog(@"store prefs %@", deviceInfo);
|
||||
// NSLog(@"Persistence Domain names %@", [defaults persistentDomainNames]);
|
||||
}
|
||||
|
||||
|
||||
// Activation
|
||||
-(BTstackError) activate {
|
||||
|
||||
@ -164,7 +188,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
|
||||
// Discovery
|
||||
-(BTstackError) startDiscovery {
|
||||
if (state != kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||
discoveryState = kW4InquiryMode;
|
||||
bt_send_cmd(&hci_write_inquiry_mode, 0x01); // with RSSI
|
||||
return 0;
|
||||
@ -175,7 +199,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
}
|
||||
}
|
||||
-(BTstackError) stopDiscovery{
|
||||
if (state != kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||
switch (discoveryState){
|
||||
case kInactive:
|
||||
state = kDeactivated;
|
||||
@ -220,27 +244,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Connections
|
||||
-(BTstackError) createL2CAPChannelAtAddress:(bd_addr_t) address withPSM:(uint16_t)psm authenticated:(BOOL)authentication {
|
||||
return 0;
|
||||
};
|
||||
-(BTstackError) closeL2CAPChannelWithID:(uint16_t) channelID {
|
||||
return 0;
|
||||
};
|
||||
-(BTstackError) sendL2CAPPacketForChannelID:(uint16_t)channelID {
|
||||
return 0;
|
||||
};
|
||||
|
||||
-(BTstackError) createRFCOMMConnectionAtAddress:(bd_addr_t) address withChannel:(uint16_t)psm authenticated:(BOOL)authentication {
|
||||
return 0;
|
||||
};
|
||||
-(BTstackError) closeRFCOMMConnectionWithID:(uint16_t) connectionID {
|
||||
return 0;
|
||||
};
|
||||
-(BTstackError) sendRFCOMMPacketForChannelID:(uint16_t)connectionID {
|
||||
return 0;
|
||||
};
|
||||
|
||||
- (void) activationHandleEvent:(uint8_t *)packet withLen:(uint16_t) size {
|
||||
switch (state) {
|
||||
|
||||
@ -463,7 +466,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case kW4InquiryModeBeforeStop:
|
||||
if (packet[0] == HCI_EVENT_COMMAND_COMPLETE && COMMAND_COMPLETE_EVENT(packet, hci_write_inquiry_mode) ) {
|
||||
discoveryState = kInactive;
|
||||
@ -517,28 +520,52 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
[_delegate handlePacketWithType:packet_type forChannel:channel andData:packet withLen:size];
|
||||
}
|
||||
|
||||
|
||||
-(void)readDeviceInfo {
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
NSDictionary * dict = [defaults persistentDomainForName:BTstackManagerID];
|
||||
[self setDeviceInfo:[NSMutableDictionary dictionaryWithCapacity:([dict count]+5)]];
|
||||
// Connections
|
||||
-(BTstackError) createL2CAPChannelAtAddress:(bd_addr_t*) address withPSM:(uint16_t)psm authenticated:(BOOL)authentication {
|
||||
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||
if (state != kActivated) return BTSTACK_BUSY;
|
||||
#if 0
|
||||
// ...f (state
|
||||
// store params
|
||||
connType = 0;
|
||||
BD_ADDR_COPY(&connAddr, address);
|
||||
connPSM = psm;
|
||||
connAuth = authentication;
|
||||
|
||||
// copy entries
|
||||
for (id key in dict) {
|
||||
NSDictionary *value = [dict objectForKey:key];
|
||||
NSMutableDictionary *deviceEntry = [NSMutableDictionary dictionaryWithCapacity:[value count]];
|
||||
[deviceEntry addEntriesFromDictionary:value];
|
||||
[deviceInfo setObject:deviceEntry forKey:key];
|
||||
}
|
||||
// NSLog(@"read prefs %@", deviceInfo );
|
||||
}
|
||||
// send write authentication enabled
|
||||
bt_send_cmd(&hci_write_authentication_enable, authentication);
|
||||
state = kW4AuthenticationEnableCommand;
|
||||
#endif
|
||||
return 0;
|
||||
};
|
||||
-(BTstackError) sendL2CAPPacketForChannelID:(uint16_t)channelID {
|
||||
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||
return 0;
|
||||
};
|
||||
-(BTstackError) closeL2CAPChannelWithID:(uint16_t) channelID {
|
||||
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||
return 0;
|
||||
};
|
||||
|
||||
-(void)storeDeviceInfo{
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults setPersistentDomain:deviceInfo forName:BTstackManagerID];
|
||||
[defaults synchronize];
|
||||
// NSLog(@"store prefs %@", deviceInfo);
|
||||
// NSLog(@"Persistence Domain names %@", [defaults persistentDomainNames]);
|
||||
}
|
||||
-(BTstackError) createRFCOMMConnectionAtAddress:(bd_addr_t*) address withChannel:(uint16_t)channel authenticated:(BOOL)authentication {
|
||||
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||
if (state != kActivated) return BTSTACK_BUSY;
|
||||
#if 0
|
||||
// store params
|
||||
connType = 1;
|
||||
BD_ADDR_COPY(&connAddr, address);
|
||||
connChan = channel;
|
||||
connAuth = authentication;
|
||||
#endif
|
||||
return 0;
|
||||
};
|
||||
-(BTstackError) sendRFCOMMPacketForChannelID:(uint16_t)connectionID {
|
||||
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||
return 0;
|
||||
};
|
||||
-(BTstackError) closeRFCOMMConnectionWithID:(uint16_t) connectionID {
|
||||
if (state <kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||
return 0;
|
||||
};
|
||||
|
||||
@end
|
||||
|
Loading…
x
Reference in New Issue
Block a user