private void UpdatePosition() { if (mNMEAClient != null) { try { if ((mNMEAClient.Status & NMEAGPSClient.NMEAGPSClient.GPS_STATUS.Fix) == NMEAGPSClient.NMEAGPSClient.GPS_STATUS.Fix) { GPSPosition position = mNMEAClient.PositionInformation; mLocationMessage.SetLocation((uint)position.HorizontalErrorEstimate, position.CurrentPosition.Latitude, position.CurrentPosition.Longitude, position.SpeedOverGround); TrackingEvent tEv = (mNMEAClient.TravellingState == NMEAGPSClient.NMEAGPSClient.MovingState.Moving) ? TrackingEvent.POSITION_MOVING : TrackingEvent.POSITION_STATIONARY; StateMachine(tEv); } else { mLocationMessage.MessageId = (mNMEAClient.Status == NMEAGPSClient.NMEAGPSClient.GPS_STATUS.OFFLINE) ? RTTMesg.RTTOutMsgIds.GPSNone : RTTMesg.RTTOutMsgIds.GPSNoFix; StateMachine(TrackingEvent.LOST_GPS); //CNXLog.WarnFormat("Setting state for No Fix {0}", mMobileMessage);(mNMEAClient.Status == NMEAGPSClient.NMEAGPSClient.GPS_STATUS.OFFLINE) } } catch (Exception ex) { CNXLog.Error("TrackerState GPS position error {0}", ex); } } }
/// <summary> /// Create a GPS message /// </summary> /// <param name="error">Error estimation</param> /// <param name="alarmActive">Alarm state</param> /// <param name="latitude">Current latitude in WGS84 decimal degrees.</param> /// <param name="longitude">Current longitude in WGS84 decimal degrees.</param> /// <param name="velocity">Current horizontal velocity in meters/second.</param> /// <returns>GPS message</returns> /// <remarks> /// When the TrackingState is packed into a byte array to be used as an RTT message values may be truncated as follows: - /// Latitude/Longitude will be truncated to single presision floating point numbers. /// The error values is packed into 6 bits in 3 meter increments giving a maximum value of 208 meters. /// </remarks> public static RTTMesg CreateGPSFix(uint error, bool alarmActive, double latitude, double longitude, double velocity) { RTTMesg mesg = new RTTMesg(); mesg.SetLocation(error, latitude, longitude, velocity); mesg.mAlarm = alarmActive; return(mesg); }