Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory() unify RAM manufacturers and include Windows to parse #962

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 8 additions & 31 deletions lib/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,7 @@ const _openbsd = (_platform === 'openbsd');
const _netbsd = (_platform === 'netbsd');
const _sunos = (_platform === 'sunos');

const OSX_RAM_manufacturers = {
'0x014F': 'Transcend Information',
'0x2C00': 'Micron Technology Inc.',
'0x802C': 'Micron Technology Inc.',
'0x80AD': 'Hynix Semiconductor Inc.',
'0x80CE': 'Samsung Electronics Inc.',
'0xAD00': 'Hynix Semiconductor Inc.',
'0xCE00': 'Samsung Electronics Inc.',
'0x02FE': 'Elpida',
'0x5105': 'Qimonda AG i. In.',
'0x8551': 'Qimonda AG i. In.',
'0x859B': 'Crucial',
'0x04CD': 'G-Skill'
};

const LINUX_RAM_manufacturers = {
const RAM_manufacturers = {
'017A': 'Apacer',
'0198': 'HyperX',
'029E': 'Corsair',
Expand Down Expand Up @@ -315,17 +300,10 @@ exports.mem = mem;

function memLayout(callback) {

function getManufacturerDarwin(manId) {
if ({}.hasOwnProperty.call(OSX_RAM_manufacturers, manId)) {
return (OSX_RAM_manufacturers[manId]);
}
return manId;
}

function getManufacturerLinux(manId) {
function getManufacturer(manId) {
const manIdSearch = manId.replace('0x', '').toUpperCase();
if (manIdSearch.length === 4 && {}.hasOwnProperty.call(LINUX_RAM_manufacturers, manIdSearch)) {
return (LINUX_RAM_manufacturers[manIdSearch]);
if (manIdSearch.length === 4 && {}.hasOwnProperty.call(RAM_manufacturers, manIdSearch)) {
return (RAM_manufacturers[manIdSearch]);
}
return manId;
}
Expand Down Expand Up @@ -358,7 +336,7 @@ function memLayout(callback) {
ecc: dataWidth && totalWidth ? totalWidth > dataWidth : false,
clockSpeed: (util.getValue(lines, 'Configured Clock Speed:') ? parseInt(util.getValue(lines, 'Configured Clock Speed:'), 10) : (util.getValue(lines, 'Speed:') ? parseInt(util.getValue(lines, 'Speed:'), 10) : null)),
formFactor: util.getValue(lines, 'Form Factor:'),
manufacturer: getManufacturerLinux(util.getValue(lines, 'Manufacturer:')),
manufacturer: getManufacturer(util.getValue(lines, 'Manufacturer:')),
partNum: util.getValue(lines, 'Part Number:'),
serialNum: util.getValue(lines, 'Serial Number:'),
voltageConfigured: parseFloat(util.getValue(lines, 'Configured Voltage:')) || null,
Expand Down Expand Up @@ -470,7 +448,7 @@ function memLayout(callback) {
ecc: eccStatus ? eccStatus === 'enabled' : null,
clockSpeed: parseInt(util.getValue(lines, ' Speed:'), 10),
formFactor: '',
manufacturer: getManufacturerDarwin(util.getValue(lines, ' Manufacturer:')),
manufacturer: getManufacturer(util.getValue(lines, ' Manufacturer:')),
partNum: util.getValue(lines, ' Part Number:'),
serialNum: util.getValue(lines, ' Serial Number:'),
voltageConfigured: null,
Expand Down Expand Up @@ -508,7 +486,7 @@ function memLayout(callback) {
ecc: false,
clockSpeed: null,
formFactor: 'SOC',
manufacturer: getManufacturerDarwin(manufacturerId),
manufacturer: getManufacturer(manufacturerId),
partNum: '',
serialNum: '',
voltageConfigured: null,
Expand Down Expand Up @@ -551,7 +529,7 @@ function memLayout(callback) {
ecc: dataWidth && totalWidth ? totalWidth > dataWidth : false,
clockSpeed: parseInt(util.getValue(lines, 'ConfiguredClockSpeed', ':'), 10) || parseInt(util.getValue(lines, 'Speed', ':'), 10) || 0,
formFactor: FormFactors[parseInt(util.getValue(lines, 'FormFactor', ':'), 10) || 0],
manufacturer: util.getValue(lines, 'Manufacturer', ':'),
manufacturer: getManufacturer(util.getValue(lines, 'Manufacturer', ':')),
partNum: util.getValue(lines, 'PartNumber', ':'),
serialNum: util.getValue(lines, 'SerialNumber', ':'),
voltageConfigured: (parseInt(util.getValue(lines, 'ConfiguredVoltage', ':'), 10) || 0) / 1000.0,
Expand All @@ -574,4 +552,3 @@ function memLayout(callback) {
}

exports.memLayout = memLayout;