Example #1
0
        public virtual bool DeleteAllTracks(IJobMonitor jobMonitor)
        {
            bool result = false;

            try
            {
                if (this.Open())
                {
                    //IList<GlobalsatPacket.TrackFileHeader> headers = ((GlobalsatProtocol2)device).ReadTrackHeaders(jobMonitor);
                    //List<GlobalsatPacket.TrackFileHeader> fetch = new List<GlobalsatPacket.TrackFileHeader>();
                    GlobalsatPacket  getDeleteAllTracks = PacketFactory.GetDeleteAllTracks();
                    GlobalsatPacket2 response           = (GlobalsatPacket2)SendPacket(getDeleteAllTracks);
                    result = true;
                }
            }
            catch (Exception e)
            {
                jobMonitor.ErrorText = Properties.Resources.Device_OpenDevice_Error + e;
                //throw new Exception(Properties.Resources.Device_OpenDevice_Error + e);
            }
            finally
            {
                this.Close();
            }
            if (!this.DataRecieved)
            {
                NoCommunicationError(jobMonitor);
            }
            return(result);
        }
Example #2
0
        public virtual IList <GlobalsatPacket.TrackFileHeader> ReadTrackHeaders(IJobMonitor monitor)
        {
            //monitor.StatusText = CommonResources.Text.Devices.ImportJob_Status_OpeningDevice;

            GlobalsatPacket  getHeadersPacket = PacketFactory.GetTrackFileHeaders();
            GlobalsatPacket2 response         = (GlobalsatPacket2)SendPacket(getHeadersPacket);

            return(response.UnpackTrackHeaders());
        }
Example #3
0
        //not working, deletes all...
        public virtual int DeleteTracks(DateTime oldest, IJobMonitor jobMonitor)
        {
            int res = -1;

            try
            {
                if (this.Open())
                {
                    IList <GlobalsatPacket.TrackFileHeader> headers = this.ReadTrackHeaders(jobMonitor);
                    IList <GlobalsatPacket.TrackFileHeader> fetch   = new List <GlobalsatPacket.TrackFileHeader>();
                    foreach (GlobalsatPacket.TrackFileHeader t in headers)
                    {
                        if (t.StartTime < oldest)
                        {
                            fetch.Add(t);
                        }
                    }
                    if (fetch.Count > 0)
                    {
                        GlobalsatPacket  getDeleteTracks = PacketFactory.GetDeleteTracks(fetch);
                        GlobalsatPacket2 response        = (GlobalsatPacket2)SendPacket(getDeleteTracks);
                    }
                    res = fetch.Count;
                }
            }
            catch (Exception e)
            {
                jobMonitor.ErrorText = Properties.Resources.Device_OpenDevice_Error + e;
                //throw new Exception(Properties.Resources.Device_OpenDevice_Error + e);
            }
            finally
            {
                this.Close();
            }
            if (!this.DataRecieved)
            {
                NoCommunicationError(jobMonitor);
            }
            return(res);
        }
Example #4
0
        public virtual IList <GlobalsatPacket.Train> ReadTracks(IList <GlobalsatPacket.TrackFileHeader> tracks, IJobMonitor monitor)
        {
            if (tracks.Count == 0)
            {
                return(new GlobalsatPacket.Train[0]);
            }

            int           totalPoints  = 0;
            IList <Int16> trackIndexes = new List <Int16>();

            foreach (GlobalsatPacket.TrackFileHeader header in tracks)
            {
                totalPoints += header.TrackPointCount;
                //track number, less than 100
                trackIndexes.Add((Int16)header.TrackPointIndex);
            }
            int totalPointsRead = 0;

            GlobalsatPacket  getFilesPacket = PacketFactory.GetTrackFileSections(trackIndexes);
            GlobalsatPacket2 response       = (GlobalsatPacket2)SendPacket(getFilesPacket);

            monitor.PercentComplete = 0;

            IList <GlobalsatPacket.Train> trains = new List <GlobalsatPacket.Train>();
            ReadMode readMode        = ReadMode.Header;
            int      trainLapsToRead = 0;
            int      pointsToRead    = 0;

            while (response.CommandId != GlobalsatPacket2.CommandId_FINISH && !monitor.Cancelled)
            {
                //Check that previous mode was finished, especially at corruptions there can be out of sync
                if (readMode != ReadMode.Header)
                {
                    byte readMode2 = response.GetTrainContent();
                    if (readMode2 == GlobalsatPacket.HeaderTypeTrackPoints)
                    {
                        if (readMode != ReadMode.Points)
                        {
                            //TODO: Handle error
                        }
                        readMode = ReadMode.Points;
                    }
                    else if (readMode2 == GlobalsatPacket.HeaderTypeLaps)
                    {
                        if (readMode != ReadMode.Laps)
                        {
                            //TODO: Handle error
                        }
                        readMode = ReadMode.Laps;
                    }
                    else
                    {
                        if (readMode != ReadMode.Header)
                        {
                            //TODO: Handle error
                            if (trains.Count > 0)
                            {
                                trains.RemoveAt(trains.Count - 1);
                            }
                        }
                        readMode = ReadMode.Header;
                    }
                }
                if (response.CommandId == GlobalsatPacket2.CommandId_FINISH)
                {
                    break;
                }
                switch (readMode)
                {
                case ReadMode.Header:
                {
                    GlobalsatPacket.Train train = response.UnpackTrainHeader();
                    if (train != null)
                    {
                        trainLapsToRead = train.LapCount;
                        pointsToRead    = train.TrackPointCount;
                        trains.Add(train);
                    }
                    readMode = ReadMode.Laps;
                    break;
                }

                case ReadMode.Laps:
                {
                    GlobalsatPacket.Train       currentTrain = trains[trains.Count - 1];
                    IList <GlobalsatPacket.Lap> laps         = response.UnpackLaps();
                    foreach (GlobalsatPacket.Lap lap in laps)
                    {
                        currentTrain.Laps.Add(lap);
                    }
                    trainLapsToRead -= laps.Count;
                    if (trainLapsToRead <= 0)
                    {
                        readMode = ReadMode.Points;
                    }
                    break;
                }

                case ReadMode.Points:
                {
                    GlobalsatPacket.Train currentTrain        = trains[trains.Count - 1];
                    IList <GlobalsatPacket.TrackPoint> points = response.UnpackTrackPoints();
                    foreach (GlobalsatPacket.TrackPoint point in points)
                    {
                        currentTrain.TrackPoints.Add(point);
                    }
                    pointsToRead    -= points.Count;
                    totalPointsRead += points.Count;
                    DateTime startTime      = currentTrain.StartTime.ToLocalTime();
                    string   statusProgress = startTime.ToShortDateString() + " " + startTime.ToShortTimeString();
                    monitor.StatusText      = String.Format(CommonResources.Text.Devices.ImportJob_Status_Reading, statusProgress);
                    monitor.PercentComplete = (float)totalPointsRead / (float)totalPoints;
                    if (pointsToRead <= 0)
                    {
                        readMode = ReadMode.Header;
                    }
                    break;
                }
                }
                //All requests are the same
                response = (GlobalsatPacket2)SendPacket(PacketFactory.GetNextTrackSection());
            }

            monitor.PercentComplete = 1;
            monitor.StatusText      = CommonResources.Text.Devices.ImportJob_Status_ImportComplete;
            return(trains);
        }