private void manuf_params(TsipPacket tp)
        {
            Debug.Print("Packet 8F.41 (Manufacturing Params):");

            UInt16 sn_prefix = tp.GetNextWord();
            UInt32 serial_num = tp.GetNextDWord();
            byte build_year = tp.GetNextByte();
            byte build_month = tp.GetNextByte();
            byte build_day = tp.GetNextByte();
            byte build_hour = tp.GetNextByte();
            Single osc_offset = tp.GetNextSingle();
            UInt16 test_code = tp.GetNextWord();

            unit_build.Date = new DateTime(build_year + 2000, build_month, build_day, build_hour, 0, 0);
            unit_build.SerialNumber = sn_prefix.ToString() + "-" + serial_num.ToString();
        }
 private void packet_mask(TsipPacket tp)
 {
     Debug.Print("Packet 8F.A5 (Packet mask):");
     UInt16 mask1 = tp.GetNextWord();
     UInt16 mask2 = tp.GetNextWord();
 }
 private void gps_time_received(TsipPacket tp)
 {
     Debug.Print(":0x41 GPS Time Received");
     Single s_time = tp.GetNextSingle();
     Int16 s_week = (short)tp.GetNextWord();
     Single s_offset = tp.GetNextSingle();
     if (GPSTimeReceived != null)
         GPSTimeReceived(this, new GPSTimeInfoEventArgs(s_time, s_week, s_offset));
 }
        private void last_fix_info(TsipPacket tp)
        {
            Debug.Print("Packet 57 (last fix info):");

            byte source_of_fix = tp.GetNextByte();
            byte tracking_mode = tp.GetNextByte();
            Single time_of_fix = tp.GetNextSingle();
            UInt16 week_of_fix = tp.GetNextWord();
        }
        // Thunderbolt E Version Information
        private void ebolt_version(TsipPacket tp)
        {
            byte rev_month;
            byte rev_day;
            UInt16 rev_year;

            byte subcode = tp.GetNextByte();
            if (subcode == 0x81) // firmware version
            {
                Debug.Print(":0x1C.0x81 (Firmware Version)");
                byte reserved8 = tp.GetNextByte();
                byte major = tp.GetNextByte(); // major version number
                byte minor = tp.GetNextByte(); // minor version number
                byte build = tp.GetNextByte(); // build number
                rev_month = tp.GetNextByte();  // build month
                rev_day = tp.GetNextByte();    // build day
                rev_year = tp.GetNextWord();   // build year
                unit_firmware.VersionString = tp.GetNextString(); // product name string
                try
                {
                    unit_firmware.Date = new DateTime(rev_year, rev_month, rev_day, 0, 0, 0);
                }
                catch (Exception e)
                {
                    unit_firmware.Date = new DateTime(0L);   // bad date
                    Debug.Print("Date Conversion Exception: " + e.Message);
                }
                unit_firmware.Code = 0;
                if (FirmwareVersionInfoReceived != null)
                    FirmwareVersionInfoReceived(this, new VersionInfoEventArgs(unit_firmware));
            }
            else if (subcode == 0x83) // hardware version
            {
                Debug.Print(":0x1C.0x83 (Hardware Version)");
                UInt32 serno = tp.GetNextDWord();    // board serial number
                rev_day = tp.GetNextByte();          // board build day
                rev_month = tp.GetNextByte();        // board build month
                rev_year = tp.GetNextWord();         // board build year
                byte rev_hour = tp.GetNextByte();    // board build hour

                unit_hardware.Code = tp.GetNextWord(); // hardware code associated with hardware ID
                unit_hardware.VersionString = tp.GetNextString(); // Hardware ID
                unit_hardware.SerialNumber = "SN:" + serno.ToString();

                try
                {
                    unit_hardware.Date = new DateTime(rev_year, rev_month, rev_day, rev_hour, 0, 0);
                }
                catch (Exception e)
                {
                    unit_hardware.Date = new DateTime(0L);  // bad date
                    Debug.Print("Date Conversion Exception: " + e.Message);
                }
                if (HardwareVersionInfoReceived != null)
                    HardwareVersionInfoReceived(this, new VersionInfoEventArgs(unit_hardware));
            }
            else
                unknown_msg(tp);
        }
        private void eeprom_status(TsipPacket tp)
        {
            Debug.Print("Packet 5F (EEPROM status):");

            byte flag = tp.GetNextByte();
            if (flag == 0x11)
            {
                UInt16 ee_status = tp.GetNextWord();
            }
        }
 private void datums(TsipPacket tp)
 {
     Debug.Print("Packet 8F.15 (Datums)");
     int index = tp.GetNextWord();
     double dx = tp.GetNextDouble();
     double dy = tp.GetNextDouble();
     double dz = tp.GetNextDouble();
     double a_axis = tp.GetNextDouble();
     double ecc = tp.GetNextDouble();
 }
        private void secondary_timing(TsipPacket tp)
        {
            Debug.Print(":0x8F.AC (Secondary Timing)");

            byte spare;
            try
            {
                receiver_mode = (ReceiverMode)tp.GetNextByte();
            }
            catch
            {
                receiver_mode = ReceiverMode.Unknown;
            }
            try
            {
                discipline_mode = (DiscipliningMode)tp.GetNextByte();
            }
            catch
            {
                discipline_mode = DiscipliningMode.Unknown;
            }
            survey_progress = tp.GetNextByte(); // 0-100%

            holdover = tp.GetNextDWord(); // seconds

            critical_alarms = tp.GetNextWord();
            minor_alarms = tp.GetNextWord();
            try
            {
                gps_status = (ReceiverStatus)tp.GetNextByte();
            }
            catch
            {
                gps_status = ReceiverStatus.Unknown;
            }

            try
            {
                discipline = (DiscipliningActivity)tp.GetNextByte();
            }
            catch
            {
                discipline = DiscipliningActivity.Unknown;
            }

            spare = tp.GetNextByte();
            spare = tp.GetNextByte();

            pps_offset = tp.GetNextSingle();  // in nano seconds (ns)

            osc_offset = tp.GetNextSingle();  // in parts per billion (ppb)

            dac_value = tp.GetNextDWord();
            dac_voltage = tp.GetNextSingle(); // in V
            temperature = tp.GetNextSingle(); // in C

            position.Latitude = tp.GetNextDouble();
            position.Longitude = tp.GetNextDouble();
            position.Altitude = tp.GetNextDouble();

            if (SecondaryTimingChanged != null)
                SecondaryTimingChanged(this, null);

            raise_position_change();

            clear_sat_tracking(); //??
        }
        //not available on ThunderBolt-E
        /// <summary>
        /// This broadcast packet provides individual satellite solutions as well as the combined
        /// timing solutions. Two formats of this packet are supported: a floating-point form and an
        /// integer form. This packet is broadcast once per second if enabled with the 0x8E-A5 packet
        /// mask command. Packet 0x8E-A5 allows the user to select which format will be broadcast.
        /// 
        /// notes:
        /// If both formats are selected the ThunderBolt will send format 0 (floating point) only.
        /// 
        /// For clock bias numbers, a positive sign indicates that the ThunderBolt PPS occurs after the
        /// GPS PPS. 
        /// 
        /// For clock bias rate numbers, a positive sign indicates that the ThunderBolt
        /// 10MHz frequency output is running slow relative to GPS.
        /// 
        /// 8 sets of satellite ID and data are sent with n=1, 2, . . . 8
        /// </summary>
        private void sat_solutions(TsipPacket tp)
        {
            Debug.Print(":0x8F.A7 (Satellite Solutions)");

            byte format = tp.GetNextByte();
            UInt32 time_of_week = tp.GetNextDWord();

            Single clock_bias;
            Single clock_bias_rate;

            if (format == 0)
            {   // floating point
                clock_bias = tp.GetNextSingle();
                clock_bias_rate = tp.GetNextSingle();
            }
            else if (format == 1)
            {   // integer values
                clock_bias = (float)(int)tp.GetNextWord();
                clock_bias *= 100.0e-12F;
                clock_bias_rate = (float)(int)tp.GetNextWord();
                clock_bias_rate *= 1.0e-12F;
            }
            else
            {
                unknown_msg(tp);
                return;
            }

            for (int i = 0; i < 32; i++)    // reset current bias flags
                Satellites[i].HasBiasInfo = false;

            for (int i = 0; i < 8; i++)     // get bias info from all visible satellites
            {
                byte prn = tp.GetNextByte();
                prn--;
                if (prn > 31)               // ignore bogus data
                    continue;

                if (format == 0)
                    Satellites[prn].SatBias = tp.GetNextSingle();
                else
                {
                    Satellites[prn].SatBias = (float)(int)tp.GetNextWord();
                    Satellites[prn].SatBias *= 100.0e-12F;
                }

                Satellites[prn].TimeOfFix = (float)time_of_week;
                Satellites[prn].HasBiasInfo = true;
            }
        }
        private void prodn_params(TsipPacket tp)
        {
            Debug.Print("Packet 8F.42 (Production Params):");

            byte prodn_options = tp.GetNextByte();
            byte prodn_number = tp.GetNextByte();
            UInt16 case_prefix = tp.GetNextWord();
            UInt32 case_sn = tp.GetNextDWord();
            UInt32 prodn_num = tp.GetNextDWord();
            UInt16 rsvd1 = tp.GetNextWord();
            UInt16 machine_id = tp.GetNextWord();
            UInt16 rsvd2 = tp.GetNextWord();
        }
        private void primary_timing(TsipPacket tp)
        {
            Debug.Print(":0x8F.AB (Primary Timing)");

            UInt32 pri_tow = tp.GetNextDWord();
            UInt16 pri_gps_week = tp.GetNextWord();
            Int16 pri_utc_offset = (short)tp.GetNextWord();
            byte time_flags = tp.GetNextByte();
            byte pri_seconds = tp.GetNextByte();
            byte pri_minutes = tp.GetNextByte();
            byte pri_hours = tp.GetNextByte();
            byte pri_day = tp.GetNextByte();
            byte pri_month = tp.GetNextByte();
            UInt16 pri_year = tp.GetNextWord();
            try
            {
                // if this fires an execption, just skip the bad packet
                current_time = new DateTime(pri_year, pri_month, pri_day, pri_hours, pri_minutes, pri_seconds);

                tow = pri_tow;
                utc_offset = pri_utc_offset;
                gps_week = pri_gps_week;

                if ((time_flags & 0x04) == 0x04)
                    time_value = TimeType.NoTimeAvailable;
                else if ((time_flags & 0x08) == 0x08)
                    time_value = TimeType.NoUTCOffset;
                else if ((time_flags & 0x10) == 0x10)
                    time_value = TimeType.UserSetTime;
                else if ((time_flags & 0x01) == 0x01)
                    time_value = TimeType.UTCTimeOk;
                else
                    time_value = TimeType.GPSTimeOk;

                // Set the time on the netduino to the current time on the Thunderbolt.
                Microsoft.SPOT.Hardware.Utility.SetLocalTime(current_time);

                if ((last_current_time != current_time) && (TimeChanged != null))
                    TimeChanged(this, new EventArgs());

                last_current_time = current_time;
            }
            catch (Exception e)
            {
                current_time = last_current_time;
                Debug.Print("Exception:" + e.Message);
            }
        }