Exemplo n.º 1
0
        private void GPSPositionChangedEventHandler(object sender, EventArgs e)
        {
            try
            {
                NMEAGPSClient.NMEAGPSClient.GPSPositionEvent gpsPosition = (NMEAGPSClient.NMEAGPSClient.GPSPositionEvent)e;
                GPSPosition position = gpsPosition.Position;
                NMEAGPSClient.NMEAGPSClient nmeaClient = (NMEAGPSClient.NMEAGPSClient)sender;
                // make sure we have valid data
                byte gpsState = (byte)position.NMEAMode;
                if (position.HorizontalErrorEstimate > TrackingService.DefaultAcceptableError)
                {
                    gpsState &= 0xfe;
                }

                // publish the new position to CAN clients.
                CANFrame frame = CNXCANMsgHelper.PackGPSFrame(gpsState, position.CurrentPosition.Latitude, position.CurrentPosition.Longitude, position.SpeedOverGround);
                int      count = mCANClient.Send(frame);

                if ((gpsState == (byte)CANGPSState.GoodFix) || (gpsState == (byte)CANGPSState.PoorFix))
                {
                    // publish the new time.
                    frame = CNXCANMsgHelper.PackDateTime(position.TimeStamp);
                    count = mCANClient.Send(frame);
                }

                CNXLog.Debug("GPSPositionChangedEventHandler");
            }
            catch (Exception ex)
            {
                CNXLog.Error("CAN GPSPositionChangedEventHandler", ex);
            }
        }
Exemplo n.º 2
0
        private void GPSStatusChangedEventHandler(object sender, EventArgs e)
        {
            NMEAGPSClient.NMEAGPSClient.GPSStatusEvent gpsStatus = (NMEAGPSClient.NMEAGPSClient.GPSStatusEvent)e;
            mGPSStatus = gpsStatus.Status;
            if (mGPSStatus < NMEAGPSClient.NMEAGPSClient.GPS_STATUS.Fix)
            {
                GPSPosition.Position position = ((NMEAGPSClient.NMEAGPSClient)sender).Position;
                // publish the new position to CAN clients.
                CANFrame frame = CNXCANMsgHelper.PackGPSFrame((byte)mGPSStatus, position.Latitude, position.Longitude, 0);
                int      count = mCANClient.Send(frame);
            }

            CNXLog.Debug("GPSStatusChangedEventHandler");
        }