-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
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 <RF24.h> | ||
#include <RF24Network.h> | ||
// Project headers | ||
// This component's header | ||
#include <Globals.h> | ||
|
||
#include "WProgram.h" | ||
|
||
/****************************************************************************/ | ||
|
||
HardwareSPI SPI(2); | ||
|
||
// Radio on Maple Native w/ Getting Started board | ||
RF24 radio(7,6); | ||
RF24Network network(radio); | ||
|
||
// vim:cin:ai:sts=2 sw=2 ft=cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
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 __GLOBALS_H__ | ||
#define __GLOBALS_H__ | ||
|
||
// STL headers | ||
// C headers | ||
// Framework headers | ||
// Library headers | ||
// Project headers | ||
|
||
class RF24; | ||
class RF24Network; | ||
|
||
extern RF24 radio; | ||
extern RF24Network network; | ||
|
||
/** | ||
* Example for how classes should be declared | ||
*/ | ||
|
||
class Template | ||
{ | ||
private: | ||
protected: | ||
public: | ||
}; | ||
|
||
#endif // __GLOBALS_H__ | ||
// vim:cin:ai:sts=2 sw=2 ft=cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
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 | ||
#include <vector> | ||
#include <string> | ||
#include <iostream> | ||
// C headers | ||
#include <stdlib.h> | ||
// Framework headers | ||
// Library headers | ||
#include <cxxtest/TestSuite.h> | ||
// Project headers | ||
#include <RF24Network.h> | ||
#include <RF24.h> | ||
// This component's header | ||
#include <Sync.h> | ||
|
||
#include "WProgram.h" | ||
#include "Globals.h" | ||
|
||
using namespace std; | ||
|
||
class PingTestSuite: public CxxTest::TestSuite | ||
{ | ||
|
||
public: | ||
void setUp() | ||
{ | ||
SPI.begin(); | ||
radio.begin(); | ||
network.begin(/* channel */100,/* this node */0); | ||
|
||
// Reset remote to initial state | ||
RF24NetworkHeader header(/*to node*/ 1, /*type*/ 'R' /*Reset*/); | ||
network.write(header,0,0); | ||
|
||
// Wait a bit for the message to take | ||
delay(50); | ||
} | ||
|
||
void tearDown() | ||
{ | ||
} | ||
|
||
void testPing() | ||
{ | ||
// Send an echo ping to the other unit | ||
RF24NetworkHeader header(/*to node*/ 1, /*type*/ 'E' /*Echo*/); | ||
uint32_t testval = 0x12345678, gotval = 0; | ||
network.write(header,&testval,sizeof(testval)); | ||
|
||
const unsigned long timeout = 1000; | ||
unsigned long sent_at = millis(); | ||
while ( millis() - sent_at < timeout && ! gotval ) | ||
{ | ||
network.update(); | ||
|
||
// Is there anything ready for us? | ||
if ( network.available() ) | ||
{ | ||
// If so, take a look at it | ||
RF24NetworkHeader header; | ||
network.peek(header); | ||
|
||
switch (header.type) | ||
{ | ||
case 'E': | ||
network.read(header,&gotval,sizeof(gotval)); | ||
break; | ||
default: | ||
// Anything else is unexpected, and ergo a test failure | ||
network.read(header,0,0); | ||
gotval = -1; | ||
break; | ||
}; | ||
} | ||
} | ||
|
||
TS_ASSERT_EQUALS( gotval, testval ); | ||
} | ||
|
||
}; | ||
// vim:cin:ai:sts=2 sw=2 ft=cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters