public override IEnumerable <CAN.Message> ParseLines(IEnumerable <string> lines, IPluginLineFilterV1 filter = null) { foreach (var line in lines) { var parsedLine = KvaserCsvLine.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; }
public override CAN.Message ParseLine(string line) { return(KvaserCsvLine.Parse(line).Message); }
public static KvaserCsvLine Parse(string line) { var ret = new KvaserCsvLine(); // Parse time first // TODO: maybe directly parse datetime var fields = line.Split(','); if (fields.Length < 9) // probably not the line we want { // should we return null? return(ret); } //// We aren't using C#7's fancy out variable declaration //// because it isn't compatible with edit and continue. //// This is something that can be added as this plugin nears completion since it saves lines of code. //DateTime parsed; //var timeMatch = DateTime.TryParse(fields[0], out parsed); //// We could extract the time //if (timeMatch) //{ // ret.Time = parsed; //} 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 :< 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; * } * //*/ // extract the arb id var arbIdString = fields[2]; // 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; } // Now handle data (only 8 byte packets at the moment) StringBuilder sb = new StringBuilder(); for (int i = 5; i < 5 + 8; 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); }