-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.coffee
46 lines (35 loc) · 1.01 KB
/
index.coffee
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
require('source-map-support').install()
express = require('express')
app = express()
elevator = require('./elevator')
state = elevator.new_state()
app.use(express.bodyParser())
app.use(express.logger("dev"))
app.get '/reset', (req, res) ->
console.log('--- RESET ---')
state = elevator.new_state()
res.send('dtc')
app.get '/call', (req, res) ->
state = elevator.call(state, parseInt(req.param('atFloor')))
log(state)
res.send('dtc')
app.get '/go', (req, res) ->
state = elevator.call(state, parseInt(req.param('floorToGo')))
log(state)
res.send('dtc')
app.get '/userHasEntered', (req, res) ->
res.send('dtc')
app.get '/userHasExited', (req, res) ->
res.send('dtc')
app.get '/nextCommand', (req, res) ->
#UP|DOWN|OPEN|CLOSE|NOTHING
result = elevator.next(state)
state = result.state
log(state)
res.send(result.cmd)
log = (state) ->
console.log('__' + state.floor + '__')
console.log(state.path)
tcp_port = 12043
app.listen(tcp_port)
console.log("Server started on tcp/" + tcp_port )