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)); }
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()); } }
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(); } }