/// <inheritdoc /> public override void StartDecode() { // TODO: This is a bit memory hungry, because all data gets read in first, but the implementation is only suited for statistical analysis now and // not for replaying large data sets. Can be improved later. MemoryStream ms = new MemoryStream(); foreach (var fileToRead in _filesToRead) { using (StreamReader sr = File.OpenText(fileToRead)) { string? line = sr.ReadLine(); Encoding raw = new Raw8BitEncoding(); while (line != null) { if (line.Contains("|")) { var splits = line.Split(new char[] { '|' }, StringSplitOptions.None); line = splits[2]; // Raw message } // Pack data into memory stream, from which the parser will get it again byte[] bytes = raw.GetBytes(line + "\r\n"); ms.Write(bytes, 0, bytes.Length); line = sr.ReadLine(); } } } ms.Position = 0; ManualResetEvent ev = new ManualResetEvent(false); var parser = new NmeaParser(InterfaceName, ms, null); parser.SuppressOutdatedMessages = false; // parse all incoming messages, ignoring any timing parser.OnNewSequence += ForwardDecoded; parser.OnParserError += (source, s, error) => { if (error == NmeaError.PortClosed) { ev.Set(); } }; parser.StartDecode(); ev.WaitOne(); // Wait for end of file parser.StopDecode(); ms.Dispose(); }
private void ConnectionWatcher() { while (!_terminated && _server != null) { try { var client = _server.AcceptTcpClient(); lock (_lock) { NmeaParser parser = new NmeaParser($"{InterfaceName}: {_activeParsers.Count}", client.GetStream(), client.GetStream()); parser.OnNewSequence += OnSentenceReceivedFromClient; parser.OnParserError += ParserOnParserError; parser.StartDecode(); _activeParsers.Add(parser); } } catch (SocketException) { // Ignore (probably going to close the socket) } } }