antirez 3 лет назад
Родитель
Сommit
9352b0b6ea
2 измененных файлов с 32 добавлено и 9 удалено
  1. 28 6
      protocols/unknown.c
  2. 4 3
      signal.c

+ 28 - 6
protocols/unknown.c

@@ -49,6 +49,7 @@ static uint32_t find_pwm(uint8_t *bits, uint32_t numbytes, uint32_t numbits,
      * Anyway at the end of the function we try to fix the sync. */
     for (uint32_t off = 0; off < symlen; off++) {
         uint32_t c = 0; // Number of contiguous symbols found.
+        uint32_t c1 = 0, c2 = 0; // Occurrences of first/second symbol.
         *s1i = off;     // Assume we start at one symbol boundaty.
         *s2i = UINT32_MAX; // Second symbol first index still unknown.
         uint32_t next = off;
@@ -74,7 +75,12 @@ static uint32_t find_pwm(uint8_t *bits, uint32_t numbytes, uint32_t numbits,
             /* One or the other should match. */
             if (match1 || match2) {
                 c++;
-                if (c > best_count) {
+                if (match1) c1++;
+                if (match2) c2++;
+                if (c > best_count &&
+                    c1 >= best_count/5 && // Require enough presence of both
+                    c2 >= best_count/5)   // zero and one.
+                {
                     best_count = c;
                     best_idx1 = *s1i;
                     best_idx2 = *s2i;
@@ -83,6 +89,8 @@ static uint32_t find_pwm(uint8_t *bits, uint32_t numbytes, uint32_t numbits,
             } else {
                 /* No match. Continue resetting the signal info. */
                 c = 0; // Start again to count contiguous symbols.
+                c1 = 0;
+                c2 = 0;
                 *s1i = next; // First symbol always at start.
                 *s2i = UINT32_MAX; // Second symbol unknown.
             }
@@ -244,7 +252,8 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     {
         linecode = LineCodeManchester;
         start1 = tmp1;
-        msgbits = pwm3_bits*2;
+        msgbits = manchester_bits*2;
+        FURI_LOG_E(TAG, "MANCHESTER START: %lu", tmp1);
     }
 
     if (linecode == LineCodeNone) return false;
@@ -255,9 +264,13 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     uint32_t preamble_len = find_preamble(bits,numbytes,numbits,&tmp1);
     uint32_t min_preamble_len = 10;
     uint32_t max_preamble_distance = 32;
-    uint32_t preamble_start;
+    uint32_t preamble_start = 0;
     bool preamble_found = false;
 
+    /* Note that because of the following checks, if the Manchester detector
+     * detected the preamble bits as data, we are ok with that, since it
+     * means that the synchronization is not designed to "break" the bits
+     * flow. In this case we ignore the preamble and return all as data. */
     if (preamble_len >= min_preamble_len &&     // Not too short.
         tmp1 < start1 &&                        // Should be before the data.
         start1-tmp1 <= max_preamble_distance)   // Not too far.
@@ -273,6 +286,13 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
                                * transfer all that is needed, like a message
                                * terminator (that we don't detect). */
 
+    if (preamble_found)
+        FURI_LOG_E(TAG, "PREAMBLE AT: %lu", preamble_start);
+    FURI_LOG_E(TAG, "START: %lu", info->start_off);
+    FURI_LOG_E(TAG, "MSGBITS: %lu", msgbits);
+    FURI_LOG_E(TAG, "DATASTART: %lu", start1);
+    FURI_LOG_E(TAG, "PULSES: %lu", info->pulses_count);
+
     /* We think there is a message and we know where it starts and the
      * line code used. We can turn it into bits and bytes. */
     uint32_t decoded;
@@ -293,11 +313,13 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     datalen = (decoded+7)/8;
     
     char *linecode_name = get_linecode_name(linecode);
-    fieldset_add_str(info->fieldset,"line code",linecode_name,strlen(linecode_name));
-    fieldset_add_uint(info->fieldset,"preamble len",preamble_len,8);
+    fieldset_add_str(info->fieldset,"line code",
+                     linecode_name,strlen(linecode_name));
+    fieldset_add_uint(info->fieldset,"data bits",decoded,8);
+    if (preamble_found)
+        fieldset_add_uint(info->fieldset,"preamble len",preamble_len,8);
     fieldset_add_str(info->fieldset,"first symbol",symbol1,strlen(symbol1));
     fieldset_add_str(info->fieldset,"second symbol",symbol2,strlen(symbol2));
-    fieldset_add_uint(info->fieldset,"data bits",decoded,8);
     for (uint32_t j = 0; j < datalen; j++) {
         char label[16];
         snprintf(label,sizeof(label),"data[%lu]",j);

+ 4 - 3
signal.c

@@ -229,11 +229,12 @@ void scan_for_signal(ProtoViewApp *app, RawSamplesBuffer *source, uint32_t min_d
             /* Accept this signal as the new signal if either it's longer
              * than the previous undecoded one, or the previous one was
              * unknown and this is decoded. */
-            bool current_not_decoded = app->signal_decoded == false ||
+            bool oldsignal_not_decoded = app->signal_decoded == false ||
                                app->msg_info->decoder == &UnknownDecoder;
 
-            if (current_not_decoded &&
-                (thislen > app->signal_bestlen || decoded))
+            if (oldsignal_not_decoded &&
+                (thislen > app->signal_bestlen ||
+                 (decoded && info->decoder != &UnknownDecoder)))
             {
                 free_msg_info(app->msg_info);
                 app->msg_info = info;