private void timerCallback(object state) { try { string line; if (state is string) { line = state as string; } else { line = inputStream.ReadLine(); } if (inputStream.EndOfStream) { run = false; } if (logParser != null) { line = logParser.ParseLine(line); } if (line == null) { return; } bool knownPacket; parser.Parse(line + "\n", 0, out knownPacket); if (exclude_unknownPackets) { if (!knownPacket) { return; } } string s; if (line.Length > 21) { s = line.Substring(0, 21); } else { s = line; } for (int i = 3; i < s.Length; i += 3) { s = s.Insert(i, " "); } string p = ""; if (s.Length > 3) { p = s.Substring(0, 3); } uint pac; if (s.StartsWith("508")) { Dispatcher.Invoke(() => { StringBuilder vin = new StringBuilder(KeywordTextBox.Text); if (vin.Length < 17) { vin = new StringBuilder("VIN".PadRight(17)); } int temp, idx; int.TryParse(s.Substring(4, 2), System.Globalization.NumberStyles.HexNumber, null, out idx); for (int i = 7; i < s.Length; i += 3) { if (int.TryParse(s.Substring(i, 2), System.Globalization.NumberStyles.HexNumber, null, out temp)) { if (temp != 0) { vin[idx * 7 + (i / 3) - 2] = (char)temp; } } } KeywordTextBox.Text = vin.ToString(); }); } if (s.StartsWith("542") || s.StartsWith("552")) { Dispatcher.Invoke(() => { StringBuilder vin = new StringBuilder(" ".PadLeft(16)); int temp, idx; idx = s.StartsWith("542") ? 0 : 8; for (int i = 4; i < s.Length; i += 3) { if (int.TryParse(s.Substring(i, 2), System.Globalization.NumberStyles.HexNumber, null, out temp)) { if (temp != 0) { batterySerial[idx * 8 + (i / 3) - 1] = (char)temp; } } } BatterySerialBox.Text = new string(batterySerial.Values.ToArray()); }); } if (s.StartsWith("558")) { Dispatcher.Invoke(() => { StringBuilder vin = new StringBuilder(" ".PadLeft(8)); int temp; for (int i = 4; i < s.Length; i += 3) { if (int.TryParse(s.Substring(i, 2), System.Globalization.NumberStyles.HexNumber, null, out temp)) { if (temp != 0) { vin[(i / 3) - 1] = (char)temp; } } } FirmwareBox.Text = vin.ToString(); }); } if (uint.TryParse(p, System.Globalization.NumberStyles.HexNumber, null, out pac)) { var l = runningTasks.Where(x => x.Str.StartsWith(p)).FirstOrDefault(); if (l == null) { Dispatcher.Invoke(() => runningTasks.Add(new StringWithNotify(pac, s, parser, this))); } else { l.Str = s; } if (l != null) { l.Used = parser.items.Any(x => x.Value.packetId == pac); l.Count++; string desc = ""; int counter = 0; foreach (var item in parser.items.Where(x => x.Value.packetId == pac)) { counter++; if (counter > 4) { break; } desc += item.Value.name + ":" + item.Value.GetValue(false) + " "; } l.Verbose = desc; } if (pac == packet) { if (prevBitsUpdate < stopwatch.ElapsedMilliseconds) { Dispatcher.BeginInvoke((Action)(() => { updateBits((StringWithNotify)PathList.SelectedItem, s); })); prevBitsUpdate = stopwatch.ElapsedMilliseconds + 100; } } if (prevUpdate < stopwatch.ElapsedMilliseconds) { Dispatcher.BeginInvoke((Action)(() => { //Graph.ResetAllAxes(); //Graph.ActualModel.ResetAllAxes(); Graph.InvalidatePlot(true); //Graph.ResetAllAxes(); //Graph.ResetAllAxes(); })); prevUpdate = stopwatch.ElapsedMilliseconds + 1000; } } } catch (Exception e) { Console.WriteLine(e.Message); } }
private void timerCallback(object state) { try { string line; string timestamp = null; line = inputStream.ReadLine(); if (inputStream.EndOfStream) { run = false; } if (logParser != null) { line = logParser.ParseLine(line, out timestamp); } if (line == null) { return; } bool knownPacket; parser.Parse(line + "\n", 0, timestamp, out knownPacket); int idLength = line.IndexOf(" ", 0); string s; s = line; int busLength = line.IndexOf(" ", idLength + 1) - idLength - 1; int bus = int.Parse(line.Substring(idLength + 1, busLength)); for (int i = idLength + 1 + busLength + 1 + 2; i < s.Length; i += 3) { s = s.Insert(i, " "); } string p = ""; p = line.Substring(0, idLength); uint pac; if (uint.TryParse(p, System.Globalization.NumberStyles.HexNumber, null, out pac)) { var l = runningTasks.Where(x => x.Str.StartsWith(s.Substring(0, idLength + 1 + busLength + 1))).FirstOrDefault(); if (l == null) { Dispatcher.Invoke(() => runningTasks.Add(new StringWithNotify(pac, s, parser, this))); } else { l.Str = s; } if (l != null) { l.Used = parser.items.Any(x => x.Value.packetId == pac); l.Count++; string desc = ""; int counter = 0; if (parser.packetTitles != null) { if (parser.packetTitles.ContainsKey((int)pac)) { if (string.IsNullOrEmpty(l.Verbose)) { l.Verbose = parser.packetTitles[(int)pac]; } } else { foreach (var item in parser.items.Where(x => x.Value.packetId == pac && (x.Value.bus == bus || x.Value.bus == -1))) { counter++; if (counter > 1) { break; } desc += item.Value.messageName; } l.Verbose = desc; } } } if (prevUpdate < stopwatch.ElapsedMilliseconds) { Dispatcher.BeginInvoke((Action)(() => { Graph.InvalidatePlot(true); })); prevUpdate = stopwatch.ElapsedMilliseconds + 1000; } } } catch (Exception e) { Console.WriteLine(e.Message); } }