This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
lab5 [2014/11/04 18:50] dan.tudose |
lab5 [2018/11/09 09:55] (current) dan.tudose |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Protocoale de transmisie ====== | ====== Protocoale de transmisie ====== | ||
| - | Pentru lucrarea curentă de laborator veți folosi biblioteca | + | Pentru lucrarea curentă de laborator veți folosi biblioteca |
| Instalarea bibliotecii este foarte facilă, trebuie doar să dezarhivați arhiva în Arduino\libraries | Instalarea bibliotecii este foarte facilă, trebuie doar să dezarhivați arhiva în Arduino\libraries | ||
| Line 9: | Line 9: | ||
| Codul pentru Transmitter: | Codul pentru Transmitter: | ||
| <code C> | <code C> | ||
| - | # | + | # |
| + | |||
| //create object | //create object | ||
| - | ZigduinoTransfer ET; | + | SparrowTransfer ST; |
| + | |||
| struct SEND_DATA_STRUCTURE{ | struct SEND_DATA_STRUCTURE{ | ||
| //put your variable definitions here for the data you want to send | //put your variable definitions here for the data you want to send | ||
| //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO | ||
| - | | + | |
| - | int pause; | + | |
| }; | }; | ||
| Line 24: | Line 23: | ||
| SEND_DATA_STRUCTURE mydata; | SEND_DATA_STRUCTURE mydata; | ||
| + | void blinkLED() //blinks the LED | ||
| + | { | ||
| + | digitalWrite(8, | ||
| + | delay(20); | ||
| + | digitalWrite(8, | ||
| + | } | ||
| + | |||
| void setup(){ | void setup(){ | ||
| - | | + | Serial.begin(9600); |
| - | //start the library, pass in the data details | + | |
| - | ET.begin(details(mydata)); | + | //start the library, pass in the data details |
| - | + | ST.begin(details(mydata)); | |
| - | pinMode(11, OUTPUT); | + | |
| - | + | | |
| - | + | digitalWrite(8, | |
| + | |||
| + | | ||
| | | ||
| } | } | ||
| void loop(){ | void loop(){ | ||
| - | //this is how you access the variables. [name of the group].[variable name] | ||
| - | mydata.blinks = 5; | ||
| - | mydata.pause = 10; | ||
| - | //send the data | ||
| - | ET.sendData(); | ||
| | | ||
| - | | + | mydata.data++; |
| - | | + | |
| - | digitalWrite(11, | + | |
| - | delay(mydata.pause * 100); | + | |
| - | digitalWrite(11, | + | |
| - | delay(mydata.pause * 100); | + | |
| - | } | + | |
| | | ||
| - | delay(5000); | + | |
| + | ST.sendData(); | ||
| + | blinkLED(); | ||
| + | |||
| + | | ||
| } | } | ||
| + | |||
| </ | </ | ||
| Line 57: | Line 59: | ||
| <code C> | <code C> | ||
| - | # | + | # |
| + | |||
| //create object | //create object | ||
| - | ZigduinoTransfer ET; | + | SparrowTransfer ST; |
| + | |||
| struct RECEIVE_DATA_STRUCTURE{ | struct RECEIVE_DATA_STRUCTURE{ | ||
| - | //put your variable definitions here for the data you want to receive | + | //put your variable definitions here for the data you want to send |
| - | //THIS MUST BE EXACTLY THE SAME ON THE OTHER NODE!!! | + | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO |
| - | | + | |
| - | int pause; | + | |
| }; | }; | ||
| - | |||
| //give a name to the group of data | //give a name to the group of data | ||
| RECEIVE_DATA_STRUCTURE mydata; | RECEIVE_DATA_STRUCTURE mydata; | ||
| + | |||
| + | uint16_t old_index, received_index, | ||
| void setup(){ | void setup(){ | ||
| Serial.begin(9600); | Serial.begin(9600); | ||
| - | //start the library, pass in the data details | ||
| - | ET.begin(details(mydata)); | ||
| | | ||
| + | //start the library, pass in the data details | ||
| + | ST.begin(details(mydata)); | ||
| + | |||
| pinMode(11, OUTPUT); | pinMode(11, OUTPUT); | ||
| - | | + | |
| + | |||
| + | } | ||
| + | |||
| + | void blinkLED() | ||
| + | { | ||
| + | digitalWrite(11, | ||
| + | delay(20); | ||
| + | digitalWrite(11, | ||
| } | } | ||
| void loop(){ | void loop(){ | ||
| //check and see if a data packet has come in. | //check and see if a data packet has come in. | ||
| - | if(ET.receiveData()){ | + | if(ST.receiveData() |
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | received_index++; |
| - | delay(mydata.pause * 100); | + | |
| - | | + | if(old_index != 0) |
| - | delay(mydata.pause * 100); | + | lost += mydata.data - old_index |
| - | | + | |
| + | Serial.print("Frame arrived: "); | ||
| + | | ||
| + | | ||
| + | Serial.print(" | ||
| + | | ||
| + | Serial.print(", | ||
| + | Serial.print(lost*100.0/ | ||
| + | | ||
| + | |||
| + | old_index = mydata.data; | ||
| } | } | ||
| - | | + | |
| - | //you should make this delay shorter than your transmit delay or else messages could be lost | + | //optional |
| - | delay(250); | + | |
| } | } | ||
| + | |||
| </ | </ | ||