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

            // 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[1], out parsed);

            // We could extract the time
            if (timeMatch)
            {
                ret.Time = parsed;
            }

            /*/ 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[9];

            // 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 = 12; i < fields.Length; 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.StringToByteArrayFastest(rawDataString);
                ret.Message.RawData = candidateRawData;
            }
            catch (Exception)
            {
            }

            return(ret);
        }
Beispiel #3
0
 public override CAN.Message ParseLine(string line)
 {
     return(VehicleSpyLine.Parse(line).Message);
 }