Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

FIT File parse crash on duplicate DeveloperData

Rank

Total Posts: 5

Joined 2013-11-22

PM

I have several FIT files coming off of Garmin watches that are causing the following error. I was wondering if anyone else has experienced this and has a solution? It looks to be a problem inside of the library itself:

An item with the same key has already been added.
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Dynastream.Fit.DeveloperDataLookup.Add(DeveloperDataIdMesg mesg)
at Dynastream.Fit.Decode.HandleMetaData(Mesg newMesg)
at Dynastream.Fit.Decode.RaiseMesgEvent(Mesg newMesg)
at Dynastream.Fit.Decode.DecodeNextMessage(Stream fitStream)
at Dynastream.Fit.Decode.Read(Stream fitStream, DecodeMode mode)
at Dynastream.Fit.Decode.Read(Stream fitStream)
at FitFileReader.ReadFile(Stream Data, TextWriter Output, Boolean WriteDebug) in d:\home\site\wwwroot\App_Code\DeviceWorkout\FitFile.cs:line 124


Thanks for any help you can provide. I have attached the FIT file that is causing this issue.      

File Attachments

RankRank

Total Posts: 44

Joined 2013-04-07

PM

What I found:
- Decoding with java seems to work
- The fit file does not seem to be corrupt

It's probably a problem of your decoding program

The problem could be the order of the fields:
===================================================================================
Record 28  0x4e1
Header
-Byte:  77  0x4d header typeNORMAL
message_type
DEFINITION local_message_no13  |
developer_flagPROFIL |

Record 28 Content:
reservedarchitecture0 LITTLE_ENDIAN global_mesg206 FIELD_DESCRIPTION fields10 |
   
field  # :   # Definition                              Size Base-Type
   
field  0 :   3 field_name                               64   7  string
   field  1 
:   8 units                                    16   7  string
   field  2 
:  13 fit_base_unit_id                          2   4  uint16
   field  3 
:  14 native_mesg_num                           2   4  uint16
   field  4 
:   0 developer_data_index                      1   2  uint8
   field  5 
:   1 field_definition_number                   1   2  uint8
   field  6 
:   2 fit_base_type_id                          1   2  uint8
   field  7 
:   6 scale                                     1   2  uint8
   field  8 
:   7 offset                                    1   1  sint8
   field  9 
:  15 native_field_num                          1   2  uint8
=================================================================================== 

I need to customize my own program as well
So far I have expected as first fields:
field  0 :   0 developer_data_index                      1   2  uint8
field  1 
:   1 field_definition_number                   1   2  uint8 

But the order may well be different …
(Mixing the fields is a philosophy of FIT SDK ;- )

In the “doughnuts“-example it was easier:
===================================================================================
Record 5  0x48
Header
-Byte:  64  0x40 header typeNORMAL
message_type
DEFINITION local_message_no0  |
developer_flagPROFIL |

Record 5 Content:
reservedarchitecture1 BIG_ENDIAN global_mesg206 FIELD_DESCRIPTION fields|
   
field  # :   # Definition                              Size Base-Type
   
field  0 :   0 developer_data_index                      1   2  uint8
   field  1 
:   1 field_definition_number                   1   2  uint8
   field  2 
:   2 fit_base_type_id                          1   2  uint8
   field  3 
:   3 field_name                               17   7  string
   field  4 
:   8 units                                    10   7  string
===================================================================================
Record 6  0x5d
Header
-Byte:  0  0x0 header typeNORMAL
message_type
DATA local_message_no0 FIELD_DESCRIPTION |
developer_flagPROFIL |

Record 6 Content:
              
developer_data_index                0                                     0
           field_definition_number                0                                     0
                  fit_base_type_id                1                                 sint8
                        field_name
                                                                   
b'doughnuts_earned\x00'
                                                                         
doughnuts_earned
                             units
                                                                          
b'doughnuts\x00'
                                                                                
doughnuts
===================================================================================
Record 7  0x7c
Header
-Byte:  96  0x60 header typeNORMAL
message_type
DEFINITION local_message_no0  |
developer_flagDEVELOPER |

Record 7 Content:
reservedarchitecture1 BIG_ENDIAN global_mesg20 RECORD fields|
   
field  # :   # Definition                              Size Base-Type
   
field  0 :   3 heart_rate                                1   2  uint8
   field  1 
:   4 cadence                                   1   2  uint8
   field  2 
:   5 distance                                  4   6  uint32
   field  3 
:   6 speed                                     2   4  uint16
dev_fields
|
   
field  # : idx num Definition                          Size Base-Type
   
field  0 :   0   0 doughnuts_earned                      1   1  sint8
=================================================================================== 

edge-python

     

File Attachments

RankRank

Total Posts: 44

Joined 2013-04-07

PM

I have now found something
It was not the order of the fields

It is by the way of using these fields
field  7 :   6 scale                                     1   2  uint8
field  8 
:   7 offset                                    1   1  sint8 

I mean if they were not needed they should be omitted


If they are not omitted,

then the values should not be set to invalid,
scale              255                       (invalid value)
offset             127                       (invalid value

values should be set to scale = 1 and offset = 0
scale                1                                     1
offset               0                                     0 

The attachment contains a fix and a pdf


What is the opinion of the moderators on this problem?

edge-python      

File Attachments

Rank

Total Posts: 5

Joined 2013-11-22

PM

edge-python -

Thanks for all of your work. The issue we're having is we use the SDK's library for parsing within our C# application. This error is being thrown when we call it's "read" function. We're looking at a way to try and get around the parsing of developer data but at this point I don't think we can. We are at the mercy of that SDK for the time being it seems.

Hopefully a moderator see this and pushes it up the chain to see if the library itself can implement your fix.