예제 #1
0
        /// <summary>
        /// Constructs a message from a typed sentence
        /// </summary>
        /// <param name="sentence">Sentence to send. It must be valid</param>
        public TalkerSentence(NmeaSentence sentence)
        {
            TalkerId = sentence.TalkerId;
            Id       = sentence.SentenceId;
            var content = sentence.ToNmeaParameterList();

            if (string.IsNullOrWhiteSpace(content) || sentence.Valid == false)
            {
                throw new InvalidOperationException("Input sentence not valid or cannot be encoded");
            }

            _fields = content.Split(new char[] { ',' }, StringSplitOptions.None);
        }
예제 #2
0
        /// <inheritdoc />
        public override void SendSentence(NmeaSinkAndSource source, NmeaSentence sentence)
        {
            lock (_lock)
            {
                if (_textWriter != null && _logFile != null)
                {
                    // If talker and ID are the same, assume it's the same message
                    if (_lastSentence.SentenceId != sentence.SentenceId && _lastSentence.TalkerId != sentence.TalkerId)
                    {
                        string msg = FormattableString.Invariant(
                            $"{DateTime.UtcNow:s}|{source.InterfaceName}|${sentence.TalkerId}{sentence.SentenceId},{sentence.ToNmeaParameterList()}|{sentence.ToReadableContent()}");
                        _textWriter.WriteLine(msg);
                    }

                    if ((_logFile.Length > Configuration.MaxFileSize) && (Configuration.MaxFileSize != 0))
                    {
                        StartNewFile();
                    }

                    _lastSentence = sentence;
                }
            }
        }