예제 #1
0
 /// <summary>
 /// Copies a BCD val into a byte stream, format is "big endian" (MSB first)
 /// </summary>
 /// <param name="Value">Value to be set to the buffer</param>
 /// <param name="index">Offset in bytes where the val should be insert</param>
 /// <param name="Length">Digits of the BCD val</param>
 public virtual void SetBcd(byte[] data, BcdValue value, int index, int length)
 {
     SetValueType(data, value.GetBytes(length), index);
 }
예제 #2
0
        /// <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);
        }