Ejemplo n.º 1
0
        private static void Run()
        {
            var aisDecoder = new AisDecoder();

            TcpClient     client        = new TcpClient("153.44.253.27", 5631);
            NetworkStream networkStream = client.GetStream();
            StreamReader  reader        = new StreamReader(networkStream);

            while (true)
            {
                var    nmeaList   = new List <NmeaMessage>();
                string nmeaString = reader.ReadLine();
                var    nmeaMsg    = aisDecoder.GetNmeaMessage(nmeaString);

                nmeaList.Add(nmeaMsg);

                while (nmeaMsg.NumberOfSentences > 1 && nmeaMsg.SentenceNumber != nmeaMsg.NumberOfSentences)
                {
                    nmeaString = reader.ReadLine();
                    nmeaMsg    = aisDecoder.GetNmeaMessage(nmeaString);
                    nmeaList.Add(nmeaMsg);
                }

                var msg = aisDecoder.GetAisMessage(nmeaList);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(msg.ToString());
            }
        }
Ejemplo n.º 2
0
        static AisMessage GetAisMsg(string aisstring = "!AIVDM,1,1,,A,14eG;o@034o8sd<L9i:a;WF>062D,0*7D")
        {
            var aisDecoder = new AisDecoder();
            var nmea       = aisDecoder.GetNmeaMessage(aisstring);

            return(aisDecoder.GetAisMessage(nmea));
        }
Ejemplo n.º 3
0
        private static void Run()
        {
            Console.ForegroundColor = ConsoleColor.Green;

            TcpClient     client        = new TcpClient("153.44.253.27", 5631);
            NetworkStream networkStream = client.GetStream();
            StreamReader  reader        = new StreamReader(networkStream);

            var nmeaList = new List <NmeaMessage>();

            while (true)
            {
                string nmeaString = reader.ReadLine();

                try
                {
                    NmeaMessage nmeaMsg = AisDecoder.ParseNmea(nmeaString);
                    nmeaList.Add(nmeaMsg);

                    if (nmeaMsg.SentenceNumber == nmeaMsg.NumberOfSentences)
                    {
                        var aisMsg = AisDecoder.DecodeAis(nmeaList);
                        Console.WriteLine(aisMsg.ToString());
                        nmeaList.Clear();
                    }
                }
                catch (InvalidNmeaException e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine(e.Message);
                    Console.ForegroundColor = ConsoleColor.Green;
                }
            }
        }
Ejemplo n.º 4
0
        public static void StartListener(int port)
        {
            UdpClient  listener   = new UdpClient(port);
            IPEndPoint groupEP    = new IPEndPoint(IPAddress.Any, port);
            var        aisDecoder = new AisDecoder();

            try
            {
                while (true)
                {
                    //Console.WriteLine("Waiting for broadcast");
                    var    nmeaList   = new List <NmeaMessage>();
                    byte[] bytes      = listener.Receive(ref groupEP);
                    var    nmeaString = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
                    var    nmeaMsg    = aisDecoder.GetNmeaMessage(nmeaString);

                    nmeaList.Add(nmeaMsg);
                    while (nmeaMsg.NumberOfSentences > 1 && nmeaMsg.SentenceNumber != nmeaMsg.NumberOfSentences)
                    {
                        bytes      = listener.Receive(ref groupEP);
                        nmeaString = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
                        nmeaMsg    = aisDecoder.GetNmeaMessage(nmeaString);
                        nmeaList.Add(nmeaMsg);
                    }

                    var msg = aisDecoder.GetAisMessage(nmeaList);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(msg.ToString());
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                listener.Close();
            }
        }
Ejemplo n.º 5
0
        static AisMessage GetAisMsg(string aisstring = "!AIVDM,1,1,,A,14eG;o@034o8sd<L9i:a;WF>062D,0*7D")
        {
            var nmea = AisDecoder.ParseNmea(aisstring);

            return(AisDecoder.DecodeAis(nmea));
        }
Ejemplo n.º 6
0
 static AisMessage GetAisMsg(string nmea = "!BSVDO,1,1,,B,402M6C1vBvk<iOH79B`U@`?02<00,0*22")
 {
     return(AisDecoder.DecodeAis(AisDecoder.ParseNmea(nmea)));
 }