|
| 1 | +/** @file |
| 2 | + Jansite FSK 11 byte Manchester encoded checksummed TPMS data. |
| 3 | +
|
| 4 | + Copyright (C) 2021 Benjamin Larsson |
| 5 | +
|
| 6 | + based on code |
| 7 | + 2019 Andreas Spiess and Christian W. Zuckschwerdt <[email protected]> |
| 8 | +
|
| 9 | + This program is free software; you can redistribute it and/or modify |
| 10 | + it under the terms of the GNU General Public License as published by |
| 11 | + the Free Software Foundation; either version 2 of the License, or |
| 12 | + (at your option) any later version. |
| 13 | +*/ |
| 14 | + |
| 15 | +/** |
| 16 | +Jansite Solar TPMS Solar Model |
| 17 | +
|
| 18 | +Signal is manchester encoded, and a 11 byte large message |
| 19 | +
|
| 20 | +Data layout (nibbles): |
| 21 | +
|
| 22 | + SS SS II II II 00 TT PP 00 CC CC |
| 23 | +
|
| 24 | +- S: 16 bits sync word, 0xdd33 |
| 25 | +- I: 24 bits ID |
| 26 | +- 0: 8 bits Unknown data 1 |
| 27 | +- T: 8 bit Temperature (deg. C offset by 55) |
| 28 | +- P: 8 bit Pressure |
| 29 | +- 0: 8 bits Unknown data 2 |
| 30 | +- C: 16 bit CRC (CRC-16/BUYPASS) |
| 31 | +- The preamble is 0xa6, 0xa6, 0x5a |
| 32 | +
|
| 33 | +TODO: identify battery bits |
| 34 | +*/ |
| 35 | + |
| 36 | +#include "decoder.h" |
| 37 | + |
| 38 | +static int tpms_jansite_solar_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row, unsigned bitpos) |
| 39 | +{ |
| 40 | + data_t *data; |
| 41 | + bitbuffer_t packet_bits = {0}; |
| 42 | + uint8_t *b; |
| 43 | + unsigned id; |
| 44 | + char id_str[7 + 1]; |
| 45 | + int flags; |
| 46 | + int pressure; |
| 47 | + int temperature; |
| 48 | + char code_str[9 * 2 + 1]; |
| 49 | + |
| 50 | + bitbuffer_manchester_decode(bitbuffer, row, bitpos, &packet_bits, 88); |
| 51 | + bitbuffer_invert(&packet_bits); |
| 52 | + |
| 53 | + if (packet_bits.bits_per_row[0] < 88) { |
| 54 | + return DECODE_FAIL_SANITY; |
| 55 | + } |
| 56 | + b = packet_bits.bb[0]; |
| 57 | + |
| 58 | + /* Check for sync */ |
| 59 | + if ((b[0]<<8 | b[1]) != 0xdd33) { |
| 60 | + return DECODE_FAIL_SANITY; |
| 61 | + } |
| 62 | + |
| 63 | + /* Check crc */ |
| 64 | + uint16_t crc_calc = crc16(&b[2], 7, 0x8005, 0x0000); |
| 65 | + if ( ((b[9]<<8) | b[10]) != crc_calc) { |
| 66 | + fprintf(stderr, "CRC missmatch %04x vs %02x %02x\n", crc_calc, b[9], b[10]); |
| 67 | + return DECODE_FAIL_MIC; |
| 68 | + } |
| 69 | + |
| 70 | + id = (unsigned)b[2] << 16 | b[3] << 8 | b[4]; |
| 71 | + flags = b[5]; |
| 72 | + temperature = b[6]; |
| 73 | + pressure = b[7]; |
| 74 | + sprintf(id_str, "%06x", id); |
| 75 | + sprintf(code_str, "%02x%02x%02x%02x%02x%02x%02x%02x%02x", b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10]); |
| 76 | + |
| 77 | + /* clang-format off */ |
| 78 | + data = data_make( |
| 79 | + "model", "", DATA_STRING, "Jansite Solar", |
| 80 | + "type", "", DATA_STRING, "TPMS", |
| 81 | + "id", "", DATA_STRING, id_str, |
| 82 | + "flags", "", DATA_INT, flags, |
| 83 | + "pressure_kPa", "Pressure", DATA_FORMAT, "%.0f kPa", DATA_DOUBLE, (float)pressure * 1.6, |
| 84 | + "temperature_C", "Temperature", DATA_FORMAT, "%.0f C", DATA_DOUBLE, (float)temperature - 55.0, |
| 85 | + "code", "", DATA_STRING, code_str, |
| 86 | + "mic", "", DATA_STRING, "CRC", |
| 87 | + NULL); |
| 88 | + /* clang-format on */ |
| 89 | + |
| 90 | + decoder_output_data(decoder, data); |
| 91 | + return 1; |
| 92 | +} |
| 93 | + |
| 94 | +/** @sa tpms_jansite_solar_decode() */ |
| 95 | +static int tpms_jansite_solar_callback(r_device *decoder, bitbuffer_t *bitbuffer) |
| 96 | +{ |
| 97 | + uint8_t const preamble_pattern[3] = {0xa6, 0xa6, 0x5a}; |
| 98 | + |
| 99 | + unsigned bitpos = 0; |
| 100 | + int ret = 0; |
| 101 | + int events = 0; |
| 102 | + |
| 103 | + while ((bitpos = bitbuffer_search(bitbuffer, 0, bitpos, preamble_pattern, 24)) + 80 <= |
| 104 | + bitbuffer->bits_per_row[0]) { |
| 105 | + |
| 106 | + ret = tpms_jansite_solar_decode(decoder, bitbuffer, 0, bitpos); |
| 107 | + if (ret > 0) |
| 108 | + events += ret; |
| 109 | + bitpos += 2; |
| 110 | + } |
| 111 | + |
| 112 | + return events > 0 ? events : ret; |
| 113 | +} |
| 114 | + |
| 115 | +static char *output_fields[] = { |
| 116 | + "model", |
| 117 | + "type", |
| 118 | + "id", |
| 119 | + "flags", |
| 120 | + "pressure_kPa", |
| 121 | + "temperature_C", |
| 122 | + "code", |
| 123 | + "mic", |
| 124 | + NULL, |
| 125 | +}; |
| 126 | + |
| 127 | +r_device tpms_jansite_solar = { |
| 128 | + .name = "Jansite TPMS Model Solar", |
| 129 | + .modulation = FSK_PULSE_PCM, |
| 130 | + .short_width = 51, |
| 131 | + .long_width = 51, |
| 132 | + .reset_limit = 5000, // Large enough to merge the 3 duplicate messages |
| 133 | + .decode_fn = &tpms_jansite_solar_callback, |
| 134 | + .disabled = 0, |
| 135 | + .fields = output_fields, |
| 136 | +}; |
0 commit comments