public void OnGPSChangedEventHandler(object o, EventArgs e) { NMEAGPSClient.NMEAGPSClient gpsClient = (NMEAGPSClient.NMEAGPSClient)o; try { // work out what needs changing //CNXLog.InfoFormat("APCWrapper GPS {0}", gpsClient.Status); //CNXLog.InfoFormat("APCWrapper GPS {0} {1}", gpsClient.Status, ((gpsClient.Status & NMEAGPSClient.NMEAGPSClient.GPS_STATUS.Fix) == NMEAGPSClient.NMEAGPSClient.GPS_STATUS.Fix)); if ((gpsClient.Status & NMEAGPSClient.NMEAGPSClient.GPS_STATUS.Fix) == NMEAGPSClient.NMEAGPSClient.GPS_STATUS.Fix) { if (gpsClient.PositionInformation.NMEAMode == GPSPosition.NMEAMODE.TWO_DIMENSION || gpsClient.PositionInformation.NMEAMode == GPSPosition.NMEAMODE.THREE_DIMENSION) { bool moving = (gpsClient.TravellingState == NMEAGPSClient.NMEAGPSClient.MovingState.Moving); mAPCDataSet.UpdatePosition(gpsClient.Position.Latitude, gpsClient.Position.Longitude, moving, gpsClient.PositionInformation.TimeStamp); } else { mAPCDataSet.NoGPS(); } } else { // nothing mAPCDataSet.NoGPS(); } } catch (Exception ex) { CNXLog.Error(string.Format("APC UpdatePosition error {0}", gpsClient.ToString()), ex); } }
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); } }
public TrackingStateManager(CommsServer commsServer, NMEAGPSClient.NMEAGPSClient gpsClient) { mCommsServer = commsServer; mNMEAClient = gpsClient; mNMEAClient.RaiseGPSPositionChangedEvent += this.OnGPSPositionChangedEventHandler; mNMEAClient.RaiseGPSStatusChangedEvent += this.OnGPSStateChangedEventHandler; // set the initial position // initialise the timer mTimer = new Timer(new TimerCallback(OnTimedEvent), null, TrackingService.MovingRate * 1000, TrackingService.MovingRate * 1000); }
public CANCommsServer(CANClient client, NMEAGPSClient.NMEAGPSClient gpsClient) { mCANClient = client; mGpsClient = gpsClient; // make a device catalogue mDeviceCatalogue = CreateCatalogue(TrackingService.VarPath + mCatalogueFilename); // start time for cataloge and status reporting mCatalogueTimer = new Timer(OnTimedEvent, null, CatalogueTime, CatalogueTime); // subscribe to gps events mGpsClient.RaiseGPSPositionChangedEvent += GPSPositionChangedEventHandler; // get the current gps status mGPSStatus = mGpsClient.Status; mGpsClient.RaiseGPSStatusChangedEvent += GPSStatusChangedEventHandler; // subscribe to CAN frame events mCANClient.RaiseFrameReceivedEvent += FrameReceivedEventHandler; }
/// <summary> /// Deals with changes of GPS position /// </summary> /// <param name="o">Event source object.</param> /// <param name="e">Event Parmeters</param> public void OnGPSPositionChangedEventHandler(object o, EventArgs e) { //mNMEAClient = (NMEAGPSClient.NMEAGPSClient)o; //mNMEAClient.RaiseGPSPositionChangedEvent -= this.OnGPSPositionChangedEventHandler; try { NMEAGPSClient.NMEAGPSClient client = (NMEAGPSClient.NMEAGPSClient)o; if (client.TravellingState == NMEAGPSClient.NMEAGPSClient.MovingState.Moving) { mBeenMoving = true; } //GPSPosition position = ((NMEAGPSClient.NMEAGPSClient.GPSPositionEvent)e).Position; //// set the mew position //mMobileMessage.TrackingState.SetLocation(position.CurrentPosition.Latitude, position.CurrentPosition.Longitude, position.SpeedOverGround, (uint)position.HorizontalErrorEstimate); //TrackingEvent tEv = (client.TravellingState == NMEAGPSClient.NMEAGPSClient.MovingState.Moving) ? TrackingEvent.POSITION_MOVING : TrackingEvent.POSITION_STATIONARY; //mPositionEvt = tEv; //StateMachine(tEv); } catch (Exception ex) { CNXLog.Error("TrackerState GPS position error {0}", ex); } }
private void StartListeningToGPS() { mGPSClient = new NMEA0183ServiceReciever(); mGPSClient.MovingThreshold = mMovingThreshold; }