public static String generate(InstrumentsData data) { string nmea = ""; if (data.Virtual != null && data.Virtual == true) { nmea += generateVirtualOriginSentences(); } if (data.Lat != null && data.Lon != null) { nmea += generatePositionSentence_GLL(data.Lat ?? 0, data.Lon ?? 0, data.FixQuality ?? FixQualityType.GPS); } if (data.Lat != null && data.Lon != null) { nmea += generatePositionSentence_GGA(data.Lat ?? 0, data.Lon ?? 0, data.FixQuality ?? FixQualityType.GPS, data.SatellitesCount ?? 4); } if (data.Heading != null && data.WaterSpeed != null) { nmea += generateSpeedAndHeadingSentence_VHW(data.WaterSpeed ?? 0, data.Heading ?? 0, data.MagneticHeading); } if (data.Heading != null) { nmea += generateTrueHeadingSentence_HDT(data.Heading ?? 0); } if (data.TrueWindAngle != null && data.TrueWindSpeed != null) { nmea += generateTrueWindSpeedAndAngleSentence_MWV(data.TrueWindAngle ?? 0, data.TrueWindSpeed ?? 0, data.FixQuality ?? FixQualityType.GPS); } if (data.ApparentWindAngle != null && data.ApparentWindSpeed != null) { nmea += generateApparentWindSpeedAndAngleSentence_MWV(data.ApparentWindAngle ?? 0, data.ApparentWindSpeed ?? 0, data.FixQuality ?? FixQualityType.GPS); } if (data.Depth != null && data.TransducerDepth != null) { nmea += generateDepthSentence_DPT(data.Depth ?? 0, data.TransducerDepth ?? 0); } if (data.Depth != null) { nmea += generateDepthSentence_DBT(data.Depth ?? 0); } if (data.CourseOverGround != null && data.SpeedOverGround != null) { nmea += generateSpeedAndCourseOverGroundSentence_VTG(data.SpeedOverGround ?? 0, data.CourseOverGround ?? 0, data.MagneticCourseOverGround); } if (data.Lat != null && data.Lon != null && data.SpeedOverGround != null && data.CourseOverGround != null) { nmea += generateRecommendedMinimumInformationSentence_RMC(data.Lat ?? 0, data.Lon ?? 0, data.SpeedOverGround ?? 0, data.CourseOverGround ?? 0, data.FixQuality ?? FixQualityType.GPS); } return(nmea); }
public NMEAServer(ref InstrumentsData instrumentsData, int port, Nullable <int> sendRateMs = null) { try { this.instrumentsData = instrumentsData; this.port = port; this.rateMs = sendRateMs; #pragma warning disable 612, 618 server = new TcpListener(port); OnServerStarted += NMEAServer_OnServerStarted; OnServerStop += NMEAServer_OnServerStop; OnServerError += NMEAServer_OnServerError; OnClientConnected += NMEAServer_OnClientConnected; OnNMEASent += NMEAServer_OnNMEASent; } catch (Exception e) { OnServerError(e); } }