mirror of
https://github.com/digistump/DigistumpArduino.git
synced 2025-09-17 09:22:28 -07:00
switch to setup for Arduino Boards Manager
This commit is contained in:
129
digistump-sam/libraries/RF24Network/tests/unit_rx/Finder.cpp
Normal file
129
digistump-sam/libraries/RF24Network/tests/unit_rx/Finder.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
// STL headers
|
||||
// C headers
|
||||
// Framework headers
|
||||
// Library headers
|
||||
#include "RF24Network.h"
|
||||
|
||||
// Project headers
|
||||
// This component's header
|
||||
#include <Finder.h>
|
||||
|
||||
extern RF24Network network;
|
||||
|
||||
// Message buffer space
|
||||
static uint8_t message[32];
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
Finder::Finder(void): this_node(0), state(state_waiting),
|
||||
last_sent(millis()-interval), child_increment(-1)
|
||||
{
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void Finder::begin(uint16_t _this_node)
|
||||
{
|
||||
this_node = _this_node;
|
||||
|
||||
if ( ! ( this_node & 07000 ) )
|
||||
{
|
||||
// Figure out the address of the first child. e.g. if our node is 045, our
|
||||
// first child is 0145. So we need to shift 01 up enough places to be the
|
||||
// highest digit
|
||||
child_increment = 01;
|
||||
uint16_t temp = this_node;
|
||||
while ( temp )
|
||||
{
|
||||
child_increment <<= 3;
|
||||
temp >>= 3;
|
||||
}
|
||||
}
|
||||
|
||||
printf_P(PSTR("%lu: Node %o increment %o\r\n"),millis(),this_node,child_increment);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void Finder::update(void)
|
||||
{
|
||||
// Check the network for traffic
|
||||
|
||||
// If we got a new finder request, launch!
|
||||
if ( network.available() )
|
||||
{
|
||||
RF24NetworkHeader header;
|
||||
network.peek(header);
|
||||
if ( header.type == 'F' )
|
||||
{
|
||||
network.read(header,message,sizeof(message));
|
||||
uint16_t from = header.from_node;
|
||||
printf_P(PSTR("%lu: APP Received FINDER request from %o\r\n"),millis(),from);
|
||||
|
||||
if ( state == state_sending )
|
||||
{
|
||||
printf_P(PSTR("%lu: APP ERROR, already sending a finder request\r\n"),millis());
|
||||
}
|
||||
else if ( child_increment == 0xffff )
|
||||
{
|
||||
printf_P(PSTR("%lu: APP This app has no children, done.\r\n"),millis());
|
||||
last_sent = millis() - interval;
|
||||
state = state_done;
|
||||
goto finish;
|
||||
}
|
||||
else
|
||||
{
|
||||
last_sent = millis() - interval;
|
||||
to_node = this_node + child_increment;
|
||||
state = state_sending;
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we're working but not ready, continue
|
||||
if ( state != state_waiting && millis() - last_sent <= interval )
|
||||
return;
|
||||
|
||||
// If we're working, send!
|
||||
if ( state == state_sending )
|
||||
{
|
||||
RF24NetworkHeader header(to_node,'F');
|
||||
/*bool ok = */ network.write(header,message,sizeof(message));
|
||||
last_sent = millis();
|
||||
|
||||
to_node += child_increment;
|
||||
|
||||
// Done?
|
||||
if ( to_node > this_node + 5 * child_increment )
|
||||
{
|
||||
state = state_done;
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
||||
// If we're now done, send the final 'E' back
|
||||
if ( state == state_done )
|
||||
{
|
||||
// Send an 'E' Echo response back to the BASE
|
||||
RF24NetworkHeader header(00,'E');
|
||||
network.write(header,message,sizeof(message));
|
||||
|
||||
state = state_waiting;
|
||||
goto finish;
|
||||
}
|
||||
finish:
|
||||
return;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
// vim:cin:ai:sts=2 sw=2 ft=cpp
|
42
digistump-sam/libraries/RF24Network/tests/unit_rx/Finder.h
Normal file
42
digistump-sam/libraries/RF24Network/tests/unit_rx/Finder.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef __FINDER_H__
|
||||
#define __FINDER_H__
|
||||
|
||||
// STL headers
|
||||
// C headers
|
||||
// Framework headers
|
||||
#include <Arduino.h>
|
||||
// Library headers
|
||||
// Project headers
|
||||
|
||||
/**
|
||||
* Manage a child-finder request
|
||||
*/
|
||||
|
||||
class Finder
|
||||
{
|
||||
private:
|
||||
uint16_t this_node;
|
||||
enum state_e { state_none = 0, state_waiting, state_sending, state_done, state_invalid };
|
||||
state_e state;
|
||||
static const unsigned long interval = 50;
|
||||
unsigned long last_sent;
|
||||
uint16_t to_node;
|
||||
uint16_t child_increment;
|
||||
protected:
|
||||
|
||||
public:
|
||||
Finder(void);
|
||||
void begin(uint16_t);
|
||||
void update(void);
|
||||
};
|
||||
|
||||
#endif // __FINDER_H__
|
||||
// vim:cin:ai:sts=2 sw=2 ft=cpp
|
210
digistump-sam/libraries/RF24Network/tests/unit_rx/Jamfile
Normal file
210
digistump-sam/libraries/RF24Network/tests/unit_rx/Jamfile
Normal file
@@ -0,0 +1,210 @@
|
||||
# (1) Project Information
|
||||
|
||||
PROJECT_LIBS = SPI RF24 RF24Network ;
|
||||
|
||||
# (2) Board Information
|
||||
|
||||
UPLOAD_PROTOCOL ?= stk500v1 ;
|
||||
UPLOAD_SPEED ?= 57600 ;
|
||||
MCU ?= atmega328p ;
|
||||
F_CPU ?= 16000000 ;
|
||||
CORE ?= arduino ;
|
||||
VARIANT ?= standard ;
|
||||
ARDUINO_VERSION ?= 100 ;
|
||||
|
||||
# (3) USB Ports
|
||||
|
||||
PORTS = p4 p6 p9 u0 u1 u2 ;
|
||||
PORT_p6 = /dev/tty.usbserial-A600eHIs ;
|
||||
PORT_p4 = /dev/tty.usbserial-A40081RP ;
|
||||
PORT_p9 = /dev/tty.usbserial-A9007LmI ;
|
||||
PORT_u0 = /dev/ttyUSB0 ;
|
||||
PORT_u1 = /dev/ttyUSB1 ;
|
||||
PORT_u2 = /dev/ttyUSB2 ;
|
||||
|
||||
# (4) Location of AVR tools
|
||||
#
|
||||
# This configuration assumes using avr-tools that were obtained separate from the Arduino
|
||||
# distribution.
|
||||
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
AVR_BIN = /usr/local/avrtools/bin ;
|
||||
AVR_ETC = /usr/local/avrtools/etc ;
|
||||
AVR_INCLUDE = /usr/local/avrtools/include ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AVR_BIN = /usr/bin ;
|
||||
AVR_INCLUDE = /usr/lib/avr/include ;
|
||||
AVR_ETC = /etc ;
|
||||
}
|
||||
|
||||
# (5) Directories where Arduino core and libraries are located
|
||||
|
||||
ARDUINO_DIR ?= /opt/Arduino ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
|
||||
#
|
||||
# --------------------------------------------------
|
||||
# Below this line usually never needs to be modified
|
||||
#
|
||||
|
||||
# Tool locations
|
||||
|
||||
CC = $(AVR_BIN)/avr-gcc ;
|
||||
C++ = $(AVR_BIN)/avr-g++ ;
|
||||
LINK = $(AVR_BIN)/avr-gcc ;
|
||||
OBJCOPY = $(AVR_BIN)/avr-objcopy ;
|
||||
AVRDUDE = $(AVR_BIN)/avrdude ;
|
||||
|
||||
# Flags
|
||||
|
||||
DEFINES += NODE=$(NODE) F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
OPTIM = -Os ;
|
||||
CCFLAGS = -Wall -Wextra -mmcu=$(MCU) -ffunction-sections -fdata-sections ;
|
||||
C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ;
|
||||
LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ;
|
||||
AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ;
|
||||
|
||||
# Search everywhere for headers
|
||||
|
||||
HDRS = $(PWD) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ;
|
||||
|
||||
# Output locations
|
||||
|
||||
LOCATE_TARGET = $(F_CPU) ;
|
||||
LOCATE_SOURCE = $(F_CPU) ;
|
||||
|
||||
#
|
||||
# Custom rules
|
||||
#
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_SOURCE) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
if ( $(ARDUINO_VERSION) < 100 )
|
||||
{
|
||||
ARDUINO_H = WProgram.h ;
|
||||
}
|
||||
else
|
||||
{
|
||||
ARDUINO_H = Arduino.h ;
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <$(ARDUINO_H)>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule C++Pde
|
||||
{
|
||||
local _CPP = $(>:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
C++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule UserObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .ino : C++Pde $(<) : $(>) ;
|
||||
case .pde : C++Pde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Objects
|
||||
{
|
||||
local _i ;
|
||||
|
||||
for _i in [ FGristFiles $(<) ]
|
||||
{
|
||||
local _b = $(_i:B)$(SUFOBJ) ;
|
||||
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
|
||||
Object $(_o) : $(_i) ;
|
||||
Depends obj : $(_o) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Main
|
||||
{
|
||||
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
|
||||
Objects $(>) ;
|
||||
}
|
||||
|
||||
rule Hex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_TARGET) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions Hex
|
||||
{
|
||||
$(OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule Upload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
UploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions UploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
#
|
||||
# Targets
|
||||
#
|
||||
|
||||
# Grab everything from the core directory
|
||||
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ;
|
||||
|
||||
# Grab everything from the current dir
|
||||
PROJECT_MODULES += [ GLOB $(PWD) : *.c *.cpp *.pde *.ino ] ;
|
||||
|
||||
# Main output executable
|
||||
MAIN = $(PWD:B).elf ;
|
||||
|
||||
Main $(MAIN) : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
|
||||
Hex $(MAIN:B).hex : $(MAIN) ;
|
||||
|
||||
# Upload targets
|
||||
for _p in $(PORTS)
|
||||
{
|
||||
Upload $(_p) : $(PORT_$(_p)) : $(MAIN:B).hex ;
|
||||
}
|
19
digistump-sam/libraries/RF24Network/tests/unit_rx/README
Normal file
19
digistump-sam/libraries/RF24Network/tests/unit_rx/README
Normal file
@@ -0,0 +1,19 @@
|
||||
This is the 'receiver' for the unit tests. Run it on a node which
|
||||
is NOT under test.
|
||||
|
||||
TODO
|
||||
|
||||
Send finder request needs a re-think. It needs to be re-implemented as a Tictocs::Timer, so it
|
||||
doesn't block the loop().
|
||||
|
||||
I could also make Tictocs objects which monitor the RF24network and pull off messages that are just
|
||||
for them. Likewise, the network can raise a signal when there is a new message. Although I would not
|
||||
want to put that into the library for fear of adding a dependency.
|
||||
|
||||
so the finder needs to maintain state
|
||||
- Waiting: Waiting for a finder request
|
||||
- Sending: In the midst of looping through children
|
||||
|
||||
Needs to have some delay between each send. So the finder has a timer component.
|
||||
|
||||
Also... Reset should also reset the internal copy of the sync data. Sync may need a 'reset' method.
|
31
digistump-sam/libraries/RF24Network/tests/unit_rx/printf.h
Normal file
31
digistump-sam/libraries/RF24Network/tests/unit_rx/printf.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
fdevopen( &serial_putc, 0 );
|
||||
}
|
||||
|
||||
#endif // __PRINTF_H__
|
135
digistump-sam/libraries/RF24Network/tests/unit_rx/unit_rx.pde
Normal file
135
digistump-sam/libraries/RF24Network/tests/unit_rx/unit_rx.pde
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Receiver for unit tests.
|
||||
*/
|
||||
|
||||
#include <RF24Network.h>
|
||||
#include <RF24.h>
|
||||
#include <SPI.h>
|
||||
#include <Sync.h>
|
||||
#include "Finder.h"
|
||||
#include "printf.h"
|
||||
|
||||
// nRF24L01(+) radio attached to SPI and pins 8 & 9
|
||||
RF24 radio(8,9);
|
||||
|
||||
// Network uses that radio
|
||||
RF24Network network(radio);
|
||||
|
||||
// Syncronizer
|
||||
Sync sync(network);
|
||||
|
||||
// Address of our node
|
||||
#if NODE > 0
|
||||
const uint16_t this_node = NODE;
|
||||
#else
|
||||
const uint16_t this_node = 1;
|
||||
#endif
|
||||
|
||||
// Address of the other node
|
||||
const uint16_t other_node = 0;
|
||||
|
||||
// Data to be synchronized
|
||||
struct sync_data_t
|
||||
{
|
||||
uint16_t first;
|
||||
uint16_t second;
|
||||
|
||||
sync_data_t(void): first(1), second(2) {}
|
||||
};
|
||||
|
||||
sync_data_t sync_data;
|
||||
|
||||
// Old value of 'first'
|
||||
uint16_t old_first;
|
||||
|
||||
// Message buffer space
|
||||
uint8_t message[32];
|
||||
|
||||
void send_finder_request(void);
|
||||
void net_delay(unsigned long amount);
|
||||
|
||||
Finder finder;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(57600);
|
||||
Serial.println("RF24Network/test/unit_rx/");
|
||||
printf_begin();
|
||||
|
||||
SPI.begin();
|
||||
radio.begin();
|
||||
network.begin(/*channel*/ 100, /*node address*/ this_node);
|
||||
finder.begin(this_node);
|
||||
|
||||
sync.register_me(sync_data);
|
||||
old_first = sync_data.first;
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
// Pump the network regularly
|
||||
sync.update();
|
||||
|
||||
// Stay on the lookout for finder messages
|
||||
finder.update();
|
||||
|
||||
// Have the values changed?
|
||||
if ( old_first != sync_data.first )
|
||||
{
|
||||
printf_P(PSTR("%lu: APP Updated first to %u\n\r"),millis(),sync_data.first);
|
||||
|
||||
// Move the first value over to the second
|
||||
sync_data.second = sync_data.first;
|
||||
|
||||
// And remember the change for next time
|
||||
old_first = sync_data.first;
|
||||
}
|
||||
|
||||
// Are there any messages for us?
|
||||
while ( network.available() )
|
||||
{
|
||||
uint16_t from;
|
||||
|
||||
// If so, take a look at it
|
||||
RF24NetworkHeader header;
|
||||
network.peek(header);
|
||||
|
||||
// Dispatch the message to the correct handler.
|
||||
switch (header.type)
|
||||
{
|
||||
// Reset to initial state
|
||||
case 'R':
|
||||
network.read(header,0,0);
|
||||
printf_P(PSTR("%lu: APP Reset to initial state\n\r"),millis());
|
||||
|
||||
sync_data = sync_data_t();
|
||||
old_first = sync_data.first;
|
||||
sync.reset();
|
||||
break;
|
||||
|
||||
// Echo back to the sender.
|
||||
case 'E':
|
||||
network.read(header,message,sizeof(message));
|
||||
from = header.from_node;
|
||||
printf_P(PSTR("%lu: APP Received ECHO request from %o\n\r"),millis(),from);
|
||||
network.write(header = RF24NetworkHeader(from,'E'),message,sizeof(message));
|
||||
break;
|
||||
|
||||
// Unrecognized message type
|
||||
default:
|
||||
printf_P(PSTR("*** WARNING *** Unknown message type %c\n\r"),header.type);
|
||||
network.read(header,0,0);
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
Reference in New Issue
Block a user