Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHIP_utils/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CXX=arm-linux-gnueabihf-gcc

# Defines the GETCHIP variable which is needed by rc-switch/RCSwitch.h
CXXFLAGS=-DGETCHIP

all: send codesend RFSniffer

send: ../rc-switch/CHIP_IO/source/common.o ../rc-switch/CHIP_IO/source/event_gpio.o ../rc-switch/RCSwitch.o send.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lpthread

codesend: ../rc-switch/CHIP_IO/source/common.o ../rc-switch/CHIP_IO/source/event_gpio.o ../rc-switch/RCSwitch.o codesend.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lpthread

RFSniffer: ../rc-switch/CHIP_IO/source/common.o ../rc-switch/CHIP_IO/source/event_gpio.o ../rc-switch/RCSwitch.o RFSniffer.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lpthread


clean:
$(RM) ../rc-switch/CHIP_IO/source/*.o ../rc-switch/*.o *.o send codesend servo RFSniffer

12 changes: 12 additions & 0 deletions CHIP_utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# About

This folder contains tools for controlling rc remote controlled power sockets
with [C.H.I.P](getchip.com) devices.


## Usage

After that you can compile the example program *send* by executing *make*.

## Note
The 'send' and 'sendcode' code is as yet untested. It _should_ work, but it is still being tested thoroughly. It's provided to allow you to start playing with it now.
85 changes: 85 additions & 0 deletions CHIP_utils/RFSniffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
RFSniffer

Usage: ./RFSniffer [<pulseLength>]
[] = optional

Hacked from http://code.google.com/p/rc-switch/
by @justy to provide a handy RF code sniffer
*/

#include "../rc-switch/RCSwitch.h"

extern "C" {
#include <unistd.h>
}

#include <stdlib.h>
#include <stdio.h>


RCSwitch mySwitch;



int main(int argc, char *argv[]) {

/*
output PIN is hardcoded for testing purposes
*/
int PIN;
// XIO-P* do not have a good enough time resolution to work properly
if( get_gpio_number("AP-EINT3", &PIN) == -1 )
return 2;

if (PIN != lookup_gpio_by_name("AP-EINT3")
&& PIN != lookup_gpio_by_name("AP-EINT1")
&& PIN != lookup_gpio_by_name("I2S-MCLK") // CHIP PRO
&& PIN != lookup_gpio_by_name("I2S-DI") // CHIP PRO
&& PIN != lookup_gpio_by_name("PWM1") // CHIP PRO
&& !(PIN >= lookup_gpio_by_name("XIO-P0") && PIN <= lookup_gpio_by_name("XIO-P7"))) {
printf("Callbacks currently available on AP-EINT1, AP-EINT3, and XIO-P0 to XIO-P7 only\n");
return -1;
}

if( gpio_allowed(PIN) < 1 )
return 3;
gpio_unexport(PIN);
if( gpio_export(PIN) < 0 )
return 4;

int pulseLength = 0;
if (argv[1] != NULL) pulseLength = atoi(argv[1]);

mySwitch = RCSwitch();
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
mySwitch.enableReceive(PIN);


while(1) {
usleep(10000); // only check to see if we got anything every 10ms

if (mySwitch.available()) {

int value = mySwitch.getReceivedValue();

if (value == 0) {
printf("Unknown encoding\n");
} else {

printf("Received %i\n", mySwitch.getReceivedValue() );
}

mySwitch.resetAvailable();

}


}

gpio_unexport(PIN);
exit(0);


}

65 changes: 65 additions & 0 deletions CHIP_utils/codesend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Usage: ./codesend decimalcode [protocol] [pulselength]
decimalcode - As decoded by RFSniffer
protocol - According to rc-switch definitions
pulselength - pulselength in microseconds

'codesend' hacked from 'send' by @justy

- The provided rc_switch 'send' command uses the form systemCode, unitCode, command
which is not suitable for our purposes. Instead, we call
send(code, length); // where length is always 24 and code is simply the code
we find using the RF_sniffer.ino Arduino sketch.

(Use RF_Sniffer.ino to check that RF signals are being produced by the RPi's transmitter
or your remote control)
*/
#include "../rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>


int main(int argc, char *argv[]) {
/*
output PIN is hardcoded for testing purposes
XIO-P* do not have a good enough time resolution to work properly
*/
int PIN;
if( get_gpio_number("AP-EINT3", &PIN) == -1 )
return 2;

if( gpio_allowed(PIN) < 1 )
return 3;
gpio_unexport(PIN);
if( gpio_export(PIN) < 0 )
return 4;

// Parse the first parameter to this command as an integer
int protocol = 0; // A value of 0 will use rc-switch's default value
int pulseLength = 0;

// If no command line argument is given, print the help text
if (argc == 1) {
printf("Usage: %s decimalcode [protocol] [pulselength]\n", argv[0]);
printf("decimalcode\t- As decoded by RFSniffer\n");
printf("protocol\t- According to rc-switch definitions\n");
printf("pulselength\t- pulselength in microseconds\n");
return -1;
}

// Change protocol and pulse length accroding to parameters
int code = atoi(argv[1]);
if (argc >= 3) protocol = atoi(argv[2]);
if (argc >= 4) pulseLength = atoi(argv[3]);

printf("sending code[%i]\n", code);
RCSwitch mySwitch = RCSwitch();
if (protocol != 0) mySwitch.setProtocol(protocol);
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
mySwitch.enableTransmit(PIN);

mySwitch.send(code, 24);

return 0;

}
49 changes: 49 additions & 0 deletions CHIP_utils/send.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Usage: ./send <systemCode> <unitCode> <command>
Command is 0 for OFF and 1 for ON
*/

#include "../rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[]) {

/*
output PIN is hardcoded for testing purposes
XIO-P* do not have a good enough time resolution to work properly
*/
int PIN;
if( get_gpio_number("AP-EINT3", &PIN) == -1 )
return 2;
if( gpio_allowed(PIN) < 1 )
return 3;
gpio_unexport(PIN);
if( gpio_export(PIN) < 0 )
return 4;

char* systemCode = argv[1];
int unitCode = atoi(argv[2]);
int command = atoi(argv[3]);

printf("sending systemCode[%s] unitCode[%i] command[%i]\n", systemCode, unitCode, command);
RCSwitch mySwitch = RCSwitch();
if (argv[4] != NULL) mySwitch.setPulseLength(atoi(argv[4]));
mySwitch.enableTransmit(PIN);

switch(command) {
case 1:
mySwitch.switchOn(systemCode, unitCode);
break;
case 0:
mySwitch.switchOff(systemCode, unitCode);
break;
default:
printf("command[%i] is unsupported\n", command);
gpio_unexport(PIN);
return -1;
}

gpio_unexport(PIN);
return 0;
}