Class: Toybox.Ant.GenericChannel

Overview

A class for controlling an ANT wireless channel.

The GenericChannel provides the methods necessary for initialization, life cycle, and encryption of ANT channels.

Since:

API Level 1.0.0

Instance Method Summary collapse

Instance Method Details

close() as Void

Close a generic ANT Channel.

Example:

using Toybox.Ant;
GenericChannel.close();

Since:

API Level 1.0.0

disableEncryption() as Void

Disable encryption on this channel.

Example:

using Toybox.Ant;
GenericChannel.disableEncryption();

Supported Devices:

Since:

API Level 2.3.0

enableEncryption(configuration as Ant.CryptoConfig) as Void

Set the encryption configuration and enable encryption on this channel.

Parameters:

  • configuration(Ant.CryptoConfig)

    The CryptoConfig object to set for the current channel

Example:

using Toybox.Ant;
// Assuming a valid CryptoConfig object is available
var configuration = Ant.CryptoConfig;
GenericChannel.enableEncryption(cryptoConfig);

Supported Devices:

See Also:

Since:

API Level 2.3.0

Throws:

getDeviceConfig() as Ant.DeviceConfig

Get the current ANT channel configuration.

Example:

using Toybox.Ant;
var devConfig = GenericChannel.getDeviceConfig();
// devConfig can now be parsed for configuration info
// from the DeviceConfig object

Returns:

  • Ant.DeviceConfig

    The DeviceConfig object with current channel device configuration.

See Also:

Since:

API Level 1.0.0

initialize(listener as Lang.Method(msg as Ant.Message) as Void, channelAssignment as Ant.ChannelAssignment)

Constructor

Parameters:

  • listener(Lang.Method)

    The Method object to call with channel messages

  • channelAssignment(Ant.ChannelAssignment)

    The ChannelAssignment object for the channel

Example:

using Toybox.Ant;
// Assumes a listenerCallback method
// and ChannelAssignment object supplied
// as parameters upon initialization
GenericChannel.initialize(method(:listenerCallback), channelAssign);

Since:

API Level 1.0.0

Throws:

open() as Lang.Boolean

Open a generic ANT Channel.

Note:

Multitasking: Ant channel connection can not be changed while in inacitve mode and ant channels opened during active mode will be closed when app becomes inactive, and re-opened automatically when is active again. These state changes are denoted by calls to AppBase.onActive() and AppBase.onInactive().

Example:

using Toybox.Ant;
GenericChannel.open();

Returns:

  • Lang.Boolean

    If channel is successfully opened return true, otherwise false

Since:

API Level 1.0.0

release() as Void

Release the generic ANT Channel back to the system.

If the channel is open it will be automatically closed.

Example:

using Toybox.Ant;
GenericChannel.release();

Since:

API Level 1.0.0

sendAcknowledge(data as Ant.Message) as Void

Send an acknowledge message.

You can expect to receive either MSG_CODE_EVENT_TRANSFER_TX_COMPLETED or MSG_CODE_EVENT_TRANSFER_TX_FAILED if the message succeeded/failed going to the recipient.

Parameters:

  • data(Lang.Number)

    An 8 byte data packet as an Array of 8 numbers

Example:

using Toybox.Ant;
// create a data Array to format Message
var data = new[8];
for (var i = 0; i < 8; i++)
{
    data[i] = i + 1;    // Set the values of each member
}
var message = new Ant.Message();
message.setPayload(data);   // Assumes valid data
GenericChannel.sendAcknowledge(message);

See Also:

Since:

API Level 1.0.0

sendBroadcast(data as Ant.Message) as Void

Send a broadcast message.

Parameters:

  • data(Lang.Number)

    An 8 byte data packet as an Array of 8 numbers

Example:

using Toybox.Ant;
// create a data Array to format Message
var data = new[8];
for (var i = 0; i < 8; i++)
{
    data[i] = i + 1;    // Set the values of each member
}
var message = new Ant.Message();
message.setPayload(data);   // Assumes valid data
GenericChannel.sendBroadcast(message);

See Also:

Since:

API Level 1.0.0

sendBurst(burstData as Ant.BurstPayload) as Void

Send an Array of Messages as a burst across the ANT channel.

Success or Fail is received by the BurstListener.

Parameters:

Example:

using Toybox.Ant;
var burstData = new Ant.BurstPayload(); // Create new payload

// Message must contain a valid payload
burstData.add(message);                 // Add Message object to payload
GenericChannel.sendBurst(burstData);    // Send Message

See Also:

Since:

API Level 2.2.0

Throws:

setBurstListener(listener as Ant.BurstListener) as Void

Set the BurstListener for burst events.

Failed bursts or those larger than the specified threshold will be discarded.

Parameters:

Example:

using Toybox.Ant;
// Assumes a valid BurstListener object as a parameter
GenericChannel.setBurstListener(listener);

See Also:

Since:

API Level 2.2.0

Throws:

setDeviceConfig(configuration as Ant.DeviceConfig) as Void

Set the current ANT channel configuration.

Parameters:

  • configuration(Ant.DeviceConfig)

    The DeviceConfig object to set for the current ANT channel

Example:

using Toybox.Ant;
// Assuming a valid DeviceConfig object is available
var configuration = Ant.DeviceConfig;
GenericChannel.setDeviceConfig(configuration);

See Also:

Since:

API Level 1.0.0


Generated Jan 5, 2024 1:53:13 PM