travis fix and scan on channel 37,38 & 39
bool isDetected(void);
bool listFull(void);
-bool validAdType(int);
+bool validAdType(unsigned char);
void printList(void);
#define BUF_SIZE 39
@@ -26,14 +26,14 @@ struct Vector {
unsigned char scan[BUF_SIZE] = { 0 };
unsigned char* data[MAX_DEVICES] = { 0 };
int last = 0;
-struct Vector scan_list = {.data = &data[0], .size = 0};
+struct Vector scan_list = {.data = (unsigned char (*)[BUF_SIZE])data, .size = 0 };
static void callback(__attribute__((unused)) int unused0,
- __attribute__((unused)) int unused1,
- __attribute__((unused)) int unused2,
- __attribute__((unused)) void* ud) {
+ __attribute__((unused)) int unused1, __attribute__((unused)) int unused2,
+ __attribute__((unused)) void* ud)
+{
- if (!listFull() && validAdType(scan[0]) && !isDetected()) {
+ if (!listFull() && validAdType(scan[8]) && !isDetected()) {
memcpy(scan_list.data[scan_list.size], scan, BUF_SIZE);
scan_list.size += 1;
}
@@ -47,7 +47,7 @@ int main(void)
{
int err;
- printf("BLE Scanner\r\n");
+ printf("\rBLE Scanner\r\n\n");
// using the pre-configured adv interval
err = ble_adv_scan(scan, BUF_SIZE, callback);
@@ -58,7 +58,8 @@ int main(void)
return 0;
}
-bool isDetected(void) {
+bool isDetected(void)
+{
for (int i = 0; i < scan_list.size; i++) {
if (memcmp(scan_list.data[i], scan, BUF_SIZE) == 0) {
return true;
@@ -67,19 +68,24 @@ bool isDetected(void) {
return false;
}
-void printList(void) {
- printf("--------SCANNING--------------------------------------------\r\n");
+void printList(void)
+{
+ printf("--------DETECTED DEVICES--------------------------------------------\r\n");
for (int i = 0; i < scan_list.size; i++) {
- printf("DEVICE #%d\r\n", i);
- for (int j = 0; j < BUF_SIZE; j++) {
+ printf("DEVICE ADDRESS: %02x %02x %02x %02x %02x %02x %02x %02x\r\n",
+ scan_list.data[i][7], scan_list.data[i][6], scan_list.data[i][5],
+ scan_list.data[i][4], scan_list.data[i][3], scan_list.data[i][2],
+ scan_list.data[i][1], scan_list.data[i][0]);
+ printf("DATA: ");
+ for (int j = 8; j < BUF_SIZE; j++) {
printf("%02x ", scan_list.data[i][j]);
}
- printf("\r\n");
+ printf("\r\n\n");
}
- printf("----------END------------------------------------------------\r\n\n");
+ printf("---------------------------------------------------------------------\r\n\n");
}
-bool validAdType(int type) {
+bool validAdType(unsigned char type) {
return type <= 0x06;
}
