fix mac memory and invalid smc values

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
si458 2024-03-04 10:57:09 +00:00
parent 3ffc92e917
commit 548c1b9bb4
2 changed files with 27 additions and 29 deletions

View File

@ -610,33 +610,26 @@ function macos_identifiers()
if(lines.length > 0) { if(lines.length > 0) {
const memorySlots = []; const memorySlots = [];
if(lines[2].trim().includes('Memory Slots:')) { // OLD MACS WITH SLOTS if(lines[2].trim().includes('Memory Slots:')) { // OLD MACS WITH SLOTS
const Memory = []; var memorySlots1 = child.stdout.str.split(/\n{2,}/).slice(3);
const bankMatches = child.stdout.str.trim().match(/BANK \d+\/DIMM\d+:[\s\S]*?(?=(BANK|$))/g); memorySlots1.forEach(function(slot,index) {
bankMatches.forEach(function(match, index) { var lines = slot.split('\n');
const bankInfo = match.match(/BANK (\d+)\/DIMM(\d+):[\s\S]*?Size: (\d+ \w+)[\s\S]*?Type: (\w+)[\s\S]*?Speed: (\d+ \w+)[\s\S]*?Status: (\w+)[\s\S]*?Manufacturer: (0x[0-9A-Fa-f]+)[\s\S]*?Part Number: (0x[0-9A-Fa-f]+)[\s\S]*?Serial Number: (.+)/); if(lines.length == 1){ // start here
if (bankInfo) { if(lines[0].trim()!=''){
const bankIndex = bankInfo[1].trim(); var slotObj = { DeviceLocator: lines[0].trim().replace(/:$/, '') }; // Initialize name as an empty string
const dimmIndex = bankInfo[2].trim(); var nextline = memorySlots1[index+1].split('\n');
const size = bankInfo[3].trim(); nextline.forEach(function(line) {
const type = bankInfo[4].trim(); if (line.trim() !== '') {
const speed = bankInfo[5].trim(); var parts = line.split(':');
const status = bankInfo[6].trim(); var key = parts[0].trim();
const manufacturer = bankInfo[7].trim(); var value = parts[1].trim();
const partNumber = bankInfo[8].trim(); value = (key == 'Part Number' || key == 'Manufacturer') ? hexToAscii(parts[1].trim()) : parts[1].trim();
const serialNumber = bankInfo[9].trim(); slotObj[key] = value; // Store attribute in the slot object
Memory.push({ }
DeviceLocator: "BANK " + bankIndex + "/DIMM" + dimmIndex, });
Size: size, memorySlots.push(slotObj);
Type: type, }
Speed: speed,
Status: status,
Manufacturer: hexToAscii(manufacturer),
PartNumber: hexToAscii(partNumber),
SerialNumber: serialNumber,
});
} }
}); });
memorySlots = Memory;
} else { // NEW MACS WITHOUT SLOTS } else { // NEW MACS WITHOUT SLOTS
memorySlots.push({ DeviceLocator: "Onboard Memory", Size: lines[2].split(":")[1].trim(), PartNumber: lines[3].split(":")[1].trim(), Manufacturer: lines[4].split(":")[1].trim() }) memorySlots.push({ DeviceLocator: "Onboard Memory", Size: lines[2].split(":")[1].trim(), PartNumber: lines[3].split(":")[1].trim(), Manufacturer: lines[4].split(":")[1].trim() })
} }
@ -683,12 +676,12 @@ function macos_identifiers()
trimIdentifiers(ret.identifiers); trimIdentifiers(ret.identifiers);
child = null; child = null;
return (ret); return (ret);
} }
function hexToAscii(hexString) { function hexToAscii(hexString) {
if(!hexString.startsWith('0x')) return hexString.trim();
hexString = hexString.startsWith('0x') ? hexString.slice(2) : hexString; hexString = hexString.startsWith('0x') ? hexString.slice(2) : hexString;
var str = ''; var str = '';
for (var i = 0; i < hexString.length; i += 2) { for (var i = 0; i < hexString.length; i += 2) {

View File

@ -305,9 +305,14 @@ function macos_thermals()
} }
} }
}); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); }); child.stderr.on('data', function (c) {
child.stdin.write('powermetrics -s smc\n'); if (c.toString().split('unable to get smc values').length > 1) { // error getting sensors so just kill
child.waitExit(5000); this.parent.kill();
return;
}
});
child.stdin.write('powermetrics -s smc -i 500 -n 1\n');
child.waitExit(2000);
} }
return (ret); return (ret);
} }