Example #1
0
        public override IEnumerable <CAN.Message> ParseLines(IEnumerable <string> lines, IPluginLineFilterV1 filter = null)
        {
            foreach (var line in lines)
            {
                var parsedLine = KvaserLine.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;
        }
Example #2
0
        public static KvaserLine Parse(string line)
        {
            var ret = new KvaserLine();

            // Parse time first
            var timeMatch = timeRegex.Match(line);

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

                // This is pretty fragile :<
                ret.Time = new DateTime().AddSeconds(double.Parse(timeString));
            }

            /*/ No support at the moment
             *          // Now get the interface name assuming the interface is of the form " [v]<can><0-9> " (note the spaces)
             *          var interfaceMatch = Regex.Match(line, @" (v?can[0-9]) ");
             *          if (interfaceMatch.Groups.Count == 2)
             *          {
             *                  ret.Interface = interfaceMatch.Groups[1].Value;
             *          }
             * //*/

            // Parse id first
            var arbIdMatcher = idRegex.Match(line);

            // We could extract the arb id
            if (arbIdMatcher.Groups.Count == 2)
            {
                // extract the arb id
                var arbIdString = arbIdMatcher.Groups[1].Value;
                // parse the arb id
                var candidateArbId = uint.Parse(arbIdString, System.Globalization.NumberStyles.HexNumber);
                ret.Message.ArbId = candidateArbId;
            }


            // Now handle data (only 8 byte packets at the moment)
            var rawDataMatcher = rawDataRegex.Match(line);

            // We could extract the raw data
            if (rawDataMatcher.Groups.Count >= 2)
            {
                // extract the raw data
                var rawDataString = rawDataMatcher.Groups[1].Value.Replace(" ", "");
                // parse the raw data
                var candidateRawData = Utils.StringToByteArrayFastest(rawDataString);
                ret.Message.RawData = candidateRawData;
            }
            else
            {
            }

            return(ret);
        }
Example #3
0
        /*/ Unused currently
         *      public static async Task<List<KvaserLine>> ParseStream(Stream s)
         *      {
         *              var ret = new List<KvaserLine>();
         *
         *              var streamLength = s.Length;
         *              using (StreamReader sr = new StreamReader(s))
         *              {
         *                      while (!sr.EndOfStream)
         *                      {
         *                              var progress = ((double)sr.BaseStream.Position / (double)sr.BaseStream.Length) * 100.0d;
         *                              var currentLineStr = await sr.ReadLineAsync();
         *                              var currentLine = KvaserLine.Parse(currentLineStr);
         *                              Debug.WriteLine(currentLine);
         *                              ret.Add(currentLine);
         *                      }
         *              }
         *
         *              return ret;
         *      }
         * //*/

        public static List <KvaserLine> ParseLines(string[] lines, IPluginLineFilterV1 filter = null)
        {
            // first strip the header out
            StripHeader(ref lines);

            var ret          = new List <KvaserLine>();
            var pastProgress = 0;

            for (int i = 0; i < lines.Length; i++)
            {
                var curProgress = ((i * 100) / lines.Length);
                if (curProgress != pastProgress)
                {
                    pastProgress = curProgress;
                    //Debug.WriteLine(curProgress);
                }

                var currentLineStr = lines[i];
                var currentLine    = KvaserLine.Parse(currentLineStr);
                if (currentLine.Message != null)
                {
                    if (filter != null)
                    {
                        if (filter.ShouldAcceptLine(currentLine.Message))
                        {
                            ret.Add(currentLine);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        // we have no filter, accept all
                        ret.Add(currentLine);
                    }
                }
            }

            return(ret);
        }
Example #4
0
 public override CAN.Message ParseLine(string line)
 {
     return(KvaserLine.Parse(line).Message);
 }