blink_tm 0.1.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4e90e73c0c9d495bf37a16e6020498d5880ef79dd2ad36aaa054fd344580e5c
4
- data.tar.gz: 02a83b060adb7e15c3e06cc6fe266aa699740b494d0a4f87296aa329741aa12a
3
+ metadata.gz: aee9807ee73b58a75f7c4c0d09fcda705f6d8087d51e3c5178ab0472ebd2faae
4
+ data.tar.gz: d9156630e58cc9d4a41b26b7f0666f2abe565de91e8d1636bb8733920a9dfac0
5
5
  SHA512:
6
- metadata.gz: 40d53fe4c787ad0995525d6531688ef5d83f9049107fca15936826ebde78515cf29c15bd567ad9c19a8bebc6acca9ce38419a874349063e76c93349739c62ea4
7
- data.tar.gz: f6483431ae948c6eda5a59ca449e086b7a3fb4c8fee9766039bbb1d8c200ddd62994cb00387a78229e32726dbe90881ea57912e01bd31af8534b575541aba4dc
6
+ metadata.gz: 204d49f580218bce9aed96a58a27a1f6fae07996e8d9a911749fec17a621b8c4cfcf2f081e71447e0d61788b22032713239c287d0b1194d6c4e6b048fdcd24a1
7
+ data.tar.gz: 4c269cca6fb02329354483e4495a88da1270c6426a2756315eb8bc88ef0577466165d0f2239181a140bcf04042c04c4ae4b53c0ec53044034bd930954f98f606
data/exe/blink-tm CHANGED
@@ -9,9 +9,9 @@ while(!dev)
9
9
  dev = BlinkTM.find_device
10
10
 
11
11
  if dev
12
- puts "#{BlinkTM::BOLD}#{BlinkTM::GREEN}:: Device discovered successfully. Path: #{dev}#{BlinkTM::RESET}"
12
+ puts "#{BlinkTM::BOLD}#{BlinkTM::GREEN}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Device discovered successfully. Path: #{dev}#{BlinkTM::RESET}"
13
13
  else
14
- puts "#{BlinkTM::BOLD}#{BlinkTM::RED}:: No device found. Retrying #{retry_count += 1}#{BlinkTM::RESET}"
14
+ puts "#{BlinkTM::BOLD}#{BlinkTM::RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: No device found. Retrying #{retry_count += 1}#{BlinkTM::RESET}"
15
15
  sleep 0.5
16
16
  end
17
17
  end
data/lib/blink_tm.rb CHANGED
@@ -1,14 +1,20 @@
1
1
  # Frozen_String_Literal: true
2
2
  require 'blink_tm/baudrate'
3
+ require 'linux_stat'
4
+
5
+ $-v = true
3
6
 
4
7
  module BlinkTM
5
8
  # Important Constants
6
9
  BAUDRATE = BlinkTM::B57600
7
10
  SCANID = 'BTM'
11
+
12
+ # POLLING time, how often should CPU, Net, IO usages should be updated.
13
+ # Should always be a float.
8
14
  POLLING = 0.375
9
15
 
10
- # Refresh should always get subtracted with 0.05
11
- REFRESH = 0.5 - 0.05
16
+ # Refresh time, how often the main loop should run
17
+ REFRESH = 0.5
12
18
 
13
19
  # Errors
14
20
  NoDeviceError = Class.new(StandardError)
@@ -27,7 +33,17 @@ module BlinkTM
27
33
  ORANGE = "\e[38;2;245;155;20m"
28
34
  BOLD = "\e[1m"
29
35
  RESET = "\e[0m"
36
+
37
+ # Other constants
38
+ ROOT_DEV = ::LinuxStat::Mounts.root
39
+ ROOT = File.split(ROOT_DEV)[-1]
40
+
41
+ SECTORS = ::LS::Filesystem.sectors(ROOT_DEV)
42
+
43
+ abort "#{BOLD}#{RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Can't get root partition#{RESET}" unless ROOT
44
+ abort "#{BOLD}#{RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Can't get sector size#{RESET}" unless SECTORS
30
45
  end
31
46
 
32
47
  require 'blink_tm/version'
48
+ require 'fcntl'
33
49
  require 'blink_tm/blink_tm'
@@ -1,10 +1,6 @@
1
-
2
- #!/usr/bin/ruby -w
1
+ #!/usr/bin/env ruby
3
2
  # Frozen_String_Literal: true
4
3
 
5
- require 'fcntl'
6
- require 'linux_stat'
7
-
8
4
  module BlinkTM
9
5
  # Detect device
10
6
  def find_device
@@ -81,7 +77,10 @@ module BlinkTM
81
77
  io_r = io_w = 0
82
78
 
83
79
  Thread.new {
84
- cpu_u = LS::CPU.total_usage(POLLING).to_f while true
80
+ while true
81
+ _cpu_u = LS::CPU.total_usage(POLLING).to_f
82
+ cpu_u = _cpu_u.nan? ? 0 : _cpu_u.to_i
83
+ end
85
84
  }
86
85
 
87
86
  Thread.new {
@@ -94,12 +93,12 @@ module BlinkTM
94
93
 
95
94
  Thread.new {
96
95
  while true
97
- io_stat1 = iostat()
96
+ io_stat1 = LS::FS.total_io(ROOT)
98
97
  sleep POLLING
99
- io_stat2 = iostat()
98
+ io_stat2 = LS::FS.total_io(ROOT)
100
99
 
101
- io_r = POLLING * io_stat2[0].-(io_stat1[0])
102
- io_w = POLLING * io_stat2[1].-(io_stat1[1])
100
+ io_r = io_stat2[0].-(io_stat1[0]).*(SECTORS).fdiv(POLLING)
101
+ io_w = io_stat2[1].-(io_stat1[1]).*(SECTORS).fdiv(POLLING)
103
102
  end
104
103
  }
105
104
 
@@ -107,7 +106,7 @@ module BlinkTM
107
106
  raise NoDeviceError unless device
108
107
 
109
108
  in_sync = false
110
- fd = IO.sysopen(device, Fcntl::O_RDWR | Fcntl::O_EXCL)
109
+ fd = IO.sysopen(device, Fcntl::O_RDWR)
111
110
  file = IO.open(fd)
112
111
 
113
112
  until in_sync
@@ -128,8 +127,6 @@ module BlinkTM
128
127
  sleep 0.05
129
128
  retry
130
129
  end
131
-
132
- sleep 0.05
133
130
  end
134
131
 
135
132
  puts "#{BlinkTM::BOLD}#{BlinkTM::GREEN}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Device ready!#{BlinkTM::RESET}"
@@ -157,23 +154,13 @@ module BlinkTM
157
154
  # "#{convert_bytes(net_u)} #{convert_bytes(net_d)} "\
158
155
  # "#{convert_bytes(io_r)} #{convert_bytes(io_w)}"
159
156
 
160
- str = "#{"%03d" % cpu_u}#{"%03d" % mem_u}#{"%03d" % swap_u}"\
157
+ str = "!##{"%03d" % cpu_u}#{"%03d" % mem_u}#{"%03d" % swap_u}"\
161
158
  "#{convert_bytes(net_u)}#{convert_bytes(net_d)}"\
162
- "#{convert_bytes(io_r)}#{convert_bytes(io_w)}"
159
+ "#{convert_bytes(io_r)}#{convert_bytes(io_w)}1~"
163
160
 
164
161
  # Rescuing from suspend
165
- file.syswrite('#')
166
-
167
- file.syswrite('!')
168
- file.flush
169
- sleep 0.025
170
-
171
162
  file.syswrite(str)
172
163
  file.flush
173
- sleep 0.025
174
-
175
- file.syswrite('~')
176
- file.flush
177
164
 
178
165
  sleep REFRESH
179
166
  end
@@ -202,22 +189,5 @@ module BlinkTM
202
189
  end
203
190
  end
204
191
 
205
- def iostat
206
- @@root_partition ||= IO.foreach('/proc/mounts').detect {
207
- |x| x.split[1] == ?/
208
- }.to_s.split[0].to_s.split(?/).to_a[-1]
209
-
210
- @@sector_size = LS::FS.stat(?/)[:block_size]
211
-
212
- io_stat = IO.foreach('/proc/diskstats'.freeze).find { |x|
213
- x.split[2] == @@root_partition
214
- } &.split.to_a
215
-
216
- _io_r = io_stat[5].to_f.*(@@sector_size).round
217
- _io_w = io_stat[9].to_f.*(@@sector_size).round
218
-
219
- [_io_r, _io_w]
220
- end
221
-
222
192
  extend(self)
223
193
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlinkTM
4
- VERSION = "0.1.1"
4
+ VERSION = "0.4.0"
5
5
  end
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: 0.1.1
4
+ version: 0.4.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-04-25 00:00:00.000000000 Z
11
+ date: 2021-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: linux_stat
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.2
19
+ version: 2.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.2
26
+ version: 2.3.0
27
27
  description: A controller for Arduino OLED System Monitor, Blink Task Manager
28
28
  email:
29
29
  - souravgoswami@protonmail.com
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.2.15
61
+ rubygems_version: 3.2.18
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: A controller for Arduino OLED System Monitor, Blink Task Manager