Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Sequence Reference Field and Dynamic Field

RankRank

Total Posts: 44

Joined 2013-04-07

PM

Hi,

An activity fit file contains shown below message definition:
=============================================================================
Record 5 Header-Byte:
header_byte:  66
header_type
:0=NORMAL  message_type:1=DEFINITION  local_message_type:2

Record 5 Content
:
reserved:0  architecture:0=LITTLE ENDIAN  global_msg:21=EVENT  no_of_fields:5

  field 
#:  Def#   Field Name                     Size Base-Type
  
field 0:   253   timestamp                        4      6
  field 1
:     3   data                             4      6
  field 2
:     0   event                            1      0
  field 3
:     1   event_type                       1      0
  field 4
:     4   event_group                      1      2
=============================================================================
(
Garmin edge 510 V3.40

I think field #1 is an Dynamic Field. The Reference Field is field #2.

The "FIT Data Transfer Protocol Rev 1.7" describes:

4.5 Dynamic Fields
The interpretation of some message fields depends on the value of another previously defined field.
This is called a DynamicField.


For me, so definitely committed:
First comes the Reference Field, then comes the Dynamic Field.

I understand the protocol wrong?
Is it not hard and fast rule?

I think it's easier to read a fit file if the rule is met.

(and:
even if in Profile.xls the Field Def # Reference Field is larger than the Field Def # Dynamic Field
in fit file must come the Reference Field before the Dynamic Field.

for example Message device_info:

in profile.xls:
device_type Field Def # 1
source_type Field Def # 25

in fit file:
source_type field # x
device_type field # x + n
)


Thank you
edge-python      
Avatar
RankRankRankRank

Total Posts: 296

Joined 0

PM

To my best knowledge you should NOT rely on sequence of fields.
I don't know how you parse .FIT files, but I found it the easiest way to read in a complete message and parse the complete message (instead of a purely sequential parser).
Btw, the interpretation of the Event.Data field is explained in profile.xls - if you've not already found this info.

Cheers,
OMB      
RankRankRank

Total Posts: 91

Joined 2012-10-12

PM

The SDK allows fields to be written in any order, messages should be fully decoded before interpreting subfields. I will clarify §4.5.      
RankRank

Total Posts: 44

Joined 2013-04-07

PM

ShaneP - 10 April 2015 02:21 PM
The SDK allows fields to be written in any order, messages should be fully decoded before interpreting subfields. I will clarify §4.5.

Thanks for the clarification.


For Dynamic Fields I have a further question:


Dynamic Fields based on 1 Reference Field, up to 1 exception:

The Dynamic Field 'target_value' (Message 'workout_step') is based on 2 Reference Fields.

Following description is accurate for all situations?
(or not comprehensive?)

#       Message: workout_step
# Dynamic Field: target_value

if target_type in ['heart_rate','power']:
    
RefField target_type
else:
    
RefField duration_type 


Thank you.
edge-python
     
RankRankRank

Total Posts: 91

Joined 2012-10-12

PM

I look at it more this way:
if target_type == heart_rate
  
// Interpret field#4 (target_value) as 'target_hr_zone'
else if duration_type == repeat_until_time
  
// Interpret field#4 (target_value) as 'repeat_time'
  // units are s
  // Scale is 1000

else if ((duration_type == repeat_until_hr_less_than) OR (duration_type == repeat_until_hr_greater_than))
  
// Interpret field#4 (target_value) as 'repeat_hr'
  // units are %orBPM
  // Type is 'workout_hr' instead of uint32 

Messages should not be defined such that more than one reference field condition can be satisfied at once. If this occurs the first one should take priority.

     
RankRank

Total Posts: 44

Joined 2013-04-07

PM

Thanks for the answer.

ShaneP - 17 April 2015 01:20 PM

Messages should not be defined such that more than one reference field condition can be satisfied at once.

The FIT SDK example 'WorkoutRepeatGreaterThanStep' contains a message with 2 satisfied reference field condition:

duration_type = 11: repeat_until_hr_greater_than
target_type = 1: heart_rate

the field target_value is interpreted as: target_hr_zone (target_type is the reference field in this case)

ShaneP - 17 April 2015 01:20 PM

If this occurs the first one should take priority.

In the example target_type seems to have the higher priority than duration_type, regardless of the order.

In the example seems to apply:

#       Message: workout_step
# Dynamic Field: target_value

if target_type in ['heart_rate','power']:
    
# use target_type as Reference Field
else:
    
# use duration_type as Reference Field 

Thank you.
edge-python
(sorry, english is not my native language)