-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalib-manager-worker.js
48 lines (38 loc) · 1.18 KB
/
calib-manager-worker.js
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
43
44
45
46
47
48
const zmq = require("zeromq");
/*
CalibManagerWorker class provides an IPC link to the linuxcnc-python CalibManager via ZeroMQ (zmq)
*/
class CalibManagerWorker {
constructor(
calibProcess
) {
this.connected = false;
this.calibProcess = calibProcess;
this.calibSocket = zmq.socket("pull");
this.calibSocket.on('connectFailed', (error) => {
this.connected = false;
setTimeout(this.connect, 3000);
console.log('Calib Connect Error: ' + error.toString());
});
this.calibSocket.on('connect', (connection) => {
console.log('Calib Connection established!');
this.connected = true;
});
this.calibSocket.on("message", async (msg) => {
var calibManagerReport = JSON.parse(msg);
await this.calibProcess.receiveUpdate(calibManagerReport);
});
this.calibSocket.on('close', (reasonCode, description) => {
this.connected = false;
console.log('Calib ZMQ connection closed: ' + description.toString());
});
}
connect() {
console.log('attempting connect calib')
this.calibSocket.connect('ipc:///tmp/cmm');
console.log('after connect calib')
}
}
module.exports = {
CalibManagerWorker
};