timex_datalink_client 0.3.1 → 0.5.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.
- checksums.yaml +4 -4
- data/lib/timex_datalink_client/helpers/char_encoders.rb +12 -7
- data/lib/timex_datalink_client/helpers/cpacket_paginator.rb +2 -4
- data/lib/timex_datalink_client/protocol_1/alarm.rb +82 -0
- data/lib/timex_datalink_client/protocol_1/eeprom.rb +100 -0
- data/lib/timex_datalink_client/protocol_1/end.rb +10 -0
- data/lib/timex_datalink_client/protocol_1/start.rb +20 -0
- data/lib/timex_datalink_client/protocol_1/sync.rb +10 -0
- data/lib/timex_datalink_client/protocol_1/time.rb +61 -0
- data/lib/timex_datalink_client/protocol_1/time_name.rb +46 -0
- data/lib/timex_datalink_client/protocol_3/alarm.rb +59 -0
- data/lib/timex_datalink_client/protocol_3/eeprom.rb +95 -0
- data/lib/timex_datalink_client/protocol_3/end.rb +10 -0
- data/lib/timex_datalink_client/protocol_3/sound_options.rb +42 -0
- data/lib/timex_datalink_client/protocol_3/sound_theme.rb +65 -0
- data/lib/timex_datalink_client/protocol_3/start.rb +20 -0
- data/lib/timex_datalink_client/protocol_3/sync.rb +10 -0
- data/lib/timex_datalink_client/protocol_3/time.rb +77 -0
- data/lib/timex_datalink_client/protocol_3/wrist_app.rb +67 -0
- data/lib/timex_datalink_client/version.rb +1 -1
- data/lib/timex_datalink_client.rb +23 -12
- metadata +21 -12
- data/lib/timex_datalink_client/alarm.rb +0 -61
- data/lib/timex_datalink_client/eeprom.rb +0 -92
- data/lib/timex_datalink_client/sound_options.rb +0 -40
- data/lib/timex_datalink_client/sound_theme.rb +0 -62
- data/lib/timex_datalink_client/start.rb +0 -18
- data/lib/timex_datalink_client/time.rb +0 -69
- data/lib/timex_datalink_client/wrist_app.rb +0 -64
@@ -0,0 +1,77 @@
|
|
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 Time
|
9
|
+
include Helpers::CharEncoders
|
10
|
+
prepend Helpers::CrcPacketsWrapper
|
11
|
+
|
12
|
+
CPACKET_TIME = [0x32]
|
13
|
+
|
14
|
+
attr_accessor :zone, :is_24h, :date_format, :time
|
15
|
+
|
16
|
+
# Create a Time instance.
|
17
|
+
#
|
18
|
+
# @param zone [Integer] Time zone number (1 or 2).
|
19
|
+
# @param is_24h [Boolean] Toggle 24 hour time.
|
20
|
+
# @param date_format [Integer] Date format.
|
21
|
+
# @param time [::Time] Time to set (including time zone).
|
22
|
+
# @param name [String, nil] Name of time zone (defaults to zone from time; 3 chars max)
|
23
|
+
# @return [Time] Time instance.
|
24
|
+
def initialize(zone:, is_24h:, date_format:, time:, name: nil)
|
25
|
+
@zone = zone
|
26
|
+
@is_24h = is_24h
|
27
|
+
@date_format = date_format
|
28
|
+
@time = time
|
29
|
+
@name = name
|
30
|
+
end
|
31
|
+
|
32
|
+
# Compile packets for a time.
|
33
|
+
#
|
34
|
+
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
|
35
|
+
def packets
|
36
|
+
[
|
37
|
+
[
|
38
|
+
CPACKET_TIME,
|
39
|
+
zone,
|
40
|
+
time.sec,
|
41
|
+
time.hour,
|
42
|
+
time.min,
|
43
|
+
time.month,
|
44
|
+
time.day,
|
45
|
+
year_mod_1900,
|
46
|
+
name_characters,
|
47
|
+
wday_from_monday,
|
48
|
+
is_24h_value,
|
49
|
+
date_format
|
50
|
+
].flatten
|
51
|
+
]
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def name
|
57
|
+
@name || time.zone.downcase
|
58
|
+
end
|
59
|
+
|
60
|
+
def name_characters
|
61
|
+
chars_for(name, length: 3, pad: true)
|
62
|
+
end
|
63
|
+
|
64
|
+
def year_mod_1900
|
65
|
+
time.year % 100
|
66
|
+
end
|
67
|
+
|
68
|
+
def wday_from_monday
|
69
|
+
(time.wday + 6) % 7
|
70
|
+
end
|
71
|
+
|
72
|
+
def is_24h_value
|
73
|
+
is_24h ? 2 : 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,67 @@
|
|
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 Protocol3
|
8
|
+
class WristApp
|
9
|
+
include Helpers::CpacketPaginator
|
10
|
+
prepend Helpers::CrcPacketsWrapper
|
11
|
+
|
12
|
+
CPACKET_CLEAR = [0x93, 0x02]
|
13
|
+
CPACKET_SECT = [0x90, 0x02]
|
14
|
+
CPACKET_DATA = [0x91, 0x02]
|
15
|
+
CPACKET_END = [0x92, 0x02]
|
16
|
+
|
17
|
+
CPACKET_DATA_LENGTH = 32
|
18
|
+
WRIST_APP_DELIMITER = /\xac.*\r\n/n
|
19
|
+
WRIST_APP_CODE_INDEX = 8
|
20
|
+
|
21
|
+
attr_accessor :zap_file
|
22
|
+
|
23
|
+
# Create a WristApp instance.
|
24
|
+
#
|
25
|
+
# @param wrist_app_data [String, nil] WristApp data.
|
26
|
+
# @param zap_file [String, nil] Path to ZAP file.
|
27
|
+
# @return [WristApp] WristApp instance.
|
28
|
+
def initialize(wrist_app_data: nil, zap_file: nil)
|
29
|
+
@wrist_app_data = wrist_app_data
|
30
|
+
@zap_file = zap_file
|
31
|
+
end
|
32
|
+
|
33
|
+
# Compile packets for an alarm.
|
34
|
+
#
|
35
|
+
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
|
36
|
+
def packets
|
37
|
+
[CPACKET_CLEAR, cpacket_sect] + payloads + [CPACKET_END]
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def cpacket_sect
|
43
|
+
CPACKET_SECT + [payloads.length, 1]
|
44
|
+
end
|
45
|
+
|
46
|
+
def payloads
|
47
|
+
paginate_cpackets(header: CPACKET_DATA, length: CPACKET_DATA_LENGTH, cpackets: wrist_app_data.bytes)
|
48
|
+
end
|
49
|
+
|
50
|
+
def wrist_app_data
|
51
|
+
@wrist_app_data || zap_file_data_binary
|
52
|
+
end
|
53
|
+
|
54
|
+
def zap_file_data
|
55
|
+
File.open(zap_file, "rb").read
|
56
|
+
end
|
57
|
+
|
58
|
+
def zap_file_data_ascii
|
59
|
+
zap_file_data.split(WRIST_APP_DELIMITER)[WRIST_APP_CODE_INDEX]
|
60
|
+
end
|
61
|
+
|
62
|
+
def zap_file_data_binary
|
63
|
+
[zap_file_data_ascii].pack("H*")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,20 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "timex_datalink_client/
|
4
|
-
require "timex_datalink_client/
|
3
|
+
require "timex_datalink_client/version"
|
4
|
+
require "timex_datalink_client/notebook_adapter"
|
5
|
+
|
5
6
|
require "timex_datalink_client/eeprom/anniversary"
|
6
7
|
require "timex_datalink_client/eeprom/appointment"
|
7
8
|
require "timex_datalink_client/eeprom/list"
|
8
9
|
require "timex_datalink_client/eeprom/phone_number"
|
9
|
-
|
10
|
-
require "timex_datalink_client/
|
11
|
-
require "timex_datalink_client/
|
12
|
-
require "timex_datalink_client/
|
13
|
-
require "timex_datalink_client/start"
|
14
|
-
require "timex_datalink_client/sync"
|
15
|
-
require "timex_datalink_client/time"
|
16
|
-
require "timex_datalink_client/
|
17
|
-
|
10
|
+
|
11
|
+
require "timex_datalink_client/protocol_1/alarm"
|
12
|
+
require "timex_datalink_client/protocol_1/eeprom"
|
13
|
+
require "timex_datalink_client/protocol_1/end"
|
14
|
+
require "timex_datalink_client/protocol_1/start"
|
15
|
+
require "timex_datalink_client/protocol_1/sync"
|
16
|
+
require "timex_datalink_client/protocol_1/time"
|
17
|
+
require "timex_datalink_client/protocol_1/time_name"
|
18
|
+
|
19
|
+
require "timex_datalink_client/protocol_3/alarm"
|
20
|
+
require "timex_datalink_client/protocol_3/eeprom"
|
21
|
+
require "timex_datalink_client/protocol_3/end"
|
22
|
+
require "timex_datalink_client/protocol_3/sound_options"
|
23
|
+
require "timex_datalink_client/protocol_3/sound_theme"
|
24
|
+
require "timex_datalink_client/protocol_3/start"
|
25
|
+
require "timex_datalink_client/protocol_3/sync"
|
26
|
+
require "timex_datalink_client/protocol_3/time"
|
27
|
+
require "timex_datalink_client/protocol_3/wrist_app"
|
18
28
|
|
19
29
|
class TimexDatalinkClient
|
20
30
|
attr_accessor :serial_device, :models, :byte_sleep, :packet_sleep, :verbose
|
@@ -22,7 +32,8 @@ class TimexDatalinkClient
|
|
22
32
|
# Create a TimexDatalinkClient instance.
|
23
33
|
#
|
24
34
|
# @param serial_device [String] Path to serial device.
|
25
|
-
# @param models [Array<Alarm, Eeprom, End, SoundOptions,
|
35
|
+
# @param models [Array<Protocol3::Alarm, Protocol3::Eeprom, Protocol3::End, Protocol3::SoundOptions,
|
36
|
+
# Protocol3::SoundTheme, Protocol3::Start, Protocol3::Sync, Protocol3::Time, Protocol3::WristApp>] Models to compile
|
26
37
|
# data for.
|
27
38
|
# @param byte_sleep [Integer, nil] Time to sleep after sending byte.
|
28
39
|
# @param packet_sleep [Integer, nil] Time to sleep after sending packet of bytes.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timex_datalink_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxwell Pray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: crc
|
@@ -80,15 +80,13 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.0.9
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email: synthead@gmail.com
|
85
85
|
executables: []
|
86
86
|
extensions: []
|
87
87
|
extra_rdoc_files: []
|
88
88
|
files:
|
89
89
|
- lib/timex_datalink_client.rb
|
90
|
-
- lib/timex_datalink_client/alarm.rb
|
91
|
-
- lib/timex_datalink_client/eeprom.rb
|
92
90
|
- lib/timex_datalink_client/eeprom/anniversary.rb
|
93
91
|
- lib/timex_datalink_client/eeprom/appointment.rb
|
94
92
|
- lib/timex_datalink_client/eeprom/list.rb
|
@@ -99,14 +97,25 @@ files:
|
|
99
97
|
- lib/timex_datalink_client/helpers/crc_packets_wrapper.rb
|
100
98
|
- lib/timex_datalink_client/helpers/length_packet_wrapper.rb
|
101
99
|
- lib/timex_datalink_client/notebook_adapter.rb
|
102
|
-
- lib/timex_datalink_client/
|
103
|
-
- lib/timex_datalink_client/
|
104
|
-
- lib/timex_datalink_client/
|
100
|
+
- lib/timex_datalink_client/protocol_1/alarm.rb
|
101
|
+
- lib/timex_datalink_client/protocol_1/eeprom.rb
|
102
|
+
- lib/timex_datalink_client/protocol_1/end.rb
|
103
|
+
- lib/timex_datalink_client/protocol_1/start.rb
|
104
|
+
- lib/timex_datalink_client/protocol_1/sync.rb
|
105
|
+
- lib/timex_datalink_client/protocol_1/time.rb
|
106
|
+
- lib/timex_datalink_client/protocol_1/time_name.rb
|
107
|
+
- lib/timex_datalink_client/protocol_3/alarm.rb
|
108
|
+
- lib/timex_datalink_client/protocol_3/eeprom.rb
|
109
|
+
- lib/timex_datalink_client/protocol_3/end.rb
|
110
|
+
- lib/timex_datalink_client/protocol_3/sound_options.rb
|
111
|
+
- lib/timex_datalink_client/protocol_3/sound_theme.rb
|
112
|
+
- lib/timex_datalink_client/protocol_3/start.rb
|
113
|
+
- lib/timex_datalink_client/protocol_3/sync.rb
|
114
|
+
- lib/timex_datalink_client/protocol_3/time.rb
|
115
|
+
- lib/timex_datalink_client/protocol_3/wrist_app.rb
|
105
116
|
- lib/timex_datalink_client/sync.rb
|
106
|
-
- lib/timex_datalink_client/time.rb
|
107
117
|
- lib/timex_datalink_client/version.rb
|
108
|
-
|
109
|
-
homepage: https://github.com/synthead/timex_datalink_client
|
118
|
+
homepage: https://github.com/synthead/timex_datalink_client/tree/v0.5.0
|
110
119
|
licenses:
|
111
120
|
- MIT
|
112
121
|
metadata: {}
|
@@ -128,5 +137,5 @@ requirements: []
|
|
128
137
|
rubygems_version: 3.3.7
|
129
138
|
signing_key:
|
130
139
|
specification_version: 4
|
131
|
-
summary:
|
140
|
+
summary: Write data to Timex Datalink devices with an optical sensor
|
132
141
|
test_files: []
|
@@ -1,61 +0,0 @@
|
|
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 Alarm
|
8
|
-
include Helpers::CharEncoders
|
9
|
-
prepend Helpers::CrcPacketsWrapper
|
10
|
-
|
11
|
-
CPACKET_ALARM = [0x50]
|
12
|
-
|
13
|
-
MESSAGE_LENGTH = 8
|
14
|
-
|
15
|
-
attr_accessor :number, :audible, :time, :message
|
16
|
-
|
17
|
-
# Create an Alarm instance.
|
18
|
-
#
|
19
|
-
# @param number [Integer] Alarm number (from 1 to 5).
|
20
|
-
# @param audible [Boolean] Toggle alarm sounds.
|
21
|
-
# @param time [::Time] Time of alarm.
|
22
|
-
# @param message [String] Alarm message text.
|
23
|
-
# @return [Alarm] Alarm instance.
|
24
|
-
def initialize(number:, audible:, time:, message:)
|
25
|
-
@number = number
|
26
|
-
@audible = audible
|
27
|
-
@time = time
|
28
|
-
@message = message
|
29
|
-
end
|
30
|
-
|
31
|
-
# Compile packets for an alarm.
|
32
|
-
#
|
33
|
-
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
|
34
|
-
def packets
|
35
|
-
[
|
36
|
-
[
|
37
|
-
CPACKET_ALARM,
|
38
|
-
number,
|
39
|
-
time.hour,
|
40
|
-
time.min,
|
41
|
-
0,
|
42
|
-
0,
|
43
|
-
message_characters,
|
44
|
-
audible_integer
|
45
|
-
].flatten
|
46
|
-
]
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def message_characters
|
52
|
-
message_padded = message.ljust(MESSAGE_LENGTH)
|
53
|
-
|
54
|
-
chars_for(message_padded)
|
55
|
-
end
|
56
|
-
|
57
|
-
def audible_integer
|
58
|
-
audible ? 1 : 0
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,92 +0,0 @@
|
|
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 Eeprom
|
8
|
-
include Helpers::CpacketPaginator
|
9
|
-
prepend Helpers::CrcPacketsWrapper
|
10
|
-
|
11
|
-
CPACKET_CLEAR = [0x93, 0x01]
|
12
|
-
CPACKET_SECT = [0x90, 0x01]
|
13
|
-
CPACKET_DATA = [0x91, 0x01]
|
14
|
-
CPACKET_END = [0x92, 0x01]
|
15
|
-
|
16
|
-
START_ADDRESS = 0x0236
|
17
|
-
APPOINTMENT_NO_NOTIFICATION = 0xff
|
18
|
-
|
19
|
-
attr_accessor :appointments, :anniversaries, :phone_numbers, :lists, :appointment_notification
|
20
|
-
|
21
|
-
# Create an Eeprom instance.
|
22
|
-
#
|
23
|
-
# @param appointments [Array<Appointment>] Appointments to be added to EEPROM data.
|
24
|
-
# @param anniversaries [Array<Anniversary>] Anniversaries to be added to EEPROM data.
|
25
|
-
# @param phone_numbers [Array<PhoneNumber>] Phone numbers to be added to EEPROM data.
|
26
|
-
# @param lists [Array<List>] Lists to be added to EEPROM data.
|
27
|
-
# @param appointment_notification [Integer] Appointment notification (intervals of 15 minutes, 255 for no
|
28
|
-
# notification)
|
29
|
-
# @return [Eeprom] Eeprom instance.
|
30
|
-
def initialize(appointments: [], anniversaries: [], phone_numbers: [], lists: [], appointment_notification: APPOINTMENT_NO_NOTIFICATION)
|
31
|
-
@appointments = appointments
|
32
|
-
@anniversaries = anniversaries
|
33
|
-
@phone_numbers = phone_numbers
|
34
|
-
@lists = lists
|
35
|
-
@appointment_notification = appointment_notification
|
36
|
-
end
|
37
|
-
|
38
|
-
# Compile packets for EEPROM data.
|
39
|
-
#
|
40
|
-
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
|
41
|
-
def packets
|
42
|
-
[CPACKET_CLEAR, header] + payloads + [CPACKET_END]
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def header
|
48
|
-
[
|
49
|
-
CPACKET_SECT,
|
50
|
-
payloads.length,
|
51
|
-
items_addresses,
|
52
|
-
items_lengths,
|
53
|
-
earliest_appointment_year,
|
54
|
-
appointment_notification
|
55
|
-
].flatten
|
56
|
-
end
|
57
|
-
|
58
|
-
def payloads
|
59
|
-
paginate_cpackets(header: CPACKET_DATA, cpackets: all_packets)
|
60
|
-
end
|
61
|
-
|
62
|
-
def all_items
|
63
|
-
[appointments, lists, phone_numbers, anniversaries]
|
64
|
-
end
|
65
|
-
|
66
|
-
def all_packets
|
67
|
-
all_items.flatten.map(&:packet).flatten
|
68
|
-
end
|
69
|
-
|
70
|
-
def items_addresses
|
71
|
-
address = START_ADDRESS
|
72
|
-
|
73
|
-
all_items.each_with_object([]) do |items, addresses|
|
74
|
-
addresses.concat(address.divmod(256))
|
75
|
-
|
76
|
-
address += items.sum { |item| item.packet.length }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def items_lengths
|
81
|
-
all_items.map(&:length)
|
82
|
-
end
|
83
|
-
|
84
|
-
def earliest_appointment_year
|
85
|
-
earliest_appointment = appointments.min_by(&:time)
|
86
|
-
|
87
|
-
return 0 unless earliest_appointment
|
88
|
-
|
89
|
-
earliest_appointment.time.year % 100
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "timex_datalink_client/helpers/crc_packets_wrapper"
|
4
|
-
|
5
|
-
class TimexDatalinkClient
|
6
|
-
class SoundOptions
|
7
|
-
prepend Helpers::CrcPacketsWrapper
|
8
|
-
|
9
|
-
CPACKET_BEEPS = [0x71]
|
10
|
-
|
11
|
-
attr_accessor :hourly_chime, :button_beep
|
12
|
-
|
13
|
-
# Create a SoundOptions instance.
|
14
|
-
#
|
15
|
-
# @param hourly_chime [Boolean] Toggle hourly chime sounds.
|
16
|
-
# @param button_beep [Boolean] Toggle button beep sounds.
|
17
|
-
# @return [SoundOptions] SoundOptions instance.
|
18
|
-
def initialize(hourly_chime:, button_beep:)
|
19
|
-
@hourly_chime = hourly_chime
|
20
|
-
@button_beep = button_beep
|
21
|
-
end
|
22
|
-
|
23
|
-
# Compile packets for sound options.
|
24
|
-
#
|
25
|
-
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
|
26
|
-
def packets
|
27
|
-
[
|
28
|
-
CPACKET_BEEPS + [hourly_chime_integer, button_beep_integer]
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
def hourly_chime_integer
|
33
|
-
hourly_chime ? 1 : 0
|
34
|
-
end
|
35
|
-
|
36
|
-
def button_beep_integer
|
37
|
-
button_beep ? 1 : 0
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,62 +0,0 @@
|
|
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 SoundTheme
|
8
|
-
include Helpers::CpacketPaginator
|
9
|
-
prepend Helpers::CrcPacketsWrapper
|
10
|
-
|
11
|
-
CPACKET_SECT = [0x90, 0x03]
|
12
|
-
CPACKET_DATA = [0x91, 0x03]
|
13
|
-
CPACKET_END = [0x92, 0x03]
|
14
|
-
|
15
|
-
SOUND_DATA_HEADER = "\x25\x04\x19\x69"
|
16
|
-
|
17
|
-
attr_accessor :spc_file
|
18
|
-
|
19
|
-
# Create a SoundTheme instance.
|
20
|
-
#
|
21
|
-
# @param sound_theme_data [String, nil] Sound theme data.
|
22
|
-
# @param spc_file [String, nil] Path to SPC file.
|
23
|
-
# @return [SoundTheme] SoundTheme instance.
|
24
|
-
def initialize(sound_theme_data: nil, spc_file: nil)
|
25
|
-
@sound_theme_data = sound_theme_data
|
26
|
-
@spc_file = spc_file
|
27
|
-
end
|
28
|
-
|
29
|
-
# Compile packets for a sound theme.
|
30
|
-
#
|
31
|
-
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
|
32
|
-
def packets
|
33
|
-
[load_sect] + payloads + [CPACKET_END]
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def load_sect
|
39
|
-
CPACKET_SECT + [payloads.length, offset]
|
40
|
-
end
|
41
|
-
|
42
|
-
def payloads
|
43
|
-
paginate_cpackets(header: CPACKET_DATA, cpackets: sound_theme_data.bytes)
|
44
|
-
end
|
45
|
-
|
46
|
-
def sound_theme_data
|
47
|
-
@sound_theme_data || spc_file_data_without_header
|
48
|
-
end
|
49
|
-
|
50
|
-
def spc_file_data
|
51
|
-
File.open(spc_file, "rb").read
|
52
|
-
end
|
53
|
-
|
54
|
-
def spc_file_data_without_header
|
55
|
-
spc_file_data.delete_prefix(SOUND_DATA_HEADER)
|
56
|
-
end
|
57
|
-
|
58
|
-
def offset
|
59
|
-
0x100 - sound_theme_data.bytesize
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "timex_datalink_client/helpers/crc_packets_wrapper"
|
4
|
-
|
5
|
-
class TimexDatalinkClient
|
6
|
-
class Start
|
7
|
-
prepend Helpers::CrcPacketsWrapper
|
8
|
-
|
9
|
-
CPACKET_START = [0x20, 0x00, 0x00, 0x03]
|
10
|
-
|
11
|
-
# Compile packets for data start command.
|
12
|
-
#
|
13
|
-
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
|
14
|
-
def packets
|
15
|
-
[CPACKET_START]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,69 +0,0 @@
|
|
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 Time
|
8
|
-
include Helpers::CharEncoders
|
9
|
-
prepend Helpers::CrcPacketsWrapper
|
10
|
-
|
11
|
-
CPACKET_TIME = [0x32]
|
12
|
-
|
13
|
-
attr_accessor :zone, :is_24h, :date_format, :time
|
14
|
-
|
15
|
-
# Create a Time instance.
|
16
|
-
#
|
17
|
-
# @param zone [Integer] Time zone number (1 or 2).
|
18
|
-
# @param is_24h [Boolean] Toggle 24 hour time.
|
19
|
-
# @param date_format [Integer] Date format.
|
20
|
-
# @param time [::Time] Time to set (including time zone).
|
21
|
-
# @return [Time] Time instance.
|
22
|
-
def initialize(zone:, is_24h:, date_format:, time:)
|
23
|
-
@zone = zone
|
24
|
-
@is_24h = is_24h
|
25
|
-
@date_format = date_format
|
26
|
-
@time = time
|
27
|
-
end
|
28
|
-
|
29
|
-
# Compile packets for a time.
|
30
|
-
#
|
31
|
-
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
|
32
|
-
def packets
|
33
|
-
[
|
34
|
-
[
|
35
|
-
CPACKET_TIME,
|
36
|
-
zone,
|
37
|
-
time.sec,
|
38
|
-
time.hour,
|
39
|
-
time.min,
|
40
|
-
time.month,
|
41
|
-
time.day,
|
42
|
-
year_mod_1900,
|
43
|
-
timezone_characters,
|
44
|
-
wday_from_monday,
|
45
|
-
is_24h_value,
|
46
|
-
date_format
|
47
|
-
].flatten
|
48
|
-
]
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def timezone_characters
|
54
|
-
chars_for(time.zone.downcase)
|
55
|
-
end
|
56
|
-
|
57
|
-
def year_mod_1900
|
58
|
-
time.year % 100
|
59
|
-
end
|
60
|
-
|
61
|
-
def wday_from_monday
|
62
|
-
(time.wday + 6) % 7
|
63
|
-
end
|
64
|
-
|
65
|
-
def is_24h_value
|
66
|
-
is_24h ? 2 : 1
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,64 +0,0 @@
|
|
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 WristApp
|
8
|
-
include Helpers::CpacketPaginator
|
9
|
-
prepend Helpers::CrcPacketsWrapper
|
10
|
-
|
11
|
-
CPACKET_CLEAR = [0x93, 0x02]
|
12
|
-
CPACKET_SECT = [0x90, 0x02]
|
13
|
-
CPACKET_DATA = [0x91, 0x02]
|
14
|
-
CPACKET_END = [0x92, 0x02]
|
15
|
-
|
16
|
-
WRIST_APP_DELIMITER = /\xac.*\r\n/n
|
17
|
-
WRIST_APP_CODE_INDEX = 8
|
18
|
-
|
19
|
-
attr_accessor :zap_file
|
20
|
-
|
21
|
-
# Create a WristApp instance.
|
22
|
-
#
|
23
|
-
# @param wrist_app_data [String, nil] WristApp data.
|
24
|
-
# @param zap_file [String, nil] Path to ZAP file.
|
25
|
-
# @return [WristApp] WristApp instance.
|
26
|
-
def initialize(wrist_app_data: nil, zap_file: nil)
|
27
|
-
@wrist_app_data = wrist_app_data
|
28
|
-
@zap_file = zap_file
|
29
|
-
end
|
30
|
-
|
31
|
-
# Compile packets for an alarm.
|
32
|
-
#
|
33
|
-
# @return [Array<Array<Integer>>] Two-dimensional array of integers that represent bytes.
|
34
|
-
def packets
|
35
|
-
[CPACKET_CLEAR, cpacket_sect] + payloads + [CPACKET_END]
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def cpacket_sect
|
41
|
-
CPACKET_SECT + [payloads.length, 1]
|
42
|
-
end
|
43
|
-
|
44
|
-
def payloads
|
45
|
-
paginate_cpackets(header: CPACKET_DATA, cpackets: wrist_app_data.bytes)
|
46
|
-
end
|
47
|
-
|
48
|
-
def wrist_app_data
|
49
|
-
@wrist_app_data || zap_file_data_binary
|
50
|
-
end
|
51
|
-
|
52
|
-
def zap_file_data
|
53
|
-
File.open(zap_file, "rb").read
|
54
|
-
end
|
55
|
-
|
56
|
-
def zap_file_data_ascii
|
57
|
-
zap_file_data.split(WRIST_APP_DELIMITER)[WRIST_APP_CODE_INDEX]
|
58
|
-
end
|
59
|
-
|
60
|
-
def zap_file_data_binary
|
61
|
-
[zap_file_data_ascii].pack("H*")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|