فهرست منبع

Only haptic once for up to 5 readers

Eric Betts 10 ماه پیش
والد
کامیت
6c3bd85ed6
2فایلهای تغییر یافته به همراه55 افزوده شده و 7 حذف شده
  1. 44 6
      seos_hci.c
  2. 11 1
      seos_hci.h

+ 44 - 6
seos_hci.c

@@ -75,6 +75,14 @@ void seos_hci_timer(void* context) {
     }
 }
 
+void seos_hci_clear_known_addresses(SeosHci* seos_hci) {
+    for(size_t i = 0; i < MAX_SCANNED_ADDRESS; i++) {
+        ScanAddress* scan_address = &seos_hci->scanned_addresses[i];
+        scan_address->used = false;
+        memset(scan_address->address, 0, MAC_ADDRESS_LEN);
+    }
+}
+
 SeosHci* seos_hci_alloc(Seos* seos) {
     SeosHci* seos_hci = malloc(sizeof(SeosHci));
     memset(seos_hci, 0, sizeof(SeosHci));
@@ -88,6 +96,8 @@ SeosHci* seos_hci_alloc(Seos* seos) {
     seos_hci_h5_set_init_callback(seos_hci->seos_hci_h5, seos_hci_init, seos_hci);
     seos_hci_h5_set_receive_callback(seos_hci->seos_hci_h5, seos_hci_recv, seos_hci);
 
+    seos_hci_clear_known_addresses(seos_hci);
+
     return seos_hci;
 }
 
@@ -139,6 +149,32 @@ void seos_hci_stop(SeosHci* seos_hci) {
         FURI_LOG_D(TAG, "clear timer");
         furi_timer_stop(seos_hci->timer);
     }
+    seos_hci_clear_known_addresses(seos_hci);
+}
+
+bool seos_hci_known_address(SeosHci* seos_hci, const uint8_t Address[MAC_ADDRESS_LEN]) {
+    // Does it exist in the list?
+    for(size_t i = 0; i < MAX_SCANNED_ADDRESS; i++) {
+        ScanAddress* scan_address = &seos_hci->scanned_addresses[i];
+        if(scan_address->used) {
+            if(memcmp(Address, scan_address->address, MAC_ADDRESS_LEN) == 0) {
+                return true;
+            }
+        }
+    }
+
+    // Not in list, add
+    for(size_t i = 0; i < MAX_SCANNED_ADDRESS; i++) {
+        ScanAddress* scan_address = &seos_hci->scanned_addresses[i];
+        if(!scan_address->used) {
+            memcpy(scan_address->address, Address, MAC_ADDRESS_LEN);
+            scan_address->used = true;
+            // It wasn't previously known
+            return false;
+        }
+    }
+
+    return false;
 }
 
 void seos_hci_handle_event_cmd_complete_ogf_host(SeosHci* seos_hci, uint16_t OCF, BitBuffer* frame) {
@@ -584,9 +620,10 @@ void seos_hci_handle_event_le_meta(SeosHci* seos_hci, BitBuffer* frame) {
                            val,
                            seos_reader_service_backwards,
                            sizeof(seos_reader_service_backwards)) == 0) {
-                        // TODO: handle duplicates
-                        notification_message(
-                            seos_hci->seos->notifications, &sequence_single_vibro);
+                        if(!seos_hci_known_address(seos_hci, Address)) {
+                            notification_message(
+                                seos_hci->seos->notifications, &sequence_single_vibro);
+                        }
                     }
                 } else if(seos_hci->flow_mode == FLOW_CRED_SCANNER) {
                     // Cred scanner looks for devices advertising credential service, it doesn't act like a credential (as in FLOW_CRED)
@@ -594,9 +631,10 @@ void seos_hci_handle_event_le_meta(SeosHci* seos_hci, BitBuffer* frame) {
                            val,
                            seos_cred_service_backwards,
                            sizeof(seos_cred_service_backwards)) == 0) {
-                        // TODO: handle duplicates
-                        notification_message(
-                            seos_hci->seos->notifications, &sequence_single_vibro);
+                        if(!seos_hci_known_address(seos_hci, Address)) {
+                            notification_message(
+                                seos_hci->seos->notifications, &sequence_single_vibro);
+                        }
                     }
                 }
                 break;

+ 11 - 1
seos_hci.h

@@ -4,12 +4,20 @@
 #include "seos_hci_h5.h"
 #include "seos_common.h"
 
+#define MAC_ADDRESS_LEN     6
+#define MAX_SCANNED_ADDRESS 5
+
 typedef void (
     *SeosHciReceiveCallback)(void* context, uint16_t handle, uint8_t flags, BitBuffer* pdu);
 
 typedef void (*SeosHciCompletedPacketsCallback)(void* context);
 typedef void (*SeosHciCentralConnectionCallback)(void* context);
 
+typedef struct {
+    uint8_t address[MAC_ADDRESS_LEN];
+    bool used;
+} ScanAddress;
+
 typedef struct {
     Seos* seos;
     SeosHciH5* seos_hci_h5;
@@ -30,13 +38,15 @@ typedef struct {
 
     bool scan_status;
     bool adv_status;
-    uint8_t address[6];
+    uint8_t address[MAC_ADDRESS_LEN];
     uint8_t address_type;
 
     size_t adv_report_count;
     bool device_found;
 
     FuriTimer* timer;
+
+    ScanAddress scanned_addresses[MAX_SCANNED_ADDRESS];
 } SeosHci;
 
 SeosHci* seos_hci_alloc(Seos* seos);