public TimeSpan GetRemainingTime(IJobMonitor jobMonitor) { TimeSpan res = TimeSpan.MinValue; try { if (this.Open()) { IList <GlobalsatPacket.TrackFileHeader> headers = this.ReadTrackHeaders(jobMonitor); GlobalsatSystemConfiguration2 systemInfo = GetGlobalsatSystemConfiguration2(); res = this.RemainingTime(headers, systemInfo); } } catch (Exception e) { jobMonitor.ErrorText = Properties.Resources.Device_OpenDevice_Error + e; } finally { this.Close(); } if (!this.DataRecieved) { NoCommunicationError(jobMonitor); } return(res); }
public virtual GlobalsatSystemConfiguration2 ResponseGetSystemConfiguration2() { //No reasonable check for CheckOffset() GlobalsatSystemConfiguration2 systemInfo = new GlobalsatSystemConfiguration2(); return(systemInfo); }
public GlobalsatSystemConfiguration2 GetGlobalsatSystemConfiguration2() { GlobalsatPacket packet = PacketFactory.GetSystemConfiguration2(); GlobalsatPacket response2 = (GlobalsatPacket)this.SendPacket(packet); GlobalsatSystemConfiguration2 systemInfo = response2.ResponseGetSystemConfiguration2(); return(systemInfo); }
public override GlobalsatSystemConfiguration2 ResponseGetSystemConfiguration2() { const int SystemConfiguration2 = 335; if (this.PacketLength < SystemConfiguration2) { ReportOffset(this.PacketLength, SystemConfiguration2); return(null); } GlobalsatSystemConfiguration2 systemInfo = new GlobalsatSystemConfiguration2(); systemInfo.cRecordTime = this.PacketData[259]; return(systemInfo); }
public virtual Bitmap GetScreenshot(IJobMonitor jobMonitor) { Bitmap result = null; //Note: No check for connected here if (this.Open()) { try { GlobalsatPacket packet = PacketFactory.GetScreenshot(); GlobalsatPacket response = (GlobalsatPacket)this.SendPacket(packet); System.Drawing.RotateFlipType rotate = RotateFlipType.RotateNoneFlipNone; if (this.FitnessDevice.CanRotateScreen) { //try getting screen orientaion try { packet = PacketFactory.GetSystemConfiguration2(); GlobalsatPacket response2 = (GlobalsatPacket)this.SendPacket(packet); GlobalsatSystemConfiguration2 systemInfo = response2.ResponseGetSystemConfiguration2(); if (systemInfo.ScreenOrientation == 1) { rotate = RotateFlipType.Rotate90FlipNone; } } catch {} } result = response.ResponseGetScreenshot(rotate); } catch (Exception e) { jobMonitor.ErrorText = Properties.Resources.Device_GetInfo_Error + e; //throw new Exception(Properties.Resources.Device_GetInfo_Error + e); } finally { this.Close(); } } if (!this.DataRecieved) { NoCommunicationError(jobMonitor); } return(result); }
public override bool Import() { bool result = false; try { if (device.Open()) { IList <GlobalsatPacket.TrackFileHeader> headers = ((GlobalsatProtocol2)device).ReadTrackHeaders(monitor); List <GlobalsatPacket.TrackFileHeader> fetch = new List <GlobalsatPacket.TrackFileHeader>(); if (device.FitnessDevice.configInfo.ImportOnlyNew && Plugin.Instance.Application != null && Plugin.Instance.Application.Logbook != null) { IDictionary <DateTime, IList <GlobalsatPacket.TrackFileHeader> > headersByStart = new Dictionary <DateTime, IList <GlobalsatPacket.TrackFileHeader> >(); foreach (GlobalsatPacket.TrackFileHeader header in headers) { //Adjust time in headers DateTime start = header.StartTime; if (!headersByStart.ContainsKey(start)) { headersByStart.Add(start, new List <GlobalsatPacket.TrackFileHeader>()); } headersByStart[start].Add(header); } DateTime now = DateTime.UtcNow; foreach (IActivity activity in Plugin.Instance.Application.Logbook.Activities) { DateTime findTime = activity.StartTime; if (headersByStart.ContainsKey(findTime) && (now - findTime).TotalSeconds > device.FitnessDevice.configInfo.SecondsAlwaysImport && //always import "bad" data findTime - device.FitnessDevice.NoGpsDate < TimeSpan.FromDays(14)) { headersByStart.Remove(findTime); } } foreach (IList <GlobalsatPacket.TrackFileHeader> dateHeaders in headersByStart.Values) { fetch.AddRange(dateHeaders); } } else { fetch.AddRange(headers); } //Read the complete activities from the device IList <GlobalsatPacket.Train> trains = ((GlobalsatProtocol2)device).ReadTracks(fetch, monitor); //popup if short remaining time GlobalsatSystemConfiguration2 systemInfo = ((GlobalsatProtocol2)device).GetGlobalsatSystemConfiguration2(); TimeSpan remainTime = device.RemainingTime(headers, systemInfo); if (remainTime < TimeSpan.FromHours(5)) { if (remainTime < TimeSpan.Zero) { remainTime = TimeSpan.Zero; } string msg = string.Format("Remaining recording time about {0}", remainTime.ToString()); MessageDialog.Show(msg, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } for (int i = 0; i < trains.Count; i++) { //Adjust "no gps fix" time so they are easier to find... //Guess assumes no-GPS matches a real activity and that activities are in order GlobalsatPacket.Train train = trains[i]; if (i > 20) { } IActivity logActivity = this.getMatchingLogActivity(i, trains.Count); if (train.StartTime - device.FitnessDevice.NoGpsDate < TimeSpan.FromDays(14) && logActivity != null) { train.Comment += "Original activity date: " + train.StartTime + ", index: " + i; if (DateTime.UtcNow - logActivity.StartTime < TimeSpan.FromDays(7)) { //fairly recent, assume this is a duplicate train.StartTime = logActivity.StartTime; } else { //older, set older date train.StartTime = DateTime.UtcNow - TimeSpan.FromDays(7 + trains.Count - i); } } } AddActivities(importResults, trains, device.FitnessDevice.configInfo.ImportSpeedDistanceTrack, device.FitnessDevice.configInfo.DetectPauses, device.FitnessDevice.configInfo.Verbose); result = true; } } catch (Exception e) { //if (device.DataRecieved) { monitor.ErrorText = e.Message; //throw e; } } finally { device.Close(); } if (!device.DataRecieved) { //override other possible errors device.NoCommunicationError(monitor); } return(result); }
public TimeSpan RemainingTime(IList <GlobalsatPacket.TrackFileHeader> headers, GlobalsatSystemConfiguration2 currentDeviceConfig) { //Find recording time in device int totalUsedPoints = 0; TimeSpan totalTime = TimeSpan.Zero; foreach (GlobalsatPacket.TrackFileHeader header in headers) { //The device allocates points in blocks/sectors for each activity, compare to file storage totalUsedPoints += (header.TrackPointCount / this.FitnessDevice.PointsInBlock + 1) * this.FitnessDevice.PointsInBlock; totalTime += header.TotalTime; } int recordingInterval = 1; if (currentDeviceConfig != null) { recordingInterval = currentDeviceConfig.cRecordTime; } TimeSpan remainTime = TimeSpan.FromSeconds((this.FitnessDevice.TotalPoints - totalUsedPoints) * recordingInterval); return(remainTime); }