ANTFS_ReferenceLibrary.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. //////////////////////////////////////////////////////////////////////////
  9. // This file contains all the enumerations and constants for general
  10. // use with ANT-FS
  11. //////////////////////////////////////////////////////////////////////////
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Text;
  15. using System.ComponentModel;
  16. using System.Reflection;
  17. #pragma warning disable 1591
  18. namespace ANT_Managed_Library.ANTFS
  19. {
  20. #region Constants
  21. /// <summary>
  22. /// Return codes for ANT-FS operations
  23. /// </summary>
  24. public enum ReturnCode : byte
  25. {
  26. [Description("Library in wrong state")]
  27. Fail = 0,
  28. [Description("Operation successful")]
  29. Pass,
  30. [Description("Library is busy with another request")]
  31. Busy
  32. };
  33. /// <summary>
  34. /// ANT-FS authentication types
  35. /// </summary>
  36. public enum AuthenticationType : byte
  37. {
  38. [Description("No authentication required")]
  39. None = 0,
  40. [Description("Not applicable (used for getting ID)")]
  41. NA,
  42. [Description("Pairing only authentication available")]
  43. Pairing,
  44. [Description("Passkey exchange and pairing supported")]
  45. PassKey
  46. }
  47. public enum AuthenticationCommand : byte
  48. {
  49. GotoTransport = 0x00,
  50. RequestSerialNumber = 0x01,
  51. Pair = 0x02,
  52. PassKey = 0x03
  53. }
  54. public enum RadioFrequency : byte
  55. {
  56. ANTFSNetwork = 50,
  57. ANTPlusNetwork = 57,
  58. Auto = 255
  59. }
  60. /// <summary>
  61. /// ANT-FS disconnect command type
  62. /// </summary>
  63. public enum DisconnectType : byte
  64. {
  65. [Description("Go back to Link state")]
  66. Link = 0,
  67. [Description("Return to broadcast")]
  68. Broadcast = 1
  69. }
  70. public enum BlackoutTime : ushort
  71. {
  72. None = 0,
  73. Infinite = 0xFFFF
  74. }
  75. [Flags]
  76. public enum Status1 : byte
  77. {
  78. DataAvailableBit = 0x20,
  79. UploadEnabledBit = 0x10,
  80. PairingEnabledBit = 0x08,
  81. BeaconPeriodBits = 0x07,
  82. DefaultSearchMask = 0x38
  83. }
  84. [Flags]
  85. public enum Status2 : byte
  86. {
  87. ClientStateBits = 0x0F,
  88. DefaultSearchMask = 0x00
  89. }
  90. public enum BeaconPeriod : byte
  91. {
  92. [Description("0.5 Hz (65535 counts)")]
  93. HalfHz = 0x00,
  94. [Description("1 Hz (32768 counts)")]
  95. OneHz = 0x01,
  96. [Description("2 Hz (16384 counts)")]
  97. TwoHz = 0x02,
  98. [Description("4 Hz (8192 counts)")]
  99. FourHz = 0x03,
  100. [Description("8 Hz (4096 counts)")]
  101. EightHz = 0x04,
  102. [Description("Keep assigned channel period")]
  103. Keep = 0x07
  104. }
  105. public enum ClientState : byte
  106. {
  107. Link = 0x00,
  108. Authenticate = 0x01,
  109. Transport = 0x02,
  110. Busy = 0x03
  111. }
  112. public enum DownloadResponse : byte
  113. {
  114. Ok = 0x00,
  115. InvalidIndex = 0x01,
  116. FileNotReadable = 0x02,
  117. NotReady = 0x03,
  118. InvalidRequest = 0x04,
  119. BadCrc = 0x05
  120. }
  121. public enum EraseResponse : byte
  122. {
  123. Ok = 0x00,
  124. Reject = 0x01
  125. }
  126. public enum UploadResponse : byte
  127. {
  128. Ok = 0x00,
  129. InvalidIndex = 0x01,
  130. FileNotWriteable = 0x02,
  131. InsufficientSpace = 0x03,
  132. InvalidRequest = 0x04,
  133. NotReady = 0x05
  134. }
  135. #endregion
  136. #region Helper Methods
  137. /// <summary>
  138. /// Helper class that prints human readable versions of the constants
  139. /// </summary>
  140. public static class Print
  141. {
  142. /// <summary>
  143. /// Prints the description attribute of an enumeration value
  144. /// </summary>
  145. /// <param name="eMyEnum">Enumeration value to print</param>
  146. /// <returns>Description string, e.g. "Operation successful"</returns>
  147. public static string AsString(Enum eMyEnum)
  148. {
  149. FieldInfo myField = eMyEnum.GetType().GetField(eMyEnum.ToString());
  150. if (myField != null)
  151. {
  152. DescriptionAttribute[] myAttributes = (DescriptionAttribute[]) myField.GetCustomAttributes(typeof(DescriptionAttribute), false);
  153. if((myAttributes != null) && (myAttributes.Length > 0))
  154. {
  155. return myAttributes[0].Description; // If available, print the Description attribute
  156. }
  157. }
  158. return Print.AsEnum(eMyEnum); // Otherwise, just print the enum value
  159. }
  160. /// <summary>
  161. /// Prints the name of an enumeration value
  162. /// </summary>
  163. /// <param name="eMyEnum">Enumeration value to print</param>
  164. /// <returns>Named enumeration string, e.g. "ANTFS.ReturnCode.Pass"</returns>
  165. public static string AsEnum(Enum eMyEnum)
  166. {
  167. return "ANTFS." + eMyEnum.GetType().Name + "." + eMyEnum.ToString(); // String representation of the enum, or numeric value, if not defined in enum
  168. }
  169. }
  170. #endregion
  171. }