Exemplo n.º 1
0
        /// design

        /// this object in instantiated on startup and the controller thread starts
        ///
        /// if the initial config is either un-configured or USE_NONE for GPS mode,
        /// the thread will do nothing but loop on the use mode flags. A call to LoadGPSConfiguration() will
        ///  cause the flags to change and the operation of the loop to change.

        public GPSController(PutNewGPSData putNewGPSData, APPLICATION_DATA appData)
        {
            m_putNewGPSData = putNewGPSData;

            m_AppData = appData;
            m_AppData.AddOnClosing(Close, APPLICATION_DATA.CLOSE_ORDER.FIRST);
            m_Log = (ErrorLog)m_AppData.Logger;

            m_FixedSiteCoordiates = new GPSDev.GPSInfo();

            m_CurrentLocationInfo = new GPSDev.GPSInfo();

            // load any static/stored positions in case a GPS device is not found
            m_GPSUseModes = GPS_USE_MODES.USE_FIXED;

            LoadGPSConfiguration();

            // start a new thread
            m_PollForDataThread = new Thread(Poller);
            m_PollForDataThread.Start();
        }
Exemplo n.º 2
0
        public string GetLocation(out GPSDev.GPSInfo info)
        {
            string l = null;

            if (m_GPSUseModes == GPS_USE_MODES.USE_RECEIVER)
            {
                lock (m_CurrentLocationInfo)
                {
                    info = m_CurrentLocationInfo.Clone();
                }
            }
            else
            {
                lock (m_FixedSiteCoordiates)
                {
                    info = m_FixedSiteCoordiates.Clone();
                }
            }

            return(l);
        }
Exemplo n.º 3
0
        void Poller()
        {
            GPSDev.GPSInfo gpsInfo = null;

            while (!m_Stop)
            {
                Thread.Sleep(m_PollLoopSleepTime);


                // do we have a comm port?
                if (m_FixedCommPort == null)
                {
                    m_FixedCommPort = FindDevicePort.GetGPSCommPort();
                    // may still be null if there is no device
                }

                if (m_ResetGPSDriver)
                {
                    // lost the device connection, start over
                    if (m_GPSDevice != null)
                    {
                        m_GPSDevice.Close();
                    }
                    m_FixedCommPort  = null; // start over, perhaps the user moved the receiver to another port
                    m_GPSDevice      = null;
                    m_ResetGPSDriver = false;

                    m_Log.Log("lost GPS Device connection", ErrorLog.LOG_TYPE.FATAL);
                    m_GPSUseModes = GPS_USE_MODES.USE_FIXED;

                    LoadGPSConfiguration();// re-load the static configuration if one is there
                }

                if (m_FixedCommPort != null)
                {
                    // we have found a comm, port, try it....

                    // do we have a device opened ?
                    if (m_GPSDevice == null && !m_Stop)
                    {
                        m_GPSDevice = new GPSDev(m_FixedCommPort, HandleLostGPSDeviceConnection, m_AppData);
                    }

                    if (m_GPSDevice == null && m_Stop)
                    {
                        break;
                    }

                    if (!m_GPSDevice.OpenSucess)
                    {
                        m_GPSDevice.Close();
                        m_GPSDevice = null;
                        continue;// try again next time around
                    }
                    else
                    {
                        if (m_ReceiverDetected == false)
                        {
                            m_Log.Log("connected to GPS Device", ErrorLog.LOG_TYPE.FATAL);
                        }

                        m_ReceiverDetected = true;
                        m_GPSUseModes      = GPS_USE_MODES.USE_RECEIVER;

                        // everything is working fine, get the latest available sat data

                        m_GPSDevice.GetLocation(out gpsInfo);

                        lock (m_CurrentLocationInfo)
                        {
                            m_CurrentLocationInfo = gpsInfo.Clone();
                        }

                        BuildURL(gpsInfo.Latitude, gpsInfo.Longitude, m_googleString);
                    }
                }


                if (m_GPSUseModes == GPS_USE_MODES.USE_RECEIVER)
                {
                    m_putNewGPSData(gpsInfo.CleanPositionString, gpsInfo.DetectedReceiver, gpsInfo.HaveSatData);
                }
                else if (m_GPSUseModes == GPS_USE_MODES.USE_FIXED)
                {
                    m_putNewGPSData(m_FixedSiteCoordiates.CleanPositionString, m_FixedSiteCoordiates.DetectedReceiver, m_FixedSiteCoordiates.HaveSatData);
                }
                else if (m_GPSUseModes == GPS_USE_MODES.USE_NONE)
                {
                    m_putNewGPSData("no position avaialbe", false, false);
                }
            }// end while (! stop)



            if (m_GPSDevice != null)
            {
                m_GPSDevice.Close();
                m_GPSDevice = null;
            }
        }