public final class AntChannel
extends java.lang.Object
This class is parcelable and can therefore be passed between processes. In this case care must be
taken that setChannelEventHandler(IAntChannelEventHandler)
and
clearChannelEventHandler()
are used properly. Also note that all copies of this object can make
calls into the ANT Radio Service, so who is making calls must be properly co-ordinated or changes to
the channel state from other processes must be accounted for.
Modifier and Type | Field and Description |
---|---|
static |
CREATOR
Creates an AntChannel from a Parcel
|
Modifier and Type | Method and Description |
---|---|
void |
addIdToInclusionExclusionList(ChannelId channelId,
int listIndex)
Adds channel IDs to the inclusion/exclusion list for this channel.
|
void |
assign(ChannelType channelType)
Specifies the type of this channel and prepares the channel for use.
|
void |
assign(ChannelType channelType,
ExtendedAssignment extendedAssignment)
Specifies the type of this channel and prepares the channel for use.
|
void |
burstTransfer(byte[] data)
Transmits the given data on this channel as a series of burst messages.
|
void |
clearAdapterEventHandler()
Clears the handler registered to this callback through
setAdapterEventHandler(IAntAdapterEventHandler) and closes its associated resources. |
void |
clearChannelEventHandler()
Clears the handler registered to this callback through
setChannelEventHandler(IAntChannelEventHandler) and closes its associated resources. |
void |
close()
Closes this channel.
|
void |
configureFrequencyAgility(int freq1,
int freq2,
int freq3)
Configures the frequency agility feature for this channel.
|
void |
configureInclusionExclusionList(int listSize,
boolean exclude)
Configures the inclusion/exclusion list for this channel which allows specifying specific
channel IDs to ignore or include in a search.
|
int |
describeContents() |
void |
disableEventBuffer()
Disables event buffering for the entire adapter.
|
BackgroundScanState |
getBackgroundScanState()
Gets the
BackgroundScanState of the ANT adapter this channel is running on. |
BurstState |
getBurstState()
Gets the
BurstState of the ANT adapter this channel is running on. |
Capabilities |
getCapabilities()
Gets the
Capabilities of this channel. |
EventBufferSettings |
getEventBufferSettings()
Gets the
EventBufferSettings of the ANT adapter this channel is running on. |
LibConfig |
getLibConfig()
Gets the
LibConfig of the ANT adapter this channel is running on. |
void |
open()
Opens this channel.
|
void |
release()
Does the opposite of
AntChannelProvider acquireChannel(), tearing down this
channel instance. |
AntVersionMessage |
requestAntVersion()
Asks the ANT Adapter this channel is running on for its version information.
|
CapabilitiesMessage |
requestCapabilities()
Asks the ANT Adapter this channel is running on for its Capabilities information.
|
ChannelIdMessage |
requestChannelId()
Asks the ANT Adapter for this channels ID information.
|
ChannelStatusMessage |
requestChannelStatus()
Asks the ANT Adapter for this channels status information.
|
void |
setAdapterEventHandler(IAntAdapterEventHandler eventHandler)
Sets up the handler to be used for event callbacks from the adapter this channel is on.
|
void |
setAdapterWideLibConfig(LibConfig libConfig)
Requests which extended data to include with data messages.
|
void |
setBroadcastData(byte[] payload)
Sets the broadcast message for this channel.
|
void |
setChannelEventHandler(IAntChannelEventHandler eventHandler)
Sets up the handler to be used for event callbacks from this channel.
|
void |
setChannelId(ChannelId channelId)
Configures the channel ID for this channel.
|
void |
setEventBuffer(EventBufferSettings eventBufferSettings)
Requests an event buffer with the desired values contained within the
EventBufferSettings . |
void |
setEventBufferToDefault()
Sets the event buffer to the default value defined by
EventBufferSettings.DEFAULT_BUFFER_TIME_MILLISECONDS . |
void |
setPeriod(int period_32768unitsPerSecond)
Configures the messaging period of this channel.
|
void |
setProximityThreshold(int searchThreshold)
Sets a signal strength 'proximity' requirement on finding matches during searching.
|
void |
setRfFrequency(int radioFrequencyOffset)
Sets the RF frequency for this channel by a frequency offset, e.g.
|
void |
setSearchPriority(int searchPriority)
Sets the search priority for this channel.
|
void |
setSearchTimeout(LowPrioritySearchTimeout lowPrioritySearchTimeout)
Configures the length of time that this channel will perform a search before timing out and closing.
|
void |
setSearchTimeout(LowPrioritySearchTimeout lowPrioritySearchTimeout,
HighPrioritySearchTimeout highPrioritySearchTimeout)
Configures the length of time that this channel will perform a search
before timing out and closing, including high priority search - warning:
high priority search can interfere with other active channels on
the same adapter.
|
void |
setTransmitPower(int outputPowerLevelSetting)
Sets the transmit power level for this channel.
|
void |
startSendAcknowledgedData(byte[] payload)
Sends an acknowledged message on this channel, without waiting for the result (complete
or failed).
|
void |
unassign()
Unassigns this channel.
|
void |
writeToParcel(Parcel dest,
int flags) |
public void assign(ChannelType channelType) throws RemoteException, AntCommandFailedException
A channel must be unassigned, using unassign()
, before it can be
reassigned.
See the ANT Message Protocol and Usage document for more details.
channelType
- Specify that this channel should be either a master or slave, and a
shared channel or not.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void assign(ChannelType channelType, ExtendedAssignment extendedAssignment) throws RemoteException, AntCommandFailedException
Capabilities
for the request to succeed. This clears channel configuration
to defaults.
A channel must be unassigned, using unassign()
, before it can be
reassigned.
See the ANT Message Protocol and Usage document for more details.
channelType
- Specify that this channel should be either a master or slave, and a
shared channel or not.extendedAssignment
- Indicates optional features to be enabled.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void unassign() throws RemoteException, AntCommandFailedException
assign(ChannelType)
.
When a channel is unassigned you should assume any channel configuration previously performed
on this channel has been lost.
See the ANT Message Protocol and Usage document for more details.
RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void setChannelId(ChannelId channelId) throws RemoteException, AntCommandFailedException
See the ANT Message Protocol and Usage document for more details.
channelId
- The device number, device type and transmission type to identify this channel.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void setPeriod(int period_32768unitsPerSecond) throws RemoteException, AntCommandFailedException
See the ANT Message Protocol and Usage document for more details.
period_32768unitsPerSecond
- The message period to use for this channel, in
1/32768ths of a second units. Valid range is 0-65535.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void setSearchPriority(int searchPriority) throws RemoteException, AntCommandFailedException, UnsupportedFeatureException
See the ANT Message Protocol and Usage document for more details.
searchPriority
- The search priority to be used for this channel.
Higher numbers are given higher priority. Valid range is
ChannelSearchPriorityMessage.LIB_MIN_SEARCH_PRIORITY
to
ChannelSearchPriorityMessage.LIB_MAX_SEARCH_PRIORITY
,
and other values are reserved for system use. If search
priority is not set, a channel automatically assumes the
default search priority value of
ChannelSearchPriorityMessage.LIB_DEFAULT_SEARCH_PRIORITY
.RemoteException
- If you receive this exception then the channel
should be considered dead. In this circumstance you can
attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.UnsupportedFeatureException
- If the service does not
support configuring search prioritypublic void setRfFrequency(int radioFrequencyOffset) throws RemoteException, AntCommandFailedException
getCapabilities()
) and calling Capabilities.getRfFrequencyMin()
and
Capabilities.getRfFrequencyMax()
. A frequency offset of 57 MHz (2457 MHz) is not
allowed and is reserved for use by the ANT+ Plugin API, which must be used to connect to
ANT+ devices. An attempt to set a frequency outside of these allowed values will fail with
a AntCommandFailureReason.INVALID_REQUEST
.
See the ANT
Message Protocol and Usage document for more details.radioFrequencyOffset
- The radio frequency to use for this channel's communication
as an offset in MHz from 2400MHz (2.4GHz).RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void addIdToInclusionExclusionList(ChannelId channelId, int listIndex) throws RemoteException, AntCommandFailedException
configureInclusionExclusionList(int, boolean)
is called.
See the ANT Message Protocol and Usage document for more details.
channelId
- The device number, device type and transmission type to identify this channel.listIndex
- The (0-based) index to place the ID at in the list. Valid range is 0-3. Always overwrites any existing value.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void configureInclusionExclusionList(int listSize, boolean exclude) throws RemoteException, AntCommandFailedException
addIdToInclusionExclusionList(ChannelId, int)
is used to configure
the IDs in the list.
See the ANT Message Protocol and Usage document for more details.
listSize
- The number of IDs to reference from the id list (starting at index 0).
Valid range is 0-4. 0=disable the list.exclude
- True to ignore the listed devices during a search. False to search for only
the listed devices during a search.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void setSearchTimeout(LowPrioritySearchTimeout lowPrioritySearchTimeout) throws RemoteException, AntCommandFailedException
The maximum search time available using this function is 25s. Setting the
timeout to LowPrioritySearchTimeout.DISABLED
will cause the
channel to immediately close when entering the search state.
Note: This API restricts against longer timeouts to ensure other channels have fair access to search time. If an application must search for longer periods of time then it can open the channel again to start a new search when the search times out. However, applications must give special consideration to avoid starting new searches when unnecessary to save battery and resources e.g. when the target device is no longer present or when the app is in the background.
See the ANT Message Protocol and Usage document for more details.
lowPrioritySearchTimeout
- The time before low priority search will timeout in 2.5s units.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.
Note: This function is not valid on channels in background
scanning mode and will fail with failure reason
AntCommandFailureReason.INVALID_REQUEST
public void setSearchTimeout(LowPrioritySearchTimeout lowPrioritySearchTimeout, HighPrioritySearchTimeout highPrioritySearchTimeout) throws RemoteException, AntCommandFailedException
The maximum search time available using this function is 30s. Setting the
timeout to LowPrioritySearchTimeout.DISABLED
and
HighPrioritySearchTimeout.DISABLED
will cause the channel to
immediately close when entering the search state.
Note: This API restricts against longer timeouts to ensure other channels have fair access to search time. If an application must search for longer periods of time then it can open the channel again to start a new search when the search times out. However, applications must give special consideration to avoid starting new searches when unnecessary to save battery and resources e.g. when the target device is no longer present or when the app is in the background.
See the ANT Message Protocol and Usage document for more details.
lowPrioritySearchTimeout
- The time before low priority search will timeout.highPrioritySearchTimeout
- The time before high priority search will timeout.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.
Note: This function is not valid on channels in background
scanning mode and will fail with failure reason
AntCommandFailureReason.INVALID_REQUEST
public void configureFrequencyAgility(int freq1, int freq2, int freq3) throws RemoteException, AntCommandFailedException
ExtendedAssignment.ExtendedAssignment()
, enableFrequencyAgility parameter in
assign(ChannelType, ExtendedAssignment)
. The valid range for frequency can be found by
getting the channel's capabilities (getCapabilities()
) and
calling Capabilities.getRfFrequencyMin()
and Capabilities.getRfFrequencyMax()
.
A frequency offset of 57 MHz (2457 MHz) is not allowed and is reserved for use by the ANT+
Plugin API, which must be used to connect to ANT+ devices. An attempt to configure a
frequency outside of these allowed values will fail with a
AntCommandFailureReason.INVALID_REQUEST
.
Should not be used with shared, or Tx-only/Rx-only channel types.
See the ANT Message Protocol and Usage and AN10 ANT Frequency Agility documents for more details.
freq1
- The first operating frequency offset in MHz from 2400MHz (2.4GHz).freq2
- The second operating frequency offset in MHz from 2400MHz (2.4GHz).freq3
- The third operating frequency offset in MHz from 2400MHz (2.4GHz).RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void setProximityThreshold(int searchThreshold) throws RemoteException, AntCommandFailedException
Only ANT devices within the set proximity bin can be acquired. Search threshold values are relative to each other only; they are not correlated to specific distances, are not expected to be exactly equivalent between different chips, and will vary depending on the RF environment.
See the ANT Message Protocol and Usage document for more details.
searchThreshold
- The proximity threshold to use. Valid range is 0-10. 0 = disabled.
Values are relative to each other only and will vary in different RF environments.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void open() throws RemoteException, AntCommandFailedException
assign(ChannelType)
.
See the ANT Message Protocol and Usage document for more details.
RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void close() throws RemoteException, AntCommandFailedException
Note: This method returns when the close command itself is successful, but not the actual
event of the channel completing the close routines. To synchronize on the actual closing
of the channel wait for the response event EventCode.CHANNEL_CLOSED
in a
MessageFromAntType.CHANNEL_EVENT
through
IAntChannelEventHandler.onReceiveMessage(MessageFromAntType, AntMessageParcel)
.
See the ANT Message Protocol and Usage document for more details.
RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public ChannelStatusMessage requestChannelStatus() throws RemoteException, AntCommandFailedException
RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public ChannelIdMessage requestChannelId() throws RemoteException, AntCommandFailedException
RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public AntVersionMessage requestAntVersion() throws RemoteException, AntCommandFailedException
RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public CapabilitiesMessage requestCapabilities() throws RemoteException, AntCommandFailedException
getCapabilities()
instead.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void setBroadcastData(byte[] payload) throws RemoteException
If this channel is a master it will broadcast this data once every message period. If this channel is a slave it will broadcast this data once at the next transmit window.
See the ANT Message Protocol and Usage document for more details.
payload
- The data to send in the broadcast message. Must be exactly
DataMessage.LENGTH_STANDARD_PAYLOAD
bytes long.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.public void startSendAcknowledgedData(byte[] payload) throws RemoteException, AntCommandFailedException
IAntChannelEventHandler.onReceiveMessage(MessageFromAntType, AntMessageParcel)
See the ANT Message Protocol and Usage document for more details.
payload
- The data to send in the acknowledged message. Must be exactly DataMessage.LENGTH_STANDARD_PAYLOAD
bytes long.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void burstTransfer(byte[] data) throws RemoteException, AntCommandFailedException
Burst transfers that exceed the maximum allowed size will fail with
AntCommandFailureReason.INVALID_REQUEST
reason.
Applications can query the maximum burst size via BurstState.getMaxBurstSize()
either from a BurstState instance received when a IAntAdapterEventHandler.onBurstStateChange(BurstState)
adapter event occurs or from getBurstState()
.
See the ANT
Message Protocol and Usage document for details.
data
- The data to send as a burst. Must be at least DataMessage.LENGTH_STANDARD_PAYLOAD
bytes long.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure or the burst failed.public void setTransmitPower(int outputPowerLevelSetting) throws RemoteException, AntCommandFailedException
See the ANT Message Protocol and Usage document for more details.
outputPowerLevelSetting
- The transmission power to use. The exact meaning of the value passed here
changes between hardware. Setting 0 is the lowest, with each higher setting indicating a higher
transmit power.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void setAdapterWideLibConfig(LibConfig libConfig) throws RemoteException, AntCommandFailedException
The Lib Config setting is adapter wide, so any extended data enabled by at least one channel will be enabled for all channels (including channels acquired by other applications). The extended data is only disabled when every channel on the adapter has cleared their requests for that feature. When first acquired, a channel is not requesting any Lib Config features.
See the ANT Message Protocol and Usage document for details.
libConfig
- Indicates extended data requested to be enabled.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void setEventBuffer(EventBufferSettings eventBufferSettings) throws RemoteException, AntCommandFailedException
EventBufferSettings
. The buffer may be flushed earlier than the
set values if another channel sets values lower than the values set by
this channel (see note). By default, channels set the maximum buffer time
to 2 seconds, the optimal value for responsiveness and power savings.
Setting the maximum buffer time to less than the default value will
sacrifice significant power savings provided by event buffering.
Event buffering can be used to lower power consumption caused by processing frequent messages. See the ANT Message Protocol and Usage document for details.
Note: Event buffering is a chip-wide setting. If multiple channels set Event Buffering, the buffering time will be set to the minimum value. If another channel sets the buffering time to 0 (disabling buffering) no buffering will occur on this adapter and so, setting the event buffer does not guarantee buffering will occur given the possibility of this scenario.
eventBufferSettings
- Indicates the specific event buffer values to
be requestedRemoteException
- If you receive this exception then the channel
should be considered dead. In this circumstance you can
attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void setEventBufferToDefault() throws RemoteException, AntCommandFailedException
EventBufferSettings.DEFAULT_BUFFER_TIME_MILLISECONDS
.
This should only be used if the channel supports event buffering.
RemoteException
- If you receive this exception then the channel
should be considered dead. In this circumstance you can
attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void disableEventBuffer() throws RemoteException, AntCommandFailedException
This should only be used if the channel supports event buffering.
RemoteException
- If you receive this exception then the channel
should be considered dead. In this circumstance you can
attempt to acquire a replacement channel.AntCommandFailedException
- If the service reported a failure.public void setChannelEventHandler(IAntChannelEventHandler eventHandler) throws RemoteException
clearChannelEventHandler()
.eventHandler
- The handler to receive the channel events.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.clearChannelEventHandler()
public void clearChannelEventHandler() throws RemoteException
setChannelEventHandler(IAntChannelEventHandler)
and closes its associated resources.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.public void setAdapterEventHandler(IAntAdapterEventHandler eventHandler) throws RemoteException
clearAdapterEventHandler()
.eventHandler
- The handler to receive the adapter events.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.clearAdapterEventHandler()
public void clearAdapterEventHandler() throws RemoteException
setAdapterEventHandler(IAntAdapterEventHandler)
and closes its associated resources.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.public Capabilities getCapabilities() throws RemoteException
Capabilities
of this channel. These are based on the adapter (hardware)
the channel is running on.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.public EventBufferSettings getEventBufferSettings() throws RemoteException
EventBufferSettings
of the ANT adapter this channel is running on.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.public BurstState getBurstState() throws RemoteException
BurstState
of the ANT adapter this channel is running on.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.public LibConfig getLibConfig() throws RemoteException
LibConfig
of the ANT adapter this channel is running on.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.public BackgroundScanState getBackgroundScanState() throws RemoteException
BackgroundScanState
of the ANT adapter this channel is running on.RemoteException
- If you receive this exception then the channel should be considered dead.
In this circumstance you can attempt to acquire a replacement channel.public void release()
AntChannelProvider
acquireChannel(), tearing down this
channel instance. It cannot be used after calling this method. This signals the ANT
Radio service to reclaim the channel resources for other applications to use.public int describeContents()
public void writeToParcel(Parcel dest, int flags)
Copyright © 2015 Dynastream Innovations Inc. All Rights Reserved.