This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
forked from timvandermeij/mobile-radio-tomography
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xbee_configurator.py
59 lines (49 loc) · 2.11 KB
/
xbee_configurator.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
import sys
from __init__ import __package__
from core.USB_Manager import USB_Manager
from settings import Arguments
from zigbee.XBee_Configurator import XBee_Configurator
COLORS = {
"green": "\033[92m",
"red": "\033[91m",
"end": "\033[0m"
}
def main(argv):
arguments = Arguments("settings.json", argv)
settings = arguments.get_settings("xbee_configurator")
arguments.check_help()
usb_manager = USB_Manager()
for sensor_id in range(0, settings.get("number_of_sensors") + 1):
if sensor_id == 0:
raw_input("Connect the ground station XBee sensor and press Enter...")
else:
raw_input("Connect XBee sensor {} and press Enter...".format(sensor_id))
usb_manager.index()
parameters = {
"ID": settings.get("pan_id"),
"NI": str(sensor_id),
"PM": 0,
"PL": 0
}
xbee_configurator = XBee_Configurator(arguments, usb_manager)
# Show the current parameters.
for key in parameters.iterkeys():
value = xbee_configurator.get(key)
if value != None:
print("{}[Sensor {}] {} is {}.{}".format(COLORS["green"], sensor_id, key, value, COLORS["end"]))
else:
print("{}[Sensor {}] {} is unknown.{}".format(COLORS["red"], sensor_id, key, COLORS["end"]))
# Set the new parameters.
for key, value in parameters.iteritems():
if xbee_configurator.set(key, value):
print("{}[Sensor {}] {} set to {}.{}".format(COLORS["green"], sensor_id, key, value, COLORS["end"]))
else:
print("{}[Sensor {}] {} not set to {}.{}".format(COLORS["red"], sensor_id, key, value, COLORS["end"]))
# Write the changes to the sensor.
if xbee_configurator.write():
print("{}[Sensor {}] Changes written to sensor.{}".format(COLORS["green"], sensor_id, COLORS["end"]))
else:
print("{}[Sensor {}] Changes not written to sensor.{}".format(COLORS["red"], sensor_id, COLORS["end"]))
usb_manager.clear()
if __name__ == "__main__":
main(sys.argv[1:])