mirror of https://github.com/sebmillet/RF433any
Provides a way to build BitVector data directly
- Also provides wait_free_433(), that will execute so long as there is a signal received (whatever it is).
This commit is contained in:
parent
d3223ec490
commit
386e52e1e2
|
@ -28,8 +28,6 @@
|
|||
#include <Arduino.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
// What items to include in the debug lines:
|
||||
|
||||
static char buffer[150];
|
||||
static char progmem_reading_buffer[100];
|
||||
|
||||
|
|
|
@ -37,6 +37,9 @@ for an example.
|
|||
See [examples/02_output-signal-timings/02_output-signal-timings.ino](examples/02_output-signal-timings/02_output-signal-timings.ino)
|
||||
for another example.
|
||||
|
||||
See [examples/03_react_on_code/03_react_on_code.ino](examples/03_react_on_code/03_react_on_code.ino)
|
||||
for an example with code check.
|
||||
|
||||
|
||||
More details
|
||||
------------
|
||||
|
|
102
RF433any.cpp
102
RF433any.cpp
|
@ -418,7 +418,6 @@ byte Rail::get_band_count() const {
|
|||
#ifdef RF433ANY_DBG_RAWCODE
|
||||
const char *sts_names[] = {
|
||||
"CONT",
|
||||
"XSEP",
|
||||
"SSEP",
|
||||
"LSEP",
|
||||
"2SEP",
|
||||
|
@ -452,6 +451,61 @@ BitVector::BitVector():
|
|||
|
||||
}
|
||||
|
||||
void BitVector::prepare_BitVector_construction(short arg_nb_bits,
|
||||
short arg_nb_bytes, short n) {
|
||||
assert(arg_nb_bits > 0);
|
||||
assert((arg_nb_bits + 7) >> 3 == arg_nb_bytes);
|
||||
assert(arg_nb_bytes == n);
|
||||
array = (uint8_t*)malloc(arg_nb_bytes);
|
||||
allocated = arg_nb_bytes;
|
||||
nb_bits = arg_nb_bits;
|
||||
}
|
||||
|
||||
BitVector::BitVector(short arg_nb_bits, short arg_nb_bytes, byte b0,
|
||||
byte b1) {
|
||||
prepare_BitVector_construction(arg_nb_bits, arg_nb_bytes, 2);
|
||||
array[1] = b0;
|
||||
array[0] = b1;
|
||||
}
|
||||
|
||||
BitVector::BitVector(short arg_nb_bits, short arg_nb_bytes, byte b0, byte b1,
|
||||
byte b2) {
|
||||
prepare_BitVector_construction(arg_nb_bits, arg_nb_bytes, 3);
|
||||
array[2] = b0;
|
||||
array[1] = b1;
|
||||
array[0] = b2;
|
||||
}
|
||||
|
||||
BitVector::BitVector(short arg_nb_bits, short arg_nb_bytes, byte b0, byte b1,
|
||||
byte b2, byte b3) {
|
||||
prepare_BitVector_construction(arg_nb_bits, arg_nb_bytes, 4);
|
||||
array[3] = b0;
|
||||
array[2] = b1;
|
||||
array[1] = b2;
|
||||
array[0] = b3;
|
||||
}
|
||||
|
||||
BitVector::BitVector(short arg_nb_bits, short arg_nb_bytes, byte b0, byte b1,
|
||||
byte b2, byte b3, byte b4) {
|
||||
prepare_BitVector_construction(arg_nb_bits, arg_nb_bytes, 5);
|
||||
array[4] = b0;
|
||||
array[3] = b1;
|
||||
array[2] = b2;
|
||||
array[1] = b3;
|
||||
array[0] = b4;
|
||||
}
|
||||
|
||||
BitVector::BitVector(short arg_nb_bits, short arg_nb_bytes, byte b0, byte b1,
|
||||
byte b2, byte b3, byte b4, byte b5) {
|
||||
prepare_BitVector_construction(arg_nb_bits, arg_nb_bytes, 6);
|
||||
array[5] = b0;
|
||||
array[4] = b1;
|
||||
array[3] = b2;
|
||||
array[2] = b3;
|
||||
array[1] = b4;
|
||||
array[0] = b5;
|
||||
}
|
||||
|
||||
BitVector::~BitVector() {
|
||||
if (array)
|
||||
free(array);
|
||||
|
@ -463,6 +517,7 @@ void BitVector::add_bit(byte v) {
|
|||
if (nb_bits >= (allocated << 3)) {
|
||||
byte old_allocated = allocated;
|
||||
|
||||
// FIXME
|
||||
++allocated; // Could be another formula ('<<= 1', ...)
|
||||
|
||||
array = (uint8_t*)realloc(array, allocated);
|
||||
|
@ -1003,8 +1058,6 @@ void DecoderManchester::consume_buf() {
|
|||
} else if (buf[0] == 1 && buf[1] == 0) {
|
||||
add_data_bit(!convention);
|
||||
} else {
|
||||
// FIXME: créer register_error pour gérer ça de manière
|
||||
// cohérente entre les différents descendants de Decoder.
|
||||
++nb_errors;
|
||||
}
|
||||
} else {
|
||||
|
@ -1070,6 +1123,8 @@ volatile unsigned char Track::IH_write_head = 0;
|
|||
volatile unsigned char Track::IH_read_head = 0;
|
||||
byte Track::IH_max_pending_timings = 0;
|
||||
bool Track::IH_interrupt_handler_is_attached = false;
|
||||
volatile short Track::IH_wait_free_count_ok;
|
||||
volatile uint16_t Track::IH_wait_free_last16;
|
||||
|
||||
// Set when Track object is created
|
||||
byte Track::pin_number = 99;
|
||||
|
@ -1253,10 +1308,10 @@ inline void Track::track_eat(byte r, uint16_t d) {
|
|||
sts = STS_CONTINUED;
|
||||
} else if (r_high.status == RAIL_STP_RCVD) {
|
||||
if (r_low.status == RAIL_CLOSED || r_low.status == RAIL_FULL
|
||||
|| r_low.status == RAIL_ERROR) { // FIXME (RAIL_ERROR)
|
||||
|| r_low.status == RAIL_ERROR) {
|
||||
sts = (r_low.last_bit_recorded ? STS_LONG_SEP : STS_SHORT_SEP);
|
||||
} else if (r_low.status == RAIL_STP_RCVD) {
|
||||
sts = STS_SEP_SEP; // FIXME (Need STS_X_SEP)
|
||||
sts = STS_SEP_SEP;
|
||||
} else {
|
||||
sts = STS_ERROR;
|
||||
}
|
||||
|
@ -1513,6 +1568,43 @@ bool Track::do_events() {
|
|||
return false;
|
||||
}
|
||||
|
||||
void Track::ih_handle_interrupt_wait_free() {
|
||||
static unsigned long last_t = 0;
|
||||
|
||||
const unsigned long t = micros();
|
||||
unsigned long d = t - last_t;
|
||||
last_t = t;
|
||||
|
||||
if (d > RF433ANY_MAX_DURATION)
|
||||
d = RF433ANY_MAX_DURATION;
|
||||
|
||||
short new_bit = (d >= 200 && d <= 25000);
|
||||
short old_bit = !!(IH_wait_free_last16 & 0x8000);
|
||||
IH_wait_free_last16 <<= 1;
|
||||
IH_wait_free_last16 |= new_bit;
|
||||
|
||||
IH_wait_free_count_ok += new_bit;
|
||||
IH_wait_free_count_ok -= old_bit;
|
||||
}
|
||||
|
||||
void Track::wait_free_433() {
|
||||
if (IH_interrupt_handler_is_attached)
|
||||
return;
|
||||
|
||||
IH_wait_free_last16 = (uint16_t)0xffff;
|
||||
IH_wait_free_count_ok = 16;
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(pin_number),
|
||||
&ih_handle_interrupt_wait_free, CHANGE);
|
||||
|
||||
// 75% of the last 16 durations must be in the interval [200, 25000]
|
||||
// (that is, 12 out of 16).
|
||||
while (IH_wait_free_count_ok >= 12)
|
||||
;
|
||||
|
||||
detachInterrupt(digitalPinToInterrupt(pin_number));
|
||||
}
|
||||
|
||||
Decoder* Track::get_data_core(byte convention) {
|
||||
Decoder *pdec_head = nullptr;
|
||||
Decoder *pdec_tail = nullptr;
|
||||
|
|
22
RF433any.h
22
RF433any.h
|
@ -43,7 +43,7 @@
|
|||
#define RF433ANY_DBG_SIMULATE
|
||||
#define RF433ANY_DBG_DECODER
|
||||
#define RF433ANY_DBG_SMALL_RECORDED
|
||||
#define RF433ANY_MAX_SECTIONS 12
|
||||
#define RF433ANY_MAX_SECTIONS 10
|
||||
|
||||
#elif RF433ANY_TESTPLAN == 5 // RF433ANY_TESTPLAN
|
||||
|
||||
|
@ -198,7 +198,6 @@ class Rail {
|
|||
|
||||
typedef enum {
|
||||
STS_CONTINUED,
|
||||
STS_X_SEP, // FIXME
|
||||
STS_SHORT_SEP,
|
||||
STS_LONG_SEP,
|
||||
STS_SEP_SEP,
|
||||
|
@ -264,6 +263,19 @@ class BitVector {
|
|||
byte nb_bits;
|
||||
public:
|
||||
BitVector();
|
||||
BitVector(short arg_nb_bits, short arg_nb_bytes, byte b0, byte b1);
|
||||
BitVector(short arg_nb_bits, short arg_nb_bytes, byte b0, byte b1,
|
||||
byte b2);
|
||||
BitVector(short arg_nb_bits, short arg_nb_bytes, byte b0, byte b1,
|
||||
byte b2, byte b3);
|
||||
BitVector(short arg_nb_bits, short arg_nb_bytes, byte b0, byte b1,
|
||||
byte b2, byte b3, byte b4);
|
||||
BitVector(short arg_nb_bits, short arg_nb_bytes, byte b0, byte b1,
|
||||
byte b2, byte b3, byte b4, byte b5);
|
||||
|
||||
void prepare_BitVector_construction(short arg_nb_bits,
|
||||
short arg_nb_bytes, short n);
|
||||
|
||||
virtual ~BitVector();
|
||||
|
||||
virtual void add_bit(byte v);
|
||||
|
@ -609,6 +621,8 @@ class Track {
|
|||
static volatile unsigned char IH_read_head;
|
||||
static byte IH_max_pending_timings;
|
||||
static bool IH_interrupt_handler_is_attached;
|
||||
static volatile uint16_t IH_wait_free_last16;
|
||||
static volatile short IH_wait_free_count_ok;
|
||||
|
||||
volatile trk_t trk;
|
||||
byte count;
|
||||
|
@ -630,6 +644,7 @@ class Track {
|
|||
Track(int arg_pin_number, byte mood = DEFAULT_RAIL_MOOD);
|
||||
|
||||
static void ih_handle_interrupt();
|
||||
static void ih_handle_interrupt_wait_free();
|
||||
static byte ih_get_max_pending_timings() {
|
||||
return IH_max_pending_timings;
|
||||
}
|
||||
|
@ -651,6 +666,9 @@ class Track {
|
|||
void deactivate_recording();
|
||||
bool process_interrupt_timing();
|
||||
bool do_events();
|
||||
|
||||
void wait_free_433();
|
||||
|
||||
Decoder* get_data(uint16_t filter, byte convention = RF433ANY_CONV0);
|
||||
};
|
||||
|
||||
|
|
|
@ -51,17 +51,19 @@ const char welcome[] PROGMEM =
|
|||
"Waiting for signal\n"
|
||||
" Durations are in microseconds\n"
|
||||
" Data is output in hexdecimal\n"
|
||||
" When high durations are equal to low, they are nul\n"
|
||||
" When high durations are equal to low, they are output as zero\n"
|
||||
" Codes: (I)nconsistent, (S)ync, (U)nknown, (T)ribit, "
|
||||
"tribit i(N)verted, (M)anchester\n"
|
||||
" I: Initseq = 'high' radio signal sent once\n"
|
||||
" LS: Low Short duration\n"
|
||||
" LL: Low Long duration\n"
|
||||
" HS: High Short duration\n"
|
||||
" HL: High Long duration\n"
|
||||
" S: Separator = typically separating repeats\n"
|
||||
" S: Separator (typically separating repeats)\n"
|
||||
" U: Low signal prefix (zero most frequently)\n"
|
||||
" V: High signal prefix (zero most frequently)\n"
|
||||
" Y: First low non-coding signal, if any "
|
||||
"(only tribit inverted)\n"
|
||||
" Y: First low non-coding signal "
|
||||
"(non-zero only if encoding is tribit inverted)\n"
|
||||
" Z: Last low signal\n";
|
||||
|
||||
void setup() {
|
||||
|
@ -95,7 +97,7 @@ void loop() {
|
|||
|
||||
Decoder *pdec0 = track.get_data(RF433ANY_FD_ALL);
|
||||
Decoder *pdec = pdec0;
|
||||
while(pdec) {
|
||||
while (pdec) {
|
||||
int nb_bits = pdec->get_nb_bits();
|
||||
bool got_data = pdec->data_got_decoded();
|
||||
BitVector *pdata = pdec->take_away_data();
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
// 03_react_on_code.ino
|
||||
|
||||
// Example sketch that comes along with RF433any library
|
||||
// Shows how to trigger different actions depending on code received.
|
||||
|
||||
/*
|
||||
Copyright 2021 Sébastien Millet
|
||||
|
||||
`RF433any' 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 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
`RF433any' 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 program. If not, see
|
||||
<https://www.gnu.org/licenses>.
|
||||
*/
|
||||
|
||||
//
|
||||
// Schematic: Radio Frequencies RECEIVER plugged on D2
|
||||
//
|
||||
|
||||
#include "RF433any.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#define PIN_RFINPUT 2
|
||||
|
||||
#define ASSERT_OUTPUT_TO_SERIAL
|
||||
|
||||
#define assert(cond) { \
|
||||
if (!(cond)) { \
|
||||
assert_failed(__LINE__); \
|
||||
} \
|
||||
}
|
||||
|
||||
static void assert_failed(int line) {
|
||||
#ifdef ASSERT_OUTPUT_TO_SERIAL
|
||||
Serial.print("\ntest.ino:");
|
||||
Serial.print(line);
|
||||
Serial.println(": assertion failed, aborted.");
|
||||
#endif
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
char serial_printf_buffer[150];
|
||||
void serial_printf(const char* msg, ...)
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
|
||||
// NOTE
|
||||
// Assume Serial has been initialized (Serial.begin(...))
|
||||
void serial_printf(const char* msg, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, msg);
|
||||
|
||||
vsnprintf(serial_printf_buffer, sizeof(serial_printf_buffer), msg, args);
|
||||
va_end(args);
|
||||
Serial.print(serial_printf_buffer);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(PIN_RFINPUT, INPUT);
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
Track track(PIN_RFINPUT);
|
||||
|
||||
void loop() {
|
||||
const BitVector *code1 = new BitVector(32, 4, 0xb9, 0x35, 0x6d, 0x00);
|
||||
|
||||
track.treset();
|
||||
|
||||
while (!track.do_events())
|
||||
delay(1);
|
||||
track.wait_free_433();
|
||||
|
||||
Decoder *pdec0 = track.get_data(
|
||||
RF433ANY_FD_DECODED | RF433ANY_FD_DEDUP | RF433ANY_FD_NO_ERROR
|
||||
);
|
||||
Decoder *pdec = pdec0;
|
||||
while (pdec) {
|
||||
const BitVector *pdata = pdec->get_pdata();
|
||||
assert(pdata); // Must be the case (RF433ANY_FD_DECODED in the call to
|
||||
// get_data() above).
|
||||
char *buf = pdata->to_str();
|
||||
assert(buf);
|
||||
serial_printf("Received %c(%d): %s\n", pdec->get_id_letter(),
|
||||
pdata->get_nb_bits(), buf);
|
||||
free(buf);
|
||||
|
||||
if (!pdata->cmp(code1)) {
|
||||
serial_printf("GOT IT!\n");
|
||||
}
|
||||
|
||||
pdec = pdec->get_next();
|
||||
}
|
||||
delete pdec0;
|
||||
|
||||
delete code1;
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:tw=80:et
|
|
@ -0,0 +1,10 @@
|
|||
ARDUINO_DIR = /usr/share/arduino
|
||||
ARDUINO_LIBS = RF433any
|
||||
ARDMK_DIR = /home/sebastien/.arduino_mk
|
||||
|
||||
# USER_LIB_PATH = /home/sebastien/travail/cpp/seb/arduino/libraries
|
||||
|
||||
BOARD_TAG = uno
|
||||
MCU = atmega328
|
||||
|
||||
include $(ARDMK_DIR)/Arduino.mk
|
|
@ -0,0 +1,343 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
# am
|
||||
|
||||
# Copyright 2019, 2020, 2021 Sébastien Millet
|
||||
|
||||
# Can perform the following:
|
||||
# 1. Compile the code
|
||||
# 2. Upload to Arduino
|
||||
# 3. Read (continually) what is arriving from the USB port the Arduino is
|
||||
# connected to
|
||||
|
||||
# Versions history (as of 1.3)
|
||||
# 1.3 Output from Arduino is recorded in files named with numbers instead of
|
||||
# date-time string.
|
||||
# 1.4 Adds -t (--testplan) option, to set TESTPLAN macro
|
||||
# 1.5 -t (or --testplan) now comes with a value, so as to manage multiple test
|
||||
# plans.
|
||||
# 1.6 Updated to work fine with Arch arduino package instead of the manually
|
||||
# installed (from tar.gz source) package used so far.
|
||||
# 1.7 Renames archlinux-arduino back to arduino, and created corresponding
|
||||
# symlink (was cleaner to do s).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
VERSION=1.7
|
||||
|
||||
PORT=
|
||||
BOARD=
|
||||
SPEED=
|
||||
FQBN=
|
||||
BUILDDIR=
|
||||
RECORDDIR=out
|
||||
READSPEED=
|
||||
RECORDFILE=
|
||||
|
||||
UPLOAD="no"
|
||||
VERBOSE="no"
|
||||
CATUSB="no"
|
||||
STTY="no"
|
||||
RECORDUSB="no"
|
||||
COMPILE="yes"
|
||||
TESTPLAN=
|
||||
|
||||
DISPLAYSEP=no
|
||||
|
||||
function finish {
|
||||
if [ "${DISPLAYSEP}" == "yes" ]; then
|
||||
echo "-----END ARDUINO OUTPUT-----" | tee -a "${RECORDFILE}"
|
||||
fi
|
||||
}
|
||||
|
||||
trap finish EXIT
|
||||
|
||||
function usage {
|
||||
echo "Usage:"
|
||||
echo " am [OPTIONS...] FILE"
|
||||
echo "Compile FILE using arduino-builder."
|
||||
echo "Example: am sketch.ino"
|
||||
echo ""
|
||||
echo "ENVIRONMENT VARIABLES"
|
||||
echo " If ARDUINO_USER_LIBS is defined and non empty, then arduino-builder"
|
||||
echo " is called with the supplementary option -libraries followed by"
|
||||
echo " ARDUINO_USER_LIBS' value."
|
||||
echo ""
|
||||
echo "OPTIONS"
|
||||
echo " -h --help Display this help screen"
|
||||
echo " -V --version Output version information and quit"
|
||||
echo " -v --verbose Be more talkative"
|
||||
echo " -u --upload Upload compiled code into Arduino"
|
||||
echo " -b --board Board, either 'uno' or 'nano'"
|
||||
echo " -p --port Port, for ex. '/dev/ttyUSB0'"
|
||||
echo " -s --speed Upload speed, for ex. 115200"
|
||||
echo " Normally, speed is infered from device type:"
|
||||
echo " 115200 for Uno, 57600 for Nano"
|
||||
echo " -B --fqbn Board Fully Qualified Name, like 'arduino:avr:uno'"
|
||||
echo " -d --builddir Build directory"
|
||||
echo " -c --catusb Display (continually) what Arduino writes on USB"
|
||||
echo " --stty Tune stty properly for later communication (implied"
|
||||
echo " by --catusb)"
|
||||
echo " -r --recordusb Write USB (continually) to a file (implies -c)"
|
||||
echo " --recordfile Output file if -r option is set"
|
||||
echo " -n --nocompile Don't compile code"
|
||||
echo " --readspeed Read speed of USB. If not specified, this script"
|
||||
echo " will try to infere it from source file. If it"
|
||||
echo " fails, it'll fallback to 9600."
|
||||
echo " This option is useful only if USB is read"
|
||||
echo " (-c or --stty option set)"
|
||||
echo " -t --testplan Set TESTPLAN macro value"
|
||||
echo " (as if #define TESTPLAN VALUE)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function version {
|
||||
echo "am version ${VERSION}"
|
||||
exit
|
||||
}
|
||||
|
||||
OPTS=$(getopt -o hVvub:p:s:B:d:crnt: --long help,version,verbose,upload,board:,port:,speed:,fqbn:,builddir:,catusb,stty,recordusb,nocompile,readspeed:,recordfile:,testplan: -n 'am' -- "$@")
|
||||
|
||||
eval set -- "$OPTS"
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h | --help ) usage; shift ;;
|
||||
-V | --version ) version; shift ;;
|
||||
-v | --verbose ) VERBOSE="yes"; shift ;;
|
||||
-u | --upload ) UPLOAD="yes"; shift ;;
|
||||
-b | --board ) BOARD="$2"; shift 2 ;;
|
||||
-p | --port ) PORT="$2"; shift 2 ;;
|
||||
-s | --speed ) SPEED="$2"; shift 2 ;;
|
||||
-B | --fqbn ) FQBN="$2"; shift 2 ;;
|
||||
-d | --builddir ) BUILDDIR="$2"; shift 2 ;;
|
||||
-c | --catusb ) CATUSB="yes"; shift ;;
|
||||
-r | --recordusb ) RECORDUSB="yes"; CATUSB="yes"; shift ;;
|
||||
-n | --nocompile ) COMPILE="no"; shift ;;
|
||||
--readspeed ) READSPEED="$2"; shift 2 ;;
|
||||
--recordfile ) RECORDFILE="$2"; shift 2 ;;
|
||||
--stty ) STTY="yes"; shift ;;
|
||||
-t | --testplan ) TESTPLAN="$2"; shift 2 ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
FILE=${1:-}
|
||||
TRAILINGOPTS=${2:-}
|
||||
|
||||
if [ -n "${TRAILINGOPTS}" ]; then
|
||||
echo "Error: trailing options"
|
||||
exit 1;
|
||||
fi
|
||||
if [ -z "${FILE}" ]; then
|
||||
echo "Error: no input file"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
set +e
|
||||
|
||||
if [ -n "${BOARD}" ]; then
|
||||
if [ "${BOARD}" != "uno" ] && [ "${BOARD}" != "nano" ]; then
|
||||
echo "Error: board '${BOARD}' unknown"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
#ARDUINODIR=$(LANG='' type -a arduino \
|
||||
# | tail -n 1 \
|
||||
# | sed 's/\S\+\sis\s//')
|
||||
#ARDUINODIR=$(readlink -f "${ARDUINODIR}")
|
||||
#ARDUINODIR=$(dirname "${ARDUINODIR}")
|
||||
|
||||
ARDUINODIR=/usr/share/arduino
|
||||
|
||||
COUNTUNO=$(compgen -G '/dev/ttyACM*' | wc -l)
|
||||
COUNTNANO=$(compgen -G '/dev/ttyUSB*' | wc -l)
|
||||
|
||||
if [ -z "${BOARD}" ]; then
|
||||
if [ "${COUNTUNO}" -ge 1 ] && [ "${COUNTNANO}" -ge 1 ]; then
|
||||
echo "Error: cannot guess board, found ${COUNTUNO} uno(s), ${COUNTNANO} nano(s)"
|
||||
exit 10
|
||||
fi
|
||||
if [ "${COUNTUNO}" -ge 1 ]; then
|
||||
BOARD=uno
|
||||
elif [ "${COUNTNANO}" -ge 1 ]; then
|
||||
BOARD=nano
|
||||
fi
|
||||
if [ -z "${BOARD}" ]; then
|
||||
echo "Error: cannot guess board, none found";
|
||||
exit 10
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${UPLOAD}" == "yes" ] || [ "${CATUSB}" == "yes" ]; then
|
||||
if [ -z "${PORT}" ]; then
|
||||
if [ "${BOARD}" == "uno" ]; then
|
||||
COUNT=${COUNTUNO}
|
||||
PORT=$(compgen -G '/dev/ttyACM*')
|
||||
elif [ "${BOARD}" == "nano" ]; then
|
||||
COUNT=${COUNTNANO}
|
||||
PORT=$(compgen -G '/dev/ttyUSB*')
|
||||
else
|
||||
echo "FATAL #001, CHECK THIS CODE"
|
||||
exit 99
|
||||
fi
|
||||
|
||||
if [ "${COUNT}" -ge 2 ]; then
|
||||
echo "Error: cannot guess port, more than 1 board '${BOARD}' found"
|
||||
exit 10
|
||||
fi
|
||||
if [ -z "${PORT}" ]; then
|
||||
echo "Error: cannot guess port, none found"
|
||||
exit 10
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "${SPEED}" ]; then
|
||||
if [ "${BOARD}" == "uno" ]; then
|
||||
SPEED=115200
|
||||
elif [ "${BOARD}" == "nano" ]; then
|
||||
SPEED=57600
|
||||
else
|
||||
echo "FATAL #002, CHECK THIS CODE"
|
||||
exit 99
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -e "${PORT}" ]; then
|
||||
echo "Error: port not found"
|
||||
exit 10
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "${FQBN}" ]; then
|
||||
if [ "${BOARD}" == "uno" ]; then
|
||||
FQBN="arduino:avr:uno"
|
||||
elif [ "${BOARD}" == "nano" ]; then
|
||||
FQBN="arduino:avr:nano:cpu=atmega328old"
|
||||
else
|
||||
echo "FATAL #003, CHECK THIS CODE"
|
||||
exit 99
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "${BUILDDIR}" ]; then
|
||||
if [[ "${FILE}" == */* ]]; then
|
||||
BUILDDIR=${FILE%/*}
|
||||
BUILDDIR="${BUILDDIR%/}/build"
|
||||
else
|
||||
BUILDDIR=build
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${RECORDUSB}" == "yes" ]; then
|
||||
if [ -z "${RECORDFILE}" ]; then
|
||||
V=${FILE##*/}
|
||||
V=${V%.*}
|
||||
V=${V:-out}
|
||||
PREV=
|
||||
for i in {15..00}; do
|
||||
F="${RECORDDIR}/${V}-$i.txt"
|
||||
if [ -e "${F}" ] && [ -n "${PREV}" ]; then
|
||||
mv "${F}" "${PREV}"
|
||||
fi
|
||||
PREV="${F}"
|
||||
done
|
||||
RECORDFILE="${F}"
|
||||
mkdir -p "${RECORDDIR}"
|
||||
fi
|
||||
else
|
||||
RECORDFILE="/dev/null"
|
||||
fi
|
||||
|
||||
if [ "${VERBOSE}" == "yes" ]; then
|
||||
echo "-- Settings"
|
||||
echo "Arduino dir: ${ARDUINODIR}"
|
||||
echo "Board: ${BOARD}"
|
||||
echo "Port: ${PORT}"
|
||||
echo "Speed: ${SPEED}"
|
||||
echo "Fqbn: ${FQBN}"
|
||||
echo "Upload: ${UPLOAD}"
|
||||
echo "Catusb: ${CATUSB}"
|
||||
echo "Recordusb: ${RECORDUSB}"
|
||||
echo "Record file: ${RECORDFILE}"
|
||||
echo "Verbose: ${VERBOSE}"
|
||||
echo "File: ${FILE}"
|
||||
echo "Build dir: ${BUILDDIR}"
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
if [ "${COMPILE}" == "yes" ]; then
|
||||
echo "-- Compile"
|
||||
|
||||
mkdir -p "${BUILDDIR}"
|
||||
|
||||
OPT_LIB=
|
||||
TMP_ULIB=${ARDUINO_USER_LIBS:-}
|
||||
if [ -n "${TMP_ULIB}" ]; then
|
||||
OPT_LIB="-libraries ""${TMP_ULIB}"""
|
||||
fi
|
||||
|
||||
TESTPLAN_OPT=""
|
||||
if [ -n "${TESTPLAN}" ]; then
|
||||
TESTPLAN_OPT="-prefs=build.extra_flags=-DTESTPLAN=${TESTPLAN}"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
# (We don't want to quote OPT_LIB as it can contain multiple options.)
|
||||
"${ARDUINODIR}/arduino-builder" \
|
||||
-hardware "${ARDUINODIR}/hardware" \
|
||||
-tools "${ARDUINODIR}/hardware/tools/avr" \
|
||||
-tools "${ARDUINODIR}/tools-builder" \
|
||||
-built-in-libraries "${ARDUINODIR}/libraries" \
|
||||
${OPT_LIB} \
|
||||
-fqbn "${FQBN}" \
|
||||
-build-path "${BUILDDIR}" \
|
||||
${TESTPLAN_OPT} \
|
||||
"${FILE}"
|
||||
fi
|
||||
|
||||
FILEBASENAME=${FILE##*/}
|
||||
|
||||
if [ "${UPLOAD}" == "yes" ]; then
|
||||
echo "-- Upload"
|
||||
"/usr/bin/avrdude" \
|
||||
-q -q -patmega328p -carduino -P"${PORT}" -b"${SPEED}" -D \
|
||||
-Uflash:w:"${BUILDDIR}/${FILEBASENAME}".hex:i
|
||||
fi
|
||||
|
||||
if [ "${CATUSB}" == "yes" ] || [ "${STTY}" == "yes" ]; then
|
||||
if [ -z "${READSPEED}" ]; then
|
||||
TFILE=$(mktemp)
|
||||
gcc -fpreprocessed -dD -x c++ -E "${FILE}" > "${TFILE}"
|
||||
for sp in 9600 19200 28800 38400 57600 115200; do
|
||||
if grep ${sp} "${TFILE}" > /dev/null; then
|
||||
READSPEED=${sp}
|
||||
fi
|
||||
done
|
||||
READSPEED=${READSPEED:-9600}
|
||||
rm "${TFILE}"
|
||||
fi
|
||||
|
||||
stty -F "${PORT}" -hupcl -echo "${READSPEED}"
|
||||
echo "-- usb setup with speed ${READSPEED}"
|
||||
fi
|
||||
|
||||
if [ "${CATUSB}" == "yes" ]; then
|
||||
echo "-- Read usb (Ctrl-C to quit)"
|
||||
DISPLAYSEP=yes
|
||||
{
|
||||
echo "speed=${READSPEED}"
|
||||
echo "fqbn=${FQBN}"
|
||||
echo "port=${PORT}"
|
||||
echo "file=${FILE}"
|
||||
echo "filedate=$(date +"%Y-%m-%dT%H:%M:%SZ" -d @$(stat -c '%Y' "${FILE}"))"
|
||||
echo "date=$(date +'%Y-%m-%dT%H:%M:%SZ')"
|
||||
echo ""
|
||||
echo "-----BEGIN ARDUINO OUTPUT-----"
|
||||
} | tee "${RECORDFILE}"
|
||||
tee -a "${RECORDFILE}" < "${PORT}"
|
||||
fi
|
||||
|
|
@ -5,4 +5,4 @@
|
|||
[2] Sync 11
|
||||
T=SYN, E=0, I=0, S=356, L=734, P=3740, Y=0, Z=340
|
||||
[3] Received 9 bits: 01 42
|
||||
T=TRI, E=0, I=0, S=356, L=734, P=3740, Y=0, Z=356
|
||||
T=TRI, E=0, I=0, S=356, L=734, P=0, Y=0, Z=356
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
T=TRI, E=0, I=0, S=356, L=734, P=15284, Y=0, Z=356
|
||||
[2] Sync 11
|
||||
T=SYN, E=0, I=0, S=356, L=734, P=3740, Y=0, Z=340
|
||||
[3] Received 10 bits: 02 84
|
||||
T=TRI, E=0, I=0, S=356, L=734, P=15284, Y=0, Z=356
|
||||
[3] Received 9 bits: 01 42
|
||||
T=TRI, E=0, I=0, S=356, L=734, P=0, Y=0, Z=356
|
||||
|
|
|
@ -51,7 +51,7 @@ uint16_t filter_mask;
|
|||
|
||||
static void assert_failed(int line) {
|
||||
#ifdef ASSERT_OUTPUT_TO_SERIAL
|
||||
Serial.print("\nRF433any.cpp:");
|
||||
Serial.print("\ntest.ino:");
|
||||
Serial.print(line);
|
||||
Serial.println(": assertion failed, aborted.");
|
||||
#endif
|
||||
|
@ -115,7 +115,7 @@ void read_simulated_timings_from_usb() {
|
|||
|
||||
#if RF433ANY_TESTPLAN == 5
|
||||
void output_decoder(Decoder *pdec) {
|
||||
while(pdec) {
|
||||
while (pdec) {
|
||||
dbgf("Decoded: %s, err: %d, code: %c, "
|
||||
"rep: %d, bits: %2d",
|
||||
(pdec->data_got_decoded() ? "yes" : "no "),
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
name=RF433any
|
||||
version=0.5.3
|
||||
version=0.6.0
|
||||
author=Sébastien Millet
|
||||
maintainer=Sébastien Millet <milletseb@laposte.net>
|
||||
sentence=A library to decode any protocol received on a 433 Mhz Radio Frequencies receiver
|
||||
paragraph=Use this library to decode any protocol received on a 433 Mhz Radio Frequencies receiver. Allow to display low level data (raw code), user level data (code received) and code timings.
|
||||
paragraph=Use this library to decode any protocol received on a 433 Mhz Radio Frequencies receiver. Allow to display low level data (raw code), user level data (code received) and code timings. No pre-defined timings to specify, the library detects it.
|
||||
category=Communication
|
||||
url=https://github.com/sebmillet/RF433any
|
||||
architectures=avr
|
||||
|
|
Loading…
Reference in New Issue