Class: TimexDatalinkClient::Protocol9::Alarm

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

Constant Summary collapse

CPACKET_ALARM =
[0x50]
VALID_DAYS_IN_MONTH =
{
  1 => 1..31,
  2 => 1..29,
  3 => 1..31,
  4 => 1..30,
  5 => 1..31,
  6 => 1..30,
  7 => 1..31,
  8 => 1..31,
  9 => 1..30,
  10 => 1..31,
  11 => 1..30,
  12 => 1..31
}.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(number:, audible:, time:, message:, month: nil, day: nil) ⇒ Alarm

Create an Alarm instance.

Parameters:

  • number (Integer)

    Alarm number (from 1 to 10).

  • audible (Boolean)

    Toggle alarm sounds.

  • time (::Time)

    Time of alarm.

  • message (String)

    Alarm message text.

  • month (Integer, nil) (defaults to: nil)

    Month of alarm.

  • day (Integer, nil) (defaults to: nil)

    Day of alarm.



70
71
72
73
74
75
76
77
# File 'lib/timex_datalink_client/protocol_9/alarm.rb', line 70

def initialize(number:, audible:, time:, message:, month: nil, day: nil)
  @number = number
  @audible = audible
  @time = time
  @message = message
  @month = month
  @day = day
end

Instance Attribute Details

#audibleObject

Returns the value of attribute audible.



32
33
34
# File 'lib/timex_datalink_client/protocol_9/alarm.rb', line 32

def audible
  @audible
end

#dayObject

Returns the value of attribute day.



32
33
34
# File 'lib/timex_datalink_client/protocol_9/alarm.rb', line 32

def day
  @day
end

#messageObject

Returns the value of attribute message.



32
33
34
# File 'lib/timex_datalink_client/protocol_9/alarm.rb', line 32

def message
  @message
end

#monthObject

Returns the value of attribute month.



32
33
34
# File 'lib/timex_datalink_client/protocol_9/alarm.rb', line 32

def month
  @month
end

#numberObject

Returns the value of attribute number.



32
33
34
# File 'lib/timex_datalink_client/protocol_9/alarm.rb', line 32

def number
  @number
end

#timeObject

Returns the value of attribute time.



32
33
34
# File 'lib/timex_datalink_client/protocol_9/alarm.rb', line 32

def time
  @time
end

Instance Method Details

#packetsArray<Array<Integer>>

Compile packets for an alarm.

Returns:

  • (Array<Array<Integer>>)

    Two-dimensional array of integers that represent bytes.

Raises:

  • (ActiveModel::ValidationError)

    One or more model values are invalid.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/timex_datalink_client/protocol_9/alarm.rb', line 83

def packets
  validate!

  [
    [
      CPACKET_ALARM,
      number,
      time.hour,
      time.min,
      month.to_i,
      day.to_i,
      audible_integer,
      message_characters
    ].flatten
  ]
end