-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
121 lines (107 loc) · 3.06 KB
/
index.js
File metadata and controls
121 lines (107 loc) · 3.06 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const { text } = require('express');
const express = require('express');
var app = express();
const port = 3000;
let arms = [];
app.use('/public', express.static(process.cwd() + '/public'));
app.get('/call/:id', (req, res) => {
let isArmExists = false;
let targetArm;
arms.forEach(arm => {
if (arm.id == req.params.id) {
isArmExists = true;
targetArm = arm
}
});
if (isArmExists) {
// if (targetArm.status == "idle") {
// targetArm.status = "move";
// res.send(`called arm with id ${req.params.id}`);
// } else {
// res.send(`arm with id ${req.params.id} is busy`);
// }
switch (targetArm.status) {
case "idling": {
targetArm.status = "move";
res.send({"msg": `called arm to move`});
};
break;
case "move": {
res.send({"msg": `waiting arm to be moving`});
};
break;
case "moving": {
res.send({"msg": `arm is still moving`});
};
break;
default: {
res.send({"msg": `error call`});
}
}
} else {
let newArm = { "id": req.params.id, "status": "move" };
arms.push(newArm);
res.send(`pushed and called new arm with id ${req.params.id}`);
}
})
app.get('/check/:id', (req, res) => {
let isArmExists = false;
let targetArm;
arms.forEach(arm => {
if (arm.id == req.params.id) {
isArmExists = true;
targetArm = arm
}
});
if (isArmExists) {
// if(targetArm.status == "move"){
// targetArm.status = "moving";
// res.send("move");
// }
// if(targetArm.status == "moving"){
// targetArm.status = "moving";
// res.send("move");
// }
// if(targetArm.status == "idle") {
// res.send("idle");
// }
// if (true) {
// res.send("error");
// }
switch (targetArm.status) {
case "idling": {
res.send({"msg": "idle"});
};
break;
case "move": {
targetArm.status = "moving";
res.send({"msg": "move"});
};
break;
case "moving": {
targetArm.status = "idling";
res.send({"msg": "idle"});
};
break;
default: {
res.send(`error check`);
}
}
} else {
res.send("no such arm");
}
})
app.get('/debug', (req, res) => {
// let text = "";
// arms.forEach(arm => {
// text += arm.id + " : " + arm.status + "\n";
// });
// res.send(text + "\n end");
res.send(arms);
})
app.get('/' , (req , res)=>{
res.sendFile(process.cwd() + '/views/index.html');
})
app.listen(process.env.PORT || port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})