コード例 #1
0
        /// <summary>
        /// Demonstrate the encoding of a 'Settings File' by writing a 'Settings File' containing a 'User Profile' Message.
        /// This example is simpler than the 'Monitoring File' example.
        /// </summary>
        static void EncodeSettingsFile()
        {
            // Generate some FIT messages
            FileIdMesg fileIdMesg = new FileIdMesg(); // Every FIT file MUST contain a 'File ID' message as the first message

            fileIdMesg.SetType(Dynastream.Fit.File.Settings);
            fileIdMesg.SetManufacturer(Manufacturer.Development);  // Types defined in the profile are available
            fileIdMesg.SetProduct(1);
            fileIdMesg.SetSerialNumber(12345);

            UserProfileMesg myUserProfile = new UserProfileMesg();

            myUserProfile.SetGender(Gender.Female);
            float myWeight = 63.1F;

            myUserProfile.SetWeight(myWeight);
            myUserProfile.SetAge(99);
            myUserProfile.SetFriendlyName(Encoding.UTF8.GetBytes("TestUser"));

            FileStream fitDest = new FileStream("ExampleSettings.fit", FileMode.Create, FileAccess.ReadWrite, FileShare.Read);

            // Create file encode object
            Encode encodeDemo = new Encode(ProtocolVersion.V10);

            // Write our header
            encodeDemo.Open(fitDest);

            // Encode each message, a definition message is automatically generated and output if necessary
            encodeDemo.Write(fileIdMesg);
            encodeDemo.Write(myUserProfile);

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

            Console.WriteLine("Encoded FIT file ExampleSettings.fit");
            return;
        }