Class: Fit4Ruby::FitHeader

Inherits:
BinData::Record
  • Object
show all
Includes:
CRC16
Defined in:
lib/fit4ruby/FitHeader.rb

Instance Method Summary collapse

Methods included from CRC16

#compute_crc, #write_crc

Instance Method Details

#dumpObject



54
55
56
57
58
59
60
61
62
# File 'lib/fit4ruby/FitHeader.rb', line 54

def dump
  puts <<"EOT"
Fit File Header
  Header Size: #{header_size.snapshot}
  Protocol Version: #{protocol_version.snapshot}
  Profile Version: #{profile_version.snapshot}
  Data Size: #{data_size.snapshot}
EOT
end

#end_posObject



68
69
70
# File 'lib/fit4ruby/FitHeader.rb', line 68

def end_pos
  header_size.snapshot  + data_size.snapshot
end

#has_crc?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/fit4ruby/FitHeader.rb', line 64

def has_crc?
  header_size.snapshot == 14
end

#read(io) ⇒ Object



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

def read(io)
  super

  unless header_size.snapshot == 12 || header_size.snapshot == 14
    Log.fatal "Unsupported header size #{header_size.snapshot}"
  end
  unless data_type.snapshot == '.FIT'
    Log.fatal "Unknown file type #{data_type.snapshot}"
  end
  if crc.snapshot != 0 &&
     compute_crc(io, 0, header_size.snapshot - 2) != crc.snapshot
    Log.fatal "CRC mismatch in header."
  end
end

#write(io) ⇒ Object



48
49
50
51
52
# File 'lib/fit4ruby/FitHeader.rb', line 48

def write(io)
  super

  write_crc(io, 0, header_size.snapshot - 2)
end