Class: Fit4Ruby::Monitoring_B

Inherits:
FitDataRecord show all
Defined in:
lib/fit4ruby/Monitoring_B.rb

Overview

The Monitoring_B object is a FIT file class. It’s a top-level object that holds all references to other FIT records that are part of the FIT file. Each of the objects it references are direct equivalents of the message record structures used in the FIT file.

Constant Summary

Constants inherited from FitDataRecord

FitDataRecord::RecordOrder

Constants included from BDFieldNameTranslator

BDFieldNameTranslator::BD_DICT

Instance Attribute Summary collapse

Attributes inherited from FitDataRecord

#message, #timestamp

Instance Method Summary collapse

Methods inherited from FitDataRecord

#<=>, #==, #export, #get, #get_as, #get_unit_by_name, #set, #set_field_values, #write

Methods included from BDFieldNameTranslator

#to_bd_field_name

Methods included from Converters

#conversion_factor, #fit_time_to_time, #secsToDHMS, #secsToHM, #secsToHMS, #speedToPace, #time_to_fit_time

Constructor Details

#initialize(field_values = {}) ⇒ Monitoring_B

Create a new Monitoring_B object.

Parameters:

  • field_values (Hash) (defaults to: {})

    A Hash that provides initial values for certain fields of the FitDataRecord.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fit4ruby/Monitoring_B.rb', line 34

def initialize(field_values = {})
  super('activity')
  @num_sessions = 0

  @file_id = FileId.new
  @field_descriptions = []
  @device_infos = []
  @softwares = nil
  @monitoring_infos = []
  @monitorings = []
end

Instance Attribute Details

#device_infosObject

Returns the value of attribute device_infos.



28
29
30
# File 'lib/fit4ruby/Monitoring_B.rb', line 28

def device_infos
  @device_infos
end

#field_descriptionsObject

Returns the value of attribute field_descriptions.



28
29
30
# File 'lib/fit4ruby/Monitoring_B.rb', line 28

def field_descriptions
  @field_descriptions
end

#file_idObject

Returns the value of attribute file_id.



28
29
30
# File 'lib/fit4ruby/Monitoring_B.rb', line 28

def file_id
  @file_id
end

#monitoring_infosObject

Returns the value of attribute monitoring_infos.



28
29
30
# File 'lib/fit4ruby/Monitoring_B.rb', line 28

def monitoring_infos
  @monitoring_infos
end

#monitoringsObject

Returns the value of attribute monitorings.



28
29
30
# File 'lib/fit4ruby/Monitoring_B.rb', line 28

def monitorings
  @monitorings
end

#softwareObject

Returns the value of attribute software.



28
29
30
# File 'lib/fit4ruby/Monitoring_B.rb', line 28

def software
  @software
end

Instance Method Details

#checkObject

Perform some basic logical checks on the object and all references sub objects. Any errors will be reported via the Log object.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fit4ruby/Monitoring_B.rb', line 48

def check
  last_timestamp = ts_16_offset = nil
  last_ts_16 = nil

  # The timestamp_16 is a 2 byte time stamp value that is used instead of
  # the 4 byte timestamp field for monitoring records that have
  # current_activity_type_intensity values with an activity type of 6. The
  # value seems to be in seconds, but the 0 value reference does not seem
  # to be included in the file. However, it can be approximated using the
  # surrounding timestamp values.
  @monitorings.each do |record|
    if last_ts_16 && ts_16_offset && record.timestamp_16 &&
       record.timestamp_16 < last_ts_16
      # Detect timestamp_16 wrap-arounds. timestamp_16 is a 16 bit value.
      # In case of a wrap-around we adjust the ts_16_offset accordingly.
      ts_16_offset += 2 ** 16
    end
    if ts_16_offset
      # We have already found the offset. Adjust all timestamps according
      # to 'offset + timestamp_16'
      if record.timestamp_16
        record.timestamp = ts_16_offset + record.timestamp_16
        last_ts_16 = record.timestamp_16
      end
    else
      # We are still looking for the offset.
      if record.timestamp_16 && last_timestamp
        # We have a previous timestamp and found the first record with a
        # timestamp_16 value set. We assume that the timestamp of this
        # record is one minute after the previously found timestamp.
        # That's just a guess. Who knows what the Garmin engineers were
        # thinking here?
        ts_16_offset = last_timestamp + 60 - record.timestamp_16
        record.timestamp = ts_16_offset + record.timestamp_16
        last_ts_16 = record.timestamp_16
      else
        # Just save the timestamp of the current record.
        last_timestamp = record.timestamp
      end
    end
  end
end

#new_fit_data_record(record_type, field_values = {}) ⇒ Object

Create a new FitDataRecord.

Parameters:

  • record_type (String)

    Type that identifies the FitDataRecord derived class to create.

  • field_values (Hash) (defaults to: {})

    A Hash that provides initial values for certain fields of the FitDataRecord.

Returns:

  • FitDataRecord



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/fit4ruby/Monitoring_B.rb', line 97

def new_fit_data_record(record_type, field_values = {})
  case record_type
  when 'file_id'
    @file_id = (record = FileId.new(field_values))
  when 'software'
    @software = (record = Software.new(field_values))
  when 'device_info'
    @device_infos << (record = DeviceInfo.new(field_values))
  when 'monitoring_info'
    @monitoring_infos << (record = MonitoringInfo.new(field_values))
  when 'monitoring'
    @monitorings << (record = Monitoring.new(field_values))
  else
    record = nil
  end

  record
end