コード例 #1
0
ファイル: DBCMessage.cs プロジェクト: ffjiangMr/.NetC-
        /// <summary>
        /// 从message中检索MultiplexedSignal
        /// 如果存在多个,则只返回第一个
        /// </summary>
        /// <param name="signal">搜索结果</param>
        /// <returns>搜索是否成功</returns>
        public Boolean SearchMultiplexerSignalFormMessage(out DBCSignal signal)
        {
            var result = false;

            signal = null;
            foreach (var item in this.Signals)
            {
                if (item.MultiplexerIndicator == MultiplexerIndicator.MultiplexedSignal)
                {
                    signal = item;
                    result = true;
                    break;
                }
            }
            return(result);
        }
コード例 #2
0
ファイル: DBCMessage.cs プロジェクト: ffjiangMr/.NetC-
        /// <summary>
        /// 根据Name从Message检索Signal
        /// 如果存在多个匹配则返回第一个匹配
        /// </summary>
        /// <param name="name">Signal name</param>
        /// <param name="signal">检索结果</param>
        /// <returns>是否成功</returns>
        public Boolean SearchSignalByName(String name, out DBCSignal signal)
        {
            var result = false;

            signal = null;
            foreach (var item in this.Signals)
            {
                if (item.SignalName == name)
                {
                    signal = item;
                    result = true;
                    break;
                }
            }
            return(result);
        }
コード例 #3
0
ファイル: DBCSignal.cs プロジェクト: ffjiangMr/.NetC-
        /// <summary>
        /// 根据原始数据解析Signal数据
        /// </summary>
        /// <param name="signal">需要解析的signal</param>
        /// <param name="data">原始数据</param>
        /// <param name="valueString">解析值</param>
        /// <returns>是否成功</returns>
        public static Boolean GetDbcData(ref DBCSignal signal, Byte[] data, out String valueString)
        {
            valueString = "";
            UInt16 start;
            UInt64 tempUInt64;

            if (signal.MultiplexerIndicator == MultiplexerIndicator.MultiplexedSignals)
            {
                DBCSignal tempSignal;
                signal.Message.SearchMultiplexerSignalFormMessage(out tempSignal);
                if (tempSignal != null)
                {
                    String tempResult;
                    GetDbcData(ref tempSignal, data, out tempResult);
                    if (tempSignal.Data != signal.MultiplexerSwitchValue)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            if (signal.ByteOrder == ByteOrder.Motorola)
            {
                start = (UInt16)(63 - (7 - signal.StartPosition % 8) - signal.StartPosition / 8 * 8);
                UInt64 temp = 0;
                for (Int32 i = 0; i < 8; i++)
                {
                    temp <<= 8;
                    temp  |= data[i];
                }
                tempUInt64 = temp << (63 - start);
                tempUInt64 = tempUInt64 >> (63 - signal.SignalSize + 1);
            }
            else
            {
                start = signal.StartPosition;
                UInt64 temp = 0;
                for (Int32 i = 8; i > 0; i--)
                {
                    temp <<= 8;
                    temp  |= data[i];
                }
                tempUInt64 = temp << (63 - start - signal.SignalSize + 1);
                tempUInt64 = tempUInt64 >> (63 - signal.SignalSize + 1);
            }
            Double  value      = signal.Factor * tempUInt64 + signal.Offset;
            String  tempString = value.ToString();
            Boolean isDecimals = tempString.Contains(".");

            if (!isDecimals)
            {
                UInt32 tempValue = (UInt32)value;
                Int32  size      = signal.Values.Count;
                if (size > 0)
                {
                    for (Int32 i = 0; i < size; i++)
                    {
                        foreach (var item in signal.Values)
                        {
                            if (item.Value == tempValue)
                            {
                                valueString = item.Key;
                                signal.Data = item.Value;
                                return(true);
                            }
                        }
                    }
                }
            }
            String factorString = signal.Factor.ToString();
            String offsetString = signal.Offset.ToString();
            var    precision    = ((factorString.Length - factorString.LastIndexOf(".") - 1) >
                                   (offsetString.Length - offsetString.LastIndexOf(".") - 1)) ?
                                  (factorString.Length - factorString.LastIndexOf(".") - 1) :
                                  (offsetString.Length - offsetString.LastIndexOf(".") - 1);

            if (precision == -1)
            {
                precision = 0;
            }
            String formatString = "0.".PadRight(2 + precision, '0');

            valueString = String.Format("{0:" + formatString + "}", value);
            signal.Data = value;
            return(true);
        }