-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb2str.cpp
More file actions
40 lines (33 loc) · 745 Bytes
/
b2str.cpp
File metadata and controls
40 lines (33 loc) · 745 Bytes
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
/*
convert binary stream (from tvbg via ttyUSB0) to text string
input is 16 bit binary representing duration of mark/space
output is duration in micro-second
$ g++ -o b2str b2str.cpp
$ stty -F /dev/ttyUSB0 115200 raw
$ cat /dev/ttyUSB0 | ./b2str
*/
#include <iostream>
using namespace std;
int main() {
unsigned short m, s;
float f;
freopen(NULL, "rb", stdin);
while (1) {
fread(&m, 2, 2, stdin);
m -= 17; f = 4.8 * m; m = (int)f;
if (s > 0) {
s += 17;
f = 4.8 * s; s = (int)f;
}
cout << m << " " << s << endl;
}
return 0;
}
/*
#!/usr/bin/python
import serial, struct
ser = serial.Serial('/dev/ttyUSB0', 115200)
while True:
val = struct.unpack('<HH', ser.read(4))
print val
*/