Example #1
0
        public NavInterfaceMBed(LogFile _logFile, SettingsManager Settings)
        {
            logFile = _logFile;  //file where we write the mbed navigation data and status message

            //Thread reader/writer lock to prevent clobbering the posvel variable while it is being accessed
            posvelLock = new ReaderWriterLockSlim();
            comStatusMessageLock = new ReaderWriterLockSlim();

            triggerTimeReceievdFromMbed = false;  //set to true when we receive a 1PPS status message
            //reset to false in the calling program when the status message is processed

            //used to store the CRC results fpr the GPS messages received at the PC
            GPS_PC_CRC = new GPSMessageCRC_atPC();
            trigger = new Trigger();

            computeCRC = new NovatelCRC();  //class to compute the Novatel CRC value (see their manual)

            comStats = new CommStats();     //accumulated comm stats
            commStatusMessage = new CommStatusMessage(); //per sec comm status message

            navIFMutex_ = new Mutex();  //not sure we need this

            ////////////////////////////////////////////////////////////////////////////////////////////
            //wait here in a loop unitl we have attached the USB cable to access the mbed device
            ////////////////////////////////////////////////////////////////////////////////////////////
            initializeMbedSerialPort();
            if (!serialInit_)
            {
                logFile.WriteLine("mbed serial port not found");
                throw new Exception("no serial port found");
            }

            /////////////////////////////////////////////////////////////////////////////////////
            //At this stage we have found the mbed port and have successfully opened the port
            /////////////////////////////////////////////////////////////////////////////////////

            logFile.WriteLine("Successfully opened the mbed device");

            utm = new UTM2Geodetic();
            posvelAt1PPS = new PosVel();

            timeFrom1PPS = new Stopwatch();

            //set up the communications interface thread
            Thread mbedCommunication = new Thread(mbedCommunicationWorker);
            mbedCommunication.IsBackground = false;

            //start the communication and begin retrieving mbed messages
            mbedCommunication.Start();
            logFile.WriteLine("Completed starting the mbed communication thread");

            if (mbedCommunication.IsAlive)
            {
                logFile.WriteLine("mbedCommunication thread is operating ");
            }
            else
            {
                logFile.WriteLine("mbed communication htread os not operating ");
                MessageBox.Show("mbed comminication thread did not start ");
            }
        }