Skip to content

Commit

Permalink
Store bits in the same order they are received.
Browse files Browse the repository at this point in the history
This makes everything more natural. No bit inversion usually
needed. Raw data matches what we see on the wire.
  • Loading branch information
antirez committed Jan 4, 2023
1 parent a5f3ce4 commit 341ceda
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion protocols/b4b1.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView

if (DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 decoded: %lu",decoded);
if (decoded != 24) return false;
bitmap_invert_bytes_bits(d,sizeof(d));
snprintf(info->name,PROTOVIEW_MSG_STR_LEN,"PT/SC remote");
snprintf(info->raw,PROTOVIEW_MSG_STR_LEN,"%02X%02X%02X",d[0],d[1],d[2]);
info->len = off+(4*24);
Expand Down
16 changes: 9 additions & 7 deletions protocols/oregon2.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView

off += 32; /* Skip preamble. */

uint8_t buffer[8];
uint8_t buffer[8], raw[8] = {0};
uint32_t decoded =
convert_from_line_code(buffer,sizeof(buffer),bits,numbytes,off,"1001","0110");
FURI_LOG_E(TAG, "Oregon2 decoded bits: %lu", decoded);
Expand All @@ -19,12 +19,12 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
char temp[3] = {0}, deviceid[2] = {0}, hum[2] = {0};
for (int j = 0; j < 64; j += 4) {
uint8_t nib[1];
nib[0] = 0;
bitmap_set(nib,1,0,bitmap_get(buffer,8,j+0));
bitmap_set(nib,1,1,bitmap_get(buffer,8,j+1));
bitmap_set(nib,1,2,bitmap_get(buffer,8,j+2));
bitmap_set(nib,1,3,bitmap_get(buffer,8,j+3));
nib[0] = (bitmap_get(buffer,8,j+0) |
bitmap_get(buffer,8,j+1) << 1 |
bitmap_get(buffer,8,j+2) << 2 |
bitmap_get(buffer,8,j+3) << 3);
FURI_LOG_E(TAG, "Not inverted nibble[%d]: %x", j/4, (unsigned int)nib[0]);
raw[j/8] |= nib[0] << (4-(j%4));
switch(j/4) {
case 1: deviceid[0] |= nib[0]; break;
case 0: deviceid[0] |= nib[0] << 4; break;
Expand All @@ -42,7 +42,9 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
snprintf(info->name,sizeof(info->name),"%s","Oregon v2.1");
/* The following line crashes the Flipper because of broken
* snprintf() implementation. */
if (0) snprintf(info->raw,sizeof(info->raw),"%08llX", *((uint64_t*)buffer));
snprintf(info->raw,sizeof(info->raw),"%02X%02X%02X%02X%02X%02X%02X%02X",
raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
raw[6],raw[7]);
snprintf(info->info1,sizeof(info->info1),"Sensor ID %02X%02X",
deviceid[0], deviceid[1]);
snprintf(info->info2,sizeof(info->info2),"Temperature %d%d.%d",
Expand Down
4 changes: 2 additions & 2 deletions signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void scan_for_signal(ProtoViewApp *app) {
* Out of range bits will silently be discarded. */
void bitmap_set(uint8_t *b, uint32_t blen, uint32_t bitpos, bool val) {
uint32_t byte = bitpos/8;
uint32_t bit = bitpos&7;
uint32_t bit = 7-(bitpos&7);
if (byte >= blen) return;
if (val)
b[byte] |= 1<<bit;
Expand All @@ -200,7 +200,7 @@ void bitmap_set(uint8_t *b, uint32_t blen, uint32_t bitpos, bool val) {
* Out of range bits return false (not bit set). */
bool bitmap_get(uint8_t *b, uint32_t blen, uint32_t bitpos) {
uint32_t byte = bitpos/8;
uint32_t bit = bitpos&7;
uint32_t bit = 7-(bitpos&7);
if (byte >= blen) return 0;
return (b[byte] & (1<<bit)) != 0;
}
Expand Down

0 comments on commit 341ceda

Please sign in to comment.