Skip to content

Commit

Permalink
Add --raw-data option from Marc Merlin
Browse files Browse the repository at this point in the history
Programs such as MisterHouse can decode the raw RF data. The raw RF data
can also be used to estimate the RF signal strength and noise by counting
the number of invalid receptions (bad size, bad check byte, bad parity).
  • Loading branch information
mmauka committed Jul 4, 2011
1 parent 710aa34 commit d6ac747
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
mochad-0.1.12

* Add --raw-data option from Marc Merlin. Programs such as MisterHouse
can decode the raw RF data.

mochad-0.1.11

* Fix xdim (extended dim) that only worked for unit code 3.
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mochad_SOURCES = mochad.c decode.c encode.c global.c x10state.c x10_write.c \
EXTRA_DIST = udev/91-usb-x10-controllers.rules hotplug2/20-usb-x10 hotplug2/mochad \
cgi/x10.pl cgi/netcat.pl cgi/getsensors.pl cgi/cgi-lib.pl \
apps/mochamon.pl apps/simplemon.pl apps/bash.sh \
apps/rfsectopl3.pl apps/x10-tk.py
apps/rfsectopl3.pl apps/x10-tk.py apps/mochad.scr

install-exec-hook:
if test -d /etc/udev/rules.d ; then \
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mochad_SOURCES = mochad.c decode.c encode.c global.c x10state.c x10_write.c \
EXTRA_DIST = udev/91-usb-x10-controllers.rules hotplug2/20-usb-x10 hotplug2/mochad \
cgi/x10.pl cgi/netcat.pl cgi/getsensors.pl cgi/cgi-lib.pl \
apps/mochamon.pl apps/simplemon.pl apps/bash.sh \
apps/rfsectopl3.pl apps/x10-tk.py
apps/rfsectopl3.pl apps/x10-tk.py apps/mochad.scr

all: all-am

Expand Down
17 changes: 17 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ house codes. This can be changed using the rftopl command (RF to PL repeater).
Please see http://sourceforge.net/apps/mediawiki/mochad/index.php?title=Main_Page
for more details on command and event messages.


If you want to debug X10 RF, or gateway raw frames to another program, you can
use the --raw-data argument.
See apps/mochad.scr for an example on how to gateway frames with misterhouse.

Another use is to simply be able to get all the raw RF frames to see if the
multiple copies received are identical (good), off by a few bits (RF marginal),
or nonsensical (bad).

07/01 23:34:42 Rx RF HouseUnit: A1 Func: Off
07/01 23:34:42 Raw data received: 5D 20 60 9F 20 DF
07/01 23:34:42 Raw data received: 5D 20 60 9F 20 DF
07/01 23:34:43 Raw data received: 5D 20 60 9F 20 DF
07/01 23:34:43 Raw data received: 5D 20 60 9F 20 DF
07/01 23:34:43 Raw data received: 5D 20 60 9F 20 DF


== Multiple controllers

The Perl program mochamon.pl shows how to monitor more than one instance of
Expand Down
29 changes: 29 additions & 0 deletions apps/mochad.scr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# By marc_soft@merlins.org.

# This script is designed to get mochad raw data to a fifo.
# This is used as an input source for misterhouse,
# See misterhouse/lib/X10_CMxx.pm for more details.

# For this script to be useful linux with udev, you'll want
# to edit /etc/udev/rules.d/91-usb-x10-controllers.rules
# and make sure this script is run instead of the mochad binary.

FIFO=/var/run/CM19a

# Kill left over daemon just in case.
killall mochad 2>/dev/null

/bin/rm $FIFO 2>/dev/null
mkfifo $FIFO

# mochad forks off.
/usr/local/bin/mochad --raw-data

( while :
do
nc localhost 1099 > $FIFO
# This will restart nc as long as the mochad daemon is running.
pgrep -f /usr/local/bin/mochad > /dev/null || break
done ) &
20 changes: 10 additions & 10 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.65 for mochad 0.1.11.
# Generated by GNU Autoconf 2.65 for mochad 0.1.12.
#
# Report bugs to <mmauka@users.sourceforge.net>.
#
Expand Down Expand Up @@ -552,8 +552,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='mochad'
PACKAGE_TARNAME='mochad'
PACKAGE_VERSION='0.1.11'
PACKAGE_STRING='mochad 0.1.11'
PACKAGE_VERSION='0.1.12'
PACKAGE_STRING='mochad 0.1.12'
PACKAGE_BUGREPORT='mmauka@users.sourceforge.net'
PACKAGE_URL=''

Expand Down Expand Up @@ -1232,7 +1232,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures mochad 0.1.11 to adapt to many kinds of systems.
\`configure' configures mochad 0.1.12 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1298,7 +1298,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of mochad 0.1.11:";;
short | recursive ) echo "Configuration of mochad 0.1.12:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1385,7 +1385,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
mochad configure 0.1.11
mochad configure 0.1.12
generated by GNU Autoconf 2.65
Copyright (C) 2009 Free Software Foundation, Inc.
Expand Down Expand Up @@ -1864,7 +1864,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by mochad $as_me 0.1.11, which was
It was created by mochad $as_me 0.1.12, which was
generated by GNU Autoconf 2.65. Invocation command line was
$ $0 $@
Expand Down Expand Up @@ -2673,7 +2673,7 @@ fi

# Define the identity of the package.
PACKAGE='mochad'
VERSION='0.1.11'
VERSION='0.1.12'


cat >>confdefs.h <<_ACEOF
Expand Down Expand Up @@ -5106,7 +5106,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by mochad $as_me 0.1.11, which was
This file was extended by mochad $as_me 0.1.12, which was
generated by GNU Autoconf 2.65. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -5163,7 +5163,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
mochad config.status 0.1.11
mochad config.status 0.1.12
configured by $0, generated by GNU Autoconf 2.65,
with options \\"\$ac_cs_config\\"
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.64])
AC_INIT([mochad], [0.1.11], [mmauka@users.sourceforge.net])
AC_INIT([mochad], [0.1.12], [mmauka@users.sourceforge.net])
#AC_CONFIG_SRCDIR([mochad.c])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])

Expand Down
6 changes: 4 additions & 2 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,10 @@ void cm15a_decode(int fd, unsigned char *buf, unsigned int len)
*p = 0x5d;
memcpy(p+1, buf, len);
len++;
cm15a_decode_rf(fd, p, len);
return;
}

if (raw_data) {
mh_sockhexdump(fd, p, len);
}

switch (*p)
Expand Down
2 changes: 2 additions & 0 deletions decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* along with mochad. If not, see <http://www.gnu.org/licenses/>.
*/

extern int raw_data;

const char *findSecEventName(unsigned char secev);

const char *findSecRemoteKeyName(unsigned char secev);
Expand Down
3 changes: 3 additions & 0 deletions global.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ int sockprintf(int fd, const char *fmt, ...);
void hexdump(void *p, size_t len);

void sockhexdump(int fd, void *p, size_t len);

void mh_sockhexdump(int fd, void *p, size_t len);

15 changes: 15 additions & 0 deletions mochad.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ void sockhexdump(int fd, void *p, size_t len)
sockprintf(fd, "%s\n", buf);
}

// Output Raw data with header for parsing by misterhouse
void mh_sockhexdump(int fd, void *p, size_t len)
{
char buf[(3*100)+1];

_hexdump(p, len, buf, sizeof(buf));
sockprintf(fd, "Raw data received: %s\n", buf);
}


static int Do_exit = 0;
static int Reattach = 0;

Expand Down Expand Up @@ -781,6 +791,9 @@ static void printcopy(void)
fflush(NULL);
}

// This affects whether decode.c will show raw frame data for debugging RF connectivity
// as well as providing raw data for parsing by users like misterhouse's X10_CMxx module.
int raw_data = 0;
int main(int argc, char *argv[])
{
int rc, i;
Expand All @@ -794,6 +807,8 @@ int main(int argc, char *argv[])
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-d") == 0)
foreground = 1;
if (strcmp(argv[i], "--raw-data") == 0)
raw_data = 1;
else if (strcmp(argv[i], "--version") == 0) {
printf("%s\n", PACKAGE_STRING);
printcopy();
Expand Down

0 comments on commit d6ac747

Please sign in to comment.