fix mac memory and invalid smc values
Signed-off-by: si458 <simonsmith5521@gmail.com>
si458 committed
Mar 4, 2024 at 10:57 UTC
548c1b9bb453e8df7d33c0ca4639c3c2b6143b4f
2 files changed
+27
-29
agents/modules_meshcore/computer-identifiers.js
+19
-26
@@ -610,33 +610,26 @@ function macos_identifiers()
610
if(lines.length > 0) {
611
const memorySlots = [];
612
if(lines[2].trim().includes('Memory Slots:')) { // OLD MACS WITH SLOTS
613
- const Memory = [];
614
- const bankMatches = child.stdout.str.trim().match(/BANK \d+\/DIMM\d+:[\s\S]*?(?=(BANK|$))/g);
615
- bankMatches.forEach(function(match, index) {
616
- 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: (.+)/);
617
- if (bankInfo) {
618
- const bankIndex = bankInfo[1].trim();
619
- const dimmIndex = bankInfo[2].trim();
620
- const size = bankInfo[3].trim();
621
- const type = bankInfo[4].trim();
622
- const speed = bankInfo[5].trim();
623
- const status = bankInfo[6].trim();
624
- const manufacturer = bankInfo[7].trim();
625
- const partNumber = bankInfo[8].trim();
626
- const serialNumber = bankInfo[9].trim();
627
- Memory.push({
628
- DeviceLocator: "BANK " + bankIndex + "/DIMM" + dimmIndex,
629
- Size: size,
630
- Type: type,
631
- Speed: speed,
632
- Status: status,
633
- Manufacturer: hexToAscii(manufacturer),
634
- PartNumber: hexToAscii(partNumber),
635
- SerialNumber: serialNumber,
636
- });
613
+ var memorySlots1 = child.stdout.str.split(/\n{2,}/).slice(3);
614
+ memorySlots1.forEach(function(slot,index) {
615
+ var lines = slot.split('\n');
616
+ if(lines.length == 1){ // start here
617
+ if(lines[0].trim()!=''){
618
+ var slotObj = { DeviceLocator: lines[0].trim().replace(/:$/, '') }; // Initialize name as an empty string
619
+ var nextline = memorySlots1[index+1].split('\n');
620
+ nextline.forEach(function(line) {
621
+ if (line.trim() !== '') {
622
+ var parts = line.split(':');
623
+ var key = parts[0].trim();
624
+ var value = parts[1].trim();
625
+ value = (key == 'Part Number' || key == 'Manufacturer') ? hexToAscii(parts[1].trim()) : parts[1].trim();
626
+ slotObj[key] = value; // Store attribute in the slot object
627
+ }
628
+ });
629
+ memorySlots.push(slotObj);
630
+ }
631
}
632
});
639
- memorySlots = Memory;
633
} else { // NEW MACS WITHOUT SLOTS
634
memorySlots.push({ DeviceLocator: "Onboard Memory", Size: lines[2].split(":")[1].trim(), PartNumber: lines[3].split(":")[1].trim(), Manufacturer: lines[4].split(":")[1].trim() })
635
}
@@ -683,12 +676,12 @@ function macos_identifiers()
676
677
trimIdentifiers(ret.identifiers);
678
686
-
679
child = null;
680
return (ret);
681
}
682
683
function hexToAscii(hexString) {
684
+ if(!hexString.startsWith('0x')) return hexString.trim();
685
hexString = hexString.startsWith('0x') ? hexString.slice(2) : hexString;
686
var str = '';
687
for (var i = 0; i < hexString.length; i += 2) {
agents/modules_meshcore/sysinfo.js
+8
-3
@@ -305,9 +305,14 @@ function macos_thermals()
305
}
306
}
307
});
308
- child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
309
- child.stdin.write('powermetrics -s smc\n');
310
- child.waitExit(5000);
308
+ child.stderr.on('data', function (c) {
309
+ if (c.toString().split('unable to get smc values').length > 1) { // error getting sensors so just kill
310
+ this.parent.kill();
311
+ return;
312
+ }
313
+ });
314
+ child.stdin.write('powermetrics -s smc -i 500 -n 1\n');
315
+ child.waitExit(2000);
316
}
317
return (ret);
318
}