Skip to content

Commit

Permalink
memory(), chassis() optimized for raspberry
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Jan 9, 2025
1 parent 13793c2 commit 0be9e22
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 237 deletions.
17 changes: 7 additions & 10 deletions lib/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,16 +780,13 @@ function getCpu() {
result.governor = util.getValue(lines, 'governor') || '';

// Test Raspberry
if (result.vendor === 'ARM') {
const linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n');
const rPIRevision = util.decodePiCpuinfo(linesRpi);
if (rPIRevision.model.toLowerCase().indexOf('raspberry') >= 0) {
result.family = result.manufacturer;
result.manufacturer = rPIRevision.manufacturer;
result.brand = rPIRevision.processor;
result.revision = rPIRevision.revisionCode;
result.socket = 'SOC';
}
if (result.vendor === 'ARM' && util.isRaspberry()) {
const rPIRevision = util.decodePiCpuinfo();
result.family = result.manufacturer;
result.manufacturer = rPIRevision.manufacturer;
result.brand = rPIRevision.processor;
result.revision = rPIRevision.revisionCode;
result.socket = 'SOC';
}

// Test RISC-V
Expand Down
3 changes: 1 addition & 2 deletions lib/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,9 @@ function memLayout(callback) {
try {
let stdout = execSync('cat /proc/cpuinfo 2>/dev/null', util.execOptsLinux);
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') {
if (util.isRaspberry(lines)) {

const clockSpeed = {
'0': 400,
Expand Down
27 changes: 9 additions & 18 deletions lib/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function system(callback) {
const model = util.getValue(lines, 'model:', ':', true);
// reference values: https://elinux.org/RPi_HardwareHistory
// https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
if ((result.model === 'BCM2835' || result.model === 'BCM2708' || result.model === 'BCM2709' || result.model === 'BCM2710' || result.model === 'BCM2711' || result.model === 'BCM2836' || result.model === 'BCM2837' || result.model === '') && model.toLowerCase().indexOf('raspberry') >= 0) {
if (util.isRaspberry(lines)) {
const rPIRevision = util.decodePiCpuinfo(lines);
result.model = rPIRevision.model;
result.version = rPIRevision.revisionCode;
Expand Down Expand Up @@ -504,23 +504,14 @@ function baseboard(callback) {
result.memSlots = util.toInt(util.getValue(lines, 'Number Of Devices')) || null;

// raspberry
let linesRpi = '';
try {
linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n');
} catch (e) {
util.noop();
}
if (linesRpi) {
const hardware = util.getValue(linesRpi, 'hardware');
if (hardware.startsWith('BCM')) {
const rpi = util.decodePiCpuinfo(linesRpi);
result.manufacturer = rpi.manufacturer;
result.model = 'Raspberry Pi';
result.serial = rpi.serial;
result.version = rpi.type + ' - ' + rpi.revision;
result.memMax = os.totalmem();
result.memSlots = 0;
}
if (util.isRaspberry()) {
const rpi = util.decodePiCpuinfo();
result.manufacturer = rpi.manufacturer;
result.model = 'Raspberry Pi';
result.serial = rpi.serial;
result.version = rpi.type + ' - ' + rpi.revision;
result.memMax = os.totalmem();
result.memSlots = 0;
}

if (callback) { callback(result); }
Expand Down
Loading

0 comments on commit 0be9e22

Please sign in to comment.