class Elemac::Converter
Constants
- BIT16_HIGH_MASK
- BIT16_LOW_MASK
- BIT32_HIGH_MASK
- BIT32_LOW_MASK
Public Class Methods
bit16_high(value)
click to toggle source
# File lib/elemac/converter.rb, line 15 def self.bit16_high(value) (value & BIT16_HIGH_MASK) >> 8 end
bit16_low(value)
click to toggle source
# File lib/elemac/converter.rb, line 18 def self.bit16_low(value) (value & BIT16_LOW_MASK) end
bit32_high(value)
click to toggle source
# File lib/elemac/converter.rb, line 9 def self.bit32_high(value) (value & BIT16_HIGH_MASK) >> 24 end
bit32_low(value)
click to toggle source
# File lib/elemac/converter.rb, line 12 def self.bit32_low(value) (value & BIT32_LOW_MASK) >> 16 end
format_date(year,month,date)
click to toggle source
# File lib/elemac/converter.rb, line 55 def self.format_date(year,month,date) "#{year.to_s.rjust(2,'0')}-#{month.to_s.rjust(2,'0')}-#{date.to_s.rjust(2,'0')}" end
format_time(hour,minute,second)
click to toggle source
# File lib/elemac/converter.rb, line 58 def self.format_time(hour,minute,second) "#{hour.to_s.rjust(2,'0')}:#{minute.to_s.rjust(2,'0')}:#{second.to_s.rjust(2,'0')}" end
int_to_hour(value)
click to toggle source
# File lib/elemac/converter.rb, line 21 def self.int_to_hour(value) hour = bit16_low(value).to_s minute = bit16_high(value).to_s "#{hour.rjust(2,'0')}:#{minute.rjust(2,'0')}" end
long_to_date(value)
click to toggle source
# File lib/elemac/converter.rb, line 30 def self.long_to_date(value) day = bit32_low(value).to_s month = bit16_high(value).to_s year = (2000 + bit16_low(value).to_i).to_s "#{year}-#{month.rjust(2,'0')}-#{day.rjust(2,'0')}" end
ph_9_enabled(value)
click to toggle source
# File lib/elemac/converter.rb, line 61 def self.ph_9_enabled(value) value & 4 > 0 end
ph_reminder(value, calibration_date, reminder=0)
click to toggle source
calibration date should be in format YYYY-MM-DD reminder is the amount of months that ph has to be calibrated
# File lib/elemac/converter.rb, line 38 def self.ph_reminder(value, calibration_date, reminder=0) value = value & 3 ph7, ph49, out_of_date = false case(value) when 0 ph7, ph49, out_of_date = false, false, false when 1 ph7, ph49, out_of_date = true, false, false when 2 ph7, ph49, out_of_date = false, true, false when 3 ph7, ph49 = true, true next_calibration_date = Date.parse(calibration_date) << -reminder out_of_date = next_calibration_date < Date.today end "PH7: #{ph7.to_s}, PH49: #{ph49.to_s}, Calibrated: #{out_of_date.to_s}" end
seconds_to_hsm(value)
click to toggle source
# File lib/elemac/converter.rb, line 26 def self.seconds_to_hsm(value) value = 14400 if value > 14400 Time.at(value).utc.strftime("%H:%M:%S") end