Exemplo n.º 1
0
static int elro_db286a_callback(r_device *decoder, bitbuffer_t *bitbuffer)
{
    data_t *data;
    uint8_t *b;
    char id_str[4*2+1];

    // 33 bits expected, 5 minimum packet repetitions (14 expected)
    int row = bitbuffer_find_repeated_row(bitbuffer, 5, 33);

    if (row < 0 || bitbuffer->bits_per_row[row] != 33)
        return 0;

    b = bitbuffer->bb[row];

    // 32 bits, trailing bit is dropped
    sprintf(id_str, "%02x%02x%02x%02x", b[0], b[1], b[2], b[3]);

    data = data_make(
            "model",    "",        DATA_STRING, "Elro-DB286A",
            "id",       "ID",      DATA_STRING, id_str,
            NULL);

    decoder_output_data(decoder, data);

    return 1;

}
Exemplo n.º 2
0
static int silvercrest_callback(r_device *decoder, bitbuffer_t *bitbuffer) {
    uint8_t *b; // bits of a row
    uint8_t cmd;
    data_t *data;

    if (bitbuffer->bits_per_row[1] !=33)
        return 0;

    /* select second row, first might be bad */
    b = bitbuffer->bb[1];
    if ((b[0] == 0x7c) && (b[1] == 0x26)) {
        cmd = b[2] & 0xF;
	// Validate button
        if ((b[3]&0xF) != cmd_lu_tab[cmd])
            return 0;


        data = data_make(
            "model", "", DATA_STRING, "Silvercrest Remote Control",
            "button", "", DATA_INT, cmd,
            NULL);

        decoder_output_data(decoder, data);

        return 1;
    }
    return 0;
}
Exemplo n.º 3
0
static int thermopro_tp11_sensor_callback(r_device *decoder, bitbuffer_t *bitbuffer) {
    int temp_raw, row;
    float temp_c;
    bitrow_t *bb = bitbuffer->bb;
    unsigned int device, value;
    data_t *data;

    // Compare first four bytes of rows that have 32 or 33 bits.
    row = bitbuffer_find_repeated_row(bitbuffer, 2, 32);
    if (row < 0)
        return 0;

    if (bitbuffer->bits_per_row[row] > 33)
        return 0;

    value = (bb[row][0] << 16) + (bb[row][1] << 8) + bb[row][2];
    device = value >> 12;

    // Validate code for known devices.
    if ((device == 0xb34 || device == 0xdb4 ) && !valid(value, bb[row][3]))
        return 0;

    temp_raw = value & 0xfff;
    temp_c = (temp_raw - 200) / 10.;

    data = data_make(
            "model",         "",            DATA_STRING, _X("Thermopro-TP11","Thermopro TP11 Thermometer"),
            "id",            "Id",          DATA_INT,    device,
            "temperature_C", "Temperature", DATA_FORMAT, "%.01f C", DATA_DOUBLE, temp_c,
            NULL);
    decoder_output_data(decoder, data);
    return 1;
}
Exemplo n.º 4
0
static int xc0324_callback(r_device *decoder, bitbuffer_t *bitbuffer)
{
    int r; // a row index
    uint16_t bitpos;
    int result;
    int events = 0;
    data_t *data = NULL;
    
    // Only for simulating initial package level deciphering / debug.
    if (decoder->verbose == 2) {
        // Verbosely output the bitbuffer 
        decoder_output_bitbufferf(decoder, bitbuffer, "XC0324:vvv hex(/binary) version of bitbuffer");
        // And then output each row to csv, json or whatever was specified.
        for (r = 0; r < bitbuffer->num_rows; ++r) {
            decoder_output_bitrowf(decoder, bitbuffer->bb[r], bitbuffer->bits_per_row[r],
              "XC0324:vvv row %03d", r);
        }
    }
    //A clean XC0324 transmission contains 3 repeats of a message in a single row.
    //But in case of transmission or demodulation glitches, 
    //loop over all rows and check for salvageable messages.
    for (r = 0; r < bitbuffer->num_rows; ++r) {
        if (bitbuffer->bits_per_row[r] < XC0324_MESSAGE_BITLEN) {
            // bail out of this "too short" row early
            if (decoder->verbose == 1) {
                // Output the bad row, only for message level debug / deciphering.
                decoder_output_bitrowf(decoder, bitbuffer->bb[r], bitbuffer->bits_per_row[r],
                  "Bad message need %d bits got %d <- XC0324:vv row %d bit %d",
                  XC0324_MESSAGE_BITLEN, bitbuffer->bits_per_row[r], r, 0);
            }
            continue; // to the next row  
        }
        // We have enough bits so search for a message preamble followed by 
        // enough bits that it could be a complete message.
        bitpos = 0;
        while ((bitpos = bitbuffer_search(bitbuffer, r, bitpos,
          (const uint8_t *)&preamble_pattern, 8))
          + XC0324_MESSAGE_BITLEN <= bitbuffer->bits_per_row[r]) {
            events += result = decode_xc0324_message(decoder, bitbuffer,
              r, bitpos, events, &data);
            // Keep production output (decoder->verbose == 0) separate from 
            // (simulated) development stage output (decoder->verbose > 0)
            if (result & !decoder->verbose) { // Production output
                data_append(data, "message_num",  "Message repeat count",
                  DATA_INT, events, NULL);
                decoder_output_data(decoder, data);
                return events; // in production, first successful decode is enough
            }
            bitpos += XC0324_MESSAGE_BITLEN;
        }
    }
    // (Only) for future regression tests.
    if ((decoder->verbose == 3) & (events == 0)) {
        decoder_output_messagef(decoder, "XC0324:vvvv Reference -> Bad transmission");
    }
    return events;
}
Exemplo n.º 5
0
/**
The sensor sends a single packet once every hour or twice a second
for 11 minutes when in pairing/test mode (pairing needs 35 sec).
depth reading is in cm, lowest reading is ~3, highest is ~305, 0 is invalid

    IIII IIII IIII IIII 0FFF L0OP DDDD DDDD

The TEK377E might send an additional 8 zero bits.

example packets are:

    010101 01010101 01010111 01101001 10011010 10101001 10100101 10011010 01101010 10011001 10011010 0000
    010101 01010101 01011000 10011010 01010110 01101010 10101010 10100101 01101010 10100110 10101001 1111

Start of frame full preamble is depending on first data bit either

    01 0101 0101 0101 0101 0111 01
    01 0101 0101 0101 0101 1000 10
*/
static int oil_standard_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row, unsigned bitpos)
{
    data_t *data;
    uint8_t *b;
    uint16_t unit_id;
    uint16_t depth             = 0;
    uint16_t binding_countdown = 0;
    uint8_t flags;
    uint8_t alarm;
    bitbuffer_t databits = {0};

    bitpos = bitbuffer_manchester_decode(bitbuffer, row, bitpos, &databits, 41);

    if (databits.bits_per_row[0] < 32 || databits.bits_per_row[0] > 40 || (databits.bb[0][4] & 0xfe) != 0)
        return 0;

    b = databits.bb[0];

    // The unit ID changes when you rebind by holding a magnet to the
    // sensor for long enough.
    unit_id = (b[0] << 8) | b[1];

    // 0x01: Rebinding (magnet held to sensor)
    // 0x02: High-bit for depth
    // 0x04: (always zero?)
    // 0x08: Leak/theft alarm
    // 0x10: (unknown toggle)
    // 0x20: (unknown toggle)
    // 0x40: (unknown toggle)
    // 0x80: (always zero?)
    flags = b[2] & ~0x0A;
    alarm = (b[2] & 0x08) >> 3;

    if (flags & 1)
        // When binding, the countdown counts up from 0x40 to 0x4a
        // (as long as you hold the magnet to it for long enough)
        // before the device ID changes. The receiver unit needs
        // to receive this *strongly* in order to change its
        // allegiance.
        binding_countdown = b[3];
    else
        // A depth reading of zero indicates no reading.
        depth = ((b[2] & 0x02) << 7) | b[3];

    data = data_make(
            "model", "", DATA_STRING, _X("Oil-SonicStd","Oil Ultrasonic STANDARD"),
            "id", "", DATA_FORMAT, "%04x", DATA_INT, unit_id,
            "flags", "", DATA_FORMAT, "%02x", DATA_INT, flags,
            "alarm", "", DATA_INT, alarm,
            "binding_countdown", "", DATA_INT, binding_countdown,
            "depth_cm", "", DATA_INT, depth,
            NULL);
    decoder_output_data(decoder, data);

    return 1;
}
Exemplo n.º 6
0
static int ge_coloreffects_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row, unsigned start_pos)
{
    data_t *data;
    bitbuffer_t packet_bits = {0};
    uint8_t device_id;
    uint8_t command;

    ge_decode(decoder, bitbuffer, row, start_pos, &packet_bits);
    //bitbuffer_print(&packet_bits);

    /* From http://www.deepdarc.com/2010/11/27/hacking-christmas-lights/
     * Decoded frame format is:
     *   Preamble
     *   Two zero bits
     *   6-bit Device ID (Can be modified by adding R15-R20 on the large PCB)
     *   8-bit Command
     *   One zero bit
     */
    
    // Frame should be 17 decoded bits (not including preamble)
    if (packet_bits.bits_per_row[0] != 17)
        return 0;
    
    // First two bits must be 0
    if (*packet_bits.bb[0] & 0xc0)
        return 0;
    
    // Last bit must be 0
    if (bit(packet_bits.bb[0], 16) != 0)
        return 0;
    
    // Extract device ID
    // We want bits [2..8]. Since the first two bits are zero, we'll just take the entire first byte
    device_id = *packet_bits.bb[0];

    // Extract command from the second byte
    bitbuffer_extract_bytes(&packet_bits, 0, 8, &command, 8);
    
    // Format data
    data = data_make(
        "model",         "",     DATA_STRING, "GE Color Effects Remote",
        "id",            "",     DATA_FORMAT, "0x%x", DATA_INT, device_id,
        "command",       "",     DATA_STRING, ge_command_name(command),
        NULL);

    decoder_output_data(decoder, data);
    return 1;

}
Exemplo n.º 7
0
static int maverick_et73_sensor_callback(r_device *decoder, bitbuffer_t *bitbuffer) {
    int temp1_raw, temp2_raw, row;
    float temp1_c, temp2_c;
    uint8_t *bytes;
    unsigned int device;
    data_t *data;

    // The device transmits many rows, let's check for 3 matching.
    row = bitbuffer_find_repeated_row(bitbuffer, 3, 48);
    if (row < 0) {
        return 0;
    }

    bytes = bitbuffer->bb[row];
    if (!bytes[0] && !bytes[1] && !bytes[2] && !bytes[3]) {
        return 0; // reduce false positives
    }

    if (bitbuffer->bits_per_row[row] != 48)
        return 0;

    device = bytes[0];

    if (decoder->verbose) {
        fprintf(stderr,"maverick_et73_raw_data:");
        bitrow_print(bytes, 48);
    }

    temp1_raw = (bytes[1] << 4) | ((bytes[2] & 0xf0) );
    temp2_raw = ((bytes[2] & 0x0f) << 8) | bytes[3];

    temp1_c = temp1_raw * 0.1;
    temp2_c = temp2_raw * 0.1;

    data = data_make(
            "model",            "",                 DATA_STRING, "Maverick ET73",
            "rid",              "Random Id",        DATA_INT, device,
            "temperature_1_C",  "Temperature 1",    DATA_FORMAT, "%.01f C", DATA_DOUBLE, temp1_c,
            "temperature_2_C",  "Temperature 2",    DATA_FORMAT, "%.01f C", DATA_DOUBLE, temp2_c,
            NULL);
    decoder_output_data(decoder, data);
    return 1;
}