Ejemplo n.º 1
0
        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));
             }
        }
Ejemplo n.º 2
0
        public object GetFieldValue(byte fieldNum, int fieldArrayIndex, ushort subFieldIndex)
        {
            Field field = GetField(fieldNum);

            if (field == null)
            {
                return(null);
            }

            if (subFieldIndex == Fit.SubfieldIndexActiveSubfield)
            {
                return(field.GetValue(fieldArrayIndex, GetActiveSubFieldIndex(fieldNum)));
            }
            else
            {
                Subfield subfield = field.GetSubfield(subFieldIndex);

                if ((subfield == null) || (subfield.CanMesgSupport(this)))
                {
                    return(field.GetValue(fieldArrayIndex, subFieldIndex));
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 3
0
        public void SetFieldValue(byte fieldNum, int fieldArrayIndex, Object value, String subfieldName)
        {
            Field    testField = new Field(this.GetField(fieldNum));
            Subfield subfield  = testField.GetSubfield(subfieldName);

            if ((subfield != null) && !(subfield.CanMesgSupport(this)))
            {
                return;
            }

            Field field = GetField(fieldNum);

            if (field == null)
            {
                // We normally won't have fields attached to our skeleton message,
                // as we add values we need to add the fields too based on the mesg,field
                // combo in the profile.
                field = new Field(Profile.GetMesg(this.Num).GetField(fieldNum));
                if (field.Num == Fit.FieldNumInvalid)
                {
                    // If there was no info in the profile our FieldNum will get set to invalid,
                    // at least preserve FieldNum while we know it
                    field.Num = fieldNum;
                }
                SetField(field);
            }
            field.SetValue(fieldArrayIndex, value, subfieldName);
        }
Ejemplo n.º 4
0
        public int GetNumFieldValues(byte fieldNum, ushort subfieldIndex)
        {
            Field field = GetField(fieldNum);

            if (field == null)
            {
                return(0);
            }

            if (subfieldIndex == Fit.SubfieldIndexActiveSubfield)
            {
                return(field.GetNumValues());
            }

            Subfield subfield = field.GetSubfield(subfieldIndex);

            if ((subfield == null) || (subfield.CanMesgSupport(this)))
            {
                return(field.GetNumValues());
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 5
0
        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));
            }
        }
Ejemplo n.º 6
0
 private string GetUnits(Subfield subfield)
 {
     if (subfield == null)
     {
         return(units);
     }
     else
     {
         return(subfield.Units);
     }
 }
Ejemplo n.º 7
0
 private string GetName(Subfield subfield)
 {
     if (subfield == null)
     {
         return(name);
     }
     else
     {
         return(subfield.Name);
     }
 }
Ejemplo n.º 8
0
 private byte GetType(Subfield subfield)
 {
     if (subfield == null)
     {
         return(type);
     }
     else
     {
         return(subfield.Type);
     }
 }
Ejemplo n.º 9
0
 internal bool IsSigned(Subfield subfield)
 {
     if (subfield == null)
     {
         return(Fit.BaseType[Type & Fit.BaseTypeNumMask].isSigned);
     }
     else
     {
         return(Fit.BaseType[subfield.Type & Fit.BaseTypeNumMask].isSigned);
     }
 }
Ejemplo n.º 10
0
        public int GetNumFieldValues(byte fieldNum, string subfieldName)
        {
            Field field = GetField(fieldNum);

            if (field == null)
            {
                return(0);
            }

            Subfield subfield = field.GetSubfield(subfieldName);

            if ((subfield == null) || (subfield.CanMesgSupport(this)))
            {
                return(field.GetNumValues());
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 11
0
        public object GetFieldValue(byte fieldNum, int fieldArrayIndex, string subfieldName)
        {
            Field field = GetField(fieldNum);

            if (field == null)
            {
                return(null);
            }

            Subfield subfield = field.GetSubfield(subfieldName);

            if ((subfield == null) || (subfield.CanMesgSupport(this)))
            {
                return(field.GetValue(fieldArrayIndex, subfieldName));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 12
0
        public void SetFieldValue(String name, int fieldArrayIndex, Object value)
        {
            Field    testField = new Field(this.GetField(name));
            Subfield subfield  = testField.GetSubfield(name);

            if ((subfield != null) && !(subfield.CanMesgSupport(this)))
            {
                return;
            }

            Field field = GetField(name, false);

            if (field == null)
            {
                field = new Field(Profile.GetMesg(this.Num).GetField(name));
                SetField(field);
            }

            field.SetValue(fieldArrayIndex, value, name);
        }
Ejemplo n.º 13
0
        public object GetFieldValue(string name, int fieldArrayIndex)
        {
            Field field = GetField(name, false);

            if (field == null)
            {
                return(null);
            }

            Subfield subfield = field.GetSubfield(name);

            if ((subfield == null) || (subfield.CanMesgSupport(this)))
            {
                return(field.GetValue(fieldArrayIndex, name));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 14
0
        public object GetValue(int index, Subfield subfield)
        {
            float scale, offset;

             if (index >= values.Count || index < 0)
             {
            return null;
             }

             if (subfield == null)
             {
            scale = this.Scale;
            offset = this.Offset;
             }
             else
             {
            scale = subfield.Scale;
            offset = subfield.Offset;
             }

             object value = values[index];
             if (IsNumeric())
             {
            if (scale != 1.0 || Offset != 0.0)
            {
               value = Convert.ToSingle(value);
               value = (float)value / scale - offset;
            }
             }
             return value;
        }
Ejemplo n.º 15
0
 private string GetUnits(Subfield subfield)
 {
     if (subfield == null)
      {
     return units;
      }
      else
      {
     return subfield.Units;
      }
 }
Ejemplo n.º 16
0
 private byte GetType(Subfield subfield)
 {
     if (subfield == null)
      {
     return type;
      }
      else
      {
     return subfield.Type;
      }
 }
Ejemplo n.º 17
0
 private string GetName(Subfield subfield)
 {
     if (subfield == null)
      {
     return name;
      }
      else
      {
     return subfield.Name;
      }
 }
Ejemplo n.º 18
0
 internal bool IsSigned(Subfield subfield)
 {
     if (subfield == null)
      {
     return Fit.BaseType[Type & Fit.BaseTypeNumMask].isSigned;
      }
      else
      {
     return Fit.BaseType[subfield.Type & Fit.BaseTypeNumMask].isSigned;
      }
 }
Ejemplo n.º 19
0
        public void SetValue(int index, object value, Subfield subfield)
        {
            float scale, offset;

            while (index >= GetNumValues())
            {
                // Add placeholders of the correct type so GetSize() will
                // still compute correctly
                switch (Type & Fit.BaseTypeNumMask)
                {
                case Fit.Enum:
                case Fit.Byte:
                case Fit.UInt8:
                case Fit.UInt8z:
                    values.Add(new byte());
                    break;

                case Fit.SInt8:
                    values.Add(new sbyte());
                    break;

                case Fit.SInt16:
                    values.Add(new short());
                    break;

                case Fit.UInt16:
                case Fit.UInt16z:
                    values.Add(new ushort());
                    break;

                case Fit.SInt32:
                    values.Add(new int());
                    break;

                case Fit.UInt32:
                case Fit.UInt32z:
                    values.Add(new uint());
                    break;

                case Fit.Float32:
                    values.Add(new float());
                    break;

                case Fit.Float64:
                    values.Add(new double());
                    break;

                case Fit.String:
                    values.Add(new byte[0]);
                    break;

                default:
                    break;
                }
            }

            if (subfield == null)
            {
                scale  = this.Scale;
                offset = this.Offset;
            }
            else
            {
                scale  = subfield.Scale;
                offset = this.Offset;
            }

            if (IsNumeric())
            {
                if (scale != 1.0 || Offset != 0.0)
                {
                    value = Convert.ToSingle(value);
                    value = ((float)value + offset) * scale;
                }
            }
            // Must convert value back to the base type, if there was a scale or offset it will
            // have been converted to float.  Caller also may have passed in an unexpected type.
            try
            {
                switch (Type & Fit.BaseTypeNumMask)
                {
                case Fit.Enum:
                case Fit.Byte:
                case Fit.UInt8:
                case Fit.UInt8z:
                    value = Convert.ToByte(value);
                    break;

                case Fit.SInt8:
                    value = Convert.ToSByte(value);
                    break;

                case Fit.SInt16:
                    value = Convert.ToInt16(value);
                    break;

                case Fit.UInt16:
                case Fit.UInt16z:
                    value = Convert.ToUInt16(value);
                    break;

                case Fit.SInt32:
                    value = Convert.ToInt32(value);
                    break;

                case Fit.UInt32:
                case Fit.UInt32z:
                    value = Convert.ToUInt32(value);
                    break;

                case Fit.Float32:
                    value = Convert.ToSingle(value);
                    break;

                case Fit.Float64:
                    value = Convert.ToDouble(value);
                    break;

                default:
                    break;
                }
            }
            // If an exception happens while converting, set the value to invalid
            catch (Exception)
            {
                value = Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue;
            }
            values[index] = value;
        }
Ejemplo n.º 20
0
        public void SetValue(int index, object value, Subfield subfield)
        {
            float scale, offset;

             while (index >= GetNumValues())
             {
            // Add placeholders of the correct type so GetSize() will
            // still compute correctly
            switch (Type & Fit.BaseTypeNumMask)
            {
               case Fit.Enum:
               case Fit.Byte:
               case Fit.UInt8:
               case Fit.UInt8z:
                  values.Add(new byte());
                  break;

               case Fit.SInt8:
                  values.Add(new sbyte());
                  break;

               case Fit.SInt16:
                  values.Add(new short());
                  break;

               case Fit.UInt16:
               case Fit.UInt16z:
                  values.Add(new ushort());
                  break;

               case Fit.SInt32:
                  values.Add(new int());
                  break;

               case Fit.UInt32:
               case Fit.UInt32z:
                  values.Add(new uint());
                  break;

               case Fit.Float32:
                  values.Add(new float());
                  break;

               case Fit.Float64:
                  values.Add(new double());
                  break;

               case Fit.String:
                  values.Add(new byte[0]);
               break;

               default:
                  break;
            }
             }

             if (subfield == null)
             {
            scale = this.Scale;
            offset = this.Offset;
             }
             else
             {
            scale = subfield.Scale;
            offset = this.Offset;
             }

             if (IsNumeric())
             {
            if (scale != 1.0 || Offset != 0.0)
            {
               value = Convert.ToSingle(value);
               value = ((float)value + offset) * scale;
            }
             }
             // Must convert value back to the base type, if there was a scale or offset it will
             // have been converted to float.  Caller also may have passed in an unexpected type.
             try
             {
            switch (Type & Fit.BaseTypeNumMask)
            {
               case Fit.Enum:
               case Fit.Byte:
               case Fit.UInt8:
               case Fit.UInt8z:
                  value = Convert.ToByte(value);
                  break;

               case Fit.SInt8:
                  value = Convert.ToSByte(value);
                  break;

               case Fit.SInt16:
                  value = Convert.ToInt16(value);
                  break;

               case Fit.UInt16:
               case Fit.UInt16z:
                  value = Convert.ToUInt16(value);
                  break;

               case Fit.SInt32:
                  value = Convert.ToInt32(value);
                  break;

               case Fit.UInt32:
               case Fit.UInt32z:
                  value = Convert.ToUInt32(value);
                  break;

               case Fit.Float32:
                  value = Convert.ToSingle(value);
                  break;

               case Fit.Float64:
                  value = Convert.ToDouble(value);
                  break;

               default:
                  break;
            }
             }
             // If an exception happens while converting, set the value to invalid
             catch (Exception)
             {
            value = Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue;
             }
             values[index] = value;
        }