Exemplo n.º 1
0
        public virtual void ReadStartMessage()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(NmeaReader));
            }

            if (_state != NmeaReadState.None)
            {
                throw new InvalidOperationException();
            }

            int start = _input.ReadByte();

            while ((start = _input.ReadByte()) != 36 /*$*/)
            {
            }
            _state = NmeaReadState.StartMessage;
        }
Exemplo n.º 2
0
        private string ReadAddressCore(out byte checksum)
        {
            if (_state != NmeaReadState.StartMessage)
            {
                throw new InvalidOperationException();
            }

            var sb = new StringBuilder();
            int b;

            checksum = 0x0;

            while ((b = _input.ReadByte()) != 44 /*comma*/)
            {
                sb.Append((char)b);
                checksum ^= (byte)b;
            }

            _state = NmeaReadState.Address;
            return(sb.ToString());
        }
Exemplo n.º 3
0
        private string ReadDataCore(out byte checksum)
        {
            if (_state != NmeaReadState.Address)
            {
                throw new InvalidOperationException();
            }

            var sb = new StringBuilder();
            int b;

            checksum = 0x0;

            while ((b = _input.ReadByte()) != 0x2a /*asterisk*/)
            {
                sb.Append((char)b);
                checksum ^= (byte)b;
            }

            _state = NmeaReadState.Data;
            return(sb.ToString());
        }
Exemplo n.º 4
0
        private void ReadEndMessageCore(out int checksum)
        {
            if (_state != NmeaReadState.Data)
            {
                throw new InvalidOperationException();
            }

            var buffer = new byte[2];

            _input.Read(buffer, 0, 2);

            string checksumString = new string(new[] { (char)buffer[0], (char)buffer[1] });

            if (!int.TryParse(checksumString, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out checksum))
            {
                _state = NmeaReadState.None;
                throw new InvalidDataException();
            }

            int cr = _input.ReadByte();

            if (cr != 13 /*CR*/)
            {
                _state = NmeaReadState.None;
                throw new InvalidDataException();
            }

            int LF = _input.ReadByte();

            if (LF != 10 /*LF*/)
            {
                _state = NmeaReadState.None;
                throw new InvalidDataException();
            }

            _state = NmeaReadState.None;
        }