# TYREGUARD400 from DAVIES CRAIG
#
# https://daviescraig.com.au/product/tyreguard-400-tpms-4-sensors-kit-1015
#
# - Type            : TPMS
# - Freq            : 434.1 MHz
# - Modulation      : ASK -> OOK_MC_ZEROBIT (Manchester Code with fixed leading zero bit)
# - Sambol duration : 100us (same for l or 0)
# - Length          : 22 bytes long
#
# Packet layout:
#
#     bytes : 1    2    3    4    5    6    7    8   9   10  11  12  13  14  15  16  17   18   19   20   21  22
#     coded : S/P  S/P  S/P  S/P  S/P  S/P  S/P  ID  ID  ID  ID  ID  ID  ID  Pr  Pr  Temp Temp Flg  Flg  CRC CRC
#
# - S/P   : preamble/sync "0xfd5fd5f" << always fixed
# - ID    : 6 bytes long start with 0x6b????? ex 0x6b20d21
# - Pr    : Last 2 bytes of pressure in psi ex : 0xe8 means XX232 psi (for XX see flags bytes)
# - Temp  : Temperature in °C offset by +40 ex : 0x2f means (47-40)=+7°C
# - Flg   : Flags bytes => should be read in binary format :
#   - Bit 73 : Unknown ; maybe the 20th MSB pressure bit? The sensor is not capable to reach this so high pressure
#   - Bit 74 : add 1024 psi (19th MSB pressure bit)
#   - Bit 75 : add  512 psi (18th MSB pressure bit)
#   - Bit 76 : add  256 psi (17th MSB pressure bit)
#   - Bit 77 : Acknoldge pressure leaking 1=Ack 0=No_ack (nothing to report)
#   - Bit 78 : Unknown
#   - Bit 79 : Leaking pressure detected 1=Leak 0=No leak (nothing to report)
#   - Bit 80 : Leaking pressure detected 1=Leak 0=No leak (nothing to report)
# - CRC   : CRC poly 0x31 start value 0xdd final 0x00 from 1st bit 80th bits
#
# To peer a new sensor to the unit, bit 79 and 80 has to be both to 1.
#
# NOTE: In the datasheet, it is said that the sensor can report low batterie. During my tests/research i'm not able to see this behavior. I have fuzzed all bits nothing was reported to the reader.
#

decoder {
    name        = TPMS-TYREGUARD400,
    modulation  = OOK_MC_ZEROBIT,
    short       = 100,
    long        = 100,
    gap         = 0,
    reset       = 500,
    preamble    = fd5fd5f,
    get         = id:@0:{28},
    get         = pression:@57:{8},
    get         = temp:@65:{8},
    get         = flags:@73:{8},
    get         = add_psi:@74:{3}:[0:no 1:256 2:512 3:768 4:1024 5:1280 6:1536 7:1792],
    get         = AckLeaking:@77:{1}:[1: yes 0:no],
    get         = Leaking_detected:@79:{2}:[0:no 1:yes 2:yes],
    get         = CRC:@81:{8},
}
