/*
This software is subject to the license described in the License.txt file
included with this software distribution. You may not use this file except
in compliance with this license.
Copyright (c) Dynastream Innovations Inc. 2016
All rights reserved.
*/
using System;
using System.Runtime.InteropServices;
namespace ANT_Managed_Library
{
#region Delegates for channel events
///
/// Delegate for the DeviceNotification event
///
/// The notification code for the current event
/// An object that optionally holds more information about the current event
public delegate void dDeviceNotificationHandler(ANT_Device.DeviceNotificationCode notification, Object notificationInfo);
///
/// Delegate for Channel Response Event for forwarding the raw msg struct. If you are coding in C# use the other response event version.
///
/// Message bytes received from device
/// Length of data in message structure
public delegate void dRawChannelResponseHandler(ANT_Device.ANTMessage message, ushort messageSize);
///
/// Delegate for Channel Response Event
///
/// Message details received from device
public delegate void dChannelResponseHandler(ANT_Response response);
#endregion
//TODO we need to refactor this interface to change the return type for those functions that are un-'safe' to a return value instead of a bool so it is usable for the device sharing service implementation
///
/// Interface for an ANT channel. Allows classes to use different channel implementations behind the interface.
///
[Obsolete("Note: NOT OBSOLETE! This warning is just to inform you that IANT_Channel interface is under development and is subject to change")]
public interface IANT_Channel: IDisposable
{
///
/// Returns the underlying C++ ANT framer reference that this channel uses for messaging. Useful to pass to unmanaged C++ implementations.
///
/// Pointer to the C++ ANT framer for messaging
IntPtr getUnmgdFramer();
///
/// Returns the channel number of this chanel
///
/// The channel number that is sent with messages on the ANT messaging layer
byte getChannelNum();
#region ChannelEventCallback Variables
///
/// This event is fired whenever there are events on the device level that may impact the channel.
/// Events that currently occur (Event, value of notification info Object):
/// Reset, null
/// Shutdown, null
///
event dDeviceNotificationHandler DeviceNotification;
///
/// The channel callback event for forwarding the raw msg struct. Triggered every time a message is received from the ANT device.
/// Examples include transmit and receive messages. If you are coding in C# use the other response event version.
///
event dRawChannelResponseHandler rawChannelResponse;
///
/// The channel callback event. Triggered every time a message is received from the ANT device.
/// Examples include transmit and receive messages.
///
event dChannelResponseHandler channelResponse;
#endregion
#region ANT Channel Functions
///
/// Returns current channel status.
/// Throws exception on timeout.
///
/// Time to wait for device success response
ANT_ChannelStatus requestStatus(UInt32 responseWaitTime);
///
/// Returns the channel ID
/// Throws exception on timeout
///
/// Time to wait for device success response
///
ANT_ChannelID requestID(UInt32 responseWaitTime);
/// Assign channel
///
/// Assign an ANT channel along with its main parameters.
/// Throws exception if the network number is invalid.
///
/// Channel Type byte
/// Network to assign to channel, must be less than device's max networks-1
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool assignChannel(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber, UInt32 responseWaitTime);
/// Assign channel (extended)
///
/// Assign an ANT channel, using extended channel assignment
/// Throws exception if the network number is invalid.
///
/// Channel Type byte
/// Network to assign to channel, must be less than device's max netwoks - 1
/// Extended assignment byte
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool assignChannelExt(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber, ANT_ReferenceLibrary.ChannelTypeExtended extAssignByte, UInt32 responseWaitTime);
/// Unassign channel
///
/// Unassign this channel.
///
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool unassignChannel(UInt32 responseWaitTime);
/// Set the Channel ID
///
/// Set the Channel ID of this channel.
/// Throws exception if device type is > 127.
///
/// Device number to assign to channel. Set to 0 for receiver wild card matching
/// Device pairing bit.
/// Device type to assign to channel. Must be less than 128. Set to 0 for receiver wild card matching
/// Transmission type to assign to channel. Set to 0 for receiver wild card matching
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool setChannelID(UInt16 deviceNumber, bool pairingEnabled, byte deviceTypeID, byte transmissionTypeID, UInt32 responseWaitTime);
/// Sets the Channel ID, using serial number as device number
///
/// Identical to setChannelID, except last two bytes of serial number are used for device number.
/// Not available on all ANT devices.
/// Throws exception if device type is > 127.
///
/// True on success. Note: Always returns true with a response time of 0
bool setChannelID_UsingSerial(bool pairingEnabled, byte deviceTypeID, byte transmissionTypeID, UInt32 waitResponseTime);
/// Sets channel message period
///
/// Set this channel's messaging period
///
/// Desired period in seconds * 32768
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool setChannelPeriod(UInt16 messagePeriod_32768unitspersecond, UInt32 responseWaitTime);
/// Sets the RSSI threshold (ARCT)
///
/// Set this channel's RSSI threshold (ARCT)
///
/// Desired RSSI threshold value
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool setSearchThresholdRSSI(byte thresholdRSSI, UInt32 responseWaitTime);
/// Sets channel RF Frequency
///
/// Set this channel's RF frequency, with the given offset from 2400Mhz.
/// Note: Changing this frequency may affect the ability to certify the product in certain areas of the world.
///
/// Offset to add to 2400Mhz
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool setChannelFreq(byte RFFreqOffset, UInt32 responseWaitTime);
/// Sets the channel transmission power
///
/// Set the transmission power of this channel
/// Throws exception if device is not capable of per-channel transmit power.
///
/// Transmission power to set to
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool setChannelTransmitPower(ANT_ReferenceLibrary.TransmitPower transmitPower, UInt32 responseWaitTime);
/// Sets the channel search timeout
///
/// Set the search timeout
///
/// timeout in 2.5 second units (in newer devices 255=infinite)
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool setChannelSearchTimeout(byte searchTimeout, UInt32 responseWaitTime);
/// Opens the channel
///
/// Opens this channel
///
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool openChannel(UInt32 responseWaitTime);
/// Sends broadcast message
///
/// Sends the given data on the broadcast transmission.
/// Throws exception if data > 8-bytes in length
///
/// data to send (length 8 or less)
bool sendBroadcastData(byte[] data);
/// Sends acknowledged message
///
/// Sends the given data as an acknowledged transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
/// Throws exception if data > 8-bytes in length
///
/// data to send (length 8 or less)
/// Time in ms to wait for acknowledgement
/// 0=fail, 1=pass, 2=timeout, 3=cancelled
ANT_ReferenceLibrary.MessagingReturnCode sendAcknowledgedData(byte[] data, UInt32 ackWaitTime);
/// Sends burst transfer
///
/// Sends the given data as a burst transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
///
/// data to send, can be any length
/// Time in ms to wait for completion of transfer
/// 0=fail, 1=pass, 2=timeout, 3=cancelled
ANT_ReferenceLibrary.MessagingReturnCode sendBurstTransfer(byte[] data, UInt32 completeWaitTime);
/// Sends extended broadcast message
///
/// Sends the given data as an extended broadcast transmission.
/// Throws exception if data > 8-bytes in length
///
/// Device number of channel ID to send to
/// Device type of channel ID to send to
/// Transmission type of channel ID to send to
/// data to send (length 8 or less)
bool sendExtBroadcastData(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data);
/// Sends extended acknowledged message
///
/// Sends the given data as an extended acknowledged transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
/// Throws exception if data > 8-bytes in length
///
/// Device number of channel ID to send to
/// Device type of channel ID to send to
/// Transmission type of channel ID to send to
/// data to send (length 8 or less)
/// Time in ms to wait for acknowledgement
/// 0=fail, 1=pass, 2=timeout, 3=cancelled
ANT_ReferenceLibrary.MessagingReturnCode sendExtAcknowledgedData(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data, UInt32 ackWaitTime);
/// Sends extended burst data
///
/// Sends the given data as an extended burst transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
///
/// Device number of channel ID to send to
/// Device type of channel ID to send to
/// Transmission type of channel ID to send to
/// data to send, can be any length
/// Time in ms to wait for completion of transfer
/// 0=fail, 1=pass, 2=timeout, 3=cancelled
ANT_ReferenceLibrary.MessagingReturnCode sendExtBurstTransfer(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data, UInt32 completeWaitTime);
/// Closes the channel
///
/// Close this channel
///
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool closeChannel(UInt32 responseWaitTime);
/// Sets the channel low priority search timeout
///
/// Sets the search timeout for the channel's low-priority search, where it will not interrupt other open channels.
/// When this period expires the channel will drop to high-priority search.
/// This feature is not available in all ANT devices.
///
/// Timeout period in 2.5 second units
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool setLowPrioritySearchTimeout(byte lowPriorityTimeout, UInt32 responseWaitTime);
/// Adds a channel ID to the device inclusion/exclusion list
///
/// Add the given channel ID to the channel's inclusion/exclusion list.
/// The channelID is then included or excluded from the wild card search depending on how the list is configured.
/// Throws exception if listIndex > 3.
///
/// deviceNumber of the channelID to add
/// deviceType of the channelID to add
/// transmissionType of the channelID to add
/// position in inclusion/exclusion list to add channelID at (Max size of list is 4)
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool includeExcludeList_addChannel(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte listIndex, UInt32 responseWaitTime);
/// Configures the device inclusion/exclusion list
///
/// Configures the inclusion/exclusion list. If isExclusionList is true the channel IDs will be
/// excluded from any wild card search on this channel. Otherwise the IDs are the only IDs accepted in the search.
/// Throws exception if list size is greater than 4.
///
/// The desired size of the list, max size is 4, 0=none
/// True = exclusion list, False = inclusion list
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool includeExcludeList_Configure(byte listSize, bool isExclusionList, UInt32 responseWaitTime);
/// Configures proximity search
///
/// Enables a one time proximity requirement for searching. Only ANT devices within the set proximity bin can be acquired.
/// Search threshold values are not correlated to specific distances as this will be dependent on the system design.
/// This feature is not available on all ANT devices.
/// Throws exception if given bin value is > 10.
///
/// Threshold bin. Value from 0-10 (0= disabled). A search threshold value of 1 (i.e. bin 1) will yield the smallest radius search and is generally recommended as there is less chance of connecting to the wrong device.
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool setProximitySearch(byte thresholdBin, UInt32 responseWaitTime);
/// Configures the three operating RF frequencies for ANT frequency agility mode
///
/// This function configures the three operating RF frequencies for ANT frequency agility mode
/// and should be used with the ADV_FrequencyAgility_0x04 extended channel assignment flag.
/// Should not be used with shared, or Tx/Rx only channel types.
/// This feature is not available on all ANT devices.
///
/// Operating RF frequency 1
/// Operating RF frequency 2
/// Operating RF frequency 3
/// Time to wait for device success response
/// True on success. Note: Always returns true with a response time of 0
bool configFrequencyAgility(byte freq1, byte freq2, byte freq3, UInt32 responseWaitTime);
#endregion
}
}