forked from VaclavSynacek/RF24SN_CPP_Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RF24SN-RF24-Wrapper.cpp
56 lines (40 loc) · 1.13 KB
/
RF24SN-RF24-Wrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "RF24SN-RF24-Wrapper.h"
#include <iostream>
#include "RF24.h"
//TODO load from program arguments
RF24 radio("/dev/spidev0.0",8000000 , 25);
uint64_t base_pipe = 0xF0F0F0F000LL; // address of the pipe to the base.
void (*_processPacket)(Packet);
void RF24Setup( void (*processPacket)(Packet) )
{
radio.begin();
radio.setPayloadSize(sizeof(Packet));
//radio.setChannel(4);
//radio.setDataRate(RF24_250KBPS);
//radio.setRetries(0,15);
radio.openReadingPipe(1,base_pipe);
radio.setAutoAck(1, false);
radio.startListening();
//TODO prety print based on --verbose argument
// printf("\n\rRF24SensorHub!\n");
radio.printDetails();
printf("size of packet = %hu\n", sizeof(Packet));
_processPacket = processPacket;
}
void sendPacket(Packet packet)
{
radio.stopListening();
radio.openWritingPipe(base_pipe+packet.nodeId); //open pipe unique to the node
radio.setAutoAck(0, false);
radio.write( &packet, sizeof(Packet) );
radio.startListening();
}
void RF24Loop(void)
{
if ( radio.available() )
{
Packet packet;
radio.read( &packet, sizeof(Packet) );
_processPacket(packet);
}
}