Esempio n. 1
0
 public RegSETrack(IRegSETrackInfo info, IRegSETrackPoint[] points)
 {
     _info = info;
     _points = points;
 }
Esempio n. 2
0
        private void LoadTracks()
        {
            lock (this)
            {
                _loadCompleted = false;
                if (!IsConnected)
                {
                    SendReadError(new RegSEError("No connection with device!"));
                    SendReadCompleted();
                    return;
                }
                using (var session = new SerialPortSession(_commport))
                {
                    var getNumOfPointsCommand = new NumOfPointsCommand();
                    getNumOfPointsCommand.Execute(session.Port);
                    int total             = getNumOfPointsCommand.GetNumOfPoints();
                    int current           = 0;
                    var loadPointsCommand = new LoadPointsCommand(current * 16);
                    loadPointsCommand.Execute(session.Port);
                    var points = new List <IRegSETrackPoint>();
                    points.AddRange(loadPointsCommand.GetPoints());
                    current += loadPointsCommand.GetPoints().Count;

                    SendProgressChanged(String.Format("Read track data... ({0}/{1})", current, total), current, total);
                    do
                    {
                        loadPointsCommand = new LoadPointsCommand(current * 16);
                        loadPointsCommand.Execute(session.Port);
                        points.AddRange(loadPointsCommand.GetPoints());
                        current += loadPointsCommand.GetPoints().Count;
                        SendProgressChanged(String.Format("Read track data... ({0}/{1})", current, total), current,
                                            total);
                    } while (current < total);

                    // split into tracks
                    if (points.Count > 0)
                    {
                        _tracks     = new List <IRegSETrack>();
                        _trackInfos = new List <IRegSETrackInfo>();

                        var startPoint = points[0];
                        if (!startPoint.HasMark(RegSEPointType.TrackStart))
                        {
                            SendReadError(new RegSEError("First point does not marked as track's start point!"));
                            SendReadCompleted();
                            return;
                        }
                        var startPointIndex = 0;
                        var numOfPoints     = 0;

                        for (var i = 1; i < points.Count; i++)
                        {
                            numOfPoints++;
                            IRegSETrackPoint point = points[i];
                            if (point.HasMark(RegSEPointType.TrackStart))
                            {
                                var             duration  = (int)(points[i - 1].Time - startPoint.Time).TotalSeconds;
                                IRegSETrackInfo trackInfo = new RegSETrackInfo(startPoint.Time, duration, numOfPoints);
                                _trackInfos.Add(trackInfo);
                                _tracks.Add(new RegSETrack(trackInfo,
                                                           points.GetRange(startPointIndex, numOfPoints).ToArray()));
                                startPoint      = point;
                                startPointIndex = i;
                                numOfPoints     = 0;
                            }
                        }
                        {
                            var             duration  = (int)(points[points.Count - 1].Time - startPoint.Time).TotalSeconds;
                            IRegSETrackInfo trackInfo = new RegSETrackInfo(startPoint.Time, duration, numOfPoints);
                            _trackInfos.Add(trackInfo);
                            _tracks.Add(new RegSETrack(trackInfo,
                                                       points.GetRange(startPointIndex, numOfPoints).ToArray()));
                        }
                    }
                    _loadCompleted = true;
                    SendReadCompleted();
                }
            }
        }