-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrest-demo.js
51 lines (43 loc) · 1.27 KB
/
rest-demo.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
var should = require("should");
var RestClient = require("./RestClient");
console.log("START\t: rest-demo.js");
var restOptions = {
protocol: "http://",
host: "localhost",
port: "8080",
};
for (var i = 1; i < process.argv.length; i++) {
var arg = process.argv[i];
if (arg === "-h") {
(++i).should.below(process.argv.length);
restOptions.host = process.argv[i];
}
}
var rest = new RestClient(restOptions);
function step1() {
console.log("INFO\t: Step 1. Homing...");
rest.post("/firestep", [{
hom: ""
}, {
mpo: ""
}], function(data) { // http response callback
console.log("INFO\t: FPD is at position x:", data.r.mpo.x, " y:", data.r.mpo.y, " z:", data.r.mpo.z);
step2(); // do AFTER step1 is done
});
}
function step2() {
console.log("INFO\t: Step 2. Move to (50,50)...");
rest.post("/firestep", [{
mov: {
x: 50,
y: 50
}
}, {
mpo: ""
}], function(data) { // http response callback
console.log("INFO\t: FPD is at position x:", data.r.mpo.x, " y:", data.r.mpo.y, " z:", data.r.mpo.z);
});
}
step1();
// step2(); <= DANGER! we can't just put step2 here because it will run in PARALLEL!
console.log("END \t: rest-demo.js");