ANT_DeviceCapabilities.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. namespace ANT_Managed_Library
  13. {
  14. /// <summary>
  15. /// Container for all the device capability information, returned from an ANTDevice
  16. /// </summary>
  17. public class ANT_DeviceCapabilities
  18. {
  19. /// <summary>
  20. /// Number of channels available
  21. /// </summary>
  22. public readonly byte maxANTChannels; //byte 0
  23. /// <summary>
  24. /// Number of simultaneous networks allowed
  25. /// </summary>
  26. public readonly byte maxNetworks; //byte 1
  27. //TODO: Document all the capabilities
  28. #pragma warning disable 1591
  29. //Basic Capabilities - byte 2
  30. public readonly bool NoReceiveChannels;
  31. public readonly bool NoTransmitChannels;
  32. public readonly bool NoReceiveMessages;
  33. public readonly bool NoTransmitMessages;
  34. public readonly bool NoAckMessages;
  35. public readonly bool NoBurstMessages;
  36. //Advanced Capabilities - byte 3
  37. public readonly bool PrivateNetworks;
  38. public readonly bool SerialNumber;
  39. public readonly bool perChannelTransmitPower;
  40. public readonly bool lowPrioritySearch;
  41. public readonly bool ScriptSupport;
  42. public readonly bool SearchList;
  43. //Advanced Capabilities 2 - byte 4
  44. public readonly bool OnboardLED;
  45. public readonly bool ExtendedMessaging;
  46. public readonly bool ScanModeSupport;
  47. public readonly bool ExtendedChannelAssignment;
  48. public readonly bool ProximitySearch;
  49. public readonly bool FS;
  50. public readonly bool FIT;
  51. //Advanced Capabilities 3 - byte 6
  52. public readonly bool AdvancedBurst;
  53. public readonly bool EventBuffering;
  54. public readonly bool EventFiltering;
  55. public readonly bool HighDutySearch;
  56. public readonly bool SelectiveDataUpdate;
  57. public readonly bool SingleChannelEncryption;
  58. #pragma warning restore 1591
  59. /// <summary>
  60. /// Number of SensRcore data channels available
  61. /// </summary>
  62. public readonly byte maxDataChannels; //byte 5
  63. internal ANT_DeviceCapabilities(byte[] capabilitiesData)
  64. {
  65. if (capabilitiesData.Length != 16)
  66. throw new ANT_Exception("This function only decodes capabilities data of exactly length 16");
  67. maxANTChannels = capabilitiesData[0];
  68. maxNetworks = capabilitiesData[1];
  69. //Now decode all the bit fields
  70. //Basic Capabilities - 3rd byte
  71. NoReceiveChannels = ((capabilitiesData[2] & (byte)BasicCapabilitiesMasks.NO_RX_CHANNELS) != 0);
  72. NoTransmitChannels = ((capabilitiesData[2] & (byte)BasicCapabilitiesMasks.NO_TX_CHANNELS) != 0);
  73. NoReceiveMessages = ((capabilitiesData[2] & (byte)BasicCapabilitiesMasks.NO_RX_MESSAGES) != 0);
  74. NoTransmitMessages = ((capabilitiesData[2] & (byte)BasicCapabilitiesMasks.NO_TX_MESSAGES) != 0);
  75. NoAckMessages = ((capabilitiesData[2] & (byte)BasicCapabilitiesMasks.NO_ACKD_MESSAGES) != 0);
  76. NoBurstMessages = ((capabilitiesData[2] & (byte)BasicCapabilitiesMasks.NO_BURST_TRANSFER) != 0);
  77. //Advanced Capabilities - 4th byte
  78. PrivateNetworks = ((capabilitiesData[3] & (byte)AdvancedCapabilitiesMasks.NETWORK_CAPABLE) != 0);
  79. SerialNumber = ((capabilitiesData[3] & (byte)AdvancedCapabilitiesMasks.SERIAL_NUMBER_CAPABLE) != 0);
  80. perChannelTransmitPower = ((capabilitiesData[3] & (byte)AdvancedCapabilitiesMasks.PER_CHANNEL_TX_POWER_CAPABLE) != 0);
  81. lowPrioritySearch = ((capabilitiesData[3] & (byte)AdvancedCapabilitiesMasks.LOW_PRIORITY_SEARCH_CAPABLE) != 0);
  82. ScriptSupport = ((capabilitiesData[3] & (byte)AdvancedCapabilitiesMasks.SCRIPT_CAPABLE) != 0);
  83. SearchList = ((capabilitiesData[3] & (byte)AdvancedCapabilitiesMasks.SEARCH_LIST_CAPABLE) != 0);
  84. //Advanced Capabilities 2 - 5th byte
  85. OnboardLED = ((capabilitiesData[4] & (byte)AdvancedCapabilities2Masks.LED_CAPABLE) != 0);
  86. ExtendedMessaging = ((capabilitiesData[4] & (byte)AdvancedCapabilities2Masks.EXT_MESSAGE_CAPABLE) != 0);
  87. ScanModeSupport = ((capabilitiesData[4] & (byte)AdvancedCapabilities2Masks.SCAN_MODE_CAPABLE) != 0);
  88. ProximitySearch = ((capabilitiesData[4] & (byte)AdvancedCapabilities2Masks.PROX_SEARCH_CAPABLE) != 0);
  89. ExtendedChannelAssignment = ((capabilitiesData[4] & (byte)AdvancedCapabilities2Masks.EXT_ASSIGN_CAPABLE) != 0);
  90. FS = ((capabilitiesData[4] & (byte)AdvancedCapabilities2Masks.FS_ANTFS_ENABLED) != 0);
  91. FIT = ((capabilitiesData[4] & (byte)AdvancedCapabilities2Masks.FIT1_CAPABLE) != 0);
  92. //SensorCore Data Channels - 6th byte
  93. maxDataChannels = capabilitiesData[5];
  94. //Advanced Capabilities 3 - 7th byte
  95. AdvancedBurst = ((capabilitiesData[6] & (byte)AdvancedCapabilities3Masks.ADVANCED_BURST_CAPABLE) != 0);
  96. EventBuffering = ((capabilitiesData[6] & (byte)AdvancedCapabilities3Masks.EVENT_BUFFERING_CAPABLE) != 0);
  97. EventFiltering = ((capabilitiesData[6] & (byte)AdvancedCapabilities3Masks.EVENT_FILTERING_CAPABLE) != 0);
  98. HighDutySearch = ((capabilitiesData[6] & (byte)AdvancedCapabilities3Masks.HIGH_DUTY_SEARCH_CAPABLE) != 0);
  99. SelectiveDataUpdate = ((capabilitiesData[6] & (byte)AdvancedCapabilities3Masks.SELECTIVE_DATA_UPDATE) != 0);
  100. SingleChannelEncryption = ((capabilitiesData[6] & (byte)AdvancedCapabilities3Masks.ENCRYPTED_CHANNEL_CAPABLE) != 0);
  101. }
  102. /// <summary>
  103. /// Prints a string containing a formatted, readable version of all the capabilities
  104. /// </summary>
  105. public String printCapabilities()
  106. {
  107. StringBuilder returnString = new StringBuilder();
  108. returnString.AppendLine( "Max ANT Channels: " + maxANTChannels);
  109. returnString.AppendLine( "Max Networks: " + maxNetworks);
  110. returnString.AppendLine( "Max Data Channels: " + maxDataChannels);
  111. returnString.AppendLine( "Capabilities:");
  112. //Basic
  113. if(NoReceiveChannels)
  114. returnString.AppendLine("-No Receive Channels");
  115. if (NoTransmitChannels)
  116. returnString.AppendLine("-No Transmit Channels");
  117. if (NoReceiveMessages)
  118. returnString.AppendLine("-No Receive Messages");
  119. if (NoTransmitMessages)
  120. returnString.AppendLine("-No Transmit Messages");
  121. if (NoAckMessages)
  122. returnString.AppendLine("-No Acknowledged Messaging");
  123. if (NoBurstMessages)
  124. returnString.AppendLine("-No Burst Messaging");
  125. //Advanced
  126. if (PrivateNetworks)
  127. returnString.AppendLine("-Private Networks");
  128. if (SerialNumber)
  129. returnString.AppendLine("-Serial Number");
  130. if (perChannelTransmitPower)
  131. returnString.AppendLine("-Per Channel Tx Power");
  132. if (lowPrioritySearch)
  133. returnString.AppendLine("-Low Priority Search");
  134. if (ScriptSupport)
  135. returnString.AppendLine("-Script Support");
  136. if (SearchList)
  137. returnString.AppendLine("-Search List");
  138. //Advanced 2
  139. if (OnboardLED)
  140. returnString.AppendLine("-Onboard LED");
  141. if (ExtendedMessaging)
  142. returnString.AppendLine("-Extended Messaging");
  143. if (ScanModeSupport)
  144. returnString.AppendLine("-Scan Channel Support");
  145. if (ExtendedChannelAssignment)
  146. returnString.AppendLine("-Ext Channel Assignment");
  147. if (ProximitySearch)
  148. returnString.AppendLine("-Proximity Search");
  149. if (FS)
  150. returnString.AppendLine("-FS");
  151. if (FIT)
  152. returnString.AppendLine("-FIT");
  153. //Advanced 3
  154. if (AdvancedBurst)
  155. returnString.AppendLine("-Advanced Burst");
  156. if (EventBuffering)
  157. returnString.AppendLine("-Event Buffering");
  158. if (EventFiltering)
  159. returnString.AppendLine("-Event Filtering");
  160. if (HighDutySearch)
  161. returnString.AppendLine("-High Duty Search");
  162. if (SelectiveDataUpdate)
  163. returnString.AppendLine("-Selective Data Update");
  164. if (SingleChannelEncryption)
  165. returnString.AppendLine("-Single Channel Encryption");
  166. return returnString.ToString();
  167. }
  168. /// <summary>
  169. /// Prints a compact string containing a formatted, readable version of just the standard capabilities
  170. /// </summary>
  171. public String printStandardCapabilities()
  172. {
  173. StringBuilder returnString = new StringBuilder();
  174. returnString.AppendLine("Max ANT Channels: " + maxANTChannels);
  175. returnString.AppendLine("Max Networks: " + maxNetworks);
  176. returnString.AppendLine("Max Data Channels: " + maxDataChannels);
  177. //Basic
  178. if (NoReceiveChannels)
  179. returnString.AppendLine("-No Receive Channels");
  180. if (NoTransmitChannels)
  181. returnString.AppendLine("-No Transmit Channels");
  182. if (NoReceiveMessages)
  183. returnString.AppendLine("-No Receive Messages");
  184. if (NoTransmitMessages)
  185. returnString.AppendLine("-No Transmit Messages");
  186. if (NoAckMessages)
  187. returnString.AppendLine("-No Acknowledged Messaging");
  188. if (NoBurstMessages)
  189. returnString.AppendLine("-No Burst Messaging");
  190. return returnString.ToString();
  191. }
  192. /// <summary>
  193. /// Prints a string containing a formatted, readable version of all the advanced capabilities
  194. /// </summary>
  195. public String printAdvCapabilities()
  196. {
  197. StringBuilder returnString = new StringBuilder();
  198. returnString.AppendLine("Adv Capabilities:");
  199. //Basic
  200. if (NoReceiveChannels)
  201. returnString.AppendLine("-No Receive Channels");
  202. if (NoTransmitChannels)
  203. returnString.AppendLine("-No Transmit Channels");
  204. if (NoReceiveMessages)
  205. returnString.AppendLine("-No Receive Messages");
  206. if (NoTransmitMessages)
  207. returnString.AppendLine("-No Transmit Messages");
  208. if (NoAckMessages)
  209. returnString.AppendLine("-No Acknowledged Messaging");
  210. if (NoBurstMessages)
  211. returnString.AppendLine("-No Burst Messaging");
  212. //Advanced
  213. if (PrivateNetworks)
  214. returnString.AppendLine("-Private Networks");
  215. if (SerialNumber)
  216. returnString.AppendLine("-Serial Number");
  217. if (perChannelTransmitPower)
  218. returnString.AppendLine("-Per Channel Tx Power");
  219. if (lowPrioritySearch)
  220. returnString.AppendLine("-Low Priority Search");
  221. if (ScriptSupport)
  222. returnString.AppendLine("-Script Support");
  223. if (SearchList)
  224. returnString.AppendLine("-Search List");
  225. //Advanced 2
  226. if (OnboardLED)
  227. returnString.AppendLine("-Onboard LED");
  228. if (ExtendedMessaging)
  229. returnString.AppendLine("-Extended Messaging");
  230. if (ScanModeSupport)
  231. returnString.AppendLine("-Scan Channel Support");
  232. if (ExtendedChannelAssignment)
  233. returnString.AppendLine("-Ext Channel Assignment");
  234. if (ProximitySearch)
  235. returnString.AppendLine("-Proximity Search");
  236. if (FS)
  237. returnString.AppendLine("-FS");
  238. if (FIT)
  239. returnString.AppendLine("-FIT");
  240. //Advanced 3
  241. if (AdvancedBurst)
  242. returnString.AppendLine("-Advanced Burst");
  243. if (EventBuffering)
  244. returnString.AppendLine("-Event Buffering");
  245. if (EventFiltering)
  246. returnString.AppendLine("-Event Filtering");
  247. if (HighDutySearch)
  248. returnString.AppendLine("-High Duty Search");
  249. if (SelectiveDataUpdate)
  250. returnString.AppendLine("-Selective Data Update");
  251. if (SingleChannelEncryption)
  252. returnString.AppendLine("-Single Channel Encryption");
  253. return returnString.ToString();
  254. }
  255. /// <summary>
  256. /// Returns a formatted, readable string of all the capabilities
  257. /// </summary>
  258. public override String ToString() { return printCapabilities(); }
  259. #pragma warning disable 1591
  260. /// <summary>
  261. /// Basic Capabilities Masks (3rd Byte)
  262. /// </summary>
  263. public enum BasicCapabilitiesMasks : byte
  264. {
  265. NO_RX_CHANNELS = 0x01,
  266. NO_TX_CHANNELS = 0x02,
  267. NO_RX_MESSAGES = 0x04,
  268. NO_TX_MESSAGES = 0x08,
  269. NO_ACKD_MESSAGES = 0x10,
  270. NO_BURST_TRANSFER = 0x20
  271. };
  272. /// <summary>
  273. /// Advanced Capabilities Masks 1 (4th Byte)
  274. /// </summary>
  275. public enum AdvancedCapabilitiesMasks : byte
  276. {
  277. OVERUN_UNDERRUN = 0x01, // Support for this functionality has been dropped
  278. NETWORK_CAPABLE = 0x02,
  279. AP1_VERSION_2 = 0x04, // This Version of the AP1 does not support transmit and only had a limited release
  280. SERIAL_NUMBER_CAPABLE = 0x08,
  281. PER_CHANNEL_TX_POWER_CAPABLE = 0x10,
  282. LOW_PRIORITY_SEARCH_CAPABLE = 0x20,
  283. SCRIPT_CAPABLE = 0x40,
  284. SEARCH_LIST_CAPABLE = 0x80
  285. };
  286. /// <summary>
  287. /// Advanced Capabilities Masks 2 (5th Byte)
  288. /// </summary>
  289. public enum AdvancedCapabilities2Masks : byte
  290. {
  291. LED_CAPABLE = 0x01,
  292. EXT_MESSAGE_CAPABLE = 0x02,
  293. SCAN_MODE_CAPABLE = 0x04,
  294. RESERVED = 0x08,
  295. PROX_SEARCH_CAPABLE = 0x10,
  296. EXT_ASSIGN_CAPABLE = 0x20,
  297. FS_ANTFS_ENABLED = 0x40,
  298. FIT1_CAPABLE = 0x80,
  299. };
  300. /// <summary>
  301. /// Advanced Capabilities Masks 3 (7th Byte)
  302. /// </summary>
  303. public enum AdvancedCapabilities3Masks : byte
  304. {
  305. ADVANCED_BURST_CAPABLE = 0x01,
  306. EVENT_BUFFERING_CAPABLE = 0x02,
  307. EVENT_FILTERING_CAPABLE = 0x04,
  308. HIGH_DUTY_SEARCH_CAPABLE = 0x08,
  309. SELECTIVE_DATA_UPDATE = 0x40,
  310. ENCRYPTED_CHANNEL_CAPABLE = 0x80,
  311. };
  312. #pragma warning restore 1591
  313. };
  314. }