Add get-uptime.js
This commit is contained in:
@@ -3,9 +3,6 @@ const path = require('path');
|
|||||||
const uhk = require('./uhk');
|
const uhk = require('./uhk');
|
||||||
const device = uhk.getUhkDevice();
|
const device = uhk.getUhkDevice();
|
||||||
|
|
||||||
let programName = path.basename(process.argv[1]);
|
|
||||||
|
|
||||||
let bps = process.argv[2];
|
|
||||||
let buffer = new Buffer(uhk.pushUint32([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.i2cBaudRate]));
|
let buffer = new Buffer(uhk.pushUint32([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.i2cBaudRate]));
|
||||||
//console.log(buffer);
|
//console.log(buffer);
|
||||||
device.write(uhk.getTransferData(buffer));
|
device.write(uhk.getTransferData(buffer));
|
||||||
|
|||||||
25
packages/usb/get-uptime.js
Executable file
25
packages/usb/get-uptime.js
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const path = require('path');
|
||||||
|
const uhk = require('./uhk');
|
||||||
|
const device = uhk.getUhkDevice();
|
||||||
|
|
||||||
|
function convertMs(milliseconds) {
|
||||||
|
let days, hours, minutes, seconds;
|
||||||
|
seconds = Math.floor(milliseconds / 1000);
|
||||||
|
minutes = Math.floor(seconds / 60);
|
||||||
|
seconds = seconds % 60;
|
||||||
|
hours = Math.floor(minutes / 60);
|
||||||
|
minutes = minutes % 60;
|
||||||
|
days = Math.floor(hours / 24);
|
||||||
|
hours = hours % 24;
|
||||||
|
return {days, hours, minutes, seconds};
|
||||||
|
}
|
||||||
|
|
||||||
|
let buffer = new Buffer(uhk.pushUint32([uhk.usbCommands.getDeviceProperty, uhk.devicePropertyIds.uptime]));
|
||||||
|
//console.log(buffer);
|
||||||
|
device.write(uhk.getTransferData(buffer));
|
||||||
|
let response = device.readSync();
|
||||||
|
//console.log(Buffer.from(response));
|
||||||
|
let uptimeMs = uhk.getUint32(response, 1);
|
||||||
|
let uptime = convertMs(uptimeMs);
|
||||||
|
console.log(`Uptime: ${uptime.days}d ${String(uptime.hours).padStart(2, '0')}:${String(uptime.minutes).padStart(2, '0')}:${String(uptime.seconds).padStart(2, '0')}`)
|
||||||
@@ -124,6 +124,7 @@ exports = module.exports = moduleExports = {
|
|||||||
configSizes: 2,
|
configSizes: 2,
|
||||||
currentKbootCommand: 3,
|
currentKbootCommand: 3,
|
||||||
i2cBaudRate: 4,
|
i2cBaudRate: 4,
|
||||||
|
uptime: 5,
|
||||||
},
|
},
|
||||||
modulePropertyIds: {
|
modulePropertyIds: {
|
||||||
protocolVersions: 0,
|
protocolVersions: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user