systeminformation 6.0.0-beta.2 → 6.0.0-beta.21
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.
- package/README.md +67 -18
- package/dist/bsd/mem.js +8 -3
- package/dist/bsd/network-stats.d.ts +1 -1
- package/dist/bsd/network-stats.js +14 -7
- package/dist/bsd/os-info.d.ts +1 -0
- package/dist/common/darwin.d.ts +2 -0
- package/dist/common/darwin.js +17 -1
- package/dist/common/defaults.d.ts +2 -1
- package/dist/common/defaults.js +36 -6
- package/dist/common/exec.js +29 -13
- package/dist/common/files.d.ts +9 -0
- package/dist/common/files.js +67 -3
- package/dist/common/filesys.d.ts +30 -0
- package/dist/common/filesys.js +228 -11
- package/dist/common/host.js +55 -3
- package/dist/common/internet.js +31 -20
- package/dist/common/mappings.d.ts +0 -3
- package/dist/common/mappings.js +35 -14
- package/dist/common/network.d.ts +15 -2
- package/dist/common/network.js +18 -22
- package/dist/common/nvidia.d.ts +1 -1
- package/dist/common/nvidia.js +4 -5
- package/dist/common/parse.d.ts +4 -6
- package/dist/common/parse.js +24 -69
- package/dist/common/security.d.ts +2 -0
- package/dist/common/security.js +18 -3
- package/dist/common/types.d.ts +53 -5
- package/dist/common/windows.d.ts +4 -0
- package/dist/common/windows.js +57 -1
- package/dist/cpu-current-load.d.ts +1 -0
- package/dist/cpu-current-load.js +54 -8
- package/dist/cpu-current-speed.js +5 -3
- package/dist/darwin/battery.d.ts +1 -1
- package/dist/darwin/battery.js +15 -5
- package/dist/darwin/camera.js +3 -3
- package/dist/darwin/disk-layout.js +16 -12
- package/dist/darwin/disks-io.js +3 -3
- package/dist/darwin/displays.d.ts +1 -0
- package/dist/darwin/displays.js +64 -2
- package/dist/darwin/fans.d.ts +2 -0
- package/dist/darwin/fans.js +28 -0
- package/dist/darwin/gpu.js +1 -1
- package/dist/darwin/index.d.ts +3 -0
- package/dist/darwin/index.js +8 -2
- package/dist/darwin/keyboard.js +4 -4
- package/dist/darwin/mouse.js +4 -4
- package/dist/darwin/network-interfaces.d.ts +3 -0
- package/dist/darwin/network-interfaces.js +81 -14
- package/dist/darwin/network-stats.d.ts +1 -1
- package/dist/darwin/network-stats.js +14 -7
- package/dist/darwin/os-info.d.ts +2 -0
- package/dist/darwin/os-info.js +24 -2
- package/dist/darwin/process-focused.d.ts +3 -0
- package/dist/darwin/process-focused.js +26 -0
- package/dist/darwin/serial-ports.d.ts +2 -0
- package/dist/darwin/serial-ports.js +94 -0
- package/dist/darwin/users.js +1 -1
- package/dist/docker.js +4 -5
- package/dist/fans.d.ts +1 -0
- package/dist/fans.js +17 -0
- package/dist/get-data.d.ts +4 -0
- package/dist/get-data.js +6 -2
- package/dist/get.js +6 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -2
- package/dist/inet-public-ip.js +2 -1
- package/dist/linux/audio.js +59 -0
- package/dist/linux/baseboard.js +9 -20
- package/dist/linux/bios.js +6 -15
- package/dist/linux/block-devices.js +3 -1
- package/dist/linux/camera.js +2 -1
- package/dist/linux/chassis.js +4 -10
- package/dist/linux/cpu-temperature.js +34 -19
- package/dist/linux/cpu.js +3 -1
- package/dist/linux/disk-layout.js +9 -12
- package/dist/linux/disks-io.js +9 -9
- package/dist/linux/displays.d.ts +8 -0
- package/dist/linux/displays.js +151 -4
- package/dist/linux/fans.d.ts +2 -0
- package/dist/linux/fans.js +92 -0
- package/dist/linux/fs-size.d.ts +1 -1
- package/dist/linux/fs-size.js +164 -37
- package/dist/linux/fs-stats.js +6 -9
- package/dist/linux/gpu.d.ts +2 -0
- package/dist/linux/gpu.js +97 -22
- package/dist/linux/index.d.ts +3 -0
- package/dist/linux/index.js +8 -2
- package/dist/linux/mem-layout.js +3 -7
- package/dist/linux/mem.d.ts +1 -0
- package/dist/linux/mem.js +21 -1
- package/dist/linux/network-interfaces.d.ts +1 -0
- package/dist/linux/network-interfaces.js +154 -113
- package/dist/linux/network-stats.d.ts +1 -1
- package/dist/linux/network-stats.js +14 -40
- package/dist/linux/npu.js +2 -1
- package/dist/linux/os-info.js +56 -5
- package/dist/linux/printer.js +4 -4
- package/dist/linux/process-focused.d.ts +4 -0
- package/dist/linux/process-focused.js +32 -0
- package/dist/linux/process-load.js +11 -13
- package/dist/linux/processes.js +89 -80
- package/dist/linux/serial-ports.d.ts +2 -0
- package/dist/linux/serial-ports.js +102 -0
- package/dist/linux/services.js +182 -49
- package/dist/linux/system.js +1 -7
- package/dist/linux/users.js +1 -1
- package/dist/linux/uuid.js +4 -10
- package/dist/linux/wifi-networks.js +2 -2
- package/dist/network-interfaces.js +1 -1
- package/dist/observe.d.ts +1 -1
- package/dist/observe.js +5 -1
- package/dist/process-focused.d.ts +1 -0
- package/dist/process-focused.js +17 -0
- package/dist/serial-ports.d.ts +1 -0
- package/dist/serial-ports.js +17 -0
- package/dist/versions.js +34 -80
- package/dist/windows/audio.d.ts +29 -0
- package/dist/windows/audio.js +151 -11
- package/dist/windows/disk-layout.js +3 -0
- package/dist/windows/disks-io.js +3 -3
- package/dist/windows/displays.d.ts +5 -0
- package/dist/windows/displays.js +101 -16
- package/dist/windows/fans.d.ts +2 -0
- package/dist/windows/fans.js +71 -0
- package/dist/windows/fs-size.js +1 -4
- package/dist/windows/gpu.js +3 -2
- package/dist/windows/index.d.ts +3 -0
- package/dist/windows/index.js +8 -2
- package/dist/windows/network-interfaces.js +36 -41
- package/dist/windows/network-stats.js +20 -6
- package/dist/windows/process-focused.d.ts +3 -0
- package/dist/windows/process-focused.js +36 -0
- package/dist/windows/process-load.js +7 -5
- package/dist/windows/processes.d.ts +1 -0
- package/dist/windows/processes.js +54 -26
- package/dist/windows/serial-ports.d.ts +3 -0
- package/dist/windows/serial-ports.js +73 -0
- package/dist/windows/services.js +4 -1
- package/package.json +1 -1
|
@@ -6,6 +6,8 @@ const const_1 = require("../common/const");
|
|
|
6
6
|
const common_1 = require("../common");
|
|
7
7
|
const security_1 = require("../common/security");
|
|
8
8
|
const parse_1 = require("../common/parse");
|
|
9
|
+
const files_1 = require("../common/files");
|
|
10
|
+
const EXEC_OPTS = { timeout: 5000 };
|
|
9
11
|
const _process_cpu = {
|
|
10
12
|
all: 0,
|
|
11
13
|
all_utime: 0,
|
|
@@ -22,7 +24,7 @@ const processLoad = async (proc) => {
|
|
|
22
24
|
const processes = (0, security_1.sanitizeServiceString)(proc);
|
|
23
25
|
if (processes.length) {
|
|
24
26
|
const args = ['-axo', 'pid,ppid,pcpu,pmem,comm'];
|
|
25
|
-
stdout = await (0, exec_1.execSecure)('ps', args);
|
|
27
|
+
stdout = await (0, exec_1.execSecure)('ps', args, EXEC_OPTS);
|
|
26
28
|
if (stdout) {
|
|
27
29
|
const procStats = [];
|
|
28
30
|
const lines = stdout.split('\n').filter((line) => {
|
|
@@ -108,19 +110,17 @@ const processLoad = async (proc) => {
|
|
|
108
110
|
result.forEach(function (item) {
|
|
109
111
|
item.cpu = 0;
|
|
110
112
|
});
|
|
111
|
-
|
|
113
|
+
const pids = [];
|
|
112
114
|
for (const i in result) {
|
|
113
|
-
|
|
114
|
-
cmd += ';cat /proc/' + result[i].pids[j] + '/stat';
|
|
115
|
-
}
|
|
115
|
+
pids.push(...result[i].pids);
|
|
116
116
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const all = (0, parse_1.parseProcStat)(
|
|
120
|
-
curr_processes =
|
|
117
|
+
const cpuBaseline = { ..._process_cpu };
|
|
118
|
+
const stats = await (0, files_1.readProcStats)(pids);
|
|
119
|
+
const all = (0, parse_1.parseProcStat)(stats.all);
|
|
120
|
+
const curr_processes = stats.procs;
|
|
121
121
|
const list_new = {};
|
|
122
122
|
curr_processes.forEach((element) => {
|
|
123
|
-
const resultProcess = (0, parse_1.calcProcStatLinux)(element, all,
|
|
123
|
+
const resultProcess = (0, parse_1.calcProcStatLinux)(element, all, cpuBaseline);
|
|
124
124
|
if (resultProcess.pid) {
|
|
125
125
|
let resultItemId = -1;
|
|
126
126
|
for (let i = 0; i < result.length; i++) {
|
|
@@ -135,9 +135,7 @@ const processLoad = async (proc) => {
|
|
|
135
135
|
cpuu: resultProcess.cpuu,
|
|
136
136
|
cpus: resultProcess.cpus,
|
|
137
137
|
utime: resultProcess.utime,
|
|
138
|
-
stime: resultProcess.stime
|
|
139
|
-
cutime: resultProcess.cutime,
|
|
140
|
-
cstime: resultProcess.cstime
|
|
138
|
+
stime: resultProcess.stime
|
|
141
139
|
};
|
|
142
140
|
}
|
|
143
141
|
});
|
package/dist/linux/processes.js
CHANGED
|
@@ -36,71 +36,84 @@ const getName = (command) => {
|
|
|
36
36
|
}
|
|
37
37
|
return result;
|
|
38
38
|
};
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const checkColumn = (i) => {
|
|
46
|
-
offset = offset2;
|
|
47
|
-
if (parsedhead[i]) {
|
|
48
|
-
offset2 = line.substring(parsedhead[i].to + offset, 10000).indexOf(' ');
|
|
39
|
+
const splitPsLine = (line, count) => {
|
|
40
|
+
const fields = [];
|
|
41
|
+
let pos = 0;
|
|
42
|
+
while (fields.length < count) {
|
|
43
|
+
while (pos < line.length && line[pos] === ' ') {
|
|
44
|
+
pos++;
|
|
49
45
|
}
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const start = pos;
|
|
47
|
+
while (pos < line.length && line[pos] !== ' ') {
|
|
48
|
+
pos++;
|
|
52
49
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const nice = (0, common_1.toInt)(line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2)) || 0;
|
|
70
|
-
checkColumn(8);
|
|
71
|
-
const started = !const_1.SUNOS
|
|
72
|
-
? (0, datetime_1.parseElapsedTime)(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim())
|
|
73
|
-
: (0, datetime_1.parseTimeUnix)(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim());
|
|
74
|
-
checkColumn(9);
|
|
75
|
-
let state = line.substring(parsedhead[9].from + offset, parsedhead[9].to + offset2).trim();
|
|
76
|
-
state =
|
|
77
|
-
state[0] === 'R'
|
|
78
|
-
? 'running'
|
|
79
|
-
: state[0] === 'S'
|
|
80
|
-
? 'sleeping'
|
|
81
|
-
: state[0] === 'T'
|
|
82
|
-
? 'stopped'
|
|
83
|
-
: state[0] === 'W'
|
|
84
|
-
? 'paging'
|
|
85
|
-
: state[0] === 'X'
|
|
86
|
-
? 'dead'
|
|
87
|
-
: state[0] === 'Z'
|
|
88
|
-
? 'zombie'
|
|
89
|
-
: state[0] === 'D' || state[0] === 'U'
|
|
90
|
-
? 'blocked'
|
|
91
|
-
: 'unknown';
|
|
92
|
-
checkColumn(10);
|
|
93
|
-
let tty = line.substring(parsedhead[10].from + offset, parsedhead[10].to + offset2).trim();
|
|
94
|
-
if (tty === '?' || tty === '??') {
|
|
95
|
-
tty = '';
|
|
50
|
+
if (pos === start) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
fields.push(line.substring(start, pos));
|
|
54
|
+
}
|
|
55
|
+
while (pos < line.length && line[pos] === ' ') {
|
|
56
|
+
pos++;
|
|
57
|
+
}
|
|
58
|
+
return { fields, rest: line.substring(pos) };
|
|
59
|
+
};
|
|
60
|
+
const parseCpuTime = (value) => {
|
|
61
|
+
const dayParts = value.split('-');
|
|
62
|
+
const days = dayParts.length > 1 ? (0, common_1.toInt)(dayParts[0]) : 0;
|
|
63
|
+
const parts = dayParts[dayParts.length - 1].split(':');
|
|
64
|
+
if (parts.length < 2 || parts.length > 3) {
|
|
65
|
+
return null;
|
|
96
66
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
67
|
+
const seconds = parseFloat(parts[parts.length - 1]);
|
|
68
|
+
if (Number.isNaN(seconds)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const minutes = (0, common_1.toInt)(parts[parts.length - 2]);
|
|
72
|
+
const hours = parts.length === 3 ? (0, common_1.toInt)(parts[0]) : 0;
|
|
73
|
+
return days * 86400 + hours * 3600 + minutes * 60 + seconds;
|
|
74
|
+
};
|
|
75
|
+
const parseLine = async (line) => {
|
|
76
|
+
const split = splitPsLine(line, 13);
|
|
77
|
+
if (!split) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const [pidValue, ppidValue, cpuValue, memValue, priValue, vszValue, rssValue, niceValue, timeValue, stateValue, ttyValue, user] = split.fields;
|
|
81
|
+
const pid = (0, common_1.toInt)(pidValue);
|
|
82
|
+
if (!pid) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const ppid = (0, common_1.toInt)(ppidValue);
|
|
86
|
+
const cpu = parseFloat(cpuValue.replace(/,/g, '.'));
|
|
87
|
+
const mem = parseFloat(memValue.replace(/,/g, '.'));
|
|
88
|
+
const priority = (0, common_1.toInt)(priValue);
|
|
89
|
+
const vsz = (0, common_1.toInt)(vszValue);
|
|
90
|
+
const rss = (0, common_1.toInt)(rssValue);
|
|
91
|
+
const nice = (0, common_1.toInt)(niceValue) || 0;
|
|
92
|
+
const started = !const_1.SUNOS ? (0, datetime_1.parseElapsedTime)(timeValue) : (0, datetime_1.parseTimeUnix)(timeValue);
|
|
93
|
+
const state = stateValue[0] === 'R'
|
|
94
|
+
? 'running'
|
|
95
|
+
: stateValue[0] === 'S'
|
|
96
|
+
? 'sleeping'
|
|
97
|
+
: stateValue[0] === 'T'
|
|
98
|
+
? 'stopped'
|
|
99
|
+
: stateValue[0] === 'W'
|
|
100
|
+
? 'paging'
|
|
101
|
+
: stateValue[0] === 'X'
|
|
102
|
+
? 'dead'
|
|
103
|
+
: stateValue[0] === 'Z'
|
|
104
|
+
? 'zombie'
|
|
105
|
+
: stateValue[0] === 'D' || stateValue[0] === 'U'
|
|
106
|
+
? 'blocked'
|
|
107
|
+
: 'unknown';
|
|
108
|
+
const tty = ttyValue === '?' || ttyValue === '??' ? '' : ttyValue;
|
|
109
|
+
const cpuTime = parseCpuTime(split.fields[12]);
|
|
100
110
|
let cmdPath = '';
|
|
101
111
|
let command = '';
|
|
102
112
|
let params = '';
|
|
103
|
-
let fullcommand =
|
|
113
|
+
let fullcommand = split.rest.trim();
|
|
114
|
+
if (fullcommand.endsWith(' <defunct>')) {
|
|
115
|
+
fullcommand = fullcommand.slice(0, -10).trim();
|
|
116
|
+
}
|
|
104
117
|
if (fullcommand.endsWith(']')) {
|
|
105
118
|
fullcommand = fullcommand.slice(0, -1);
|
|
106
119
|
}
|
|
@@ -159,6 +172,7 @@ const parseLine = async (line, parsedhead) => {
|
|
|
159
172
|
cpu: cpu,
|
|
160
173
|
cpuu: 0,
|
|
161
174
|
cpus: 0,
|
|
175
|
+
cpuTime,
|
|
162
176
|
mem: mem,
|
|
163
177
|
priority: priority,
|
|
164
178
|
memVsz: vsz,
|
|
@@ -173,13 +187,13 @@ const parseLine = async (line, parsedhead) => {
|
|
|
173
187
|
path: cmdPath
|
|
174
188
|
};
|
|
175
189
|
};
|
|
176
|
-
const parseProcesses = async (lines
|
|
190
|
+
const parseProcesses = async (lines) => {
|
|
177
191
|
const result = [];
|
|
178
192
|
if (lines.length > 1) {
|
|
179
193
|
lines = lines.splice(1);
|
|
180
194
|
for (const line of lines) {
|
|
181
195
|
if (line.trim() !== '') {
|
|
182
|
-
const parsed = await parseLine(line
|
|
196
|
+
const parsed = await parseLine(line);
|
|
183
197
|
if (parsed) {
|
|
184
198
|
result.push(parsed);
|
|
185
199
|
}
|
|
@@ -252,6 +266,7 @@ const parseProcesses2 = (lines) => {
|
|
|
252
266
|
: 'unknown',
|
|
253
267
|
tty: parts[7],
|
|
254
268
|
user: parts[8],
|
|
269
|
+
cpuTime: null,
|
|
255
270
|
command: command,
|
|
256
271
|
params: '',
|
|
257
272
|
path: ''
|
|
@@ -268,42 +283,38 @@ const processes = async () => {
|
|
|
268
283
|
if ((_processes_cpu.ms && Date.now() - _processes_cpu.ms >= 500) || _processes_cpu.ms === 0) {
|
|
269
284
|
try {
|
|
270
285
|
if (const_1.LINUX || const_1.ANDROID) {
|
|
271
|
-
cmd = 'export LC_ALL=C; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,etime:30,state:5,tty:15,user:20,command; unset LC_ALL';
|
|
286
|
+
cmd = 'export LC_ALL=C.UTF-8; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,etime:30,state:5,tty:15,user:20,time,command; unset LC_ALL';
|
|
272
287
|
}
|
|
273
288
|
if (const_1.FREEBSD || const_1.NETBSD || const_1.OPENBSD) {
|
|
274
|
-
cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,etime,state,tty,user,command; unset LC_ALL';
|
|
289
|
+
cmd = 'export LC_ALL=C.UTF-8; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,etime,state,tty,user,time,command; unset LC_ALL';
|
|
275
290
|
}
|
|
276
291
|
if (const_1.DARWIN) {
|
|
277
|
-
cmd = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz=temp_title_1,rss=temp_title_2,nice,etime=temp_title_3,state,tty,user,command -r';
|
|
292
|
+
cmd = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz=temp_title_1,rss=temp_title_2,nice,etime=temp_title_3,state,tty,user,time,command -r';
|
|
278
293
|
}
|
|
279
294
|
if (const_1.SUNOS) {
|
|
280
|
-
cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm';
|
|
295
|
+
cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,time,comm';
|
|
281
296
|
}
|
|
282
297
|
({ stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux));
|
|
283
298
|
if (stdout.trim()) {
|
|
284
|
-
const lines = stdout.
|
|
285
|
-
|
|
286
|
-
result.list = (await parseProcesses(lines, parsedhead)).slice();
|
|
299
|
+
const lines = stdout.split('\n');
|
|
300
|
+
result.list = (await parseProcesses(lines)).slice();
|
|
287
301
|
result.all = result.list.length;
|
|
288
302
|
result.running = result.list.filter((e) => e.state === 'running').length;
|
|
289
303
|
result.blocked = result.list.filter((e) => e.state === 'blocked').length;
|
|
290
304
|
result.sleeping = result.list.filter((e) => e.state === 'sleeping').length;
|
|
291
305
|
if (const_1.LINUX) {
|
|
292
|
-
|
|
293
|
-
result.list.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
({ stdout } = await (0, exec_1.exec)(cmd, const_1.execOptsLinux));
|
|
297
|
-
let curr_processes = stdout.toString().split('\n');
|
|
298
|
-
const all = (0, parse_1.parseProcStat)(curr_processes[0]);
|
|
299
|
-
curr_processes = curr_processes.slice(1);
|
|
306
|
+
const cpuBaseline = { ..._processes_cpu };
|
|
307
|
+
const stats = await (0, files_1.readProcStats)(result.list.map((element) => element.pid));
|
|
308
|
+
const all = (0, parse_1.parseProcStat)(stats.all);
|
|
309
|
+
const curr_processes = stats.procs;
|
|
300
310
|
const list_new = {};
|
|
301
311
|
curr_processes.forEach((element) => {
|
|
302
|
-
const resultProcess = (0, parse_1.calcProcStatLinux)(element, all,
|
|
312
|
+
const resultProcess = (0, parse_1.calcProcStatLinux)(element, all, cpuBaseline);
|
|
303
313
|
if (resultProcess.pid) {
|
|
304
314
|
const listPos = result.list.map((e) => e.pid).indexOf(resultProcess.pid);
|
|
305
315
|
if (listPos >= 0) {
|
|
306
316
|
result.list[listPos].cpu = resultProcess.cpuu + resultProcess.cpus;
|
|
317
|
+
result.list[listPos].cpuTime = (resultProcess.utime + resultProcess.stime) / 100;
|
|
307
318
|
result.list[listPos].cpuu = resultProcess.cpuu;
|
|
308
319
|
result.list[listPos].cpus = resultProcess.cpus;
|
|
309
320
|
}
|
|
@@ -311,9 +322,7 @@ const processes = async () => {
|
|
|
311
322
|
cpuu: resultProcess.cpuu,
|
|
312
323
|
cpus: resultProcess.cpus,
|
|
313
324
|
utime: resultProcess.utime,
|
|
314
|
-
stime: resultProcess.stime
|
|
315
|
-
cutime: resultProcess.cutime,
|
|
316
|
-
cstime: resultProcess.cstime
|
|
325
|
+
stime: resultProcess.stime
|
|
317
326
|
};
|
|
318
327
|
}
|
|
319
328
|
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serialPorts = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const common_1 = require("../common");
|
|
7
|
+
const defaults_1 = require("../common/defaults");
|
|
8
|
+
const files_1 = require("../common/files");
|
|
9
|
+
const security_1 = require("../common/security");
|
|
10
|
+
const busType = (subsystem, name) => {
|
|
11
|
+
switch (subsystem) {
|
|
12
|
+
case 'usb':
|
|
13
|
+
case 'usb-serial':
|
|
14
|
+
return 'usb';
|
|
15
|
+
case 'pnp':
|
|
16
|
+
case 'amba':
|
|
17
|
+
case 'platform':
|
|
18
|
+
case 'of_serial':
|
|
19
|
+
return 'onboard';
|
|
20
|
+
case 'pci':
|
|
21
|
+
return 'pci';
|
|
22
|
+
case 'bluetooth':
|
|
23
|
+
return 'bluetooth';
|
|
24
|
+
default:
|
|
25
|
+
return name.startsWith('rfcomm') ? 'bluetooth' : 'unknown';
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const usbDevicePath = async (devicePath) => {
|
|
29
|
+
let current = devicePath;
|
|
30
|
+
for (let depth = 0; depth < 6; depth++) {
|
|
31
|
+
if (await (0, files_1.fileExists)(`${current}/idVendor`)) {
|
|
32
|
+
return current;
|
|
33
|
+
}
|
|
34
|
+
const parent = (0, path_1.dirname)(current);
|
|
35
|
+
if (parent === current) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
current = parent;
|
|
39
|
+
}
|
|
40
|
+
return '';
|
|
41
|
+
};
|
|
42
|
+
const stableIds = async (path) => {
|
|
43
|
+
const map = {};
|
|
44
|
+
try {
|
|
45
|
+
for (const entry of (await (0, promises_1.readdir)(path)).filter(security_1.isSafePathSegment)) {
|
|
46
|
+
try {
|
|
47
|
+
map[(0, path_1.basename)(await (0, promises_1.readlink)(`${path}/${entry}`))] = entry;
|
|
48
|
+
}
|
|
49
|
+
catch { }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch { }
|
|
53
|
+
return map;
|
|
54
|
+
};
|
|
55
|
+
const serialPorts = async (sysPath = '/sys/class/tty', byIdPath = '/dev/serial/by-id') => {
|
|
56
|
+
await (0, common_1.nextTick)();
|
|
57
|
+
const result = [];
|
|
58
|
+
let names = [];
|
|
59
|
+
try {
|
|
60
|
+
names = (await (0, promises_1.readdir)(sysPath)).filter(security_1.isSafePathSegment);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
const byId = await stableIds(byIdPath);
|
|
66
|
+
for (const name of names.sort()) {
|
|
67
|
+
let devicePath = '';
|
|
68
|
+
try {
|
|
69
|
+
devicePath = await (0, promises_1.realpath)(`${sysPath}/${name}/device`);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if ((await (0, files_1.readSysfs)(`${sysPath}/${name}/type`)) === '0') {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
let subsystem = '';
|
|
78
|
+
try {
|
|
79
|
+
subsystem = (0, path_1.basename)(await (0, promises_1.realpath)(`${devicePath}/subsystem`));
|
|
80
|
+
}
|
|
81
|
+
catch { }
|
|
82
|
+
const port = {
|
|
83
|
+
...(0, common_1.cloneObj)(defaults_1.initSerialPortResult),
|
|
84
|
+
device: `/dev/${name}`,
|
|
85
|
+
name,
|
|
86
|
+
type: busType(subsystem, name),
|
|
87
|
+
pnpId: byId[name] || null
|
|
88
|
+
};
|
|
89
|
+
const usbPath = await usbDevicePath(devicePath);
|
|
90
|
+
if (usbPath) {
|
|
91
|
+
port.type = 'usb';
|
|
92
|
+
port.vendorId = (await (0, files_1.readSysfs)(`${usbPath}/idVendor`)).toLowerCase() || null;
|
|
93
|
+
port.productId = (await (0, files_1.readSysfs)(`${usbPath}/idProduct`)).toLowerCase() || null;
|
|
94
|
+
port.manufacturer = (await (0, files_1.readSysfs)(`${usbPath}/manufacturer`)) || null;
|
|
95
|
+
port.serialNumber = (await (0, files_1.readSysfs)(`${usbPath}/serial`)) || null;
|
|
96
|
+
port.name = (await (0, files_1.readSysfs)(`${usbPath}/product`)) || name;
|
|
97
|
+
}
|
|
98
|
+
result.push(port);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
};
|
|
102
|
+
exports.serialPorts = serialPorts;
|