public void DeserializeData(Stream stream, bool isLittleEndian)
        {
            switch (m_Type)
            {
                case DataType.Enum:
                case DataType.UInt8:
                case DataType.UInt8z:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            GarminFitnessByteRange data = new GarminFitnessByteRange(0);

                            data.Deserialize(stream, Constants.CurrentVersion);
                            m_ByteValues[i] = data;
                        }
                        break;
                    }
                case DataType.SInt8:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            GarminFitnessSByteRange data = new GarminFitnessSByteRange(0);

                            data.Deserialize(stream, Constants.CurrentVersion);
                            m_SByteValues[i] = data;
                        }
                        break;
                    }
                case DataType.UInt16:
                case DataType.UInt16z:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            Byte[] data = new Byte[sizeof(UInt16)];

                            stream.Read(data, 0, sizeof(UInt16));
                            m_UInt16Values[i] = BitConverter.ToUInt16(data, 0);

                            if (!isLittleEndian)
                            {
                                Byte temp = data[0];
                                data[0] = data[1];
                                data[1] = temp;

                                m_UInt16Values[i] = BitConverter.ToUInt16(data, 0);
                            }
                        }
                        break;
                    }
                case DataType.SInt16:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            Byte[] data = new Byte[sizeof(Int16)];

                            stream.Read(data, 0, sizeof(UInt16));
                            m_Int16Values[i] = BitConverter.ToInt16(data, 0);

                            if (!isLittleEndian)
                            {
                                Byte temp = data[0];
                                data[0] = data[1];
                                data[1] = temp;

                                m_Int16Values[i] = BitConverter.ToInt16(data, 0);
                            }
                        }
                        break;
                    }
                case DataType.UInt32:
                case DataType.UInt32z:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            Byte[] data = new Byte[sizeof(UInt32)];

                            stream.Read(data, 0, sizeof(UInt32));
                            m_UInt32Values[i] = BitConverter.ToUInt32(data, 0);

                            if (!isLittleEndian)
                            {
                                Byte temp = data[0];
                                data[0] = data[3];
                                data[3] = temp;
                                temp = data[1];
                                data[1] = data[2];
                                data[2] = temp;

                                m_UInt32Values[i] = BitConverter.ToUInt32(data, 0);
                            }
                        }
                        break;
                    }
                case DataType.SInt32:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            Byte[] data = new Byte[sizeof(UInt32)];

                            stream.Read(data, 0, sizeof(UInt32));
                            m_Int32Values[i] = BitConverter.ToInt32(data, 0);

                            if (!isLittleEndian)
                            {
                                Byte temp = data[0];
                                data[0] = data[3];
                                data[3] = temp;
                                temp = data[1];
                                data[1] = data[2];
                                data[2] = temp;

                                m_Int32Values[i] = BitConverter.ToInt32(data, 0);
                            }
                        }
                        break;
                    }
                case DataType.Float32:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            Byte[] data = new Byte[sizeof(Single)];

                            stream.Read(data, 0, sizeof(Single));
                            m_SingleValues[i] = BitConverter.ToSingle(data, 0);

                            if (!isLittleEndian)
                            {
                                Byte temp = data[0];
                                data[0] = data[3];
                                data[3] = temp;
                                temp = data[1];
                                data[1] = data[2];
                                data[2] = temp;

                                m_SingleValues[i] = BitConverter.ToSingle(data, 0);
                            }
                        }
                        break;
                    }
                case DataType.Float64:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            Byte[] data = new Byte[sizeof(Double)];

                            stream.Read(data, 0, sizeof(Double));
                            m_DoubleValues[i] = BitConverter.ToDouble(data, 0);

                            if (!isLittleEndian)
                            {
                                Byte temp = data[0];
                                data[0] = data[7];
                                data[7] = temp;
                                temp = data[1];
                                data[1] = data[6];
                                data[6] = temp;
                                temp = data[2];
                                data[2] = data[5];
                                data[5] = temp;
                                temp = data[3];
                                data[3] = data[4];
                                data[4] = temp;

                                m_DoubleValues[i] = BitConverter.ToDouble(data, 0);
                            }
                        }
                        break;
                    }
                case DataType.String:
                case DataType.Byte:
                    {
                        stream.Read(m_ByteValues, 0, m_ByteValues.Length);
                        break;
                    }
                default:
                    {
                        Debug.Assert(false);
                        break;
                    }
            }
        }
        private void ReadHRZone(int index, XmlNode parentNode)
        {
            Debug.Assert(index >= 0 && index < Constants.GarminHRZoneCount);

            bool viewAsRead = false;
            bool lowRead = false;
            bool highRead = false;
            GarminFitnessByteRange lowLimit = new GarminFitnessByteRange(0);
            GarminFitnessByteRange highLimit = new GarminFitnessByteRange(0);

            for (int i = 0; i < parentNode.ChildNodes.Count; ++i)
            {
                XmlNode currentChild = parentNode.ChildNodes[i];

                if (currentChild.Name == Constants.ViewAsTCXString)
                {
                    GarminFitnessBool HRIsInPercentMax = new GarminFitnessBool(true,
                                                                               Constants.PercentMaxTCXString,
                                                                               Constants.BPMTCXString);
                    HRIsInPercentMax.Deserialize(currentChild);

                    // When we read % max, make sure we don't overwrite the BPM vs %Max/HRR since there
                    //  is no difference between both of these in the TCX file
                    if (!HRIsInPercentMax ||
                        HRZonesReferential == HRReferential.HRReferential_BPM)
                    {
                        HRZonesReferential = HRIsInPercentMax ? HRReferential.HRReferential_PercentMax : HRReferential.HRReferential_BPM;
                    }
                    viewAsRead = true;
                }
                else if (currentChild.Name == Constants.LowTCXString &&
                         currentChild.ChildNodes.Count == 1 &&
                         currentChild.FirstChild.Name == Constants.ValueTCXString)
                {
                    lowLimit.Deserialize(currentChild.FirstChild);
                    lowRead = true;
                }
                else if (currentChild.Name == Constants.HighTCXString &&
                         currentChild.ChildNodes.Count == 1 &&
                         currentChild.FirstChild.Name == Constants.ValueTCXString)
                {
                    highLimit.Deserialize(currentChild.FirstChild);
                    highRead = true;
                }
            }

            // Check if all was read successfully
            if (!viewAsRead || !lowRead || !highRead)
            {
                throw new GarminFitnessXmlDeserializationException("Missing information in heart rate zone XML node", parentNode);
            }

            m_HeartRateZones[index].Lower = new GarminFitnessDoubleRange((double)Math.Min(lowLimit, highLimit) / MaximumHeartRate, 0, 1);
            m_HeartRateZones[index].Upper = new GarminFitnessDoubleRange((double)Math.Max(lowLimit, highLimit) / MaximumHeartRate, 0, 1);
        }
示例#3
0
        public void Deserialize_V17(Stream stream, DataVersion version)
        {
            GarminFitnessByteRange intensity = new GarminFitnessByteRange(0);

            // Call base deserialization
            Deserialize(typeof(IStep), stream, version);

            byte[] intBuffer = new byte[sizeof(Int32)];

            m_Name.Deserialize(stream, version);

            // Duration
            stream.Read(intBuffer, 0, sizeof(Int32));
            DurationFactory.Create((IDuration.DurationType)BitConverter.ToInt32(intBuffer, 0), stream, version, this);

            // Target
            stream.Read(intBuffer, 0, sizeof(Int32));
            Int32 type = BitConverter.ToInt32(intBuffer, 0);

            // This sucks but I changed the order of the enum between version 0 and 1,
            //  so make sure the version is right
            if (version.VersionNumber == 0)
            {
                if (type == 3)
                {
                    // Null was #3, now #0
                    type = 0;
                }
                else
                {
                    // Everything else is pushed up 1 position
                    ++type;
                }
            }

            TargetFactory.Create((ITarget.TargetType)type, stream, version, this);

            intensity.Deserialize(stream, Constants.CurrentVersion);
            m_Intensity = (StepIntensity)(Byte)intensity;
        }
        public void Deserialize_V23(Stream stream, DataVersion version)
        {
            m_MaxHeartRate.Deserialize(stream, version);

            m_GearWeightInPounds.Deserialize(stream, version);

            GarminFitnessByteRange HRZoneReference = new GarminFitnessByteRange(0);
            HRZoneReference.Deserialize(stream, version);
            HRZonesReferential = (HRReferential)(Byte)HRZoneReference;

            for (int i = 0; i < m_HeartRateZones.Count; ++i)
            {
                m_HeartRateZones[i].Lower.Deserialize(stream, version);

                m_HeartRateZones[i].Upper.Deserialize(stream, version);
            }

            m_SpeedIsInPace.Deserialize(stream, version);

            for (int i = 0; i < m_SpeedZones.Count; ++i)
            {
                m_SpeedZones[i].InternalLow.Deserialize(stream, version);

                m_SpeedZones[i].InternalHigh.Deserialize(stream, version);

                m_SpeedZones[i].InternalName.Deserialize(stream, version);
            }
        }