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; } } }
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)); }
static AisMessage GetAisMsg(string nmea = "!BSVDO,1,1,,B,402M6C1vBvk<iOH79B`U@`?02<00,0*22") { return(AisDecoder.DecodeAis(AisDecoder.ParseNmea(nmea))); }