2
0

Subfield.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #region Copyright
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // The following FIT Protocol software provided may be used with FIT protocol
  4. // devices only and remains the copyrighted property of Dynastream Innovations Inc.
  5. // The software is being provided on an "as-is" basis and as an accommodation,
  6. // and therefore all warranties, representations, or guarantees of any kind
  7. // (whether express, implied or statutory) including, without limitation,
  8. // warranties of merchantability, non-infringement, or fitness for a particular
  9. // purpose, are specifically disclaimed.
  10. //
  11. // Copyright 2016 Dynastream Innovations Inc.
  12. ////////////////////////////////////////////////////////////////////////////////
  13. // ****WARNING**** This file is auto-generated! Do NOT edit this file.
  14. // Profile Version = 16.60Release
  15. // Tag = production-akw-16.60.00-0-g5d3d436
  16. ////////////////////////////////////////////////////////////////////////////////
  17. #endregion
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Diagnostics;
  21. using System.Text;
  22. using System.IO;
  23. namespace Dynastream.Fit
  24. {
  25. /// <summary>
  26. /// The Subfield class represents an alternative field definition used
  27. /// by dynamic fields. They can only be associated with a containing
  28. /// field object.
  29. /// </summary>
  30. public class Subfield
  31. {
  32. #region Internal Classes
  33. /// <summary>
  34. /// The SubfieldMap class tracks the reference field/value pairs which indicate a field
  35. /// should use the alternate subfield definition rather than the usual defn (allows Dynamic Fields)
  36. /// </summary>
  37. private class SubfieldMap
  38. {
  39. private byte refFieldNum;
  40. private object refFieldValue;
  41. internal SubfieldMap(byte refFieldNum, object refFieldValue)
  42. {
  43. this.refFieldNum = refFieldNum;
  44. this.refFieldValue = refFieldValue;
  45. }
  46. internal SubfieldMap(SubfieldMap subfieldMap)
  47. {
  48. this.refFieldNum = subfieldMap.refFieldNum;
  49. this.refFieldValue = subfieldMap.refFieldValue;
  50. }
  51. /// <summary>
  52. /// Checks if the reference fields in a given message indicate the subfield (alternate)
  53. /// definition should be used
  54. /// </summary>
  55. /// <param name="mesg">message of interest</param>
  56. /// <returns>true if the subfield is active</returns>
  57. internal bool CanMesgSupport(Mesg mesg)
  58. {
  59. Field field = mesg.GetField(refFieldNum);
  60. if (field != null)
  61. {
  62. object value = field.GetValue(0, Fit.SubfieldIndexMainField);
  63. // Float refvalues are not supported
  64. if (Convert.ToInt64(value) == Convert.ToInt64(refFieldValue))
  65. {
  66. return true;
  67. }
  68. }
  69. return false;
  70. }
  71. }
  72. #endregion Internal Classes
  73. #region Fields
  74. private string name;
  75. private byte type;
  76. private float scale;
  77. private float offset;
  78. private string units;
  79. private List<SubfieldMap> maps;
  80. private List<FieldComponent> components;
  81. #endregion // Fields
  82. #region Properties
  83. internal string Name
  84. {
  85. get
  86. {
  87. return name;
  88. }
  89. }
  90. internal byte Type
  91. {
  92. get
  93. {
  94. return type;
  95. }
  96. }
  97. internal float Scale
  98. {
  99. get
  100. {
  101. return scale;
  102. }
  103. }
  104. internal float Offset
  105. {
  106. get
  107. {
  108. return offset;
  109. }
  110. }
  111. internal string Units
  112. {
  113. get
  114. {
  115. return units;
  116. }
  117. }
  118. internal List<FieldComponent> Components
  119. {
  120. get
  121. {
  122. return components;
  123. }
  124. }
  125. #endregion // Properties
  126. #region Constructors
  127. internal Subfield(Subfield subfield)
  128. {
  129. if (subfield == null)
  130. {
  131. this.name = "unknown";
  132. this.type = 0;
  133. this.scale = 1f;
  134. this.offset = 0f;
  135. this.units = "";
  136. this.maps = new List<SubfieldMap>();
  137. this.components = new List<FieldComponent>();
  138. return;
  139. }
  140. this.name = subfield.name;
  141. this.type = subfield.type;
  142. this.scale = subfield.scale;
  143. this.offset = subfield.offset;
  144. this.units = subfield.units;
  145. this.maps = new List<SubfieldMap>();
  146. foreach (SubfieldMap map in subfield.maps)
  147. {
  148. this.maps.Add(new SubfieldMap(map));
  149. }
  150. this.components = new List<FieldComponent>();
  151. foreach (FieldComponent comp in subfield.components)
  152. {
  153. this.components.Add(new FieldComponent(comp));
  154. }
  155. }
  156. internal Subfield(string name, byte type, float scale, float offset, string units)
  157. {
  158. this.name = name;
  159. this.type = type;
  160. this.scale = scale;
  161. this.offset = offset;
  162. this.units = units;
  163. this.maps = new List<SubfieldMap>();
  164. this.components = new List<FieldComponent>();
  165. }
  166. #endregion // Constructors
  167. #region Methods
  168. internal void AddMap(byte refFieldNum, object refFieldValue)
  169. {
  170. maps.Add(new SubfieldMap(refFieldNum, refFieldValue));
  171. }
  172. internal void AddComponent(FieldComponent newComponent)
  173. {
  174. components.Add(newComponent);
  175. }
  176. /// <summary>
  177. /// Checks if the reference fields in a given message indicate the subfield (alternate)
  178. /// definition should be used
  179. /// </summary>
  180. /// <param name="mesg">message of interest</param>
  181. /// <returns>true if the subfield is active</returns>
  182. public bool CanMesgSupport(Mesg mesg)
  183. {
  184. foreach (SubfieldMap map in maps)
  185. {
  186. if (map.CanMesgSupport(mesg))
  187. {
  188. return true;
  189. }
  190. }
  191. return false;
  192. }
  193. #endregion // Methods
  194. } // Class
  195. } // namespace