Exemplo n.º 1
0
        private void writeDefintion(string[] str)
        {
            byte        header          = byte.Parse(str[1]);
            int         localMesgIndex  = header & 0x0f;
            byte        reserved        = byte.Parse(str[2]);
            localMsgDef msgDef          = new localMsgDef();
            byte        arch            = msgDef.Architecture = byte.Parse(str[3]);
            UInt16      globalMesgIndex = msgDef.globalMesgIndex = UInt16.Parse(str[4]);
            byte        fields          = msgDef.Fields = byte.Parse(str[5]);

            msgDef.localFields            = new localField[fields];
            msgDef.mesg                   = FIT.getMessageStruct(msgDef.globalMesgIndex);
            localMesgDefs[localMesgIndex] = msgDef;
            fitstream.writeValue(header);
            fitstream.writeValue(reserved);
            fitstream.writeValue(arch);
            fitstream.writeValue(globalMesgIndex, 0);
            fitstream.writeValue(fields);

            for (int i = 0; i < fields; i++)
            {
                localField fielddef = new localField();
                byte       FieldDefinitionNumber = fielddef.FieldDefinitionNumber = byte.Parse(str[6 + (i) * 3]);
                byte       size     = fielddef.size = byte.Parse(str[7 + (i) * 3]);
                byte       baseType = fielddef.baseType = byte.Parse(str[8 + (i) * 3]);
                fielddef.GlobalField = FIT.getFieldStruct(msgDef.mesg, (int)FieldDefinitionNumber);
                localMesgDefs[localMesgIndex].localFields[i] = fielddef;
                fitstream.writeValue(FieldDefinitionNumber);
                fitstream.writeValue(size);
                fitstream.writeValue(baseType);
            }
        }
Exemplo n.º 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;
                    }
                }
            }
Exemplo n.º 3
0
        private void writeDefintion(string[] str)
        {
            byte header = byte.Parse(str[1]);
            int localMesgIndex = header & 0x0f;
            byte reserved = byte.Parse(str[2]);
            localMsgDef msgDef = new localMsgDef();
            byte arch = msgDef.Architecture = byte.Parse(str[3]);
            UInt16 globalMesgIndex = msgDef.globalMesgIndex = UInt16.Parse(str[4]);
            byte fields = msgDef.Fields = byte.Parse(str[5]);
            msgDef.localFields = new localField[fields];
            msgDef.mesg = FIT.getMessageStruct(msgDef.globalMesgIndex);
            localMesgDefs[localMesgIndex] = msgDef;
            fitstream.writeValue(header);
            fitstream.writeValue(reserved);
            fitstream.writeValue(arch);
            fitstream.writeValue(globalMesgIndex, 0);
            fitstream.writeValue(fields);

            for (int i = 0; i < fields; i++)
            {
                localField fielddef = new localField();
                byte FieldDefinitionNumber = fielddef.FieldDefinitionNumber = byte.Parse(str[6 + (i) * 3]);
                byte size = fielddef.size = byte.Parse(str[7 + (i) * 3]);
                byte baseType = fielddef.baseType = byte.Parse(str[8 + (i) * 3]);
                fielddef.GlobalField = FIT.getFieldStruct(msgDef.mesg, (int)FieldDefinitionNumber);
                localMesgDefs[localMesgIndex].localFields[i] = fielddef;
                fitstream.writeValue(FieldDefinitionNumber);
                fitstream.writeValue(size);
                fitstream.writeValue(baseType);
            }
        }
Exemplo n.º 4
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;
                    }
            }
Exemplo n.º 5
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);
            }
Exemplo n.º 6
0
            private string readFieldDef()
            {
                localMsgDef msgDef = new localMsgDef();

                msgDef.reserved = file.readbyte();
                if (msgDef.reserved != 0)
                {
                    return("");
                }

                msgDef.Architecture = file.readbyte();
                if (msgDef.Architecture > 1)
                {
                    return("");
                }

                msgDef.globalMesgIndex = file.readUInt16(msgDef.Architecture);
                if (msgDef.globalMesgIndex > 255 && msgDef.globalMesgIndex < 0xFE00)
                {
                    return("");
                }
                msgDef.mesg = FIT.getMessageStruct(msgDef.globalMesgIndex);

                msgDef.Fields = file.readbyte();
                if (msgDef.Fields > msgDef.mesg.fields.Length + 10)
                {
                    return("");
                }

                recordString          += (string.Format(";{0};{1};{2};{3}", msgDef.reserved, msgDef.Architecture, msgDef.globalMesgIndex, msgDef.Fields));
                recordDefinitionHeader = ";;reserved;Architecture;globalMesgIndex;Fields";
                msgDef.localFields     = new localField[msgDef.Fields];
                for (int i = 0; i < msgDef.Fields; i++)
                {
                    localField fieldDef = new localField();
                    byte       d        = fieldDef.FieldDefinitionNumber = file.readbyte();
                    byte       s        = fieldDef.size = file.readbyte();
                    byte       b        = fieldDef.baseType = file.readbyte();
                    fieldDef.arch        = (((b & 0x80) == 0x80) && msgDef.Architecture == 1) ? 1 : 0;;
                    fieldDef.GlobalField = FIT.getFieldStruct(msgDef.mesg, d);
                    {
                        if (d == 253)
                        {
                            msgDef.isCompressedMsg = false;
                        }
                        //if (fieldDef.field.valid && (fieldDef.field.type != b || fieldDef.field.num != d)) return "";
                        if (!(d <= 80 || d >= 253))
                        {
                            return("");
                        }
                        if (!(b == 0x00 && s == 1 || b == 0x01 && s == 1 || b == 0x02 && s == 1 || b == 0x83 && s == 2 || b == 0x84 && s == 2 || b == 0x85 && s == 4 || b == 0x86 && s == 4 || b == 0x07 && s > 0 || b == 0x88 && s == 4 || b == 0x89 && s == 8 || b == 0x0A && s == 1 || b == 0x8B && s == 2 || b == 0x8C && s == 4 || b == 0x0D && s > 0))
                        {
                            return("");
                        }
                        recordString += (string.Format(";{0};{1};{2}", d, s, b));
                    }
                    msgDef.localFields[i] = fieldDef;
                }
                msgDef.isValid = true;
                localMsgDef    = localMsgDefs[localMesgIndex] = msgDef;
                return(string.Format("{0}\n{1}\n{2}", recordDefinitionHeader, recordString, getHeader(localMesgIndex)));
            }
Exemplo n.º 7
0
            private string readFieldDef()
            {
                localMsgDef msgDef = new localMsgDef();

                msgDef.reserved = file.readbyte();
                if (msgDef.reserved != 0) return "";

                msgDef.Architecture = file.readbyte();
                if (msgDef.Architecture > 1) return "";

                msgDef.globalMesgIndex = file.readUInt16(msgDef.Architecture);
                if (msgDef.globalMesgIndex > 255 && msgDef.globalMesgIndex < 0xFE00) return "";
                msgDef.mesg = FIT.getMessageStruct(msgDef.globalMesgIndex);

                msgDef.Fields = file.readbyte();
                if (msgDef.Fields > msgDef.mesg.fields.Length + 10) return "";

                recordString += (string.Format(";{0};{1};{2};{3}", msgDef.reserved, msgDef.Architecture, msgDef.globalMesgIndex, msgDef.Fields));
                recordDefinitionHeader = ";;reserved;Architecture;globalMesgIndex;Fields";
                msgDef.localFields = new localField[msgDef.Fields];
                for (int i = 0; i < msgDef.Fields; i++)
                {
                    localField fieldDef = new localField();
                    byte d = fieldDef.FieldDefinitionNumber = file.readbyte();
                    byte s = fieldDef.size = file.readbyte();
                    byte b = fieldDef.baseType = file.readbyte();
                    fieldDef.arch = (((b & 0x80) == 0x80) && msgDef.Architecture == 1) ? 1 : 0; ;
                    fieldDef.GlobalField = FIT.getFieldStruct(msgDef.mesg, d);
                    {
                        if (d == 253) msgDef.isCompressedMsg = false;
                        //if (fieldDef.field.valid && (fieldDef.field.type != b || fieldDef.field.num != d)) return "";
                        if (!(d <= 80 || d >= 253)) return "";
                        if (!(b == 0x00 && s == 1 || b == 0x01 && s == 1 || b == 0x02 && s == 1 || b == 0x83 && s == 2 || b == 0x84 && s == 2 || b == 0x85 && s == 4 || b == 0x86 && s == 4 || b == 0x07 && s > 0 || b == 0x88 && s == 4 || b == 0x89 && s == 8 || b == 0x0A && s == 1 || b == 0x8B && s == 2 || b == 0x8C && s == 4 || b == 0x0D && s > 0)) return "";
                        recordString += (string.Format(";{0};{1};{2}", d, s, b));
                    }
                    msgDef.localFields[i] = fieldDef;
                }
                msgDef.isValid = true;
                localMsgDef = localMsgDefs[localMesgIndex] = msgDef;
                return string.Format("{0}\n{1}\n{2}", recordDefinitionHeader, recordString, getHeader(localMesgIndex));
            }
Exemplo n.º 8
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;
            }