formatting

This commit is contained in:
VerstreuteSeele
2023-01-27 02:09:42 +01:00
parent 0879f92e3d
commit a2b797fe01
44 changed files with 1735 additions and 1623 deletions

View File

@@ -7,55 +7,49 @@
#include "../../app.h"
static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
static bool decode(uint8_t* bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo* info) {
/* We consider a preamble of 17 symbols. They are more, but the decoding
* is more likely to happen if we don't pretend to receive from the
* very start of the message. */
uint32_t sync_len = 17;
const char *sync_pattern = "10101010101010110";
if (numbits-sync_len < 8*10) return false; /* Expect 10 bytes. */
const char* sync_pattern = "10101010101010110";
if(numbits - sync_len < 8 * 10) return false; /* Expect 10 bytes. */
uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
if (off == BITMAP_SEEK_NOT_FOUND) return false;
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");
info->start_off = off;
off += sync_len; /* Skip preamble + sync. */
uint8_t raw[10];
uint32_t decoded =
convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
"01","10"); /* Manchester. */
uint32_t decoded = convert_from_line_code(
raw, sizeof(raw), bits, numbytes, off, "01", "10"); /* Manchester. */
FURI_LOG_E(TAG, "Citroen TPMS decoded bits: %lu", decoded);
if (decoded < 8*10) return false; /* Require the full 10 bytes. */
if(decoded < 8 * 10) return false; /* Require the full 10 bytes. */
/* Check the CRC. It's a simple XOR of bytes 1-9, the first byte
* is not included. The meaning of the first byte is unknown and
* we don't display it. */
uint8_t crc = 0;
for (int j = 1; j < 10; j++) crc ^= raw[j];
if (crc != 0) return false; /* Require sane checksum. */
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;
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;
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. */
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);
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 = {
.name = "Citroen TPMS",
.decode = decode,
.get_fields = NULL,
.build_message = NULL
};
ProtoViewDecoder CitroenTPMSDecoder =
{.name = "Citroen TPMS", .decode = decode, .get_fields = NULL, .build_message = NULL};

View File

@@ -10,54 +10,49 @@
#include "../../app.h"
static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
static bool decode(uint8_t* bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo* info) {
const char* sync_pattern = "010101010101"
"0110";
uint8_t sync_len = 12 + 4; /* We just use 12 preamble symbols + sync. */
if(numbits - sync_len < 8 * 8) return false;
const char *sync_pattern = "010101010101" "0110";
uint8_t sync_len = 12+4; /* We just use 12 preamble symbols + sync. */
if (numbits-sync_len < 8*8) return false;
uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
if (off == BITMAP_SEEK_NOT_FOUND) return false;
uint64_t off = bitmap_seek_bits(bits, numbytes, 0, numbits, sync_pattern);
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];
uint32_t decoded =
convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
"01","10"); /* Manchester. */
uint32_t decoded = convert_from_line_code(
raw, sizeof(raw), bits, numbytes, off, "01", "10"); /* Manchester. */
FURI_LOG_E(TAG, "Ford TPMS decoded bits: %lu", decoded);
if (decoded < 8*8) return false; /* Require the full 8 bytes. */
if(decoded < 8 * 8) return false; /* Require the full 8 bytes. */
/* CRC is just the sum of the first 7 bytes MOD 256. */
uint8_t crc = 0;
for (int j = 0; j < 7; j++) crc += raw[j];
if (crc != raw[7]) return false; /* Require sane CRC. */
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;
info->pulses_count = (off + 8 * 8 * 2) - info->start_off;
float psi = 0.25 * (((raw[6]&0x20)<<3)|raw[4]);
float psi = 0.25 * (((raw[6] & 0x20) << 3) | raw[4]);
/* Temperature apperas to be valid only if the most significant
* bit of the value is not set. Otherwise its meaning is unknown.
* Likely useful to alternatively send temperature or other info. */
int temp = raw[5] & 0x80 ? 0 : raw[5]-56;
int temp = raw[5] & 0x80 ? 0 : raw[5] - 56;
int flags = raw[5] & 0x7f;
int car_moving = (raw[6] & 0x44) == 0x44;
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);
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 = {
.name = "Ford TPMS",
.decode = decode,
.get_fields = NULL,
.build_message = NULL
};
ProtoViewDecoder FordTPMSDecoder =
{.name = "Ford TPMS", .decode = decode, .get_fields = NULL, .build_message = NULL};

View File

@@ -6,85 +6,82 @@
#include "../../app.h"
#define USE_TEST_VECTOR 0
static const char *test_vector =
static const char* test_vector =
"...01010101010101010110" // Preamble + sync
/* The following is Marshal encoded, so each two characters are
* actaully one bit. 01 = 0, 10 = 1. */
"010110010110" // Flags.
"10011001101010011001" // Pressure, multiply by 0.75 to obtain kpa.
// 244 kpa here.
"1010010110011010" // Temperature, subtract 30 to obtain celsius. 22C here.
// 244 kpa here.
"1010010110011010" // Temperature, subtract 30 to obtain celsius. 22C here.
"1001010101101001"
"0101100110010101"
"1001010101100110" // Tire ID. 0x7AD779 here.
"1001010101100110" // Tire ID. 0x7AD779 here.
"0101010101010101"
"0101010101010101" // Two FF bytes (usually). Unknown.
"0101010101010101" // Two FF bytes (usually). Unknown.
"0110010101010101"; // CRC8 with (poly 7, initialization 0).
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,0,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, 0, test_vector);
numbits = strlen(test_vector);
}
if (numbits-12 < 9*8) return false;
if(numbits - 12 < 9 * 8) return false;
const char *sync_pattern = "01010101010101010110";
uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
if (off == BITMAP_SEEK_NOT_FOUND) return false;
const char* sync_pattern = "01010101010101010110";
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");
info->start_off = off;
off += 20; /* Skip preamble. */
uint8_t raw[9];
uint32_t decoded =
convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
"01","10"); /* Manchester. */
uint32_t decoded = convert_from_line_code(
raw, sizeof(raw), bits, numbytes, off, "01", "10"); /* Manchester. */
FURI_LOG_E(TAG, "Renault TPMS decoded bits: %lu", decoded);
if (decoded < 8*9) return false; /* Require the full 9 bytes. */
if (crc8(raw,8,0,7) != raw[8]) return false; /* Require sane CRC. */
if(decoded < 8 * 9) return false; /* Require the full 9 bytes. */
if(crc8(raw, 8, 0, 7) != raw[8]) return false; /* Require sane CRC. */
info->pulses_count = (off+8*9*2) - info->start_off;
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;
uint8_t flags = raw[0] >> 2;
float kpa = 0.75 * ((uint32_t)((raw[0] & 3) << 8) | raw[1]);
int temp = raw[2] - 30;
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);
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);
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);
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)
{
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;
const char* psync = "01010101010101010101010101010110";
const char* p = psync;
while(*p) {
raw_samples_add_or_update(samples,*p == '1',te);
raw_samples_add_or_update(samples, *p == '1', te);
p++;
}
@@ -93,21 +90,21 @@ static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fieldset
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[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);
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);
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);
raw_samples_add_or_update(samples, false, te);
raw_samples_add_or_update(samples, true, te);
}
}
}
@@ -116,5 +113,4 @@ ProtoViewDecoder RenaultTPMSDecoder = {
.name = "Renault TPMS",
.decode = decode,
.get_fields = get_fields,
.build_message = build_message
};
.build_message = build_message};

View File

@@ -11,20 +11,21 @@
#include "../../app.h"
#define USE_TEST_VECTOR 0
static const char *test_vector = "000000111101010101011010010110010110101001010110100110011001100101010101011010100110100110011010101010101010101010101010101010101010101010101010";
static const char* test_vector =
"000000111101010101011010010110010110101001010110100110011001100101010101011010100110100110011010101010101010101010101010101010101010101010101010";
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,0,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, 0, test_vector);
numbits = strlen(test_vector);
}
if (numbits < 64) return false; /* Preamble + data. */
if(numbits < 64) return false; /* Preamble + data. */
const char *sync_pattern = "1111010101" "01011010";
uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
if (off == BITMAP_SEEK_NOT_FOUND) return false;
const char* sync_pattern = "1111010101"
"01011010";
uint64_t off = bitmap_seek_bits(bits, numbytes, 0, numbits, sync_pattern);
if(off == BITMAP_SEEK_NOT_FOUND) return false;
FURI_LOG_E(TAG, "Schrader TPMS gap+preamble found");
info->start_off = off;
@@ -34,38 +35,33 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
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. */
uint32_t decoded = convert_from_line_code(
raw, sizeof(raw), bits, numbytes, off, "01", "10"); /* Manchester code. */
FURI_LOG_E(TAG, "Schrader TPMS decoded bits: %lu", decoded);
if (decoded < 64) return false; /* Require the full 8 bytes. */
if(decoded < 64) return false; /* Require the full 8 bytes. */
raw[0] |= 0xf0; // Fix the preamble nibble for checksum computation.
uint8_t cksum = crc8(raw,sizeof(raw)-1,0xf0,0x7);
if (cksum != raw[7]) {
uint8_t cksum = crc8(raw, sizeof(raw) - 1, 0xf0, 0x7);
if(cksum != raw[7]) {
FURI_LOG_E(TAG, "Schrader TPMS checksum mismatch");
return false;
}
info->pulses_count = (off+8*8*2) - info->start_off;
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;
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];
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);
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 = {
.name = "Schrader TPMS",
.decode = decode,
.get_fields = NULL,
.build_message = NULL
};
ProtoViewDecoder SchraderTPMSDecoder =
{.name = "Schrader TPMS", .decode = decode, .get_fields = NULL, .build_message = NULL};

View File

@@ -15,50 +15,45 @@
#include "../../app.h"
static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
static bool decode(uint8_t* bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo* info) {
const char* sync_pattern = "010101010101"
"01100101";
uint8_t sync_len = 12 + 8; /* We just use 12 preamble symbols + sync. */
if(numbits - sync_len + 8 < 8 * 10) return false;
const char *sync_pattern = "010101010101" "01100101";
uint8_t sync_len = 12+8; /* We just use 12 preamble symbols + sync. */
if (numbits-sync_len+8 < 8*10) return false;
uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
if (off == BITMAP_SEEK_NOT_FOUND) return false;
uint64_t off = bitmap_seek_bits(bits, numbytes, 0, numbits, sync_pattern);
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. */
off += sync_len - 8; /* Skip preamble, not sync that is part of the data. */
uint8_t raw[10];
uint32_t decoded =
convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
"01","10"); /* Manchester code. */
uint32_t decoded = convert_from_line_code(
raw, sizeof(raw), bits, numbytes, off, "01", "10"); /* Manchester code. */
FURI_LOG_E(TAG, "Schrader EG53MA4 TPMS decoded bits: %lu", decoded);
if (decoded < 10*8) return false; /* Require the full 10 bytes. */
if(decoded < 10 * 8) return false; /* Require the full 10 bytes. */
/* CRC is just all bytes added mod 256. */
uint8_t crc = 0;
for (int j = 0; j < 9; j++) crc += raw[j];
if (crc != raw[9]) return false; /* Require sane CRC. */
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;
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. */
float kpa = (float)raw[7]*2.75;
float kpa = (float)raw[7] * 2.75;
int temp_f = raw[8];
int temp_c = (temp_f-32)*5/9; /* Convert Fahrenheit to Celsius. */
int temp_c = (temp_f - 32) * 5 / 9; /* Convert Fahrenheit to Celsius. */
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);
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 = {
.name = "Schrader EG53MA4 TPMS",
.decode = decode,
.get_fields = NULL,
.build_message = NULL
};
ProtoViewDecoder SchraderEG53MA4TPMSDecoder =
{.name = "Schrader EG53MA4 TPMS", .decode = decode, .get_fields = NULL, .build_message = NULL};

View File

@@ -24,40 +24,33 @@
#include "../../app.h"
static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
if (numbits-6 < 64*2) return false; /* Ask for 64 bit of data (each bit
static bool decode(uint8_t* bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo* info) {
if(numbits - 6 < 64 * 2)
return false; /* Ask for 64 bit of data (each bit
is two symbols in the bitmap). */
char *sync[] = {
"00111100",
"001111100",
"00111101",
"001111101",
NULL
};
char* sync[] = {"00111100", "001111100", "00111101", "001111101", NULL};
int j;
uint32_t off = 0;
for (j = 0; sync[j]; j++) {
off = bitmap_seek_bits(bits,numbytes,0,numbits,sync[j]);
if (off != BITMAP_SEEK_NOT_FOUND) {
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;
off += strlen(sync[j]) - 2;
break;
}
}
}
if (off == BITMAP_SEEK_NOT_FOUND) return false;
if(off == BITMAP_SEEK_NOT_FOUND) return false;
FURI_LOG_E(TAG, "Toyota TPMS sync[%s] found", sync[j]);
uint8_t raw[9];
uint32_t decoded =
convert_from_diff_manchester(raw,sizeof(raw),bits,numbytes,off,true);
uint32_t decoded = convert_from_diff_manchester(raw, sizeof(raw), bits, numbytes, off, true);
FURI_LOG_E(TAG, "Toyota TPMS decoded bits: %lu", decoded);
if (decoded < 8*9) return false; /* Require the full 8 bytes. */
if (crc8(raw,8,0x80,7) != raw[8]) return false; /* Require sane CRC. */
if(decoded < 8 * 9) return false; /* Require the full 8 bytes. */
if(crc8(raw, 8, 0x80, 7) != raw[8]) return false; /* Require sane CRC. */
/* 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.
@@ -65,25 +58,21 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
* 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) {
if(info->start_off >= 12) {
info->start_off -= 12;
bitmap_set_pattern(bits,numbytes,info->start_off,"010101010101");
bitmap_set_pattern(bits, numbytes, info->start_off, "010101010101");
}
info->pulses_count = (off+8*9*2) - info->start_off;
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;
float psi = (float)((raw[4] & 0x7f) << 1 | raw[5] >> 7) * 0.25 - 7;
int temp = ((raw[5] & 0x7f) << 1 | raw[6] >> 7) - 40;
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_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 = {
.name = "Toyota TPMS",
.decode = decode,
.get_fields = NULL,
.build_message = NULL
};
ProtoViewDecoder ToyotaTPMSDecoder =
{.name = "Toyota TPMS", .decode = decode, .get_fields = NULL, .build_message = NULL};