Class: ICharger::Log::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/icharger/log/row.rb

Instance Method Summary collapse

Constructor Details

#initialize(raw_line) ⇒ Row

Returns a new instance of Row.



6
7
8
9
# File 'lib/icharger/log/row.rb', line 6

def initialize(raw_line)
  @fields = raw_line.strip.split(';')
  throw ArgumentError, "Unexpected field count (#{@fields.length})" unless @fields.length == 22
end

Instance Method Details

#capacityFloat

Gets the capacity stored or removed so far, in amp-hours.

Returns:

  • (Float)

    amp-hours stored (+) or removed (-)



70
71
72
# File 'lib/icharger/log/row.rb', line 70

def capacity
  @fields[8].to_i / 100.0
end

#cell_countNumber

Gets the number of individual cells measured.

Returns:

  • (Number)

    number of individual cells

See Also:



111
112
113
# File 'lib/icharger/log/row.rb', line 111

def cell_count
  @fields[11..20].reject{ |v| v.to_i == 0 }.length
end

#cell_voltage(index) ⇒ Float

Gets the individual cell voltage, in volts.

Parameters:

  • index

    index of the cell (0-based)

Returns:

  • (Float)

    specified cell voltage (V)

See Also:



103
104
105
# File 'lib/icharger/log/row.rb', line 103

def cell_voltage(index)
  @fields[11 + index].to_i / 1000.0
end

#channelNumber

Gets the charger channel number.

Returns:

  • (Number)

    charger channel number



14
15
16
# File 'lib/icharger/log/row.rb', line 14

def channel
  /(?<ch>\d)/.match(@fields[0])[:ch].to_i
end

#currentFloat

Gets the instantaneous charge (+) or discharge (-) current, in amps.

Returns:

  • (Float)

    instantaneous current (A)



49
50
51
# File 'lib/icharger/log/row.rb', line 49

def current
  @fields[5].to_i / 100.0
end

#external_temperature(unit = :c) ⇒ Float

Gets the external temperature sensor value, in celsius or fahrenheit.

Parameters:

  • unit (defaults to: :c)

    :c or :f for celsius or fahrenheit

Returns:

  • (Float)

    temperature in requested unit



94
95
96
# File 'lib/icharger/log/row.rb', line 94

def external_temperature(unit = :c)
  convert_temperature((@fields[10].to_i / 10.0), unit)
end

#external_temperature?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/icharger/log/row.rb', line 86

def external_temperature?
  0 != external_temperature
end

#field21Object



115
116
117
# File 'lib/icharger/log/row.rb', line 115

def field21
  @fields[21].to_i
end

#field3Object

XXX always seems to be 1



37
38
39
# File 'lib/icharger/log/row.rb', line 37

def field3
  @fields[3].to_i
end

#field4Object

XXX always seems to be 0



42
43
44
# File 'lib/icharger/log/row.rb', line 42

def field4
  @fields[4].to_i
end

#input_voltageFloat

Gets the input power supply voltage, in volts.

Returns:

  • (Float)

    input power supply (V)



56
57
58
# File 'lib/icharger/log/row.rb', line 56

def input_voltage
  @fields[6].to_i / 1000.0
end

#internal_temperature(unit = :c) ⇒ Float

Gets the internal temperature sensor value, in celsius or fahrenheit.

Parameters:

  • unit (defaults to: :c)

    :c or :f for celsius or fahrenheit

Returns:

  • (Float)

    temperature in requested unit



82
83
84
# File 'lib/icharger/log/row.rb', line 82

def internal_temperature(unit = :c)
  convert_temperature((@fields[9].to_i / 10.0), unit)
end

#internal_temperature?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/icharger/log/row.rb', line 74

def internal_temperature?
  0 != internal_temperature
end

#pack_voltageFloat

Gets the total battery pack voltage, in volts.

Returns:

  • (Float)

    battery pack voltage (V)



63
64
65
# File 'lib/icharger/log/row.rb', line 63

def pack_voltage
  @fields[7].to_i / 1000.0
end

#stateObject

Note:

This is a guess…

Gets the current state of operation.

Returns:

  • :charging, :discharging, :unknown



22
23
24
25
26
27
# File 'lib/icharger/log/row.rb', line 22

def state
  {
    1 => :charging,
    2 => :discharging
  }.fetch(@fields[1].to_i, :unknown)
end

#timeNumber

Gets the time in milliseconds.

Returns:

  • (Number)

    time stamp, in milliseconds



32
33
34
# File 'lib/icharger/log/row.rb', line 32

def time
  @fields[2].to_i
end