Skip to content

Commit

Permalink
b4b1: more robust message detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Jan 25, 2023
1 parent 32b3f76 commit cc32c5e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions protocols/b4b1.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@

static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
if (numbits < 30) return false;
const char *sync_patterns[3] = {
"10000000000000000000000000000001", /* 30 zero bits. */
"100000000000000000000000000000001", /* 31 zero bits. */
"1000000000000000000000000000000001", /* 32 zero bits. */

/* Test different pulse + gap + first byte possibilities. */
const char *sync_patterns[6] = {
"100000000000000000000000000000011101", /* 30 times gap + one. */
"100000000000000000000000000000010001", /* 30 times gap + zero. */
"1000000000000000000000000000000011101", /* 31 times gap + one. */
"1000000000000000000000000000000010001", /* 31 times gap + zero. */
"10000000000000000000000000000000011101", /* 32 times gap + one. */
"10000000000000000000000000000000010001", /* 32 times gap + zero. */
};

uint32_t off;
Expand All @@ -24,11 +29,11 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
if (off != BITMAP_SEEK_NOT_FOUND) break;
}
if (off == BITMAP_SEEK_NOT_FOUND) return false;
if (DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 preamble at: %lu",off);
if (DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 preamble id:%d at: %lu",j,off);
info->start_off = off;

// Seek data setction. Why -1? Last bit is data.
off += strlen(sync_patterns[j])-1;
// Seek data setction. Why -5? Last 5 half-bit-times are data.
off += strlen(sync_patterns[j])-5;

uint8_t d[3]; /* 24 bits of data. */
uint32_t decoded =
Expand Down

0 comments on commit cc32c5e

Please sign in to comment.