ANT_Channel.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  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 in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2013
  6. All rights reserved.
  7. */
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Runtime.InteropServices;
  13. namespace ANT_Managed_Library
  14. {
  15. /// <summary>
  16. /// Control class for an individual ANT channel. Created and accessed through the ANTDevice class.
  17. /// </summary>
  18. public class ANT_Channel : IANT_Channel
  19. {
  20. #region variables
  21. readonly ANT_Device creatingDevice = null;
  22. IntPtr unmanagedANTFramerPointer = IntPtr.Zero;
  23. private byte channelNumber;
  24. private bool disposed = false;
  25. #endregion
  26. #region ChannelEventCallback Variables
  27. /// <summary>
  28. /// The channel callback event for forwarding the raw msg struct. Triggered every time a message is received from the ANT device.
  29. /// Examples include transmit and receive messages. If you are coding in C# use the other response event version.
  30. /// </summary>
  31. public event dRawChannelResponseHandler rawChannelResponse;
  32. /// <summary>
  33. /// This event is fired whenever there are events on the device level that may impact the channel.
  34. /// Events that currently occur (Event, value of notification info Object):
  35. /// Reset, null
  36. /// Shutdown, null
  37. /// </summary>
  38. public event dDeviceNotificationHandler DeviceNotification;
  39. /// <summary>
  40. /// The channel callback event. Triggered every time a message is received from the ANT device.
  41. /// Examples include transmit and receive messages.
  42. /// </summary>
  43. public event dChannelResponseHandler channelResponse; //The event to assign callback functions to in a managed application
  44. #endregion
  45. #region ANT_DLL Imports
  46. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
  47. private static extern int ANT_GetChannelID(IntPtr FramerPtr, byte ucANTChannel_, ref UInt16 pusDeviceNumber_, ref byte pucDeviceType_, ref byte pucTransmitType_, UInt32 ulResponseTime_);
  48. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention = CallingConvention.Cdecl)]
  49. private static extern int ANT_GetChannelStatus(IntPtr FramerPtr, byte ucANTChannel_, ref byte pucStatus_, UInt32 ulResponseTime_);
  50. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_AssignChannel_RTO", CallingConvention = CallingConvention.Cdecl)]
  51. private static extern int ANT_AssignChannel(IntPtr FramerPtr, byte ucANTChannel, byte ucChanType, byte ucNetNumber, UInt32 ulResponseTime_);
  52. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_AssignChannelExt_RTO", CallingConvention=CallingConvention.Cdecl)]
  53. private static extern int ANT_AssignChannelExt(IntPtr FramerPtr, byte ucANTChannel, byte ucChanType, byte ucNetNumber, byte ucExtFlags, UInt32 ulResponseTime_);
  54. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_UnAssignChannel_RTO", CallingConvention=CallingConvention.Cdecl)]
  55. private static extern int ANT_UnAssignChannel(IntPtr FramerPtr, byte ucANTChannel, UInt32 ulResponseTime);
  56. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SetChannelId_RTO", CallingConvention=CallingConvention.Cdecl)]
  57. private static extern int ANT_SetChannelId(IntPtr FramerPtr, byte ucANTChannel, UInt16 usDeviceNumber, byte ucDeviceType, byte ucTransmissionType_, UInt32 ulResponseTime_);
  58. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SetSerialNumChannelId_RTO", CallingConvention=CallingConvention.Cdecl)]
  59. private static extern int ANT_SetSerialNumChannelId_RTO(IntPtr FramerPtr, byte ucANTChannel_, byte ucDeviceType_, byte ucTransmissionType_, UInt32 ulResponseTime_);
  60. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SetChannelPeriod_RTO", CallingConvention=CallingConvention.Cdecl)]
  61. private static extern int ANT_SetChannelPeriod(IntPtr FramerPtr, byte ucANTChannel_, UInt16 usMesgPeriod_, UInt32 ulResponseTime_);
  62. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_RSSI_SetSearchThreshold_RTO", CallingConvention=CallingConvention.Cdecl)]
  63. private static extern int ANT_RSSI_SetSearchThreshold(IntPtr FramerPtr, byte ucANTChannel_, byte ucThreshold_, UInt32 ulResponseTime_);
  64. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SetChannelRFFreq_RTO", CallingConvention=CallingConvention.Cdecl)]
  65. private static extern int ANT_SetChannelRFFreq(IntPtr FramerPtr, byte ucANTChannel_, byte ucRFFreq_, UInt32 ulResponseTime_);
  66. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SetChannelTxPower_RTO", CallingConvention=CallingConvention.Cdecl)]
  67. private static extern int ANT_SetChannelTxPower(IntPtr FramerPtr, byte ucANTChannel_, byte ucTransmitPower_, UInt32 ulResponseTime_);
  68. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SetChannelSearchTimeout_RTO", CallingConvention=CallingConvention.Cdecl)]
  69. private static extern int ANT_SetChannelSearchTimeout(IntPtr FramerPtr, byte ucANTChannel_, byte ucSearchTimeout_, UInt32 ulResponseTime_);
  70. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_OpenChannel_RTO", CallingConvention=CallingConvention.Cdecl)]
  71. private static extern int ANT_OpenChannel(IntPtr FramerPtr, byte ucANTChannel, UInt32 ulResponseTime_);
  72. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_CloseChannel_RTO", CallingConvention=CallingConvention.Cdecl)]
  73. private static extern int ANT_CloseChannel(IntPtr FramerPtr, byte ucANTChannel, UInt32 ulResponseTime_);
  74. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
  75. private static extern int ANT_SendBroadcastData(IntPtr FramerPtr, byte ucANTChannel, byte[] pucData);
  76. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SendAcknowledgedData_RTO", CallingConvention=CallingConvention.Cdecl)]
  77. private static extern byte ANT_SendAcknowledgedData(IntPtr FramerPtr, byte ucANTChannel, byte[] pucData, UInt32 ulResponseTime_);
  78. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SendBurstTransfer_RTO", CallingConvention=CallingConvention.Cdecl)]
  79. private static extern byte ANT_SendBurstTransfer(IntPtr FramerPtr, byte ucANTChannel_, byte[] pucData_, UInt32 usNumBytes, UInt32 ulResponseTime_);
  80. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SendAdvancedBurstTransfer_RTO", CallingConvention = CallingConvention.Cdecl)]
  81. private static extern byte ANT_SendAdvancedBurstTransfer(IntPtr FramerPtr, byte ucANTChannel_, byte[] pucData_, UInt32 usNumBytes, byte numStdPcktsPerSerialMsg_, UInt32 ulResponseTime_);
  82. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
  83. private static extern int ANT_SendExtBroadcastData(IntPtr FramerPtr, byte ucANTChannel, UInt16 usDeviceNumber, byte ucDeviceType, byte ucTransmissionType_, byte[] pucData);
  84. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SendExtAcknowledgedData_RTO", CallingConvention=CallingConvention.Cdecl)]
  85. private static extern byte ANT_SendExtAcknowledgedData(IntPtr FramerPtr, byte ucANTChannel, UInt16 usDeviceNumber, byte ucDeviceType, byte ucTransmissionType_, byte[] pucData, UInt32 ulResponseTime_);
  86. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SendExtBurstTransfer_RTO", CallingConvention=CallingConvention.Cdecl)]
  87. private static extern byte ANT_SendExtBurstTransfer(IntPtr FramerPtr, byte ucANTChannel_, UInt16 usDeviceNumber, byte ucDeviceType, byte ucTransmissionType_, byte[] pucData_, UInt32 usNumBytes, UInt32 ulResponseTime_);
  88. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_SetLowPriorityChannelSearchTimeout_RTO", CallingConvention=CallingConvention.Cdecl)]
  89. private static extern int ANT_SetLowPriorityChannelSearchTimeout(IntPtr FramerPtr, byte ucANTChannel_, byte ucSearchTimeout_, UInt32 ulResponseTime_);
  90. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_AddChannelID_RTO", CallingConvention=CallingConvention.Cdecl)]
  91. private static extern int ANT_AddChannelID(IntPtr FramerPtr, byte ucANTChannel_, UInt16 usDeviceNumber_, byte ucDeviceType_, byte ucTransmissionType_, byte ucListIndex_, UInt32 ulResponseTime_);
  92. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_ConfigList_RTO", CallingConvention=CallingConvention.Cdecl)]
  93. private static extern int ANT_ConfigList(IntPtr FramerPtr, byte ucANTChannel_, byte ucListSize_, byte ucExclude_, UInt32 ulResponseTime_);
  94. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_EncryptedChannelEnable_RTO", CallingConvention = CallingConvention.Cdecl)]
  95. private static extern int ANT_EncryptedChannelEnable(IntPtr FramerPtr, byte ucANTChannel, byte ucMode, byte ucVolatileKeyIndex, byte ucDecimationRate, UInt32 ulResponseTime_);
  96. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_AddCryptoID_RTO", CallingConvention = CallingConvention.Cdecl)]
  97. private static extern int ANT_AddCryptoID(IntPtr FramerPtr, byte ucANTChannel, byte[] pucData, byte ucListIndex, UInt32 ulResponseTime_);
  98. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, EntryPoint = "ANT_ConfigCryptoList_RTO", CallingConvention = CallingConvention.Cdecl)]
  99. private static extern int ANT_ConfigCryptoList(IntPtr FramerPtr, byte ucANTChannel, byte ucListSize, byte ucBlacklist, UInt32 ulResponseTime_);
  100. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
  101. private static extern int ANT_SetProximitySearch(IntPtr FramerPtr, byte ucANTChannel_, byte ucSearchThreshold_, UInt32 ulResponseTime_);
  102. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention=CallingConvention.Cdecl)]
  103. private static extern int ANT_ConfigFrequencyAgility(IntPtr FramerPtr, byte ucANTChannel_, byte ucFreq1_, byte ucFreq2_, byte ucFreq3_, UInt32 ulResponseTime_);
  104. [DllImport(ANT_Common.ANT_UNMANAGED_WRAPPER, CallingConvention = CallingConvention.Cdecl)]
  105. private static extern int ANT_ConfigSelectiveDataUpdate(IntPtr FramerPtr, byte ucANTChannel_, byte ucSduConfig_, UInt32 ulResponseTime_);
  106. #endregion
  107. #region Constructor
  108. //Internal, because a channel can not be created without a device instance. Channels must be created by the device class which assigns the appropriate channel number
  109. internal ANT_Channel(ANT_Device creatingDevice, byte ucChannelNumber)
  110. {
  111. this.creatingDevice = creatingDevice;
  112. this.unmanagedANTFramerPointer = creatingDevice.getFramerPtr();
  113. channelNumber = ucChannelNumber;
  114. }
  115. #endregion
  116. #region non-ANTdll Functions
  117. /// <summary>
  118. /// Returns the ANTDevice that this channel belongs to
  119. /// </summary>
  120. public ANT_Device getParentDevice()
  121. {
  122. return creatingDevice;
  123. }
  124. /// <summary>
  125. /// Returns the underlying C++ ANT framer reference that this channel uses for messaging. Useful to pass to unmanaged C++ implementations.
  126. /// </summary>
  127. /// <returns>Pointer to the C++ ANT framer for messaging</returns>
  128. public IntPtr getUnmgdFramer()
  129. {
  130. return creatingDevice.getFramerPtr();
  131. }
  132. /// <summary>
  133. /// Returns the channel number of this instance
  134. /// </summary>
  135. public byte getChannelNum()
  136. {
  137. return channelNumber;
  138. }
  139. internal void NotifyDeviceEvent(ANT_Device.DeviceNotificationCode notification, object notificationInfo)
  140. {
  141. if (DeviceNotification != null)
  142. DeviceNotification(notification, notificationInfo);
  143. }
  144. internal void MessageReceived(ANT_Device.ANTMessage newMessage, ushort messageSize)
  145. {
  146. if (channelResponse != null)
  147. channelResponse(new ANT_Response(this, channelNumber, DateTime.Now, newMessage.msgID, newMessage.ucharBuf.Take(messageSize).ToArray()));
  148. if (rawChannelResponse != null)
  149. rawChannelResponse(newMessage, messageSize);
  150. }
  151. /// <summary>
  152. /// Dispose this channel.
  153. /// </summary>
  154. public void Dispose()
  155. {
  156. //There are no unmanaged resources to clean up in this channel implementation
  157. //It would be nice to close the channel if it is open, but it is really hard to tell if the channel
  158. //is open or not without requesting channelStatus, and we don't want to issue extraneous commands and clutter the logs
  159. //We can however nullify our reference in the device list, so that if someone calls getChannel again they get a new non-disposed channel
  160. creatingDevice.channelDisposed(channelNumber);
  161. disposed = true;
  162. GC.SuppressFinalize(this);
  163. }
  164. /// <summary>
  165. /// Returns current channel status.
  166. /// Throws exception on timeout.
  167. /// </summary>
  168. /// <param name="responseWaitTime">Time to wait for device success response</param>
  169. public ANT_ChannelStatus requestStatus(UInt32 responseWaitTime)
  170. {
  171. if (disposed)
  172. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  173. byte statusByte = 0;
  174. if (ANT_GetChannelStatus(unmanagedANTFramerPointer, channelNumber, ref statusByte, responseWaitTime) == 1)
  175. {
  176. return new ANT_ChannelStatus((ANT_ReferenceLibrary.BasicChannelStatusCode)(statusByte & 0x03), (byte)((statusByte & 0x0C) >> 2), (ANT_ReferenceLibrary.ChannelType)(statusByte & 0xF0));
  177. }
  178. else
  179. {
  180. throw new ANT_Exception("Timed out waiting for requested message");
  181. }
  182. }
  183. /// <summary>
  184. /// Returns the channel ID
  185. /// Throws exception on timeout
  186. /// </summary>
  187. /// <param name="responseWaitTime">Time to wait for device success response</param>
  188. /// <returns></returns>
  189. public ANT_ChannelID requestID(UInt32 responseWaitTime)
  190. {
  191. if (disposed)
  192. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  193. ushort deviceNumber = 0;
  194. byte deviceType = 0;
  195. byte transmitType = 0;
  196. if (ANT_GetChannelID(unmanagedANTFramerPointer, channelNumber, ref deviceNumber, ref deviceType, ref transmitType, responseWaitTime) == 1)
  197. {
  198. return new ANT_ChannelID(deviceNumber, deviceType, transmitType);
  199. }
  200. else
  201. {
  202. throw new ANT_Exception("Timed out waiting for requested message");
  203. }
  204. }
  205. #endregion
  206. #region ANT Channel Functions
  207. /// <overloads>Assign channel</overloads>
  208. /// <summary>
  209. /// Assign an ANT channel along with its main parameters.
  210. /// Throws exception if the network number is invalid.
  211. /// </summary>
  212. /// <param name="channelTypeByte">Channel Type byte</param>
  213. /// <param name="networkNumber">Network to assign to channel, must be less than device's max networks-1</param>
  214. /// <param name="responseWaitTime">Time to wait for device success response</param>
  215. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  216. public bool assignChannel(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber, UInt32 responseWaitTime)
  217. {
  218. if (disposed)
  219. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  220. if (networkNumber > creatingDevice.getDeviceCapabilities().maxNetworks - 1)
  221. throw new ANT_Exception("Network number must be less than device's max networks - 1");
  222. return (ANT_AssignChannel(unmanagedANTFramerPointer, channelNumber, (byte)channelTypeByte, networkNumber, responseWaitTime) == 1);
  223. }
  224. /// <summary>
  225. /// Assign an ANT channel.
  226. /// </summary>
  227. /// <param name="channelTypeByte">Channel Type byte</param>
  228. /// <param name="networkNumber">Network to assign to channel</param>
  229. public void assignChannel(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber) { assignChannel(channelTypeByte, networkNumber, 0); }
  230. /// <overloads>Assign channel (extended)</overloads>
  231. /// <summary>
  232. /// Assign an ANT channel, using extended channel assignment
  233. /// Throws exception if the network number is invalid.
  234. /// </summary>
  235. /// <param name="channelTypeByte">Channel Type byte</param>
  236. /// <param name="networkNumber">Network to assign to channel, must be less than device's max netwoks - 1</param>
  237. /// <param name="extAssignByte">Extended assignment byte</param>
  238. /// <param name="responseWaitTime">Time to wait for device success response</param>
  239. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  240. public bool assignChannelExt(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber, ANT_ReferenceLibrary.ChannelTypeExtended extAssignByte, UInt32 responseWaitTime)
  241. {
  242. if (disposed)
  243. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  244. if (networkNumber > creatingDevice.getDeviceCapabilities().maxNetworks - 1)
  245. throw new ANT_Exception("Network number must be less than device's max networks - 1");
  246. return (ANT_AssignChannelExt(unmanagedANTFramerPointer, channelNumber, (byte)channelTypeByte, networkNumber, (byte)extAssignByte, responseWaitTime) == 1);
  247. }
  248. /// <summary>
  249. /// Assign an ANT channel, using extended channel assignment
  250. /// Throws exception if the network number is invalid.
  251. /// </summary>
  252. /// <param name="channelTypeByte">Channel Type byte</param>
  253. /// <param name="networkNumber">Network to assign to channel, must be less than device's max netwoks - 1</param>
  254. /// <param name="extAssignByte">Extended assignment byte</param>
  255. public void assignChannelExt(ANT_ReferenceLibrary.ChannelType channelTypeByte, byte networkNumber, ANT_ReferenceLibrary.ChannelTypeExtended extAssignByte) { assignChannelExt(channelTypeByte, networkNumber, extAssignByte, 0); }
  256. /// <overloads>Unassign channel</overloads>
  257. /// <summary>
  258. /// Unassign this channel.
  259. /// </summary>
  260. /// <param name="responseWaitTime">Time to wait for device success response</param>
  261. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  262. public bool unassignChannel(UInt32 responseWaitTime)
  263. {
  264. if (disposed)
  265. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  266. return (ANT_UnAssignChannel(unmanagedANTFramerPointer, channelNumber, responseWaitTime) == 1);
  267. }
  268. /// <summary>
  269. /// Unassigns this channel.
  270. /// </summary>
  271. public void unassignChannel() { unassignChannel(0); }
  272. /// <overloads>Set the Channel ID</overloads>
  273. /// <summary>
  274. /// Set the Channel ID of this channel.
  275. /// Throws exception if device type is > 127.
  276. /// </summary>
  277. /// <param name="deviceNumber">Device number to assign to channel. Set to 0 for receiver wild card matching</param>
  278. /// <param name="pairingEnabled">Device pairing bit.</param>
  279. /// <param name="deviceTypeID">Device type to assign to channel. Must be less than 128. Set to 0 for receiver wild card matching</param>
  280. /// <param name="transmissionTypeID">Transmission type to assign to channel. Set to 0 for receiver wild card matching</param>
  281. /// <param name="responseWaitTime">Time to wait for device success response</param>
  282. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  283. public bool setChannelID(UInt16 deviceNumber, bool pairingEnabled, byte deviceTypeID, byte transmissionTypeID, UInt32 responseWaitTime)
  284. {
  285. if (disposed)
  286. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  287. if (deviceTypeID > 127)
  288. throw new ANT_Exception("Device Type ID is larger than 127");
  289. if (pairingEnabled) //Set the pairing flag
  290. deviceTypeID |= 0x80;
  291. return (ANT_SetChannelId(unmanagedANTFramerPointer, channelNumber, deviceNumber, deviceTypeID, transmissionTypeID, responseWaitTime) == 1);
  292. }
  293. /// <summary>
  294. /// Set the Channel ID of this channel.
  295. /// Throws exception if device type is > 127.
  296. /// </summary>
  297. /// <param name="deviceNumber">Device number to assign to channel. Set to 0 for receiver wild card matching</param>
  298. /// <param name="pairingEnabled">Device pairing bit</param>
  299. /// <param name="deviceTypeID">Device type to assign to channel. Set to 0 for receiver wild card matching</param>
  300. /// <param name="transmissionTypeID">Transmission type to assign to channel. Set to 0 for receiver wild card matching</param>
  301. public void setChannelID(UInt16 deviceNumber, bool pairingEnabled, byte deviceTypeID, byte transmissionTypeID) { setChannelID(deviceNumber, pairingEnabled, deviceTypeID, transmissionTypeID, 0); }
  302. /// <overloads>Sets the Channel ID, using serial number as device number</overloads>
  303. /// <summary>
  304. /// Identical to setChannelID, except last two bytes of serial number are used for device number.
  305. /// Not available on all ANT devices.
  306. /// Throws exception if device type is > 127.
  307. /// </summary>
  308. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  309. public bool setChannelID_UsingSerial(bool pairingEnabled, byte deviceTypeID, byte transmissionTypeID, UInt32 waitResponseTime)
  310. {
  311. if (disposed)
  312. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  313. if (deviceTypeID > 127)
  314. throw new ANT_Exception("Device Type ID is larger than 127");
  315. if (pairingEnabled) //Set the pairing flag
  316. deviceTypeID |= 0x80;
  317. return (ANT_SetSerialNumChannelId_RTO(unmanagedANTFramerPointer, channelNumber, deviceTypeID, transmissionTypeID, waitResponseTime) == 1);
  318. }
  319. /// <summary>
  320. /// Identical to setChannelID, except last two bytes of serial number are used for device number.
  321. /// </summary>
  322. public void setChannelID_UsingSerial(bool pairingEnabled, byte deviceTypeID, byte transmissionTypeID) { setChannelID_UsingSerial(pairingEnabled, deviceTypeID, transmissionTypeID, 0); }
  323. /// <overloads>Sets channel message period</overloads>
  324. /// <summary>
  325. /// Set this channel's messaging period
  326. /// </summary>
  327. /// <param name="messagePeriod_32768unitspersecond">Desired period in seconds * 32768</param>
  328. /// <param name="responseWaitTime">Time to wait for device success response</param>
  329. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  330. public bool setChannelPeriod(UInt16 messagePeriod_32768unitspersecond, UInt32 responseWaitTime)
  331. {
  332. if (disposed)
  333. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  334. return (ANT_SetChannelPeriod(unmanagedANTFramerPointer, channelNumber, messagePeriod_32768unitspersecond, responseWaitTime) == 1);
  335. }
  336. /// <summary>
  337. /// Set this channel's messaging period
  338. /// </summary>
  339. /// <param name="messagePeriod_32768unitspersecond">Desired period in seconds * 32768</param>
  340. public void setChannelPeriod(UInt16 messagePeriod_32768unitspersecond) { setChannelPeriod(messagePeriod_32768unitspersecond, 0); }
  341. /// <overloads>Sets the RSSI threshold (ARCT)</overloads>
  342. /// <summary>
  343. /// Set this channel's RSSI threshold (ARCT)
  344. /// </summary>
  345. /// <param name="thresholdRSSI">Desired RSSI threshold value</param>
  346. /// <param name="responseWaitTime">Time to wait for device success response</param>
  347. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  348. public bool setSearchThresholdRSSI(byte thresholdRSSI, UInt32 responseWaitTime)
  349. {
  350. if (disposed)
  351. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  352. return (ANT_RSSI_SetSearchThreshold(unmanagedANTFramerPointer, channelNumber, thresholdRSSI, responseWaitTime) == 1);
  353. }
  354. /// <summary>
  355. /// Set this channel's RSSI threshold (ARCT)
  356. /// </summary>
  357. /// <param name="thresholdRSSI">Desired RSSI threshold value</param>
  358. public void setSearchThresholdRSSI(byte thresholdRSSI) { setSearchThresholdRSSI(thresholdRSSI, 0); }
  359. /// <overloads>Sets channel RF Frequency</overloads>
  360. /// <summary>
  361. /// Set this channel's RF frequency, with the given offset from 2400Mhz.
  362. /// Note: Changing this frequency may affect the ability to certify the product in certain areas of the world.
  363. /// </summary>
  364. /// <param name="RFFreqOffset">Offset to add to 2400Mhz</param>
  365. /// <param name="responseWaitTime">Time to wait for device success response</param>
  366. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  367. public bool setChannelFreq(byte RFFreqOffset, UInt32 responseWaitTime)
  368. {
  369. if (disposed)
  370. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  371. return (ANT_SetChannelRFFreq(unmanagedANTFramerPointer, channelNumber, RFFreqOffset, responseWaitTime) == 1);
  372. }
  373. /// <summary>
  374. /// Set this channel's RF frequency, with the given offset from 2400Mhz.
  375. /// Note: Changing this frequency may affect the ability to certify the product in certain areas of the world.
  376. /// </summary>
  377. /// <param name="RFFreqOffset">Offset to add to 2400Mhz</param>
  378. public void setChannelFreq(byte RFFreqOffset) { setChannelFreq(RFFreqOffset, 0); }
  379. /// <overloads>Sets the channel transmission power</overloads>
  380. /// <summary>
  381. /// Set the transmission power of this channel
  382. /// Throws exception if device is not capable of per-channel transmit power.
  383. /// </summary>
  384. /// <param name="transmitPower">Transmission power to set to</param>
  385. /// <param name="responseWaitTime">Time to wait for device success response</param>
  386. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  387. public bool setChannelTransmitPower(ANT_ReferenceLibrary.TransmitPower transmitPower, UInt32 responseWaitTime)
  388. {
  389. if (disposed)
  390. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  391. if (!creatingDevice.getDeviceCapabilities().perChannelTransmitPower)
  392. throw new ANT_Exception("Device not capable of per-channel transmit power");
  393. return (ANT_SetChannelTxPower(unmanagedANTFramerPointer, channelNumber, (byte)transmitPower, responseWaitTime) == 1);
  394. }
  395. /// <summary>
  396. /// Set the transmission power of this channel
  397. /// </summary>
  398. /// <param name="transmitPower">Transmission power to set to</param>
  399. public void setChannelTransmitPower(ANT_ReferenceLibrary.TransmitPower transmitPower) { setChannelTransmitPower(transmitPower, 0); }
  400. /// <overloads>Sets the channel search timeout</overloads>
  401. /// <summary>
  402. /// Set the search timeout
  403. /// </summary>
  404. /// <param name="searchTimeout">timeout in 2.5 second units (in newer devices 255=infinite)</param>
  405. /// <param name="responseWaitTime">Time to wait for device success response</param>
  406. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  407. public bool setChannelSearchTimeout(byte searchTimeout, UInt32 responseWaitTime)
  408. {
  409. if (disposed)
  410. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  411. return (ANT_SetChannelSearchTimeout(unmanagedANTFramerPointer, channelNumber, searchTimeout, responseWaitTime) == 1);
  412. }
  413. /// <summary>
  414. /// Set the search timeout
  415. /// </summary>
  416. /// <param name="searchTimeout">timeout in 2.5 second units (in newer devices 255=infinite)</param>
  417. public void setChannelSearchTimeout(byte searchTimeout) { setChannelSearchTimeout(searchTimeout, 0); }
  418. /// <overloads>Opens the channel</overloads>
  419. /// <summary>
  420. /// Opens this channel
  421. /// </summary>
  422. /// <param name="responseWaitTime">Time to wait for device success response</param>
  423. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  424. public bool openChannel(UInt32 responseWaitTime)
  425. {
  426. if (disposed)
  427. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  428. return (ANT_OpenChannel(unmanagedANTFramerPointer, channelNumber, responseWaitTime) == 1);
  429. }
  430. /// <summary>
  431. /// Opens this channel
  432. /// </summary>
  433. public void openChannel() { openChannel(0); }
  434. /// <overloads>Sends broadcast message</overloads>
  435. /// <summary>
  436. /// Sends the given data on the broadcast transmission.
  437. /// Throws exception if data > 8-bytes in length
  438. /// </summary>
  439. /// <param name="data">data to send (length 8 or less)</param>
  440. public bool sendBroadcastData(byte[] data)
  441. {
  442. if (disposed)
  443. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  444. int padNum = 8 - data.Length;
  445. if (padNum < 0)
  446. throw new ANT_Exception("Send data must not be greater than 8 bytes");
  447. data = data.Concat(new byte[padNum]).ToArray();
  448. return ANT_SendBroadcastData(unmanagedANTFramerPointer, channelNumber, data) == 1;
  449. }
  450. /// <overloads>Sends acknowledged message</overloads>
  451. /// <summary>
  452. /// Sends the given data as an acknowledged transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
  453. /// Throws exception if data > 8-bytes in length
  454. /// </summary>
  455. /// <param name="data">data to send (length 8 or less)</param>
  456. /// <param name="ackWaitTime">Time in ms to wait for acknowledgement</param>
  457. /// <returns>0=fail, 1=pass, 2=timeout, 3=cancelled</returns>
  458. public ANT_ReferenceLibrary.MessagingReturnCode sendAcknowledgedData(byte[] data, UInt32 ackWaitTime)
  459. {
  460. if (disposed)
  461. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  462. int padNum = 8 - data.Length;
  463. if (padNum < 0)
  464. throw new ANT_Exception("Send data must not be greater than 8 bytes");
  465. data = data.Concat(new byte[padNum]).ToArray();
  466. return (ANT_ReferenceLibrary.MessagingReturnCode)ANT_SendAcknowledgedData(unmanagedANTFramerPointer, channelNumber, data, ackWaitTime);
  467. }
  468. /// <summary>
  469. /// Sends the given data as an acknowledged transmission.
  470. /// Throws exception if data > 8-bytes in length
  471. /// </summary>
  472. /// <param name="data">data to send (length 8 or less)</param>
  473. public void sendAcknowledgedData(byte[] data) { sendAcknowledgedData(data, 0); }
  474. /// <overloads>Sends burst transfer</overloads>
  475. /// <summary>
  476. /// Sends the given data as a burst transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
  477. /// </summary>
  478. /// <param name="data">data to send, can be any length</param>
  479. /// <param name="completeWaitTime">Time in ms to wait for completion of transfer</param>
  480. /// <returns>0=fail, 1=pass, 2=timeout, 3=cancelled</returns>
  481. public ANT_ReferenceLibrary.MessagingReturnCode sendBurstTransfer(byte[] data, UInt32 completeWaitTime)
  482. {
  483. if (disposed)
  484. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  485. int padNum = 8 - (data.Length % 8);
  486. if(padNum != 8)
  487. data = data.Concat(new byte[padNum]).ToArray();
  488. return (ANT_ReferenceLibrary.MessagingReturnCode)ANT_SendBurstTransfer(unmanagedANTFramerPointer, channelNumber, data, (uint)data.Length, completeWaitTime);
  489. }
  490. /// <summary>
  491. /// Sends the given data as a burst transmission.
  492. /// </summary>
  493. /// <param name="data">data to send, can be any length</param>
  494. public void sendBurstTransfer(byte[] data) { sendBurstTransfer(data, 0); }
  495. /// <overloads>Sends extended broadcast message</overloads>
  496. /// <summary>
  497. /// Sends the given data as an extended broadcast transmission.
  498. /// Throws exception if data > 8-bytes in length
  499. /// </summary>
  500. /// <param name="deviceNumber">Device number of channel ID to send to</param>
  501. /// <param name="deviceTypeID">Device type of channel ID to send to</param>
  502. /// <param name="transmissionTypeID">Transmission type of channel ID to send to</param>
  503. /// <param name="data">data to send (length 8 or less)</param>
  504. public bool sendExtBroadcastData(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data)
  505. {
  506. if (disposed)
  507. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  508. int padNum = 8 - data.Length;
  509. if (padNum < 0)
  510. throw new ANT_Exception("Send data must not be greater than 8 bytes");
  511. data = data.Concat(new byte[padNum]).ToArray();
  512. return ANT_SendExtBroadcastData(unmanagedANTFramerPointer, channelNumber, deviceNumber, deviceTypeID, transmissionTypeID, data) == 1;
  513. }
  514. /// <overloads>Sends extended acknowledged message</overloads>
  515. /// <summary>
  516. /// Sends the given data as an extended acknowledged transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
  517. /// Throws exception if data > 8-bytes in length
  518. /// </summary>
  519. /// <param name="deviceNumber">Device number of channel ID to send to</param>
  520. /// <param name="deviceTypeID">Device type of channel ID to send to</param>
  521. /// <param name="transmissionTypeID">Transmission type of channel ID to send to</param>
  522. /// <param name="data">data to send (length 8 or less)</param>
  523. /// <param name="ackWaitTime">Time in ms to wait for acknowledgement</param>
  524. /// <returns>0=fail, 1=pass, 2=timeout, 3=cancelled</returns>
  525. public ANT_ReferenceLibrary.MessagingReturnCode sendExtAcknowledgedData(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data, UInt32 ackWaitTime)
  526. {
  527. if (disposed)
  528. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  529. int padNum = 8 - data.Length;
  530. if (padNum < 0)
  531. throw new ANT_Exception("Send data must not be greater than 8 bytes");
  532. data = data.Concat(new byte[padNum]).ToArray();
  533. return (ANT_ReferenceLibrary.MessagingReturnCode)ANT_SendExtAcknowledgedData(unmanagedANTFramerPointer, channelNumber, deviceNumber, deviceTypeID, transmissionTypeID, data, ackWaitTime);
  534. }
  535. /// <summary>
  536. /// Sends the given data as an extended acknowledged transmission.
  537. /// Throws exception if data > 8-bytes in length
  538. /// </summary>
  539. /// <param name="deviceNumber">Device number of channel ID to send to</param>
  540. /// <param name="deviceTypeID">Device type of channel ID to send to</param>
  541. /// <param name="transmissionTypeID">Transmission type of channel ID to send to</param>
  542. /// <param name="data">data to send (length 8 or less)</param>
  543. public void sendExtAcknowledgedData(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data) { sendExtAcknowledgedData(deviceNumber, deviceTypeID, transmissionTypeID, data, 0); }
  544. /// <overloads>Sends extended burst data</overloads>
  545. /// <summary>
  546. /// Sends the given data as an extended burst transmission. Returns: 0=fail, 1=pass, 2=timeout, 3=cancelled
  547. /// </summary>
  548. /// <param name="deviceNumber">Device number of channel ID to send to</param>
  549. /// <param name="deviceTypeID">Device type of channel ID to send to</param>
  550. /// <param name="transmissionTypeID">Transmission type of channel ID to send to</param>
  551. /// <param name="data">data to send, can be any length</param>
  552. /// <param name="completeWaitTime">Time in ms to wait for completion of transfer</param>
  553. /// <returns>0=fail, 1=pass, 2=timeout, 3=cancelled</returns>
  554. public ANT_ReferenceLibrary.MessagingReturnCode sendExtBurstTransfer(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data, UInt32 completeWaitTime)
  555. {
  556. if (disposed)
  557. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  558. //The new unmanaged wrapper burst function handles the padding, but we just do it here anyway to keep in line with the other send functions
  559. int padNum = 8 - (data.Length % 8);
  560. if(padNum != 8)
  561. data = data.Concat(new byte[padNum]).ToArray();
  562. return (ANT_ReferenceLibrary.MessagingReturnCode)ANT_SendExtBurstTransfer(unmanagedANTFramerPointer, channelNumber, deviceNumber, deviceTypeID, transmissionTypeID, data, (uint)data.Length, completeWaitTime);
  563. }
  564. /// <summary>
  565. /// Sends the given data as an extended burst transmission.
  566. /// </summary>
  567. /// <param name="deviceNumber">Device number of channel ID to send to</param>
  568. /// <param name="deviceTypeID">Device type of channel ID to send to</param>
  569. /// <param name="transmissionTypeID">Transmission type of channel ID to send to</param>
  570. /// <param name="data">data to send, can be any length</param>
  571. public void sendExtBurstTransfer(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte[] data) { sendExtBurstTransfer(deviceNumber, deviceTypeID, transmissionTypeID, data, 0); }
  572. /// <overloads>Closes the channel</overloads>
  573. /// <summary>
  574. /// Close this channel
  575. /// </summary>
  576. /// <param name="responseWaitTime">Time to wait for device success response</param>
  577. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  578. public bool closeChannel(UInt32 responseWaitTime)
  579. {
  580. if (disposed)
  581. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  582. return (ANT_CloseChannel(unmanagedANTFramerPointer, channelNumber, responseWaitTime) == 1);
  583. }
  584. /// <summary>
  585. /// Close this channel
  586. /// </summary>
  587. public void closeChannel() { closeChannel(0); }
  588. /// <overloads>Sets the channel low priority search timeout</overloads>
  589. /// <summary>
  590. /// Sets the search timeout for the channel's low-priority search, where it will not interrupt other open channels.
  591. /// When this period expires the channel will drop to high-priority search.
  592. /// This feature is not available in all ANT devices.
  593. /// </summary>
  594. /// <param name="lowPriorityTimeout">Timeout period in 2.5 second units</param>
  595. /// <param name="responseWaitTime">Time to wait for device success response</param>
  596. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  597. public bool setLowPrioritySearchTimeout(byte lowPriorityTimeout, UInt32 responseWaitTime)
  598. {
  599. if (disposed)
  600. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  601. return ANT_SetLowPriorityChannelSearchTimeout(unmanagedANTFramerPointer, channelNumber, lowPriorityTimeout, responseWaitTime) == 1;
  602. }
  603. /// <summary>
  604. /// Sets the timeout period for the channel's low-priority search, where it will not interrupt other open channels.
  605. /// When this period expires the channel will drop to high-priority search.
  606. /// </summary>
  607. /// <param name="lowPriorityTimeout">Timeout period in 2.5 second units</param>
  608. public void setLowPrioritySearchTimeout(byte lowPriorityTimeout) { setLowPrioritySearchTimeout(lowPriorityTimeout, 0); }
  609. /// <overloads>Adds a channel ID to the device inclusion/exclusion list</overloads>
  610. /// <summary>
  611. /// Add the given channel ID to the channel's inclusion/exclusion list.
  612. /// The channelID is then included or excluded from the wild card search depending on how the list is configured.
  613. /// Throws exception if listIndex > 3.
  614. /// </summary>
  615. /// <param name="deviceNumber">deviceNumber of the channelID to add</param>
  616. /// <param name="deviceTypeID">deviceType of the channelID to add</param>
  617. /// <param name="transmissionTypeID">transmissionType of the channelID to add</param>
  618. /// <param name="listIndex">position in inclusion/exclusion list to add channelID at (Max size of list is 4)</param>
  619. /// <param name="responseWaitTime">Time to wait for device success response</param>
  620. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  621. public bool includeExcludeList_addChannel(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte listIndex, UInt32 responseWaitTime)
  622. {
  623. if (disposed)
  624. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  625. if (listIndex > 3)
  626. throw new ANT_Exception("listIndex must be 0..3");
  627. return ANT_AddChannelID(unmanagedANTFramerPointer, channelNumber, deviceNumber, deviceTypeID, transmissionTypeID, listIndex, responseWaitTime) == 1;
  628. }
  629. /// <summary>
  630. /// Add the given channel ID to the channel's inclusion/exclusion list.
  631. /// The channelID is then included or excluded from the wild card search depending on how the list is configured.
  632. /// Throws exception if listIndex > 3.
  633. /// </summary>
  634. /// <param name="deviceNumber">deviceNumber of the channelID to add</param>
  635. /// <param name="deviceTypeID">deviceType of the channelID to add</param>
  636. /// <param name="transmissionTypeID">transmissionType of the channelID to add</param>
  637. /// <param name="listIndex">position in inclusion/exclusion list to add channelID at (0..3)</param>
  638. public void includeExcludeList_addChannel(UInt16 deviceNumber, byte deviceTypeID, byte transmissionTypeID, byte listIndex)
  639. {
  640. includeExcludeList_addChannel(deviceNumber, deviceTypeID, transmissionTypeID, listIndex, 0);
  641. }
  642. /// <overloads>Configures the device inclusion/exclusion list</overloads>
  643. /// <summary>
  644. /// Configures the inclusion/exclusion list. If isExclusionList is true the channel IDs will be
  645. /// excluded from any wild card search on this channel. Otherwise the IDs are the only IDs accepted in the search.
  646. /// Throws exception if list size is greater than 4.
  647. /// </summary>
  648. /// <param name="listSize">The desired size of the list, max size is 4, 0=none</param>
  649. /// <param name="isExclusionList">True = exclusion list, False = inclusion list</param>
  650. /// <param name="responseWaitTime">Time to wait for device success response</param>
  651. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  652. public bool includeExcludeList_Configure(byte listSize, bool isExclusionList, UInt32 responseWaitTime)
  653. {
  654. if (disposed)
  655. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  656. if (listSize > 4)
  657. throw new ANT_Exception("Inclusion Exclusion List has a maximum size of 4");
  658. return ANT_ConfigList(unmanagedANTFramerPointer, channelNumber, listSize, Convert.ToByte(isExclusionList), responseWaitTime) == 1;
  659. }
  660. /// <summary>
  661. /// Configures the inclusion/exclusion list. If isExclusionList is true the channel IDs will be
  662. /// excluded from any wild card search on this channel. Otherwise the IDs are the only IDs accepted in the search.
  663. /// Throws exception if list size is greater than 4.
  664. /// </summary>
  665. /// <param name="listSize">The desired size of the list, max size is 4, 0=none</param>
  666. /// <param name="isExclusionList">True = exclusion list, False = inclusion list</param>
  667. public void includeExcludeList_Configure(byte listSize, bool isExclusionList) { includeExcludeList_Configure(listSize, isExclusionList, 0); }
  668. public bool encryptedChannelEnable(ANT_ReferenceLibrary.EncryptedChannelMode encryptionMode, byte volatileKeyIndex, byte decimationRate, UInt32 responseWaitTime)
  669. {
  670. if (disposed)
  671. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  672. return ANT_EncryptedChannelEnable(unmanagedANTFramerPointer, channelNumber, (byte)encryptionMode, volatileKeyIndex,
  673. decimationRate, responseWaitTime) == 1;
  674. }
  675. public void encryptedChannelEnable(ANT_ReferenceLibrary.EncryptedChannelMode encryptionMode,
  676. byte volatileKeyIndex, byte decimationRate)
  677. {
  678. encryptedChannelEnable(encryptionMode, volatileKeyIndex, decimationRate, 0);
  679. }
  680. public bool encryptionIDList_AddID(byte[] encryptionID, byte listIndex, UInt32 responseWaitTime)
  681. {
  682. if (disposed)
  683. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  684. if (listIndex > 3)
  685. throw new ANT_Exception("listIndex must be 0..3");
  686. return ANT_AddCryptoID(unmanagedANTFramerPointer, channelNumber, encryptionID, listIndex, responseWaitTime) == 1;
  687. }
  688. public void encryptionIDList_AddID(byte[] encryptionID, byte listIndex)
  689. {
  690. encryptionIDList_AddID(encryptionID, listIndex, 0);
  691. }
  692. public bool encryptionIDList_Configure(byte listSize, bool isBlacklist, UInt32 responseWaitTime)
  693. {
  694. if (disposed)
  695. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  696. if (listSize > 4)
  697. throw new ANT_Exception("Blacklist Whitelist has a maximum size of 4");
  698. return ANT_ConfigCryptoList(unmanagedANTFramerPointer, channelNumber, listSize, Convert.ToByte(isBlacklist), responseWaitTime) == 1;
  699. }
  700. public void encryptionIDList_Configure(byte listSize, bool isBlacklist)
  701. {
  702. encryptionIDList_Configure(listSize, isBlacklist, 0);
  703. }
  704. /// <overloads>Configures proximity search</overloads>
  705. /// <summary>
  706. /// Enables a one time proximity requirement for searching. Only ANT devices within the set proximity bin can be acquired.
  707. /// Search threshold values are not correlated to specific distances as this will be dependent on the system design.
  708. /// This feature is not available on all ANT devices.
  709. /// Throws exception if given bin value is > 10.
  710. /// </summary>
  711. /// <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>
  712. /// <param name="responseWaitTime">Time to wait for device success response</param>
  713. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  714. public bool setProximitySearch(byte thresholdBin, UInt32 responseWaitTime)
  715. {
  716. if (disposed)
  717. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  718. if (thresholdBin > 10)
  719. throw new ANT_Exception("Threshold bin must be 0-10");
  720. return ANT_SetProximitySearch(unmanagedANTFramerPointer, channelNumber, thresholdBin, responseWaitTime) == 1;
  721. }
  722. /// <summary>
  723. /// Enables a one time proximity requirement for searching. Only ANT devices within the set proximity bin can be acquired.
  724. /// Search threshold values are not correlated to specific distances as this will be dependent on the system design.
  725. /// Throws exception if given bin value is > 10.
  726. /// </summary>
  727. /// <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>
  728. public void setProximitySearch(byte thresholdBin) { setProximitySearch(thresholdBin, 0);}
  729. /// <overloads>Configures the three operating RF frequencies for ANT frequency agility mode</overloads>
  730. /// <summary>
  731. /// This function configures the three operating RF frequencies for ANT frequency agility mode
  732. /// and should be used with the ADV_FrequencyAgility_0x04 extended channel assignment flag.
  733. /// Should not be used with shared, or Tx/Rx only channel types.
  734. /// This feature is not available on all ANT devices.
  735. /// </summary>
  736. /// <param name="freq1">Operating RF frequency 1</param>
  737. /// <param name="freq2">Operating RF frequency 2</param>
  738. /// <param name="freq3">Operating RF frequency 3</param>
  739. /// <param name="responseWaitTime">Time to wait for device success response</param>
  740. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  741. public bool configFrequencyAgility(byte freq1, byte freq2, byte freq3, UInt32 responseWaitTime)
  742. {
  743. if (disposed)
  744. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  745. return ANT_ConfigFrequencyAgility(unmanagedANTFramerPointer, channelNumber, freq1, freq2, freq3, responseWaitTime) == 1;
  746. }
  747. /// <summary>
  748. /// This function configures the three operating RF frequencies for ANT frequency agility mode
  749. /// and should be used with ADV_FrequencyAgility_0x04 channel assignment flag.
  750. /// Should not be used with shared, or Tx/Rx only channel types.
  751. /// </summary>
  752. /// <param name="freq1">Operating RF frequency 1</param>
  753. /// <param name="freq2">Operating RF frequency 2</param>
  754. /// <param name="freq3">Operating RF frequency 3</param>
  755. public void configFrequencyAgility(byte freq1, byte freq2, byte freq3) { configFrequencyAgility(freq1, freq2, freq3, 0); }
  756. /// <overloads>Configures Selective Data Updates</overloads>
  757. /// <summary>
  758. /// Allows enabling Selective Data Update
  759. /// </summary>
  760. /// <param name="sduConfig">Specify desired previously defined SDU mask and which messages it should apply to</param>
  761. /// <param name="responseWaitTime">Time to wait for device success response</param>
  762. /// <returns>True on success. Note: Always returns true with a response time of 0</returns>
  763. public bool configSdu(byte sduConfig, UInt32 responseWaitTime)
  764. {
  765. if (disposed)
  766. throw new ObjectDisposedException("This ANTChannel object has been disposed");
  767. return ANT_ConfigSelectiveDataUpdate(unmanagedANTFramerPointer, channelNumber, sduConfig, responseWaitTime) == 1;
  768. }
  769. /// <summary>
  770. /// Allows enabling Selective Data Update
  771. /// </summary>
  772. /// <param name="sduConfig">Specify desired previously defined SDU mask and which messages it should apply to</param>
  773. public void configSdu(byte sduConfig) { configSdu(sduConfig, 0); }
  774. #endregion
  775. }
  776. }