Просмотр исходного кода

Remove hardcoded limit from search_coherent_signal().

antirez 3 лет назад
Родитель
Сommit
705cbd1d95
2 измененных файлов с 13 добавлено и 5 удалено
  1. 12 4
      protocols/pvchat.c
  2. 1 1
      signal.c

+ 12 - 4
protocols/pvchat.c

@@ -76,7 +76,10 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     for (j = 0; j < sizeof(raw)-2; j++)
         if (raw[j] == 0xff && raw[j+1] == 0xaa) break;
 
-    if (j == sizeof(raw)-1) return false; // No terminator found.
+    if (j == sizeof(raw)-1) {
+        FURI_LOG_E(TAG, "Chat: terminator not found");
+        return false; // No terminator found.
+    }
 
     uint32_t datalen = j+3; // If the terminator was found at j, then
                             // we need to sum three more bytes to have
@@ -84,11 +87,17 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     info->pulses_count = 8*3*datalen;
 
     // Check if the control sum matches.
-    if (sum_bytes(raw,datalen-1,0) != raw[datalen-1]) return false;
+    if (sum_bytes(raw,datalen-1,0) != raw[datalen-1]) {
+        FURI_LOG_E(TAG, "Chat: checksum mismatch");
+        return false;
+    }
 
     // Check if the length of the sender looks sane
     uint8_t senderlen = raw[0];
-    if (senderlen >= sizeof(raw)) return false; // Overflow
+    if (senderlen >= sizeof(raw)) {
+        FURI_LOG_E(TAG, "Chat: invalid sender length");
+        return false; // Overflow
+    }
 
     fieldset_add_str(info->fieldset,"sender",(char*)raw+1,senderlen);
     fieldset_add_str(info->fieldset,"message",(char*)raw+1+senderlen,
@@ -133,7 +142,6 @@ static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fs)
     *p++ = 0xff;
     *p++ = 0xaa;
     *p = sum_bytes(data,datalen-1,0);
-    FURI_LOG_E(TAG,"SUM: %lu", (unsigned long)*p);
 
     // Emit bits
     for (uint32_t j = 0; j < datalen*8; j++) {

+ 1 - 1
signal.c

@@ -55,7 +55,7 @@ uint32_t search_coherent_signal(RawSamplesBuffer *s, uint32_t idx, uint32_t min_
 
     uint32_t len = 0; /* Observed len of coherent samples. */
     s->short_pulse_dur = 0;
-    for (uint32_t j = idx; j < idx+500; j++) {
+    for (uint32_t j = idx; j < idx+s->total; j++) {
         bool level;
         uint32_t dur;
         raw_samples_get(s, j, &level, &dur);