示例#1
0
        public ActivitySummary Decode(Stream stream)
        {
            Debug.WriteLine("Decoding fit file");
            data = null;
            lock (_lock)
            {
                var decodeDemo      = new Fit.Decode();
                var mesgBroadcaster = new MesgBroadcaster();
                decodeDemo.MesgEvent             += mesgBroadcaster.OnMesg;
                mesgBroadcaster.SessionMesgEvent += mesgBroadcaster_SessionMesgEvent;

                var status = decodeDemo.IsFIT(stream);
                status &= decodeDemo.CheckIntegrity(stream);

                if (status)
                {
                    decodeDemo.Read(stream);
                }
                else
                {
                    decodeDemo.Read(stream);
                }
            }

            return(data);
        }
示例#2
0
        private static void Decode_Fit_File(string file)
        {
            ///// Attempt to open .FIT file
            fitSource = new FileStream(file, FileMode.Open);
            //Console.WriteLine("Opening {0}", file);

            //construction
            Decode          decoder         = new Decode();
            MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

            // Connect the Broadcaster to the event source
            decoder.MesgEvent           += mesgBroadcaster.OnMesg;
            decoder.MesgDefinitionEvent += mesgBroadcaster.OnMesgDefinition;

            //take the raw data
            mesgBroadcaster.FileIdMesgEvent += Decoders.OnFileIDMesg;
            mesgBroadcaster.RecordMesgEvent += Decoders.OnRecordMessage;

            //check and init for processing
            bool status = decoder.IsFIT(fitSource);

            status &= decoder.CheckIntegrity(fitSource);

            //the decode (here all data is created)
            if (status)
            {
                //Console.WriteLine("Decoding...");
                decoder.Read(fitSource);
                //Console.WriteLine("Successfully decoded file: {0}", file);
            }

            //close off the decoding process
            fitSource.Close();
        }
示例#3
0
        void loadGarminDeviceSettings(string driveRoot)
        {
            tNumActivities.Text = "< calculating >";
            unprocessedFiles    = new List <string>();
            lstBikeProfile.Items.Clear();
            tNoDevice.SendToBack();
            pnlRequiresProcessing.Hide();
            FileStream fitSource    = new FileStream(driveRoot + "Garmin\\Settings\\Settings.fit", FileMode.Open);
            Decode     fitSourceDec = new Decode();

            MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

            // connect the broadcaster to our event (message) source (this this case the decoder)
            fitSourceDec.MesgEvent           += mesgBroadcaster.OnMesg;
            fitSourceDec.MesgDefinitionEvent += mesgBroadcaster.OnMesgDefinition;

            // subscribe to message events of interest by connecting to the broadcaster
            //mesgBroadcaster.MesgEvent += new MesgEventHandler(OnMesg);
            //mesgBroadcaster.MesgDefinitionEvent += new MesgDefinitionEventHandler(OnMesgDefn);

            mesgBroadcaster.FileIdMesgEvent      += new MesgEventHandler(OnFileIDMesg);
            mesgBroadcaster.UserProfileMesgEvent += new MesgEventHandler(OnUserProfileMesg);
            mesgBroadcaster.BikeProfileMesgEvent += new MesgEventHandler(OnBikeProfileMesg);
            mesgBroadcaster.FileCreatorMesgEvent += new MesgEventHandler(OnFileCreatorMesg);

            bool status = fitSourceDec.IsFIT(fitSource);

            status &= fitSourceDec.CheckIntegrity(fitSource);
            if (status == true)
            {
                fitSourceDec.Read(fitSource);
            }
            else
            {
                MessageBox.Show("fit file integrity failed, attempting to read anyway");
                fitSourceDec.Read(fitSource);
            }
            fitSource.Close();

            // determine if there are any activities on the device

            string[] files = Directory.GetFiles(driveRoot + "Garmin\\Activities\\", "*.fit");
            Array.Sort(files);
            //Array.Sort(files,StringComparer.InvariantCulture);
            if (files.Length > 0)
            {
                tNumActivities.Text = files.Length.ToString();
                if (th_loadingActivities != null && th_loadingActivities.IsAlive)
                {
                    th_loadingActivities.Abort();
                }
                th_loadingActivities = new Thread(new ParameterizedThreadStart(this.ReadActivitiesOnDevice));
                th_loadingActivities.Start(driveRoot);
            }
            else
            {
                tNumActivities.Text = "0";
            }
        }
        static private void ProcessFitFile(string fileName)
        {
            try
            {
                Decode     decodeFit = new Decode();
                FileStream fitSource = new FileStream(fileName, FileMode.Open);
                // Attempt to open .FIT file

                Decode          decodeDemo      = new Decode();
                MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

                // Connect the Broadcaster to our event (message) source (in this case the Decoder)
                decodeDemo.MesgEvent += OnMesg;

                bool status = decodeDemo.IsFIT(fitSource);
                status &= decodeDemo.CheckIntegrity(fitSource);

                // Process the file
                if (status)
                {
                    decodeDemo.Read(fitSource);
                }
                else
                {
                    try
                    {
                        if (decodeDemo.InvalidDataSize)
                        {
                            decodeDemo.Read(fitSource);
                        }
                        else
                        {
                            decodeDemo.Read(fitSource, DecodeMode.InvalidHeader);
                        }
                    }
                    catch (FitException ex)
                    {
                    }
                }
                fitSource.Close();

                int totalMesgs = 0;
                foreach (KeyValuePair <ushort, int> pair in mesgCounts)
                {
                    totalMesgs += pair.Value;
                }
            }
            catch (FitException ex)
            {
                Console.WriteLine("A FitException occurred when trying to decode the FIT file. Message: " + ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occurred when trying to decode the FIT file. Message: " + ex.Message);
            }
        }
示例#5
0
        internal static Tcx ReadFitFileIntoTcxObject(string fitFile)
        {
            // Attempt to open .FIT file
            FileStream fitSource = new FileStream(fitFile, FileMode.Open);

            Console.WriteLine("Opening {0}", fitFile);

            Decode decodeDemo = new Decode();

            MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

            // Connect the Broadcaster to our event (message) source (in this case the Decoder)
            decodeDemo.MesgEvent           += mesgBroadcaster.OnMesg;
            decodeDemo.MesgDefinitionEvent += mesgBroadcaster.OnMesgDefinition;


            // Subscribe to message events of interest by connecting to the Broadcaster
            mesgBroadcaster.MesgEvent           += new MesgEventHandler(OnMesg);
            mesgBroadcaster.MesgDefinitionEvent += new MesgDefinitionEventHandler(OnMesgDefn);

            mesgBroadcaster.FileIdMesgEvent      += new MesgEventHandler(OnFileIDMesg);
            mesgBroadcaster.UserProfileMesgEvent += new MesgEventHandler(OnUserProfileMesg);

            mesgBroadcaster.TotalsMesgEvent += new MesgEventHandler(OnTotals);

            mesgBroadcaster.WorkoutMesgEvent += new MesgEventHandler(OnWorkoutMesgEvent);

            mesgBroadcaster.SessionMesgEvent += new MesgEventHandler(OnSessionMesgEvent);

            bool status = decodeDemo.IsFIT(fitSource);

            status &= decodeDemo.CheckIntegrity(fitSource);
            // Process the file
            if (status == true)
            {
                Console.WriteLine("Decoding...");
                try { decodeDemo.Read(fitSource); } catch {}
                Console.WriteLine("Decoded FIT file {0}", fitFile);
            }
            else
            {
                Console.WriteLine("Integrity Check Failed {0}", fitFile);
                Console.WriteLine("Attempting to decode...");
                try { decodeDemo.Read(fitSource); }
                catch { }
            }
            fitSource.Close();

            return(tcx);
        }
示例#6
0
        private void convertFilesGarmin()
        {
            int        result;
            string     gcUploadFileName = "GCupload.fit";
            HttpGarmin garminUpload     = new HttpGarmin(txtGarminUsername.Text, txtGarminPassword.Text, gcUploadFileName);

            result = garminUpload.GarminLogin();

            foreach (string sourceFile in Directory.GetFiles(txtSource.Text, "*.fit"))
            {
                string sourceFileName  = Path.GetFileName(sourceFile);
                string destinationFile = txtDestination.Text + "\\" + sourceFileName;
                string archiveFile     = txtArchive.Text + "\\" + sourceFileName;
                string gcUploadFile    = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\" + gcUploadFileName;

                fitSource = new FileStream(sourceFile, FileMode.Open);

                Decode          GD3decoder      = new Decode();
                MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

                GD3encoder = new Encode(ProtocolVersion.V20);
                fitDest    = new FileStream(destinationFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
                GD3encoder.Open(fitDest);

                GD3decoder.MesgEvent += mesgBroadcaster.OnMesg;

                mesgBroadcaster.MesgEvent += OnMesg;

                bool status = GD3decoder.IsFIT(fitSource);
                status &= GD3decoder.CheckIntegrity(fitSource);

                if (status)
                {
                    GD3decoder.Read(fitSource);
                }

                fitSource.Close();
                GD3encoder.Close();
                fitDest.Close();

                System.IO.File.Move(sourceFile, archiveFile);

                System.IO.File.Copy(destinationFile, gcUploadFile, true);
                result = garminUpload.GarminUpload();
                System.IO.File.Delete(gcUploadFile);
            }

            result = garminUpload.GarminLogout();
        }
示例#7
0
        public Boolean DecodeFile(FileStream fitSource)
        {
            Decode          decoder     = new Decode();
            MesgBroadcaster Broadcaster = new MesgBroadcaster();

            decoder.MesgEvent           += Broadcaster.OnMesg;
            decoder.MesgDefinitionEvent += Broadcaster.OnMesgDefinition;

            //add HrMesg listener HeartRateMesgListener
            Broadcaster.RecordMesgEvent  += HeartRateMesgListener.MesgEvent;
            Broadcaster.SessionMesgEvent += ElapsedTimeMesgListener.MesgEvent;

            Boolean status = decoder.IsFIT(fitSource);

            status &= decoder.CheckIntegrity(fitSource);

            Boolean DecodeResult;

            if (status)
            {
                HeartRateLogger.Instance.Reset();
                DecodeResult = decoder.Read(fitSource);
            }
            else
            {
                try
                {
                    Console.WriteLine("Integrity Check Failed {0}", fitSource.Name);
                    if (decoder.InvalidDataSize)
                    {
                        Console.WriteLine("Invalid Size Detected, Attempting to decode...");
                        DecodeResult = decoder.Read(fitSource);
                    }
                    else
                    {
                        Console.WriteLine("Attempting to decode by skipping the header...");
                        DecodeResult = decoder.Read(fitSource, DecodeMode.InvalidHeader);
                    }
                }
                catch (FitException ex)
                {
                    Console.WriteLine("DecodeDemo caught FitException: " + ex.Message);
                    DecodeResult = false;
                }
            }
            fitSource.Dispose();
            return(DecodeResult);
        }
示例#8
0
        public FitImporter(MemoryActivity activity)
            : base(activity)
        {
            Decoder            = new Decode();
            MessageBroadcaster = new MesgBroadcaster();

            // Connect the Broadcaster to our event (message) source (in this case the Decoder)
            Decoder.MesgEvent           += MessageBroadcaster.OnMesg;
            Decoder.MesgDefinitionEvent += MessageBroadcaster.OnMesgDefinition;

            // Subscribe to message events of interest by connecting to the Broadcaster
            MessageBroadcaster.SessionMesgEvent    += MessageBroadcaster_SessionMesgEvent;
            MessageBroadcaster.RecordMesgEvent     += MessageBroadcaster_RecordMesgEvent;
            MessageBroadcaster.EventMesgEvent      += MessageBroadcaster_EventMesgEvent;
            MessageBroadcaster.LapMesgEvent        += MessageBroadcaster_LapMesgEvent;
            MessageBroadcaster.DeviceInfoMesgEvent += MessageBroadcaster_DeviceInfoMesgEvent;
            MessageBroadcaster.FileIdMesgEvent     += MessageBroadcaster_FileIdMesgEvent;
        }
示例#9
0
        public Boolean EncodeFile(FileStream fitSource, FileStream fitDest)
        {
            Encoder.Open(fitDest);
            Decode          decoder     = new Decode();
            MesgBroadcaster Broadcaster = new MesgBroadcaster();

            decoder.MesgEvent           += Broadcaster.OnMesg;
            decoder.MesgDefinitionEvent += Broadcaster.OnMesgDefinition;
            Broadcaster.MesgEvent       += PowerEncodeListener.MesgEvent;

            Boolean DecodeResult = false;

            try {
                DecodeResult = decoder.Read(fitSource);
            }catch (Exception e) {
                Console.WriteLine("ERROR ENCODING");
                Console.WriteLine(e.InnerException);
            }
            Encoder.Close();
            fitSource.Close();
            fitDest.Close();
            return(DecodeResult);
        }
示例#10
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            Console.WriteLine("FIT Decode Example Application");

            if (args.Length != 1)
            {
                Console.WriteLine("Usage: decode.exe <filename>");
                return;
            }

            try
            {
                // Attempt to open .FIT file
                fitSource = new FileStream(args[0], FileMode.Open);
                Console.WriteLine("Opening {0}", args[0]);

                Decode          decodeDemo      = new Decode();
                MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

                // Connect the Broadcaster to our event (message) source (in this case the Decoder)
                decodeDemo.MesgEvent                      += mesgBroadcaster.OnMesg;
                decodeDemo.MesgDefinitionEvent            += mesgBroadcaster.OnMesgDefinition;
                decodeDemo.DeveloperFieldDescriptionEvent += OnDeveloperFieldDescriptionEvent;

                // Subscribe to message events of interest by connecting to the Broadcaster
                mesgBroadcaster.MesgEvent           += OnMesg;
                mesgBroadcaster.MesgDefinitionEvent += OnMesgDefn;

                mesgBroadcaster.FileIdMesgEvent      += OnFileIDMesg;
                mesgBroadcaster.UserProfileMesgEvent += OnUserProfileMesg;
                mesgBroadcaster.MonitoringMesgEvent  += OnMonitoringMessage;
                mesgBroadcaster.DeviceInfoMesgEvent  += OnDeviceInfoMessage;
                mesgBroadcaster.RecordMesgEvent      += OnRecordMessage;

                bool status = decodeDemo.IsFIT(fitSource);
                status &= decodeDemo.CheckIntegrity(fitSource);

                // Process the file
                if (status)
                {
                    Console.WriteLine("Decoding...");
                    decodeDemo.Read(fitSource);
                    Console.WriteLine("Decoded FIT file {0}", args[0]);
                }
                else
                {
                    try
                    {
                        Console.WriteLine("Integrity Check Failed {0}", args[0]);
                        if (decodeDemo.InvalidDataSize)
                        {
                            Console.WriteLine("Invalid Size Detected, Attempting to decode...");
                            decodeDemo.Read(fitSource);
                        }
                        else
                        {
                            Console.WriteLine("Attempting to decode by skipping the header...");
                            decodeDemo.Read(fitSource, DecodeMode.InvalidHeader);
                        }
                    }
                    catch (FitException ex)
                    {
                        Console.WriteLine("DecodeDemo caught FitException: " + ex.Message);
                    }
                }
                fitSource.Close();

                Console.WriteLine("");
                Console.WriteLine("Summary:");
                int totalMesgs = 0;
                foreach (KeyValuePair <ushort, int> pair in mesgCounts)
                {
                    Console.WriteLine("MesgID {0,3} Count {1}", pair.Key, pair.Value);
                    totalMesgs += pair.Value;
                }

                Console.WriteLine("{0} Message Types {1} Total Messages", mesgCounts.Count, totalMesgs);

                stopwatch.Stop();
                Console.WriteLine("");
                Console.WriteLine("Time elapsed: {0:0.#}s", stopwatch.Elapsed.TotalSeconds);
                Console.ReadKey();
            }
            catch (FitException ex)
            {
                Console.WriteLine("A FitException occurred when trying to decode the FIT file. Message: " + ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occurred when trying to decode the FIT file. Message: " + ex.Message);
            }
        }
示例#11
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            Console.WriteLine("FIT Decode Example Application");

            if (args.Length != 1)
            {
                Console.WriteLine("Usage: decode.exe <filename>");
                return;
            }

            try
            {
                // Attempt to open .FIT file
                fitSource = new FileStream(args[0], FileMode.Open);
                Console.WriteLine("Opening {0}", args[0]);

                Decode          decoder         = new Decode();
                MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

                // Connect the Broadcaster to our event (message) source (in this case the Decoder)
                decoder.MesgEvent                      += mesgBroadcaster.OnMesg;
                decoder.MesgDefinitionEvent            += mesgBroadcaster.OnMesgDefinition;
                decoder.DeveloperFieldDescriptionEvent += OnDeveloperFieldDescriptionEvent;

                // Subscribe to message events of interest by connecting to the Broadcaster
                mesgBroadcaster.MesgEvent           += OnMesg;
                mesgBroadcaster.MesgDefinitionEvent += OnMesgDefn;

                /*
                 * mesgBroadcaster.FileIdMesgEvent += OnFileIDMesg;
                 * mesgBroadcaster.UserProfileMesgEvent += OnUserProfileMesg;
                 * mesgBroadcaster.MonitoringMesgEvent += OnMonitoringMessage;
                 * mesgBroadcaster.DeviceInfoMesgEvent += OnDeviceInfoMessage;
                 * mesgBroadcaster.RecordMesgEvent += OnRecordMessage;
                 */
                mesgBroadcaster.AccelerometerDataMesgEvent           += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.ActivityMesgEvent                    += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.AntChannelIdMesgEvent                += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.AntRxMesgEvent                       += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.AntTxMesgEvent                       += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.AviationAttitudeMesgEvent            += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.BarometerDataMesgEvent               += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.BikeProfileMesgEvent                 += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.BloodPressureMesgEvent               += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.CadenceZoneMesgEvent                 += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.CameraEventMesgEvent                 += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.CapabilitiesMesgEvent                += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.ConnectivityMesgEvent                += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.CourseMesgEvent                      += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.CoursePointMesgEvent                 += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.DeveloperDataIdMesgEvent             += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.DeviceInfoMesgEvent                  += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.DeviceSettingsMesgEvent              += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.DiveAlarmMesgEvent                   += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.DiveGasMesgEvent                     += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.DiveSettingsMesgEvent                += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.DiveSummaryMesgEvent                 += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.EventMesgEvent                       += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.ExdDataConceptConfigurationMesgEvent += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.ExdDataFieldConfigurationMesgEvent   += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.ExdScreenConfigurationMesgEvent      += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.ExerciseTitleMesgEvent               += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.FieldCapabilitiesMesgEvent           += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.FieldDescriptionMesgEvent            += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.FileCapabilitiesMesgEvent            += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.FileCreatorMesgEvent                 += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.FileIdMesgEvent                      += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.GoalMesgEvent                    += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.GpsMetadataMesgEvent             += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.GyroscopeDataMesgEvent           += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.HrMesgEvent                      += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.HrmProfileMesgEvent              += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.HrvMesgEvent                     += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.HrZoneMesgEvent                  += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.LapMesgEvent                     += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.LengthMesgEvent                  += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.MagnetometerDataMesgEvent        += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.MemoGlobMesgEvent                += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.MesgCapabilitiesMesgEvent        += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.MetZoneMesgEvent                 += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.MonitoringInfoMesgEvent          += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.MonitoringMesgEvent              += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.NmeaSentenceMesgEvent            += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.ObdiiDataMesgEvent               += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.OhrSettingsMesgEvent             += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.OneDSensorCalibrationMesgEvent   += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.PadMesgEvent                     += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.PowerZoneMesgEvent               += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.RecordMesgEvent                  += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.ScheduleMesgEvent                += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SdmProfileMesgEvent              += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SegmentFileMesgEvent             += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SegmentIdMesgEvent               += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SegmentLapMesgEvent              += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SegmentLeaderboardEntryMesgEvent += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SegmentPointMesgEvent            += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SessionMesgEvent                 += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SetMesgEvent                     += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SlaveDeviceMesgEvent             += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SoftwareMesgEvent                += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SpeedZoneMesgEvent               += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.SportMesgEvent                   += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.StressLevelMesgEvent             += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.ThreeDSensorCalibrationMesgEvent += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.TimestampCorrelationMesgEvent    += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.TotalsMesgEvent                  += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.TrainingFileMesgEvent            += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.UserProfileMesgEvent             += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.VideoClipMesgEvent               += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.VideoDescriptionMesgEvent        += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.VideoFrameMesgEvent              += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.VideoMesgEvent                   += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.VideoTitleMesgEvent              += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.WatchfaceSettingsMesgEvent       += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.WeatherAlertMesgEvent            += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.WeatherConditionsMesgEvent       += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.WeightScaleMesgEvent             += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.WorkoutMesgEvent                 += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.WorkoutSessionMesgEvent          += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.WorkoutStepMesgEvent             += MesgBroadcaster_GeneralMesgEvent;
                mesgBroadcaster.ZonesTargetMesgEvent             += MesgBroadcaster_GeneralMesgEvent;



                bool status = decoder.IsFIT(fitSource);
                status &= decoder.CheckIntegrity(fitSource);

                // Process the file
                if (status)
                {
                    Console.WriteLine("Decoding...");
                    decoder.Read(fitSource);
                    Console.WriteLine("Decoded FIT file {0}", args[0]);
                }
                else
                {
                    try
                    {
                        Console.WriteLine("Integrity Check Failed {0}", args[0]);
                        if (decoder.InvalidDataSize)
                        {
                            Console.WriteLine("Invalid Size Detected, Attempting to decode...");
                            decoder.Read(fitSource);
                        }
                        else
                        {
                            Console.WriteLine("Attempting to decode by skipping the header...");
                            decoder.Read(fitSource, DecodeMode.InvalidHeader);
                        }
                    }
                    catch (FitException ex)
                    {
                        Console.WriteLine("DecodeDemo caught FitException: " + ex.Message);
                    }
                }
                fitSource.Close();

                Console.WriteLine("");
                Console.WriteLine("Summary:");
                int totalMesgs = 0;
                foreach (KeyValuePair <ushort, int> pair in mesgCounts)
                {
                    Console.WriteLine("MesgID {0,3} Count {1}", pair.Key, pair.Value);
                    totalMesgs += pair.Value;
                }

                Console.WriteLine("{0} Message Types {1} Total Messages", mesgCounts.Count, totalMesgs);

                stopwatch.Stop();
                Console.WriteLine("");
                Console.WriteLine("Time elapsed: {0:0.#}s", stopwatch.Elapsed.TotalSeconds);
                Console.ReadKey();
            }
            catch (FitException ex)
            {
                Console.WriteLine("A FitException occurred when trying to decode the FIT file. Message: " + ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occurred when trying to decode the FIT file. Message: " + ex.Message);
            }
        }
示例#12
0
    public bool Decode()
    {
        // Create the Decode Object
        Decode decoder = new Decode();

        // Check that this is a FIT file
        if (!decoder.IsFIT(inputStream))
        {
            throw new FileTypeException($"Expected FIT File Type: {fileType}, received a non FIT file.");
        }

        // Create the Message Broadcaster Object
        MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

        // Connect the the Decode and Message Broadcaster Objects
        decoder.MesgEvent                      += mesgBroadcaster.OnMesg;
        decoder.MesgDefinitionEvent            += mesgBroadcaster.OnMesgDefinition;
        decoder.DeveloperFieldDescriptionEvent += OnDeveloperFieldDescriptionEvent;

        // Connect the Message Broadcaster Events to the Message Listener Delegates
        mesgBroadcaster.ActivityMesgEvent    += OnActivityMesg;
        mesgBroadcaster.ClimbProMesgEvent    += OnClimbProMesg;
        mesgBroadcaster.CourseMesgEvent      += OnCourseMesg;
        mesgBroadcaster.CoursePointMesgEvent += OnCoursePointMesg;
        mesgBroadcaster.DeviceInfoMesgEvent  += OnDeviceInfoMesg;
        mesgBroadcaster.EventMesgEvent       += OnEventMesg;
        mesgBroadcaster.FileIdMesgEvent      += OnFileIdMesg;
        mesgBroadcaster.HrMesgEvent          += OnHrMesg;
        mesgBroadcaster.HrvMesgEvent         += OnHrvMesg;
        mesgBroadcaster.LapMesgEvent         += OnLapMesg;
        mesgBroadcaster.LengthMesgEvent      += OnLengthMesg;
        mesgBroadcaster.RecordMesgEvent      += OnRecordMesg;
        mesgBroadcaster.SegmentLapMesgEvent  += OnSegmentLapMesg;
        mesgBroadcaster.SessionMesgEvent     += OnSessionMesg;
        mesgBroadcaster.UserProfileMesgEvent += OnUserProfileMesg;
        mesgBroadcaster.WorkoutMesgEvent     += OnWorkoutMesg;
        mesgBroadcaster.WorkoutStepMesgEvent += OnWorkoutStepMesg;
        mesgBroadcaster.ZonesTargetMesgEvent += OnZonesTargetMesg;

        // Decode the FIT File
        try
        {
            bool readOK = decoder.Read(inputStream);

            // If there are HR messages, merge the heart-rate data with the Record messages.
            if (readOK && Messages.HeartRates.Count > 0)
            {
                HrToRecordMesgWithoutPlugin.MergeHeartRates(Messages);
            }

            return(readOK);
        }
        catch (FileTypeException ex)
        {
            throw (ex);
        }
        catch (FitException ex)
        {
            throw (ex);
        }
        catch (System.Exception ex)
        {
            throw (ex);
        }
        finally
        {
        }
    }
示例#13
0
        void ReadActivitiesOnDevice(object driveRoot)
        {
            if (pnlLoadingActivities.InvokeRequired)
            {
                pnlLoadingActivities.Invoke(new MethodInvoker(pnlLoadingActivities.BringToFront));
            }
            ClearListView(lstDeviceActivities);

            string[] files = Directory.GetFiles((string)driveRoot + "Garmin\\Activities\\", "*.fit").OrderByDescending(d => new FileInfo(d).CreationTime).ToArray();

            SetControlPropertyThreadSafe(prgReadingActivities, "Value", 0);
            SetControlPropertyThreadSafe(prgReadingActivities, "Maximum", files.Length);
            SetControlPropertyThreadSafe(prgReadingActivities, "Step", 1);
            if (files.Length > 0)
            {
                unprocessedCount = 0;
                for (int f = 0; f < files.Length; f++)
                {
                    curDeviceFile = files[f];
                    FileStream      fitFile             = new FileStream(files[f], FileMode.Open);
                    Decode          fitFileDec          = new Decode();
                    MesgBroadcaster fileMesgBroadcaster = new MesgBroadcaster();

                    // connect the broadcaster to our event (message) source (this this case the decoder)
                    fitFileDec.MesgEvent                 += fileMesgBroadcaster.OnMesg;
                    fitFileDec.MesgDefinitionEvent       += fileMesgBroadcaster.OnMesgDefinition;
                    fileMesgBroadcaster.SessionMesgEvent += new MesgEventHandler(OnSessionMesg);

                    bool statusFile = fitFileDec.IsFIT(fitFile);
                    statusFile &= fitFileDec.CheckIntegrity(fitFile);
                    if (statusFile == true)
                    {
                        fitFileDec.Read(fitFile);
                    }
                    else
                    {
                        MessageBox.Show("fit file integrity failed, attempting to read anyway");
                        fitFileDec.Read(fitFile);
                    }

                    //lstDeviceActivities.Items[lstDeviceActivities.Items.Count-1].SubItems[14].Text = files[f];
                    fitFile.Close();
                    SetControlPropertyThreadSafe(prgReadingActivities, "Value", f + 1);
                }
                if (unprocessedCount > 0)
                {
                    SetControlPropertyThreadSafe(pnlRequiresProcessing, "Visible", true);
                }
                else
                {
                    SetControlPropertyThreadSafe(pnlRequiresProcessing, "Visible", false);
                }
            }
            ResizeListView(lstDeviceActivities);
            //SetListViewColumnWidth(lstDeviceActivities,0,0);
            SetListViewColumnWidth(lstDeviceActivities, 14, 0);
            SetListViewColumnWidth(lstDeviceActivities, 15, 0);
            if (lstDeviceActivities.InvokeRequired)
            {
                lstDeviceActivities.Invoke(new MethodInvoker(lstDeviceActivities.BringToFront));
            }
        }
示例#14
0
        public void Foo()
        {
            using (var fitDest = new FileStream("Test.fit", FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
            {
                Encoder = new Encode();
                // Write our header
                Encoder.Open(fitDest);

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                logger.Trace("FIT Decode Example Application");

                //if (args.Length != 1)
                //{
                //   logger.Trace("Usage: decode.exe <filename>");
                //   return;
                //}

                // Attempt to open .FIT file
                var fileName = "B1.fit";
                fitSource = new FileStream(fileName, FileMode.Open);
                logger.Trace("Opening {0}", fileName);

                Decode          decodeDemo      = new Decode();
                MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

                // Connect the Broadcaster to our event (message) source (in this case the Decoder)
                decodeDemo.MesgEvent           += mesgBroadcaster.OnMesg;
                decodeDemo.MesgDefinitionEvent += mesgBroadcaster.OnMesgDefinition;

                // Subscribe to message events of interest by connecting to the Broadcaster
                mesgBroadcaster.MesgEvent           += new MesgEventHandler(OnMesg);
                mesgBroadcaster.MesgDefinitionEvent += new MesgDefinitionEventHandler(OnMesgDefn);

                mesgBroadcaster.FileIdMesgEvent      += new MesgEventHandler(OnFileIDMesg);
                mesgBroadcaster.UserProfileMesgEvent += new MesgEventHandler(OnUserProfileMesg);

                bool status = decodeDemo.IsFIT(fitSource);
                status &= decodeDemo.CheckIntegrity(fitSource);
                // Process the file
                if (status == true)
                {
                    logger.Trace("Decoding...");
                    decodeDemo.Read(fitSource);
                    logger.Trace("Decoded FIT file {0}", fileName);
                }
                else
                {
                    try
                    {
                        logger.Trace("Integrity Check Failed {0}", fileName);
                        logger.Trace("Attempting to decode...");
                        decodeDemo.Read(fitSource);
                    }
                    catch (FitException ex)
                    {
                        logger.Trace("DecodeDemo caught FitException: " + ex.Message);
                    }
                }
                fitSource.Close();

                Encoder.Close();

                logger.Trace("");
                logger.Trace("Summary:");
                int totalMesgs = 0;
                foreach (KeyValuePair <ushort, int> pair in mesgCounts)
                {
                    logger.Trace("MesgID {0,3} Count {1}", pair.Key, pair.Value);
                    totalMesgs += pair.Value;
                }

                logger.Trace("{0} Message Types {1} Total Messages", mesgCounts.Count, totalMesgs);

                stopwatch.Stop();
                logger.Trace("");
                logger.Trace("Time elapsed: {0:0.#}s", stopwatch.Elapsed.TotalSeconds);
            }

            Console.ReadKey();
        }
示例#15
0
        private void TestActivityFitFile(string filename, int expectedTotalMessages, int expectedTotalDefinitions)
        {
            // Read the answer CSV file
            var file = FitParserHelpers.ReadFitCsvFile(TESTDATA_PATH + filename + ".csv");

            // Decode a Fit file
            var fileStream = System.IO.File.OpenRead(TESTDATA_PATH + filename + ".fit");

            Assert.IsNotNull(fileStream);

            var decode = new Decode();

            Assert.IsNotNull(decode);

            var mesgBroadcaster = new MesgBroadcaster();

            Assert.IsNotNull(mesgBroadcaster);

            Assert.IsTrue(decode.IsFIT(fileStream));

            // Note that it is possible to have something that fails an integrity check, but we can still attempt to parse it
            Assert.IsTrue(decode.CheckIntegrity(fileStream));

            // Connect the Broadcaster to our event (message) source (in this case the Decoder)
            decode.MesgEvent           += mesgBroadcaster.OnMesg;
            decode.MesgDefinitionEvent += mesgBroadcaster.OnMesgDefinition;

            int totalMessages = 0, totalDefinitions = 0;
            int currentRecord = 0;

            mesgBroadcaster.MesgEvent += (sender, args) =>
            {
                foreach (var field in args.mesg.fields)
                {
                    string fieldName             = FitParserHelpers.ConvertPascalCaseToRubyCase(field.Name);
                    var    record                = file.Records[currentRecord];
                    string fieldValue            = ConvertField(field.GetValue()).ToString();
                    var    csvField              = record.GetField(fieldName);
                    string diagnosticFieldString = FormatFieldString(currentRecord, record, args.mesg.fields);
                    Assert.IsNotNull(csvField, diagnosticFieldString);
                    Assert.AreEqual(csvField.Value.ToString(), fieldValue, diagnosticFieldString);
                }
                totalMessages++;
                currentRecord++;
            };

            mesgBroadcaster.MesgDefinitionEvent += (sender, args) =>
            {
                foreach (var field in args.mesgDef.GetFields())
                {
                    var record = file.Records[currentRecord];
                }
                totalDefinitions++;
                currentRecord++;
            };

            Assert.IsTrue(decode.Read(fileStream));
            Assert.AreEqual(expectedTotalMessages, totalMessages);
            Assert.AreEqual(expectedTotalDefinitions, totalDefinitions);

            fileStream.Close();
        }
示例#16
0
        public void Decode(string fileName)
        {
            try
            {
                // Attempt to open .FIT file
                _fitSource = new FileStream(fileName, FileMode.Open);

                Decode          decodeDemo      = new Decode();
                MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

                // Connect the Broadcaster to our event (message) source (in this case the Decoder)
                decodeDemo.MesgEvent += mesgBroadcaster.OnMesg;
                // Subscribe to message events of interest by connecting to the Broadcaster
                mesgBroadcaster.MesgEvent += OnMesg;

                mesgBroadcaster.ActivityMesgEvent         += ActivityValues.OnActivityMesg;
                mesgBroadcaster.DeveloperDataIdMesgEvent  += DeveloperDataIdValues.OnDeveloperDataIdMesg;
                mesgBroadcaster.DeviceInfoMesgEvent       += DeviceInfoValues.OnDeviceInfoMesg;
                mesgBroadcaster.FieldDescriptionMesgEvent += FieldDescriptionValues.OnFieldDescriptionMesg;
                mesgBroadcaster.FileIdMesgEvent           += FileIdValues.OnFileIDMesg;
                mesgBroadcaster.EventMesgEvent            += EventValues.OnEventMesg;
                mesgBroadcaster.SportMesgEvent            += SportValues.OnSportMesg;
                mesgBroadcaster.WorkoutMesgEvent          += WorkoutValues.OnWorkoutMesg;
                //mesgBroadcaster.HrZoneMesgEvent += HRZonesManager.OnMesg;

                bool status = decodeDemo.IsFIT(_fitSource);
                status &= decodeDemo.CheckIntegrity(_fitSource);

                // Process the file
                if (status)
                {
                    //Console.WriteLine("Decoding...");
                    decodeDemo.Read(_fitSource);
                    //Console.WriteLine("Decoded FIT file {0}", args[0]);
                }
                else
                {
                    try
                    {
                        //Console.WriteLine("Integrity Check Failed {0}", args[0]);
                        if (decodeDemo.InvalidDataSize)
                        {
                            //Console.WriteLine("Invalid Size Detected, Attempting to decode...");
                            decodeDemo.Read(_fitSource);
                        }
                        else
                        {
                            //Console.WriteLine("Attempting to decode by skipping the header...");
                            decodeDemo.Read(_fitSource, DecodeMode.InvalidHeader);
                        }
                    }
                    catch (FitException ex)
                    {
                        MessageBox.Show("Decode caught FitException: " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //Console.WriteLine("DecodeDemo caught FitException: " + ex.Message);
                    }
                }
                _fitSource.Close();
            }
            catch (FitException ex)
            {
                MessageBox.Show("A FitException occurred when trying to decode the FIT file. Message: " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Console.WriteLine("A FitException occurred when trying to decode the FIT file. Message: " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception occurred when trying to decode the FIT file. Message: " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Console.WriteLine("Exception occurred when trying to decode the FIT file. Message: " + ex.Message);
            }
            finally
            {
            }
        }
示例#17
0
        public override void Decode(string filePath)
        {
            Decode          decoder         = new Decode();
            MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

            decoder.MesgEvent           += mesgBroadcaster.OnMesg;
            decoder.MesgDefinitionEvent += mesgBroadcaster.OnMesgDefinition;

            mesgBroadcaster.AccelerometerDataMesgEvent           += Write;
            mesgBroadcaster.ActivityMesgEvent                    += Write;
            mesgBroadcaster.AntChannelIdMesgEvent                += Write;
            mesgBroadcaster.AntRxMesgEvent                       += Write;
            mesgBroadcaster.AntTxMesgEvent                       += Write;
            mesgBroadcaster.AviationAttitudeMesgEvent            += Write;
            mesgBroadcaster.BarometerDataMesgEvent               += Write;
            mesgBroadcaster.BikeProfileMesgEvent                 += Write;
            mesgBroadcaster.BloodPressureMesgEvent               += Write;
            mesgBroadcaster.CadenceZoneMesgEvent                 += Write;
            mesgBroadcaster.CameraEventMesgEvent                 += Write;
            mesgBroadcaster.CapabilitiesMesgEvent                += Write;
            mesgBroadcaster.ClimbProMesgEvent                    += Write;
            mesgBroadcaster.ConnectivityMesgEvent                += Write;
            mesgBroadcaster.CourseMesgEvent                      += Write;
            mesgBroadcaster.CoursePointMesgEvent                 += Write;
            mesgBroadcaster.DeveloperDataIdMesgEvent             += Write;
            mesgBroadcaster.DeviceInfoMesgEvent                  += Write;
            mesgBroadcaster.DeviceSettingsMesgEvent              += Write;
            mesgBroadcaster.DiveAlarmMesgEvent                   += Write;
            mesgBroadcaster.DiveGasMesgEvent                     += Write;
            mesgBroadcaster.DiveSettingsMesgEvent                += Write;
            mesgBroadcaster.DiveSummaryMesgEvent                 += Write;
            mesgBroadcaster.EventMesgEvent                       += Write;
            mesgBroadcaster.ExdDataConceptConfigurationMesgEvent += Write;
            mesgBroadcaster.ExdDataFieldConfigurationMesgEvent   += Write;
            mesgBroadcaster.ExdScreenConfigurationMesgEvent      += Write;
            mesgBroadcaster.ExerciseTitleMesgEvent               += Write;
            mesgBroadcaster.FieldCapabilitiesMesgEvent           += Write;
            mesgBroadcaster.FieldDescriptionMesgEvent            += Write;
            mesgBroadcaster.FileCapabilitiesMesgEvent            += Write;
            mesgBroadcaster.FileCreatorMesgEvent                 += Write;
            mesgBroadcaster.FileIdMesgEvent                      += Write;
            mesgBroadcaster.GoalMesgEvent             += Write;
            mesgBroadcaster.GpsMetadataMesgEvent      += Write;
            mesgBroadcaster.GyroscopeDataMesgEvent    += Write;
            mesgBroadcaster.HrMesgEvent               += Write;
            mesgBroadcaster.HrmProfileMesgEvent       += Write;
            mesgBroadcaster.HrvMesgEvent              += Write;
            mesgBroadcaster.HrZoneMesgEvent           += Write;
            mesgBroadcaster.JumpMesgEvent             += Write;
            mesgBroadcaster.LapMesgEvent              += Write;
            mesgBroadcaster.LengthMesgEvent           += Write;
            mesgBroadcaster.MagnetometerDataMesgEvent += Write;
            mesgBroadcaster.MemoGlobMesgEvent         += Write;
            mesgBroadcaster.MesgCapabilitiesMesgEvent += Write;
            mesgBroadcaster.MesgEvent                        += Write;
            mesgBroadcaster.MetZoneMesgEvent                 += Write;
            mesgBroadcaster.MonitoringInfoMesgEvent          += Write;
            mesgBroadcaster.MonitoringMesgEvent              += Write;
            mesgBroadcaster.NmeaSentenceMesgEvent            += Write;
            mesgBroadcaster.ObdiiDataMesgEvent               += Write;
            mesgBroadcaster.OhrSettingsMesgEvent             += Write;
            mesgBroadcaster.OneDSensorCalibrationMesgEvent   += Write;
            mesgBroadcaster.PadMesgEvent                     += Write;
            mesgBroadcaster.PowerZoneMesgEvent               += Write;
            mesgBroadcaster.RecordMesgEvent                  += Write;
            mesgBroadcaster.ScheduleMesgEvent                += Write;
            mesgBroadcaster.SdmProfileMesgEvent              += Write;
            mesgBroadcaster.SegmentFileMesgEvent             += Write;
            mesgBroadcaster.SegmentIdMesgEvent               += Write;
            mesgBroadcaster.SegmentLapMesgEvent              += Write;
            mesgBroadcaster.SegmentLeaderboardEntryMesgEvent += Write;
            mesgBroadcaster.SegmentPointMesgEvent            += Write;
            mesgBroadcaster.SessionMesgEvent                 += Write;
            mesgBroadcaster.SlaveDeviceMesgEvent             += Write;
            mesgBroadcaster.SoftwareMesgEvent                += Write;
            mesgBroadcaster.SpeedZoneMesgEvent               += Write;
            mesgBroadcaster.SportMesgEvent                   += Write;
            mesgBroadcaster.StressLevelMesgEvent             += Write;
            mesgBroadcaster.ThreeDSensorCalibrationMesgEvent += Write;
            mesgBroadcaster.TimestampCorrelationMesgEvent    += Write;
            mesgBroadcaster.TotalsMesgEvent                  += Write;
            mesgBroadcaster.TrainingFileMesgEvent            += Write;
            mesgBroadcaster.UserProfileMesgEvent             += Write;
            mesgBroadcaster.VideoClipMesgEvent               += Write;
            mesgBroadcaster.VideoDescriptionMesgEvent        += Write;
            mesgBroadcaster.VideoFrameMesgEvent              += Write;
            mesgBroadcaster.VideoMesgEvent                   += Write;
            mesgBroadcaster.VideoTitleMesgEvent              += Write;
            mesgBroadcaster.WatchfaceSettingsMesgEvent       += Write;
            mesgBroadcaster.WeatherAlertMesgEvent            += Write;
            mesgBroadcaster.WeatherConditionsMesgEvent       += Write;
            mesgBroadcaster.WeightScaleMesgEvent             += Write;
            mesgBroadcaster.WorkoutMesgEvent                 += Write;
            mesgBroadcaster.WorkoutSessionMesgEvent          += Write;
            mesgBroadcaster.WorkoutStepMesgEvent             += Write;
            mesgBroadcaster.ZonesTargetMesgEvent             += Write;

            FileStream fitDest = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);

            decoder.Read(fitDest);
        }
示例#18
0
        /// <summary>
        /// Loads a FIT file.
        /// </summary>
        /// <param name="fileName">Full path to the FIT file to be opened.</param>
        public void Load(string fileName)
        {
            try
            {
                // save the file name
                FileName = fileName;

                // clear any existing laps and records
                Laps.Clear();
                Records.Clear();

                // create the decoder and broadcaster
                Decode          decoder        = new Decode();
                MesgBroadcaster msgBroadcaster = new MesgBroadcaster();

                // connect the decoder to the broadcaster
                decoder.MesgEvent           += msgBroadcaster.OnMesg;
                decoder.MesgDefinitionEvent += msgBroadcaster.OnMesgDefinition;

                // connect the message event handlers
                msgBroadcaster.FileIdMesgEvent      += HandleFileIDMesg;
                msgBroadcaster.DeviceInfoMesgEvent  += HandleDeviceInfoMessage;
                msgBroadcaster.UserProfileMesgEvent += HandleUserProfileMesg;
                msgBroadcaster.ActivityMesgEvent    += HandleActivityMessage;
                msgBroadcaster.SessionMesgEvent     += HandleSessionMessage;
                msgBroadcaster.LapMesgEvent         += HandleLapMessage;
                msgBroadcaster.LengthMesgEvent      += HandleLengthMessage;
                msgBroadcaster.RecordMesgEvent      += HandleRecordMessage;

                // open and check the file
                FileStream stream = new FileStream(fileName, FileMode.Open);
                bool       status = decoder.IsFIT(stream);
                status &= decoder.CheckIntegrity(stream);

                // Process the file
                if (status)
                {
                    decoder.Read(stream);
                }
                else
                {
                    try
                    {
                        if (decoder.InvalidDataSize)
                        {
                            decoder.Read(stream);
                        }
                        else
                        {
                            decoder.Read(stream, DecodeMode.InvalidHeader);
                        }
                    }
                    catch (FitException ex)
                    {
                        Console.WriteLine("FIT exception: " + ex.Message);
                    }
                }
                stream.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Load exception: " + ex.Message);
            }
        }
示例#19
0
        static void RunOptionsAndReturnExitCode(Options opts)
        {
            options = opts;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            Console.WriteLine("FIT Decode Example Application");

            try
            {
                fitDest = new FileStream(options.OutFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
                Console.WriteLine("Opening Destintion {0}", options.OutFile);
                // Write our header
                encodeDemo.Open(fitDest);

                // Attempt to open .FIT file
                fitSource = new FileStream(options.InFile, FileMode.Open);
                Console.WriteLine("Opening Source {0}", options.InFile);

                Decode          decodeDemo      = new Decode();
                MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

                // Connect the Broadcaster to our event (message) source (in this case the Decoder)
                decodeDemo.MesgEvent           += mesgBroadcaster.OnMesg;
                decodeDemo.MesgDefinitionEvent += mesgBroadcaster.OnMesgDefinition;
                //decodeDemo.DeveloperFieldDescriptionEvent += OnDeveloperFieldDescriptionEvent;

                // Subscribe to message events of interest by connecting to the Broadcaster
                mesgBroadcaster.MesgEvent           += OnMesg;
                mesgBroadcaster.MesgDefinitionEvent += OnMesgDefn;

                mesgBroadcaster.FileIdMesgEvent      += OnFileIDMesg;
                mesgBroadcaster.UserProfileMesgEvent += OnUserProfileMesg;
                mesgBroadcaster.MonitoringMesgEvent  += OnMonitoringMessage;
                mesgBroadcaster.DeviceInfoMesgEvent  += OnDeviceInfoMessage;
                mesgBroadcaster.RecordMesgEvent      += OnRecordMessage;

                bool status = decodeDemo.IsFIT(fitSource);
                status &= decodeDemo.CheckIntegrity(fitSource);

                // Process the file
                if (status)
                {
                    Console.WriteLine("Translating...");
                    decodeDemo.Read(fitSource);
                    Console.WriteLine("Translated FIT file {0}", options.InFile);
                }
                else
                {
                    try
                    {
                        Console.WriteLine("Integrity Check Failed {0}", options.InFile);
                        if (decodeDemo.InvalidDataSize)
                        {
                            Console.WriteLine("Invalid Size Detected, Attempting to decode...");
                            decodeDemo.Read(fitSource);
                        }
                        else
                        {
                            Console.WriteLine("Attempting to decode by skipping the header...");
                            decodeDemo.Read(fitSource, DecodeMode.InvalidHeader);
                        }
                    }
                    catch (FitException ex)
                    {
                        Console.WriteLine("Translate caught FitException: " + ex.Message);
                    }
                }
                fitSource.Close();

                // Update header datasize and file CRC
                encodeDemo.Close();
                fitDest.Close();

                Console.WriteLine("");
                Console.WriteLine("Summary:");
                int totalMesgs = 0;
                foreach (KeyValuePair <ushort, int> pair in mesgCounts)
                {
                    Console.WriteLine("MesgID {0,3} Count {1}", pair.Key, pair.Value);
                    totalMesgs += pair.Value;
                }

                Console.WriteLine("{0} Message Types {1} Total Messages", mesgCounts.Count, totalMesgs);

                stopwatch.Stop();
                Console.WriteLine("");
                Console.WriteLine("Time elapsed: {0:0.#}s", stopwatch.Elapsed.TotalSeconds);
                Console.ReadKey();
            }
            catch (FitException ex)
            {
                Console.WriteLine("A FitException occurred when trying to decode the FIT file. Message: " + ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occurred when trying to decode the FIT file. Message: " + ex.Message);
            }
        }