ANT_DeviceCapabilities.cs 15 KB

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