-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathX10RFSniffer.cpp
More file actions
114 lines (94 loc) · 2.56 KB
/
X10RFSniffer.cpp
File metadata and controls
114 lines (94 loc) · 2.56 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <wiringPi.h>
#include <iostream>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <sched.h>
#include <sstream>
using namespace std;
//store data into array
#define MAX_CHANGE_TO_KEEP 70
static int durations[MAX_CHANGE_TO_KEEP];
void log(string a){
cout << a ;
}
string longToString(long mylong){
string mystring;
stringstream mystream;
mystream << mylong;
return mystream.str();
}
string intToString(int myint){
string mystring;
stringstream mystream;
mystream << myint;
return mystream.str();
}
string measure2String(long duration){
string mystring;
stringstream mystream;
mystream << duration;
return mystream.str();
}
void handleInterrupt() {
static unsigned int duration;
static unsigned int changeCount;
static unsigned long lastTime;
static int lockPassed;
static int lockChange;
long time = micros();
duration = time - lastTime;
//wait for lock
if (lockChange == 0 && duration > 26000 && duration < 28000 && lockPassed == 0) {
changeCount = 0;
log("Lock started"); cout << endl;
log(measure2String(duration));cout << endl;
//store duration
durations[changeCount++] = duration;
lockChange = 1;
} else if (lockChange == 1 && duration > 7000 && duration < 9000 && lockPassed == 0) {
log("Lock started 2"); cout << endl;
log(measure2String(duration));cout << endl;
durations[changeCount++] = duration;
lockChange = 2;
} else if (lockChange == 2 && duration > 3000 && duration < 5000 && lockPassed == 0) {
log("Lock started 3"); cout << endl;
log(measure2String(duration));cout << endl;
durations[changeCount++] = duration;
lockChange = 3;
lockPassed = 1; //lock is finished
}
else if (lockPassed != 0) { // REST OF DATA
//log(measure2String(duration));
if (changeCount > MAX_CHANGE_TO_KEEP) { // store 100 change Max
//ended
lockPassed = 0;
changeCount = 0;
lockChange = 0;
log("===============================");
for (int i=0; i < MAX_CHANGE_TO_KEEP; i=i++) {
log(measure2String(durations[i]));
log(" ");
}
cout << endl;
} else {
//store duration
durations[changeCount++] = duration;
}
} else {
//wait for another
changeCount = 0;
lockChange = 0;
lockPassed = 0;
}
lastTime = time;
}
int main(void) {
if(wiringPiSetup() == -1)
return 0;
//attach interrupt to changes on the pin
wiringPiISR(2, INT_EDGE_BOTH, &handleInterrupt);
//interrupt will handle changes
while(true);
}