timex_datalink_client 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/timex_datalink_client/helpers/char_encoders.rb +2 -2
- data/lib/timex_datalink_client/protocol_1/eeprom/anniversary.rb +44 -0
- data/lib/timex_datalink_client/protocol_1/eeprom/appointment.rb +49 -0
- data/lib/timex_datalink_client/protocol_1/eeprom/list.rb +43 -0
- data/lib/timex_datalink_client/protocol_1/eeprom/phone_number.rb +56 -0
- data/lib/timex_datalink_client/protocol_1/end.rb +12 -2
- data/lib/timex_datalink_client/protocol_1/sync.rb +33 -3
- data/lib/timex_datalink_client/protocol_3/eeprom/anniversary.rb +44 -0
- data/lib/timex_datalink_client/protocol_3/eeprom/appointment.rb +49 -0
- data/lib/timex_datalink_client/protocol_3/eeprom/list.rb +43 -0
- data/lib/timex_datalink_client/protocol_3/eeprom/phone_number.rb +56 -0
- data/lib/timex_datalink_client/protocol_3/end.rb +12 -2
- data/lib/timex_datalink_client/protocol_3/sync.rb +33 -3
- data/lib/timex_datalink_client/protocol_9/alarm.rb +63 -0
- data/lib/timex_datalink_client/protocol_9/eeprom/chrono.rb +47 -0
- data/lib/timex_datalink_client/protocol_9/eeprom/phone_number.rb +74 -0
- data/lib/timex_datalink_client/protocol_9/eeprom.rb +85 -0
- data/lib/timex_datalink_client/protocol_9/end.rb +20 -0
- data/lib/timex_datalink_client/protocol_9/sound_options.rb +42 -0
- data/lib/timex_datalink_client/protocol_9/start.rb +20 -0
- data/lib/timex_datalink_client/protocol_9/sync.rb +40 -0
- data/lib/timex_datalink_client/protocol_9/time.rb +61 -0
- data/lib/timex_datalink_client/protocol_9/time_name.rb +46 -0
- data/lib/timex_datalink_client/protocol_9/timer.rb +54 -0
- data/lib/timex_datalink_client/version.rb +1 -1
- data/lib/timex_datalink_client.rb +25 -8
- metadata +22 -9
- data/lib/timex_datalink_client/eeprom/anniversary.rb +0 -42
- data/lib/timex_datalink_client/eeprom/appointment.rb +0 -47
- data/lib/timex_datalink_client/eeprom/list.rb +0 -41
- data/lib/timex_datalink_client/eeprom/phone_number.rb +0 -56
- data/lib/timex_datalink_client/end.rb +0 -18
- data/lib/timex_datalink_client/sync.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1e1ba04b363121e40f0dd55b6ec5b6b97abed22e912f2b5155f11a0bef098c7
|
4
|
+
data.tar.gz: fbfaed8471f55ab6d5ebfa515f62f1d396239e4b9c043a3aad2f783be3007219
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
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)
|
@@ -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
|
@@ -1,10 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "timex_datalink_client/
|
3
|
+
require "timex_datalink_client/helpers/crc_packets_wrapper"
|
4
4
|
|
5
5
|
class TimexDatalinkClient
|
6
6
|
class Protocol1
|
7
|
-
class End
|
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
|
8
18
|
end
|
9
19
|
end
|
10
20
|
end
|
@@ -1,10 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "timex_datalink_client/sync"
|
4
|
-
|
5
3
|
class TimexDatalinkClient
|
6
4
|
class Protocol1
|
7
|
-
class Sync
|
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
|
8
38
|
end
|
9
39
|
end
|
10
40
|
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 Protocol3
|
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 Protocol3
|
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 Protocol3
|
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 Protocol3
|
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
|
@@ -1,10 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "timex_datalink_client/
|
3
|
+
require "timex_datalink_client/helpers/crc_packets_wrapper"
|
4
4
|
|
5
5
|
class TimexDatalinkClient
|
6
6
|
class Protocol3
|
7
|
-
class End
|
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
|
8
18
|
end
|
9
19
|
end
|
10
20
|
end
|
@@ -1,10 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "timex_datalink_client/sync"
|
4
|
-
|
5
3
|
class TimexDatalinkClient
|
6
4
|
class Protocol3
|
7
|
-
class Sync
|
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
|
8
38
|
end
|
9
39
|
end
|
10
40
|
end
|
@@ -0,0 +1,63 @@
|
|
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 Protocol9
|
8
|
+
class Alarm
|
9
|
+
include Helpers::CharEncoders
|
10
|
+
prepend Helpers::CrcPacketsWrapper
|
11
|
+
|
12
|
+
CPACKET_ALARM = [0x50]
|
13
|
+
|
14
|
+
attr_accessor :number, :audible, :time, :message, :month, :day
|
15
|
+
|
16
|
+
# Create an Alarm instance.
|
17
|
+
#
|
18
|
+
# @param number [Integer] Alarm number (from 1 to 10).
|
19
|
+
# @param audible [Boolean] Toggle alarm sounds.
|
20
|
+
# @param time [::Time] Time of alarm.
|
21
|
+
# @param message [String] Alarm message text.
|
22
|
+
# @param month [Integer, nil] Month of alarm.
|
23
|
+
# @param day [Integer, nil] Day of alarm.
|
24
|
+
# @return [Alarm] Alarm instance.
|
25
|
+
def initialize(number:, audible:, time:, message:, month: nil, day: nil)
|
26
|
+
@number = number
|
27
|
+
@audible = audible
|
28
|
+
@time = time
|
29
|
+
@message = message
|
30
|
+
@month = month
|
31
|
+
@day = day
|
32
|
+
end
|
33
|
+
|
34
|
+
# Compile packets for an alarm.
|
35
|
+
#
|
36
|
+
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
|
37
|
+
def packets
|
38
|
+
[
|
39
|
+
[
|
40
|
+
CPACKET_ALARM,
|
41
|
+
number,
|
42
|
+
time.hour,
|
43
|
+
time.min,
|
44
|
+
month.to_i,
|
45
|
+
day.to_i,
|
46
|
+
audible_integer,
|
47
|
+
message_characters
|
48
|
+
].flatten
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def message_characters
|
55
|
+
chars_for(message, length: 16, pad: true)
|
56
|
+
end
|
57
|
+
|
58
|
+
def audible_integer
|
59
|
+
audible ? 1 : 0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "timex_datalink_client/helpers/char_encoders"
|
4
|
+
|
5
|
+
class TimexDatalinkClient
|
6
|
+
class Protocol9
|
7
|
+
class Eeprom
|
8
|
+
class Chrono
|
9
|
+
include Helpers::CharEncoders
|
10
|
+
|
11
|
+
CHRONO_LABEL_LENGTH = 8
|
12
|
+
CHRONO_INITIAL_SIZE = 14
|
13
|
+
|
14
|
+
attr_accessor :label, :laps
|
15
|
+
|
16
|
+
# Create a Chrono instance.
|
17
|
+
#
|
18
|
+
# @param label [String] Label for chrono.
|
19
|
+
# @param laps [Integer] Number of laps for chrono.
|
20
|
+
# @return [Chrono] Chrono instance.
|
21
|
+
def initialize(label:, laps:)
|
22
|
+
@label = label
|
23
|
+
@laps = laps
|
24
|
+
end
|
25
|
+
|
26
|
+
# Compile a packet for a chrono.
|
27
|
+
#
|
28
|
+
# @return [Array<Integer>] Array of integers that represent bytes.
|
29
|
+
def packet
|
30
|
+
label_characters
|
31
|
+
end
|
32
|
+
|
33
|
+
def chrono_bytesize
|
34
|
+
CHRONO_INITIAL_SIZE + laps * 4
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def label_characters
|
40
|
+
centered_label = label.center(CHRONO_LABEL_LENGTH)
|
41
|
+
|
42
|
+
chars_for(centered_label, length: CHRONO_LABEL_LENGTH)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|