ANT_Channel.cs 61 KB

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