This commit is contained in:
Harald Hoyer 2017-04-20 08:59:58 +02:00
parent 00c9b306b0
commit cb7612b32d

View file

@ -45,8 +45,6 @@ from time import sleep
from binascii import hexlify from binascii import hexlify
from ant.core import driver from ant.core import driver
from ant.core import node from ant.core import node
from PowerMeterTx import PowerMeterTx
from constants import *
from bluetooth import * from bluetooth import *
from ant.core import message from ant.core import message
from ant.core.constants import * from ant.core.constants import *
@ -61,7 +59,6 @@ INIT_A4 = struct.pack('BBBBBBBBBBBBBBB', 0xf0, 0xa4, 0x01, 0x01, 0x01, 0x01, 0x0
START = struct.pack('BBBBBB', 0xf0, 0xa5, 0x01, 0x01, 0x02, 0x99) START = struct.pack('BBBBBB', 0xf0, 0xa5, 0x01, 0x01, 0x02, 0x99)
STOP = struct.pack('BBBBBB', 0xf0, 0xa5, 0x01, 0x01, 0x04, 0x9b) STOP = struct.pack('BBBBBB', 0xf0, 0xa5, 0x01, 0x01, 0x04, 0x9b)
READ = struct.pack('BBBBB', 0xf0, 0xa2, 0x01, 0x01, 0x94) READ = struct.pack('BBBBB', 0xf0, 0xa2, 0x01, 0x01, 0x94)
POWER_SENSOR_ID = int(int(hashlib.md5(getserial()).hexdigest(), 16) & 0xfffe) + 1
DEBUG = False DEBUG = False
LOG = None LOG = None
NETKEY = '\xB9\xA5\x21\xFB\xBD\x72\xC3\x45' NETKEY = '\xB9\xA5\x21\xFB\xBD\x72\xC3\x45'
@ -90,6 +87,8 @@ def getserial():
return cpuserial return cpuserial
POWER_SENSOR_ID = int(int(hashlib.md5(getserial()).hexdigest(), 16) & 0xfffe) + 1
# Transmitter for Bicycle Power ANT+ sensor # Transmitter for Bicycle Power ANT+ sensor
class PowerMeterTx(object): class PowerMeterTx(object):
class PowerData: class PowerData:
@ -277,7 +276,7 @@ def main(win):
level = 1 level = 1
while True: while True:
sleep(0.3) sleep(0.25)
while True: while True:
key = win.getch() key = win.getch()
if key == ord('q'): if key == ord('q'):
@ -299,6 +298,7 @@ def main(win):
got = send_ack(READ, plen=21) got = send_ack(READ, plen=21)
if len(got) == 21: if len(got) == 21:
ic = IConsole(got) ic = IConsole(got)
power_meter.update(power = ic.power, cadence = ic.rpm)
win.addstr(0,0, "%s - %s - %s - %s - %s - %s - %s - %s" % (ic.time_str, win.addstr(0,0, "%s - %s - %s - %s - %s - %s - %s - %s" % (ic.time_str,
ic.speed_str, ic.speed_str,
ic.rpm_str, ic.rpm_str,
@ -309,11 +309,10 @@ def main(win):
ic.lvl_str)) ic.lvl_str))
win.clrtoeol() win.clrtoeol()
win.refresh() win.refresh()
power_meter.update(power = ic.power, cadence = ic.rpm)
if __name__ =='__main__': if __name__ =='__main__':
sock = btcon() sock = btcon()
stick = driver.USB1Driver(device="/dev/ttyUSB0", log=LOG, debug=DEBUG) stick = driver.USB1Driver(device="/dev/ttyANT", log=LOG, debug=DEBUG)
antnode = node.Node(stick) antnode = node.Node(stick)
print("Starting ANT node") print("Starting ANT node")
antnode.start() antnode.start()