|
| 1 | +/** @file |
| 2 | + Amazon Basics Meat Thermometer |
| 3 | +
|
| 4 | + Copyright (C) 2021 Benjamin Larsson |
| 5 | +
|
| 6 | + This program is free software; you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU General Public License as published by |
| 8 | + the Free Software Foundation; either version 2 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +*/ |
| 11 | +/** |
| 12 | +Amazon Basics Meat Thermometer |
| 13 | +
|
| 14 | +Manchester encoded PCM signal. |
| 15 | +
|
| 16 | +[00] {48} e4 00 a3 01 40 ff |
| 17 | +
|
| 18 | +II 00 UU TT T0 FF |
| 19 | +
|
| 20 | +I - power on random id |
| 21 | +0 - zeros |
| 22 | +U - Unknown |
| 23 | +T - bcd coded temperature |
| 24 | +F - ones |
| 25 | +
|
| 26 | +
|
| 27 | +*/ |
| 28 | +#include "decoder.h" |
| 29 | + |
| 30 | +#define SYNC_PATTERN_START_OFF 72 |
| 31 | + |
| 32 | +// Convert two BCD encoded nibbles to an integer |
| 33 | +static unsigned bcd2int(uint8_t bcd) |
| 34 | +{ |
| 35 | + return 10*(bcd>>4) + (bcd & 0xF); |
| 36 | +} |
| 37 | + |
| 38 | +static int abmt_callback(r_device *decoder, bitbuffer_t *bitbuffer) |
| 39 | +{ |
| 40 | + int row; |
| 41 | + float temp_c; |
| 42 | + bitbuffer_t packet_bits = {0}; |
| 43 | + unsigned int id; |
| 44 | + data_t *data; |
| 45 | + unsigned bitpos = 0; |
| 46 | + uint8_t *b; |
| 47 | + int16_t temp; |
| 48 | + uint8_t const sync_pattern[3] = {0x55, 0xAA, 0xAA}; |
| 49 | + |
| 50 | + // Find repeats |
| 51 | + row = bitbuffer_find_repeated_row(bitbuffer, 4, 90); |
| 52 | + if (row < 0) |
| 53 | + return DECODE_ABORT_EARLY; |
| 54 | + |
| 55 | + if (bitbuffer->bits_per_row[row] > 120) |
| 56 | + return DECODE_ABORT_LENGTH; |
| 57 | + |
| 58 | + // search for 24 bit sync pattern |
| 59 | + bitpos = bitbuffer_search(bitbuffer, row, bitpos, sync_pattern, 24); |
| 60 | + // if sync is not found or sync is found with to little bits available, abort |
| 61 | + if ((bitpos == bitbuffer->bits_per_row[row]) || (bitpos < SYNC_PATTERN_START_OFF)) |
| 62 | + return DECODE_FAIL_SANITY; |
| 63 | + |
| 64 | + // sync bitstream |
| 65 | + bitbuffer_manchester_decode(bitbuffer, row, bitpos-SYNC_PATTERN_START_OFF, &packet_bits, 48); |
| 66 | + bitbuffer_invert(&packet_bits); |
| 67 | + |
| 68 | + b = packet_bits.bb[0]; |
| 69 | + id = b[0]; |
| 70 | + temp = bcd2int(b[3])*10 + bcd2int(b[4]>>4); |
| 71 | + temp_c = (float)temp; |
| 72 | + |
| 73 | + /* clang-format off */ |
| 74 | + data = data_make( |
| 75 | + "model", "", DATA_STRING, "AmazonBasicsMeatThermometer", |
| 76 | + "id", "Id", DATA_INT, id, |
| 77 | + "temperature_C", "Temperature", DATA_FORMAT, "%.01f C", DATA_DOUBLE, temp_c, |
| 78 | + NULL); |
| 79 | + /* clang-format on */ |
| 80 | + decoder_output_data(decoder, data); |
| 81 | + return 1; |
| 82 | +} |
| 83 | + |
| 84 | +static char *output_fields[] = { |
| 85 | + "model", |
| 86 | + "id", |
| 87 | + "temperature_C", |
| 88 | + NULL, |
| 89 | +}; |
| 90 | + |
| 91 | +r_device abmt = { |
| 92 | + .name = "Amazon Basics Meat Thermometer", |
| 93 | + .modulation = OOK_PULSE_PCM_RZ, |
| 94 | + .short_width = 550, |
| 95 | + .long_width = 550, |
| 96 | + .gap_limit = 2000, |
| 97 | + .reset_limit = 5000, |
| 98 | + .decode_fn = &abmt_callback, |
| 99 | + .disabled = 0, |
| 100 | + .fields = output_fields, |
| 101 | +}; |
0 commit comments