blink_tm 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db910772825de89e18bf29aa17905561b275accef99af4ce513f7bdee177b531
4
- data.tar.gz: d67946a495717d5fb69c0c8a82b0c3af779a59a1afd1384d2a9e2bc172fd2a34
3
+ metadata.gz: 941ae55ced42e5243dd9a489783f1b02da24fcd9c29a9cf4e3f310ea26080fbc
4
+ data.tar.gz: bf0c03acd5b71bddd03e0e717b8c1f12acd824668eb6e2e56948db9f055a9a67
5
5
  SHA512:
6
- metadata.gz: 13d05ea503502ffacdaec63e656dc23bfb11d4f4190a1be9925989d2278d6444547bd659297d8b1f281b421fd8f67ac8ec7ad2a3e80f10ddd5a551838643adbf
7
- data.tar.gz: 4966f3fe0180f4b7b366dadf621a29a8d3712ee2e8a5b60e6219be5df5b2902b857d8562920f674d136fb60ecadaeeec992ebe1fffc4d24e715c5e399d733973
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
- while(!dev)
9
- dev = BlinkTM.find_device
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
- if dev
12
- puts "#{BlinkTM::BOLD}#{BlinkTM::GREEN}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Device discovered successfully. Path: #{dev}#{BlinkTM::RESET}"
13
- else
14
- puts "#{BlinkTM::BOLD}#{BlinkTM::RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: No device found. Retrying #{retry_count += 1}#{BlinkTM::RESET}"
15
- sleep 0.5
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
- BlinkTM.start(dev)
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
@@ -7,7 +7,7 @@ VALUE setBaudRate(volatile VALUE obj, volatile VALUE dev, volatile VALUE speed)
7
7
  char *device = StringValuePtr(dev) ;
8
8
  unsigned int spd = NUM2UINT(speed) ;
9
9
 
10
- int serial_port = open(device, O_RDWR) ;
10
+ int serial_port = open(device, O_RDWR | O_NOCTTY) ;
11
11
  struct termios tty ;
12
12
 
13
13
  char status = tcgetattr(serial_port, &tty) ;
@@ -22,7 +22,10 @@ VALUE setBaudRate(volatile VALUE obj, volatile VALUE dev, volatile VALUE speed)
22
22
  -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
23
23
  */
24
24
 
25
- if(status != 0) return Qnil ;
25
+ if(status != 0) {
26
+ close(serial_port) ;
27
+ return Qnil ;
28
+ }
26
29
 
27
30
  tty.c_cflag &= ~CSIZE ;
28
31
  tty.c_cflag |= CS8 ;
@@ -46,18 +49,20 @@ VALUE setBaudRate(volatile VALUE obj, volatile VALUE dev, volatile VALUE speed)
46
49
  cfsetospeed(&tty, spd) ;
47
50
  status = tcsetattr(serial_port, TCSANOW, &tty) ;
48
51
 
49
- if (status == 0) return Qtrue ;
52
+ close(serial_port) ;
50
53
 
54
+ if (status == 0) return Qtrue ;
51
55
  return Qfalse ;
52
56
  }
53
57
 
54
58
  VALUE getBaudRate(volatile VALUE obj, volatile VALUE dev) {
55
59
  char *device = StringValuePtr(dev) ;
56
60
 
57
- int serial_port = open(device, O_RDWR) ;
61
+ int serial_port = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK) ;
58
62
  struct termios tty ;
59
63
 
60
64
  char status = tcgetattr(serial_port, &tty) ;
65
+ close(serial_port) ;
61
66
 
62
67
  if(status == 0) {
63
68
  unsigned int in = cfgetispeed(&tty) ;
data/ext/crc32/crc32.c ADDED
@@ -0,0 +1,33 @@
1
+ /*
2
+ Source:
3
+ https://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art008
4
+
5
+ Note that this obeys the standard and matches with Ruby's Zlib.crc32(...)
6
+ */
7
+
8
+ #define CRC32_DIVISOR 0xEDB88320
9
+ #include "ruby.h"
10
+
11
+ static VALUE getCRC(volatile VALUE obj, volatile VALUE str) {
12
+ char *input = StringValuePtr(str) ;
13
+ unsigned char len = strlen(input) ;
14
+ unsigned long crc = 0xFFFFFFFF ;
15
+
16
+ for (unsigned char i = 0 ; i < len ; ++i) {
17
+ crc ^= input[i] ;
18
+
19
+ for (unsigned char k = 8 ; k ; --k) {
20
+ crc = crc & 1 ? (crc >> 1) ^ CRC32_DIVISOR : crc >> 1 ;
21
+ }
22
+ }
23
+
24
+ char buffer[11] ;
25
+ sprintf(buffer, "%lu", crc ^ 0xFFFFFFFF) ;
26
+
27
+ return rb_str_new_cstr(buffer) ;
28
+ }
29
+
30
+ void Init_crc32() {
31
+ VALUE blinktm = rb_define_module("BlinkTM") ;
32
+ rb_define_module_function(blinktm, "crc32", getCRC, 1) ;
33
+ }
@@ -0,0 +1,2 @@
1
+ require 'mkmf'
2
+ create_makefile 'blink_tm/crc32'
@@ -1,11 +1,9 @@
1
- #!/usr/bin/ruby -w
1
+ #!/usr/bin/env ruby
2
2
  # Frozen_String_Literal: true
3
3
 
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
- puts "#{BOLD}#{GREEN}:: #{Time.now.strftime('%H:%M:%S.%2N')}: A potential device discovered: #{vendor}:#{product}#{RESET}"
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
- puts "#{BlinkTM::BOLD}#{BlinkTM::BLUE}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Changing baudrate to 57600...#{BlinkTM::RESET}"
19
+ log 'success', "Changing baudrate to 57600..."
22
20
 
23
21
  if BlinkTM.set_baudrate(x, BlinkTM::BAUDRATE)
24
- puts "#{BlinkTM::BOLD}#{BlinkTM::GREEN}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Successfully Changed baudrate to 57600...#{BlinkTM::RESET}"
22
+ log 'success', 'Successfully Changed baudrate to 57600...'
25
23
  else
26
- puts "#{BlinkTM::BOLD}#{BlinkTM::RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Cannot change the baudrate#{BlinkTM::RESET}"
24
+ log 'error', 'Cannot change the baudrate'
27
25
  end
28
26
  else
29
- "#{BOLD}#{RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: No permission granted to change Baudrate#{RESET}"
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).readpartial(30).to_s.scrub.include?("BTM")
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.125
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
 
@@ -77,7 +81,10 @@ module BlinkTM
77
81
  io_r = io_w = 0
78
82
 
79
83
  Thread.new {
80
- cpu_u = LS::CPU.total_usage(POLLING).to_f while true
84
+ while true
85
+ _cpu_u = LS::CPU.total_usage(POLLING).to_f
86
+ cpu_u = _cpu_u.nan? ? 0 : _cpu_u.to_i
87
+ end
81
88
  }
82
89
 
83
90
  Thread.new {
@@ -90,106 +97,115 @@ module BlinkTM
90
97
 
91
98
  Thread.new {
92
99
  while true
93
- io_stat1 = BlinkTM.diskstats(ROOT)
100
+ io_stat1 = LS::FS.total_io(ROOT)
94
101
  sleep POLLING
95
- io_stat2 = BlinkTM.diskstats(ROOT)
102
+ io_stat2 = LS::FS.total_io(ROOT)
96
103
 
97
104
  io_r = io_stat2[0].-(io_stat1[0]).*(SECTORS).fdiv(POLLING)
98
105
  io_w = io_stat2[1].-(io_stat1[1]).*(SECTORS).fdiv(POLLING)
99
106
  end
100
107
  }
101
108
 
102
- begin
103
- raise NoDeviceError unless device
109
+ prev_crc32 = ''
110
+ raise NoDeviceError unless device
104
111
 
105
- in_sync = false
106
- fd = IO.sysopen(device, Fcntl::O_RDWR)
107
- file = IO.open(fd)
112
+ in_sync = false
108
113
 
109
- until in_sync
110
- # Clear out any extra zombie bits
111
- file.syswrite(?~)
112
- # Start the device
113
- file.syswrite(?#)
114
- file.flush
114
+ fd = IO.sysopen(
115
+ device,
116
+ Fcntl::O_RDWR | Fcntl::O_NOCTTY | Fcntl::O_NONBLOCK | Fcntl::O_TRUNC
117
+ )
115
118
 
116
- sleep 0.125
119
+ file = IO.open(fd)
120
+ yield file
117
121
 
118
- begin
119
- if file.readpartial(8000).include?(?~)
120
- in_sync = true
121
- break
122
- end
123
- rescue EOFError
124
- sleep 0.05
125
- retry
126
- end
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
128
+
129
+ sleep 0.125
127
130
 
131
+ begin
132
+ if file.read_nonblock(8000).include?(?~)
133
+ in_sync = true
134
+ break
135
+ end
136
+ rescue EOFError
128
137
  sleep 0.05
138
+ retry
129
139
  end
140
+ end
130
141
 
131
- puts "#{BlinkTM::BOLD}#{BlinkTM::GREEN}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Device ready!#{BlinkTM::RESET}"
132
- refresh = 0
142
+ sync_error_count = 0
133
143
 
134
- while true
135
- # cpu(01234) memUsed(999993) swapUsed(999992) io_active(0)
136
- # netUpload(999991) netDownload(999990)
137
- # disktotal(999990) diskused(999990)
144
+ log 'success', 'Device ready!'
145
+ file.read
138
146
 
139
- memstat = LS::Memory.stat
140
- mem_u = memstat[:used].to_i.*(1024).*(100).fdiv(memstat[:total].to_i * 1024).round
147
+ while true
148
+ # cpu(01234) memUsed(999993) swapUsed(999992) io_active(0)
149
+ # netUpload(999991) netDownload(999990)
150
+ # disktotal(999990) diskused(999990)
141
151
 
142
- swapstat = LS::Swap.stat
143
- swap_u = swapstat[:used].to_i.*(1024).*(100).fdiv(swapstat[:total].to_i * 1024).round
152
+ memstat = LS::Memory.stat
153
+ mem_u = memstat[:used].to_i.*(1024).*(100).fdiv(memstat[:total].to_i * 1024).round
144
154
 
145
- # Output has to be exactly this long. If not, blink-taskmanager shows invalid result.
146
- # No string is split inside blink-task manager, it just depends on the string length.
147
- #
148
- # cpu(100) memUsed(100) swapUsed(100)
149
- # netDownload(9991) netUpload(9991)
150
- # ioWrite(9991) ioRead(9991)
155
+ swapstat = LS::Swap.stat
156
+ swap_u = swapstat[:used].to_i.*(1024).*(100).fdiv(swapstat[:total].to_i * 1024).round
151
157
 
152
- # Debugging string
153
- # str = "#{"%03d" % cpu_u} #{"%03d" % mem_u} #{"%03d" % swap_u} "\
154
- # "#{convert_bytes(net_u)} #{convert_bytes(net_d)} "\
155
- # "#{convert_bytes(io_r)} #{convert_bytes(io_w)}"
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)
156
164
 
157
- refresh ^= 1
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)}"
158
169
 
159
- str = "!##{cpu_u.nan? ? '000' : "%03d" % cpu_u}#{"%03d" % mem_u}#{"%03d" % swap_u}"\
160
- "#{convert_bytes(net_u)}#{convert_bytes(net_d)}"\
161
- "#{convert_bytes(io_r)}#{convert_bytes(io_w)}#{refresh}~"
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~"
162
173
 
163
- # Rescuing from suspend
164
- file.syswrite(str)
165
- file.flush
174
+ # Rescuing from suspend
175
+ file.syswrite(str)
176
+ file.flush
177
+ crc32 = file.read.scrub![/\d+/]
166
178
 
167
- sleep REFRESH
168
- end
169
- rescue Interrupt, SystemExit, SignalException
170
- file &.close
171
- exit 0
172
- rescue Errno::ENOENT, BlinkTM::NoDeviceError
173
- file &.close
174
- device = find_device
175
-
176
- unless device
177
- 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}"
178
- sleep 0.1
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
179
184
  end
180
185
 
181
- retry
182
- rescue BlinkTM::DeviceNotReady
183
- file &.close
184
- sleep 0.1
185
- retry
186
- rescue Exception
187
- puts $!.full_message
188
- 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}"
189
192
  sleep 0.1
190
- retry
191
193
  end
192
194
  end
193
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
+
194
210
  extend(self)
195
211
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlinkTM
4
- VERSION = "0.2.0"
4
+ VERSION = "2.0.0"
5
5
  end
data/lib/blink_tm.rb CHANGED
@@ -1,22 +1,24 @@
1
1
  # Frozen_String_Literal: true
2
2
  require 'blink_tm/baudrate'
3
- require 'blink_tm/diskstats'
4
3
  require 'linux_stat'
5
4
 
5
+ $-v = true
6
+
6
7
  module BlinkTM
7
8
  # Important Constants
8
- BAUDRATE = BlinkTM::B57600
9
+ BAUDRATE = BlinkTM::B38400
9
10
  SCANID = 'BTM'
10
11
 
11
12
  # POLLING time, how often should CPU, Net, IO usages should be updated.
12
13
  # Should always be a float.
13
- POLLING = 0.375
14
+ POLLING = 0.250
14
15
 
15
16
  # Refresh time, how often the main loop should run
16
17
  REFRESH = 0.5
17
18
 
18
19
  # Errors
19
20
  NoDeviceError = Class.new(StandardError)
21
+ SyncError = Class.new(StandardError)
20
22
  DeviceNotReady = Class.new(StandardError)
21
23
 
22
24
  # Units
@@ -32,12 +34,13 @@ module BlinkTM
32
34
  ORANGE = "\e[38;2;245;155;20m"
33
35
  BOLD = "\e[1m"
34
36
  RESET = "\e[0m"
37
+ LOCKFILE = '/tmp/blinktaskmanager.pid'
35
38
 
36
39
  # Other constants
37
40
  ROOT_DEV = ::LinuxStat::Mounts.root
38
41
  ROOT = File.split(ROOT_DEV)[-1]
39
42
 
40
- SECTORS = get_sector_size(ROOT_DEV)
43
+ SECTORS = ::LS::Filesystem.sectors(ROOT_DEV)
41
44
 
42
45
  abort "#{BOLD}#{RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Can't get root partition#{RESET}" unless ROOT
43
46
  abort "#{BOLD}#{RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Can't get sector size#{RESET}" unless SECTORS
@@ -46,3 +49,4 @@ end
46
49
  require 'blink_tm/version'
47
50
  require 'fcntl'
48
51
  require 'blink_tm/blink_tm'
52
+ require 'blink_tm/crc32'
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.2.0
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-04-29 00:00:00.000000000 Z
11
+ date: 2021-12-24 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
@@ -31,15 +31,14 @@ executables:
31
31
  - blink-tm
32
32
  extensions:
33
33
  - ext/baudrate/extconf.rb
34
- - ext/diskstats/extconf.rb
34
+ - ext/crc32/extconf.rb
35
35
  extra_rdoc_files: []
36
36
  files:
37
37
  - exe/blink-tm
38
38
  - ext/baudrate/baudrate.c
39
39
  - ext/baudrate/extconf.rb
40
- - ext/diskstats/diskstats.c
41
- - ext/diskstats/extconf.rb
42
- - ext/diskstats/sectors.h
40
+ - ext/crc32/crc32.c
41
+ - ext/crc32/extconf.rb
43
42
  - lib/blink_tm.rb
44
43
  - lib/blink_tm/blink_tm.rb
45
44
  - lib/blink_tm/version.rb
@@ -62,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
61
  - !ruby/object:Gem::Version
63
62
  version: '0'
64
63
  requirements: []
65
- rubygems_version: 3.2.15
64
+ rubygems_version: 3.2.29
66
65
  signing_key:
67
66
  specification_version: 4
68
67
  summary: A controller for Arduino OLED System Monitor, Blink Task Manager
@@ -1,41 +0,0 @@
1
- #include <stdio.h>
2
- #include <string.h>
3
-
4
- #include <sys/ioctl.h>
5
- #include <fcntl.h>
6
- #include <linux/fs.h>
7
-
8
- #include "ruby.h"
9
- #include "sectors.h"
10
-
11
- VALUE getDiskstats (volatile VALUE obj, volatile VALUE path) {
12
- FILE *file = fopen("/proc/diskstats", "r") ;
13
- if(!file) return rb_ary_new() ;
14
-
15
- char lines[120] ;
16
- unsigned long long read, write ;
17
- char *p = StringValuePtr(path) ;
18
-
19
- while(fgets(lines, 119, file)) {
20
- sscanf(lines, "%*s %*s %s %*s %*s %llu %*s %*s %*s %llu", lines, &read, &write) ;
21
-
22
- if(strcmp(lines, p) == 0) {
23
- fclose(file) ;
24
-
25
- return rb_ary_new_from_args(
26
- 2,
27
- ULL2NUM(read),
28
- ULL2NUM(write)
29
- ) ;
30
- }
31
- }
32
-
33
- fclose(file) ;
34
- return rb_ary_new() ;
35
- }
36
-
37
- void Init_diskstats() {
38
- VALUE blink_tm = rb_define_module("BlinkTM") ;
39
- rb_define_module_function(blink_tm, "diskstats", getDiskstats, 1) ;
40
- rb_define_module_function(blink_tm, "get_sector_size", getSectorSize, 1) ;
41
- }
@@ -1,2 +0,0 @@
1
- require 'mkmf'
2
- create_makefile 'blink_tm/diskstats'
@@ -1,15 +0,0 @@
1
- VALUE getSectorSize (volatile VALUE obj, volatile VALUE path) {
2
- char *dev = StringValuePtr(path) ;
3
-
4
- unsigned int fd ;
5
- unsigned int sSize = 0 ;
6
-
7
- fd = open(dev, O_RDONLY | O_NONBLOCK) ;
8
- if(fd < 0) return Qnil ;
9
-
10
- short status = ioctl(fd, BLKSSZGET, &sSize) ;
11
- close(fd) ;
12
- if(status < 0) return Qnil ;
13
-
14
- return USHORT2NUM(sSize) ;
15
- }