mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-22 06:41:17 +00:00
cleanups
This commit is contained in:
parent
56fe0872e0
commit
554588a5c7
@ -88,12 +88,12 @@ void hci_create_cmd_packet(uint8_t *buffer, uint8_t *cmd_len, hci_cmd_t *cmd, ..
|
||||
case '1': // 8 bit value
|
||||
case '2': // 16 bit value
|
||||
case 'H': // hci_handle
|
||||
word = va_arg(argptr, int); // minimum c parameter width is int
|
||||
word = va_arg(argptr, int); // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
|
||||
buffer[pos++] = word & 0xff;
|
||||
if (*format == '2') {
|
||||
buffer[pos++] = word >> 8;
|
||||
} else if (*format == 'H') {
|
||||
|
||||
// TODO
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
|
@ -31,9 +31,14 @@ int hci_power_control(HCI_POWER_MODE mode);
|
||||
// run the hci daemon loop
|
||||
void hci_run();
|
||||
|
||||
//
|
||||
void hexdump(uint8_t *data, int size);
|
||||
|
||||
// create hci command packet based on a template and a list of parameters
|
||||
void hci_create_cmd_packet(uint8_t *buffer, uint8_t *cmd_len, hci_cmd_t *cmd, ...);
|
||||
|
||||
int hci_send_cmd_packet(uint8_t *buffer, int size);
|
||||
|
||||
extern hci_cmd_t hci_inquiry;
|
||||
extern hci_cmd_t hci_reset;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <unistd.h> /* UNIX standard function definitions */
|
||||
#include <stdio.h>
|
||||
|
||||
#include "hci.h"
|
||||
#include "hci_transport_h4.h"
|
||||
|
||||
typedef enum {
|
||||
@ -98,6 +99,9 @@ static int h4_close(){
|
||||
}
|
||||
|
||||
static int h4_send_cmd_packet(uint8_t *packet, int size){
|
||||
printf("CMD: ");
|
||||
hexdump(packet, size);
|
||||
|
||||
char *data = (char*) packet;
|
||||
char cmd_type = 1;
|
||||
write(fd, &cmd_type, 1);
|
||||
@ -155,6 +159,8 @@ static int h4_handle_data() {
|
||||
h4_state = H4_W4_EVENT_PAYLOAD;
|
||||
break;
|
||||
case H4_W4_EVENT_PAYLOAD:
|
||||
printf("EVT: ");
|
||||
hexdump( hci_event_buffer, read_pos);
|
||||
event_packet_handler(hci_event_buffer, read_pos);
|
||||
h4_state = H4_W4_PACKET_TYPE;
|
||||
read_pos = 0;
|
||||
|
48
src/main.c
48
src/main.c
@ -19,38 +19,13 @@ static hci_transport_t * transport;
|
||||
static hci_uart_config_t config;
|
||||
static uint8_t buffer [200];
|
||||
|
||||
#if 0
|
||||
static void *hci_daemon_thread(void *arg){
|
||||
printf("HCI Daemon started\n");
|
||||
hci_run(transport, &config);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
void hexdump(uint8_t *data, int size){
|
||||
int i;
|
||||
for (i=0; i<size;i++){
|
||||
printf("%02X ", data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_cmd(uint8_t *data, int size){
|
||||
printf("CMD: ");
|
||||
hexdump(data, size);
|
||||
}
|
||||
|
||||
void event_handler(uint8_t *packet, int size){
|
||||
printf("EVT: ");
|
||||
hexdump( packet, size);
|
||||
|
||||
//
|
||||
if (packet[3] == 3 && packet[4] == 12){
|
||||
// reset done, send inq
|
||||
uint8_t len;
|
||||
hci_create_cmd_packet( buffer, &len, &hci_inquiry, HCI_INQUIRY_LAP, 30, 0);
|
||||
transport->send_cmd_packet( buffer, len );
|
||||
dump_cmd( buffer, len);
|
||||
hci_send_cmd_packet( buffer, len );
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,21 +46,8 @@ int main (int argc, const char * argv[]) {
|
||||
config.baudrate = 57600;
|
||||
config.flowcontrol = 1;
|
||||
|
||||
#if 0
|
||||
// create and start HCI daemon thread
|
||||
pthread_t new_thread;
|
||||
pthread_create(&new_thread, NULL, hci_daemon_thread, NULL);
|
||||
|
||||
// open UNIX domain socket
|
||||
while(1){
|
||||
sleep(1);
|
||||
printf(".\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// hci_init(transport, &config);
|
||||
// hci_power_control(HCI_POWER_ON);
|
||||
hci_init(transport, &config);
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
// open low-level device
|
||||
transport->open(&config);
|
||||
@ -93,7 +55,6 @@ int main (int argc, const char * argv[]) {
|
||||
//
|
||||
// register callbacks
|
||||
//
|
||||
// hci_run();
|
||||
transport->register_event_packet_handler(&event_handler);
|
||||
|
||||
// get fd for select call
|
||||
@ -102,8 +63,7 @@ int main (int argc, const char * argv[]) {
|
||||
// send hci reset
|
||||
uint8_t len;
|
||||
hci_create_cmd_packet( buffer, &len, &hci_reset);
|
||||
transport->send_cmd_packet( buffer, len );
|
||||
dump_cmd( buffer, len);
|
||||
hci_send_cmd_packet( buffer, len );
|
||||
|
||||
//
|
||||
fd_set descriptors;
|
||||
|
Loading…
x
Reference in New Issue
Block a user