forked from haraldh/iconsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testspeed.py
46 lines (40 loc) · 1.22 KB
/
testspeed.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
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 bluetooth import *
from SpeedTx import SpeedTx
from iConst import *
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 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)
speed.update(speed = 25)
#print("Speed: %s" % i)
i += 1
if (i > 200):
break
if speed:
print "Closing speed sensor"
speed.close()
speed.unassign()
if antnode:
print "Stopping ANT node"
antnode.stop()