Ejemplo n.º 1
0
        private void UpdateTeamStatus(TrackingData Data)
        {
            TeamData     td;
            ListViewItem lvi = new ListViewItem();

            try
            {
                int _prev_speed     = 0;
                int _prev_direction = 0;

                if (m_Teams.ContainsKey(Data.CID))
                {
                    td = m_Teams[Data.CID];
                    // The GPS update came - change the status from Delayed to Tracking
                    if (td.Status == TrackStatus.DELAYED)
                    {
                        td.Status = TrackStatus.TRACKING;
                    }
                    _prev_speed     = td.Coordinates.Speed;
                    _prev_direction = td.Coordinates.Direction;
                    if (_prev_direction > 180)
                    {
                        _prev_direction -= 180;
                    }
                }
                else
                {
                    td        = new TeamData();
                    td.CID    = Data.CID;
                    td.Status = TrackStatus.TRACKING;
                    td.Name   = Data.CID;
                }
                td.Coordinates       = Data.Coordinates;
                td.Coordinates.MGRS  = GPSTrack.FormatMGRS(td.Coordinates.MGRS);
                td.Coordinates       = GPSTrack.MGRS_To_LatLon(td.Coordinates);
                td.Coordinates.Time  = DateTime.Now;
                td.Coordinates.Speed = (td.Coordinates.Speed + _prev_speed) / 2;
                if (td.Coordinates.Direction > 180)
                {
                    td.Coordinates.Direction -= 180;
                }
                td.Coordinates.Direction = (td.Coordinates.Direction + _prev_direction) / 2;
                if (td.Coordinates.Direction < 0)
                {
                    td.Coordinates.Direction += 180;
                }

                m_Teams[td.CID] = td;
                UpdateTrackingHistory(td);
                UpdateTeamDisplay(td);
                m_statusStrip.Items[0].Text = String.Format("{0} is receiving SA updates", m_SerialCommPort.PortName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.InnerException + ex.ToString());
            }
        }
Ejemplo n.º 2
0
        private void NewTrackingInfoReceived(object sender, EventArgs e)
        {
            TrackingData td = ((GPSTrack)sender).NewData;

            if (StatusView.InvokeRequired)
            {
                StatusView.Invoke(new UpdateTrackingStatus(this.UpdateTeamStatus), td);
            }
            else
            {
                UpdateTeamStatus(td);
            }
        }
Ejemplo n.º 3
0
        public void ProcessTrackingData(string IncomingData)
        {
            bool needs_update = false;

            lock (ReceivedSerialData)
            {
                IncomingData = IncomingData.Replace("\r", "");
                IncomingData = IncomingData.Replace("OK", "");
                int new_length = ReceivedSerialData.Length + IncomingData.Length;
                if (new_length > 4096)
                {
                    // Too many unrecognized symbols accumulated -
                    //   switch into the scrolling mode
                    ReceivedSerialData.Remove(0, IncomingData.Length);
                }
                ReceivedSerialData.Append(IncomingData);

                bool match_found = false;
                do
                {
                    Match rm = SA_rx.Match(ReceivedSerialData.ToString());
                    match_found = rm.Success;
                    if (match_found)
                    {
                        TrackingData ct = new TrackingData();
                        ct.CID  = rm.Groups["CID"].Value;
                        ct.PFOM = 0;  int.TryParse(rm.Groups["PFOM"].Value, out ct.PFOM);
                        ct.TFOM = 0; int.TryParse(rm.Groups["TFOM"].Value, out ct.TFOM);
                        ct.Coordinates.Altitude  = 0; int.TryParse(rm.Groups["ALT"].Value, out ct.Coordinates.Altitude);
                        ct.Coordinates.Speed     = 0; int.TryParse(rm.Groups["SPEED"].Value, out ct.Coordinates.Speed);
                        ct.Coordinates.Direction = 0; int.TryParse(rm.Groups["DIR"].Value, out ct.Coordinates.Direction);
                        ct.Coordinates.MGRS      = rm.Groups["ZD"].Value + rm.Groups["ZL"].Value + rm.Groups["GG"].Value +
                                                   rm.Groups["X"].Value + rm.Groups["Y"].Value;
                        ct.Coordinates.Time = DateTime.Now;
                        ReceivedSerialData.Remove(rm.Index, rm.Length);
                        // Check if the same information is already in the system
                        if (StoredData.ContainsKey(ct.CID))
                        {
                            // Any changes???
                            TrackingData old_ct = StoredData[ct.CID];
                            if ((old_ct.PFOM != ct.PFOM) || (old_ct.TFOM != ct.TFOM) ||
                                !old_ct.Coordinates.MGRS.Equals(ct.Coordinates.MGRS) ||
                                (old_ct.Coordinates.Direction != ct.Coordinates.Direction) ||
                                (old_ct.Coordinates.Altitude != ct.Coordinates.Altitude) ||
                                (old_ct.Coordinates.Speed != ct.Coordinates.Speed))
                            {
                                needs_update = true;
                            }
                        }
                        else
                        {
                            // New CID detected
                            needs_update = true;
                        }
                        // Save received data indexed by the CID
                        StoredData[ct.CID] = ct;
                        if (needs_update && (TrackReceived != null))
                        {
                            NewData = ct;
                            TrackReceived(this, EventArgs.Empty);
                        }
                    }
                } while (match_found);
            }
        }