IANT_Channel.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. using System;
  9. using System.Runtime.InteropServices;
  10. namespace ANT_Managed_Library
  11. {
  12. #region Delegates for channel events
  13. /// <summary>
  14. /// Delegate for the DeviceNotification event
  15. /// </summary>
  16. /// <param name="notification">The notification code for the current event</param>
  17. /// <param name="notificationInfo">An object that optionally holds more information about the current event</param>
  18. public delegate void dDeviceNotificationHandler(ANT_Device.DeviceNotificationCode notification, Object notificationInfo);
  19. /// <summary>
  20. /// Delegate for Channel Response Event for forwarding the raw msg struct. If you are coding in C# use the other response event version.
  21. /// </summary>
  22. /// <param name="message">Message bytes received from device</param>
  23. /// <param name="messageSize">Length of data in message structure</param>
  24. public delegate void dRawChannelResponseHandler(ANT_Device.ANTMessage message, ushort messageSize);
  25. /// <summary>
  26. /// Delegate for Channel Response Event
  27. /// </summary>
  28. /// <param name="response">Message details received from device</param>
  29. public delegate void dChannelResponseHandler(ANT_Response response);
  30. #endregion
  31. //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
  32. /// <summary>
  33. /// Interface for an ANT channel. Allows classes to use different channel implementations behind the interface.
  34. /// </summary>
  35. [Obsolete("Note: NOT OBSOLETE! This warning is just to inform you that IANT_Channel interface is under development and is subject to change")]
  36. public interface IANT_Channel: IDisposable
  37. {
  38. /// <summary>
  39. /// Returns the underlying C++ ANT framer reference that this channel uses for messaging. Useful to pass to unmanaged C++ implementations.
  40. /// </summary>
  41. /// <returns>Pointer to the C++ ANT framer for messaging</returns>
  42. IntPtr getUnmgdFramer();
  43. /// <summary>
  44. /// Returns the channel number of this chanel
  45. /// </summary>
  46. /// <returns>The channel number that is sent with messages on the ANT messaging layer</returns>
  47. byte getChannelNum();
  48. #region ChannelEventCallback Variables
  49. /// <summary>
  50. /// This event is fired whenever there are events on the device level that may impact the channel.
  51. /// Events that currently occur (Event, value of notification info Object):
  52. /// Reset, null
  53. /// Shutdown, null
  54. /// </summary>
  55. event dDeviceNotificationHandler DeviceNotification;
  56. /// <summary>
  57. /// The channel callback event for forwarding the raw msg struct. Triggered every time a message is received from the ANT device.
  58. /// Examples include transmit and receive messages. If you are coding in C# use the other response event version.
  59. /// </summary>
  60. event dRawChannelResponseHandler rawChannelResponse;
  61. /// <summary>
  62. /// The channel callback event. Triggered every time a message is received from the ANT device.
  63. /// Examples include transmit and receive messages.
  64. /// </summary>
  65. event dChannelResponseHandler channelResponse;
  66. #endregion
  67. #region ANT Channel Functions
  68. /// <summary>
  69. /// Returns current channel status.
  70. /// Throws exception on timeout.
  71. /// </summary>
  72. /// <param name="responseWaitTime">Time to wait for device success response</param>
  73. ANT_ChannelStatus requestStatus(UInt32 responseWaitTime);
  74. /// <summary>
  75. /// Returns the channel ID
  76. /// Throws exception on timeout
  77. /// </summary>
  78. /// <param name="responseWaitTime">Time to wait for device success response</param>
  79. /// <returns></returns>
  80. ANT_ChannelID requestID(UInt32 responseWaitTime);
  81. /// <overloads>Assign channel</overloads>
  82. /// <summary>
  83. /// Assign an ANT channel along with its main parameters.
  84. /// Throws exception if the network number is invalid.
  85. /// </summary>
  86. /// <param name="channelTypeByte">Channel Type byte</param>
  87. /// <param name="networkNumber">Network to assign to channel, must be less than device's max networks-1</param>
  88. /// <param name="responseWaitTime">Time to wait for device success response</param>
  89. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  90. bool assignChannel(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber, UInt32 responseWaitTime);
  91. /// <overloads>Assign channel (extended)</overloads>
  92. /// <summary>
  93. /// Assign an ANT channel, using extended channel assignment
  94. /// Throws exception if the network number is invalid.
  95. /// </summary>
  96. /// <param name="channelTypeByte">Channel Type byte</param>
  97. /// <param name="networkNumber">Network to assign to channel, must be less than device's max netwoks - 1</param>
  98. /// <param name="extAssignByte">Extended assignment byte</param>
  99. /// <param name="responseWaitTime">Time to wait for device success response</param>
  100. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  101. bool assignChannelExt(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber, ANT_ReferenceLibrary.ChannelTypeExtended extAssignByte, UInt32 responseWaitTime);
  102. /// <overloads>Unassign channel</overloads>
  103. /// <summary>
  104. /// Unassign this channel.
  105. /// </summary>
  106. /// <param name="responseWaitTime">Time to wait for device success response</param>
  107. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  108. bool unassignChannel(UInt32 responseWaitTime);
  109. /// <overloads>Set the Channel ID</overloads>
  110. /// <summary>
  111. /// Set the Channel ID of this channel.
  112. /// Throws exception if device type is > 127.
  113. /// </summary>
  114. /// <param name="deviceNumber">Device number to assign to channel. Set to 0 for receiver wild card matching</param>
  115. /// <param name="pairingEnabled">Device pairing bit.</param>
  116. /// <param name="deviceTypeID">Device type to assign to channel. Must be less than 128. Set to 0 for receiver wild card matching</param>
  117. /// <param name="transmissionTypeID">Transmission type to assign to channel. Set to 0 for receiver wild card matching</param>
  118. /// <param name="responseWaitTime">Time to wait for device success response</param>
  119. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  120. bool setChannelID(UInt16 deviceNumber, bool pairingEnabled, byte deviceTypeID, byte transmissionTypeID, UInt32 responseWaitTime);
  121. /// <overloads>Sets the Channel ID, using serial number as device number</overloads>
  122. /// <summary>
  123. /// Identical to setChannelID, except last two bytes of serial number are used for device number.
  124. /// Not available on all ANT devices.
  125. /// Throws exception if device type is > 127.
  126. /// </summary>
  127. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  128. bool setChannelID_UsingSerial(bool pairingEnabled, byte deviceTypeID, byte transmissionTypeID, UInt32 waitResponseTime);
  129. /// <overloads>Sets channel message period</overloads>
  130. /// <summary>
  131. /// Set this channel's messaging period
  132. /// </summary>
  133. /// <param name="messagePeriod_32768unitspersecond">Desired period in seconds * 32768</param>
  134. /// <param name="responseWaitTime">Time to wait for device success response</param>
  135. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  136. bool setChannelPeriod(UInt16 messagePeriod_32768unitspersecond, UInt32 responseWaitTime);
  137. /// <overloads>Sets the RSSI threshold (ARCT)</overloads>
  138. /// <summary>
  139. /// Set this channel's RSSI threshold (ARCT)
  140. /// </summary>
  141. /// <param name="thresholdRSSI">Desired RSSI threshold value</param>
  142. /// <param name="responseWaitTime">Time to wait for device success response</param>
  143. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  144. bool setSearchThresholdRSSI(byte thresholdRSSI, UInt32 responseWaitTime);
  145. /// <overloads>Sets channel RF Frequency</overloads>
  146. /// <summary>
  147. /// Set this channel's RF frequency, with the given offset from 2400Mhz.
  148. /// Note: Changing this frequency may affect the ability to certify the product in certain areas of the world.
  149. /// </summary>
  150. /// <param name="RFFreqOffset">Offset to add to 2400Mhz</param>
  151. /// <param name="responseWaitTime">Time to wait for device success response</param>
  152. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  153. bool setChannelFreq(byte RFFreqOffset, UInt32 responseWaitTime);
  154. /// <overloads>Sets the channel transmission power</overloads>
  155. /// <summary>
  156. /// Set the transmission power of this channel
  157. /// Throws exception if device is not capable of per-channel transmit power.
  158. /// </summary>
  159. /// <param name="transmitPower">Transmission power to set to</param>
  160. /// <param name="responseWaitTime">Time to wait for device success response</param>
  161. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  162. bool setChannelTransmitPower(ANT_ReferenceLibrary.TransmitPower transmitPower, UInt32 responseWaitTime);
  163. /// <overloads>Sets the channel search timeout</overloads>
  164. /// <summary>
  165. /// Set the search timeout
  166. /// </summary>
  167. /// <param name="searchTimeout">timeout in 2.5 second units (in newer devices 255=infinite)</param>
  168. /// <param name="responseWaitTime">Time to wait for device success response</param>
  169. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  170. bool setChannelSearchTimeout(byte searchTimeout, UInt32 responseWaitTime);
  171. /// <overloads>Opens the channel</overloads>
  172. /// <summary>
  173. /// Opens this channel
  174. /// </summary>
  175. /// <param name="responseWaitTime">Time to wait for device success response</param>
  176. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  177. bool openChannel(UInt32 responseWaitTime);
  178. /// <overloads>Sends broadcast message</overloads>
  179. /// <summary>
  180. /// Sends the given data on the broadcast transmission.
  181. /// Throws exception if data > 8-bytes in length
  182. /// </summary>
  183. /// <param name="data">data to send (length 8 or less)</param>
  184. bool sendBroadcastData(byte[] data);
  185. /// <overloads>Sends acknowledged message</overloads>
  186. /// <summary>
  187. /// Sends the given data as an acknowledged transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
  188. /// Throws exception if data > 8-bytes in length
  189. /// </summary>
  190. /// <param name="data">data to send (length 8 or less)</param>
  191. /// <param name="ackWaitTime">Time in ms to wait for acknowledgement</param>
  192. /// <returns>0=fail, 1=pass, 2=timeout, 3=cancelled</returns>
  193. ANT_ReferenceLibrary.MessagingReturnCode sendAcknowledgedData(byte[] data, UInt32 ackWaitTime);
  194. /// <overloads>Sends burst transfer</overloads>
  195. /// <summary>
  196. /// Sends the given data as a burst transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
  197. /// </summary>
  198. /// <param name="data">data to send, can be any length</param>
  199. /// <param name="completeWaitTime">Time in ms to wait for completion of transfer</param>
  200. /// <returns>0=fail, 1=pass, 2=timeout, 3=cancelled</returns>
  201. ANT_ReferenceLibrary.MessagingReturnCode sendBurstTransfer(byte[] data, UInt32 completeWaitTime);
  202. /// <overloads>Sends extended broadcast message</overloads>
  203. /// <summary>
  204. /// Sends the given data as an extended broadcast transmission.
  205. /// Throws exception if data > 8-bytes in length
  206. /// </summary>
  207. /// <param name="deviceNumber">Device number of channel ID to send to</param>
  208. /// <param name="deviceTypeID">Device type of channel ID to send to</param>
  209. /// <param name="transmissionTypeID">Transmission type of channel ID to send to</param>
  210. /// <param name="data">data to send (length 8 or less)</param>
  211. bool sendExtBroadcastData(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data);
  212. /// <overloads>Sends extended acknowledged message</overloads>
  213. /// <summary>
  214. /// Sends the given data as an extended acknowledged transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
  215. /// Throws exception if data > 8-bytes in length
  216. /// </summary>
  217. /// <param name="deviceNumber">Device number of channel ID to send to</param>
  218. /// <param name="deviceTypeID">Device type of channel ID to send to</param>
  219. /// <param name="transmissionTypeID">Transmission type of channel ID to send to</param>
  220. /// <param name="data">data to send (length 8 or less)</param>
  221. /// <param name="ackWaitTime">Time in ms to wait for acknowledgement</param>
  222. /// <returns>0=fail, 1=pass, 2=timeout, 3=cancelled</returns>
  223. ANT_ReferenceLibrary.MessagingReturnCode sendExtAcknowledgedData(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data, UInt32 ackWaitTime);
  224. /// <overloads>Sends extended burst data</overloads>
  225. /// <summary>
  226. /// Sends the given data as an extended burst transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
  227. /// </summary>
  228. /// <param name="deviceNumber">Device number of channel ID to send to</param>
  229. /// <param name="deviceTypeID">Device type of channel ID to send to</param>
  230. /// <param name="transmissionTypeID">Transmission type of channel ID to send to</param>
  231. /// <param name="data">data to send, can be any length</param>
  232. /// <param name="completeWaitTime">Time in ms to wait for completion of transfer</param>
  233. /// <returns>0=fail, 1=pass, 2=timeout, 3=cancelled</returns>
  234. ANT_ReferenceLibrary.MessagingReturnCode sendExtBurstTransfer(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data, UInt32 completeWaitTime);
  235. /// <overloads>Closes the channel</overloads>
  236. /// <summary>
  237. /// Close this channel
  238. /// </summary>
  239. /// <param name="responseWaitTime">Time to wait for device success response</param>
  240. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  241. bool closeChannel(UInt32 responseWaitTime);
  242. /// <overloads>Sets the channel low priority search timeout</overloads>
  243. /// <summary>
  244. /// Sets the search timeout for the channel's low-priority search, where it will not interrupt other open channels.
  245. /// When this period expires the channel will drop to high-priority search.
  246. /// This feature is not available in all ANT devices.
  247. /// </summary>
  248. /// <param name="lowPriorityTimeout">Timeout period in 2.5 second units</param>
  249. /// <param name="responseWaitTime">Time to wait for device success response</param>
  250. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  251. bool setLowPrioritySearchTimeout(byte lowPriorityTimeout, UInt32 responseWaitTime);
  252. /// <overloads>Adds a channel ID to the device inclusion/exclusion list</overloads>
  253. /// <summary>
  254. /// Add the given channel ID to the channel's inclusion/exclusion list.
  255. /// The channelID is then included or excluded from the wild card search depending on how the list is configured.
  256. /// Throws exception if listIndex > 3.
  257. /// </summary>
  258. /// <param name="deviceNumber">deviceNumber of the channelID to add</param>
  259. /// <param name="deviceTypeID">deviceType of the channelID to add</param>
  260. /// <param name="transmissionTypeID">transmissionType of the channelID to add</param>
  261. /// <param name="listIndex">position in inclusion/exclusion list to add channelID at (Max size of list is 4)</param>
  262. /// <param name="responseWaitTime">Time to wait for device success response</param>
  263. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  264. bool includeExcludeList_addChannel(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte listIndex, UInt32 responseWaitTime);
  265. /// <overloads>Configures the device inclusion/exclusion list</overloads>
  266. /// <summary>
  267. /// Configures the inclusion/exclusion list. If isExclusionList is true the channel IDs will be
  268. /// excluded from any wild card search on this channel. Otherwise the IDs are the only IDs accepted in the search.
  269. /// Throws exception if list size is greater than 4.
  270. /// </summary>
  271. /// <param name="listSize">The desired size of the list, max size is 4, 0=none</param>
  272. /// <param name="isExclusionList">True = exclusion list, False = inclusion list</param>
  273. /// <param name="responseWaitTime">Time to wait for device success response</param>
  274. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  275. bool includeExcludeList_Configure(byte listSize, bool isExclusionList, UInt32 responseWaitTime);
  276. /// <overloads>Configures proximity search</overloads>
  277. /// <summary>
  278. /// Enables a one time proximity requirement for searching. Only ANT devices within the set proximity bin can be acquired.
  279. /// Search threshold values are not correlated to specific distances as this will be dependent on the system design.
  280. /// This feature is not available on all ANT devices.
  281. /// Throws exception if given bin value is > 10.
  282. /// </summary>
  283. /// <param name="thresholdBin">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. </param>
  284. /// <param name="responseWaitTime">Time to wait for device success response</param>
  285. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  286. bool setProximitySearch(byte thresholdBin, UInt32 responseWaitTime);
  287. /// <overloads>Configures the three operating RF frequencies for ANT frequency agility mode</overloads>
  288. /// <summary>
  289. /// This function configures the three operating RF frequencies for ANT frequency agility mode
  290. /// and should be used with the ADV_FrequencyAgility_0x04 extended channel assignment flag.
  291. /// Should not be used with shared, or Tx/Rx only channel types.
  292. /// This feature is not available on all ANT devices.
  293. /// </summary>
  294. /// <param name="freq1">Operating RF frequency 1</param>
  295. /// <param name="freq2">Operating RF frequency 2</param>
  296. /// <param name="freq3">Operating RF frequency 3</param>
  297. /// <param name="responseWaitTime">Time to wait for device success response</param>
  298. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  299. bool configFrequencyAgility(byte freq1, byte freq2, byte freq3, UInt32 responseWaitTime);
  300. #endregion
  301. }
  302. }