Class: TimexDatalinkClient::Protocol4::Time

Inherits:
Object
  • Object
show all
Includes:
Helpers::CharEncoders, Helpers::CrcPacketsWrapper
Defined in:
lib/timex_datalink_client/protocol_4/time.rb

Constant Summary collapse

CPACKET_TIME =
[0x32]

Constants included from Helpers::CharEncoders

Helpers::CharEncoders::CHARS, Helpers::CharEncoders::EEPROM_CHARS, Helpers::CharEncoders::EEPROM_TERMINATOR, Helpers::CharEncoders::INVALID_CHAR, Helpers::CharEncoders::PHONE_CHARS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::CharEncoders

#chars_for, #eeprom_chars_for, #phone_chars_for

Constructor Details

#initialize(zone:, is_24h:, date_format:, time:, name: nil) ⇒ Time

Create a Time instance.

Parameters:

  • zone (Integer)

    Time zone number (1 or 2).

  • is_24h (Boolean)

    Toggle 24 hour time.

  • date_format (Integer)

    Date format.

  • time (::Time)

    Time to set (including time zone).

  • name (String, nil) (defaults to: nil)

    Name of time zone (defaults to zone from time; 3 chars max)



24
25
26
27
28
29
30
# File 'lib/timex_datalink_client/protocol_4/time.rb', line 24

def initialize(zone:, is_24h:, date_format:, time:, name: nil)
  @zone = zone
  @is_24h = is_24h
  @date_format = date_format
  @time = time
  @name = name
end

Instance Attribute Details

#date_formatObject

Returns the value of attribute date_format.



14
15
16
# File 'lib/timex_datalink_client/protocol_4/time.rb', line 14

def date_format
  @date_format
end

#is_24hObject

Returns the value of attribute is_24h.



14
15
16
# File 'lib/timex_datalink_client/protocol_4/time.rb', line 14

def is_24h
  @is_24h
end

#timeObject

Returns the value of attribute time.



14
15
16
# File 'lib/timex_datalink_client/protocol_4/time.rb', line 14

def time
  @time
end

#zoneObject

Returns the value of attribute zone.



14
15
16
# File 'lib/timex_datalink_client/protocol_4/time.rb', line 14

def zone
  @zone
end

Instance Method Details

#packetsArray<Array<Integer>>

Compile packets for a time.

Returns:

  • (Array<Array<Integer>>)

    Two-dimensional array of integers that represent bytes.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/timex_datalink_client/protocol_4/time.rb', line 35

def packets
  [
    [
      CPACKET_TIME,
      zone,
      time.sec,
      time.hour,
      time.min,
      time.month,
      time.day,
      year_mod_1900,
      name_characters,
      wday_from_monday,
      is_24h_value,
      date_format
    ].flatten
  ]
end