-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsalusmon.c
58 lines (47 loc) · 1.09 KB
/
salusmon.c
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
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <getopt.h>
#include <assert.h>
#include <bcm2835.h>
#include "energenie.h"
#include "hw.h"
#include "radio.h"
void sendpacket(uint8_t *txbuf, int txbuflen) {
writeRegMultibyte(0, txbuf, txbuflen);
// check FIFO level
while(readReg(0x28) & 0x20) {
usleep(1000);
}
while(!(readReg(0x28) & 0x08)) {
usleep(1000);
}
}
int main(int argc, char *argv[]) {
int i;
FILE *f;
if (initHardware()) {
fprintf(stderr, "Cannot initialize BCM2835\n.");
exit(EXIT_FAILURE);
}
f = fopen("dump.txt", "w");
// init the 868 Mhz module
bcm2835_spi_chipSelect(CS_868MHZ);
setRxMode();
while(1) {
// wait for data
if (!(readReg(0x28) & 0x04)) {
usleep(10000);
continue;
}
fprintf(f, "%20i ", time(NULL));
for(int i=0; i < 12; i++) {
fprintf(f, "%02x ", readReg(0x00));
}
fprintf(f, "\n");
fflush(f);
clearFIFO();
}
shutdownHardware();
}