-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjora_gateway.cpp
94 lines (71 loc) · 1.62 KB
/
jora_gateway.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
84
85
86
87
88
89
90
91
92
//to compile:
//g++ -o jora_gateway Jora.h Jora.cpp jora_gateway.cpp -lwiringPi -lbcm2835
#include "Jora.h"
//triggered on interrupt
void onReceive(int packetSize){
printf("Received packet: ");
//read packet
for(int i = 0; i < packetSize; i++){
//p.payload[i] = (char)j.read();
printf("%c", Jora.read());
}
printf("\n");
//m.new_msg = true;
}
void setup(){
printf("Setting up Jora Gateway...\n");
wiringPiSetup();
Jora.setPins(CS_PIN, RESET_PIN, IRQ_PIN);
if(Jora.begin(DEFAULT_FREQ) < 0){
printf("Jora begin failed!\n");
while(true){ //stay here
printf(".");
delay(3000);
}
}
#ifndef ARDUINO
Jora.setTxPower(14, PA_OUTPUT_PA_BOOST_PIN); //gateway uses inAir9B (PA_BOOST)
#else
Jora.setTxPower(1, PA_OUTPUT_RFO_PIN);
#endif
Jora.onReceive(onReceive);
Jora.receive();
#ifdef DEBUG
printf("CH: %#07x\n", Jora.getFrequency());
#endif
printf("Jora begin Success!\n");
}
//for basic receive testing
void receiver(){
int packetSize = Jora.parsePacket();
if(packetSize){
printf("Received packet: ");
while(Jora.available()){
printf("%c", (char)Jora.read());
}
printf(" with RSSI %d\n", Jora.packetRssi());
}
}
//for basic sender testing
void sender(int counter){
printf("Sending packet: %d\n", counter);
//Jora.beginPacket();
//Jora.print("hello");
//Jora.print(counter);
//Jora.endPacket();
}
int main (int argc, char *argv[]){
setup();
printf("Starting Jora Gateway...\n");
int counter = 0;
while(true){
//receiver();
//sender(counter);
counter++;
//delay(1000);
//printf("MAIN: _onReceive: %d\n", j.getOR());
//delay(50);
};
printf("Finished..\n");
return (0);
}