|
| 1 | +/** @file |
| 2 | + Gasmate BA1008 meat thermometer. |
| 3 | +
|
| 4 | + Copyright (C) 2023 Christian W. Zuckschwerdt <[email protected]> |
| 5 | + based on protocol analysis by Lucy Winters |
| 6 | +
|
| 7 | + This program is free software; you can redistribute it and/or modify |
| 8 | + it under the terms of the GNU General Public License as published by |
| 9 | + the Free Software Foundation; either version 2 of the License, or |
| 10 | + (at your option) any later version. |
| 11 | +*/ |
| 12 | + |
| 13 | +#include "decoder.h" |
| 14 | + |
| 15 | +/** |
| 16 | +Gasmate BA1008 meat thermometer. |
| 17 | +
|
| 18 | +Notably this protocol does not feature ID or CHANNEL information. |
| 19 | +
|
| 20 | +S.a. #2324 |
| 21 | +
|
| 22 | +Data Layout: |
| 23 | +
|
| 24 | + PF TT ?? ?A |
| 25 | +
|
| 26 | +- P: (4 bit) preamble/model/type? fixed 0xf |
| 27 | +- F: (4 bit) Unknown bit; Sign bit; 2-bit temperature 100ths (BCD) |
| 28 | +- T: (8 bit) temperature 10ths and 1ths (BCD) |
| 29 | +- ?: (12 bit) unknown value |
| 30 | +- A: (4 bit) checksum, nibble-wide add with carry |
| 31 | +
|
| 32 | +Raw data: |
| 33 | +
|
| 34 | + F4040BFB [-04C] |
| 35 | + F4060BF9 [-06C] |
| 36 | + F4100BEF [-10C] |
| 37 | + f0030ffc [+03C] |
| 38 | + F0230FDC [+23C] |
| 39 | + F0310FCE [+31C] |
| 40 | +
|
| 41 | +Format string: |
| 42 | +
|
| 43 | + PREAMBLE?h ?b SIGN:b TEMP:2hhhC ?hhh CHK:h |
| 44 | +
|
| 45 | +*/ |
| 46 | + |
| 47 | +static int gasmate_ba1008_decode(r_device *decoder, bitbuffer_t *bitbuffer) |
| 48 | +{ |
| 49 | + if (bitbuffer->num_rows != 1) { |
| 50 | + decoder_log(decoder, 2, __func__, "Row check fail"); |
| 51 | + return DECODE_ABORT_LENGTH; |
| 52 | + } |
| 53 | + |
| 54 | + int row = 0; |
| 55 | + uint8_t *b = bitbuffer->bb[row]; |
| 56 | + // we expect 32 bits |
| 57 | + if (bitbuffer->bits_per_row[row] != 32) { |
| 58 | + decoder_log(decoder, 2, __func__, "Length check fail"); |
| 59 | + return DECODE_ABORT_LENGTH; |
| 60 | + } |
| 61 | + |
| 62 | + // preamble/model/type and first flag bit check |
| 63 | + if ((b[0] & 0xf8) != 0xf0) { |
| 64 | + decoder_log(decoder, 2, __func__, "Model check fail"); |
| 65 | + return DECODE_ABORT_EARLY; |
| 66 | + } |
| 67 | + |
| 68 | + // check checksum |
| 69 | + if ((add_nibbles(b, 4) & 0x0f) != 0x0c) { |
| 70 | + decoder_log(decoder, 2, __func__, "Checksum fail"); |
| 71 | + return DECODE_FAIL_MIC; |
| 72 | + } |
| 73 | + |
| 74 | + int sign = (b[0] & 0x04) >> 2; |
| 75 | + int huns = (b[0] & 0x03); |
| 76 | + int tens = (b[1] & 0xf0) >> 4; |
| 77 | + int ones = (b[1] & 0x0f); |
| 78 | + int temp_raw = huns * 100 + tens * 10 + ones; |
| 79 | + int temp_c = sign ? -temp_raw : temp_raw; |
| 80 | + int unknown1 = (b[2] << 4) | (b[3] >> 4); |
| 81 | + |
| 82 | + /* clang-format off */ |
| 83 | + data_t *data = data_make( |
| 84 | + "model", "", DATA_STRING, "Gasmate-BA1008", |
| 85 | + "temperature_C", "Temperature_C", DATA_FORMAT, "%d C", DATA_INT, temp_c, |
| 86 | + "unknown_1", "Unknown Value", DATA_FORMAT, "%03x", DATA_INT, unknown1, |
| 87 | + "mic", "Integrity", DATA_STRING, "CHECKSUM", |
| 88 | + NULL); |
| 89 | + /* clang-format on */ |
| 90 | + |
| 91 | + decoder_output_data(decoder, data); |
| 92 | + return 1; |
| 93 | +} |
| 94 | + |
| 95 | +static char *output_fields[] = { |
| 96 | + "model", |
| 97 | + "temperature_C", |
| 98 | + "unknown_1", |
| 99 | + "mic", |
| 100 | + NULL, |
| 101 | +}; |
| 102 | + |
| 103 | +r_device const gasmate_ba1008 = { |
| 104 | + .name = "Gasmate BA1008 meat thermometer", |
| 105 | + .modulation = OOK_PULSE_PPM, |
| 106 | + .short_width = 536, |
| 107 | + .long_width = 1668, |
| 108 | + .reset_limit = 2000, |
| 109 | + .decode_fn = &gasmate_ba1008_decode, |
| 110 | + .fields = output_fields, |
| 111 | +}; |
0 commit comments