1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-14 07:13:37 +00:00

1. Updated metadata for linux ipcSocket

2, Added linux-acpi, and attached events to power-monitor for linux
This commit is contained in:
Bryan Roe
2020-05-30 22:59:06 -07:00
parent 0aa17b4a61
commit b78a29eb88
4 changed files with 137 additions and 2 deletions

47
modules/linux-acpi.js Normal file
View File

@@ -0,0 +1,47 @@
/*
Copyright 2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
function linux_acpi()
{
this._ObjectID = 'linux-acpi';
require('events').EventEmitter.call(this, true)
.createEvent('acpi');
Object.defineProperty(this, "supported", { value: require('fs').existsSync('/var/run/acpid.socket') });
if(this.supported)
{
this._client = require('net').createConnection({ path: '/var/run/acpid.socket', metadata: 'linux-acpi' }, function ()
{
this.on('data', function (chunk)
{
var blocks;
var ubuffer = null;
var tokens = chunk.toString().split('\n');
if (tokens.length == 1) { this.unshift(chunk); }
if (tokens.peek() != '') { ubuffer = Buffer.from(tokens.pop()); }
else { tokens.pop(); }
for (var i in tokens)
{
blocks = tokens[i].split(' ');
this.ret.emit('acpi', { name: blocks[0], type: Buffer.from(blocks[2], 'hex').readUInt32BE(), value: Buffer.from(blocks[3], 'hex').readUInt32BE() });
}
});
});
this._client.ret = this;
}
}
module.exports = new linux_acpi();