Jordan Earls
/
pjon_testing
Testing getting PJON working on mbed https://github.com/gioblu/PJON
Revision 1:bd0ee507dd4c, committed 2016-01-10
- Comitter:
- earlz
- Date:
- Sun Jan 10 09:41:00 2016 +0000
- Parent:
- 0:fa2f348efd7e
- Child:
- 2:5648483c5dbc
- Commit message:
- Use the network analysis example
Changed in this revision
--- a/main.cpp Sun Jan 10 07:26:52 2016 +0000 +++ b/main.cpp Sun Jan 10 09:41:00 2016 +0000 @@ -1,6 +1,6 @@ #include "mbed.h" #include <pjon.h> - +/* // network(Arduino pin used, selected device id) PJON network(p12, 1); DigitalOut myled(LED1); @@ -15,3 +15,76 @@ wait(0.2); } } +*/ + +float test; +float mistakes; +int busy; +int fail; + +// network(Arduino pin used, selected device id) +PJON network(p13, 45); +Serial serial(USBTX, USBRX); +Timer timer; +int packet; +char content[] = "01234567890123456789"; + +void setup() { + serial.baud(19200); + timer.start(); + serial.printf("PJON - Network analysis\n\r"); + serial.printf("Starting a 10 seconds communication test..\n\r\n\r"); +} + +void loop() { + long time = timer.read_ms(); + while(timer.read_ms() - time < 10000) { + + /* + Here send_string low level function is used to + be able to catch every single sending result. + */ + + int response = network.send_string(44, content, 20); + if(response == ACK) + test++; + if(response == NAK) + mistakes++; + if(response == BUSY) + busy++; + if(response == FAIL) + fail++; + wait_us(14); + } + + serial.printf("Absolute com speed: "); + serial.printf("%i", (test * 24 ) / 10 ); + serial.printf("B/s\n\r"); + serial.printf("Practical bandwidth: "); + serial.printf("%i", (test * 20 ) / 10 ); + serial.printf("B/s\n\r"); + serial.printf("Packets sent: "); + serial.printf("%f\n\r", test); + serial.printf("Mistakes (error found with CRC) "); + serial.printf("%f\n\r", mistakes); + serial.printf("Fail (no answer from receiver) "); + serial.printf("%i\n\r", fail); + serial.printf("Busy (Channel is busy or affected by interference) "); + serial.printf("%i\n\r", busy); + serial.printf("Accuracy: "); + serial.printf("%i", 100 - (100 / (test / mistakes))); + serial.printf(" %\n\r"); + serial.printf(" --------------------- \n\r"); + + test = 0; + mistakes = 0; + busy = 0; + fail = 0; +}; + +int main(){ + setup(); + while(true){ + loop(); + } +} \ No newline at end of file
--- a/pjon.cpp Sun Jan 10 07:26:52 2016 +0000 +++ b/pjon.cpp Sun Jan 10 09:41:00 2016 +0000 @@ -137,7 +137,7 @@ function to optimize transmission time */ void PJON::send_bit(uint8_t VALUE, int duration) { - _input_pin = VALUE; //digitalWrite(_input_pin, VALUE); + _input_pin = VALUE > 0; //digitalWrite(_input_pin, VALUE); wait_us(duration); } @@ -167,7 +167,7 @@ wait_us(BIT_WIDTH); for(uint8_t mask = 0x01; mask; mask <<= 1) { - _input_pin = b & mask; //digitalWriteFast(_input_pin, b & mask); + _input_pin = (b & mask) > 0; //digitalWriteFast(_input_pin, b & mask); wait_us(BIT_WIDTH); } }
--- a/pjon.h Sun Jan 10 07:26:52 2016 +0000 +++ b/pjon.h Sun Jan 10 09:41:00 2016 +0000 @@ -64,10 +64,10 @@ #define COMPATIBILITY_MODE true //mbed (needs tweaking) - #define BIT_WIDTH 40 - #define BIT_SPACER 112 - #define ACCEPTANCE 40 - #define READ_DELAY 16 + #define BIT_WIDTH 45 + #define BIT_SPACER 115 + #define ACCEPTANCE 39 + #define READ_DELAY 25 /* The following constants setup are quite conservative and determined only with a huge amount of time and blind testing (without oscilloscope)