updated protoview

This commit is contained in:
jbohack
2023-01-23 14:21:10 -05:00
parent 35fe007814
commit 5c4f4cfbd2
26 changed files with 2224 additions and 274 deletions

View File

@@ -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
};

View File

@@ -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
};

View File

@@ -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
};

View File

@@ -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
};

View File

@@ -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
};

View File

@@ -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
};