Exemplo n.º 1
0
        public Vehicle(bool fFerry = false)
        {
            VehicleinfoLoad();

            foreach (Resource res in Enum.GetValues(typeof(Resource)))
            {
                XmlDocument doc     = new XmlDocument();
                string      strPath = cCNXPath + res.ToString() + ".xml";
                if (File.Exists(strPath))
                {
                    doc.Load(strPath);
                    switch (res)
                    {
                    case Resource.DriverConfig:
                        m_configD = new DriverConfig(doc);
                        break;

                    case Resource.RoutePatternForVehicle:
                        m_configRP = new RoutePatternConfig(doc);
                        break;

                    case Resource.ServiceAlertForVehicle:
                        m_configSA = new ServiceAlertConfig(doc);
                        break;

                    case Resource.VehicleConfig:
                        m_configV = new VehicleConfig(doc);
                        break;
                    }
                }

                switch (res)
                {
                case Resource.DriverConfig:
                    break;

                case Resource.RoutePatternForVehicle:
                    break;

                case Resource.ServiceAlertForVehicle:
                    break;

                case Resource.VehicleConfig:
                    m_nRouteNoFmt          = m_configV.RouteNoFmt;
                    m_strNSDStopping       = m_configV.NSDStopping;
                    m_strNSDStoppingConcat = m_configV.NSDStoppingConcat;
                    break;
                }
            }

            m_fFerry = fFerry;
        }
Exemplo n.º 2
0
        private void OnTripStatus(object parm)
        {
            Debug.WriteLine(string.Format("{0} {1}", DateTime.Now.ToString("HH:mm:ss.fff"), "OnTripStatus"));

            RoutePatternConfig configRP = null;
            ServiceAlertConfig configSA = null;
            VehicleConfig      configV  = null;

            Interlocked.Exchange <RoutePatternConfig>(ref configRP, m_configRP);
            Interlocked.Exchange <ServiceAlertConfig>(ref configSA, m_configSA);
            Interlocked.Exchange <VehicleConfig>(ref configV, m_configV);

            bool       bContinue = true, bDispose = false;
            Trip       trip = null;
            TripStatus ts = (TripStatus)parm;
            Timeout    timeoutFix = new Timeout(TimeSpan.FromMinutes(2)), timeoutOnRoute = new Timeout(TimeSpan.FromSeconds(500));

            do
            {
                if (ts != null)
                {
                    if (ts.NoTrip)
                    {
                        trip = null;
                    }
                    else if (!ts.OffRoute)
                    {
                        timeoutOnRoute.Reset();
                        if (trip == null || ts.RouteTag != trip.RouteTag || ts.RP < trip.RP || ts.TripNo != trip.TripNo || ts.ServiceStart != trip.ServiceStart)
                        {
                            trip = Trip.Create(this, ts.RouteTag, ts.RP, ts.TripNo, ts.ServiceStart, m_configRP, m_configSA, m_configV, m_fFerry);
                        }
                        else
                        {
                            trip.ProgressRP(ts.RP);
                        }

                        EnableSignalPriority(ts.SignalPriority);
                    }
                    else if (trip != null)
                    {
                        trip.OffRoute = true;
                        EnableSignalPriority(false);
                    }
                }

                if (trip != null)
                {
                    GPSFix fix = m_Fix;

                    bool bEndTrip = false;
                    if (timeoutOnRoute.HasExpired)
                    {
                        bEndTrip = true;
                    }
                    else if (fix == null || !UTM.IsValidLL4Zone(configV.UTMZoneNo, configV.UTMZoneLetter, fix.Lat, fix.Long))
                    {
                        bEndTrip = timeoutFix.HasExpired;
                    }
                    else
                    {
                        timeoutFix.Reset();
                        //if( m_fFerry || !trip.OffRoute )
                        //	bEndTrip = !trip.UpdatePosition( UTM.LL2UTM( configV.UTMZoneNo, fix.Lat, fix.Long ), fix.Speed, fix.SpeedWeighted );
                    }

                    if (bEndTrip)
                    {
                        trip = null;
                    }
                    else
                    {
                        Thread.Sleep(999);
                    }
                }

                lock ( m_qTS )
                {
                    if (m_qTS.Count == 0)
                    {
                        ts = null;
                    }
                    else
                    {
                        ts = m_qTS.Dequeue();
                        if (ts == null)
                        {
                            bDispose = true;
                        }
                    }

                    if (bDispose || (trip == null && ts == null))
                    {
                        bContinue = m_bTSThreadPoolActive = false;
                    }
                }
            }while(bContinue);

            if (!bDispose)
            {
                QueueRequest(new RequestEventArgs(RequestType.DisplayNextStop, null));
                QueueRequest(new RequestEventArgs(RequestType.DisplayNextStopExtra, null));
                if (configV.HeadSignDefault != null)
                {
                    QueueRequest(new RequestEventArgs(RequestType.HeadSign, configV.HeadSignDefault));
                }
                EnableSignalPriority(false);
            }
        }