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 Lang.Boolean

Close a generic ANT Channel.

Example:

using Toybox.Ant;

// Assumes a valid GenericChannel object
genericChannel.close();

Returns:

Since:

API Level 1.0.0

disableEncryption() as Lang.Boolean

Disable encryption on this channel.

Example:

using Toybox.Ant;

// Assumes a valid GenericChannel object
genericChannel.disableEncryption();

Supported Devices:

Returns:

Since:

API Level 2.3.0

enableEncryption(configuration as Ant.CryptoConfig) as Lang.Boolean

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;
var cryptoConfig = new Ant.CryptoConfig({});

// Assumes a valid GenericChannel object
genericChannel.enableEncryption(cryptoConfig);

Supported Devices:

Returns:

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 fields can now be accessed for configuration info

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;

// Assumes a valid GenericChannel object
genericChannel.open();

Returns:

Since:

API Level 1.0.0

release() as Lang.Boolean

Release the generic ANT Channel back to the system.

If the channel is open it will be automatically closed.

Example:

using Toybox.Ant;

// Assumes a valid GenericChannel object
genericChannel.release();

Returns:

Since:

API Level 1.0.0

sendAcknowledge(data as Ant.Message) as Lang.Boolean

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(Ant.Message)

    A message whose payload is an 8-byte Array of 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

// Assumes a valid GenericChannel object
genericChannel.sendAcknowledge(message);

Returns:

See Also:

Since:

API Level 1.0.0

sendBroadcast(data as Ant.Message) as Lang.Boolean

Send a broadcast message.

Parameters:

  • data(Ant.Message)

    A message whose payload is an 8-byte Array of 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

// Assumes a valid GenericChannel object
genericChannel.sendBroadcast(message);

Returns:

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

// Assumes a valid GenericChannel object
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 GenericChannel object
// 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 Lang.Boolean

Set the current ANT channel configuration.

Parameters:

  • configuration(Ant.DeviceConfig)

    The DeviceConfig object to set for the current ANT channel

Example:

using Toybox.Ant;
var configuration = new Ant.DeviceConfig({});

// Assumes a valid GenericChannel object
genericChannel.setDeviceConfig(configuration);

Returns:

See Also:

Since:

API Level 1.0.0

Throws:

  • (Lang.UnexpectedTypeError)

    Thrown if configuration values in configuration are not of the correct type.


Generated Dec 11, 2024, 8:58:42 AM