timex_datalink_client 0.4.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/timex_datalink_client/helpers/char_encoders.rb +2 -2
  3. data/lib/timex_datalink_client/helpers/cpacket_paginator.rb +2 -4
  4. data/lib/timex_datalink_client/protocol_1/alarm.rb +82 -0
  5. data/lib/timex_datalink_client/protocol_1/eeprom/anniversary.rb +44 -0
  6. data/lib/timex_datalink_client/protocol_1/eeprom/appointment.rb +49 -0
  7. data/lib/timex_datalink_client/protocol_1/eeprom/list.rb +43 -0
  8. data/lib/timex_datalink_client/protocol_1/eeprom/phone_number.rb +56 -0
  9. data/lib/timex_datalink_client/protocol_1/eeprom.rb +100 -0
  10. data/lib/timex_datalink_client/protocol_1/end.rb +20 -0
  11. data/lib/timex_datalink_client/protocol_1/start.rb +20 -0
  12. data/lib/timex_datalink_client/protocol_1/sync.rb +40 -0
  13. data/lib/timex_datalink_client/protocol_1/time.rb +61 -0
  14. data/lib/timex_datalink_client/protocol_1/time_name.rb +46 -0
  15. data/lib/timex_datalink_client/protocol_3/alarm.rb +59 -0
  16. data/lib/timex_datalink_client/protocol_3/eeprom/anniversary.rb +44 -0
  17. data/lib/timex_datalink_client/protocol_3/eeprom/appointment.rb +49 -0
  18. data/lib/timex_datalink_client/protocol_3/eeprom/list.rb +43 -0
  19. data/lib/timex_datalink_client/protocol_3/eeprom/phone_number.rb +56 -0
  20. data/lib/timex_datalink_client/protocol_3/eeprom.rb +95 -0
  21. data/lib/timex_datalink_client/protocol_3/end.rb +20 -0
  22. data/lib/timex_datalink_client/protocol_3/sound_options.rb +42 -0
  23. data/lib/timex_datalink_client/protocol_3/sound_theme.rb +65 -0
  24. data/lib/timex_datalink_client/protocol_3/start.rb +20 -0
  25. data/lib/timex_datalink_client/protocol_3/sync.rb +40 -0
  26. data/lib/timex_datalink_client/protocol_3/time.rb +77 -0
  27. data/lib/timex_datalink_client/protocol_3/wrist_app.rb +67 -0
  28. data/lib/timex_datalink_client/protocol_9/alarm.rb +63 -0
  29. data/lib/timex_datalink_client/protocol_9/eeprom/chrono.rb +47 -0
  30. data/lib/timex_datalink_client/protocol_9/eeprom/phone_number.rb +74 -0
  31. data/lib/timex_datalink_client/protocol_9/eeprom.rb +85 -0
  32. data/lib/timex_datalink_client/protocol_9/end.rb +20 -0
  33. data/lib/timex_datalink_client/protocol_9/sound_options.rb +42 -0
  34. data/lib/timex_datalink_client/protocol_9/start.rb +20 -0
  35. data/lib/timex_datalink_client/protocol_9/sync.rb +40 -0
  36. data/lib/timex_datalink_client/protocol_9/time.rb +61 -0
  37. data/lib/timex_datalink_client/protocol_9/time_name.rb +46 -0
  38. data/lib/timex_datalink_client/protocol_9/timer.rb +54 -0
  39. data/lib/timex_datalink_client/version.rb +1 -1
  40. data/lib/timex_datalink_client.rb +44 -16
  41. metadata +38 -16
  42. data/lib/timex_datalink_client/alarm.rb +0 -59
  43. data/lib/timex_datalink_client/eeprom/anniversary.rb +0 -42
  44. data/lib/timex_datalink_client/eeprom/appointment.rb +0 -47
  45. data/lib/timex_datalink_client/eeprom/list.rb +0 -41
  46. data/lib/timex_datalink_client/eeprom/phone_number.rb +0 -56
  47. data/lib/timex_datalink_client/eeprom.rb +0 -92
  48. data/lib/timex_datalink_client/end.rb +0 -18
  49. data/lib/timex_datalink_client/sound_options.rb +0 -40
  50. data/lib/timex_datalink_client/sound_theme.rb +0 -62
  51. data/lib/timex_datalink_client/start.rb +0 -18
  52. data/lib/timex_datalink_client/sync.rb +0 -37
  53. data/lib/timex_datalink_client/time.rb +0 -75
  54. data/lib/timex_datalink_client/wrist_app.rb +0 -64
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '082ddc8969ac82b8858b2f68fd9c8f34b7f53b46eccc407200615eba75b00821'
4
- data.tar.gz: 99ae5a09d43fe26bf849808be2bceb18350d1c97e8fce962ee2a367a07a12677
3
+ metadata.gz: c1e1ba04b363121e40f0dd55b6ec5b6b97abed22e912f2b5155f11a0bef098c7
4
+ data.tar.gz: fbfaed8471f55ab6d5ebfa515f62f1d396239e4b9c043a3aad2f783be3007219
5
5
  SHA512:
6
- metadata.gz: 13adc215949a1c2af60c9d65da0e5ad8b780e27bf4f1009cc29ff85f7ffab3f9b912ae7f8cab1b785c14de28ece73036335eff2f7f85b78da9e2ca0e16e63eaa
7
- data.tar.gz: 43a8a73d8e9194295e83f7794e4b0c86d90b0b04b236b1f8b6779a267d33a6cc3af2de9b45efbab5112fa1dd26a4858a7a3c6755f49c6636e90782d5a49e6ce8
6
+ metadata.gz: fca16b6fdacba5294c6eb4b5645f5e2a8b54f3f38b1477771d84357e6365bb7e39e0821d9827e912d35f0f0dd2a58a081f422f650f604fb28770e55093895e41
7
+ data.tar.gz: fa6e1bc0cb2f273e729510cb6eabc4399c90c034ae3b7888fde84160aaff0a57b4867ba661929a437558613401435aa62e1ab71790494d764536cff6949b41a1
@@ -19,8 +19,8 @@ class TimexDatalinkClient
19
19
  end
20
20
  end
21
21
 
22
- def eeprom_chars_for(string_chars)
23
- chars = chars_for(string_chars, char_map: EEPROM_CHARS, length: 31).append(EEPROM_TERMINATOR)
22
+ def eeprom_chars_for(string_chars, length: 31)
23
+ chars = chars_for(string_chars, char_map: EEPROM_CHARS, length: length).append(EEPROM_TERMINATOR)
24
24
 
25
25
  packed_int = chars.each_with_index.sum do |char, index|
26
26
  char << (6 * index)
@@ -3,10 +3,8 @@
3
3
  class TimexDatalinkClient
4
4
  class Helpers
5
5
  module CpacketPaginator
6
- ITEMS_PER_PACKET = 32
7
-
8
- def paginate_cpackets(header:, cpackets:)
9
- paginated_cpackets = cpackets.each_slice(ITEMS_PER_PACKET)
6
+ def paginate_cpackets(header:, length:, cpackets:)
7
+ paginated_cpackets = cpackets.each_slice(length)
10
8
 
11
9
  paginated_cpackets.map.with_index(1) do |paginated_cpacket, index|
12
10
  header + [index] + paginated_cpacket
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/char_encoders"
4
+ require "timex_datalink_client/helpers/crc_packets_wrapper"
5
+
6
+ class TimexDatalinkClient
7
+ class Protocol1
8
+ class Alarm
9
+ include Helpers::CharEncoders
10
+ prepend Helpers::CrcPacketsWrapper
11
+
12
+ CPACKET_ALARM = [0x50]
13
+ CPACKET_ALARM_SILENT = [0x70, 0x00]
14
+
15
+ ALARM_SILENT_START_INDEX = 0x61
16
+
17
+ attr_accessor :number, :audible, :time, :message, :month, :day
18
+
19
+ # Create an Alarm instance.
20
+ #
21
+ # @param number [Integer] Alarm number (from 1 to 5).
22
+ # @param audible [Boolean] Toggle alarm sounds.
23
+ # @param time [::Time] Time of alarm.
24
+ # @param message [String] Alarm message text.
25
+ # @param month [Integer, nil] Month of alarm.
26
+ # @param day [Integer, nil] Day of alarm.
27
+ # @return [Alarm] Alarm instance.
28
+ def initialize(number:, audible:, time:, message:, month: nil, day: nil)
29
+ @number = number
30
+ @audible = audible
31
+ @time = time
32
+ @message = message
33
+ @month = month
34
+ @day = day
35
+ end
36
+
37
+ # Compile packets for an alarm.
38
+ #
39
+ # @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
40
+ def packets
41
+ [alarm_data_packet].tap do |packets|
42
+ packets << alarm_silent_packet unless audible
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def alarm_data_packet
49
+ [
50
+ CPACKET_ALARM,
51
+ number,
52
+ time.hour,
53
+ time.min,
54
+ month.to_i,
55
+ day.to_i,
56
+ message_characters,
57
+ audible_integer
58
+ ].flatten
59
+ end
60
+
61
+ def alarm_silent_packet
62
+ [
63
+ CPACKET_ALARM_SILENT,
64
+ alarm_silent_index,
65
+ 0
66
+ ].flatten
67
+ end
68
+
69
+ def message_characters
70
+ chars_for(message, length: 8, pad: true)
71
+ end
72
+
73
+ def audible_integer
74
+ audible ? 1 : 0
75
+ end
76
+
77
+ def alarm_silent_index
78
+ ALARM_SILENT_START_INDEX + number
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/char_encoders"
4
+ require "timex_datalink_client/helpers/length_packet_wrapper"
5
+
6
+ class TimexDatalinkClient
7
+ class Protocol1
8
+ class Eeprom
9
+ class Anniversary
10
+ include Helpers::CharEncoders
11
+ prepend Helpers::LengthPacketWrapper
12
+
13
+ attr_accessor :time, :anniversary
14
+
15
+ # Create an Anniversary instance.
16
+ #
17
+ # @param time [::Time] Time of anniversary.
18
+ # @param anniversary [String] Anniversary text.
19
+ # @return [Anniversary] Anniversary instance.
20
+ def initialize(time:, anniversary:)
21
+ @time = time
22
+ @anniversary = anniversary
23
+ end
24
+
25
+ # Compile a packet for an anniversary.
26
+ #
27
+ # @return [Array<Integer>] Array of integers that represent bytes.
28
+ def packet
29
+ [
30
+ time.month,
31
+ time.day,
32
+ anniversary_characters
33
+ ].flatten
34
+ end
35
+
36
+ private
37
+
38
+ def anniversary_characters
39
+ eeprom_chars_for(anniversary)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/char_encoders"
4
+ require "timex_datalink_client/helpers/length_packet_wrapper"
5
+
6
+ class TimexDatalinkClient
7
+ class Protocol1
8
+ class Eeprom
9
+ class Appointment
10
+ include Helpers::CharEncoders
11
+ prepend Helpers::LengthPacketWrapper
12
+
13
+ attr_accessor :time, :message
14
+
15
+ # Create an Appointment instance.
16
+ #
17
+ # @param time [::Time] Time of appointment.
18
+ # @param message [String] Appointment text.
19
+ # @return [Appointment] Appointment instance.
20
+ def initialize(time:, message:)
21
+ @time = time
22
+ @message = message
23
+ end
24
+
25
+ # Compile a packet for an appointment.
26
+ #
27
+ # @return [Array<Integer>] Array of integers that represent bytes.
28
+ def packet
29
+ [
30
+ time.month,
31
+ time.day,
32
+ time_15m,
33
+ message_characters
34
+ ].flatten
35
+ end
36
+
37
+ private
38
+
39
+ def time_15m
40
+ time.hour * 4 + time.min / 15
41
+ end
42
+
43
+ def message_characters
44
+ eeprom_chars_for(message)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/char_encoders"
4
+ require "timex_datalink_client/helpers/length_packet_wrapper"
5
+
6
+ class TimexDatalinkClient
7
+ class Protocol1
8
+ class Eeprom
9
+ class List
10
+ include Helpers::CharEncoders
11
+ prepend Helpers::LengthPacketWrapper
12
+
13
+ attr_accessor :list_entry, :priority
14
+
15
+ # Create a List instance.
16
+ #
17
+ # @param list_entry [String] List entry text.
18
+ # @param priority [Integer] List priority.
19
+ # @return [List] List instance.
20
+ def initialize(list_entry:, priority:)
21
+ @list_entry = list_entry
22
+ @priority = priority
23
+ end
24
+
25
+ # Compile a packet for a list.
26
+ #
27
+ # @return [Array<Integer>] Array of integers that represent bytes.
28
+ def packet
29
+ [
30
+ priority,
31
+ list_entry_characters
32
+ ].flatten
33
+ end
34
+
35
+ private
36
+
37
+ def list_entry_characters
38
+ eeprom_chars_for(list_entry)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/char_encoders"
4
+ require "timex_datalink_client/helpers/length_packet_wrapper"
5
+
6
+ class TimexDatalinkClient
7
+ class Protocol1
8
+ class Eeprom
9
+ class PhoneNumber
10
+ include Helpers::CharEncoders
11
+ prepend Helpers::LengthPacketWrapper
12
+
13
+ PHONE_DIGITS = 12
14
+
15
+ attr_accessor :name, :number, :type
16
+
17
+ # Create a PhoneNumber instance.
18
+ #
19
+ # @param name [String] Name associated to phone number.
20
+ # @param number [String] Phone number text.
21
+ # @param type [String] Phone number type.
22
+ # @return [PhoneNumber] PhoneNumber instance.
23
+ def initialize(name:, number:, type: " ")
24
+ @name = name
25
+ @number = number
26
+ @type = type
27
+ end
28
+
29
+ # Compile a packet for a phone number.
30
+ #
31
+ # @return [Array<Integer>] Array of integers that represent bytes.
32
+ def packet
33
+ [
34
+ number_with_type_characters,
35
+ name_characters
36
+ ].flatten
37
+ end
38
+
39
+ private
40
+
41
+ def number_with_type_padded
42
+ number_with_type = "#{number} #{type}"
43
+ number_with_type.rjust(PHONE_DIGITS)
44
+ end
45
+
46
+ def number_with_type_characters
47
+ phone_chars_for(number_with_type_padded)
48
+ end
49
+
50
+ def name_characters
51
+ eeprom_chars_for(name)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/cpacket_paginator"
4
+ require "timex_datalink_client/helpers/crc_packets_wrapper"
5
+
6
+ class TimexDatalinkClient
7
+ class Protocol1
8
+ class Eeprom
9
+ include Helpers::CpacketPaginator
10
+ prepend Helpers::CrcPacketsWrapper
11
+
12
+ CPACKET_SECT = [0x60]
13
+ CPACKET_DATA = [0x61]
14
+ CPACKET_END = [0x62]
15
+
16
+ CPACKET_DATA_LENGTH = 27
17
+ START_INDEX = 14
18
+ APPOINTMENT_NO_NOTIFICATION = 0xff
19
+
20
+ attr_accessor :appointments, :anniversaries, :phone_numbers, :lists, :appointment_notification
21
+
22
+ # Create an Eeprom instance.
23
+ #
24
+ # @param appointments [Array<Appointment>] Appointments to be added to EEPROM data.
25
+ # @param anniversaries [Array<Anniversary>] Anniversaries to be added to EEPROM data.
26
+ # @param phone_numbers [Array<PhoneNumber>] Phone numbers to be added to EEPROM data.
27
+ # @param lists [Array<List>] Lists to be added to EEPROM data.
28
+ # @param appointment_notification [Integer] Appointment notification (intervals of 15 minutes, 255 for no
29
+ # notification)
30
+ # @return [Eeprom] Eeprom instance.
31
+ def initialize(appointments: [], anniversaries: [], phone_numbers: [], lists: [], appointment_notification: APPOINTMENT_NO_NOTIFICATION)
32
+ @appointments = appointments
33
+ @anniversaries = anniversaries
34
+ @phone_numbers = phone_numbers
35
+ @lists = lists
36
+ @appointment_notification = appointment_notification
37
+ end
38
+
39
+ # Compile packets for EEPROM data.
40
+ #
41
+ # @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
42
+ def packets
43
+ [header] + payloads + [CPACKET_END]
44
+ end
45
+
46
+ private
47
+
48
+ def header
49
+ [
50
+ CPACKET_SECT,
51
+ payloads.length
52
+ ].flatten
53
+ end
54
+
55
+ def payload
56
+ [
57
+ items_indexes,
58
+ items_lengths,
59
+ earliest_appointment_year,
60
+ appointment_notification,
61
+ all_packets
62
+ ].flatten
63
+ end
64
+
65
+ def payloads
66
+ paginate_cpackets(header: CPACKET_DATA, length: CPACKET_DATA_LENGTH, cpackets: payload)
67
+ end
68
+
69
+ def all_items
70
+ [appointments, lists, phone_numbers, anniversaries]
71
+ end
72
+
73
+ def all_packets
74
+ all_items.flatten.map(&:packet).flatten
75
+ end
76
+
77
+ def items_indexes
78
+ index = START_INDEX
79
+
80
+ all_items.each_with_object([]) do |items, indexes|
81
+ indexes.concat(index.divmod(256))
82
+
83
+ index += items.sum { |item| item.packet.length }
84
+ end
85
+ end
86
+
87
+ def items_lengths
88
+ all_items.map(&:length)
89
+ end
90
+
91
+ def earliest_appointment_year
92
+ earliest_appointment = appointments.min_by(&:time)
93
+
94
+ return 0 unless earliest_appointment
95
+
96
+ earliest_appointment.time.year % 100
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/crc_packets_wrapper"
4
+
5
+ class TimexDatalinkClient
6
+ class Protocol1
7
+ class End
8
+ prepend Helpers::CrcPacketsWrapper
9
+
10
+ CPACKET_SKIP = [0x21]
11
+
12
+ # Compile packets for data end command.
13
+ #
14
+ # @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
15
+ def packets
16
+ [CPACKET_SKIP]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/crc_packets_wrapper"
4
+
5
+ class TimexDatalinkClient
6
+ class Protocol1
7
+ class Start
8
+ prepend Helpers::CrcPacketsWrapper
9
+
10
+ CPACKET_START = [0x20, 0x00, 0x00, 0x01]
11
+
12
+ # Compile packets for data start command.
13
+ #
14
+ # @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
15
+ def packets
16
+ [CPACKET_START]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TimexDatalinkClient
4
+ class Protocol1
5
+ class Sync
6
+ PING_BYTE = [0x78]
7
+ SYNC_1_BYTE = [0x55]
8
+ SYNC_2_BYTE = [0xaa]
9
+
10
+ SYNC_2_LENGTH = 40
11
+
12
+ attr_accessor :length
13
+
14
+ # Create a Sync instance.
15
+ #
16
+ # @param length [Integer] Number of 0x55 sync bytes to use.
17
+ # @return [Sync] Sync instance.
18
+ def initialize(length: 300)
19
+ @length = length
20
+ end
21
+
22
+ # Compile packets for syncronization data.
23
+ #
24
+ # @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
25
+ def packets
26
+ [PING_BYTE + render_sync_1 + render_sync_2]
27
+ end
28
+
29
+ private
30
+
31
+ def render_sync_1
32
+ SYNC_1_BYTE * length
33
+ end
34
+
35
+ def render_sync_2
36
+ SYNC_2_BYTE * SYNC_2_LENGTH
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/crc_packets_wrapper"
4
+
5
+ class TimexDatalinkClient
6
+ class Protocol1
7
+ class Time
8
+ prepend Helpers::CrcPacketsWrapper
9
+
10
+ CPACKET_TIME = [0x30]
11
+
12
+ attr_accessor :zone, :is_24h, :time
13
+
14
+ # Create a Time instance.
15
+ #
16
+ # @param zone [Integer] Time zone number (1 or 2).
17
+ # @param is_24h [Boolean] Toggle 24 hour time.
18
+ # @param time [::Time] Time to set.
19
+ # @return [Time] Time instance.
20
+ def initialize(zone:, is_24h:, time:)
21
+ @zone = zone
22
+ @is_24h = is_24h
23
+ @time = time
24
+ end
25
+
26
+ # Compile packets for a time.
27
+ #
28
+ # @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
29
+ def packets
30
+ [
31
+ [
32
+ CPACKET_TIME,
33
+ zone,
34
+ time.hour,
35
+ time.min,
36
+ time.month,
37
+ time.day,
38
+ year_mod_1900,
39
+ wday_from_monday,
40
+ time.sec,
41
+ is_24h_value
42
+ ].flatten
43
+ ]
44
+ end
45
+
46
+ private
47
+
48
+ def year_mod_1900
49
+ time.year % 100
50
+ end
51
+
52
+ def wday_from_monday
53
+ (time.wday + 6) % 7
54
+ end
55
+
56
+ def is_24h_value
57
+ is_24h ? 2 : 1
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/char_encoders"
4
+ require "timex_datalink_client/helpers/crc_packets_wrapper"
5
+
6
+ class TimexDatalinkClient
7
+ class Protocol1
8
+ class TimeName
9
+ include Helpers::CharEncoders
10
+ prepend Helpers::CrcPacketsWrapper
11
+
12
+ CPACKET_NAME = [0x31]
13
+
14
+ attr_accessor :zone, :name
15
+
16
+ # Create a TimeName instance.
17
+ #
18
+ # @param zone [Integer] Time zone number (1 or 2).
19
+ # @param name [String] Name of time zone (3 chars max)
20
+ # @return [TimeName] TimeName instance.
21
+ def initialize(zone:, name:)
22
+ @zone = zone
23
+ @name = name
24
+ end
25
+
26
+ # Compile packets for a time name.
27
+ #
28
+ # @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
29
+ def packets
30
+ [
31
+ [
32
+ CPACKET_NAME,
33
+ zone,
34
+ name_characters
35
+ ].flatten
36
+ ]
37
+ end
38
+
39
+ private
40
+
41
+ def name_characters
42
+ chars_for(name, length: 3, pad: true)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timex_datalink_client/helpers/char_encoders"
4
+ require "timex_datalink_client/helpers/crc_packets_wrapper"
5
+
6
+ class TimexDatalinkClient
7
+ class Protocol3
8
+ class Alarm
9
+ include Helpers::CharEncoders
10
+ prepend Helpers::CrcPacketsWrapper
11
+
12
+ CPACKET_ALARM = [0x50]
13
+
14
+ attr_accessor :number, :audible, :time, :message
15
+
16
+ # Create an Alarm instance.
17
+ #
18
+ # @param number [Integer] Alarm number (from 1 to 5).
19
+ # @param audible [Boolean] Toggle alarm sounds.
20
+ # @param time [::Time] Time of alarm.
21
+ # @param message [String] Alarm message text.
22
+ # @return [Alarm] Alarm instance.
23
+ def initialize(number:, audible:, time:, message:)
24
+ @number = number
25
+ @audible = audible
26
+ @time = time
27
+ @message = message
28
+ end
29
+
30
+ # Compile packets for an alarm.
31
+ #
32
+ # @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
33
+ def packets
34
+ [
35
+ [
36
+ CPACKET_ALARM,
37
+ number,
38
+ time.hour,
39
+ time.min,
40
+ 0,
41
+ 0,
42
+ message_characters,
43
+ audible_integer
44
+ ].flatten
45
+ ]
46
+ end
47
+
48
+ private
49
+
50
+ def message_characters
51
+ chars_for(message, length: 8, pad: true)
52
+ end
53
+
54
+ def audible_integer
55
+ audible ? 1 : 0
56
+ end
57
+ end
58
+ end
59
+ end