This commit is contained in:
matthias.ringwald 2009-11-07 17:00:21 +00:00
parent 04611bcdb1
commit 559c26db5f

View File

@ -67,27 +67,18 @@ int getDeviceIndexForAddress( bd_addr_t addr){
} }
void next(){ void next(){
switch (state) {
int i; int i;
int found = 0; int found = 0;
switch (state) {
case 0: case 0:
printf("Starting inquiry scan..\n"); printf("Starting inquiry scan..\n");
bt_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, INQUIRY_INTERVAL, 0); bt_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, INQUIRY_INTERVAL, 0);
state++; state = 1;
break; break;
case 1: case 1:
printf("Inquiry scan done.\n");
for (i=0;i<MAX_DEVICES;i++) {
// retry remote name request
if (devices[i].state == 2) devices[i].state = 1;
}
state++;
next();
break;
case 2:
for (i=0;i<deviceCount;i++) { for (i=0;i<deviceCount;i++) {
// remote name request // remote name request
if (devices[i].state == 1){ if (devices[i].state == 1){
@ -102,6 +93,7 @@ void next(){
} }
} }
if (!found) { if (!found) {
printf("Queried all devices, restart.\n");
state = 0; state = 0;
next(); next();
} }
@ -114,6 +106,8 @@ void next(){
void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
bd_addr_t addr; bd_addr_t addr;
int i;
int numResponses;
switch (packet_type){ switch (packet_type){
@ -130,9 +124,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
case HCI_EVENT_INQUIRY_RESULT: case HCI_EVENT_INQUIRY_RESULT:
case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI: case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI:
{ numResponses = packet[2];
int numResponses = packet[2];
int i;
for (i=0; i<numResponses && deviceCount < MAX_DEVICES;i++){ for (i=0; i<numResponses && deviceCount < MAX_DEVICES;i++){
bt_flip_addr(addr, &packet[3+i*6]); bt_flip_addr(addr, &packet[3+i*6]);
int index = getDeviceIndexForAddress(addr); int index = getDeviceIndexForAddress(addr);
@ -149,7 +141,6 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
deviceCount++; deviceCount++;
} }
break; break;
}
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE: case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
bt_flip_addr(addr, &packet[3]); bt_flip_addr(addr, &packet[3]);
@ -166,6 +157,12 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
break; break;
case HCI_EVENT_INQUIRY_COMPLETE: case HCI_EVENT_INQUIRY_COMPLETE:
printf("Inquiry scan done.\n");
for (i=0;i<deviceCount;i++) {
// retry remote name request
if (devices[i].state == 2)
devices[i].state = 1;
}
next(); next();
break; break;