-
Notifications
You must be signed in to change notification settings - Fork 5
/
testpowerspeed.py
61 lines (54 loc) · 1.79 KB
/
testpowerspeed.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
60
import serial, struct, sys, hashlib, curses
from time import sleep
from binascii import hexlify,unhexlify
from ant.core import driver
from ant.core import node
from PowerMeterTx import PowerMeterTx
from SpeedTx import SpeedTx
from iConst import *
power_meter = None
POWER_SENSOR_ID = int(int(hashlib.md5(getserial()).hexdigest(), 16) & 0xFFFFfffe) + 1
speed = None
SPEED_SENSOR_ID = int(int(hashlib.md5(getserial()).hexdigest(), 16) & 0xFFFFfffe) + 2
if __name__ =='__main__':
NETKEY = unhexlify(sys.argv[1])
stick = driver.USB1Driver(device="/dev/ttyANT", log=None, debug=True)
antnode = node.Node(stick)
print("Starting ANT node on network %s" % sys.argv[1])
antnode.start()
key = node.NetworkKey('N:ANT+', NETKEY)
antnode.setNetworkKey(0, key)
print("Starting power meter with ANT+ ID " + repr(POWER_SENSOR_ID))
try:
# Create the power meter object and open it
power_meter = PowerMeterTx(antnode, POWER_SENSOR_ID)
power_meter.open()
except Exception as e:
print("power_meter error: " + e.message)
power_meter = None
print("Starting speed sensor with ANT+ ID " + repr(SPEED_SENSOR_ID))
try:
speed = SpeedTx(antnode, SPEED_SENSOR_ID, wheel = 0.1)
speed.open()
except Exception as e:
print("speed error: " + e.message)
speed = None
i = 0
while True:
sleep(1)
power_meter.update(power = i, cadence = i)
speed.update(speed = 25)
i += 1
if (i > 200):
break
if power_meter:
print "Closing power meter"
power_meter.close()
power_meter.unassign()
if speed:
print "Closing speed sensor"
speed.close()
speed.unassign()
if antnode:
print "Stopping ANT node"
antnode.stop()