forked from pabutusa/multirx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfiguration.py
More file actions
executable file
·64 lines (42 loc) · 1.43 KB
/
configuration.py
File metadata and controls
executable file
·64 lines (42 loc) · 1.43 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
#!/usr/bin/env python2
import xml.etree.ElementTree as ET
import sys
class Configuration:
def __init__(self, filename):
try:
self.tree = ET.parse(filename)
except IOError:
sys.exit("configuration file not found.")
self.root = self.tree.getroot()
self.channel = []
for self.i in self.root.findall('channel'):
self.frequency = int(float(self.i.find('frequency').text)*1E6)
self.key = self.i.find('key').text
self.description = self.i.find('description').text
self.ctcss = float(self.i.find('ctcss').text)
self.x = (self.key, self.frequency, self.description, self.ctcss)
self.channel.append(self.x)
self.high = 0
for self.j in self.channel:
if self.j[1] > self.high:
self.high = self.j[1]
self.low = float("inf")
for self.j in self.channel:
if self.j[1] < self.low:
self.low = self.j[1]
self.middle = self.lower() + ((self.upper() - self.lower())/2)
def upper(self):
return self.high
def lower(self):
return self.low
def center(self):
return self.middle
if __name__ == '__main__':
config = Configuration('receiver.xml')
high = config.upper()
low = config.lower()
center = config.center()
print "high=%d low=%d" % (high, low)
print "center=%d" % center
for i in config.channel:
print i