Class: TimexDatalinkClient::Protocol1::Time

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, 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.



28
29
30
31
32
# File 'lib/timex_datalink_client/protocol_1/time.rb', line 28

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.



15
16
17
# File 'lib/timex_datalink_client/protocol_1/time.rb', line 15

def is_24h
  @is_24h
end

#timeObject

Returns the value of attribute time.



15
16
17
# File 'lib/timex_datalink_client/protocol_1/time.rb', line 15

def time
  @time
end

#zoneObject

Returns the value of attribute zone.



15
16
17
# File 'lib/timex_datalink_client/protocol_1/time.rb', line 15

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.

Raises:

  • (ActiveModel::ValidationError)

    One or more model values are invalid.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/timex_datalink_client/protocol_1/time.rb', line 38

def packets
  validate!

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