antirez 3 лет назад
Родитель
Сommit
be293ca5c3
5 измененных файлов с 12 добавлено и 10 удалено
  1. 1 1
      app.h
  2. 1 1
      protocols/b4b1.c
  3. 1 1
      protocols/oregon2.c
  4. 1 1
      protocols/renault_tpms.c
  5. 8 6
      signal.c

+ 1 - 1
app.h

@@ -139,7 +139,7 @@ void bitmap_set(uint8_t *b, uint32_t blen, uint32_t bitpos, bool val);
 void bitmap_set_pattern(uint8_t *b, uint32_t blen, const char *pat);
 void bitmap_invert_bytes_bits(uint8_t *p, uint32_t len);
 bool bitmap_match_bits(uint8_t *b, uint32_t blen, uint32_t bitpos, const char *bits);
-uint32_t bitmap_seek_bits(uint8_t *b, uint32_t blen, uint32_t startpos, const char *bits);
+uint32_t bitmap_seek_bits(uint8_t *b, uint32_t blen, uint32_t startpos, uint32_t maxbits, const char *bits);
 uint32_t convert_from_line_code(uint8_t *buf, uint64_t buflen, uint8_t *bits, uint32_t len, uint32_t offset, const char *zero_pattern, const char *one_pattern);
 
 /* view_*.c */

+ 1 - 1
protocols/b4b1.c

@@ -20,7 +20,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     uint32_t off;
     int j;
     for (j = 0; j < 3; j++) {
-        off = bitmap_seek_bits(bits,numbytes,0,sync_patterns[j]);
+        off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_patterns[j]);
         if (off != BITMAP_SEEK_NOT_FOUND) break;
     }
     if (off == BITMAP_SEEK_NOT_FOUND) return false;

+ 1 - 1
protocols/oregon2.c

@@ -9,7 +9,7 @@
 static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
     if (numbits < 32) return false;
     const char *sync_pattern = "01100110" "01100110" "10010110" "10010110";
-    uint64_t off = bitmap_seek_bits(bits,numbytes,0,sync_pattern);
+    uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
     if (off == BITMAP_SEEK_NOT_FOUND) return false;
     FURI_LOG_E(TAG, "Oregon2 preamble+sync found");
 

+ 1 - 1
protocols/renault_tpms.c

@@ -32,7 +32,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     if (numbits < 13*8) return false;
 
     const char *sync_pattern = "10101010" "10101010" "10101010" "10101001";
-    uint64_t off = bitmap_seek_bits(bits,numbytes,0,sync_pattern);
+    uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
     if (off == BITMAP_SEEK_NOT_FOUND) return false;
     FURI_LOG_E(TAG, "Renault TPMS preamble+sync found");
 

+ 8 - 6
signal.c

@@ -222,8 +222,7 @@ void bitmap_invert_bytes_bits(uint8_t *p, uint32_t len) {
  * form "11010110..." is found in the 'b' bitmap of 'blen' bits at 'bitpos'
  * position. */
 bool bitmap_match_bits(uint8_t *b, uint32_t blen, uint32_t bitpos, const char *bits) {
-    size_t l = strlen(bits);
-    for (size_t j = 0; j < l; j++) {
+    for (size_t j = 0; bits[j]; j++) {
         bool expected = (bits[j] == '1') ? true : false;
         if (bitmap_get(b,blen,bitpos+j) != expected) return false;
     }
@@ -231,14 +230,17 @@ bool bitmap_match_bits(uint8_t *b, uint32_t blen, uint32_t bitpos, const char *b
 }
 
 /* Search for the specified bit sequence (see bitmap_match_bits() for details)
- * in the bitmap 'b' of 'blen' bytes. Returns the offset (in bits) of the
- * match, or BITMAP_SEEK_NOT_FOUND if not found.
+ * in the bitmap 'b' of 'blen' bytes, looking forward at most 'maxbits' ahead.
+ * Returns the offset (in bits) of the match, or BITMAP_SEEK_NOT_FOUND if not
+ * found.
  *
  * Note: there are better algorithms, such as Boyer-Moore. Here we hope that
  * for the kind of patterns we search we'll have a lot of early stops so
  * we use a vanilla approach. */
-uint32_t bitmap_seek_bits(uint8_t *b, uint32_t blen, uint32_t startpos, const char *bits) {
-    uint32_t endpos = blen*8;
+uint32_t bitmap_seek_bits(uint8_t *b, uint32_t blen, uint32_t startpos, uint32_t maxbits, const char *bits) {
+    uint32_t endpos = startpos+blen*8;
+    uint32_t end2 = startpos+maxbits;
+    if (end2 < endpos) endpos = end2;
     for (uint32_t j = startpos; j < endpos; j++)
         if (bitmap_match_bits(b,blen,j,bits)) return j;
     return BITMAP_SEEK_NOT_FOUND;