예제 #1
0
            public string readValue(localField localFieldDef)
            {
                globalField FIELD  = localFieldDef.GlobalField;
                double      scale  = FIELD.scale;
                double      offset = FIELD.offset;
                int         size   = localFieldDef.size;
                int         arch   = localFieldDef.arch;
                string      fm     = scale <= 1 ? "0" : scale <= 10 ? "0.0" : scale <= 100 ? "0.00" : scale <= 1000 ? "0.000" : "0.0000";

                baseType = localFieldDef.baseType;
                switch (baseType)
                {
                case 0x00: strValue = FIT.EnumToString(localFieldDef.GlobalField.name, (int)(_enum = readbyte())); break;                                              //enum

                case 0x01: strValue = ((isLastValueValid = (_sbyte = readsbyte()) != 0x7f) ? (_sbyte / scale - offset).ToString(fm) : ""); break;                      //sbyte

                case 0x02: strValue = ((isLastValueValid = (_byte = readbyte()) != 0xFF) ? (_byte / scale - offset).ToString(fm) : ""); break;                         //byte

                case 0x83: strValue = ((isLastValueValid = (_int16 = readInt16(arch)) != 0x7FFF) ? (_int16 / scale - offset).ToString(fm) : ""); break;                //int16

                case 0x84: strValue = ((isLastValueValid = (_Uint16 = readUInt16(arch)) != 0xFFFF) ? (_Uint16 / scale - offset).ToString(fm) : ""); break;             //Uint16

                case 0x85: strValue = ((isLastValueValid = (_int32 = readInt32(arch)) != 0x7FFFFFFF) ? (_int32 / scale - offset).ToString(fm) : ""); break;            //int32

                case 0x86: strValue = ((isLastValueValid = (_Uint32 = readUInt32(arch)) != 0xFFFFFFFF) ? (_Uint32 / scale - offset).ToString(fm) : ""); break;         //Uint32

                case 0x87: strValue = ((isLastValueValid = (_Uint32 = readUInt32(arch)) != 0xFFFFFFFF) ? (_Uint32 / scale - offset).ToString(fm) : ""); break;         //float32

                case 0x89: strValue = ((isLastValueValid = (_Uint64 = readUInt64(arch)) != 0xFFFFFFFFFFFFFFFF) ? (_Uint64 / scale - offset).ToString(fm) : ""); break; //float64

                case 0x0A: strValue = ((isLastValueValid = (_byte = readbyte()) != 0x00) ? (_byte / scale - offset).ToString(fm) : ""); break;                         //byteZ

                case 0x8B: strValue = ((isLastValueValid = (_Uint16 = readUInt16(arch)) != 0x00) ? (_Uint16 / scale - offset).ToString(fm) : ""); break;               //Uint16Z

                case 0x8C: strValue = ((isLastValueValid = (_Uint32 = readUInt32(arch)) != 0x00) ? (_Uint32 / scale - offset).ToString(fm) : ""); break;;              //Uint32Z

                case 0x07:
                    for (int i = 0; i < size; i++)
                    {
                        strValue += readChar();
                    }
                    break;;      //string

                case 0x0D:
                    for (int i = 0; i < size; i++)
                    {
                        strValue += readbyte().ToString("X2");
                    }
                    break;;      //string

                default:
                    break;
                }
                switch (FIELD.name)
                {
                case "timestamp": break;

                case "position_lat": break;

                case "position_long": break;

                case "altitude": break;

                case "distance": break;

                case "speed": break;

                case "power": break;
                }

                return(strValue);
            }
예제 #2
0
            public void writeValue(localField localFieldDef, string value, statistics st, int globalMesgIndex)
            {
                UInt32      _UInt32     = 0;
                Int32       _Int32      = 0;
                UInt16      _UInt16     = 0;
                Int16       _Int16      = 0;
                byte        _byte       = 0;
                int         size        = localFieldDef.size;
                int         arch        = localFieldDef.arch;
                int         baseType    = localFieldDef.baseType;
                globalField globalField = localFieldDef.GlobalField;
                string      fieldName   = globalField.name;
                double      scale       = globalField.scale;
                double      offset      = globalField.offset;

                if (localFieldDef.FieldDefinitionNumber == 253)
                {
                    DateTime dt;
                    DateTime.TryParseExact(value, "yyyy-MM-dd HH:mm:ss", cuNL, DateTimeStyles.None, out dt);
                    value = ((UInt32)dt.ToUniversalTime().Subtract(dt1989).Duration().TotalSeconds).ToString("0");
                }
                if (globalMesgIndex == FIT.FIT_MESG_NUM_SESSION)
                {
                    switch (fieldName)
                    {
                    case "start_time": writeValue(st.SessionStartTimestamp, arch); return;

                    case "start_position_lat": writeValue(st.start_position_lat, arch); return;

                    case "start_position_long": writeValue(st.start_position_long, arch); return;

                    case "total_elapsed_time": writeValue(st.total_elapsed_time, arch); return;

                    case "total_timer_time": writeValue(st.total_timer_time, arch); return;

                    case "total_distance": writeValue(st.total_distance, arch); return;

                    case "total_calories": writeValue(st.total_calories, arch); return;

                    case "avg_speed": writeValue(st.avg_speed, arch); return;

                    case "max_speed": writeValue(st.max_speed, arch); return;

                    case "avg_heart_rate": writeValue(st.avg_heart_rate); return;

                    case "max_heart_rate": writeValue(st.max_heart_rate); return;

                    case "avg_cadence": writeValue(st.avg_cadence); return;

                    case "max_cadence": writeValue(st.max_cadence); return;

                    case "avg_power": writeValue(st.avg_power, arch); return;

                    case "max_power": writeValue(st.max_power, arch); return;

                    case "total_ascent": writeValue((UInt16)(st.SessionTotal_ascent / 5.0), arch); return;

                    case "total_descent": writeValue((UInt16)(st.SessionTotal_descent / 5.0), arch); return;
                    }
                }
                if (globalMesgIndex == FIT.FIT_MESG_NUM_LAP)
                {
                    switch (fieldName)
                    {
                    case "start_time": writeValue(st.LapStartTimestamp, arch); return;

                    case "start_position_lat": writeValue(st.start_position_lat, arch); return;

                    case "start_position_long": writeValue(st.start_position_long, arch); return;

                    case "total_elapsed_time": writeValue(st.total_elapsed_time, arch); return;

                    case "total_timer_time": writeValue(st.total_timer_time, arch); return;

                    case "total_distance": writeValue(st.total_distance, arch); return;

                    case "total_calories": writeValue(st.total_calories, arch); return;

                    case "avg_speed": writeValue(st.avg_speed, arch); return;

                    case "max_speed": writeValue(st.max_speed, arch); return;

                    case "avg_heart_rate": writeValue(st.avg_heart_rate); return;

                    case "max_heart_rate": writeValue(st.max_heart_rate); return;

                    case "avg_cadence": writeValue(st.avg_cadence); return;

                    case "max_cadence": writeValue(st.max_cadence); return;

                    case "avg_power": writeValue(st.avg_power, arch); return;

                    case "max_power": writeValue(st.max_power, arch); return;

                    case "total_ascent": writeValue((UInt16)(st.LapTotal_ascent / 5.0), arch); return;

                    case "total_descent": writeValue((UInt16)(st.LapTotal_descent / 5.0), arch); return;
                    }
                }

                switch (baseType)
                {
                case 0x00: writeValue(FIT.StringToEnum(fieldName, value)); break;    //enum

                case 0x01: if (value == "")
                    {
                        writeValue((sbyte)0x7F);
                    }
                    else
                    {
                        writeValue((sbyte)((double.Parse(value) + offset) * scale + 0.1));
                    } break;                                                                                                                           //sbyte

                case 0x02: if (value == "")
                    {
                        writeValue((byte)0xFF);
                    }
                    else
                    {
                        writeValue(_byte = (byte)((double.Parse(value) + offset) * scale + 0.1));
                    } break;                                                                                                                                 //byte

                case 0x83: if (value == "")
                    {
                        writeValue((Int16)0x7FFF, arch);
                    }
                    else
                    {
                        writeValue(_Int16 = (Int16)((double.Parse(value) + offset) * scale + 0.1), arch);
                    } break;                                                                                                                                                  //int16

                case 0x84: if (value == "")
                    {
                        writeValue((UInt16)0xFFFF, arch);
                    }
                    else
                    {
                        writeValue(_UInt16 = (UInt16)((double.Parse(value) + offset) * scale + 0.1), arch);
                    } break;                                                                                                                                                     //Uint16

                case 0x85: if (value == "")
                    {
                        writeValue((Int32)0x7FFFFFFF, arch);
                    }
                    else
                    {
                        writeValue(_Int32 = (Int32)((double.Parse(value) + offset) * scale + 0.1), arch);
                    } break;                                                                                                                                                      //int32

                case 0x86: if (value == "")
                    {
                        writeValue((UInt32)0xFFFFFFFF, arch);
                    }
                    else
                    {
                        writeValue(_UInt32 = (UInt32)((double.Parse(value) + offset) * scale + 0.1), arch);
                    } break;                                                                                                                                                         //Uint32

                case 0x87: if (value == "")
                    {
                        writeValue((UInt32)0xFFFFFFFF, arch);
                    }
                    else
                    {
                        writeValue((UInt32)((double.Parse(value) + offset) * scale + 0.1), arch);
                    } break;                                                                                                                                               //float32

                case 0x89: if (value == "")
                    {
                        writeValue((UInt64)0xFFFFFFFFFFFFFFFF, arch);
                    }
                    else
                    {
                        writeValue((UInt64)((double.Parse(value) + offset) * scale + 0.1), arch);
                    } break;                                                                                                                                                       //float64

                case 0x0A: if (value == "")
                    {
                        writeValue((byte)0x00);
                    }
                    else
                    {
                        writeValue((byte)((double.Parse(value) + offset) * scale + 0.1));
                    } break;                                                                                                                         //byteZ

                case 0x8B: if (value == "")
                    {
                        writeValue((UInt16)0x00, arch);
                    }
                    else
                    {
                        writeValue((UInt16)((double.Parse(value) + offset) * scale + 0.1), arch);
                    } break;                                                                                                                                         //Uint16Z

                case 0x8C: if (value == "")
                    {
                        writeValue((UInt32)0x00, arch);
                    }
                    else
                    {
                        writeValue((UInt32)((double.Parse(value) + offset) * scale + 0.1), arch);
                    } break;                                                                                                                                         //Uint32Z

                case 0x07:
                    for (int i = 0; i < size; i++)
                    {
                        writeValue(value.ToArray()[i]);
                    }
                    break;;      //string

                case 0x0D:
                    for (int i = 0; i < size; i++)
                    {
                        writeValue(byte.Parse(value.Substring(i * 2, 2), NumberStyles.AllowHexSpecifier));
                    }
                    break;;      //string

                default:
                    break;
                }
                if (globalMesgIndex == FIT.FIT_MESG_NUM_RECORD)
                {
                    switch (fieldName)
                    {
                    case "timestamp": st.timestamp = _UInt32; break;

                    case "position_lat": if (st.start_position_lat == 0)
                        {
                            st.start_position_lat = _Int32;
                        }
                        break;

                    case "position_long": st.start_position_long = _Int32; break;

                    case "altitude": st.altitude = _UInt16; break;

                    case "distance": st.distance = _UInt32; break;

                    case "speed": st.speed = _UInt16; break;

                    case "power": st.power = _UInt16; break;

                    case "cadence": st.cadence = _byte; break;

                    case "heart_rate": st.heart_rate = _byte; break;
                    }
                }
            }
예제 #3
0
            private string readFieldData()
            {
                string str = "";

                localMsgDef = localMsgDefs[localMesgIndex];
                foreach (localField localField in localMsgDef.localFields)
                {
                    str = file.readValue(localField);
                    globalField globalField = localField.GlobalField;
                    if (globalField.foutMarge >= 0)
                    {
                        Int64 value = file.getLastValue();
                        if (file.isLastValueValid)
                        {
                            if (localField.lastGoodValue == Int64.MinValue)
                            {
                                localField.lastGoodValue = value;
                            }
                            else
                            if (Math.Abs(localField.lastGoodValue - value) > globalField.foutMarge)
                            {
                                return("");
                            }
                            else
                            {
                                localField.lastGoodValue = value;
                            }
                        }
                        else
                        {
                            if (globalField.name == "software_version" || globalField.name == "device_index") //verplicht veld
                            {
                                return("");
                            }
                        }
                    }

                    if (globalField.name == "timestamp")
                    {
                        str = FIT.timestampToLocalTime(UInt32.Parse(str));
                    }
                    recordString += ";" + str;
                    switch (globalField.name)
                    {
                    case "timestamp": timestamp = file._Uint32; break;

                    case "position_lat": position_lat = file._int32; break;

                    case "position_long": position_long = file._int32; break;

                    case "altitude": altitude = file._Uint16; break;

                    case "distance": distance = file._Uint32; break;

                    case "speed": speed = file._Uint16; break;

                    case "power": power = file._Uint16; break;

                    case "cadence": cadence = file._byte; break;

                    case "event": _event = file._enum; break;

                    case "event_type": _event_type = file._enum; break;
                    }
                }
                return(recordString);
            }