Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds x10_sec device for decoding X10 Security RF signals #671

Merged
merged 11 commits into from
Jan 27, 2018

Conversation

anthonykava
Copy link
Contributor

Please be kind. This addresses issue #30 and adapts code provided by the OP. Adds an x10_sec device that decodes X10 Security signals. I'm also providing a test to rtl_433_tests.

"model", "", DATA_STRING, "X10 Security",
"id", "Device ID", DATA_STRING, x10_id_str,
"code", "Code", DATA_STRING, x10_code_str,
"remarks", "Remarks", DATA_STRING, remarks_str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remarks should probably be named event

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming to 'event'

"time", "", DATA_STRING, time_str,
"model", "", DATA_STRING, "X10 Security",
"id", "Device ID", DATA_STRING, x10_id_str,
"code", "Code", DATA_STRING, x10_code_str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't output data twice. use either code or remarks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's merit to having the hex code (code) and the human-readable event (will be 'event', 'remarks' in this version) as separate fields, e.g., for CSV or JSON output. The hex code could be in the human-readable 'event' but then you have to parse for it if you're using the output.


static int x10_sec_callback(bitbuffer_t *bitbuffer)
{
bitrow_t *bb = bitbuffer->bb;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use uint8_t *b;

char x10_id_str[5]="\0"; /* string showing hex value */
char x10_code_str[5]="\0"; /* string showing hex value */

/* validate what we received ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loop all rows, see new_template.c, then b = bitbuffer->bb[r];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing to loop per new_template.c


/* debug output */
if(debug_output)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join all braces on the previous line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving braces

if(test_a==bb[1][1] && test_b==bb[1][3])
{
/* set remarks based on code received */
switch(bb[1][2])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a space between keywords and parens if (…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding spaces

@zuckschwerdt
Copy link
Collaborator

just add more commits to this same branch.

char x10_code_str[5] = "\0"; /* string showing hex value */
char time_str[LOCAL_TIME_BUFLEN];

for ( r=0; r<bitbuffer->num_rows; ++r) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use space after opening parens

}

/* get x10_id_str, x10_code_str, and time_str ready for output */
sprintf(x10_id_str,"%02x%02x",b[0],b[4]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert space after every comma

@zuckschwerdt
Copy link
Collaborator

looks good. The indentation appears funny in some lines. I'd prefer 4 spaces instead of tabs.

test_b = b[2] ^ 0xff;
if (test_a != b[1] || test_b != b[3]) {
continue;
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this else, which reduces the indent for everything below. Otherwise it looks perfect now!

*/
test_a = b[0] ^ 0x0f;
test_b = b[2] ^ 0xff;
if (test_a != b[1] || test_b != b[3]) continue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this warning is due to integer promotion and possible sign extend on 0xff. You can get the same result without warning by:
if ((b[0] ^ 0x0f) != b[1] || (b[2] ^ b[3]) != 0xff) continue; or maybe
if ((b[0] ^ b[1]) != 0x0f || (b[2] ^ b[3]) != 0xff) continue; for consistency.

#include "util.h"

static int x10_sec_callback(bitbuffer_t *bitbuffer) {
bitrow_t *bb = bitbuffer->bb;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this var is also unused. everything else looks perfect.

@zuckschwerdt
Copy link
Collaborator

Sorry, didn't see it earlier: you need to increment #define MAX_PROTOCOLS 98 in https://github.com/merbanan/rtl_433/blob/master/include/rtl_433.h#L46

@anthonykava
Copy link
Contributor Author

Thanks for all your help, @zuckschwerdt !

@zuckschwerdt
Copy link
Collaborator

zuckschwerdt commented Jan 26, 2018

anytime ;)
With the new looping, did you notice there are 10 packets, 5x window open, then 5x window close?
This is an interesting case as the events are not separated but in a single "stream". I might add some utility logic to condense this into just two events.
Also did you notice this signal in fact has 41 bits? The last one might be the parity on the last byte (or just a stop bit).
Can you record more samples with different conditions?

@anthonykava
Copy link
Contributor Author

Yes, even before the looping, I was seeing 5x CLOSE and 5x OPEN in that sample, and I see that every time. I believe the the X10 sensors always transmit events multiple times in case of reception errors. I've seen this on the W800 RF receiver too.

I did not notice the 41-bits. I'm going to try recording more samples this weekend with a more appropriate antenna (although the stock RTL-SDR antenna did just fine at short range).

@zuckschwerdt
Copy link
Collaborator

It is common to see the same packet repeated for reliability. I wonder however why open and close are in the same run of packets? Did you quickly open and close?
The reception is fine btw, it seems rather strong. If you want to picture the signal quickly, just drop it into http://triq.net/iqs to get a spectrogram view.

@anthonykava
Copy link
Contributor Author

The sample is based on pressing the 'TEST' button on a DS10A sensor. The test button generates a CLOSE event immediately followed by an OPEN event. I can easily capture samples of the reed switch itself in operation with a delay between events. Reception should be rather strong at a distance of 20 cm! I'll upload more samples.

@anthonykava
Copy link
Contributor Author

Some quick samples with separated OPEN and CLOSE events:

x10_sec.ds10.tests.2018-01-26.2015Z.tar.gz

@zuckschwerdt
Copy link
Collaborator

So a normal signal is repeated 5 times, which could be used to increase reliability. And a close/open sequence indicates the test function (and is not useful for normal operation).
The protocol mentions that the additional bit could be a parity on the last byte 8e. If you happen to change the address, be sure to look if that bit ever changes. (Use rtl_433 -q -F json -R 0 -X x10sec:OOK_PPM_RAW:1100:2000:10000 -r FILE to quickly look at the bytes.

@zuckschwerdt zuckschwerdt merged commit e4aaa54 into merbanan:master Jan 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants