@@ -23,7 +23,7 @@ void setup()
2323{
2424 Serial.begin (9600 );
2525 Serial.println (" Starting RF_TEST" );
26- // randomSeed(analogRead(0));
26+ randomSeed (analogRead (0 ));
2727 app.Begin ();
2828}
2929
@@ -32,117 +32,3 @@ void loop()
3232 app.Update ();
3333 delay (100 );
3434}
35- /* #include <SPI.h>
36- //#include "RF24.h"
37- //#include "printf.h"
38-
39-
40- //RF24 radio(9,10);
41-
42- typedef enum
43- {
44- BROADCAST_PEER_DISCOVERY = 1,
45- BROADCAST_MISC,
46-
47- BROADCAST_MAX,
48- } broadcast_chanel;
49-
50- const uint64_t broadcast_addresses[BROADCAST_MAX] = { 0, 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
51- const uint64_t client_addresses[4] = { 0x112100000F0LL, 0x11210000F1LL, 0x11210000F2LL, 0x11210000F3LL };
52- const uint8_t client_num = 1;
53-
54- unsigned long last_broadcast;
55-
56- struct Peer
57- {
58- uint64_t address;
59- uint32_t last_seen;
60- boolean used;
61- Peer() : address(0), last_seen(0), used(false) {}
62- };
63-
64- Peer peers[20];
65-
66-
67- void setup(void)
68- {
69- Serial.begin(9600);
70- Serial.println("RF_TEST");
71- Serial.print("ADDRESS: ");
72- Serial.print(client_num, DEC);
73- Serial.print(" - ");
74- Serial.print((uint32_t)(client_addresses[client_num] >> 32), HEX);
75- Serial.print((uint32_t)(client_addresses[client_num] ), HEX);
76- Serial.println("");
77-
78- radio.begin();
79- radio.enableDynamicPayloads();
80- radio.setRetries(2,1);
81- //radio.openWritingPipe(client_addresses[client_num]);
82- radio.openReadingPipe(0, client_addresses[client_num]);
83- radio.openReadingPipe(BROADCAST_PEER_DISCOVERY,broadcast_addresses[BROADCAST_PEER_DISCOVERY]);
84- radio.openReadingPipe(BROADCAST_MISC,broadcast_addresses[BROADCAST_MISC]);
85- radio.setAutoAck(0, true);
86- radio.setAutoAck(BROADCAST_PEER_DISCOVERY, false);
87- radio.setAutoAck(BROADCAST_MISC, false);
88-
89- // Im here!
90- sendPD();
91- }
92-
93- bool doPD()
94- {
95- return millis() - last_broadcast > 3000;
96- }
97-
98- void sendPD()
99- {
100- radio.stopListening();
101- radio.openWritingPipe(broadcast_addresses[BROADCAST_PEER_DISCOVERY]);
102- radio.write(&client_addresses[client_num], sizeof(client_addresses[client_num]));
103- last_broadcast = millis();
104- radio.startListening();
105- }
106-
107- void sendMessage(uint64_t address, const void* message, uint8_t length)
108- {
109- radio.stopListening();
110- radio.openWritingPipe(address);
111- radio.write(message, length);
112- radio.startListening();
113- }
114-
115-
116- void loop(void)
117- {
118- uint8_t pipe_num;
119- if (radio.available(&pipe_num))
120- {
121- uint8_t len = radio.getDynamicPayloadSize();
122-
123- if (pipe_num == BROADCAST_PEER_DISCOVERY)
124- {
125- uint64_t payload;
126- radio.read( &payload, len );
127- Serial.print("Found client: ");
128- Serial.print((uint32_t)(payload >> 32), HEX);
129- Serial.print((uint32_t)(payload ), HEX);
130- Serial.println("");
131- sendMessage(payload, "Hello there.", 12);
132- }
133- else //if (pipe_num == 0)
134- {
135- char payload[33];
136- radio.read(payload, len);
137- payload[len] = 0;
138- Serial.print("Got packet. Message: ");
139- Serial.println(payload);
140- }
141- }
142-
143- // Periodically send a PD broadcast.
144- if (doPD()) { sendPD(); }
145-
146- delay(10);
147-
148- }*/
0 commit comments