From 8c251354b08356479c3aa2d2225812ff5afac1d8 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Mon, 17 Feb 2020 21:35:21 +0100 Subject: [PATCH] memLayout() raspberry PI support --- CHANGELOG.md | 1 + docs/history.html | 5 +++++ docs/index.html | 2 +- lib/memory.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++ lib/system.js | 4 ++++ 5 files changed, 68 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4ccc44..510915e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.22.1 | 2020-02-17 | `memLayout()` raspberry PI support | | 4.22.0 | 2020-02-17 | `services()` added pids (windows) | | 4.21.3 | 2020-02-16 | `versions()` fixed mysql version (macOS) | | 4.21.2 | 2020-02-11 | `networkConnections()` fixed linux (debian) issue | diff --git a/docs/history.html b/docs/history.html index a4fc72b..8568500 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.22.1 + 2020-02-17 + memLayout() raspberry PI support + 4.22.0 2020-02-17 diff --git a/docs/index.html b/docs/index.html index cfa35a7..95bb7ee 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.22.0
+
Current Version: 4.22.1
diff --git a/lib/memory.js b/lib/memory.js index bfe9632..ace26ac 100644 --- a/lib/memory.js +++ b/lib/memory.js @@ -15,6 +15,7 @@ const os = require('os'); const exec = require('child_process').exec; +const execSync = require('child_process').execSync; const util = require('./util'); let _platform = process.platform; @@ -314,6 +315,62 @@ function memLayout(callback) { } }); } + if (!result.length) { + result.push({ + size: os.totalmem(), + bank: '', + type: '', + clockSpeed: 0, + formFactor: '', + partNum: '', + serialNum: '', + voltageConfigured: -1, + voltageMin: -1, + voltageMax: -1, + }); + + // Try Raspberry PI + try { + let stdout = execSync('cat /proc/cpuinfo 2>/dev/null'); + let lines = stdout.toString().split('\n'); + let model = util.getValue(lines, 'hardware', ':', true).toUpperCase(); + let version = util.getValue(lines, 'revision', ':', true).toLowerCase(); + + if (model === 'BCM2835' || model === 'BCM2708' || model === 'BCM2709' || model === 'BCM2835' || model === 'BCM2837') { + + const clockSpeed = { + '0': 400, + '1': 450, + '2': 450, + '3': 3200 + }; + result[0].clockSpeed = version && version[2] && clockSpeed[version[2]] || 400; + result[0].clockSpeed = version && version[4] && version[4] === 'd' ? '500' : result[0].clockSpeed; + result[0].type = 'LPDDR2'; + result[0].type = version && version[2] && version[2] === '3' ? 'LPDDR4' : result[0].type; + result[0].formFactor = 'SoC'; + + stdout = execSync('vcgencmd get_config sdram_freq 2>/dev/null'); + lines = stdout.toString().split('\n'); + let freq = parseInt(util.getValue(lines, 'sdram_freq', '=', true), 10) || 0; + if (freq) { + result.clockSpeed = freq; + } + + stdout = execSync('vcgencmd measure_volts sdram_p 2>/dev/null'); + lines = stdout.toString().split('\n'); + let voltage = parseInt(util.getValue(lines, 'sdram_freq', '=', true), 10) || 0; + if (voltage) { + result.voltageConfigured = voltage; + result.voltageMin = voltage; + result.voltageMax = voltage; + } + } + } catch (e) { + util.noop(); + } + + } if (callback) { callback(result); } resolve(result); }); diff --git a/lib/system.js b/lib/system.js index d946286..9650f72 100644 --- a/lib/system.js +++ b/lib/system.js @@ -100,6 +100,10 @@ function system(callback) { if (result.model === 'BCM2835' || result.model === 'BCM2708' || result.model === 'BCM2709' || result.model === 'BCM2835' || result.model === 'BCM2837') { // Pi 4 + if (['c03112'].indexOf(result.version) >= 0) { + result.model = result.model + ' - Pi 4 Model B'; + result.version = result.version + ' - Rev. 1.2'; + } if (['a03111', 'b03111', 'c03111'].indexOf(result.version) >= 0) { result.model = result.model + ' - Pi 4 Model B'; result.version = result.version + ' - Rev. 1.1';