mirror of
https://github.com/seahu/rflink.git
synced 2026-01-24 19:05:35 +01:00
first commit
This commit is contained in:
221
RPi_rflink/Base.cpp
Normal file
221
RPi_rflink/Base.cpp
Normal file
@@ -0,0 +1,221 @@
|
||||
#include "Base.h"
|
||||
#include <wiringPi.h>
|
||||
// My header files
|
||||
#include "server.h"
|
||||
#include "Plug.h"
|
||||
|
||||
//****************************************************************************************************************************************
|
||||
// seting start values for global variables and strutures
|
||||
|
||||
void(*Reboot)(void)=0; // reset function on adres 0.
|
||||
byte PKSequenceNumber=0; // 1 byte packet counter
|
||||
boolean RFDebug=false; // debug RF signals with plugin 001
|
||||
boolean RFUDebug=false; // debug RF signals with plugin 254
|
||||
boolean QRFDebug=false;
|
||||
byte logLevel=4; // log level (0-nothing, 1-error log, 2-warning, 3-running status, 4-debug)
|
||||
|
||||
struct RawSignalStruct RawSignal={0,0,0,0,0,0L}; // Raw signal variabelen places in a struct
|
||||
|
||||
byte PIN_RF_TX_DATA=DEFAUL_PIN_RF_TX_DATA ; // Data to the 433Mhz transmitter on this pin (wiringpi numbering)
|
||||
byte PIN_RF_RX_DATA=DEFAULT_PIN_RF_RX_DATA; // On this input, the 433Mhz-RF signal is received. LOW when no signal. (wiringpi numbering)
|
||||
|
||||
// ===============================================================================
|
||||
unsigned long RepeatingTimer=0L;
|
||||
unsigned long SignalCRC=0L; // holds the bitstream value for some plugins to identify RF repeats
|
||||
unsigned long SignalHash=0L; // holds the processed plugin number
|
||||
unsigned long SignalHashPrevious=0L; // holds the last processed plugin number
|
||||
|
||||
|
||||
char pbuffer[PRINT_BUFFER_SIZE]; // Buffer for printing data
|
||||
char InputBuffer_Serial[BUFSIZE]; // Buffer for input data this name is uset in PluginTX_XXX function therefore this is alias to inBuf from server.cpp
|
||||
|
||||
// serial port emulation for print and write functions
|
||||
Ser Serial;
|
||||
|
||||
// log functions
|
||||
void log(int level,std::string str, boolean endLine) // log withou end line
|
||||
{
|
||||
if (level<=logLevel) {
|
||||
std::cout << str;
|
||||
if (endLine==true) std::cout << std::endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void log(int level, std::string str) { // log witj end line
|
||||
return log(level, str, true);
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
wiringPiSetup();
|
||||
//serialOpen(BAUD); // Initialise the serial port
|
||||
pinMode(PIN_RF_RX_DATA, INPUT); // Initialise in/output ports
|
||||
pinMode(PIN_RF_TX_DATA, OUTPUT); // Initialise in/output ports
|
||||
pinMode(PIN_RF_TX_VCC, OUTPUT); // Initialise in/output ports
|
||||
pinMode(PIN_RF_RX_VCC, OUTPUT); // Initialise in/output ports
|
||||
digitalWrite(PIN_RF_RX_VCC,HIGH); // turn VCC to RF receiver ON
|
||||
digitalWrite(PIN_RF_RX_DATA,PUD_UP); // pull-up resister on (to prevent garbage)
|
||||
|
||||
pinMode(PIN_BSF_0,OUTPUT); // rflink board switch signal
|
||||
digitalWrite(PIN_BSF_0,HIGH); // rflink board switch signal
|
||||
|
||||
Serial.ini(); // ini mutex for print line
|
||||
|
||||
//PKSequenceNumber++;
|
||||
PluginInit();
|
||||
PluginTXInit();
|
||||
}
|
||||
|
||||
int serve_input(char* inBuf){
|
||||
strncpy(InputBuffer_Serial,inBuf,BUFSIZE);
|
||||
//InputBuffer_Serial=inBuf; // create alias from inBuf to global bariable InputBuffer_Serial uset in PluginTX_XXX function
|
||||
byte ValidCommand=0;
|
||||
//Serial.print("20;incoming;");
|
||||
//Serial.println(InputBuffer_Serial);
|
||||
log(LOG_STATUS,"Client incoming: ",false);
|
||||
log(LOG_STATUS,InputBuffer_Serial);
|
||||
|
||||
if (strlen(InputBuffer_Serial) > 7){ // need to see minimal 8 characters on the serial port
|
||||
// 10;....;..;ON;
|
||||
if (strncmp (InputBuffer_Serial,"10;",3) == 0) { // Command from Master to RFLink
|
||||
// -------------------------------------------------------
|
||||
// Handle Device Management Commands
|
||||
// -------------------------------------------------------
|
||||
if (strcasecmp(InputBuffer_Serial+3,"PING;")==0) {
|
||||
sprintf(InputBuffer_Serial,"20;%02X;PONG;",PKSequenceNumber++);
|
||||
Serial.println(InputBuffer_Serial);
|
||||
} else
|
||||
if (strcasecmp(InputBuffer_Serial+3,"REBOOT;")==0) {
|
||||
strcpy(InputBuffer_Serial,"reboot");
|
||||
return -1;
|
||||
} else
|
||||
if (strncasecmp(InputBuffer_Serial+3,"RFDEBUG=O",9) == 0) {
|
||||
if (InputBuffer_Serial[12] == 'N' || InputBuffer_Serial[12] == 'n' ) {
|
||||
RFDebug=true; // full debug on
|
||||
RFUDebug=false; // undecoded debug off
|
||||
QRFDebug=false; // undecoded debug off
|
||||
sprintf(InputBuffer_Serial,"20;%02X;RFDEBUG=ON;",PKSequenceNumber++);
|
||||
} else {
|
||||
RFDebug=false; // full debug off
|
||||
sprintf(InputBuffer_Serial,"20;%02X;RFDEBUG=OFF;",PKSequenceNumber++);
|
||||
}
|
||||
Serial.println(InputBuffer_Serial);
|
||||
} else
|
||||
if (strncasecmp(InputBuffer_Serial+3,"RFUDEBUG=O",10) == 0) {
|
||||
if (InputBuffer_Serial[13] == 'N' || InputBuffer_Serial[13] == 'n') {
|
||||
RFUDebug=true; // undecoded debug on
|
||||
QRFDebug=false; // undecoded debug off
|
||||
RFDebug=false; // full debug off
|
||||
sprintf(InputBuffer_Serial,"20;%02X;RFUDEBUG=ON;",PKSequenceNumber++);
|
||||
} else {
|
||||
RFUDebug=false; // undecoded debug off
|
||||
sprintf(InputBuffer_Serial,"20;%02X;RFUDEBUG=OFF;",PKSequenceNumber++);
|
||||
}
|
||||
Serial.println(InputBuffer_Serial);
|
||||
} else
|
||||
if (strncasecmp(InputBuffer_Serial+3,"QRFDEBUG=O",10) == 0) {
|
||||
if (InputBuffer_Serial[13] == 'N' || InputBuffer_Serial[13] == 'n') {
|
||||
QRFDebug=true; // undecoded debug on
|
||||
RFUDebug=false; // undecoded debug off
|
||||
RFDebug=false; // full debug off
|
||||
sprintf(InputBuffer_Serial,"20;%02X;QRFDEBUG=ON;",PKSequenceNumber++);
|
||||
} else {
|
||||
QRFDebug=false; // undecoded debug off
|
||||
sprintf(InputBuffer_Serial,"20;%02X;QRFDEBUG=OFF;",PKSequenceNumber++);
|
||||
}
|
||||
Serial.println(InputBuffer_Serial);
|
||||
} else
|
||||
if (strncasecmp(InputBuffer_Serial+3,"VERSION",7) == 0) {
|
||||
sprintf(InputBuffer_Serial,"20;%02X;VER=1.1;REV=%02x;BUILD=%02x;",PKSequenceNumber++,REVNR, BUILDNR);
|
||||
Serial.println(InputBuffer_Serial);
|
||||
} else {
|
||||
// -------------------------------------------------------
|
||||
// Handle Generic Commands / Translate protocol data into Nodo text commands
|
||||
// -------------------------------------------------------
|
||||
// check plugins
|
||||
if (InputBuffer_Serial[strlen(InputBuffer_Serial)-1]==';') InputBuffer_Serial[strlen(InputBuffer_Serial)-1]=0; // remove last ";" char
|
||||
if(PluginTXCall(0, InputBuffer_Serial)) {
|
||||
ValidCommand=1;
|
||||
} else {
|
||||
// Answer that an invalid command was received?
|
||||
ValidCommand=2;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // if > 7
|
||||
if (ValidCommand != 0) {
|
||||
if (ValidCommand==1) {
|
||||
sprintf(InputBuffer_Serial,"20;%02X;OK;",PKSequenceNumber++);
|
||||
Serial.println( InputBuffer_Serial );
|
||||
} else {
|
||||
sprintf(InputBuffer_Serial, "20;%02X;CMD UNKNOWN;", PKSequenceNumber++); // Node and packet number
|
||||
Serial.println( InputBuffer_Serial );
|
||||
}
|
||||
}
|
||||
// odemknout mutex pro vystup s RX (aby se nemotala odpoved na vstup s vystupen z projmace)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void help(char *argv) {
|
||||
printf("Use:\n %s \n %s TCP_port_number \n %s TCP_port_number log_level_number \n %s TCP_port_number TX_PIN RX_PIN \n %s TCP_port_number TX_PIN RX_PIN log_level_number.\n or %s -h for this help\n\n TCP_port_number: 1-65535\n log_level number: 0-nothing, 1-error log, 2-warning, 3-running status, 4-debug\n TX_PIN - transmitter pin (by wiringpi numbering)\n TR_PIN - receiver pin (by wiringpi numbering)\n",argv, argv, argv, argv, argv, argv );
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int port=DEFAULT_TCP_PORT;
|
||||
int scan_log=logLevel; // form sscanf("%d", int) who make with int not byte
|
||||
int scan_pin_tx=PIN_RF_TX_DATA;
|
||||
int scan_pin_rx=PIN_RF_RX_DATA;
|
||||
|
||||
switch(argc)
|
||||
{
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
if (strcmp(argv[1],"-h")!=0 and \
|
||||
sscanf(argv[1],"%d",&port)!=EOF ) break;
|
||||
help(argv[0]);
|
||||
return false;
|
||||
case 3:
|
||||
if (sscanf(argv[1],"%d",&port)!=EOF and \
|
||||
sscanf(argv[2],"%d",&scan_log)!=EOF and \
|
||||
( scan_log>=0 and scan_log<=4 ) ) break;
|
||||
help(argv[0]);
|
||||
return false;
|
||||
case 4:
|
||||
if (sscanf(argv[1],"%d",&port)!=EOF and \
|
||||
sscanf(argv[2],"%d",&scan_pin_tx)!=EOF and \
|
||||
sscanf(argv[3],"%d",&scan_pin_rx)!=EOF ) break;
|
||||
help(argv[0]);
|
||||
return false;
|
||||
case 5:
|
||||
if (sscanf(argv[1],"%d",&port)!=EOF and \
|
||||
sscanf(argv[2],"%d",&scan_pin_tx)!=EOF and \
|
||||
sscanf(argv[3],"%d",&scan_pin_rx)!=EOF and \
|
||||
sscanf(argv[4],"%d",&scan_log)!=EOF and
|
||||
( scan_log>=0 and scan_log<=4 ) )
|
||||
break;
|
||||
help(argv[0]);
|
||||
return false;
|
||||
default:
|
||||
help(argv[0]);
|
||||
return false;
|
||||
|
||||
}
|
||||
logLevel=(byte) scan_log;
|
||||
PIN_RF_TX_DATA=(byte) scan_pin_tx;
|
||||
PIN_RF_RX_DATA=(byte) scan_pin_rx;
|
||||
|
||||
printf("Log level: %d\n",logLevel);
|
||||
sprintf(pbuffer,"TCP port: %d",port);
|
||||
log(LOG_STATUS, pbuffer);
|
||||
sprintf(pbuffer,"TX pin: %d",PIN_RF_TX_DATA);
|
||||
log(LOG_STATUS, pbuffer);
|
||||
sprintf(pbuffer,"RX pin: %d",PIN_RF_RX_DATA);
|
||||
log(LOG_STATUS, pbuffer);
|
||||
|
||||
setup();
|
||||
TCPserver(port);
|
||||
}
|
||||
/*********************************************************************************************/
|
||||
|
||||
121
RPi_rflink/Base.h
Normal file
121
RPi_rflink/Base.h
Normal file
@@ -0,0 +1,121 @@
|
||||
#ifndef _base_h
|
||||
#define _base_h
|
||||
|
||||
// C style headers
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wiringPi.h>
|
||||
// C++ style headers
|
||||
#include <iostream> // std::cout, std::ios
|
||||
#include <string>
|
||||
// My headers
|
||||
#include "./arduino/types.h"
|
||||
#include "./arduino/binary.h"
|
||||
#include "./arduino/EmulateArduino.h"
|
||||
#include "Misc.h"
|
||||
#include "RawSignal.h"
|
||||
|
||||
#define WELCOME "20;00;Nodo RadioFrequencyLink - RFLink Gateway V1.1 - "
|
||||
#define DEFAULT_TCP_PORT 5050 // defaul TCP port for TCP server
|
||||
#define BUILDNR 0x07 // shown in version
|
||||
#define REVNR 0x33 // shown in version and startup string
|
||||
#define MIN_RAW_PULSES 20 // =8 bits. Minimal number of bits*2 that need to have been received before we spend CPU time on decoding the signal.
|
||||
#define RAWSIGNAL_SAMPLE_RATE 30 // Sample width / resolution in uSec for raw RF pulses.
|
||||
#define MIN_PULSE_LENGTH 25 // Pulses shorter than this value in uSec. will be seen as garbage and not taken as actual pulses.
|
||||
#define SIGNAL_TIMEOUT 5 // Timeout, after this time in mSec. the RF signal will be considered to have stopped.
|
||||
#define SIGNAL_REPEAT_TIME 500 // Time in mSec. in which the same RF signal should not be accepted again. Filters out retransmits.
|
||||
#define BAUD 57600 // Baudrate for serial communication.
|
||||
#define TRANSMITTER_STABLE_DELAY 500 // delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms).
|
||||
#define RAW_BUFFER_SIZE 512 // Maximum number of pulses that is received in one go.
|
||||
#define PLUGIN_MAX 55 // Maximum number of Receive plugins
|
||||
#define PLUGIN_TX_MAX 26 // Maximum number of Transmit plugins
|
||||
#define SCAN_HIGH_TIME 50 // tijdsinterval in ms. voor achtergrondtaken snelle verwerking
|
||||
#define FOCUS_TIME 50 // Duration in mSec. that, after receiving serial data from USB only the serial port is checked.
|
||||
#define INPUT_COMMAND_SIZE 60 // Maximum number of characters that a command via serial can be.
|
||||
#define PRINT_BUFFER_SIZE 60 // Maximum number of characters that a command should print in one go via the print buffer.
|
||||
#define BUFSIZE 1000 // Max size for InputBuffer_Serial and max size incoming packet from TCP server
|
||||
|
||||
// to include Config_xx.c files:
|
||||
#define stringify(x) #x
|
||||
#define CONFIGFILE2(a, b) stringify(a/Config/b)
|
||||
#define CONFIGFILE(a, b) CONFIGFILE2(a, b)
|
||||
#define CONFIG_FILE Config_02.c
|
||||
#define SKETCH_PATH ../
|
||||
#include CONFIGFILE(SKETCH_PATH,CONFIG_FILE)
|
||||
|
||||
#define VALUE_PAIR 44
|
||||
#define VALUE_ALLOFF 55
|
||||
#define VALUE_OFF 74
|
||||
#define VALUE_ON 75
|
||||
#define VALUE_DIM 76
|
||||
#define VALUE_BRIGHT 77
|
||||
#define VALUE_UP 78
|
||||
#define VALUE_DOWN 79
|
||||
#define VALUE_STOP 80
|
||||
#define VALUE_CONFIRM 81
|
||||
#define VALUE_LIMIT 82
|
||||
#define VALUE_ALLON 141
|
||||
|
||||
// PIN Definition
|
||||
// This pin is not the first pin on the RPi GPIO header!
|
||||
// Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
|
||||
// for more information.
|
||||
#define PIN_BSF_0 27 // Board Specific Function lijn-0
|
||||
#define PIN_BSF_1 27 // Board Specific Function lijn-1
|
||||
#define PIN_BSF_2 27 // Board Specific Function lijn-2
|
||||
#define PIN_BSF_3 27 // Board Specific Function lijn-3
|
||||
#define PIN_RF_TX_VCC 27 // +5 volt / Vcc power to the transmitter on this pin
|
||||
#define DEFAUL_PIN_RF_TX_DATA 28 // Data to the 433Mhz transmitter on this pin (wiringpi numbering)
|
||||
#define PIN_RF_RX_VCC 27 // Power to the receiver on this pin
|
||||
#define DEFAULT_PIN_RF_RX_DATA 29 // On this input, the 433Mhz-RF signal is received. LOW when no signal. (wiringpi numbering)
|
||||
|
||||
#define LOG_NOTHING 0
|
||||
#define LOG_ERROR 1
|
||||
#define LOG_WARNING 2
|
||||
#define LOG_STATUS 3
|
||||
#define LOG_DEBUG 4
|
||||
#define LOG_HARD_DEBUG 5
|
||||
|
||||
struct RawSignalStruct // Raw signal variabelen places in a struct
|
||||
{
|
||||
int Number; // Number of pulses, times two as every pulse has a mark and a space.
|
||||
byte Repeats; // Number of re-transmits on transmit actions.
|
||||
byte Delay; // Delay in ms. after transmit of a single RF pulse packet
|
||||
byte Multiply; // Pulses[] * Multiply is the real pulse time in microseconds
|
||||
unsigned long Time; // Timestamp indicating when the signal was received (millis())
|
||||
byte Pulses[RAW_BUFFER_SIZE+2]; // Table with the measured pulses in microseconds divided by RawSignal.Multiply. (halves RAM usage) // First pulse is located in element 1. Element 0 is used for special purposes, like signalling the use of a specific plugin
|
||||
};
|
||||
|
||||
extern struct RawSignalStruct RawSignal;
|
||||
|
||||
extern byte PIN_RF_TX_DATA; // Data to the 433Mhz transmitter on this pin (wiringpi numbering)
|
||||
extern byte PIN_RF_RX_DATA; // On this input, the 433Mhz-RF signal is received. LOW when no signal. (wiringpi numbering)
|
||||
|
||||
extern unsigned long RepeatingTimer;
|
||||
extern unsigned long SignalCRC; // holds the bitstream value for some plugins to identify RF repeats
|
||||
extern unsigned long SignalHash; // holds the processed plugin number
|
||||
extern unsigned long SignalHashPrevious; // holds the last processed plugin number
|
||||
|
||||
//****************************************************************************************************************************************
|
||||
extern byte PKSequenceNumber; // 1 byte packet counter
|
||||
extern boolean RFDebug; // debug RF signals with plugin 001
|
||||
extern boolean RFUDebug; // debug RF signals with plugin 254
|
||||
extern boolean QRFDebug; // debug RF signals with plugin 254 but no multiplication
|
||||
extern byte logLevel; // log level (0-nothing, 1-error log, 2-warning, 3-running status, 4-debug)
|
||||
|
||||
extern char pbuffer[PRINT_BUFFER_SIZE]; // Buffer for printing data
|
||||
extern char InputBuffer_Serial[BUFSIZE]; // Buffer for input data this name is uset in PluginTX_XXX function therefore this is alias to inBuf from server.cpp
|
||||
|
||||
|
||||
// serial port emulation for print and write functions
|
||||
extern Ser Serial;
|
||||
|
||||
// protoype log function
|
||||
void log(int level, std::string str, boolean endLine); // log withou endline
|
||||
void log(int level, std::string str); // log with endline
|
||||
|
||||
//functions prototype for serve incoming packet
|
||||
int serve_input(char* InputBuffer_Serial);
|
||||
|
||||
#endif
|
||||
156
RPi_rflink/Makefile
Normal file
156
RPi_rflink/Makefile
Normal file
@@ -0,0 +1,156 @@
|
||||
|
||||
|
||||
# Defines the RPI variable which is needed by rc-switch/RCSwitch.h
|
||||
CXXFLAGS=-DRPI
|
||||
|
||||
# configuration file for plugins placed into directory ../../Config/
|
||||
CONFIG_PLUGINS="Config_02.c"
|
||||
|
||||
#all: send codesend RFSniffer
|
||||
all: | prepare
|
||||
|
||||
# prepare (generate) files for plagins and filess need for compile
|
||||
prepare: | createDirPlugins ./Plugins/Make_Generated_list_plugin.txt ./Plugins/Make_Generated_all_h.h ./Plugins/Make_Generated_all_RX.h ./Plugins/Make_Generated_all_TX.h
|
||||
$(MAKE) RFlink
|
||||
|
||||
# variable object conatin project files for compilation with .o (make use default macros for create .o from .c or .cpp)
|
||||
objects = ./Base.o ./RawSignal.o ./server.o ./Plug.o ./Misc.o ./arduino/EmulateArduino.o
|
||||
#objects =
|
||||
|
||||
# NOTICE main diference between = and :=
|
||||
#---------------------------------------
|
||||
# name_variable = $(shell cmd) # this will be actualize every time vhen $(name_variable) is call
|
||||
# name_variable := $(shell cmd) # this will be set only one when start make
|
||||
|
||||
# example howto generate variable form files in directory and coincided rename items of variable to .o
|
||||
#allowed_plagins = $(patsubst %.h,%.o,$(wildcard ./Plugins/Plugin_*.h))
|
||||
|
||||
# examle howto generate variable from shell (only one command may be used not sequence )
|
||||
allowed_plagins = $(shell cat ./Plugins/Make_Generated_list_plugin.txt )
|
||||
|
||||
RFlink: $(objects) $(allowed_plagins)
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi -lpthread
|
||||
|
||||
clean:
|
||||
$(RM) ./RFlink ./*.o ./*.gch ./arduino/*.o ./arduino/*.gch ./Plugins/* ; rmdir ./Plugins
|
||||
|
||||
|
||||
#---------------------------------------------- install/uninstall-------------------------------------------------------------------------
|
||||
# must be run as sudo (sudo make install)
|
||||
install: ./RFlink
|
||||
if ! [ -d "/opt/rflink" ] ; then mkdir "/opt/rflink"; fi ;
|
||||
if ! [ -f "/opt/rflink/RFlink" ] ; then cp "./RFlink" "/opt/rflink/" ; fi ;
|
||||
if ! [ -f "/etc/rflink.conf" ] ; then cp "./etc/rflink.conf" "/etc/" ; fi ;
|
||||
if ! [ -f "/etc/init.d/rflink.sh" ] ; then cp "./etc/init.d/rflink.sh" "/etc/init.d/" ; fi
|
||||
|
||||
# must be run as sudo (sudo make uninstall)
|
||||
uninstall:
|
||||
if [ -f "/etc/init.d/rflink.sh" ] ; then rm "/etc/init.d/rflink.sh" ; fi
|
||||
if [ -f "/etc/rflink.conf" ] ; then rm "/etc/rflink.conf" ; fi ;
|
||||
if [ -f "/opt/rflink/RFlink" ] ; then rm "/opt/rflink/RFlink" ; fi ;
|
||||
if [ -d "/opt/rflink" ] ; then rmdir "/opt/rflink"; fi ;
|
||||
|
||||
# enable autostart RFlink service after start system
|
||||
autostart_on: /opt/rflink/RFlink
|
||||
update-rc.d rflink.sh enable
|
||||
/etc/init.d/rflink.sh start
|
||||
|
||||
# disable auto start RFlink service after start system
|
||||
autostart_off: /opt/rflink/RFlink
|
||||
/etc/init.d/rflink.sh stop
|
||||
update-rc.d rflink.sh disable
|
||||
|
||||
#---------------------------------------------- GENERATE FILES -------------------------------------------------------------------------
|
||||
|
||||
#create dir with pugins if not exist
|
||||
createDirPlugins:
|
||||
if ! [ -d ./Plugins ] ; then mkdir "./Plugins"; fi ;
|
||||
|
||||
# generate not only list of allowed plugins but also .cpp, .h files for allowed plagins
|
||||
# file "Make_Generated_list_plugin.txt" contain name of allowed plafin with .o used later for generate variable with list files for compile
|
||||
# .cpp and .h contain nessesery files for compile plugins
|
||||
./Plugins/Make_Generated_list_plugin.txt:
|
||||
cd ./Plugins; \
|
||||
for i in `ls ../../Plugins/Plugin_*.c`;do \
|
||||
n=$${i#*_}; \
|
||||
n=$${n%.*}; \
|
||||
if grep -q "^#define PLUGIN_$$n" "../../Config/$(CONFIG_PLUGINS)"; then \
|
||||
echo -n "./Plugins/Plugin_$$n.o " >> ./Make_Generated_list_plugin.txt; \
|
||||
\
|
||||
echo "//This file is generated by GNU make, do not edit." >> ./Plugin_$$n.cpp; \
|
||||
echo "#include \"Plugin_$$n.h\"" >> ./Plugin_$$n.cpp; \
|
||||
echo "#ifdef PLUGIN_$$n" >> ./Plugin_$$n.cpp; \
|
||||
echo "#include \"../../Plugins/Plugin_$$n.c\"" >> ./Plugin_$$n.cpp; \
|
||||
echo "#endif" >> ./Plugin_$$n.cpp; \
|
||||
\
|
||||
echo "//This file is generated by GNU make, do not edit." >> ./Plugin_$$n.h; \
|
||||
echo -n "#ifndef _plugin_$$n" >> ./Plugin_$$n.h; \
|
||||
echo "_h" >> ./Plugin_$$n.h; \
|
||||
echo -n " #define _plugin_$$n" >> ./Plugin_$$n.h; \
|
||||
echo "_h" >> ./Plugin_$$n.h; \
|
||||
echo " #include \"../../Config/$(CONFIG_PLUGINS)\"" >> ./Plugin_$$n.h; \
|
||||
echo " #ifdef PLUGIN_$$n" >> ./Plugin_$$n.h; \
|
||||
echo " #include \"../Base.h\"" >> ./Plugin_$$n.h; \
|
||||
echo " //prototype functions" >> ./Plugin_$$n.h; \
|
||||
echo " boolean Plugin_$$n(byte function, char *string);" >> ./Plugin_$$n.h; \
|
||||
if grep -q "^#define PLUGIN_TX_$$n" "../../Config/$(CONFIG_PLUGINS)"; then \
|
||||
echo " boolean PluginTX_$$n(byte function, char *string);" >> ./Plugin_$$n.h; \
|
||||
fi; \
|
||||
echo " #endif" >> ./Plugin_$$n.h; \
|
||||
echo "#endif" >> ./Plugin_$$n.h; \
|
||||
fi; \
|
||||
done;
|
||||
|
||||
# Generate Make_Generated_all_h.h file contain include directives for all plugins:
|
||||
# #include "./Plugins/Plugin_001.h"
|
||||
# #include "./Plugins/Plugin_002.h"
|
||||
# ...
|
||||
# ..
|
||||
./Plugins/Make_Generated_all_h.h:
|
||||
echo "//This file is generated by GNU make, do not edit.\n//This generated file is used in ../Plug.h ." >> ./Plugins/Make_Generated_all_h.h; \
|
||||
cd ./Plugins; \
|
||||
for i in `ls ./Plugin_*.h`;do \
|
||||
echo "#include \"$$i\"" >> ./Make_Generated_all_h.h; \
|
||||
done;
|
||||
|
||||
|
||||
# Generate Make_Generated_all_RX.h file contain block C++ code init RX function plugins.
|
||||
# Only for enable plugin in ..\Config\Config_02.c. Example:
|
||||
# Plugin_id[x]=1;Plugin_ptr[x++]=&Plugin_001;
|
||||
# Plugin_id[x]=2;Plugin_ptr[x++]=&Plugin_002;
|
||||
# ...
|
||||
# ..
|
||||
./Plugins/Make_Generated_all_RX.h:
|
||||
cd ./Plugins; \
|
||||
echo "//This file is generated by GNU make, do not edit." >> ./Make_Generated_all_RX.h; \
|
||||
echo "//This generated file is used in ../Plug.h ." >> ./Make_Generated_all_RX.h; \
|
||||
x=1; \
|
||||
for i in `ls Plugin_*.h`;do \
|
||||
n=$${i#*_}; \
|
||||
n=$${n%.*}; \
|
||||
if grep -q "^#define PLUGIN_$$n" "../../Config/$(CONFIG_PLUGINS)"; then \
|
||||
echo "Plugin_id[x]=$$x;Plugin_ptr[x++]=&Plugin_$$n;" >> ./Make_Generated_all_RX.h; \
|
||||
x=$$(($$x+1)); \
|
||||
fi; \
|
||||
done;
|
||||
|
||||
# Generate Make_Generated_all_TX.h file contain block C++ code init TX function plugins.
|
||||
# Only for enable plugin in ..\Config\Config_02.c. Example:
|
||||
# PluginTX_id[x]=1;PluginTX_ptr[x++]=&Plugin_001;
|
||||
# PluginTX_id[x]=2;PluginTX_ptr[x++]=&Plugin_002;
|
||||
# ...
|
||||
# ..
|
||||
./Plugins/Make_Generated_all_TX.h:
|
||||
cd ./Plugins; \
|
||||
echo "//This file is generated by GNU make, do not edit." >> ./Make_Generated_all_TX.h; \
|
||||
echo "//This generated file is used in ../Plug.h ." >> ./Make_Generated_all_TX.h; \
|
||||
x=1; \
|
||||
for i in `ls Plugin_*.h`;do \
|
||||
n=$${i#*_}; \
|
||||
n=$${n%.*}; \
|
||||
if grep -q "^#define PLUGIN_TX_$$n" "../../Config/$(CONFIG_PLUGINS)"; then \
|
||||
echo "PluginTX_id[x]=$$x;PluginTX_ptr[x++]=&PluginTX_$$n;" >> ./Make_Generated_all_TX.h; \
|
||||
x=$$(($$x+1)); \
|
||||
fi; \
|
||||
done;
|
||||
|
||||
84
RPi_rflink/Misc.cpp
Normal file
84
RPi_rflink/Misc.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "Misc.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Convert HEX or DEC tring to unsigned long HEX, DEC
|
||||
\*********************************************************************************************/
|
||||
unsigned long str2int(char *string) {
|
||||
return(strtoul(string,NULL,0));
|
||||
}
|
||||
/*********************************************************************************************\
|
||||
* Convert string to command code
|
||||
\*********************************************************************************************/
|
||||
int str2cmd(char *command) {
|
||||
if(strcasecmp(command,"ON") == 0) return VALUE_ON;
|
||||
if(strcasecmp(command,"OFF") == 0) return VALUE_OFF;
|
||||
if(strcasecmp(command,"ALLON") == 0) return VALUE_ALLON;
|
||||
if(strcasecmp(command,"ALLOFF") == 0) return VALUE_ALLOFF;
|
||||
if(strcasecmp(command,"PAIR") == 0) return VALUE_PAIR;
|
||||
if(strcasecmp(command,"DIM") == 0) return VALUE_DIM;
|
||||
if(strcasecmp(command,"BRIGHT") == 0) return VALUE_BRIGHT;
|
||||
if(strcasecmp(command,"UP") == 0) return VALUE_UP;
|
||||
if(strcasecmp(command,"DOWN") == 0) return VALUE_DOWN;
|
||||
if(strcasecmp(command,"STOP") == 0) return VALUE_STOP;
|
||||
if(strcasecmp(command,"CONFIRM") == 0) return VALUE_CONFIRM;
|
||||
if(strcasecmp(command,"LIMIT") == 0) return VALUE_LIMIT;
|
||||
return false;
|
||||
}
|
||||
/********************************************************************************************\
|
||||
* Convert unsigned long to float long through memory
|
||||
\*********************************************************************************************/
|
||||
float ul2float(unsigned long ul) {
|
||||
float f;
|
||||
memcpy(&f, &ul,4);
|
||||
return f;
|
||||
}
|
||||
/*********************************************************************************************/
|
||||
void PrintHex8(uint8_t *data, uint8_t length) { // prints 8-bit data in hex (lowercase)
|
||||
char tmp[length*2+1];
|
||||
byte first ;
|
||||
int j=0;
|
||||
for (uint8_t i=0; i<length; i++) {
|
||||
first = (data[i] >> 4) | 48;
|
||||
if (first > 57) tmp[j] = first + (byte)39;
|
||||
else tmp[j] = first ;
|
||||
j++;
|
||||
|
||||
first = (data[i] & 0x0F) | 48;
|
||||
if (first > 57) tmp[j] = first + (byte)39;
|
||||
else tmp[j] = first;
|
||||
j++;
|
||||
}
|
||||
tmp[length*2] = 0;
|
||||
Serial.print(tmp);
|
||||
}
|
||||
/*********************************************************************************************/
|
||||
// todo: make uppercase? 3a = 3 or 48 (0x30) = 0x33 >57 (0x39) a>3a >39 > +27
|
||||
void PrintHexByte(uint8_t data) { // prints 8-bit value in hex (single byte)
|
||||
char tmp[3];
|
||||
byte first ;
|
||||
first = (data >> 4) | 48; // or with 0x30
|
||||
if (first > 57) tmp[0] = first + (byte)7; // 39; // if > 0x39 add 0x27
|
||||
else tmp[0] = first ;
|
||||
|
||||
first = (data & 0x0F) | 48;
|
||||
if (first > 57) tmp[1] = first + (byte)7; // 39;
|
||||
else tmp[1] = first;
|
||||
tmp[2] = 0;
|
||||
Serial.print(tmp);
|
||||
}
|
||||
/*********************************************************************************************/
|
||||
// Reverse all bits in a byte
|
||||
byte reverseBits(byte data) {
|
||||
byte b = data;
|
||||
for (byte i = 0; i < 8; ++i) {
|
||||
data = (data << 1) | (b & 1);
|
||||
b >>= 1;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/*********************************************************************************************/
|
||||
|
||||
16
RPi_rflink/Misc.h
Normal file
16
RPi_rflink/Misc.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _misc_h
|
||||
#define _misc_h
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
#define HEX 1
|
||||
|
||||
unsigned long str2int(char *string);
|
||||
|
||||
int str2cmd(char *command);
|
||||
float ul2float(unsigned long ul);
|
||||
void PrintHex8(uint8_t *data, uint8_t length);
|
||||
void PrintHexByte(uint8_t data);
|
||||
byte reverseBits(byte data);
|
||||
|
||||
#endif
|
||||
146
RPi_rflink/Plug.cpp
Normal file
146
RPi_rflink/Plug.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
#include "Plug.h"
|
||||
|
||||
/**********************************************************************************************\
|
||||
* Load plugins
|
||||
* oreginal file name plugin.c, bat with this name g++ compiler have problem
|
||||
* therefore I create Plugin_001.cpp who contain #include to oreginal Plugin_001.c
|
||||
* and I create Plugin_001.h who contain all nessery headers file for compile and enable
|
||||
* use those modules in main program
|
||||
* Those files is generated by GNU make (only for enabled plagin in ../Config/Config_02.c)
|
||||
* PS: by GNU make is also generated files who is used here:
|
||||
* ./Plugins/Make_Generated_all_h.h
|
||||
* ./Plugins/Make_Generated_all_RX.h
|
||||
* ./Plugins/Make_Generated_all_TX.h
|
||||
\*********************************************************************************************/
|
||||
/**********************************************
|
||||
* example Plugin_001.cpp :
|
||||
*
|
||||
* #include "Plugin_001.h"
|
||||
* #ifdef PLUGIN_001
|
||||
* #include "../../Plugins/Plugin_001.c"
|
||||
* #endif
|
||||
**********************************************/
|
||||
/**********************************************
|
||||
* example Plugin_001.h :
|
||||
*
|
||||
* #ifndef _plugin_001_h
|
||||
* #define _plugin_001_h
|
||||
* #include "../../Config/Config_02.c"
|
||||
* #ifdef PLUGIN_001
|
||||
* #include "../Global.h"
|
||||
* //prototype functions
|
||||
* boolean Plugin_001(byte function, char *string);
|
||||
* #endif
|
||||
* #endif
|
||||
* *********************************************/
|
||||
|
||||
|
||||
// Van alle devices die worden mee gecompileerd, worden in een tabel de adressen opgeslagen zodat hier naar toe gesprongen kan worden
|
||||
boolean (*Plugin_ptr[PLUGIN_MAX])(byte, char*); // Receive plugins
|
||||
byte Plugin_id[PLUGIN_MAX];
|
||||
boolean (*PluginTX_ptr[PLUGIN_TX_MAX])(byte, char*); // Transmit plugins
|
||||
byte PluginTX_id[PLUGIN_TX_MAX];
|
||||
|
||||
|
||||
/*********************************************************************************************/
|
||||
void PluginInit(void)
|
||||
{
|
||||
byte x;
|
||||
|
||||
// Wis de pointertabel voor de plugins.
|
||||
for(x=0;x<PLUGIN_MAX;x++)
|
||||
{
|
||||
Plugin_ptr[x]=0;
|
||||
Plugin_id[x]=0;
|
||||
}
|
||||
|
||||
x=0;
|
||||
/*** examle entry of below includet file ***
|
||||
#ifdef PLUGIN_001
|
||||
Plugin_id[x]=1;Plugin_ptr[x++]=&Plugin_001;
|
||||
#endif
|
||||
********************************************/
|
||||
#include "./Plugins/Make_Generated_all_RX.h"
|
||||
// Initialiseer alle plugins door aanroep met verwerkingsparameter PLUGIN_INIT
|
||||
PluginInitCall(0,0);
|
||||
}
|
||||
/*********************************************************************************************/
|
||||
void PluginTXInit(void)
|
||||
{
|
||||
byte x;
|
||||
|
||||
// Wis de pointertabel voor de plugins.
|
||||
for(x=0;x<PLUGIN_TX_MAX;x++)
|
||||
{
|
||||
PluginTX_ptr[x]=0;
|
||||
PluginTX_id[x]=0;
|
||||
}
|
||||
|
||||
x=0;
|
||||
/*** examle entry of below includet file ***
|
||||
#ifdef PLUGIN_TX_001
|
||||
PluginTX_id[x]=1;PluginTX_ptr[x++]=&PluginTX_001;
|
||||
#endif
|
||||
********************************************/
|
||||
#include "./Plugins/Make_Generated_all_TX.h"
|
||||
// Initialiseer alle plugins door aanroep met verwerkingsparameter PLUGINTX_INIT
|
||||
PluginTXInitCall(0,0);
|
||||
}
|
||||
/*********************************************************************************************\
|
||||
* This function initializes the Receive plugin function table
|
||||
\*********************************************************************************************/
|
||||
byte PluginInitCall(byte Function, char *str) {
|
||||
int x;
|
||||
|
||||
for (x=0; x<PLUGIN_MAX; x++) {
|
||||
if (Plugin_id[x]!=0) {
|
||||
Plugin_ptr[x](Function,str);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*********************************************************************************************\
|
||||
* This function initializes the Transmit plugin function table
|
||||
\*********************************************************************************************/
|
||||
byte PluginTXInitCall(byte Function, char *str) {
|
||||
int x;
|
||||
|
||||
for (x=0; x<PLUGIN_TX_MAX; x++) {
|
||||
if (PluginTX_id[x]!=0) {
|
||||
PluginTX_ptr[x](Function,str);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*********************************************************************************************\
|
||||
* With this function plugins are called that have Receive functionality.
|
||||
\*********************************************************************************************/
|
||||
byte PluginRXCall(byte Function, char *str) {
|
||||
int x;
|
||||
|
||||
for (x=0; x<PLUGIN_MAX; x++) {
|
||||
if (Plugin_id[x]!=0) {
|
||||
SignalHash=x; // store plugin number
|
||||
if (Plugin_ptr[x](Function,str)) {
|
||||
SignalHashPrevious=SignalHash; // store previous plugin number after success
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*********************************************************************************************\
|
||||
* With this function plugins are called that have Transmit functionality.
|
||||
\*********************************************************************************************/
|
||||
byte PluginTXCall(byte Function, char *str) {
|
||||
int x;
|
||||
|
||||
for (x=0; x<PLUGIN_TX_MAX; x++) {
|
||||
if (PluginTX_id[x]!=0) {
|
||||
if (PluginTX_ptr[x](Function,str)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
79
RPi_rflink/Plug.h
Normal file
79
RPi_rflink/Plug.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#ifndef _Plugin_h
|
||||
#define _Plugin_h
|
||||
|
||||
#include "Base.h"
|
||||
/*
|
||||
#include "./Plugins/Plugin_001.h"
|
||||
#include "./Plugins/Plugin_002.h"
|
||||
#include "./Plugins/Plugin_003.h"
|
||||
#include "./Plugins/Plugin_004.h"
|
||||
#include "./Plugins/Plugin_005.h"
|
||||
#include "./Plugins/Plugin_006.h"
|
||||
#include "./Plugins/Plugin_007.h"
|
||||
#include "./Plugins/Plugin_008.h"
|
||||
#include "./Plugins/Plugin_009.h"
|
||||
#include "./Plugins/Plugin_010.h"
|
||||
#include "./Plugins/Plugin_011.h"
|
||||
#include "./Plugins/Plugin_012.h"
|
||||
#include "./Plugins/Plugin_013.h"
|
||||
#include "./Plugins/Plugin_014.h"
|
||||
#include "./Plugins/Plugin_015.h"
|
||||
#include "./Plugins/Plugin_030.h"
|
||||
#include "./Plugins/Plugin_031.h"
|
||||
#include "./Plugins/Plugin_032.h"
|
||||
#include "./Plugins/Plugin_033.h"
|
||||
#include "./Plugins/Plugin_034.h"
|
||||
#include "./Plugins/Plugin_035.h"
|
||||
#include "./Plugins/Plugin_040.h"
|
||||
#include "./Plugins/Plugin_041.h"
|
||||
#include "./Plugins/Plugin_042.h"
|
||||
#include "./Plugins/Plugin_043.h"
|
||||
#include "./Plugins/Plugin_044.h"
|
||||
#include "./Plugins/Plugin_045.h"
|
||||
#include "./Plugins/Plugin_046.h"
|
||||
#include "./Plugins/Plugin_048.h"
|
||||
#include "./Plugins/Plugin_060.h"
|
||||
#include "./Plugins/Plugin_061.h"
|
||||
#include "./Plugins/Plugin_062.h"
|
||||
#include "./Plugins/Plugin_063.h"
|
||||
#include "./Plugins/Plugin_070.h"
|
||||
#include "./Plugins/Plugin_071.h"
|
||||
#include "./Plugins/Plugin_072.h"
|
||||
#include "./Plugins/Plugin_073.h"
|
||||
#include "./Plugins/Plugin_074.h"
|
||||
#include "./Plugins/Plugin_075.h"
|
||||
#include "./Plugins/Plugin_080.h"
|
||||
//#include "./Plugins/Plugin_081.h"
|
||||
#include "./Plugins/Plugin_082.h"
|
||||
#include "./Plugins/Plugin_090.h"
|
||||
#include "./Plugins/Plugin_100.h"
|
||||
#include "./Plugins/Plugin_254.h"
|
||||
*/
|
||||
|
||||
#include "./Plugins/Make_Generated_all_h.h"
|
||||
|
||||
//#define PLUGIN_001
|
||||
|
||||
//prototypes
|
||||
void PluginInit(void);
|
||||
void PluginTXInit(void);
|
||||
byte PluginInitCall(byte Function, char *str);
|
||||
byte PluginTXInitCall(byte Function, char *str);
|
||||
byte PluginRXCall(byte Function, char *str);
|
||||
byte PluginTXCall(byte Function, char *str);
|
||||
|
||||
// Van alle devices die worden mee gecompileerd, worden in een tabel de adressen opgeslagen zodat hier naar toe gesprongen kan worden
|
||||
extern boolean (*Plugin_ptr[PLUGIN_MAX])(byte, char*); // Receive plugins
|
||||
extern byte Plugin_id[PLUGIN_MAX];
|
||||
extern boolean (*PluginTX_ptr[PLUGIN_TX_MAX])(byte, char*); // Transmit plugins
|
||||
extern byte PluginTX_id[PLUGIN_TX_MAX];
|
||||
|
||||
//example Plugin_001.cpp :
|
||||
//
|
||||
//#include "Plugin_001.h"
|
||||
//#ifdef PLUGIN_001
|
||||
//#include "../../Plugins/Plugin_001.c"
|
||||
//#endif
|
||||
|
||||
|
||||
#endif
|
||||
167
RPi_rflink/RawSignal.cpp
Normal file
167
RPi_rflink/RawSignal.cpp
Normal file
@@ -0,0 +1,167 @@
|
||||
#include "RawSignal.h"
|
||||
// Include libraries for RPi:
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <wiringPi.h>
|
||||
// Thread
|
||||
#include <pthread.h>
|
||||
// My header files
|
||||
#include "Base.h"
|
||||
#include "Plug.h" // for PluginRXCall() and
|
||||
|
||||
|
||||
bool enableRawScan=true; // flag for end RawSignal thread
|
||||
|
||||
bool ReceiverInterrupt=false; // flag signalzet enabled or disabled interupt (exist because for Raspberry Pi (wiringPi) you can't unregister the ISR)
|
||||
pthread_cond_t thread_flag_cv;
|
||||
pthread_mutex_t thread_flag_mutex;
|
||||
pthread_t threadScanEvent_id; // struct for id of scanevent theader
|
||||
|
||||
// Oreginaly this function was run cycle with timeout so that can be serve serial line input
|
||||
// Now run continualy with waiting for new data who get from function calling by interrupt.
|
||||
// So that consume min. resources for wait is used conditional variable and whole function ScanEvent is execute in separate thread/
|
||||
boolean ScanEvent() { // Deze routine maakt deel uit van de hoofdloop en wordt iedere 125uSec. doorlopen
|
||||
enableRawScan=true;
|
||||
// init mutex and conditional varibale
|
||||
pthread_mutex_init(&thread_flag_mutex, NULL);
|
||||
pthread_cond_init(&thread_flag_cv, NULL);
|
||||
// enable Receive (interupt)
|
||||
enableReceive(); // use only for start iterupt receivre (can't use reparetly becouse for Raspberry Pi (wiringPi) you can't unregister the ISR)
|
||||
pthread_mutex_lock(&thread_flag_mutex);
|
||||
while (enableRawScan==true){
|
||||
log(LOG_HARD_DEBUG,"RawSignal: Wait for packet.");
|
||||
pthread_cond_wait(&thread_flag_cv, &thread_flag_mutex); // wait for new packed
|
||||
ReceiverInterrupt=false; // disable Receive
|
||||
PluginRXCall(0,0); // Check all plugins to see which plugin can handle the received signal.
|
||||
ReceiverInterrupt=true; // anable Receivre
|
||||
}
|
||||
disableReceive();
|
||||
pthread_mutex_unlock(&thread_flag_mutex);
|
||||
}
|
||||
|
||||
// prepare scanEvent function to be main function for new theader (must have right format and argument)
|
||||
void* p_scanEvent(void* unused){
|
||||
ScanEvent();
|
||||
}
|
||||
|
||||
// create theader with function &p_ScanEvent
|
||||
int StartScanEventTheader(){
|
||||
pthread_create(&threadScanEvent_id, NULL, &p_scanEvent, NULL);
|
||||
log(LOG_STATUS,"RawSignal: Scan event theader started.");
|
||||
}
|
||||
|
||||
// Stop theader
|
||||
int StopScanEventTheader(){
|
||||
enableRawScan=false;
|
||||
setRawSignal(0); // send signal to unblock conditional variable (for anable end ScanEvent cycle)
|
||||
pthread_join(threadScanEvent_id, NULL);
|
||||
log(LOG_STATUS,"RawSignal: Scan event theader stoped.");
|
||||
}
|
||||
|
||||
// Process sampling data.
|
||||
// Because proces samples data is time consuming and function for serve interrupt must by very short.
|
||||
// This function only fill in RawSignal struture and unlock condition varible used in function ScanEvent() who do main work for process data.
|
||||
void setRawSignal(int RawCodeLength){
|
||||
pthread_mutex_lock(&thread_flag_mutex);
|
||||
|
||||
RawSignal.Repeats=0; // no repeats
|
||||
RawSignal.Multiply=RAWSIGNAL_SAMPLE_RATE; // sample size.
|
||||
RawSignal.Number=RawCodeLength-1; // Number of received pulse times (pulsen *2)
|
||||
RawSignal.Pulses[RawSignal.Number+1]=0; // Last element contains the timeout.
|
||||
RawSignal.Time=millis(); // Time the RF packet was received (to keep track of retransmits
|
||||
RawCodeLength=1; // Start at 1 for legacy reasons. Element 0 can be used to pass special information like plugin number etc.
|
||||
//place for threader conditions set
|
||||
pthread_cond_signal(&thread_flag_cv);
|
||||
|
||||
pthread_mutex_unlock(&thread_flag_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
// handle interrupt
|
||||
void handleInterrupt() {
|
||||
if (ReceiverInterrupt==false) return; // if no enabled interrupt fast end
|
||||
static unsigned long lastTime = 0;
|
||||
static unsigned long PulseLength=0L;
|
||||
static int RawCodeLength=1; // Start at 1 for legacy reasons. Element 0 can be used to pass special information like plugin number etc.
|
||||
// oreginaly algorithm have some code for reduce noise, bat I do not understand this code, therefore I this code removed, otherwise must be retype this code for run in interrrupt.
|
||||
const long time = micros();
|
||||
PulseLength = time - lastTime;
|
||||
lastTime = time;
|
||||
|
||||
if ( RawCodeLength<RAW_BUFFER_SIZE ) {
|
||||
RawSignal.Pulses[RawCodeLength++]=4+PulseLength/(unsigned long)(RAWSIGNAL_SAMPLE_RATE); // store in RawSignal !!!! (+4 is corection beatwen arduino cycle time calculate and real time from raspberryPi)
|
||||
}
|
||||
else { // Raw data reach max size
|
||||
setRawSignal(RawCodeLength);
|
||||
PulseLength=0L;
|
||||
RawCodeLength=1;
|
||||
return;
|
||||
}
|
||||
if ( PulseLength < MIN_PULSE_LENGTH or PulseLength >= SIGNAL_TIMEOUT*1000 ) { // puls is so short -> this is no packet or time out
|
||||
//Serial.println("S");
|
||||
if (RawCodeLength>=MIN_RAW_PULSES) { // Raw data satisfy min. size
|
||||
setRawSignal(RawCodeLength);
|
||||
}
|
||||
PulseLength=0L;
|
||||
RawCodeLength=1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable receiving data (use only for start interrupt receivre)
|
||||
*/
|
||||
void enableReceive() {
|
||||
ReceiverInterrupt=true;
|
||||
RawSignal.Number=0;
|
||||
RawSignal.Repeats=0;
|
||||
RawSignal.Delay=0; // Delay in ms. after transmit of a single RF pulse packet
|
||||
RawSignal.Multiply=0; // Pulses[] * Multiply is the real pulse time in microseconds
|
||||
RawSignal.Time=0; // Timestamp indicating when the signal was received (millis())
|
||||
RawSignal.Pulses[0]=0;
|
||||
log(LOG_HARD_DEBUG,"RawSignal: Enable interrupt.");
|
||||
wiringPiISR(PIN_RF_RX_DATA, INT_EDGE_BOTH, &handleInterrupt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable receiving data
|
||||
*/
|
||||
void disableReceive() {
|
||||
ReceiverInterrupt=false;
|
||||
// For Raspberry Pi (wiringPi) you can't unregister the ISR
|
||||
}
|
||||
|
||||
/*********************************************************************************************/
|
||||
// RFLink Board specific: Generate a short pulse to switch the Aurel Transceiver from TX to RX mode.
|
||||
void RFLinkHW( void ) {
|
||||
delayMicroseconds(36);
|
||||
digitalWrite(PIN_BSF_0,LOW);
|
||||
delayMicroseconds(16);
|
||||
digitalWrite(PIN_BSF_0,HIGH);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Send rawsignal buffer to RF * DEPRICATED * DO NOT USE *
|
||||
\*********************************************************************************************/
|
||||
void RawSendRF(void) { // * DEPRICATED * DO NOT USE *
|
||||
int x;
|
||||
disableReceive();
|
||||
RawSignal.Pulses[RawSignal.Number]=1; // due to a bug in Arduino 1.0.1
|
||||
|
||||
for(byte y=0; y<RawSignal.Repeats; y++) { // herhaal verzenden RF code
|
||||
x=1;
|
||||
//noInterrupts();
|
||||
while(x<RawSignal.Number) {
|
||||
digitalWrite(PIN_RF_TX_DATA,HIGH);
|
||||
delayMicroseconds(RawSignal.Pulses[x++]*RawSignal.Multiply-5); // min een kleine correctie
|
||||
digitalWrite(PIN_RF_TX_DATA,LOW);
|
||||
delayMicroseconds(RawSignal.Pulses[x++]*RawSignal.Multiply-7); // min een kleine correctie
|
||||
}
|
||||
//interrupts();
|
||||
if (y+1 < RawSignal.Repeats) delay(RawSignal.Delay); // Delay buiten het gebied waar de interrupts zijn uitgeschakeld! Anders werkt deze funktie niet.
|
||||
}
|
||||
enableReceive();
|
||||
}
|
||||
/*********************************************************************************************/
|
||||
21
RPi_rflink/RawSignal.h
Normal file
21
RPi_rflink/RawSignal.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef _RawSignal_h
|
||||
#define _RawSignal_h
|
||||
|
||||
#include "./arduino/types.h"
|
||||
|
||||
// flag for end RawSignal thread
|
||||
extern bool enableRawScan;
|
||||
|
||||
//global use prototypes:
|
||||
int StartScanEventTheader();
|
||||
int StopScanEventTheader();
|
||||
void RFLinkHW( void );
|
||||
void RawSendRF(void);
|
||||
|
||||
//local use prototypes:
|
||||
void enableReceive();
|
||||
void disableReceive();
|
||||
boolean ScanEvent();
|
||||
void setRawSignal(int RawCodeLength);
|
||||
|
||||
#endif
|
||||
105
RPi_rflink/arduino/EmulateArduino.cpp
Normal file
105
RPi_rflink/arduino/EmulateArduino.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include "EmulateArduino.h"
|
||||
#include <sstream> // std::ostringstream
|
||||
#include <pthread.h> // for mutex
|
||||
|
||||
int (*send_function)(const char*, const int); // define pointer to send_function (this my by set for function send line by socket)
|
||||
|
||||
// print lilne mutex (safe, that print line will not break print from another threader)
|
||||
pthread_mutex_t print_line_mutex;
|
||||
|
||||
// output string buffer
|
||||
std::ostringstream outBuf;
|
||||
|
||||
/*
|
||||
* add end line for Ser::prints functions and send this line throught socket by pointer into send_function
|
||||
*/
|
||||
void Ser::enter(){
|
||||
pthread_mutex_lock(&print_line_mutex); // lock mutex
|
||||
|
||||
outBuf << "\r\n";
|
||||
if ( send_function!=NULL ) (*send_function)(outBuf.str().c_str(),outBuf.str().size());
|
||||
outBuf.str(""); // erase buffer for nex use
|
||||
|
||||
pthread_mutex_unlock(&print_line_mutex); // unlock mutex
|
||||
}
|
||||
|
||||
void Ser::set_send_function(int (*fnc)(const char*, const int)=NULL){
|
||||
send_function=fnc;
|
||||
}
|
||||
|
||||
void Ser::ini(void){ // ini mutext for print line
|
||||
pthread_mutex_init(&print_line_mutex, NULL);
|
||||
send_function=NULL;
|
||||
}
|
||||
|
||||
|
||||
void Ser::print(void){
|
||||
return;
|
||||
}
|
||||
|
||||
void Ser::println(void){
|
||||
return Ser::enter();
|
||||
}
|
||||
|
||||
void Ser::print(const char* s ){
|
||||
outBuf << s << std::flush;
|
||||
return;
|
||||
}
|
||||
|
||||
void Ser::println(const char* s ){
|
||||
outBuf << s;
|
||||
return Ser::enter();
|
||||
}
|
||||
|
||||
void Ser::print(int n ){
|
||||
outBuf << n;
|
||||
return;
|
||||
}
|
||||
|
||||
void Ser::print(long n ){
|
||||
outBuf << n;
|
||||
return;
|
||||
}
|
||||
|
||||
void Ser::println(long n ){
|
||||
//std::cout << n << "\n" << std::flush;
|
||||
outBuf << n ;
|
||||
return Ser::enter();
|
||||
}
|
||||
|
||||
void Ser::write(const char* s ){
|
||||
outBuf << s;
|
||||
return;
|
||||
}
|
||||
void Ser::write(const char s ){
|
||||
outBuf << s ;
|
||||
return;
|
||||
}
|
||||
|
||||
void Ser::println(unsigned long n, int i){
|
||||
if (i==1) { //hex print number
|
||||
outBuf << std::hex << n << std::dec;
|
||||
}
|
||||
else {
|
||||
outBuf << n;
|
||||
}
|
||||
return Ser::enter();
|
||||
}
|
||||
|
||||
void Ser::println(unsigned long* n, int i){
|
||||
if (i==1) { //hex print number
|
||||
outBuf << std::hex << n << std::dec;
|
||||
}
|
||||
else {
|
||||
outBuf << n;
|
||||
}
|
||||
return Ser::enter();
|
||||
}
|
||||
|
||||
|
||||
// map function from arduino
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max)
|
||||
{
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
||||
34
RPi_rflink/arduino/EmulateArduino.h
Normal file
34
RPi_rflink/arduino/EmulateArduino.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef _emulate_arduino_h
|
||||
#define _emulate_arduino_h
|
||||
|
||||
#define F(x) x // redefine macro from arduino
|
||||
|
||||
// class simulate arduino Serial class
|
||||
class Ser
|
||||
{
|
||||
public:
|
||||
void ini(void);
|
||||
void set_send_function(int (*fnc)(const char*, const int)); // can set function for send line etc. by tcp socket, if is NULL no print
|
||||
void print(void);
|
||||
void println(void);
|
||||
void print(const char* s );
|
||||
void println(const char* s );
|
||||
void print(int n );
|
||||
void print(long n );
|
||||
void println(long n );
|
||||
void write(const char* s );
|
||||
void write(const char s);
|
||||
|
||||
void println(unsigned long n, int i);
|
||||
void println(unsigned long* n, int i);
|
||||
|
||||
private:
|
||||
void enter(); // function who call function set in set_send_function()
|
||||
|
||||
};
|
||||
|
||||
// prototype other function from arduino
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max);
|
||||
|
||||
#endif
|
||||
|
||||
266
RPi_rflink/arduino/Inspiration/Print.cpp
Normal file
266
RPi_rflink/arduino/Inspiration/Print.cpp
Normal file
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
Print.cpp - Base class that provides print() and println()
|
||||
Copyright (c) 2008 David A. Mellis. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Modified 23 November 2006 by David A. Mellis
|
||||
Modified 03 August 2015 by Chuck Todd
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
// Public Methods //////////////////////////////////////////////////////////////
|
||||
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
if (write(*buffer++)) n++;
|
||||
else break;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
PGM_P p = reinterpret_cast<PGM_P>(ifsh);
|
||||
size_t n = 0;
|
||||
while (1) {
|
||||
unsigned char c = pgm_read_byte(p++);
|
||||
if (c == 0) break;
|
||||
if (write(c)) n++;
|
||||
else break;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
return printNumber(n, 10);
|
||||
} else {
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
|
||||
do {
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, uint8_t digits)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number)) return print("nan");
|
||||
if (isinf(number)) return print("inf");
|
||||
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
n += print('.');
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)(remainder);
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
84
RPi_rflink/arduino/Inspiration/Print.h
Normal file
84
RPi_rflink/arduino/Inspiration/Print.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Print.h - Base class that provides print() and println()
|
||||
Copyright (c) 2008 David A. Mellis. All right reserved.
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef Print_h
|
||||
#define Print_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h> // for size_t
|
||||
|
||||
#include "WString.h"
|
||||
#include "Printable.h"
|
||||
|
||||
#define DEC 10
|
||||
#define HEX 16
|
||||
#define OCT 8
|
||||
#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar
|
||||
#undef BIN
|
||||
#endif
|
||||
#define BIN 2
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printFloat(double, uint8_t);
|
||||
protected:
|
||||
void setWriteError(int err = 1) { write_error = err; }
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError() { return write_error; }
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
36
RPi_rflink/arduino/Inspiration/Printable.h
Normal file
36
RPi_rflink/arduino/Inspiration/Printable.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Printable.h - Interface class that allows printing of complex types
|
||||
Copyright (c) 2011 Adrian McEwen. All right reserved.
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef Printable_h
|
||||
#define Printable_h
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
class Print;
|
||||
|
||||
/** The Printable class provides a way for new classes to allow themselves to be printed.
|
||||
By deriving from Printable and implementing the printTo method, it will then be possible
|
||||
for users to print out instances of this class by passing them into the usual
|
||||
Print::print and Print::println methods.
|
||||
*/
|
||||
|
||||
class Printable
|
||||
{
|
||||
public:
|
||||
virtual size_t printTo(Print& p) const = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
513
RPi_rflink/arduino/binary.h
Normal file
513
RPi_rflink/arduino/binary.h
Normal file
@@ -0,0 +1,513 @@
|
||||
#ifndef Binary_h
|
||||
#define Binary_h
|
||||
#define B0 0
|
||||
#define B00 0
|
||||
#define B000 0
|
||||
#define B0000 0
|
||||
#define B00000 0
|
||||
#define B000000 0
|
||||
#define B0000000 0
|
||||
#define B00000000 0
|
||||
#define B1 1
|
||||
#define B01 1
|
||||
#define B001 1
|
||||
#define B0001 1
|
||||
#define B00001 1
|
||||
#define B000001 1
|
||||
#define B0000001 1
|
||||
#define B00000001 1
|
||||
#define B10 2
|
||||
#define B010 2
|
||||
#define B0010 2
|
||||
#define B00010 2
|
||||
#define B000010 2
|
||||
#define B0000010 2
|
||||
#define B00000010 2
|
||||
#define B11 3
|
||||
#define B011 3
|
||||
#define B0011 3
|
||||
#define B00011 3
|
||||
#define B000011 3
|
||||
#define B0000011 3
|
||||
#define B00000011 3
|
||||
#define B100 4
|
||||
#define B0100 4
|
||||
#define B00100 4
|
||||
#define B000100 4
|
||||
#define B0000100 4
|
||||
#define B00000100 4
|
||||
#define B101 5
|
||||
#define B0101 5
|
||||
#define B00101 5
|
||||
#define B000101 5
|
||||
#define B0000101 5
|
||||
#define B00000101 5
|
||||
#define B110 6
|
||||
#define B0110 6
|
||||
#define B00110 6
|
||||
#define B000110 6
|
||||
#define B0000110 6
|
||||
#define B00000110 6
|
||||
#define B111 7
|
||||
#define B0111 7
|
||||
#define B00111 7
|
||||
#define B000111 7
|
||||
#define B0000111 7
|
||||
#define B00000111 7
|
||||
#define B1000 8
|
||||
#define B01000 8
|
||||
#define B001000 8
|
||||
#define B0001000 8
|
||||
#define B00001000 8
|
||||
#define B1001 9
|
||||
#define B01001 9
|
||||
#define B001001 9
|
||||
#define B0001001 9
|
||||
#define B00001001 9
|
||||
#define B1010 10
|
||||
#define B01010 10
|
||||
#define B001010 10
|
||||
#define B0001010 10
|
||||
#define B00001010 10
|
||||
#define B1011 11
|
||||
#define B01011 11
|
||||
#define B001011 11
|
||||
#define B0001011 11
|
||||
#define B00001011 11
|
||||
#define B1100 12
|
||||
#define B01100 12
|
||||
#define B001100 12
|
||||
#define B0001100 12
|
||||
#define B00001100 12
|
||||
#define B1101 13
|
||||
#define B01101 13
|
||||
#define B001101 13
|
||||
#define B0001101 13
|
||||
#define B00001101 13
|
||||
#define B1110 14
|
||||
#define B01110 14
|
||||
#define B001110 14
|
||||
#define B0001110 14
|
||||
#define B00001110 14
|
||||
#define B1111 15
|
||||
#define B01111 15
|
||||
#define B001111 15
|
||||
#define B0001111 15
|
||||
#define B00001111 15
|
||||
#define B10000 16
|
||||
#define B010000 16
|
||||
#define B0010000 16
|
||||
#define B00010000 16
|
||||
#define B10001 17
|
||||
#define B010001 17
|
||||
#define B0010001 17
|
||||
#define B00010001 17
|
||||
#define B10010 18
|
||||
#define B010010 18
|
||||
#define B0010010 18
|
||||
#define B00010010 18
|
||||
#define B10011 19
|
||||
#define B010011 19
|
||||
#define B0010011 19
|
||||
#define B00010011 19
|
||||
#define B10100 20
|
||||
#define B010100 20
|
||||
#define B0010100 20
|
||||
#define B00010100 20
|
||||
#define B10101 21
|
||||
#define B010101 21
|
||||
#define B0010101 21
|
||||
#define B00010101 21
|
||||
#define B10110 22
|
||||
#define B010110 22
|
||||
#define B0010110 22
|
||||
#define B00010110 22
|
||||
#define B10111 23
|
||||
#define B010111 23
|
||||
#define B0010111 23
|
||||
#define B00010111 23
|
||||
#define B11000 24
|
||||
#define B011000 24
|
||||
#define B0011000 24
|
||||
#define B00011000 24
|
||||
#define B11001 25
|
||||
#define B011001 25
|
||||
#define B0011001 25
|
||||
#define B00011001 25
|
||||
#define B11010 26
|
||||
#define B011010 26
|
||||
#define B0011010 26
|
||||
#define B00011010 26
|
||||
#define B11011 27
|
||||
#define B011011 27
|
||||
#define B0011011 27
|
||||
#define B00011011 27
|
||||
#define B11100 28
|
||||
#define B011100 28
|
||||
#define B0011100 28
|
||||
#define B00011100 28
|
||||
#define B11101 29
|
||||
#define B011101 29
|
||||
#define B0011101 29
|
||||
#define B00011101 29
|
||||
#define B11110 30
|
||||
#define B011110 30
|
||||
#define B0011110 30
|
||||
#define B00011110 30
|
||||
#define B11111 31
|
||||
#define B011111 31
|
||||
#define B0011111 31
|
||||
#define B00011111 31
|
||||
#define B100000 32
|
||||
#define B0100000 32
|
||||
#define B00100000 32
|
||||
#define B100001 33
|
||||
#define B0100001 33
|
||||
#define B00100001 33
|
||||
#define B100010 34
|
||||
#define B0100010 34
|
||||
#define B00100010 34
|
||||
#define B100011 35
|
||||
#define B0100011 35
|
||||
#define B00100011 35
|
||||
#define B100100 36
|
||||
#define B0100100 36
|
||||
#define B00100100 36
|
||||
#define B100101 37
|
||||
#define B0100101 37
|
||||
#define B00100101 37
|
||||
#define B100110 38
|
||||
#define B0100110 38
|
||||
#define B00100110 38
|
||||
#define B100111 39
|
||||
#define B0100111 39
|
||||
#define B00100111 39
|
||||
#define B101000 40
|
||||
#define B0101000 40
|
||||
#define B00101000 40
|
||||
#define B101001 41
|
||||
#define B0101001 41
|
||||
#define B00101001 41
|
||||
#define B101010 42
|
||||
#define B0101010 42
|
||||
#define B00101010 42
|
||||
#define B101011 43
|
||||
#define B0101011 43
|
||||
#define B00101011 43
|
||||
#define B101100 44
|
||||
#define B0101100 44
|
||||
#define B00101100 44
|
||||
#define B101101 45
|
||||
#define B0101101 45
|
||||
#define B00101101 45
|
||||
#define B101110 46
|
||||
#define B0101110 46
|
||||
#define B00101110 46
|
||||
#define B101111 47
|
||||
#define B0101111 47
|
||||
#define B00101111 47
|
||||
#define B110000 48
|
||||
#define B0110000 48
|
||||
#define B00110000 48
|
||||
#define B110001 49
|
||||
#define B0110001 49
|
||||
#define B00110001 49
|
||||
#define B110010 50
|
||||
#define B0110010 50
|
||||
#define B00110010 50
|
||||
#define B110011 51
|
||||
#define B0110011 51
|
||||
#define B00110011 51
|
||||
#define B110100 52
|
||||
#define B0110100 52
|
||||
#define B00110100 52
|
||||
#define B110101 53
|
||||
#define B0110101 53
|
||||
#define B00110101 53
|
||||
#define B110110 54
|
||||
#define B0110110 54
|
||||
#define B00110110 54
|
||||
#define B110111 55
|
||||
#define B0110111 55
|
||||
#define B00110111 55
|
||||
#define B111000 56
|
||||
#define B0111000 56
|
||||
#define B00111000 56
|
||||
#define B111001 57
|
||||
#define B0111001 57
|
||||
#define B00111001 57
|
||||
#define B111010 58
|
||||
#define B0111010 58
|
||||
#define B00111010 58
|
||||
#define B111011 59
|
||||
#define B0111011 59
|
||||
#define B00111011 59
|
||||
#define B111100 60
|
||||
#define B0111100 60
|
||||
#define B00111100 60
|
||||
#define B111101 61
|
||||
#define B0111101 61
|
||||
#define B00111101 61
|
||||
#define B111110 62
|
||||
#define B0111110 62
|
||||
#define B00111110 62
|
||||
#define B111111 63
|
||||
#define B0111111 63
|
||||
#define B00111111 63
|
||||
#define B1000000 64
|
||||
#define B01000000 64
|
||||
#define B1000001 65
|
||||
#define B01000001 65
|
||||
#define B1000010 66
|
||||
#define B01000010 66
|
||||
#define B1000011 67
|
||||
#define B01000011 67
|
||||
#define B1000100 68
|
||||
#define B01000100 68
|
||||
#define B1000101 69
|
||||
#define B01000101 69
|
||||
#define B1000110 70
|
||||
#define B01000110 70
|
||||
#define B1000111 71
|
||||
#define B01000111 71
|
||||
#define B1001000 72
|
||||
#define B01001000 72
|
||||
#define B1001001 73
|
||||
#define B01001001 73
|
||||
#define B1001010 74
|
||||
#define B01001010 74
|
||||
#define B1001011 75
|
||||
#define B01001011 75
|
||||
#define B1001100 76
|
||||
#define B01001100 76
|
||||
#define B1001101 77
|
||||
#define B01001101 77
|
||||
#define B1001110 78
|
||||
#define B01001110 78
|
||||
#define B1001111 79
|
||||
#define B01001111 79
|
||||
#define B1010000 80
|
||||
#define B01010000 80
|
||||
#define B1010001 81
|
||||
#define B01010001 81
|
||||
#define B1010010 82
|
||||
#define B01010010 82
|
||||
#define B1010011 83
|
||||
#define B01010011 83
|
||||
#define B1010100 84
|
||||
#define B01010100 84
|
||||
#define B1010101 85
|
||||
#define B01010101 85
|
||||
#define B1010110 86
|
||||
#define B01010110 86
|
||||
#define B1010111 87
|
||||
#define B01010111 87
|
||||
#define B1011000 88
|
||||
#define B01011000 88
|
||||
#define B1011001 89
|
||||
#define B01011001 89
|
||||
#define B1011010 90
|
||||
#define B01011010 90
|
||||
#define B1011011 91
|
||||
#define B01011011 91
|
||||
#define B1011100 92
|
||||
#define B01011100 92
|
||||
#define B1011101 93
|
||||
#define B01011101 93
|
||||
#define B1011110 94
|
||||
#define B01011110 94
|
||||
#define B1011111 95
|
||||
#define B01011111 95
|
||||
#define B1100000 96
|
||||
#define B01100000 96
|
||||
#define B1100001 97
|
||||
#define B01100001 97
|
||||
#define B1100010 98
|
||||
#define B01100010 98
|
||||
#define B1100011 99
|
||||
#define B01100011 99
|
||||
#define B1100100 100
|
||||
#define B01100100 100
|
||||
#define B1100101 101
|
||||
#define B01100101 101
|
||||
#define B1100110 102
|
||||
#define B01100110 102
|
||||
#define B1100111 103
|
||||
#define B01100111 103
|
||||
#define B1101000 104
|
||||
#define B01101000 104
|
||||
#define B1101001 105
|
||||
#define B01101001 105
|
||||
#define B1101010 106
|
||||
#define B01101010 106
|
||||
#define B1101011 107
|
||||
#define B01101011 107
|
||||
#define B1101100 108
|
||||
#define B01101100 108
|
||||
#define B1101101 109
|
||||
#define B01101101 109
|
||||
#define B1101110 110
|
||||
#define B01101110 110
|
||||
#define B1101111 111
|
||||
#define B01101111 111
|
||||
#define B1110000 112
|
||||
#define B01110000 112
|
||||
#define B1110001 113
|
||||
#define B01110001 113
|
||||
#define B1110010 114
|
||||
#define B01110010 114
|
||||
#define B1110011 115
|
||||
#define B01110011 115
|
||||
#define B1110100 116
|
||||
#define B01110100 116
|
||||
#define B1110101 117
|
||||
#define B01110101 117
|
||||
#define B1110110 118
|
||||
#define B01110110 118
|
||||
#define B1110111 119
|
||||
#define B01110111 119
|
||||
#define B1111000 120
|
||||
#define B01111000 120
|
||||
#define B1111001 121
|
||||
#define B01111001 121
|
||||
#define B1111010 122
|
||||
#define B01111010 122
|
||||
#define B1111011 123
|
||||
#define B01111011 123
|
||||
#define B1111100 124
|
||||
#define B01111100 124
|
||||
#define B1111101 125
|
||||
#define B01111101 125
|
||||
#define B1111110 126
|
||||
#define B01111110 126
|
||||
#define B1111111 127
|
||||
#define B01111111 127
|
||||
#define B10000000 128
|
||||
#define B10000001 129
|
||||
#define B10000010 130
|
||||
#define B10000011 131
|
||||
#define B10000100 132
|
||||
#define B10000101 133
|
||||
#define B10000110 134
|
||||
#define B10000111 135
|
||||
#define B10001000 136
|
||||
#define B10001001 137
|
||||
#define B10001010 138
|
||||
#define B10001011 139
|
||||
#define B10001100 140
|
||||
#define B10001101 141
|
||||
#define B10001110 142
|
||||
#define B10001111 143
|
||||
#define B10010000 144
|
||||
#define B10010001 145
|
||||
#define B10010010 146
|
||||
#define B10010011 147
|
||||
#define B10010100 148
|
||||
#define B10010101 149
|
||||
#define B10010110 150
|
||||
#define B10010111 151
|
||||
#define B10011000 152
|
||||
#define B10011001 153
|
||||
#define B10011010 154
|
||||
#define B10011011 155
|
||||
#define B10011100 156
|
||||
#define B10011101 157
|
||||
#define B10011110 158
|
||||
#define B10011111 159
|
||||
#define B10100000 160
|
||||
#define B10100001 161
|
||||
#define B10100010 162
|
||||
#define B10100011 163
|
||||
#define B10100100 164
|
||||
#define B10100101 165
|
||||
#define B10100110 166
|
||||
#define B10100111 167
|
||||
#define B10101000 168
|
||||
#define B10101001 169
|
||||
#define B10101010 170
|
||||
#define B10101011 171
|
||||
#define B10101100 172
|
||||
#define B10101101 173
|
||||
#define B10101110 174
|
||||
#define B10101111 175
|
||||
#define B10110000 176
|
||||
#define B10110001 177
|
||||
#define B10110010 178
|
||||
#define B10110011 179
|
||||
#define B10110100 180
|
||||
#define B10110101 181
|
||||
#define B10110110 182
|
||||
#define B10110111 183
|
||||
#define B10111000 184
|
||||
#define B10111001 185
|
||||
#define B10111010 186
|
||||
#define B10111011 187
|
||||
#define B10111100 188
|
||||
#define B10111101 189
|
||||
#define B10111110 190
|
||||
#define B10111111 191
|
||||
#define B11000000 192
|
||||
#define B11000001 193
|
||||
#define B11000010 194
|
||||
#define B11000011 195
|
||||
#define B11000100 196
|
||||
#define B11000101 197
|
||||
#define B11000110 198
|
||||
#define B11000111 199
|
||||
#define B11001000 200
|
||||
#define B11001001 201
|
||||
#define B11001010 202
|
||||
#define B11001011 203
|
||||
#define B11001100 204
|
||||
#define B11001101 205
|
||||
#define B11001110 206
|
||||
#define B11001111 207
|
||||
#define B11010000 208
|
||||
#define B11010001 209
|
||||
#define B11010010 210
|
||||
#define B11010011 211
|
||||
#define B11010100 212
|
||||
#define B11010101 213
|
||||
#define B11010110 214
|
||||
#define B11010111 215
|
||||
#define B11011000 216
|
||||
#define B11011001 217
|
||||
#define B11011010 218
|
||||
#define B11011011 219
|
||||
#define B11011100 220
|
||||
#define B11011101 221
|
||||
#define B11011110 222
|
||||
#define B11011111 223
|
||||
#define B11100000 224
|
||||
#define B11100001 225
|
||||
#define B11100010 226
|
||||
#define B11100011 227
|
||||
#define B11100100 228
|
||||
#define B11100101 229
|
||||
#define B11100110 230
|
||||
#define B11100111 231
|
||||
#define B11101000 232
|
||||
#define B11101001 233
|
||||
#define B11101010 234
|
||||
#define B11101011 235
|
||||
#define B11101100 236
|
||||
#define B11101101 237
|
||||
#define B11101110 238
|
||||
#define B11101111 239
|
||||
#define B11110000 240
|
||||
#define B11110001 241
|
||||
#define B11110010 242
|
||||
#define B11110011 243
|
||||
#define B11110100 244
|
||||
#define B11110101 245
|
||||
#define B11110110 246
|
||||
#define B11110111 247
|
||||
#define B11111000 248
|
||||
#define B11111001 249
|
||||
#define B11111010 250
|
||||
#define B11111011 251
|
||||
#define B11111100 252
|
||||
#define B11111101 253
|
||||
#define B11111110 254
|
||||
#define B11111111 255
|
||||
#endif
|
||||
13
RPi_rflink/arduino/types.h
Normal file
13
RPi_rflink/arduino/types.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _types_h
|
||||
#define _types_h
|
||||
//#include <type.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef bool boolean;
|
||||
typedef unsigned short word; // 2bytes
|
||||
|
||||
typedef int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#endif
|
||||
133
RPi_rflink/etc/init.d/rflink.sh
Executable file
133
RPi_rflink/etc/init.d/rflink.sh
Executable file
@@ -0,0 +1,133 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: Seahu
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Control and Sniffer devices on 433 MHz for Home Automation System
|
||||
# Description: This daemon will start 433 MHz control and sniffer and specialy used for Domoticz Home Automation System
|
||||
### END INIT INFO
|
||||
|
||||
dir="/opt/rflink"
|
||||
cmd="./RFlink"
|
||||
cmd_to_syslog="./RFlink-syslog.sh"
|
||||
user=""
|
||||
TCP_port=5050
|
||||
PIN_TX=28
|
||||
PIN_RX=29
|
||||
log_level=1
|
||||
log_file=""
|
||||
|
||||
#include config file (may redefine TCP_port, log_level, log_file)
|
||||
. /etc/rflink.conf
|
||||
|
||||
cmd="$cmd $TCP_port $PIN_TX $PIN_RX $log_level"
|
||||
cmd_to_syslog="$cmd_to_sysylog $TCP_port $PIN_TX $PIN_RX $log_level"
|
||||
|
||||
name=`basename $0`
|
||||
pid_file="/var/run/$name.pid"
|
||||
|
||||
get_pid() {
|
||||
cat "$pid_file"
|
||||
}
|
||||
|
||||
is_running() {
|
||||
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
killtree() {
|
||||
local parent=$1 child
|
||||
for child in $(ps -o ppid= -o pid= | awk "\$1==$parent {print \$2}"); do
|
||||
killtree $child
|
||||
done
|
||||
kill $parent 2> /dev/null
|
||||
}
|
||||
|
||||
start_with_logger() {
|
||||
if [ -z "$user" ]; then
|
||||
sudo $cmd | logger
|
||||
else
|
||||
sudo -u "$user" $cmd | logger
|
||||
fi
|
||||
}
|
||||
|
||||
start_with_log_file() {
|
||||
if [ -z "$user" ]; then
|
||||
sudo $cmd >> "$log_file"
|
||||
else
|
||||
sudo -u "$user" $cmd >> "$log_file"
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
if is_running; then
|
||||
echo "Already started"
|
||||
else
|
||||
echo "Starting $name"
|
||||
cd "$dir"
|
||||
if [ -z "$log_file" ]; then
|
||||
start_with_logger &
|
||||
else
|
||||
start_with_log_file &
|
||||
fi
|
||||
echo $! > "$pid_file"
|
||||
if ! is_running; then
|
||||
echo "Unable to start, see $stdout_log and $stderr_log"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
if is_running; then
|
||||
echo -n "Stopping $name.."
|
||||
killtree `get_pid`
|
||||
for i in {1..10}
|
||||
do
|
||||
if ! is_running; then
|
||||
break
|
||||
fi
|
||||
|
||||
echo -n "."
|
||||
sleep 1
|
||||
done
|
||||
echo
|
||||
|
||||
if is_running; then
|
||||
echo "Not stopped; may still be shutting down or shutdown may have failed"
|
||||
exit 1
|
||||
else
|
||||
echo "Stopped"
|
||||
if [ -f "$pid_file" ]; then
|
||||
rm "$pid_file"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "Not running"
|
||||
fi
|
||||
;;
|
||||
restart)
|
||||
$0 stop
|
||||
if is_running; then
|
||||
echo "Unable to stop, will not attempt to start"
|
||||
exit 1
|
||||
fi
|
||||
$0 start
|
||||
;;
|
||||
status)
|
||||
if is_running; then
|
||||
echo "Running"
|
||||
else
|
||||
echo "Stopped"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|status}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
17
RPi_rflink/etc/rflink.conf
Normal file
17
RPi_rflink/etc/rflink.conf
Normal file
@@ -0,0 +1,17 @@
|
||||
########################################################################################
|
||||
## Config file for RFLink service
|
||||
## RFLink service is software solution for control and collect data from wireless sensors
|
||||
## on 433MHz (686Mhz, 2.4Ghz depents on used transmitter and receiver)
|
||||
## This solution discrem wide range of sesors, socket, remote controls, door bells,
|
||||
## meteorological stations, etc. of many manufectures.
|
||||
## Is suitable for create Home automation.
|
||||
## RFLink have support for many home automation system etc.:
|
||||
## Domoticz (tested), Jeedom, Pimatic, Domotiga, OpenHAB, HoMIDoM
|
||||
## more at http://www.nemcon.nl/blog2/ or www.seahu.cz
|
||||
#######################################################################################
|
||||
|
||||
TCP_port=5050
|
||||
PIN_TX=28 # use wiringpi numbering
|
||||
PIN_RX=29 # use wiringpi numbering
|
||||
log_level=3 # 0-nothing, 1-error log, 2-warning, 3-running status, 4-debug
|
||||
log_file="" # if log_file="" then log into syslog
|
||||
121
RPi_rflink/readme.txt
Normal file
121
RPi_rflink/readme.txt
Normal file
@@ -0,0 +1,121 @@
|
||||
# About
|
||||
|
||||
Modification RFlink for run on raspberryPI. ( http://www.nemcon.nl/blog2/ )
|
||||
This modification enable connect RF tranceiver and receiver directly into free raspberryPI pins.
|
||||
Instead comunication with serial port use TCP conecction.
|
||||
This modification use interrupt and theaders for reduce cpu load.
|
||||
|
||||
|
||||
rcswitch-pi is for controlling rc remote controlled power sockets
|
||||
with the raspberry pi. Kudos to the projects [rc-switch](http://code.google.com/p/rc-switch)
|
||||
and [wiringpi](https://projects.drogon.net/raspberry-pi/wiringpi).
|
||||
I just adapted the rc-switch code to use the wiringpi library instead of
|
||||
the library provided by the arduino.
|
||||
|
||||
|
||||
## Compile and install
|
||||
#### Compile
|
||||
First you have to install the [wiringpi](https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/) library (also you can install by: apt-get install wiringpi).
|
||||
After that you can compile on this directory by executing *make* . This generate one execute file RFlink who you can run.
|
||||
|
||||
#### Install
|
||||
After taht you can copy RFlink into /opt/rflink and install initialization stript as standart linux daemon by *make install*.
|
||||
If you can automaticaly start this daemon after start system than type *make autostart_on*.
|
||||
Addions plugins may by add into standart diractory *../Plugins* and enableb in *../Config/Config_02.c* (you can change config file into *./Makefile* by edit varibale CONFIG_PLUGINS).
|
||||
|
||||
## Run from comandline
|
||||
Use:
|
||||
*/opt/rflink/RFlink*
|
||||
*/opt/rflink/RFlink TCP_port_number*
|
||||
*/opt/rflink/RFlink TCP_port_number log_level_number*
|
||||
*/opt/rflink/RFlink TCP_port_number TX_PIN RX_PIN*
|
||||
*/opt/rflink/RFlink TCP_port_number TX_PIN RX_PIN log_level_number*
|
||||
or */opt/rflink/RFlink -h* for this help
|
||||
|
||||
TCP_port_number: 1-65535
|
||||
log_level number: 0-nothing, 1-error log, 2-warning, 3-running status, 4-debug
|
||||
TX_PIN - transmitter pin (by wiringpi numbering)
|
||||
TR_PIN - receiver pin (by wiringpi numbering)
|
||||
|
||||
For view wiringpi numbering pins run command *gpio readall* or see bellow for numbering raspberryPI v3:
|
||||
+-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
|
||||
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
|
||||
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
|
||||
| | | 3.3v | | | 1 || 2 | | | 5v | | |
|
||||
| 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5V | | |
|
||||
| 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | |
|
||||
| 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 1 | ALT5 | TxD | 15 | 14 |
|
||||
| | | 0v | | | 9 || 10 | 1 | ALT5 | RxD | 16 | 15 |
|
||||
| 17 | 0 | GPIO. 0 | IN | 1 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
|
||||
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
|
||||
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
|
||||
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
|
||||
| 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | |
|
||||
| 9 | 13 | MISO | IN | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
|
||||
| 11 | 14 | SCLK | IN | 0 | 23 || 24 | 1 | IN | CE0 | 10 | 8 |
|
||||
| | | 0v | | | 25 || 26 | 1 | IN | CE1 | 11 | 7 |
|
||||
| 0 | 30 | SDA.0 | OUT | 0 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 |
|
||||
| 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | |
|
||||
| 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |
|
||||
| 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |
|
||||
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 1 | OUT | GPIO.27 | 27 | 16 |
|
||||
| 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | OUT | GPIO.28 | 28 | 20 |
|
||||
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
|
||||
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
|
||||
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
|
||||
+-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
|
||||
|
||||
PS: rigt columb is wPi
|
||||
|
||||
## run as daemon (service)
|
||||
#### Start
|
||||
*/etc/init.d/rflink start*
|
||||
|
||||
#### Stop
|
||||
*/etc/init.d/rflink stop*
|
||||
|
||||
### Configure
|
||||
*edit file /etc/rflink.conf*
|
||||
|
||||
#### defult values:
|
||||
port: 5050
|
||||
log level: 4
|
||||
PIN_TX: 28
|
||||
PIN_RX: 29
|
||||
|
||||
## Test
|
||||
1. run with default values */opt/rflink/RFlink* or own config values etc. */opt/rflink/RFlink 5050 28 29 4*
|
||||
2. run *telnet localhost 5050*
|
||||
|
||||
you can see:
|
||||
> pi@raspberrypi:~ $ telnet localhost 5050
|
||||
> Trying ::1...
|
||||
> Trying 127.0.0.1...
|
||||
> Connected to localhost.
|
||||
> Escape character is '^]'.
|
||||
> 20;00;Nodo RadioFrequencyLink - RFLink Gateway V1.1 - R33;
|
||||
|
||||
try type:
|
||||
> 10;PING;
|
||||
|
||||
you may get:
|
||||
> 20;10;PONG;
|
||||
|
||||
if RFlink detect RF activity you can get something like that:
|
||||
> 20;14;FA500;ID=0a00;SWITCH=0a00;CMD=OFF;
|
||||
|
||||
for end connection type:
|
||||
> 10;REBOOT;
|
||||
|
||||
|
||||
## Note
|
||||
This tested only witch 433MHz receiver, not test transceiver. And tested only with free aviable modules, full version contain much more no tested plugins.
|
||||
Raspberry pi generate much more eletrict noise than arduino. This is not problem for load CPU, but some time noise random generate corect data for some plugins.
|
||||
|
||||
|
||||
### Autor
|
||||
Ing. Ondrej Lycka (ondrej.lycka(at)seznam.cz)
|
||||
www.seahu.cz
|
||||
|
||||
### Licence
|
||||
GNU
|
||||
126
RPi_rflink/server.cpp
Normal file
126
RPi_rflink/server.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "server.h"
|
||||
#include <iostream>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "Base.h" // define extern int threadScanEvent_id;
|
||||
#include "RawSignal.h" // define extern bool endRawSignal;
|
||||
|
||||
#define BUFSIZE 1000
|
||||
|
||||
int clientSocket=-1; // if of client socket
|
||||
|
||||
|
||||
int socket_getline(char* buf, int size)
|
||||
{
|
||||
int i=0;
|
||||
for (i=0; i<size; i++) {
|
||||
if ( recv(clientSocket, buf+i, 1, 0) <= 0){
|
||||
clientSocket=-1;
|
||||
Serial.set_send_function(NULL); // disable Serial.println send line by socket
|
||||
log(LOG_ERROR,"TCP server: Problem with receivere data.");
|
||||
return -1;
|
||||
}
|
||||
if ( buf[i]=='\r'){ // ignor
|
||||
buf[i]=0x00;
|
||||
i--;
|
||||
}
|
||||
if ( buf[i]=='\r' or buf[i]=='\n') {
|
||||
buf[i]=0x00;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int socket_send(const char* buf, const int size)
|
||||
{
|
||||
log(LOG_DEBUG,"TCP server send: ",false);
|
||||
log(LOG_DEBUG,buf);
|
||||
int ret=send(clientSocket, buf, size, 0);
|
||||
if ( ret == -1 ) { // +1 for NUL terminator
|
||||
clientSocket=-1;
|
||||
Serial.set_send_function(NULL); // disable Serial.println send line by socket = disable this function
|
||||
log(LOG_ERROR,"TCP server: Problem send data.");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int TCPserver(int port)
|
||||
{
|
||||
log(LOG_STATUS,"TCP server: START.");
|
||||
sockaddr_in sockName; // "name" of port
|
||||
sockaddr_in clientInfo; // client who connected
|
||||
int mainSocket; // Soket
|
||||
char buf[BUFSIZE]; // Přijímací buffer
|
||||
char inBuf[BUFSIZE]; // Input buffer
|
||||
int size; // count of sender or receivered bytes
|
||||
socklen_t addrlen; // size remote addres
|
||||
|
||||
// Create main socket
|
||||
if ((mainSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
|
||||
{
|
||||
log(LOG_ERROR,"TCP server: Main socket can't be created.");
|
||||
return -1;
|
||||
}
|
||||
sockName.sin_family = AF_INET;
|
||||
sockName.sin_port = htons(port);
|
||||
sockName.sin_addr.s_addr = INADDR_ANY; //allow connect from anywhere
|
||||
if (bind(mainSocket, (sockaddr *)&sockName, sizeof(sockName)) == -1) // add name to scoket
|
||||
{
|
||||
log(LOG_ERROR,"TCP server: Problem add name to socket.");
|
||||
return -1;
|
||||
}
|
||||
if (listen(mainSocket, 10) == -1) // create reguest queue (max 10)
|
||||
{
|
||||
log(LOG_ERROR,"TCP server: Problem create reguest queue.");
|
||||
return -1;
|
||||
}
|
||||
do
|
||||
{
|
||||
sprintf(pbuffer,"TCP server: Wait for next connection on port: %d .",port);
|
||||
log(LOG_STATUS, pbuffer);
|
||||
addrlen = sizeof(clientInfo); //size struct clienInfo for function accept
|
||||
clientSocket = accept(mainSocket, (sockaddr*)&clientInfo, &addrlen); // accpet one connection from queue, client is new soccket join clinet with server
|
||||
int totalSize = 0;
|
||||
if (clientSocket == -1)
|
||||
{
|
||||
log(LOG_ERROR,"TCP server: Problem conect with client.");
|
||||
return -1;
|
||||
}
|
||||
log(LOG_STATUS,"TCP server: Client connect.");
|
||||
// --------------------- conction is stored now can work -----------------------------
|
||||
Serial.set_send_function(socket_send); // enable Serial.println send line by socket
|
||||
Serial.print(WELCOME);
|
||||
sprintf(inBuf,"R%02x;",REVNR);
|
||||
Serial.println(inBuf);
|
||||
StartScanEventTheader(); // create separate thread
|
||||
while( clientSocket!=-1 ){ // enableRawScan is use together as flag for enable server
|
||||
if (socket_getline(inBuf, BUFSIZE)==-1){ //get line into inBuf
|
||||
log(LOG_ERROR,"TCP server: End when reading input.");
|
||||
break;
|
||||
}
|
||||
//std::cout << "client input:" << inBuf << std::endl;
|
||||
if (serve_input(inBuf)==-1) { // serve line
|
||||
//std::cout << "end from input:" << std::endl;
|
||||
log(LOG_ERROR,"TCP server: End from input.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
Serial.set_send_function(NULL); // disable Serial.println send line by socket
|
||||
close(clientSocket);
|
||||
//std::cout << "Connection close." << std::endl;
|
||||
log(LOG_ERROR,"TCP server: Connection close.");
|
||||
StopScanEventTheader();
|
||||
}
|
||||
while (true);
|
||||
// next newer run (only for inspiration)
|
||||
log(LOG_STATUS,"TCP server: END.");
|
||||
close(mainSocket);
|
||||
return 0;
|
||||
}
|
||||
7
RPi_rflink/server.h
Normal file
7
RPi_rflink/server.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _server_h
|
||||
#define _server_h
|
||||
|
||||
// start TCP server
|
||||
int TCPserver(int port);
|
||||
|
||||
#endif
|
||||
8418
RPi_rflink/ukaz.txt
Normal file
8418
RPi_rflink/ukaz.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user