From c8f51ead7ef13ac2211a8bb2a330c0d320c633f4 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 21 Apr 2017 16:12:57 +0200 Subject: [PATCH] ii --- PowerMeterTx.py | 2 +- README.md | 18 +++++++++++++++++- SpeedTx.py | 2 +- iconsole.py => iConsole.py | 9 ++++++--- const.py => iConst.py | 1 - requirements.txt | 2 ++ testpower.py | 7 ++++--- testspeed.py | 7 ++++--- 8 files changed, 35 insertions(+), 13 deletions(-) rename iconsole.py => iConsole.py (97%) mode change 100644 => 100755 rename const.py => iConst.py (91%) create mode 100644 requirements.txt diff --git a/PowerMeterTx.py b/PowerMeterTx.py index 76864e9..9d977e0 100644 --- a/PowerMeterTx.py +++ b/PowerMeterTx.py @@ -1,7 +1,7 @@ from ant.core import message from ant.core.constants import * from ant.core.exceptions import ChannelError -from const import * +from iConst import * import thread from binascii import hexlify import struct diff --git a/README.md b/README.md index 6d2a158..2fbc4a8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ # iconsole -reverse engineering of the iconsole+ bike computer serial protocol +Reverse engineering of the iconsole+ bike computer serial protocol. + +Broadcasts the power and speed on the ANT network. + +## Requirements + +``` +$ pip install --user requirements.txt +``` + +## Usage + +``` +$ python iConsole.py +``` + +Use the ANT+ network key to record the data with ANT+ compatible devices, such as a bike computer or fitness watch. \ No newline at end of file diff --git a/SpeedTx.py b/SpeedTx.py index ae4328f..7a08afb 100644 --- a/SpeedTx.py +++ b/SpeedTx.py @@ -1,7 +1,7 @@ from ant.core import message from ant.core.constants import * from ant.core.exceptions import ChannelError -from const import * +from iConst import * import thread from binascii import hexlify import struct diff --git a/iconsole.py b/iConsole.py old mode 100644 new mode 100755 similarity index 97% rename from iconsole.py rename to iConsole.py index 0864fc4..68db965 --- a/iconsole.py +++ b/iConsole.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + # f0:b2 01:01:04:06 03:11 01:3b 01:07 01:0d 01:01 0f:33 09 02 # T: 3:05 21.0km/h RPM58 D:0.6 cal 12 HF 0 W:1450 LVL8 # @@ -42,13 +44,13 @@ import serial, struct, sys, hashlib, curses from time import sleep -from binascii import hexlify +from binascii import hexlify,unhexlify from ant.core import driver from ant.core import node from bluetooth import * from PowerMeterTx import PowerMeterTx from SpeedTx import SpeedTx -from const import * +from iConst import * INIT_A0 = struct.pack('BBBBB', 0xf0, 0xa0, 0x02, 0x02, 0x94) PING = struct.pack('BBBBB', 0xf0, 0xa0, 0x01, 0x01, 0x92) @@ -232,9 +234,10 @@ def main(win): win.refresh() if __name__ =='__main__': + NETKEY = unhexlify(sys.argv[1]) stick = driver.USB1Driver(device="/dev/ttyANT", log=LOG, debug=DEBUG) antnode = node.Node(stick) - print("Starting ANT node") + print("Starting ANT node on network %s" % sys.argv[1]) antnode.start() key = node.NetworkKey('N:ANT+', NETKEY) antnode.setNetworkKey(0, key) diff --git a/const.py b/iConst.py similarity index 91% rename from const.py rename to iConst.py index 18a03cb..fa3cfbb 100644 --- a/const.py +++ b/iConst.py @@ -1,4 +1,3 @@ -NETKEY = '\xB9\xA5\x21\xFB\xBD\x72\xC3\x45' CADENCE_DEVICE_TYPE = 0x7A SPEED_DEVICE_TYPE = 0x7B SPEED_CADENCE_DEVICE_TYPE = 0x79 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5ca292f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +git+https://github.com/baderj/python-ant.git +pybluez diff --git a/testpower.py b/testpower.py index e0557fb..81ede05 100644 --- a/testpower.py +++ b/testpower.py @@ -1,20 +1,21 @@ import serial, struct, sys, hashlib, curses from time import sleep -from binascii import hexlify +from binascii import hexlify,unhexlify from ant.core import driver from ant.core import node from bluetooth import * from PowerMeterTx import PowerMeterTx -from const import * +from iConst import * power_meter = None POWER_SENSOR_ID = int(int(hashlib.md5(getserial()).hexdigest(), 16) & 0xfffe) + 1 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") + print("Starting ANT node on network %s" % sys.argv[1]) antnode.start() key = node.NetworkKey('N:ANT+', NETKEY) antnode.setNetworkKey(0, key) diff --git a/testspeed.py b/testspeed.py index 6fd4a3a..7693cda 100644 --- a/testspeed.py +++ b/testspeed.py @@ -1,20 +1,21 @@ import serial, struct, sys, hashlib, curses from time import sleep -from binascii import hexlify +from binascii import hexlify,unhexlify from ant.core import driver from ant.core import node from bluetooth import * from SpeedTx import SpeedTx -from const import * +from iConst import * speed = None SPEED_SENSOR_ID = int(int(hashlib.md5(getserial()).hexdigest(), 16) & 0xfffe) + 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") + print("Starting ANT node on network %s" % sys.argv[1]) antnode.start() key = node.NetworkKey('N:ANT+', NETKEY) antnode.setNetworkKey(0, key)