Class: TimexDatalinkClient::Protocol1::Time

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

Constant Summary collapse

CPACKET_TIME =
[0x30]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zone:, is_24h:, time:) ⇒ Time

Create a Time instance.

Parameters:

  • zone (Integer)

    Time zone number (1 or 2).

  • is_24h (Boolean)

    Toggle 24 hour time.

  • time (::Time)

    Time to set.



20
21
22
23
24
# File 'lib/timex_datalink_client/protocol_1/time.rb', line 20

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

Instance Attribute Details

#is_24hObject

Returns the value of attribute is_24h.



12
13
14
# File 'lib/timex_datalink_client/protocol_1/time.rb', line 12

def is_24h
  @is_24h
end

#timeObject

Returns the value of attribute time.



12
13
14
# File 'lib/timex_datalink_client/protocol_1/time.rb', line 12

def time
  @time
end

#zoneObject

Returns the value of attribute zone.



12
13
14
# File 'lib/timex_datalink_client/protocol_1/time.rb', line 12

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.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/timex_datalink_client/protocol_1/time.rb', line 29

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