X-Git-Url: https://git.rvb.name/rtl-433.git/blobdiff_plain/ca13278b24eb61443559bcb61e64627fba3d8823..6d15c6f967221af825cf84e3ed12b96c763b127b:/src/devices/waveman.c diff --git a/src/devices/waveman.c b/src/devices/waveman.c index 6ac2dca..22e427b 100644 --- a/src/devices/waveman.c +++ b/src/devices/waveman.c @@ -1,39 +1,73 @@ #include "rtl_433.h" -static int waveman_callback(uint8_t bb[BITBUF_ROWS][BITBUF_COLS],int16_t bits_per_row[BITBUF_ROWS]) { +static int waveman_callback(bitbuffer_t *bitbuffer) { + uint8_t *b = bitbuffer->bb[0]; /* Two bits map to 2 states, 0 1 -> 0 and 1 1 -> 1 */ int i; uint8_t nb[3] = {0}; + data_t *data; + char id_str[2]; - if (((bb[0][0]&0x55)==0x55) && ((bb[0][1]&0x55)==0x55) && ((bb[0][2]&0x55)==0x55) && ((bb[0][3]&0x55)==0x00)) { + /* @todo iterate through all rows */ + + /* Reject codes of wrong length */ + if ( 24 != bitbuffer->bits_per_row[0]) + return 0; + + /* + * Catch the case triggering false positive for other transmitters. + * example: Brennstuhl RCS 2044SN + * @todo is this message valid at all??? if not then put more validation below + * instead of this special case + */ + if ( 0xFF == b[0] && + 0xFF == b[1] && + 0xFF == b[2] ) + return 0; + + /* Test if the bit stream conforms to the rule of every odd bit being set to one */ + if (((b[0]&0x55)==0x55) && ((b[1]&0x55)==0x55) && ((b[2]&0x55)==0x55) && ((b[3]&0x55)==0x00)) { + /* Extract data from the bit stream */ for (i=0 ; i<3 ; i++) { - nb[i] |= ((bb[0][i]&0xC0)==0xC0) ? 0x00 : 0x01; - nb[i] |= ((bb[0][i]&0x30)==0x30) ? 0x00 : 0x02; - nb[i] |= ((bb[0][i]&0x0C)==0x0C) ? 0x00 : 0x04; - nb[i] |= ((bb[0][i]&0x03)==0x03) ? 0x00 : 0x08; + nb[i] |= ((b[i]&0xC0)==0xC0) ? 0x00 : 0x01; + nb[i] |= ((b[i]&0x30)==0x30) ? 0x00 : 0x02; + nb[i] |= ((b[i]&0x0C)==0x0C) ? 0x00 : 0x04; + nb[i] |= ((b[i]&0x03)==0x03) ? 0x00 : 0x08; } - fprintf(stdout, "BUTTON:TYPE=WAVEMAN,"); - fprintf(stdout, "ID= %c,", 'A'+nb[0]); - fprintf(stdout, "CHANNEL=%d,", (nb[1]>>2)+1); - fprintf(stdout, "PRESSED=%d,", (nb[1]&3)+1); - fprintf(stdout, "STATE=%s\n", (nb[2]==0xe) ? "on" : "off"); - fprintf(stderr, "%02x %02x %02x\n",nb[0],nb[1],nb[2]); - - if (debug_output) - debug_callback(bb, bits_per_row); + id_str[0] = 'A'+nb[0]; + id_str[1] = 0; + data = data_make("model", NULL, DATA_STRING, "Waveman Switch Transmitter", + "id", NULL, DATA_STRING, id_str, + "channel", NULL, DATA_INT, (nb[1]>>2)+1, + "button", NULL, DATA_INT, (nb[1]&3)+1, + "state", NULL, DATA_STRING, (nb[2]==0xe) ? "on" : "off", + NULL); + data_acquired_handler(data); return 1; } return 0; } +static char *output_fields[] = { + "model", + "id", + "channel", + "button", + "state", + NULL +}; + + r_device waveman = { - /* .id = */ 6, - /* .name = */ "Waveman Switch Transmitter", - /* .modulation = */ OOK_PWM_P, - /* .short_limit = */ 1000/4, - /* .long_limit = */ 8000/4, - /* .reset_limit = */ 30000/4, - /* .json_callback = */ &waveman_callback, + .name = "Waveman Switch Transmitter", + .modulation = OOK_PULSE_PWM_RAW, + .short_limit = 1000, + .long_limit = 8000, + .reset_limit = 30000, + .json_callback = &waveman_callback, + .disabled = 0, + .demod_arg = 1, // Remove startbit + .fields = output_fields };