mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-22 06:41:17 +00:00
use null_object for bt control, test power cycle
This commit is contained in:
parent
8b658ebcf8
commit
7301ad89bc
@ -5,7 +5,7 @@ VPATH = src
|
||||
|
||||
# These paths must be changed to match the compilation environment
|
||||
SDK_PATH = /Developer/Platforms/iPhoneOS.platform/Developer
|
||||
SDK_VERSION = 2.0
|
||||
SDK_VERSION = 2.1
|
||||
GCC_VERSION = 4.0.1
|
||||
|
||||
#
|
||||
@ -44,7 +44,7 @@ $(SRCS): $(HEADERS)
|
||||
$(NAME): $(SRCS)
|
||||
$(CXX) $(CXXFLAGS) -o $(NAME) $(filter %.mm,$^) $(filter %.m,$^) $(filter %.c,$^) $(LDFLAGS)
|
||||
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate ; ldid -S $(NAME)
|
||||
ssh root@192.168.3.102 rm BTdaemon
|
||||
ssh root@192.168.3.102 rm -f BTdaemon
|
||||
scp $(NAME) root@192.168.3.102:.
|
||||
|
||||
.PHONY: all clean
|
||||
|
@ -13,5 +13,5 @@ typedef struct {
|
||||
int (*on)(void *config); // <-- turn BT module on and configure
|
||||
int (*off)(void *config); // <-- turn BT module off
|
||||
int (*valid)(void *confif); // <-- test if hardware can be supported
|
||||
const char * (*names)(void *config); // <-- return hardware name
|
||||
const char * (*name)(void *config); // <-- return hardware name
|
||||
} bt_control_t;
|
||||
|
63
src/hci.c
63
src/hci.c
@ -132,6 +132,11 @@ static void event_handler(uint8_t *packet, int size){
|
||||
|
||||
// handle BT initialization
|
||||
if (hci_stack.state == HCI_STATE_INITIALIZING){
|
||||
// handle H4 synchronization loss on restart
|
||||
// if (hci_stack.substate == 1 && packet[0] == HCI_EVENT_HARDWARE_ERROR){
|
||||
// hci_stack.substate = 0;
|
||||
// }
|
||||
// handle normal init sequence
|
||||
if (hci_stack.substate % 2){
|
||||
// odd: waiting for event
|
||||
if (packet[0] == HCI_EVENT_COMMAND_COMPLETE){
|
||||
@ -164,47 +169,71 @@ void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, int size
|
||||
hci_stack.acl_packet_handler = handler;
|
||||
}
|
||||
|
||||
static int null_control_function(void *config){
|
||||
return 0;
|
||||
}
|
||||
static const char * null_control_name(void *config){
|
||||
return "Hardware unknown";
|
||||
}
|
||||
|
||||
static bt_control_t null_control = {
|
||||
null_control_function,
|
||||
null_control_function,
|
||||
null_control_function,
|
||||
null_control_name
|
||||
};
|
||||
|
||||
void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){
|
||||
|
||||
// reference to use transport layer implementation
|
||||
hci_stack.hci_transport = transport;
|
||||
|
||||
// references to used control implementation
|
||||
hci_stack.control = control;
|
||||
if (control) {
|
||||
hci_stack.control = control;
|
||||
} else {
|
||||
hci_stack.control = &null_control;
|
||||
}
|
||||
|
||||
// reference to used config
|
||||
hci_stack.config = config;
|
||||
|
||||
// empty cmd buffer
|
||||
hci_stack.hci_cmd_buffer = malloc(3+255);
|
||||
|
||||
// set up state
|
||||
hci_stack.num_cmd_packets = 1; // assume that one cmd can be sent
|
||||
hci_stack.state = HCI_STATE_INITIALIZING;
|
||||
hci_stack.substate = 0;
|
||||
|
||||
|
||||
// higher level handler
|
||||
hci_stack.event_packet_handler = dummy_handler;
|
||||
hci_stack.acl_packet_handler = dummy_handler;
|
||||
|
||||
|
||||
// register packet handlers with transport
|
||||
transport->register_event_packet_handler( event_handler);
|
||||
transport->register_acl_packet_handler( acl_handler);
|
||||
|
||||
// turn on
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
// open low-level device
|
||||
transport->open(config);
|
||||
}
|
||||
|
||||
int hci_power_control(HCI_POWER_MODE power_mode){
|
||||
if (hci_stack.control) {
|
||||
if (power_mode == HCI_POWER_ON) {
|
||||
hci_stack.control->on(hci_stack.config);
|
||||
} else if (power_mode == HCI_POWER_OFF){
|
||||
hci_stack.control->off(hci_stack.config);
|
||||
}
|
||||
if (power_mode == HCI_POWER_ON) {
|
||||
|
||||
// set up state machine
|
||||
hci_stack.num_cmd_packets = 1; // assume that one cmd can be sent
|
||||
hci_stack.state = HCI_STATE_INITIALIZING;
|
||||
hci_stack.substate = 0;
|
||||
|
||||
// power on
|
||||
hci_stack.control->on(hci_stack.config);
|
||||
|
||||
// open low-level device
|
||||
hci_stack.hci_transport->open(hci_stack.config);
|
||||
|
||||
} else if (power_mode == HCI_POWER_OFF){
|
||||
|
||||
// close low-level device
|
||||
hci_stack.hci_transport->close(hci_stack.config);
|
||||
|
||||
// power off
|
||||
hci_stack.control->off(hci_stack.config);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
26
src/main.c
26
src/main.c
@ -13,6 +13,7 @@
|
||||
#include "hci.h"
|
||||
#include "hci_transport_h4.h"
|
||||
#include "hci_dump.h"
|
||||
#include "bt_control_iphone.h"
|
||||
|
||||
#include "l2cap.h"
|
||||
|
||||
@ -23,16 +24,16 @@ hci_con_handle_t con_handle= 0;
|
||||
uint16_t dest_cid;
|
||||
|
||||
void event_handler(uint8_t *packet, int size){
|
||||
bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard
|
||||
// bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9}; // MacBook Pro
|
||||
|
||||
// printf("Event type: %x, opcode: %x, other %x\n", packet[0], packet[3] | packet[4] << 8);
|
||||
|
||||
#if 0
|
||||
// bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard
|
||||
// bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9}; // MacBook Pro
|
||||
|
||||
// bt stack activated, set authentication enabled
|
||||
if (packet[0] == BTSTACK_EVENT_HCI_WORKING) {
|
||||
hci_send_cmd(&hci_write_authentication_enable, 1);
|
||||
// hci_send_cmd(&hci_host_buffer_size, 400, 255, 1, 0, 0);
|
||||
// hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 30, 0);
|
||||
}
|
||||
|
||||
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_authentication_enable) ) {
|
||||
@ -55,6 +56,21 @@ void event_handler(uint8_t *packet, int size){
|
||||
l2cap_send_signaling_packet(con_handle, CONNECTION_REQUEST, sig_seq_nr++, 0x13, local_cid);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (packet[0] == BTSTACK_EVENT_HCI_WORKING) {
|
||||
hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 10, 0);
|
||||
}
|
||||
if (packet[0] == HCI_EVENT_INQUIRY_COMPLETE){
|
||||
// power cycle
|
||||
hci_power_control( HCI_POWER_OFF );
|
||||
//
|
||||
printf ("Power off!\n");
|
||||
sleep(10);
|
||||
printf ("Restart!\n");
|
||||
hci_power_control( HCI_POWER_ON );
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void acl_handler(uint8_t *packet, int size){
|
||||
@ -95,7 +111,7 @@ int main (int argc, const char * argv[]) {
|
||||
|
||||
bt_control_t * control = NULL;
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
//
|
||||
if (argc <= 1){
|
||||
printf("HCI Daemon tester. Specify device name for Ericsson ROK 101 007\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user