-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreceiver.cpp
83 lines (60 loc) · 1.9 KB
/
receiver.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <RF24/RF24.h>
#include <ctime>
#include <fstream>
//#include <wiringPi.h>
using namespace std;
RF24 radio(22,0);
/********************************/
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = {0xF0F0F0F0E1LL, 0x7365727631LL};
struct secureMessage{
char message [16];
};
void writeToFile (char input[16]) {
// current date/time based on current system
time_t now = time(0);
// Hängt Sachen an die Datei an
std::ofstream data("datafifo", std::ios_base::app | std::ios_base::out);
data << now << " " << input << " " <<"\n"; // Leerzeichen um später besser trennen zu können
}
void setupReceiver() {
radio.begin();
radio.setPayloadSize(sizeof(secureMessage)); //Groesse der gesendeten Daten
radio.setAutoAck(1);
radio.setDataRate(RF24_250KBPS); //250kbs
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(90);
radio.setRetries(15,15);
radio.setCRCLength(RF24_CRC_16);
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.maskIRQ(0,0,1);
radio.startListening();
}
void receiveData() {
secureMessage t_message;
if( radio.available()){ // Variable for the received timestamp
while (radio.available()) { // While there is data ready
radio.read( &t_message, sizeof(t_message) );
writeToFile(t_message.message);
}
}
}
void testPrint() {
cout << "Hallo";
}
int main(int argc, char** argv){
cout << "\n RF24 Receiver for Studienarbeit\n";
//radio.printDetails();
setupReceiver();
// wiringPiISR (1, INT_EDGE_BOTH, &testPrint)
while(1) {
receiveData();
}
return 0;
}