Exemplo n.º 1
0
        public override IEnumerable <CAN.Message> ParseLines(IEnumerable <string> lines, IPluginLineFilterV1 filter = null)
        {
            foreach (var line in lines)
            {
                var parsedLine = SavvyLine.Parse(line);
                // If we have a problem with the parsed line, just forget about it
                if (parsedLine == null)
                {
                    continue;
                }

                // If we've got a filter
                if (filter != null)
                {
                    // use it
                    if (filter.ShouldAcceptLine(parsedLine.Message))
                    {
                        var parsedMessage = parsedLine.Message;
                        yield return(parsedMessage);
                    }
                    else
                    {
                        // This message didn't meet the filter
                        continue;
                    }
                }
                else
                {
                    // no filter, yield this element
                    yield return(parsedLine.Message);
                }
            }
            yield break;
        }
Exemplo n.º 2
0
 public override CAN.Message ParseLine(string line)
 {
     return(SavvyLine.Parse(line).Message);
 }
Exemplo n.º 3
0
        public static SavvyLine Parse(string line)
        {
            var       ret             = new SavvyLine();
            const int dataFrameIndex  = 6;
            const int fieldLen        = 0xE;
            const int arbIdFrameIndex = 1;
            const int dataFrameCount  = 5;

            //// Example Data Frame "7431355,000007E8,false,Rx,0,8,29,D8,59,81,8F,97,7B,D7,"
            // Parse time first
            var fields = line.Split(',');

            //Expect 14 Fields
            if (fields.Length < fieldLen) // probably not the line we want
            {
                return(ret);
            }

            //// Check to see if we are on the header
            //// "Time Stamp,ID,Extended,Dir,Bus,LEN,D1,D2,D3,D4,D5,D6,D7,D8"
            if (String.Compare(fields[0], "Time Stamp") == 0)
            {
                return(ret);
            }

            var timeMatch = timeRegex.Match(fields[0]);

            // We could extract the time
            if (timeMatch.Groups.Count == 2)
            {
                // extract the time
                var timeString = timeMatch.Groups[1].Value;

                // This is pretty fragile :<
                // Savvy Can Frames come in as Microseconds convert the to miliseconds
                ret.Time = new DateTime().AddMilliseconds(double.Parse(timeString) / 1000);
            }

            var arbIdString = fields[arbIdFrameIndex];

            // parse the arb id
            uint candidateArbId;
            bool arbIdMatch = uint.TryParse(arbIdString, System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture, out candidateArbId);

            // We could extract the arb id
            if (arbIdMatch)
            {
                ret.Message.ArbId = candidateArbId;
            }

            var  dataFrameString = fields[dataFrameCount];
            int  candidateFrameLen;
            bool dataFrameLenMatch = int.TryParse(dataFrameString, System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture, out candidateFrameLen);

            if (!(dataFrameLenMatch))
            {
                candidateFrameLen = 8;
            }

            // Now handle data
            StringBuilder sb = new StringBuilder();

            for (int i = dataFrameIndex; i < dataFrameIndex + candidateFrameLen; i++)
            {
                sb.Append(fields[i]);
            }

            // extract the raw data
            var rawDataString = sb.ToString();

            // parse the raw data
            // TODO: Better error handling. This fails on metadata lines
            try
            {
                var candidateRawData = Utils.StringToByteArray(rawDataString);
                ret.Message.RawData = candidateRawData;
            }
            catch (Exception)
            {
            }

            return(ret);
        }