mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-29 04:09:58 -07:00
updated protoview
This commit is contained in:
@@ -25,6 +25,9 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
}
|
||||
if (off == BITMAP_SEEK_NOT_FOUND) return false;
|
||||
if (DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 preamble at: %lu",off);
|
||||
info->start_off = off;
|
||||
|
||||
// Seek data setction. Why -1? Last bit is data.
|
||||
off += strlen(sync_patterns[j])-1;
|
||||
|
||||
uint8_t d[3]; /* 24 bits of data. */
|
||||
@@ -32,13 +35,54 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
convert_from_line_code(d,sizeof(d),bits,numbytes,off,"1000","1110");
|
||||
|
||||
if (DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 decoded: %lu",decoded);
|
||||
if (decoded != 24) return false;
|
||||
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);
|
||||
if (decoded < 24) return false;
|
||||
|
||||
off += 24*4; // seek to end symbol offset to calculate the length.
|
||||
off++; // In this protocol there is a final pulse as terminator.
|
||||
info->pulses_count = off - info->start_off;
|
||||
|
||||
fieldset_add_bytes(info->fieldset,"id",d,5);
|
||||
fieldset_add_uint(info->fieldset,"button",d[2]&0xf,4);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Give fields and defaults for the signal creator. */
|
||||
static void get_fields(ProtoViewFieldSet *fieldset) {
|
||||
uint8_t default_id[3]= {0xAB, 0xCD, 0xE0};
|
||||
fieldset_add_bytes(fieldset,"id",default_id,5);
|
||||
fieldset_add_uint(fieldset,"button",1,4);
|
||||
}
|
||||
|
||||
/* Create a signal. */
|
||||
static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fs)
|
||||
{
|
||||
uint32_t te = 334; // Short pulse duration in microseconds.
|
||||
|
||||
// Sync: 1 te pulse, 31 te gap.
|
||||
raw_samples_add(samples,true,te);
|
||||
raw_samples_add(samples,false,te*31);
|
||||
|
||||
// ID + button state
|
||||
uint8_t data[3];
|
||||
memcpy(data,fs->fields[0]->bytes,3);
|
||||
data[2] = (data[2]&0xF0) | (fs->fields[1]->uvalue & 0xF);
|
||||
for (uint32_t j = 0; j < 24; j++) {
|
||||
if (bitmap_get(data,sizeof(data),j)) {
|
||||
raw_samples_add(samples,true,te*3);
|
||||
raw_samples_add(samples,false,te);
|
||||
} else {
|
||||
raw_samples_add(samples,true,te);
|
||||
raw_samples_add(samples,false,te*3);
|
||||
}
|
||||
}
|
||||
|
||||
// Signal terminator. Just a single short pulse.
|
||||
raw_samples_add(samples,true,te);
|
||||
}
|
||||
|
||||
ProtoViewDecoder B4B1Decoder = {
|
||||
"B4B1", decode
|
||||
.name = "PT/SC remote",
|
||||
.decode = decode,
|
||||
.get_fields = get_fields,
|
||||
.build_message = build_message
|
||||
};
|
||||
|
||||
@@ -32,9 +32,11 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
const char *sync_pattern = "101010101010101010101010" "0000";
|
||||
uint8_t sync_len = 24+4;
|
||||
if (numbits-sync_len+sync_len < 3*66) return false;
|
||||
uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
|
||||
uint32_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
|
||||
if (off == BITMAP_SEEK_NOT_FOUND) return false;
|
||||
off += sync_len;
|
||||
|
||||
info->start_off = off;
|
||||
off += sync_len; // Seek start of message.
|
||||
|
||||
/* Now there is half the gap left, but we allow from 3 to 7, instead of 5
|
||||
* symbols of gap, to avoid missing the signal for a matter of wrong
|
||||
@@ -52,36 +54,72 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
|
||||
"110","100"); /* Pulse width modulation. */
|
||||
FURI_LOG_E(TAG, "Keeloq decoded bits: %lu", decoded);
|
||||
|
||||
if (decoded < 66) return false; /* Require the full 66 bits. */
|
||||
bitmap_reverse_bytes(raw,sizeof(raw)); /* Keeloq is LSB first. */
|
||||
|
||||
info->pulses_count = (off+66*3) - info->start_off;
|
||||
|
||||
bitmap_reverse_bytes_bits(raw,sizeof(raw)); /* Keeloq is LSB first. */
|
||||
|
||||
int buttons = raw[7]>>4;
|
||||
int s3 = (buttons&1) != 0;
|
||||
int s0 = (buttons&2) != 0;
|
||||
int s1 = (buttons&4) != 0;
|
||||
int s2 = (buttons&8) != 0;
|
||||
int lowbat = (raw[8]&0x1) == 0; // Actual bit meaning: good battery level
|
||||
int alwaysone = (raw[8]&0x2) != 0;
|
||||
|
||||
int remote_id = ((raw[7]&0x0f) << 24) |
|
||||
(raw[6] << 16) |
|
||||
(raw[5] << 8) |
|
||||
(raw[4] << 0);
|
||||
int lowbat = raw[8]&0x80;
|
||||
|
||||
snprintf(info->name,sizeof(info->name),"%s","Keeloq remote");
|
||||
snprintf(info->raw,sizeof(info->raw),"%02X%02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
|
||||
raw[6],raw[7],raw[8]);
|
||||
snprintf(info->info1,sizeof(info->info1),"Encrpyted %02X%02X%02X%02X",
|
||||
raw[3],raw[2],raw[1],raw[0]);
|
||||
snprintf(info->info2,sizeof(info->info2),"ID %08X", remote_id);
|
||||
snprintf(info->info3,sizeof(info->info3),"s0-s3: %d%d%d%d",
|
||||
s0,s1,s2,s3);
|
||||
snprintf(info->info4,sizeof(info->info4),"Low battery? %s",
|
||||
lowbat ? "yes" : "no");
|
||||
fieldset_add_bytes(info->fieldset,"encr",raw,8);
|
||||
raw[7] = raw[7]<<4; // Make ID bits contiguous
|
||||
fieldset_add_bytes(info->fieldset,"id",raw+4,7); // 28 bits, 7 nibbles
|
||||
fieldset_add_bin(info->fieldset,"s[2,1,0,3]",buttons,4);
|
||||
fieldset_add_bin(info->fieldset,"low battery",lowbat,1);
|
||||
fieldset_add_bin(info->fieldset,"always one",alwaysone,1);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void get_fields(ProtoViewFieldSet *fieldset) {
|
||||
uint8_t remote_id[4] = {0xab, 0xcd, 0xef, 0xa0};
|
||||
uint8_t encr[4] = {0xab, 0xab, 0xab, 0xab};
|
||||
fieldset_add_bytes(fieldset,"encr",encr,8);
|
||||
fieldset_add_bytes(fieldset,"id",remote_id,7);
|
||||
fieldset_add_bin(fieldset,"s[2,1,0,3]",2,4);
|
||||
fieldset_add_bin(fieldset,"low battery",0,1);
|
||||
fieldset_add_bin(fieldset,"always one",1,1);
|
||||
}
|
||||
|
||||
static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fieldset)
|
||||
{
|
||||
uint32_t te = 380; // Short pulse duration in microseconds.
|
||||
|
||||
// Sync: 12 pairs of pulse/gap + 9 times gap
|
||||
for (int j = 0; j < 12; j++) {
|
||||
raw_samples_add(samples,true,te);
|
||||
raw_samples_add(samples,false,te);
|
||||
}
|
||||
raw_samples_add(samples,false,te*9);
|
||||
|
||||
// Data, 66 bits.
|
||||
uint8_t data[9] = {0};
|
||||
memcpy(data,fieldset->fields[0]->bytes,4); // Encrypted part.
|
||||
memcpy(data+4,fieldset->fields[1]->bytes,4); // ID.
|
||||
data[7] = data[7]>>4 | fieldset->fields[2]->uvalue << 4; // s[2,1,0,3]
|
||||
int low_battery = fieldset->fields[3] != 0;
|
||||
int always_one = fieldset->fields[4] != 0;
|
||||
low_battery = !low_battery; // Bit real meaning is good battery level.
|
||||
data[8] |= low_battery;
|
||||
data[8] |= (always_one << 1);
|
||||
bitmap_reverse_bytes_bits(data,sizeof(data)); /* Keeloq is LSB first. */
|
||||
|
||||
for (int j = 0; j < 66; j++) {
|
||||
if (bitmap_get(data,9,j)) {
|
||||
raw_samples_add(samples,true,te);
|
||||
raw_samples_add(samples,false,te*2);
|
||||
} else {
|
||||
raw_samples_add(samples,true,te*2);
|
||||
raw_samples_add(samples,false,te);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProtoViewDecoder KeeloqDecoder = {
|
||||
"Keeloq", decode
|
||||
.name = "Keeloq",
|
||||
.decode = decode,
|
||||
.get_fields = get_fields,
|
||||
.build_message = build_message
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
if (off == BITMAP_SEEK_NOT_FOUND) return false;
|
||||
FURI_LOG_E(TAG, "Oregon2 preamble+sync found");
|
||||
|
||||
info->start_off = off;
|
||||
off += 32; /* Skip preamble. */
|
||||
|
||||
uint8_t buffer[8], raw[8] = {0};
|
||||
@@ -21,8 +22,10 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
FURI_LOG_E(TAG, "Oregon2 decoded bits: %lu", decoded);
|
||||
|
||||
if (decoded < 11*4) return false; /* Minimum len to extract some data. */
|
||||
info->pulses_count = (off+11*4*4) - info->start_off;
|
||||
|
||||
char temp[3] = {0}, deviceid[2] = {0}, hum[2] = {0};
|
||||
char temp[3] = {0}, hum[2] = {0};
|
||||
uint8_t deviceid[2];
|
||||
for (int j = 0; j < 64; j += 4) {
|
||||
uint8_t nib[1];
|
||||
nib[0] = (bitmap_get(buffer,8,j+0) |
|
||||
@@ -45,21 +48,20 @@ 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. */
|
||||
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",
|
||||
temp[0],temp[1],temp[2]);
|
||||
snprintf(info->info3,sizeof(info->info3),"Humidity %d%d",
|
||||
hum[0],hum[1]);
|
||||
float tempval = ((temp[0]-'0')*10) +
|
||||
(temp[1]-'0') +
|
||||
((float)(temp[2]-'0')*0.1);
|
||||
int humval = (hum[0]-'0')*10 + (hum[1]-'0');
|
||||
|
||||
fieldset_add_bytes(info->fieldset,"Sensor ID",deviceid,4);
|
||||
fieldset_add_float(info->fieldset,"Temperature",tempval,1);
|
||||
fieldset_add_uint(info->fieldset,"Humidity",humval,7);
|
||||
return true;
|
||||
}
|
||||
|
||||
ProtoViewDecoder Oregon2Decoder = {
|
||||
"Oregon2", decode
|
||||
.name = "Oregon2",
|
||||
.decode = decode,
|
||||
.get_fields = NULL,
|
||||
.build_message = NULL
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
if (off == BITMAP_SEEK_NOT_FOUND) return false;
|
||||
FURI_LOG_E(TAG, "Renault TPMS preamble+sync found");
|
||||
|
||||
info->start_off = off;
|
||||
off += sync_len; /* Skip preamble + sync. */
|
||||
|
||||
uint8_t raw[10];
|
||||
@@ -37,24 +38,24 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
for (int j = 1; j < 10; j++) crc ^= raw[j];
|
||||
if (crc != 0) return false; /* Require sane checksum. */
|
||||
|
||||
info->pulses_count = (off+8*10*2) - info->start_off;
|
||||
|
||||
int repeat = raw[5] & 0xf;
|
||||
float kpa = (float)raw[6]*1.364;
|
||||
int temp = raw[7]-50;
|
||||
int battery = raw[8]; /* This may be the battery. It's not clear. */
|
||||
|
||||
snprintf(info->name,sizeof(info->name),"%s","Citroen TPMS");
|
||||
snprintf(info->raw,sizeof(info->raw),
|
||||
"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
|
||||
raw[6],raw[7],raw[8],raw[9]);
|
||||
snprintf(info->info1,sizeof(info->info1),"Tire ID %02X%02X%02X%02X",
|
||||
raw[1],raw[2],raw[3],raw[4]);
|
||||
snprintf(info->info2,sizeof(info->info2),"Pressure %.2f kpa", (double)kpa);
|
||||
snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp);
|
||||
snprintf(info->info4,sizeof(info->info4),"Repeat %d, Bat %d", repeat, battery);
|
||||
fieldset_add_bytes(info->fieldset,"Tire ID",raw+1,4*2);
|
||||
fieldset_add_float(info->fieldset,"Pressure kpa",kpa,2);
|
||||
fieldset_add_int(info->fieldset,"Temperature C",temp,8);
|
||||
fieldset_add_uint(info->fieldset,"Repeat",repeat,4);
|
||||
fieldset_add_uint(info->fieldset,"Battery",battery,8);
|
||||
return true;
|
||||
}
|
||||
|
||||
ProtoViewDecoder CitroenTPMSDecoder = {
|
||||
"Citroen TPMS", decode
|
||||
.name = "Citroen TPMS",
|
||||
.decode = decode,
|
||||
.get_fields = NULL,
|
||||
.build_message = NULL
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
if (off == BITMAP_SEEK_NOT_FOUND) return false;
|
||||
FURI_LOG_E(TAG, "Fort TPMS preamble+sync found");
|
||||
|
||||
info->start_off = off;
|
||||
off += sync_len; /* Skip preamble and sync. */
|
||||
|
||||
uint8_t raw[8];
|
||||
@@ -35,6 +36,8 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
for (int j = 0; j < 7; j++) crc += raw[j];
|
||||
if (crc != raw[7]) return false; /* Require sane CRC. */
|
||||
|
||||
info->pulses_count = (off+8*8*2) - info->start_off;
|
||||
|
||||
float psi = 0.25 * (((raw[6]&0x20)<<3)|raw[4]);
|
||||
|
||||
/* Temperature apperas to be valid only if the most significant
|
||||
@@ -44,21 +47,17 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
int flags = raw[5] & 0x7f;
|
||||
int car_moving = (raw[6] & 0x44) == 0x44;
|
||||
|
||||
snprintf(info->name,sizeof(info->name),"%s","Ford TPMS");
|
||||
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),"Tire ID %02X%02X%02X%02X",
|
||||
raw[0],raw[1],raw[2],raw[3]);
|
||||
snprintf(info->info2,sizeof(info->info2),"Pressure %.2f psi", (double)psi);
|
||||
if (temp)
|
||||
snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp);
|
||||
else
|
||||
snprintf(info->info3,sizeof(info->info3),"Flags %d", flags);
|
||||
snprintf(info->info4,sizeof(info->info4),"Moving %s", car_moving ? "yes" : "no");
|
||||
fieldset_add_bytes(info->fieldset,"Tire ID",raw,4*2);
|
||||
fieldset_add_float(info->fieldset,"Pressure psi",psi,2);
|
||||
fieldset_add_int(info->fieldset,"Temperature C",temp,8);
|
||||
fieldset_add_hex(info->fieldset,"Flags",flags,7);
|
||||
fieldset_add_uint(info->fieldset,"Moving",car_moving,1);
|
||||
return true;
|
||||
}
|
||||
|
||||
ProtoViewDecoder FordTPMSDecoder = {
|
||||
"Ford TPMS", decode
|
||||
.name = "Ford TPMS",
|
||||
.decode = decode,
|
||||
.get_fields = NULL,
|
||||
.build_message = NULL
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ static const char *test_vector =
|
||||
static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
|
||||
|
||||
if (USE_TEST_VECTOR) { /* Test vector to check that decoding works. */
|
||||
bitmap_set_pattern(bits,numbytes,test_vector);
|
||||
bitmap_set_pattern(bits,numbytes,0,test_vector);
|
||||
numbits = strlen(test_vector);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
if (off == BITMAP_SEEK_NOT_FOUND) return false;
|
||||
FURI_LOG_E(TAG, "Renault TPMS preamble+sync found");
|
||||
|
||||
info->start_off = off;
|
||||
off += 20; /* Skip preamble. */
|
||||
|
||||
uint8_t raw[9];
|
||||
@@ -47,20 +48,73 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
if (decoded < 8*9) return false; /* Require the full 9 bytes. */
|
||||
if (crc8(raw,8,0,7) != raw[8]) return false; /* Require sane CRC. */
|
||||
|
||||
float kpa = 0.75 *((uint32_t)((raw[0]&3)<<8) | raw[1]);
|
||||
info->pulses_count = (off+8*9*2) - info->start_off;
|
||||
|
||||
uint8_t flags = raw[0]>>2;
|
||||
float kpa = 0.75 * ((uint32_t)((raw[0]&3)<<8) | raw[1]);
|
||||
int temp = raw[2]-30;
|
||||
|
||||
snprintf(info->name,sizeof(info->name),"%s","Renault TPMS");
|
||||
snprintf(info->raw,sizeof(info->raw),"%02X%02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
|
||||
raw[6],raw[7],raw[8]);
|
||||
snprintf(info->info1,sizeof(info->info1),"Tire ID %02X%02X%02X",
|
||||
raw[3],raw[4],raw[5]);
|
||||
snprintf(info->info2,sizeof(info->info2),"Pressure %.2f kpa", (double)kpa);
|
||||
snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp);
|
||||
fieldset_add_bytes(info->fieldset,"Tire ID",raw+3,3*2);
|
||||
fieldset_add_float(info->fieldset,"Pressure kpa",kpa,2);
|
||||
fieldset_add_int(info->fieldset,"Temperature C",temp,8);
|
||||
fieldset_add_hex(info->fieldset,"Flags",flags,6);
|
||||
fieldset_add_bytes(info->fieldset,"Unknown1",raw+6,2);
|
||||
fieldset_add_bytes(info->fieldset,"Unknown2",raw+7,2);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Give fields and defaults for the signal creator. */
|
||||
static void get_fields(ProtoViewFieldSet *fieldset) {
|
||||
uint8_t default_id[3]= {0xAB, 0xCD, 0xEF};
|
||||
fieldset_add_bytes(fieldset,"Tire ID",default_id,3*2);
|
||||
fieldset_add_float(fieldset,"Pressure kpa",123,2);
|
||||
fieldset_add_int(fieldset,"Temperature C",20,8);
|
||||
// We don't know what flags are, but 1B is a common value.
|
||||
fieldset_add_hex(fieldset,"Flags",0x1b,6);
|
||||
fieldset_add_bytes(fieldset,"Unknown1",(uint8_t*)"\xff",2);
|
||||
fieldset_add_bytes(fieldset,"Unknown2",(uint8_t*)"\xff",2);
|
||||
}
|
||||
|
||||
/* Create a Renault TPMS signal, according to the fields provided. */
|
||||
static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fieldset)
|
||||
{
|
||||
uint32_t te = 50; // Short pulse duration in microseconds.
|
||||
|
||||
// Preamble + sync
|
||||
const char *psync = "01010101010101010101010101010110";
|
||||
const char *p = psync;
|
||||
while(*p) {
|
||||
raw_samples_add_or_update(samples,*p == '1',te);
|
||||
p++;
|
||||
}
|
||||
|
||||
// Data, 9 bytes
|
||||
uint8_t data[9] = {0};
|
||||
unsigned int raw_pressure = fieldset->fields[1]->fvalue * 4 / 3;
|
||||
data[0] = fieldset->fields[3]->uvalue << 2; // Flags
|
||||
data[0] |= (raw_pressure >> 8) & 3; // Pressure kpa high 2 bits
|
||||
data[1] = raw_pressure & 0xff; // Pressure kpa low 8 bits
|
||||
data[2] = fieldset->fields[2]->value + 30; // Temperature C
|
||||
memcpy(data+3,fieldset->fields[0]->bytes,6); // ID, 24 bits.
|
||||
data[6] = fieldset->fields[4]->bytes[0]; // Unknown 1
|
||||
data[7] = fieldset->fields[5]->bytes[0]; // Unknown 2
|
||||
data[8] = crc8(data,8,0,7);
|
||||
|
||||
// Generate Manchester code for each bit
|
||||
for (uint32_t j = 0; j < 9*8; j++) {
|
||||
if (bitmap_get(data,sizeof(data),j)) {
|
||||
raw_samples_add_or_update(samples,true,te);
|
||||
raw_samples_add_or_update(samples,false,te);
|
||||
} else {
|
||||
raw_samples_add_or_update(samples,false,te);
|
||||
raw_samples_add_or_update(samples,true,te);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProtoViewDecoder RenaultTPMSDecoder = {
|
||||
"Renault TPMS", decode
|
||||
.name = "Renault TPMS",
|
||||
.decode = decode,
|
||||
.get_fields = get_fields,
|
||||
.build_message = build_message
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ static const char *test_vector = "0000001111010101010110100101100101101010010101
|
||||
static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
|
||||
|
||||
if (USE_TEST_VECTOR) { /* Test vector to check that decoding works. */
|
||||
bitmap_set_pattern(bits,numbytes,test_vector);
|
||||
bitmap_set_pattern(bits,numbytes,0,test_vector);
|
||||
numbits = strlen(test_vector);
|
||||
}
|
||||
|
||||
@@ -27,11 +27,13 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
if (off == BITMAP_SEEK_NOT_FOUND) return false;
|
||||
FURI_LOG_E(TAG, "Schrader TPMS gap+preamble found");
|
||||
|
||||
info->start_off = off;
|
||||
off += 10; /* Skip just the long pulse and the first 3 bits of sync, so
|
||||
that we have the first byte of data with the sync nibble
|
||||
0011 = 0x3. */
|
||||
|
||||
uint8_t raw[8];
|
||||
uint8_t id[4];
|
||||
uint32_t decoded =
|
||||
convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
|
||||
"01","10"); /* Manchester code. */
|
||||
@@ -46,20 +48,24 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
return false;
|
||||
}
|
||||
|
||||
info->pulses_count = (off+8*8*2) - info->start_off;
|
||||
|
||||
float kpa = (float)raw[5]*2.5;
|
||||
int temp = raw[6]-50;
|
||||
id[0] = raw[1]&7;
|
||||
id[1] = raw[2];
|
||||
id[2] = raw[3];
|
||||
id[3] = raw[4];
|
||||
|
||||
snprintf(info->name,sizeof(info->name),"%s","Schrader TPMS");
|
||||
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),"Tire ID %01X%02X%02X%02X",
|
||||
raw[1]&7,raw[2],raw[3],raw[4]); /* Only 28 bits of ID, not 32. */
|
||||
snprintf(info->info2,sizeof(info->info2),"Pressure %.2f kpa", (double)kpa);
|
||||
snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp);
|
||||
fieldset_add_bytes(info->fieldset,"Tire ID",id,4*2);
|
||||
fieldset_add_float(info->fieldset,"Pressure kpa",kpa,2);
|
||||
fieldset_add_int(info->fieldset,"Temperature C",temp,8);
|
||||
return true;
|
||||
}
|
||||
|
||||
ProtoViewDecoder SchraderTPMSDecoder = {
|
||||
"Schrader TPMS", decode
|
||||
.name = "Schrader TPMS",
|
||||
.decode = decode,
|
||||
.get_fields = NULL,
|
||||
.build_message = NULL
|
||||
};
|
||||
|
||||
@@ -25,6 +25,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
if (off == BITMAP_SEEK_NOT_FOUND) return false;
|
||||
FURI_LOG_E(TAG, "Schrader EG53MA4 TPMS preamble+sync found");
|
||||
|
||||
info->start_off = off;
|
||||
off += sync_len-8; /* Skip preamble, not sync that is part of the data. */
|
||||
|
||||
uint8_t raw[10];
|
||||
@@ -40,6 +41,8 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
for (int j = 0; j < 9; j++) crc += raw[j];
|
||||
if (crc != raw[9]) return false; /* Require sane CRC. */
|
||||
|
||||
info->pulses_count = (off+10*8*2) - info->start_off;
|
||||
|
||||
/* To convert the raw pressure to kPa, RTL433 uses 2.5, but is likely
|
||||
* wrong. Searching on Google for users experimenting with the value
|
||||
* reported, the value appears to be 2.75. */
|
||||
@@ -47,17 +50,15 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
int temp_f = raw[8];
|
||||
int temp_c = (temp_f-32)*5/9; /* Convert Fahrenheit to Celsius. */
|
||||
|
||||
snprintf(info->name,sizeof(info->name),"%s","Schrader EG53MA4 TPMS");
|
||||
snprintf(info->raw,sizeof(info->raw),"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
|
||||
raw[6],raw[7],raw[8],raw[9]);
|
||||
snprintf(info->info1,sizeof(info->info1),"Tire ID %02X%02X%02X",
|
||||
raw[4],raw[5],raw[6]); /* Only 28 bits of ID, not 32. */
|
||||
snprintf(info->info2,sizeof(info->info2),"Pressure %.2f kpa", (double)kpa);
|
||||
snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp_c);
|
||||
fieldset_add_bytes(info->fieldset,"Tire ID",raw+4,3*2);
|
||||
fieldset_add_float(info->fieldset,"Pressure kpa",kpa,2);
|
||||
fieldset_add_int(info->fieldset,"Temperature C",temp_c,8);
|
||||
return true;
|
||||
}
|
||||
|
||||
ProtoViewDecoder SchraderEG53MA4TPMSDecoder = {
|
||||
"Schrader EG53MA4 TPMS", decode
|
||||
.name = "Schrader EG53MA4 TPMS",
|
||||
.decode = decode,
|
||||
.get_fields = NULL,
|
||||
.build_message = NULL
|
||||
};
|
||||
|
||||
@@ -42,6 +42,7 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
for (j = 0; sync[j]; j++) {
|
||||
off = bitmap_seek_bits(bits,numbytes,0,numbits,sync[j]);
|
||||
if (off != BITMAP_SEEK_NOT_FOUND) {
|
||||
info->start_off = off;
|
||||
off += strlen(sync[j])-2;
|
||||
break;
|
||||
}
|
||||
@@ -58,20 +59,31 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
|
||||
if (decoded < 8*9) return false; /* Require the full 8 bytes. */
|
||||
if (crc8(raw,8,0x80,7) != raw[8]) return false; /* Require sane CRC. */
|
||||
|
||||
float kpa = (float)((raw[4]&0x7f)<<1 | raw[5]>>7) * 0.25 - 7;
|
||||
/* We detected a valid signal. However now info->start_off is actually
|
||||
* pointing to the sync part, not the preamble of alternating 0 and 1.
|
||||
* Protoview decoders get called with some space to the left, in order
|
||||
* for the decoder itself to fix the signal if neeeded, so that its
|
||||
* logical representation will be more accurate and better to save
|
||||
* and retransmit. */
|
||||
if (info->start_off >= 12) {
|
||||
info->start_off -= 12;
|
||||
bitmap_set_pattern(bits,numbytes,info->start_off,"010101010101");
|
||||
}
|
||||
|
||||
info->pulses_count = (off+8*9*2) - info->start_off;
|
||||
|
||||
float psi = (float)((raw[4]&0x7f)<<1 | raw[5]>>7) * 0.25 - 7;
|
||||
int temp = ((raw[5]&0x7f)<<1 | raw[6]>>7) - 40;
|
||||
|
||||
snprintf(info->name,sizeof(info->name),"%s","Toyota TPMS");
|
||||
snprintf(info->raw,sizeof(info->raw),"%02X%02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
|
||||
raw[6],raw[7],raw[8]);
|
||||
snprintf(info->info1,sizeof(info->info1),"Tire ID %02X%02X%02X%02X",
|
||||
raw[0],raw[1],raw[2],raw[3]);
|
||||
snprintf(info->info1,sizeof(info->info1),"Pressure %.2f psi", (double)kpa);
|
||||
snprintf(info->info2,sizeof(info->info2),"Temperature %d C", temp);
|
||||
fieldset_add_bytes(info->fieldset,"Tire ID",raw,4*2);
|
||||
fieldset_add_float(info->fieldset,"Pressure psi",psi,2);
|
||||
fieldset_add_int(info->fieldset,"Temperature C",temp,8);
|
||||
return true;
|
||||
}
|
||||
|
||||
ProtoViewDecoder ToyotaTPMSDecoder = {
|
||||
"Toyota TPMS", decode
|
||||
.name = "Toyota TPMS",
|
||||
.decode = decode,
|
||||
.get_fields = NULL,
|
||||
.build_message = NULL
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user