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(Subfield subfield) { if (subfield == null) { this.name = "unknown"; this.type = 0; this.scale = 1f; this.offset = 0f; this.units = ""; this.maps = new List<SubfieldMap>(); 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)); } }
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); }
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); } } }
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); } }
internal bool IsSigned(Subfield subfield) { byte type = subfield == null ? Type : subfield.Type; type &= Fit.BaseTypeNumMask; return(Fit.BaseType[type].isSigned); }
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); }
private string GetName(Subfield subfield) { if (subfield == null) { return(name); } else { return(subfield.Name); } }
private string GetUnits(Subfield subfield) { if (subfield == null) { return(units); } else { return(subfield.Units); } }
internal bool IsSigned(Subfield subfield) { if (subfield == null) { return(Fit.BaseType[Type & Fit.BaseTypeNumMask].isSigned); } else { return(Fit.BaseType[subfield.Type & Fit.BaseTypeNumMask].isSigned); } }
private byte GetType(Subfield subfield) { if (subfield == null) { return(type); } else { return(subfield.Type); } }
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.CanMessageSupport(this))) { return; } Field field = GetField(name, false); if (field == null) { field = new Field(Profile.GetMessage(this.MessageNumber).GetField(name)); SetField(field); } field.SetValue(fieldArrayIndex, value, name); }
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.CanMessageSupport(this))) { return(field.GetValue(fieldArrayIndex, name)); } else { return(null); } }
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.CanMessageSupport(this))) { return(field.GetValue(fieldArrayIndex, subfieldName)); } else { return(null); } }
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.CanMessageSupport(this))) { return(field.GetNumValues()); } else { return(0); } }
private byte GetType(Subfield subfield) { return(subfield == null ? Type : subfield.Type); }
internal bool IsSigned(Subfield subfield) { if (subfield == null) { return Fit.BaseType[Type & Fit.BaseTypeNumMask].isSigned; } else { return Fit.BaseType[subfield.Type & Fit.BaseTypeNumMask].isSigned; } }
public void SetValue(int index, object value, Subfield subfield) { double 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.SInt64: values.Add(new long()); break; case Fit.UInt64: case Fit.UInt64z: values.Add(new ulong()); 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 = Scale; offset = Offset; } else { scale = subfield.Scale; offset = Offset; } // Cast to long as scale and offset only apply to integer based types // and we want to make sure we have maximum precision. long invalidValue = 0; long castedValue = 0; if (IsNumeric()) { // Cast to long as scale and offset only apply to integer based types // and we want to make sure we have maximum precision. invalidValue = (long)Convert.ToDouble(Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue); castedValue = (long)Convert.ToDouble(value); // If the field is numeric, check if the value is less than the base // type's invalid value. For "z" base types where 0 is invalid, check // that the value is > 0. Apply scale and offset if valid. if ((castedValue < invalidValue) || ((invalidValue == 0) && (castedValue > 0))) { 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. bool success = false; switch (Type & Fit.BaseTypeNumMask) { case Fit.Enum: case Fit.Byte: case Fit.UInt8: case Fit.UInt8z: if ((Convert.ToDouble(value) >= byte.MinValue) && (Convert.ToDouble(value) <= byte.MaxValue)) { value = Convert.ToByte(value); success = true; } break; case Fit.SInt8: if ((Convert.ToDouble(value) >= sbyte.MinValue) && (Convert.ToDouble(value) <= sbyte.MaxValue)) { value = Convert.ToSByte(value); success = true; } break; case Fit.SInt16: if ((Convert.ToDouble(value) >= short.MinValue) && (Convert.ToDouble(value) <= short.MaxValue)) { value = Convert.ToInt16(value); success = true; } break; case Fit.UInt16: case Fit.UInt16z: if ((Convert.ToDouble(value) >= ushort.MinValue) && (Convert.ToDouble(value) <= ushort.MaxValue)) { value = Convert.ToUInt16(value); success = true; } break; case Fit.SInt32: if ((Convert.ToDouble(value) >= int.MinValue) && (Convert.ToDouble(value) <= int.MaxValue)) { value = Convert.ToInt32(value); success = true; } break; case Fit.UInt32: case Fit.UInt32z: if ((Convert.ToDouble(value) >= uint.MinValue) && (Convert.ToDouble(value) <= uint.MaxValue)) { value = Convert.ToUInt32(value); success = true; } break; case Fit.SInt64: value = Convert.ToInt64(value); success = true; break; case Fit.UInt64: case Fit.UInt64z: value = Convert.ToUInt64(value); success = true; break; case Fit.Float32: if ((Convert.ToDouble(value) >= float.MinValue) && (Convert.ToDouble(value) <= float.MaxValue)) { value = Convert.ToSingle(value); success = true; } break; case Fit.Float64: if (((double)value >= double.MinValue) && ((double)value <= double.MaxValue)) { value = Convert.ToDouble(value); success = true; } break; case Fit.String: success = true; break; default: break; } // If the conversion failed, set the value to invalid if (success == false) { value = Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue; } values[index] = value; }
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; }
private string GetUnits(Subfield subfield) { if (subfield == null) { return units; } else { return subfield.Units; } }
private byte GetType(Subfield subfield) { if (subfield == null) { return type; } else { return subfield.Type; } }
private string GetName(Subfield subfield) { if (subfield == null) { return name; } else { return subfield.Name; } }
private string GetUnits(Subfield subfield) { return(subfield == null ? Units : subfield.Units); }
public object GetValue(int index, Subfield subfield) { double scale, offset; if (index >= values.Count || index < 0) { return(null); } if (subfield == null) { scale = Scale; offset = Offset; } else { scale = subfield.Scale; offset = subfield.Offset; } object value; bool castToFloat = false; switch (Type & Fit.BaseTypeNumMask) { case Fit.Enum: case Fit.Byte: case Fit.UInt8: case Fit.UInt8z: value = Convert.ToByte(values[index]); if (((byte)value == (byte)Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue) && (scale != 1.0)) { castToFloat = true; } break; case Fit.SInt8: value = Convert.ToSByte(values[index]); if (((sbyte)value == (sbyte)Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue) && (scale != 1.0)) { castToFloat = true; } break; case Fit.SInt16: value = Convert.ToInt16(values[index]); if (((short)value == (short)Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue) && (scale != 1.0)) { castToFloat = true; } break; case Fit.UInt16: case Fit.UInt16z: value = Convert.ToUInt16(values[index]); if (((ushort)value == (ushort)Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue) && (scale != 1.0)) { castToFloat = true; } break; case Fit.SInt32: value = Convert.ToInt32(values[index]); if (((int)value == (int)Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue) && (scale != 1.0)) { castToFloat = true; } break; case Fit.UInt32: case Fit.UInt32z: value = Convert.ToUInt32(values[index]); if (((uint)value == (uint)Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue) && (scale != 1.0)) { castToFloat = true; } break; case Fit.SInt64: value = Convert.ToInt64(values[index]); if (((long)value == (long)Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue) && (scale != 1.0)) { castToFloat = true; } break; case Fit.UInt64: case Fit.UInt64z: value = Convert.ToUInt64(values[index]); if (((ulong)value == (ulong)Fit.BaseType[Type & Fit.BaseTypeNumMask].invalidValue) && (scale != 1.0)) { castToFloat = true; } break; case Fit.Float32: value = Convert.ToSingle(values[index]); if (float.IsNaN((float)value) && (scale != 1.0)) { castToFloat = true; } break; case Fit.Float64: value = Convert.ToDouble(values[index]); if (double.IsNaN((double)value) && (scale != 1.0)) { castToFloat = true; } break; case Fit.String: value = values[index]; break; default: value = null; break; } if (castToFloat == true) { //Cast to Single Precision (float) since its expecting a float value if scale > 1 value = Convert.ToSingle(value); return(value); } if (IsNumeric()) { if (scale != 1.0 || Offset != 0.0) { value = (float)((Convert.ToSingle(value) / scale) - offset); } } return(value); }
public void SetValue(int index, object value, Subfield subfield) { double 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; }
private string GetName(Subfield subfield) { return(subfield == null ? Name : subfield.Name); }
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. 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; } values[index] = value; }