/// <summary> /// Provides EFS type associated to this CodecNT type /// </summary> /// <param name="type"></param> /// <returns>null is no EFS type could be found</returns> private string EFSType(ErtmsSolutions.CodecNT.Type type) { string retVal = null; if (type.ertms_type == ErtmsValueType.acceleration) { retVal = "MessageTypes.Acceleration"; } else if (type.ertms_type == ErtmsValueType.distance) { retVal = "MessageTypes.Distance"; } else if (type.ertms_type == ErtmsValueType.gradient) { retVal = "MessageTypes.Gradient"; } else if (type.ertms_type == ErtmsValueType.length) { retVal = "MessageTypes.Length"; } else if (type.ertms_type == ErtmsValueType.number) { retVal = "BaseTypes.Number"; } else if (type.ertms_type == ErtmsValueType.time_or_date) { retVal = "MessageTypes.Time"; } else if (type.ertms_type == ErtmsValueType.speed) { retVal = "MessageTypes.Speed"; } else if (type.ertms_type == ErtmsValueType.text) { retVal = "String"; } return(retVal); }
/// <summary> /// Provides EFS type associated to this CodecNT type /// </summary> /// <param name="type"></param> /// <returns>null is no EFS type could be found</returns> private string DefaultValue(ErtmsSolutions.CodecNT.Type type) { string retVal = null; if (type.ertms_type == ErtmsValueType.acceleration) { retVal = "0"; } else if (type.ertms_type == ErtmsValueType.distance) { retVal = "0"; } else if (type.ertms_type == ErtmsValueType.gradient) { retVal = "0"; } else if (type.ertms_type == ErtmsValueType.length) { retVal = "0"; } else if (type.ertms_type == ErtmsValueType.number) { retVal = "0"; } else if (type.ertms_type == ErtmsValueType.identity_number) { retVal = "0"; } else if (type.ertms_type == ErtmsValueType.speed) { retVal = "0"; } else if (type.ertms_type == ErtmsValueType.text) { retVal = "''"; } return(retVal); }
/// <summary> /// Appends the corresponding type to the name space /// </summary> /// <param name="nameSpace">The namespace in which the type must be added</param> /// <param name="name">the name of the type</param> /// <param name="type">the type to convert</param> private DataDictionary.Types.Type AppendType(DataDictionary.Types.NameSpace nameSpace, string name, ErtmsSolutions.CodecNT.Type type) { DataDictionary.Types.Type retVal = null; if (EFSType(type) == null) { if (type.value is UiValue) { UiValue uiValue = type.value as UiValue; List <DataDictionary.Constants.EnumValue> values = getSpecialValues(uiValue.special_or_reserved_values); Decimal maxValue = twoPow(type.length) - 1; if (IsEnumeration(values, maxValue)) { DataDictionary.Types.Enum enumeration = (DataDictionary.Types.Enum)DataDictionary.Generated.acceptor.getFactory().createEnum(); enumeration.Name = type.id; enumeration.Default = values[0].Name; foreach (DataDictionary.Constants.EnumValue value in values) { enumeration.appendValues(value); } nameSpace.appendEnumerations(enumeration); retVal = enumeration; } else { DataDictionary.Types.Range range = (DataDictionary.Types.Range)DataDictionary.Generated.acceptor.getFactory().createRange(); range.Name = type.id; double factor = 1.0; System.Globalization.CultureInfo info = System.Globalization.CultureInfo.InvariantCulture; ResolutionFormula resolutionFormula = uiValue.resolution_formula; if (resolutionFormula != null && resolutionFormula.Value != null) { factor = double.Parse(resolutionFormula.Value, info); // In that case the precision is integer range.setPrecision(DataDictionary.Generated.acceptor.PrecisionEnum.aIntegerPrecision); range.MinValue = "0"; range.MaxValue = "" + maxValue; range.Default = "0"; } else { if (Math.Round(factor) == factor) { // Integer precision range.setPrecision(DataDictionary.Generated.acceptor.PrecisionEnum.aIntegerPrecision); range.MinValue = "0"; range.MaxValue = "" + maxValue * new Decimal(factor); range.Default = "0"; } else { // Double precision range.setPrecision(DataDictionary.Generated.acceptor.PrecisionEnum.aDoublePrecision); range.MinValue = "0.0"; range.MaxValue = (maxValue * new Decimal(factor)).ToString(info); range.Default = "0.0"; } } foreach (DataDictionary.Constants.EnumValue value in values) { range.appendSpecialValues(value); } nameSpace.appendRanges(range); retVal = range; } } else if (type.value is CharValue) { CharValue charValue = type.value as CharValue; // Nothing to do : translated into string } else if (type.value is BcdValue) { BcdValue bcdValue = type.value as BcdValue; DataDictionary.Types.Range range = (DataDictionary.Types.Range)DataDictionary.Generated.acceptor.getFactory().createRange(); range.Name = type.id; range.MinValue = "0"; range.MaxValue = "" + (twoPow(type.length) - 1); range.Default = "0"; nameSpace.appendRanges(range); retVal = range; } if (retVal != null) { retVal.Comment = type.short_description; if (type.description != null) { retVal.Comment = retVal.Comment + "\n" + type.description; } } } return(retVal); }