Class: Elemac::Converter
- Inherits:
-
Object
- Object
- Elemac::Converter
- Defined in:
- lib/elemac/converter.rb
Constant Summary collapse
- BIT32_HIGH_MASK =
4278190080
- BIT32_LOW_MASK =
16711680
- BIT16_HIGH_MASK =
65280
- BIT16_LOW_MASK =
255
Class Method Summary collapse
- .bit16_high(value) ⇒ Object
- .bit16_low(value) ⇒ Object
- .bit32_high(value) ⇒ Object
- .bit32_low(value) ⇒ Object
- .format_date(year, month, date) ⇒ Object
- .format_time(hour, minute, second) ⇒ Object
- .int_to_hour(value) ⇒ Object
- .long_to_date(value) ⇒ Object
- .ph_9_enabled(value) ⇒ Object
-
.ph_reminder(value, calibration_date, reminder = 0) ⇒ Object
calibration date should be in format YYYY-MM-DD reminder is the amount of months that ph has to be calibrated.
- .seconds_to_hsm(value) ⇒ Object
Class Method Details
.bit16_high(value) ⇒ Object
15 16 17 |
# File 'lib/elemac/converter.rb', line 15 def self.bit16_high(value) (value & BIT16_HIGH_MASK) >> 8 end |
.bit16_low(value) ⇒ Object
18 19 20 |
# File 'lib/elemac/converter.rb', line 18 def self.bit16_low(value) (value & BIT16_LOW_MASK) end |
.bit32_high(value) ⇒ Object
9 10 11 |
# File 'lib/elemac/converter.rb', line 9 def self.bit32_high(value) (value & BIT16_HIGH_MASK) >> 24 end |
.bit32_low(value) ⇒ Object
12 13 14 |
# File 'lib/elemac/converter.rb', line 12 def self.bit32_low(value) (value & BIT32_LOW_MASK) >> 16 end |
.format_date(year, month, date) ⇒ Object
55 56 57 |
# 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) ⇒ Object
58 59 60 |
# 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) ⇒ Object
21 22 23 24 25 |
# 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) ⇒ Object
30 31 32 33 34 35 |
# 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) ⇒ Object
61 62 63 |
# File 'lib/elemac/converter.rb', line 61 def self.ph_9_enabled(value) value & 4 > 0 end |
.ph_reminder(value, calibration_date, reminder = 0) ⇒ Object
calibration date should be in format YYYY-MM-DD reminder is the amount of months that ph has to be calibrated
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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) ⇒ Object
26 27 28 29 |
# 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 |