-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanual-controller-interface.js
More file actions
43 lines (35 loc) · 1019 Bytes
/
manual-controller-interface.js
File metadata and controls
43 lines (35 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"use strict";
const net = require('net');
async function getStatus()
{
const resp = await issueCommand({'action': 'get-status'});
return resp;
}
function issueCommand(command)
{
return new Promise((resolve, reject) => {
const client = net.createConnection(
process.env.MANUAL_CONTROL_PORT,
'localhost',
function () {
console.log('connected');
//client.write('{\"action\": \"get-status\"}');
client.write(JSON.stringify(command))
}
);
client.on('data', function(data) {
resolve(JSON.parse(data));
});
client.on('close', function() {
console.log('connection closed');
});
});
}
module.exports.getStatus = getStatus;
module.exports.issueCommand = issueCommand;
async function tryGetStatus()
{
console.log("tryGetStatus begins");
var stat = await getStatus();
console.log(`tryGetStatus got ${JSON.stringify(stat)}`);
}