123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- #region Copyright
- #endregion
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Text;
- using System.IO;
- namespace Dynastream.Fit
- {
-
-
-
-
-
- public class Subfield
- {
- #region Internal Classes
-
-
-
-
- private class SubfieldMap
- {
- private byte refFieldNum;
- private object refFieldValue;
- internal SubfieldMap(byte refFieldNum, object refFieldValue)
- {
- this.refFieldNum = refFieldNum;
- this.refFieldValue = refFieldValue;
- }
- internal SubfieldMap(SubfieldMap subfieldMap)
- {
- this.refFieldNum = subfieldMap.refFieldNum;
- this.refFieldValue = subfieldMap.refFieldValue;
- }
-
-
-
-
-
-
- internal bool CanMesgSupport(Mesg mesg)
- {
- Field field = mesg.GetField(refFieldNum);
- if (field != null)
- {
- object value = field.GetValue(0, Fit.SubfieldIndexMainField);
-
- if (Convert.ToInt64(value) == Convert.ToInt64(refFieldValue))
- {
- return true;
- }
- }
- return false;
- }
- }
- #endregion Internal Classes
- #region Fields
- private string name;
- private byte type;
- private float scale;
- private float offset;
- private string units;
- private List<SubfieldMap> maps;
- private List<FieldComponent> components;
- #endregion // Fields
- #region Properties
- internal string Name
- {
- get
- {
- return name;
- }
- }
- internal byte Type
- {
- get
- {
- return type;
- }
- }
- internal float Scale
- {
- get
- {
- return scale;
- }
- }
- internal float Offset
- {
- get
- {
- return offset;
- }
- }
- internal string Units
- {
- get
- {
- return units;
- }
- }
- internal List<FieldComponent> Components
- {
- get
- {
- return components;
- }
- }
- #endregion // Properties
- #region Constructors
- internal Subfield(Subfield subfield)
- {
- if (subfield == null)
- {
- this.name = "unknown";
- this.type = 0;
- this.scale = 1f;
- this.offset = 0f;
- this.units = "";
- this.maps = new List<SubfieldMap>();
- this.components = new List<FieldComponent>();
- return;
- }
- this.name = subfield.name;
- this.type = subfield.type;
- this.scale = subfield.scale;
- this.offset = subfield.offset;
- this.units = subfield.units;
- this.maps = new List<SubfieldMap>();
- foreach (SubfieldMap map in subfield.maps)
- {
- this.maps.Add(new SubfieldMap(map));
- }
- this.components = new List<FieldComponent>();
- foreach (FieldComponent comp in subfield.components)
- {
- this.components.Add(new FieldComponent(comp));
- }
- }
- internal Subfield(string name, byte type, float scale, float offset, string units)
- {
- this.name = name;
- this.type = type;
- this.scale = scale;
- this.offset = offset;
- this.units = units;
- this.maps = new List<SubfieldMap>();
- this.components = new List<FieldComponent>();
- }
- #endregion // Constructors
- #region Methods
- internal void AddMap(byte refFieldNum, object refFieldValue)
- {
- maps.Add(new SubfieldMap(refFieldNum, refFieldValue));
- }
- internal void AddComponent(FieldComponent newComponent)
- {
- components.Add(newComponent);
- }
-
-
-
-
-
-
- public bool CanMesgSupport(Mesg mesg)
- {
- foreach (SubfieldMap map in maps)
- {
- if (map.CanMesgSupport(mesg))
- {
- return true;
- }
- }
- return false;
- }
- #endregion // Methods
- }
- }
|