I made a data field based on https://developer.garmin.com/connect-iq/core-topics/ant-and-ant-plus/ and github.com/.../AuxHR.
It seems that Garmin has changed the ANT certification process because even though this part of the code is exactly as in github my app failed to certify. I got this response:
"The acknowledge message type cannot be paired on the tested device. Accounting to ANT+ device profile, the acknowledge message type should be supported."
Does anyone have a working code for ANT Heart Rate Monitor that passes certification and is publicly available?
This is my code: function onMessage(msg as Message) {
// Parse the payload
var payload = msg.getPayload();
if (Ant.MSG_ID_BROADCAST_DATA == msg.messageId) {
// Were we searching?
if (searching) {
searching = false;
// Update our device configuration primarily to see the device number of the sensor we paired to
deviceCfg = GenericChannel.getDeviceConfig();
System.println("Found: " + deviceCfg.deviceNumber);
}
data.parse(payload);
} else if (Ant.MSG_ID_ACKNOWLEDGED_DATA == msg.messageId) {
System.println("ACK_DATA " + payload + ", len: " + msg.length + ", txType: " + msg.transmissionType);
} else if (Ant.MSG_ID_CHANNEL_RESPONSE_EVENT == msg.messageId) {
var msgId = payload[0] & 0xFF;
if (Ant.MSG_ID_RF_EVENT == msgId) {
var msgCode = payload[1] & 0xFF;
if (Ant.MSG_CODE_EVENT_CHANNEL_CLOSED == msgCode) {
// Channel closed, re-open
System.println("Re-open");
open();
} else if (Ant.MSG_CODE_EVENT_RX_FAIL_GO_TO_SEARCH == msgCode) {
System.println("Failed, go to search");
searching = true;
}
} else if (log) {
//It is a channel response.
}
}
}
and here's my channel init code: // Get the channel
chanAssign = new Ant.ChannelAssignment(
Ant.CHANNEL_TYPE_RX_NOT_TX, // Bidirectional Receive (Slave)
Ant.NETWORK_PLUS);
GenericChannel.initialize(method(:onMessage), chanAssign);
// Set the configuration
deviceCfg = new Ant.DeviceConfig( {
:deviceNumber => antID, //Set to 0 to use wildcard search
:deviceType => 120, // Heart Rate Sensors
:transmissionType => 0,
:messagePeriod => 8070,
:radioFrequency => 57, //Ant+ Frequency
:searchTimeoutLowPriority => 10, //Timeout in 25s
:searchThreshold => 0} ); //Pair to all transmitting sensors
GenericChannel.setDeviceConfig(deviceCfg);