This commit is contained in:
matthias.ringwald 2009-05-09 17:45:45 +00:00
parent 56fe0872e0
commit 554588a5c7
4 changed files with 17 additions and 46 deletions

View File

@ -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':

View File

@ -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;

View File

@ -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;

View File

@ -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;