Class: ICharger::Log::Row
- Inherits:
-
Object
- Object
- ICharger::Log::Row
- Defined in:
- lib/icharger/log/row.rb
Instance Method Summary collapse
-
#capacity ⇒ Float
Gets the capacity stored or removed so far, in amp-hours.
-
#cell_count ⇒ Number
Gets the number of individual cells measured.
-
#cell_voltage(index) ⇒ Float
Gets the individual cell voltage, in volts.
-
#channel ⇒ Number
Gets the charger channel number.
-
#current ⇒ Float
Gets the instantaneous charge (+) or discharge (-) current, in amps.
-
#external_temperature(unit = :c) ⇒ Float
Gets the external temperature sensor value, in celsius or fahrenheit.
- #external_temperature? ⇒ Boolean
- #field21 ⇒ Object
-
#field3 ⇒ Object
XXX always seems to be 1.
-
#field4 ⇒ Object
XXX always seems to be 0.
-
#initialize(raw_line) ⇒ Row
constructor
A new instance of Row.
-
#input_voltage ⇒ Float
Gets the input power supply voltage, in volts.
-
#internal_temperature(unit = :c) ⇒ Float
Gets the internal temperature sensor value, in celsius or fahrenheit.
- #internal_temperature? ⇒ Boolean
-
#pack_voltage ⇒ Float
Gets the total battery pack voltage, in volts.
-
#state ⇒ Object
Gets the current state of operation.
-
#time ⇒ Number
Gets the time in milliseconds.
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
#capacity ⇒ Float
Gets the capacity stored or removed so far, in amp-hours.
70 71 72 |
# File 'lib/icharger/log/row.rb', line 70 def capacity @fields[8].to_i / 100.0 end |
#cell_count ⇒ Number
Gets the number of individual cells measured.
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.
103 104 105 |
# File 'lib/icharger/log/row.rb', line 103 def cell_voltage(index) @fields[11 + index].to_i / 1000.0 end |
#channel ⇒ Number
Gets the 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 |
#current ⇒ Float
Gets the instantaneous charge (+) or discharge (-) current, in amps.
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.
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
86 87 88 |
# File 'lib/icharger/log/row.rb', line 86 def external_temperature? 0 != external_temperature end |
#field21 ⇒ Object
115 116 117 |
# File 'lib/icharger/log/row.rb', line 115 def field21 @fields[21].to_i end |
#field3 ⇒ Object
XXX always seems to be 1
37 38 39 |
# File 'lib/icharger/log/row.rb', line 37 def field3 @fields[3].to_i end |
#field4 ⇒ Object
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_voltage ⇒ Float
Gets the input power supply voltage, in volts.
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.
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
74 75 76 |
# File 'lib/icharger/log/row.rb', line 74 def internal_temperature? 0 != internal_temperature end |
#pack_voltage ⇒ Float
Gets the total battery pack voltage, in volts.
63 64 65 |
# File 'lib/icharger/log/row.rb', line 63 def pack_voltage @fields[7].to_i / 1000.0 end |
#state ⇒ Object
This is a guess…
Gets the current state of operation.
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 |
#time ⇒ Number
Gets the time in milliseconds.
32 33 34 |
# File 'lib/icharger/log/row.rb', line 32 def time @fields[2].to_i end |