Exemplo n.º 1
0
        public void Rmc()
        {
            var expected = new RMC("SN")
            {
                Status   = Flag.Active,
                Position = new Position()
                {
                    Latitude            = 49.01432,
                    LatitudeHemisphere  = NorthSouth.North,
                    Longitude           = 123.07771,
                    LongitudeHemisphere = EastWest.West,
                },
                SOG = 0.111,
                TMG = 200.928,
                // missing Magnetic Variation
                // missing Magnetic Variation sign
                // missing date and time
            };
            var actual = new RMC("SN", ",A,4900.8592,N,12304.6626,W,0.111,200.928,,0.000,".Split(','));

            Assert.InRange(actual.Position.Latitude, expected.Position.Latitude - .00001, expected.Position.Latitude + .00001);
            Assert.Equal(expected.ToString(), actual.ToString());

            actual = (RMC)MessageBase.Parse("$ECRMC,205351,A,4857.077,N,12303.894,W,4.389,182.020,030416,16.445,E*40");

            Assert.InRange(actual.MagneticVariation, 16.444999, 16.445001);

            // A different real life example. Time has two or three decimals, magnetic variation fields are missing and this is NMEA 2.3, with an extra field D or A.
            actual = (RMC)MessageBase.Parse("$GPRMC,222248.00,A,4857.49084,N,12302.35656,W,3.018,114.14,090416,,,D*7A");
            Assert.NotNull(actual);
        }
Exemplo n.º 2
0
        public void ShouldBeAbleToReadAllCommandsInFileWithoutException()
        {
            string line;

            // Read the file and display it line by line.
            System.IO.StreamReader file = new System.IO.StreamReader(@"..\..\..\doc\autopilot-sample.txt");

            int linenumber = 0;

            while ((line = file.ReadLine()) != null)
            {
                linenumber++;

                MessageBase message;

                if (line != @"$PSMDOV,1" && // Shipmodul overflow
                    !line.StartsWith("$,") && // nonsense I haven't figured out yet
                    !line.StartsWith("!AI") && // AIS stuff
                    !line.StartsWith("!") // weed out other garbage
                    )
                {
                    message = MessageBase.Parse(line);
                }
            }

            file.Close();
        }
        public MessageReader(string hostname, string exchange)
        {
            var factory = new ConnectionFactory()
            {
                HostName = hostname
            };

            _connection = factory.CreateConnection();
            _model      = _connection.CreateModel();

            _model.ExchangeDeclare(exchange, "fanout");

            var queueName = _model.QueueDeclare().QueueName;

            _model.QueueBind(queue: queueName, exchange: exchange, routingKey: string.Empty);

            _consumer = new EventingBasicConsumer(_model);

            _consumer.Received += (m, ea) =>
            {
                var line = Encoding.UTF8.GetString(ea.Body);
                try
                {
                    var message = MessageBase.Parse(line);
                    OnMessage(message, ea.BasicProperties.Timestamp.DateTime());
                }
                catch (FormatException x)
                {
                    Trace.WriteLine("Discarding message that can't be parsed. Exception was:");
                    Trace.WriteLine(x);
                }
            };

            _model.BasicConsume(queue: queueName, noAck: true, consumer: _consumer);
        }
Exemplo n.º 4
0
        public void Hdm()
        {
            var expected = new HDM("AP")
            {
                Heading = new MagneticMessageCompassValue(153.4),
            };
            var actual = (HDM)MessageBase.Parse("$APHDM,153.40,M*00");

            Assert.Equal(expected.Heading.Value, actual.Heading.Value);
            Assert.Equal(expected.Heading.IsMagnetic, actual.Heading.IsMagnetic);
            Assert.Equal(expected.GetType(), actual.GetType());
            Assert.Equal(expected.ToString(), actual.ToString());

            Assert.InRange(actual.Heading.Value, 153.399999, 153.400001);
        }
Exemplo n.º 5
0
 public void Gga()
 {
     var actual = MessageBase.Parse("$GPGGA,222247.00,4857.49115,N,12302.35773,W,2,12,0.67,-3.8,M,-17.7,M,,0000*47");
 }
Exemplo n.º 6
0
 public void Gll()
 {
     var actual = MessageBase.Parse("$GPGLL,4857.49115,N,12302.35773,W,222247.00,A,D*7C");
 }
Exemplo n.º 7
0
 public void Gbs()
 {
     var actual = MessageBase.Parse("$GPGBS,222247.00,2.0,1.5,2.7,,,,*41");
 }
Exemplo n.º 8
0
        static int Main(string[] args)
        {
            var commandName = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);

            if (args.Length != 1)
            {
                Console.Error.WriteLine(@"
  This program prints all messages coming in on an exchange to the console. 
  Messages that we can interpret are yelolow, others in red.

  Usage: {0} exchange

  Where:
   exchange is the name of a RabbitMQ exchange.

", commandName);
                Console.ReadKey();
                return(-1);
            }

            var exchange = args[0];

            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var model = connection.CreateModel())
                {
                    model.ExchangeDeclare(exchange, "fanout");
                    var queueName = model.QueueDeclare().QueueName;
                    model.QueueBind(queue: queueName, exchange: exchange, routingKey: string.Empty);

                    var consumer = new EventingBasicConsumer(model);
                    consumer.Received += (m, ea) =>
                    {
                        var line = Encoding.UTF8.GetString(ea.Body);

                        try
                        {
                            var message = MessageBase.Parse(line);
                            if (message is UnknownMessage)
                            {
                                Console.ForegroundColor = ConsoleColor.Magenta;
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Yellow;
                            }
                            Console.WriteLine(message.ToString());
                        }
                        catch (FormatException)
                        { // just skip non-NMEA messages, such as AIS
                            if (string.IsNullOrWhiteSpace(line) || line[0] == '$')
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine(line);
                            }
                        }
                    };

                    model.BasicConsume(queue: queueName, noAck: true, consumer: consumer);

                    Console.ReadLine();
                    return(0);
                }
        }