forked from jsolderitsch/tello-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTelloCommandLine.js
57 lines (43 loc) · 1.21 KB
/
TelloCommandLine.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
/*
Based On
Rzye Tello
Scratch Ext 1.0.0.0
http://www.ryzerobotics.com
1/1/2018
*/
const readline = require('readline'),
rl = readline.createInterface(process.stdin, process.stdout),
prefix = 'Tello> ';
var PORT = 8889;
var HOST = '192.168.10.1';
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.bind(8001);
client.on('message', (msg,info) => {
console.log('Data received from server : ' + msg.toString());
rl.prompt();
});
console.log('---------------------------------------');
console.log('Tello Command Console');
console.log('---------------------------------------');
rl.on('line', (input) => {
commandStr = input.trim();
switch(commandStr) {
case 'quit':
client.close();
rl.close();
break;
default:
console.log(`Command: ${commandStr}`);
client.send(commandStr, 0, commandStr.length, PORT, HOST, function(err, bytes) {
if (err) throw err;
});
break;
}
}).on('close', function() {
console.log('Exiting Command Line Processor');
process.exit(0);
});
console.log(prefix + 'Enter a Tello SDK Command.');
rl.setPrompt(prefix, prefix.length);
rl.prompt();