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
@ -56,7 +56,11 @@ typedef enum {
|
|||||||
kW4SysBTDisabled,
|
kW4SysBTDisabled,
|
||||||
kW4Activated,
|
kW4Activated,
|
||||||
kActivated,
|
kActivated,
|
||||||
kW4Deactivated
|
kW4Deactivated,
|
||||||
|
#if 0
|
||||||
|
kW4DisoveryStopped,
|
||||||
|
kW4AuthenticationEnableCommand
|
||||||
|
#endif
|
||||||
} ManagerState;
|
} ManagerState;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -83,6 +87,14 @@ typedef enum {
|
|||||||
ManagerState state;
|
ManagerState state;
|
||||||
DiscoveryState discoveryState;
|
DiscoveryState discoveryState;
|
||||||
int discoveryDeviceIndex;
|
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
|
// shared instance
|
||||||
@ -106,11 +118,11 @@ typedef enum {
|
|||||||
-(BOOL) isDiscoveryActive;
|
-(BOOL) isDiscoveryActive;
|
||||||
|
|
||||||
// Connections
|
// 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) closeL2CAPChannelWithID:(uint16_t) channelID;
|
||||||
-(BTstackError) sendL2CAPPacketForChannelID:(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) closeRFCOMMConnectionWithID:(uint16_t) connectionID;
|
||||||
-(BTstackError) sendRFCOMMPacketForChannelID:(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
|
// read device database
|
||||||
[self readDeviceInfo];
|
[self readDeviceInfo];
|
||||||
[self storeDeviceInfo];
|
|
||||||
|
|
||||||
// Use Cocoa run loop
|
// Use Cocoa run loop
|
||||||
run_loop_init(RUN_LOOP_COCOA);
|
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];
|
[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
|
// Activation
|
||||||
-(BTstackError) activate {
|
-(BTstackError) activate {
|
||||||
|
|
||||||
@ -164,7 +188,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
|
|
||||||
// Discovery
|
// Discovery
|
||||||
-(BTstackError) startDiscovery {
|
-(BTstackError) startDiscovery {
|
||||||
if (state != kActivated) return BTSTACK_NOT_ACTIVATED;
|
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||||
discoveryState = kW4InquiryMode;
|
discoveryState = kW4InquiryMode;
|
||||||
bt_send_cmd(&hci_write_inquiry_mode, 0x01); // with RSSI
|
bt_send_cmd(&hci_write_inquiry_mode, 0x01); // with RSSI
|
||||||
return 0;
|
return 0;
|
||||||
@ -175,7 +199,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
-(BTstackError) stopDiscovery{
|
-(BTstackError) stopDiscovery{
|
||||||
if (state != kActivated) return BTSTACK_NOT_ACTIVATED;
|
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||||
switch (discoveryState){
|
switch (discoveryState){
|
||||||
case kInactive:
|
case kInactive:
|
||||||
state = kDeactivated;
|
state = kDeactivated;
|
||||||
@ -220,27 +244,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
return nil;
|
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 {
|
- (void) activationHandleEvent:(uint8_t *)packet withLen:(uint16_t) size {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
|
||||||
@ -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];
|
[_delegate handlePacketWithType:packet_type forChannel:channel andData:packet withLen:size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
-(void)readDeviceInfo {
|
// send write authentication enabled
|
||||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
bt_send_cmd(&hci_write_authentication_enable, authentication);
|
||||||
NSDictionary * dict = [defaults persistentDomainForName:BTstackManagerID];
|
state = kW4AuthenticationEnableCommand;
|
||||||
[self setDeviceInfo:[NSMutableDictionary dictionaryWithCapacity:([dict count]+5)]];
|
#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;
|
||||||
|
};
|
||||||
|
|
||||||
// copy entries
|
-(BTstackError) createRFCOMMConnectionAtAddress:(bd_addr_t*) address withChannel:(uint16_t)channel authenticated:(BOOL)authentication {
|
||||||
for (id key in dict) {
|
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||||
NSDictionary *value = [dict objectForKey:key];
|
if (state != kActivated) return BTSTACK_BUSY;
|
||||||
NSMutableDictionary *deviceEntry = [NSMutableDictionary dictionaryWithCapacity:[value count]];
|
#if 0
|
||||||
[deviceEntry addEntriesFromDictionary:value];
|
// store params
|
||||||
[deviceInfo setObject:deviceEntry forKey:key];
|
connType = 1;
|
||||||
}
|
BD_ADDR_COPY(&connAddr, address);
|
||||||
// NSLog(@"read prefs %@", deviceInfo );
|
connChan = channel;
|
||||||
}
|
connAuth = authentication;
|
||||||
|
#endif
|
||||||
-(void)storeDeviceInfo{
|
return 0;
|
||||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
};
|
||||||
[defaults setPersistentDomain:deviceInfo forName:BTstackManagerID];
|
-(BTstackError) sendRFCOMMPacketForChannelID:(uint16_t)connectionID {
|
||||||
[defaults synchronize];
|
if (state < kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||||
// NSLog(@"store prefs %@", deviceInfo);
|
return 0;
|
||||||
// NSLog(@"Persistence Domain names %@", [defaults persistentDomainNames]);
|
};
|
||||||
}
|
-(BTstackError) closeRFCOMMConnectionWithID:(uint16_t) connectionID {
|
||||||
|
if (state <kActivated) return BTSTACK_NOT_ACTIVATED;
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user