# Decoder for Continental / Nissan S180144020 key remote
# FCC ID: KR5S180144014
#
# Tested with 2x US 2013 Nissan Altima key fobs
#
# Operates on 433.92MHz with FSK at +/-32kHz.  With the default low-pass
# filter of 10% of the sample rate, this means that a sample rate strictly
# greater than 320ksps must be used.  For a RTL-SDR, that means passing
# "-s 1.024e6".
#
# The protocol was reverse engineered, so it may not be 100% complete.  There
# are 3 possible packet types:
# - sync: 128 bits of all 0
# - code: contains the rolling code, always sent twice for redundancy
# - time: contains the amount of time that the button was held
#
# Every button press generates a sequence of sync, code, sync, code, time...
# packets.  There is always a 100ms gap between packets.  Time packets will
# be transmitted every 100ms until the button is released.
#
# More than one button can be held as well, which will set more than one bit
# in the 'button' field.

decoder {
    name=Continental-Remote-code,
    modulation=FSK_MC_ZEROBIT,
    short=122,
    reset=1000,
    preamble=ffff,
    bits>=104,

    get=message:@0:{8}:[0x2a:HOLD_TIME 0x2c:REL_TIME 0x26:HOLD_CODE 0x24:REL_CODE],
    get=src:@8:{16}:%x,
    get=dest:@24:{16}:%x,
    get=button:@40:{8}:[0x00:NONE 0x01:ALARM 0x02:TRUNK 0x04:UNLOCK 0x08:LOCK 0x40:START],
    get=rv:@52:{2},
    get=seq:@56:{8},
    get=code:@64:{32}:%08x,
    get=xorsum:@96:{8}:%02x,
}

decoder {
    name=Continental-Remote-time,
    modulation=FSK_MC_ZEROBIT,
    short=122,
    reset=1000,
    preamble=ffff,
    bits>=64,
    bits<=103,

    get=message:@0:{8}:[0x2a:HOLD_TIME 0x2c:REL_TIME 0x26:HOLD_CODE 0x24:REL_CODE],
    get=src:@8:{16}:%x,
    get=dest:@24:{16}:%x,
    get=button:@40:{8}:[0x00:NONE 0x01:ALARM 0x02:TRUNK 0x04:UNLOCK 0x08:LOCK 0x40:START],
    get=clk_10.4kHz:@48:{16}:,
}
