Exemple #1
0
        /// <summary>
        /// Displays the FIT file.
        /// </summary>
        private void DisplayFitFile()
        {
            ClearDisplay();
            if (fitFile != null)
            {
                // display the file name
                FileNameTextBox.Text = fitFile.FileName;
                FileNameTextBox.Focus();
                FileNameTextBox.Select(FileNameTextBox.Text.Length, 0);

                // display the record summary
                NumRecordsLabel.Content  = fitFile.Records.Count.ToString();
                NumLengthsLabel.Content  = fitFile.Lengths.Count.ToString();
                NumLapsLabel.Content     = fitFile.Laps.Count.ToString();
                NumSessionsLabel.Content = fitFile.Sessions.Count.ToString();
                FitRecord last = fitFile.Records[fitFile.Records.Count - 1];
                TimeLabel.Content     = (last.Timestamp - fitFile.Records[0].Timestamp).ToString();
                DistanceLabel.Content = (last.Distance ?? 0).ToString("0.#");
                FitRecordSummary summary = fitFile.Records.Summary;
                AverageCadenceLabel.Content   = summary.AveCadence.ToString("0");
                AverageHeartRateLabel.Content = summary.AveHeartRate.ToString("0");
                AveragePowerLabel.Content     = summary.AvePower.ToString("0");
                AverageSpeedLabel.Content     = summary.AveSpeed.ToString("0.#");
                MaxCadenceLabel.Content       = summary.MaxCadence.ToString();
                MaxHeartRateLabel.Content     = summary.MaxHeartRate.ToString();
                MaxPowerLabel.Content         = summary.MaxPower.ToString();
                MaxSpeedLabel.Content         = summary.MaxSpeed.ToString("0.#");

                // display the data grids
                FileIDDataGrid.ItemsSource      = GetNonNullPropertiesValues(typeof(FitFileID), fitFile.FileID);
                DeviceInfoDataGrid.ItemsSource  = fitFile.DeviceInfos;
                UserProfileDataGrid.ItemsSource = GetNonNullPropertiesValues(typeof(FitUserProfile), fitFile.UserProfile);
                ActivityDataGrid.ItemsSource    = GetNonNullPropertiesValues(typeof(FitActivity), fitFile.Activity);
                SessionsDataGrid.ItemsSource    = fitFile.Sessions;
                LapsDataGrid.ItemsSource        = fitFile.Laps;
                LengthsDataGrid.ItemsSource     = fitFile.Lengths;
                RecordsDataGrid.ItemsSource     = fitFile.Records;
                MessagesDataGrid.ItemsSource    = fitFile.Messages;
            }
        }
Exemple #2
0
        public fitFileReader(FileStream file, StreamWriter outFile)
        {
            string ErrorBytes = "";
            int    RecordsOk  = 5;

            localMsgDef[] localMesgDefs = new localMsgDef[16];
            FitRecord     record        = new FitRecord(file);

            long   pos = file.Position = (byte)file.ReadByte() == 14 ? 14 : 12;
            UInt32 TraveltotalSeconds   = 0;
            UInt32 TravelStartTimestamp = 0;
            UInt32 TravelEndTimestamp   = 0;
            UInt32 TraveltotalMeters    = 0;
            UInt32 TravelStartMeters    = 0;
            UInt32 TravelEndMeters      = 0;
            UInt32 maxSpeed             = 0;
            UInt32 totPower             = 0;
            UInt32 PowertotalSeconds    = 0;
            UInt32 PowerStartTimestamp  = 0;
            UInt32 PowerEndTimestamp    = 0;


            while (true)
            {
                try
                {
                    if (RecordsOk > 5)
                    {
                        pos = file.Position;
                    }
                    string str = record.read(localMesgDefs);
                    if (str == "")
                    {
                        if (pos + 2 >= file.Length)
                        {
                            break;
                        }
                        file.Position = pos++;
                        ErrorBytes   += ((RecordsOk > 0) ? string.Format("Error at pos {0} byte:", (file.Position).ToString("X4")) : "") + file.ReadByte().ToString("X2");
                        RecordsOk     = 0;
                    }
                    else
                    {
                        RecordsOk++;
                        if (ErrorBytes != "")
                        {
                            outFile.WriteLine(ErrorBytes);
                        }
                        ErrorBytes = "";
                        outFile.WriteLine(str);
                        if (record.localMsgDef.globalMesgIndex == FIT.FIT_MESG_NUM_RECORD && record.speed > 2000)
                        {
                            TravelEndTimestamp = record.timestamp;
                            TravelEndMeters    = record.distance;
                            if (TravelStartMeters == 0)
                            {
                                TravelStartTimestamp = TravelEndTimestamp;
                                TravelStartMeters    = TravelEndMeters;
                            }
                        }
                        else
                        {
                            TraveltotalSeconds  += TravelEndTimestamp - TravelStartTimestamp;
                            TraveltotalMeters   += TravelEndMeters - TravelStartMeters;
                            TravelStartTimestamp = TravelEndTimestamp = 0;
                            TravelStartMeters    = TravelEndMeters = 0;
                        }
                        if (record.localMsgDef.globalMesgIndex == FIT.FIT_MESG_NUM_RECORD && record.power > 0 && record.power != 0xFFFF)
                        {
                            PowerEndTimestamp = record.timestamp;
                            totPower         += record.power;
                            if (PowerStartTimestamp == 0)
                            {
                                PowerStartTimestamp = PowerEndTimestamp;
                            }
                        }
                        else
                        {
                            PowertotalSeconds  += PowerEndTimestamp - PowerStartTimestamp;
                            PowerStartTimestamp = PowerEndTimestamp = 0;
                        }
                    }
                }
                catch (IOException e) { break; }
                catch (Exception ex) { Console.WriteLine(ex.Message);; }
            }
            closeSession(outFile, localMesgDefs, TravelEndTimestamp);
            if (ErrorBytes != "")
            {
                outFile.WriteLine(ErrorBytes);
            }
            outFile.WriteLine(String.Format("Tijd: {0}, Afstand: {1}, Snelheid: {2}. Gem Vermogen: {3}, Calorien: {4}", new TimeSpan(0, 0, (int)TraveltotalSeconds), (TraveltotalMeters / 100000.0).ToString("0.00"), ((TraveltotalMeters / 100000.0) / (TraveltotalSeconds / 3600.0)).ToString("0.0"), PowertotalSeconds == 0 ? 0 : totPower / PowertotalSeconds, totPower / 1000.0 * 1.1));
        }
Exemple #3
0
        public fitFileReader(FileStream file, StreamWriter outFile)
        {
            string ErrorBytes = "";
            int RecordsOk = 5;
            localMsgDef[] localMesgDefs = new localMsgDef[16];
            FitRecord record = new FitRecord(file);

            long pos = file.Position = (byte)file.ReadByte() == 14 ? 14 : 12;
            UInt32 TraveltotalSeconds = 0;
            UInt32 TravelStartTimestamp = 0;
            UInt32 TravelEndTimestamp = 0;
            UInt32 TraveltotalMeters = 0;
            UInt32 TravelStartMeters = 0;
            UInt32 TravelEndMeters = 0;
            UInt32 maxSpeed = 0;
            UInt32 totPower = 0;
            UInt32 PowertotalSeconds = 0;
            UInt32 PowerStartTimestamp = 0;
            UInt32 PowerEndTimestamp = 0;

            while (true)
            {
                try
                {
                    if (RecordsOk > 5)
                        pos = file.Position;
                    string str = record.read(localMesgDefs);
                    if (str == "")
                    {
                        if (pos + 2 >= file.Length) break;
                        file.Position = pos++;
                        ErrorBytes += ((RecordsOk > 0) ? string.Format("Error at pos {0} byte:", (file.Position).ToString("X4")) : "") + file.ReadByte().ToString("X2");
                        RecordsOk = 0;
                    }
                    else
                    {
                        RecordsOk++;
                        if (ErrorBytes != "") outFile.WriteLine(ErrorBytes);
                        ErrorBytes = "";
                        outFile.WriteLine(str);
                        if (record.localMsgDef.globalMesgIndex == FIT.FIT_MESG_NUM_RECORD && record.speed > 2000)
                        {
                            TravelEndTimestamp = record.timestamp;
                            TravelEndMeters = record.distance;
                            if (TravelStartMeters == 0)
                            {
                                TravelStartTimestamp = TravelEndTimestamp;
                                TravelStartMeters = TravelEndMeters;
                            }
                        }
                        else
                        {
                            TraveltotalSeconds += TravelEndTimestamp - TravelStartTimestamp;
                            TraveltotalMeters += TravelEndMeters - TravelStartMeters;
                            TravelStartTimestamp = TravelEndTimestamp = 0;
                            TravelStartMeters = TravelEndMeters = 0;
                        }
                        if (record.localMsgDef.globalMesgIndex == FIT.FIT_MESG_NUM_RECORD && record.power > 0 && record.power != 0xFFFF)
                        {
                            PowerEndTimestamp = record.timestamp;
                            totPower += record.power;
                            if (PowerStartTimestamp == 0)
                            {
                                PowerStartTimestamp = PowerEndTimestamp;
                            }
                        }
                        else
                        {
                            PowertotalSeconds += PowerEndTimestamp - PowerStartTimestamp;
                            PowerStartTimestamp = PowerEndTimestamp = 0;
                        }

                    }
                }
                catch (IOException e) { break; }
                catch (Exception ex) { Console.WriteLine(ex.Message); ; }
            }
            closeSession(outFile, localMesgDefs, TravelEndTimestamp);
            if (ErrorBytes != "") outFile.WriteLine(ErrorBytes);
            outFile.WriteLine(String.Format("Tijd: {0}, Afstand: {1}, Snelheid: {2}. Gem Vermogen: {3}, Calorien: {4}", new TimeSpan(0, 0, (int)TraveltotalSeconds), (TraveltotalMeters / 100000.0).ToString("0.00"), ((TraveltotalMeters / 100000.0) / (TraveltotalSeconds / 3600.0)).ToString("0.0"), PowertotalSeconds == 0 ? 0 : totPower / PowertotalSeconds, totPower / 1000.0 * 1.1));
        }