-
Notifications
You must be signed in to change notification settings - Fork 1
/
recpt3.py
executable file
·59 lines (46 loc) · 1.12 KB
/
recpt3.py
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
#!/usr/local/bin/python
import sys
import os
import json
import subprocess
import time
def load_channel_list():
f = open("channel.json","r")
j = f.read()
f.close()
ch = json.loads(j)
if not ch.has_key("channels"):
return None
return ch["channels"]
def usage():
print "%s [device] [channel]" % (sys.argv[0])
def tunning(dev,ch):
mib = "dev.ptx.0.%s.freq" % (dev)
subprocess.call("sysctl %s=%d > /dev/null 2>&1" % (mib,ch["freq"]),shell=True)
# wait for reception to stabilize
time.sleep(5)
def recording(dev):
dev = "/dev/ptx0.%s" % dev
f = open(dev,"rb")
while True:
buf = f.read(1024)
sys.stdout.write(buf)
def main(argv):
if len(argv) < 3:
usage()
return
channel = load_channel_list()
if channel is None:
print "invalid channel.json"
return -1
node = argv[1]
ch = argv[2]
if not channel.has_key(ch):
print "channel '%s' is not defined" % ch
return -2
ch = channel[ch]
tunning(node, ch)
recording(node)
return 0
if __name__ == "__main__":
exit(main(sys.argv))