/
process.js
62 lines (54 loc) · 2.11 KB
/
process.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var app = require('express')(),
http = require('http').createServer(app),
bodyParser = require('body-parser').json({ strict: false });
const Station = require('./station');
const sockets = require('./index');
var procStat = new Station("Processing Station", "192.168.3.60", 3006);
procStat.getEvents(['rotateE','partAvE','atRubE','atTestE','inPositionE','wkpcOKE', 'testingE']);
procStat.subscribe()
procStat.runServer = function(){
var ref = this;
app.use(bodyParser);
app.post('/', function(req, res){
let id = req.body.eventID;
/*clearTimeout(idle)
ref.light('Amber', false) //no amber light
idle = setTimeout(() => ref.light('Amber', true), 300000)*/
switch (id) {
case ('rotate'):
sockets.procSocket.emit('rotate', req.body.status)
break;
case ('partAv'):
sockets.procSocket.emit('partAv', req.body.status)
break;
case ('atRub'):
sockets.procSocket.emit('atRub', req.body.status)
break;
case ('atTest'):
sockets.procSocket.emit('atTest', req.body.status)
break;
case ('inPosition'):
sockets.procSocket.emit(id, req.body.status)
break
case ('wkpcOK'):
sockets.procSocket.emit('wkpcOK', req.body.status)
break;
case ('testing'):
sockets.procSocket.emit('testing', req.body.status)
case ('rubUp')://doesnt work. bad device
sockets.procSocket.emit('rubIsUp', req.body.status)
break;
case ('rubDown'): //doesnt work, bad device
sockets.procSocket.emit('rubIsDown', req.body.status)
break;
default:
break;
}
res.end()
})
http.listen(ref.eventPort, function() {
console.log(ref.name, ': listening on port', ref.eventPort);
});
}
//let idle = setTimeout(() => procStat.light('Amber', true), 300000) //no amber light
module.exports = {procStat}