Browse Source

Filter out double NEXA UDP-msg.

Thomas Chef 4 năm trước cách đây
mục cha
commit
e0fb6efc92
2 tập tin đã thay đổi với 16 bổ sung2 xóa
  1. 2 2
      main/main.c
  2. 14 0
      main/nexaTransmit.c

+ 2 - 2
main/main.c

@@ -78,11 +78,11 @@ void app_main(void)
 
         if( c == '0' ) {
             //sendNexaCode(0x1B5C1DA0);
-            sendNexaCode(0x2A37C840);
+            sendNexaCode(0x2A37C840,false,0);
         }
         if( c == '1' ) {
             //sendNexaCode(0x1B5C1DB0);
-            sendNexaCode(0x2A37C850);   // Volvo: ON
+            sendNexaCode(0x2A37C850,false,0);   // Volvo: ON
         }
     }
 }

+ 14 - 0
main/nexaTransmit.c

@@ -158,6 +158,20 @@ void sendNexaCode(uint32_t data, bool send_dim, uint8_t dim_level ) {
 // Public interface for sending a NEXA Code in string format. For example: <NT4C90AD91>
 void sendNexaCodeStr(char *str) {
 
+    const uint32_t now = millis();
+    static char oldData[40];
+    static uint32_t oldDataTime = 0;
+
+    // Check if we have a retransmission of exactly the same data within 250mS
+    // If we have a identical re-transmission, then skip that one
+    if( ((now - oldDataTime) < 250) && strncmp(str,oldData,40)==0 ) {
+        ESP_LOGW("NEXA TX", "Retransm: %10d mS",now - oldDataTime);
+        oldDataTime = now;
+        return;
+    }
+    strncpy(oldData,str,40);
+    oldDataTime = now;
+
     char diffLevel = '\0';   // 0-F = 0-15 Dim-level
 
     if( strlen(str) == 13 && str[0] == '<' && str[12] == '>' ) {