Ant.MSG_CODE_EVENT_TRANSFER_TX_COMPLETED
twice every time I call Ant.GenericChannel.sendAcknowledge()
, which is disrupting my state machine.I only have one Connect app on my Edge 520. I only have one profile using one Connect data field. I've looked everywhere to find the cause.
I have distilled the code into a single-file app, which exhibits the problem, attached below. The suspicious debug output from this app includes lines like this, where you can see the msg.timestamp value is repeated.
*** id=78, timestamp=29667, Obj: 144
*** id=78, timestamp=29667, Obj: 144
*** id=78, timestamp=46051, Obj: 144
*** id=78, timestamp=46051, Obj: 144
*** id=78, timestamp=62435, Obj: 144
*** id=78, timestamp=62435, Obj: 144
*** id=78, timestamp=13282, Obj: 144
*** id=78, timestamp=13282, Obj: 144
*** id=78, timestamp=29666, Obj: 144
*** id=78, timestamp=29666, Obj: 144
*** id=78, timestamp=46050, Obj: 144
*** id=78, timestamp=46050, Obj: 144
Any tips would be greatly appreciated...I'm out of ideas.
Thanks.
using Toybox.Application;
using Toybox.System;
using Toybox.Communications;
using Toybox.Background;
using Toybox.Ant;
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.Time;
class DataFieldView extends Ui.SimpleDataField {
function initialize() {
SimpleDataField.initialize();
label = "test";
}
function compute(info) {
return Time.now().value();
}
}
class DataFieldApp extends Application.AppBase {
const DEVICE_ID = 22;
const DEVICE_TYPE = 0x08;
const MESSAGE_PERIOD = 32768 / 2;
var channel;
function initialize() {
AppBase.initialize();
}
function onStart(state) {
channel = new Ant.GenericChannel(method(:onMessage), new Ant.ChannelAssignment(Ant.CHANNEL_TYPE_RX_NOT_TX, Ant.NETWORK_PUBLIC));
var device = new Ant.DeviceConfig({
:deviceNumber => DEVICE_ID,
:deviceType => DEVICE_TYPE,
:transmissionType => 0,
:messagePeriod => MESSAGE_PERIOD,
:radioFrequency => 66, // 66 is the default frequency band
:searchTimeoutLowPriority => 12, //30s timeout
:searchThreshold => 0}); //pair to all transmitting devices
channel.setDeviceConfig(device);
channel.open();
}
function onStop(state) {
channel.release();
channel = null;
}
function getInitialView() {
return [ new DataFieldView() ];
}
function onMessage(msg) {
System.println("*** id=" + msg.messageId + ", " + msg.timestamp + ", " + msg);
var payload = msg.getPayload();
if(Ant.MSG_ID_BROADCAST_DATA == msg.messageId) {
}
else if(Ant.MSG_ID_CHANNEL_RESPONSE_EVENT == msg.messageId) {
if(payload[0] == Ant.MSG_ID_RF_EVENT) {
var messageCode = payload[1];
System.println("messageCode=" + messageCode.format("%X"));
switch(messageCode) {
case Ant.MSG_CODE_EVENT_CHANNEL_CLOSED:
System.println("channel closed; trying to re-open");
channel.open();
break;
}
} else {
//message is a "channel response"
var initiatingMsgId = payload[0];
var responseCode = payload[1];
if(responseCode != Ant.MSG_CODE_RESPONSE_NO_ERROR) {
System.println("******** channel response, msgId=" + initiatingMsgId.format("%X") + ", responseCode=" + responseCode.format("%X"));
}
}
}
else {
System.println("******** unknown= " + msg.messageId.format("%X"));
}
}
}