1 /* Schraeder TPMS protocol
3 * Copyright © 2016 Benjamin Larsson
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
12 * Packet payload: 8,5 bytes, 17 nibbles
14 * 01 23 45 67 89 AB CD EF 0
15 * [00] {68} 7f 67 03 a3 8b 20 04 94 9
16 * SP UU UI II II IU UU UC C
22 * C = CRC8 from nibble 1 to E
26 #include "pulse_demod.h"
30 static int schraeder_callback(bitbuffer_t *bitbuffer) {
31 char time_str[LOCAL_TIME_BUFLEN];
32 bitrow_t *bb = bitbuffer->bb;
33 uint32_t serial_id = 0;
36 uint8_t work_buffer[9];
39 /* Reject wrong amount of bits */
40 if ( bitbuffer->bits_per_row[0] != 68)
43 /* shift the buffer 4 bits for the crc8 calculation */
45 work_buffer[i] = (bb[0][i]&0x0F)<<4 | (bb[0][i+1]&0xF0) >> 4;
47 /* Calculate the crc */
48 if (work_buffer[7] != crc8(work_buffer, 7, 0x07, 0xf0)) {
52 local_time_str(0, time_str);
54 /* Get serial number id */
55 serial_id = (bb[0][2]&0x0F) << 20 | bb[0][3] << 12 | bb[0][4] << 4 | (bb[0][5]&0xF0) >> 4;
56 sprintf(hexid, "%X", serial_id);
58 if (debug_output >= 1) {
59 fprintf(stderr, "Schraeder TPMS decoder\n");
60 bitbuffer_print(bitbuffer);
61 fprintf(stderr, "id = 0x%X\n", serial_id);
62 fprintf(stderr, "CRC = %x\n", crc8(work_buffer, 7, 0x07, 0xf0));
65 data = data_make("time", "", DATA_STRING, time_str,
66 "model", "", DATA_STRING, "Schraeder",
67 "type", "", DATA_STRING, "TPMS",
68 "id", "ID", DATA_STRING, hexid,
69 "crc", "", DATA_STRING, "OK",
72 data_acquired_handler(data);
76 static char *output_fields[] = {
87 r_device schraeder = {
88 .name = "Schraeder TPMS",
89 .modulation = OOK_PULSE_MANCHESTER_ZEROBIT,
93 .json_callback = &schraeder_callback,
95 .fields = output_fields,