blink_tm 1.0.0 → 2.0.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/exe/blink-tm +60 -11
- data/lib/blink_tm/blink_tm.rb +101 -106
- data/lib/blink_tm/version.rb +1 -1
- data/lib/blink_tm.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 941ae55ced42e5243dd9a489783f1b02da24fcd9c29a9cf4e3f310ea26080fbc
|
|
4
|
+
data.tar.gz: bf0c03acd5b71bddd03e0e717b8c1f12acd824668eb6e2e56948db9f055a9a67
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 00543e80f694b6a711f55aeacd7ab7175675273b513af336b3e3307c73a07ea21f9960a41a81bd285cd6023ff35fa2a2979552f0a7725d1580328808989ac2e6
|
|
7
|
+
data.tar.gz: 03f51e941ee7531fd2dd29500383abe4d0d88af40b25208d2b2d5991fccae3a3b67954e2efa7aa6eacbb5ca1690230037220cde6d66ef3c5281385fc4ef1d8bb
|
data/exe/blink-tm
CHANGED
|
@@ -1,19 +1,68 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
require 'blink_tm'
|
|
3
3
|
|
|
4
|
-
# Find Device running Blink Taskmanager
|
|
5
|
-
dev = nil
|
|
6
|
-
retry_count = 0
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
if ARGV.any?(/^\-(\-version|v)$/)
|
|
6
|
+
puts "BlinkTM Version #{BlinkTM::BOLD}#{BlinkTM::VERSION}#{BlinkTM::RESET}"
|
|
7
|
+
exit
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
written_pid = false
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
BlinkTM::log "BlinkTM Version #{BlinkTM::VERSION}"
|
|
13
|
+
if File.exist?(BlinkTM::LOCKFILE)
|
|
14
|
+
BlinkTM.log 'error', "Lock file #{BlinkTM::LOCKFILE} already exists! If it's not running you might manually delete this to make blinktm work."
|
|
15
|
+
|
|
16
|
+
pid = IO.read(BlinkTM::LOCKFILE) if File.readable?(BlinkTM::LOCKFILE)
|
|
17
|
+
process_name = File.readable?("/proc/#{pid}/cmdline") ? IO.read("/proc/#{pid}/cmdline") : 'unknown'
|
|
18
|
+
stat = File.readable?("/proc/#{pid}/stat") ? IO.read("/proc/#{pid}/stat") : nil
|
|
19
|
+
state = stat ? stat.gsub(/\(.+\)/, '').split[1] : 'unknown'
|
|
20
|
+
friendly_state = case state
|
|
21
|
+
when ?S then 'Sleeping'
|
|
22
|
+
when ?I then 'Idle'
|
|
23
|
+
when ?Z then 'Zombie'
|
|
24
|
+
when ?R then 'Running'
|
|
25
|
+
when ?T then 'Stopped'
|
|
26
|
+
else 'Unknown'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
BlinkTM.log 'info', <<~EOF
|
|
30
|
+
Process Details:
|
|
31
|
+
\t- ID: #{pid}
|
|
32
|
+
\t- Command: #{File.basename(process_name.gsub(?\u0000, ?\s))}
|
|
33
|
+
\t- Status: #{friendly_state}
|
|
34
|
+
EOF
|
|
35
|
+
|
|
36
|
+
exit!
|
|
37
|
+
else
|
|
38
|
+
begin
|
|
39
|
+
IO.write(BlinkTM::LOCKFILE, $$)
|
|
40
|
+
written_pid = true
|
|
41
|
+
rescue Exception
|
|
42
|
+
puts "Can't write to #{BlinkTM::LOCKFILE}"
|
|
43
|
+
exit!
|
|
16
44
|
end
|
|
17
45
|
end
|
|
18
46
|
|
|
19
|
-
|
|
47
|
+
retry_count = 0
|
|
48
|
+
|
|
49
|
+
# Find Device running Blink Taskmanager
|
|
50
|
+
dev = BlinkTM::find_device!
|
|
51
|
+
file = nil
|
|
52
|
+
|
|
53
|
+
begin
|
|
54
|
+
BlinkTM.start(dev) { |x| file = x }
|
|
55
|
+
rescue BlinkTM::SyncError
|
|
56
|
+
sleep 1
|
|
57
|
+
retry
|
|
58
|
+
rescue Errno::ENOENT, Errno::EIO, BlinkTM::NoDeviceError
|
|
59
|
+
file &.close
|
|
60
|
+
sleep 0.125
|
|
61
|
+
dev = BlinkTM::find_device!
|
|
62
|
+
retry
|
|
63
|
+
rescue Interrupt, SystemExit, SignalException
|
|
64
|
+
file &.close
|
|
65
|
+
File.delete(BlinkTM::LOCKFILE)
|
|
66
|
+
rescue Exception
|
|
67
|
+
File.delete(BlinkTM::LOCKFILE)
|
|
68
|
+
end
|
data/lib/blink_tm/blink_tm.rb
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
module BlinkTM
|
|
5
5
|
# Detect device
|
|
6
6
|
def find_device
|
|
7
|
-
dev = nil
|
|
8
|
-
|
|
9
7
|
Dir.glob('/sys/bus/usb/devices/*').each { |x|
|
|
10
8
|
v = File.join(x, 'idVendor')
|
|
11
9
|
vendor = IO.read(v).strip if File.readable?(v)
|
|
@@ -14,39 +12,45 @@ module BlinkTM
|
|
|
14
12
|
product = IO.read(p).strip if File.readable?(p)
|
|
15
13
|
|
|
16
14
|
if vendor == '1a86' && product == '7523'
|
|
17
|
-
|
|
15
|
+
log 'warn', "A potential device discovered: #{vendor}:#{product}"
|
|
18
16
|
|
|
19
17
|
Dir.glob('/dev/ttyUSB[0-9]*').each { |x|
|
|
20
18
|
if File.writable?(x)
|
|
21
|
-
|
|
19
|
+
log 'success', "Changing baudrate to 57600..."
|
|
22
20
|
|
|
23
21
|
if BlinkTM.set_baudrate(x, BlinkTM::BAUDRATE)
|
|
24
|
-
|
|
22
|
+
log 'success', 'Successfully Changed baudrate to 57600...'
|
|
25
23
|
else
|
|
26
|
-
|
|
24
|
+
log 'error', 'Cannot change the baudrate'
|
|
27
25
|
end
|
|
28
26
|
else
|
|
29
|
-
|
|
27
|
+
log 'error', 'No permission granted to change Baudrate'
|
|
30
28
|
end
|
|
31
29
|
|
|
32
30
|
if File.readable?(x)
|
|
33
31
|
begin
|
|
34
|
-
if File.open(x).
|
|
35
|
-
puts "#{BOLD}#{ORANGE}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Multiple Blink Task "\
|
|
36
|
-
"Manager Hardware Found! "\
|
|
37
|
-
"Selecting: #{vendor}:#{product}#{RESET}" if dev
|
|
38
|
-
|
|
39
|
-
dev = x
|
|
40
|
-
end
|
|
32
|
+
return x if File.open(x).read_nonblock(30).to_s.scrub.include?("BTM")
|
|
41
33
|
rescue EOFError
|
|
42
|
-
sleep 0.
|
|
34
|
+
sleep 0.05
|
|
43
35
|
retry
|
|
36
|
+
rescue Errno::ENOENT, Errno::EIO
|
|
44
37
|
end
|
|
45
38
|
end
|
|
46
39
|
}
|
|
47
40
|
end
|
|
48
41
|
}
|
|
49
42
|
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
@@retry_count = 0
|
|
47
|
+
def find_device!
|
|
48
|
+
while(!(dev = BlinkTM.find_device))
|
|
49
|
+
log 'error', "No device found. Retrying #{@@retry_count += 1}"
|
|
50
|
+
sleep 0.5
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
log 'success', "Device discovered successfully. Path: #{dev}#{BlinkTM::RESET}"
|
|
50
54
|
dev
|
|
51
55
|
end
|
|
52
56
|
|
|
@@ -103,114 +107,105 @@ module BlinkTM
|
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
prev_crc32 = ''
|
|
110
|
+
raise NoDeviceError unless device
|
|
106
111
|
|
|
107
|
-
|
|
108
|
-
raise NoDeviceError unless device
|
|
109
|
-
|
|
110
|
-
in_sync = false
|
|
112
|
+
in_sync = false
|
|
111
113
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
fd = IO.sysopen(
|
|
115
|
+
device,
|
|
116
|
+
Fcntl::O_RDWR | Fcntl::O_NOCTTY | Fcntl::O_NONBLOCK | Fcntl::O_TRUNC
|
|
117
|
+
)
|
|
116
118
|
|
|
117
|
-
|
|
119
|
+
file = IO.open(fd)
|
|
120
|
+
yield file
|
|
118
121
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
until in_sync
|
|
123
|
+
# Clear out any extra zombie bits
|
|
124
|
+
file.syswrite(?~.freeze)
|
|
125
|
+
# Start the device
|
|
126
|
+
file.syswrite(?#.freeze)
|
|
127
|
+
file.flush
|
|
125
128
|
|
|
126
|
-
|
|
129
|
+
sleep 0.125
|
|
127
130
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
end
|
|
133
|
-
rescue EOFError
|
|
134
|
-
sleep 0.05
|
|
135
|
-
retry
|
|
131
|
+
begin
|
|
132
|
+
if file.read_nonblock(8000).include?(?~)
|
|
133
|
+
in_sync = true
|
|
134
|
+
break
|
|
136
135
|
end
|
|
136
|
+
rescue EOFError
|
|
137
|
+
sleep 0.05
|
|
138
|
+
retry
|
|
137
139
|
end
|
|
140
|
+
end
|
|
138
141
|
|
|
139
|
-
|
|
142
|
+
sync_error_count = 0
|
|
140
143
|
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
log 'success', 'Device ready!'
|
|
145
|
+
file.read
|
|
143
146
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
memstat = LS::Memory.stat
|
|
150
|
-
mem_u = memstat[:used].to_i.*(1024).*(100).fdiv(memstat[:total].to_i * 1024).round
|
|
151
|
-
|
|
152
|
-
swapstat = LS::Swap.stat
|
|
153
|
-
swap_u = swapstat[:used].to_i.*(1024).*(100).fdiv(swapstat[:total].to_i * 1024).round
|
|
154
|
-
|
|
155
|
-
# Output has to be exactly this long. If not, blink-taskmanager shows invalid result.
|
|
156
|
-
# No string is split inside blink-task manager, it just depends on the string length.
|
|
157
|
-
#
|
|
158
|
-
# cpu(100) memUsed(100) swapUsed(100)
|
|
159
|
-
# netDownload(9991) netUpload(9991)
|
|
160
|
-
# ioWrite(9991) ioRead(9991)
|
|
161
|
-
|
|
162
|
-
# Debugging string
|
|
163
|
-
# str = "#{"%03d" % cpu_u} #{"%03d" % mem_u} #{"%03d" % swap_u} "\
|
|
164
|
-
# "#{convert_bytes(net_u)} #{convert_bytes(net_d)} "\
|
|
165
|
-
# "#{convert_bytes(io_r)} #{convert_bytes(io_w)}"
|
|
166
|
-
|
|
167
|
-
str = "!##{"%03d" % cpu_u}#{"%03d" % mem_u}#{"%03d" % swap_u}"\
|
|
168
|
-
"#{convert_bytes(net_u)}#{convert_bytes(net_d)}"\
|
|
169
|
-
"#{convert_bytes(io_r)}#{convert_bytes(io_w)}1~"
|
|
170
|
-
|
|
171
|
-
# Rescuing from suspend
|
|
172
|
-
file.syswrite(str)
|
|
173
|
-
file.flush
|
|
174
|
-
crc32 = file.read.scrub![/\d+/]
|
|
175
|
-
|
|
176
|
-
unless crc32 == prev_crc32 || prev_crc32.empty?
|
|
177
|
-
raise SyncError if sync_error_count > 1
|
|
178
|
-
sync_error_count += 1
|
|
179
|
-
else
|
|
180
|
-
sync_error_count = 0 unless sync_error_count == 0
|
|
181
|
-
end
|
|
147
|
+
while true
|
|
148
|
+
# cpu(01234) memUsed(999993) swapUsed(999992) io_active(0)
|
|
149
|
+
# netUpload(999991) netDownload(999990)
|
|
150
|
+
# disktotal(999990) diskused(999990)
|
|
182
151
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
152
|
+
memstat = LS::Memory.stat
|
|
153
|
+
mem_u = memstat[:used].to_i.*(1024).*(100).fdiv(memstat[:total].to_i * 1024).round
|
|
154
|
+
|
|
155
|
+
swapstat = LS::Swap.stat
|
|
156
|
+
swap_u = swapstat[:used].to_i.*(1024).*(100).fdiv(swapstat[:total].to_i * 1024).round
|
|
157
|
+
|
|
158
|
+
# Output has to be exactly this long. If not, blink-taskmanager shows invalid result.
|
|
159
|
+
# No string is split inside blink-task manager, it just depends on the string length.
|
|
160
|
+
#
|
|
161
|
+
# cpu(100) memUsed(100) swapUsed(100)
|
|
162
|
+
# netDownload(9991) netUpload(9991)
|
|
163
|
+
# ioWrite(9991) ioRead(9991)
|
|
164
|
+
|
|
165
|
+
# Debugging string
|
|
166
|
+
str = "#{"%03d" % cpu_u} #{"%03d" % mem_u} #{"%03d" % swap_u} "\
|
|
167
|
+
"#{convert_bytes(net_u)} #{convert_bytes(net_d)} "\
|
|
168
|
+
"#{convert_bytes(io_r)} #{convert_bytes(io_w)}"
|
|
169
|
+
|
|
170
|
+
str = "!##{"%03d" % cpu_u}#{"%03d" % mem_u}#{"%03d" % swap_u}"\
|
|
171
|
+
"#{convert_bytes(net_u)}#{convert_bytes(net_d)}"\
|
|
172
|
+
"#{convert_bytes(io_r)}#{convert_bytes(io_w)}1~"
|
|
173
|
+
|
|
174
|
+
# Rescuing from suspend
|
|
175
|
+
file.syswrite(str)
|
|
176
|
+
file.flush
|
|
177
|
+
crc32 = file.read.scrub![/\d+/]
|
|
178
|
+
|
|
179
|
+
unless crc32 == prev_crc32 || prev_crc32.empty?
|
|
180
|
+
raise SyncError if sync_error_count > 1
|
|
181
|
+
sync_error_count += 1
|
|
182
|
+
else
|
|
183
|
+
sync_error_count = 0 unless sync_error_count == 0
|
|
196
184
|
end
|
|
197
185
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
file &.close
|
|
205
|
-
sleep 0.1
|
|
206
|
-
retry
|
|
207
|
-
rescue Exception
|
|
208
|
-
puts $!.full_message
|
|
209
|
-
file &.close
|
|
186
|
+
prev_crc32 = BlinkTM.crc32(str[2..-2])
|
|
187
|
+
sleep REFRESH
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
unless device
|
|
191
|
+
puts "#{BlinkTM::BOLD}#{BlinkTM::RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Error establishing connection. Don't worry if this is a valid device. Retrying...#{BlinkTM::RESET}"
|
|
210
192
|
sleep 0.1
|
|
211
|
-
retry
|
|
212
193
|
end
|
|
213
194
|
end
|
|
214
195
|
|
|
196
|
+
def log(type, message = nil)
|
|
197
|
+
message, type = type, nil if type && !message
|
|
198
|
+
|
|
199
|
+
colour = case type
|
|
200
|
+
when 0, 'fatal', 'error' then BlinkTM::RED
|
|
201
|
+
when 1, 'warn' then BlinkTM::ORANGE
|
|
202
|
+
when 2, 'info' then BlinkTM::BLUE
|
|
203
|
+
when 3, 'success', 'ok' then BlinkTM::GREEN
|
|
204
|
+
else ''
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
puts "#{BlinkTM::BOLD}#{colour}:: #{Time.now.strftime('%H:%M:%S.%2N')}: #{message}#{BlinkTM::RESET}"
|
|
208
|
+
end
|
|
209
|
+
|
|
215
210
|
extend(self)
|
|
216
211
|
end
|
data/lib/blink_tm/version.rb
CHANGED
data/lib/blink_tm.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: blink_tm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sourav Goswami
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-12-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: linux_stat
|
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
62
|
version: '0'
|
|
63
63
|
requirements: []
|
|
64
|
-
rubygems_version: 3.2.
|
|
64
|
+
rubygems_version: 3.2.29
|
|
65
65
|
signing_key:
|
|
66
66
|
specification_version: 4
|
|
67
67
|
summary: A controller for Arduino OLED System Monitor, Blink Task Manager
|