Ejemplo n.º 1
0
        public override IEnumerable <CAN.Message> ParseLines(IEnumerable <string> lines, IPluginLineFilterV1 filter = null)
        {
            foreach (var line in lines)
            {
                var parsedLine = KvaserTextLine.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;
        }
Ejemplo n.º 2
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 <KvaserTextLine> ParseLines(string[] lines, IPluginLineFilterV1 filter = null)
        {
            // first strip the header out

            var ret          = new List <KvaserTextLine>();
            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    = KvaserTextLine.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);
        }
Ejemplo n.º 3
0
        public static KvaserTextLine Parse(string line)
        {
            // 😢
            try
            {
                var ret = new KvaserTextLine();

                // split!
                var split       = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var numFields   = split.Length;
                var channel     = split[0];
                var arbIdString = split[1];
                var dlc         = split[2];
                var timeString  = split[numFields - 2];
                var data        = split.Skip(3).Take(numFields - 5);

                // Parse time first
                if (double.TryParse(timeString, out var timeSeconds))
                {
                    ret.Time = new DateTime().AddSeconds(timeSeconds);
                }

                // parse the arb id
                var candidateArbId = uint.Parse(arbIdString, System.Globalization.NumberStyles.HexNumber);
                ret.Message.ArbId = candidateArbId;

                // parse the raw data
                var candidateRawData = Utils.StringToByteArrayFastest(String.Join("", data));
                ret.Message.RawData = candidateRawData;

                return(ret);
            }
            catch (Exception)
            {
                return(null);
            }
            return(null);
        }
Ejemplo n.º 4
0
 public override CAN.Message ParseLine(string line)
 {
     return(KvaserTextLine.Parse(line).Message);
 }