Class: F4R::GlobalFit::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/f4r.rb

Overview

Helper class to get all types and messages in a usable format for F4R.

Instance Method Summary collapse

Instance Method Details

#get_base_typesHash

Provides base types to F4R::GlobalFit.base_types.

Returns:

  • (Hash)


519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/f4r.rb', line 519

def get_base_types
  csv = CSV.read(Config.directory + '/base_types.csv', converters: %i[numeric])
  csv[1..-1].inject([]) do |r, row|
    r << {
      number: row[0],
      fit: row[1].to_sym,
      bindata: row[2].to_sym,
      bindata_en: row[3].to_sym,
      endian: row[4],
      bytes: row[5],
      undef: row[6],
    };r
  end
end

#get_messagesArray<Hash>

Provides messages to F4R::GlobalFit.messages.

Returns:

  • (Array<Hash>)


457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/f4r.rb', line 457

def get_messages
  messages = {}

  profile_messages.keys.each do |name|
    messages[name] = []
    if undocumented_messages[name]
      messages[name] = profile_messages[name] | undocumented_messages[name]
    else
      messages[name] = profile_messages[name]
    end
  end

  (undocumented_messages.keys - messages.keys).each do |name|
    messages[name] = undocumented_messages[name]
  end

  messages.keys.inject([]) do |r, name|
    type = GlobalFit.types[:mesg_num][:values].find { |v| v[:value_name] == name }
    source = undocumented_types[:mesg_num][:values].
      find { |t| t[:value_name] == name }

    unless type
      Log.error <<~ERROR
        Message "#{name}" not found in FIT profile or undocumented messages types.
      ERROR
    end

    r << {
      name: name,
      number: type[:value].to_i,
      source: source ? "F4R #{VERSION}" : "FIT SDK #{FIT_PROFILE_REV}",
      fields: messages[name.to_sym].select { |f| f[:field_def] }
    };r
  end
end

#get_typesHash

Provides types to F4R::GlobalFit.types.

Returns:

  • (Hash)


498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/f4r.rb', line 498

def get_types
  types = {}

  profile_types.keys.each do |name|
    types[name] = {}
    if undocumented_types[name]
      values = profile_types[name][:values] | undocumented_types[name][:values]
      types[name][:values] = values
    else
      types[name] = profile_types[name]
    end
  end

  types
end