Tigge / openant

ANT and ANT-FS Python Library
MIT License
174 stars 80 forks source link

Is TX support working? #61

Closed kkarsten62 closed 1 year ago

kkarsten62 commented 3 years ago

Hello,

I am new to ANT and Python development, but I have already set up heart rate monitor and cadence sensor working in a Python/PyQt app. Works fine - many thanks to all founders of all this nice stuff :-)

Now I would like to adapt the Garmin Edge remote control to my app: https://www.thisisant.com/directory/edge-remote-control/ I asked already in ant forum: https://www.thisisant.com/forum/viewthread/7454/ but I am still blocked.

So far, what I understood is that we now have to switch from Slave to Master, so I followed the nice example speed_and_distance.py which simulate a kind of "Treadmill".

I thought that when starting the script that in any case the method self.on_event_tx (self.channel.on_broadcast_tx_data = self.on_event_tx) will be triggered by each EVENT_TX. But this happens not. The on_event_tx method will never be called and so the broadcast buffer will never be filled with Treadmill data. I set some 'prints' in the Ant basic code and I see that the receiving events are always 1, which means a kind of timeout.

In parallel I set up a slave (a second small laptop with ANT+ USB Stick) for receiving the treadmill data. I guess that pairing is successful because the on_data method (channel.on_broadcast_data = on_data) will be triggered twice on the slave, but all data bytes are zero.

Maybe somebody can test this behavior.

Any help is appreciated.

kkarsten62

kkarsten62 commented 3 years ago

I have reviewed the ant.py code and from my understanding there is a bug. message._data[1] is always be 0x01 which is interpreted as EVENT_RX_SEARCH_TIMEOUT. So event EVENT_TX will never be issued and the broadcast data from master will never be sent. According to D00000652_ANT_Message_Protocol_and_Usage_Rev_5.1.pdf (Page 54) the right event code is in message._data[2]. I changed ant.py and attached there is an example which works now properly. garmin_edge_remote_control.py.txt

diff --git a/ant/base/ant.py b/ant/base/ant.py
index 7771459..7134818 100644
--- a/ant/base/ant.py
+++ b/ant/base/ant.py
@@ -183,7 +183,7 @@ class Ant:
                         self._events.put(
                             (
                                 "event",
-                                (message._data[0], message._data[1], message._data[2:]),
+                                (message._data[0], message._data[2], message._data[2:]),
                             )
                         )
                     elif message._id == Message.ID.BROADCAST_DATA:
kkarsten62 commented 3 years ago

Attached a next example for a Remote Control from o_synce, which works also properly. In addition to the Garmin Edge Remote Control you can use 6 different button click states and it broadcasts page 80,81 and 82 which provides information about hard-, software and battery status.

https://www.thisisant.com/directory/antremote https://www.o-synce-shop.de/shop/en/accessories/remotes/81/ant-remote-wireless-remote-control?c=32 o_synce_remote_control.py.txt

kkarsten62

tuna-f1sh commented 1 year ago

I had a look into this, checking the ANT Message Protocol and agree it is a bug where you say; for a RF EVENT_ Message ID is 0x01 and one should use data[2] as the event code. I've pushed a fix and will merge to a new release.

Screenshot 2023-01-30 at 15 46 51