Class: TimexDatalinkClient::Protocol6::Time

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

Constant Summary collapse

CPACKET_TIME =
[0x32].freeze
CPACKET_FLEX_TIME =
[0x33].freeze
ZONE_OFFSET_MAP =
{
  -39600 => 0x15,
  -36000 => 0x16,
  -32400 => 0x17,
  -28800 => 0x18,
  -25200 => 0x19,
  -21600 => 0x1a,
  -18000 => 0x1b,
  -14400 => 0x1c,
  -12600 => 0x14,
  -10800 => 0x1d,
  -7200 => 0x1e,
  -3600 => 0x1f,
  0 => 0x00,
  3600 => 0x01,
  7200 => 0x02,
  10800 => 0x03,
  12600 => 0x0d,
  14400 => 0x04,
  16200 => 0x0e,
  18000 => 0x05,
  19800 => 0x0f,
  20700 => 0x11,
  21600 => 0x06,
  23400 => 0x12,
  25200 => 0x07,
  28800 => 0x08,
  32400 => 0x09,
  34200 => 0x13,
  36000 => 0x0a,
  39600 => 0x0b,
  43200 => 0x0c
}.freeze
FLEX_TIME_ZONE =
0x10
FLEX_DST_VALUE =
0x08
DATE_FORMAT_MAP =
{
  "%_m-%d-%y" => 0x00,
  "%_d-%m-%y" => 0x01,
  "%y-%m-%d" => 0x02,
  "%_m.%d.%y" => 0x04,
  "%_d.%m.%y" => 0x05,
  "%y.%m.%d" => 0x06
}.freeze

Constants included from Helpers::CharEncoders

Helpers::CharEncoders::CHARS, Helpers::CharEncoders::CHARS_PROTOCOL_6, 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, #protocol_6_chars_for

Constructor Details

#initialize(zone:, is_24h:, date_format:, time:, name: nil, flex_time: false, flex_time_zone: false, flex_dst: false) ⇒ Time

Create a Time instance.

Parameters:

  • zone (Integer)

    Time zone number (1 or 2).

  • is_24h (Boolean)

    Toggle 24 hour time.

  • date_format ("%_m-%d-%y", "%_d-%m-%y", "%y-%m-%d", "%_m.%d.%y", "%_d.%m.%y", "%y.%m.%d")

    Date format (represented by Time#strftime 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).

  • flex_time (Boolean) (defaults to: false)

    Toggle using FLEXtime to set time and date.

  • flex_time_zone (Boolean) (defaults to: false)

    Toggle using FLEXtime to set time zone.

  • flex_dst (Boolean) (defaults to: false)

    Toggle using FLEXtime to apply daylight savings time offset.



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/timex_datalink_client/protocol_6/time.rb', line 98

def initialize(
  zone:, is_24h:, date_format:, time:, name: nil, flex_time: false, flex_time_zone: false, flex_dst: false
)
  @zone = zone
  @is_24h = is_24h
  @date_format = date_format
  @time = time
  @name = name
  @flex_time = flex_time
  @flex_time_zone = flex_time_zone
  @flex_dst = flex_dst
end

Instance Attribute Details

#date_formatObject

Returns the value of attribute date_format.



84
85
86
# File 'lib/timex_datalink_client/protocol_6/time.rb', line 84

def date_format
  @date_format
end

#flex_dstObject

Returns the value of attribute flex_dst.



84
85
86
# File 'lib/timex_datalink_client/protocol_6/time.rb', line 84

def flex_dst
  @flex_dst
end

#flex_timeObject

Returns the value of attribute flex_time.



84
85
86
# File 'lib/timex_datalink_client/protocol_6/time.rb', line 84

def flex_time
  @flex_time
end

#flex_time_zoneObject

Returns the value of attribute flex_time_zone.



84
85
86
# File 'lib/timex_datalink_client/protocol_6/time.rb', line 84

def flex_time_zone
  @flex_time_zone
end

#is_24hObject

Returns the value of attribute is_24h.



84
85
86
# File 'lib/timex_datalink_client/protocol_6/time.rb', line 84

def is_24h
  @is_24h
end

#nameObject

Returns the value of attribute name.



84
85
86
# File 'lib/timex_datalink_client/protocol_6/time.rb', line 84

def name
  @name
end

#timeObject

Returns the value of attribute time.



84
85
86
# File 'lib/timex_datalink_client/protocol_6/time.rb', line 84

def time
  @time
end

#zoneObject

Returns the value of attribute zone.



84
85
86
# File 'lib/timex_datalink_client/protocol_6/time.rb', line 84

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.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/timex_datalink_client/protocol_6/time.rb', line 115

def packets
  validate!

  [
    [
      cpacket,
      zone,
      second,
      hour,
      minute,
      month,
      day,
      year_mod_1900,
      name_characters,
      wday_from_monday,
      formatted_time_zone,
      is_24h_value,
      date_format_value
    ].flatten
  ]
end