Exemplo n.º 1
0
        private void ParseSignal(string strLine)
        {
            if (strLine.StartsWith("SG_MUL_VAL_"))
            {
                return;
            }
            if (_mode.Key != DBCObjType.Message)
            {
                throw new ApplicationException("Signal definition not in message block");
            }
            string pattern = @"SG_\s+(?<name>\S+)\s*(?<multiplexedID>m\d+)?(?<multiplexor>M)?\s*:\s*";

            pattern += @"(?<startBit>\d+)\|(?<length>\d+)@(?<byteOrder>[0|1])(?<sign>[+|-])\s*";
            pattern += @"\(\s*(?<factor>\S+)\s*,\s*(?<offset>\S+)\s*\)\s*";
            pattern += @"\[\s*(?<minValue>\S+)\s*\|\s*(?<maxValue>\S+)\s*\]\s*""(?<unit>.*)""\s+(?<receiverAll>.+)\s*";
            Regex  re               = new Regex(pattern);
            string name             = re.Match(strLine).Groups["name"].Value;
            string strMultiplexedID = re.Match(strLine).Groups["multiplexedID"].Value;
            int    iMultiplexedID   = -1;

            if (strMultiplexedID.Length > 0)
            {
                iMultiplexedID = int.Parse(strMultiplexedID.Trim().Substring(1));
            }
            string strMultiplexor = re.Match(strLine).Groups["multiplexor"].Value;
            bool   bMultiplexor   = strMultiplexor.Length > 0;
            string strStartBit    = re.Match(strLine).Groups["startBit"].Value;
            int    iStartBit      = int.Parse(strStartBit);
            string strLength      = re.Match(strLine).Groups["length"].Value;
            int    iLen           = int.Parse(strLength);
            string strByteOrder   = re.Match(strLine).Groups["byteOrder"].Value;
            bool   bIntelOrder    = strByteOrder.Contains("1");
            string strSign        = re.Match(strLine).Groups["sign"].Value;
            bool   bSigned        = strSign.Contains("-");
            string strFactor      = re.Match(strLine).Groups["factor"].Value;
            double dFactor        = double.Parse(strFactor);

            if (dFactor == 0)
            {
                throw new ApplicationException("Factor can not equal zero of signal: " + name);
            }
            string strOffset   = re.Match(strLine).Groups["offset"].Value;
            double dOffset     = double.Parse(strOffset);
            string strMinValue = re.Match(strLine).Groups["minValue"].Value;
            double dMinValue   = double.Parse(strMinValue);
            string strMaxValue = re.Match(strLine).Groups["maxValue"].Value;
            double dMaxValue   = double.Parse(strMaxValue);
            string unit        = re.Match(strLine).Groups["unit"].Value;
            string receiverAll = re.Match(strLine).Groups["receiverAll"].Value;

            string[] receivers = receiverAll.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            Signal signal = new Signal(
                name,
                iStartBit,
                iLen,
                bIntelOrder,
                bSigned,
                dFactor,
                dOffset,
                dMinValue,
                dMaxValue,
                unit,
                bMultiplexor,
                iMultiplexedID
                );

            foreach (string receiver in receivers)
            {
                signal.AddReceiver(_netWork.Nodes[receiver.Trim()]);
            }
            if (_mode.Value is Message message)
            {
                message.AddSignal(signal);
            }
            else
            {
                throw new ApplicationException("_mode.Value can not convert to Message");
            }
        }