-
Notifications
You must be signed in to change notification settings - Fork 68
/
PiGateway.cpp
75 lines (61 loc) · 1.31 KB
/
PiGateway.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
/*
The MySensors library adds a new layer on top of the RF24 library.
It handles radio network routing, relaying and ids.
Created by OUJABER Mohamed <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
#include <stdio.h>
#include "MyGateway.h"
#include <RF24.h>
MyGateway *gw;
int daemonizeFlag = 0;
void openSyslog()
{
setlogmask(LOG_UPTO (LOG_INFO));
openlog(NULL, 0, LOG_USER);
}
void closeSyslog()
{
closelog();
}
void log(int priority, const char *format, ...)
{
va_list argptr;
va_start(argptr, format);
if (daemonizeFlag == 1) {
vsyslog(priority, format, argptr);
} else {
vprintf(format, argptr);
}
va_end(argptr);
}
void msgCallback(char *msg){
printf("[CALLBACK]%s", msg);
}
void setup(void)
{
printf("Starting Gateway...\n");
gw = new MyGateway(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ, 60);
if (gw == NULL)
{
printf("gw is null!");
}
gw->begin(RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE, &msgCallback);
}
void loop(void)
{
gw->processRadioMessage();
}
int main(int argc, char** argv)
{
openSyslog();
setup();
while(1) {
loop();
sleep(1);
}
closeSyslog();
return 0;
}