forked from rt-net/stack-chan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.js
50 lines (49 loc) · 1.19 KB
/
mod.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
import MDNS from 'mdns'
import Timer from 'timer'
let initialized = false
function onRobotCreated(robot) {
const mdns = new MDNS(
{
hostName: 'stackchan',
},
function (message, value) {
switch (message) {
case 1:
if (value !== '') {
trace(`MDNS - connection successful. claimed hostname is "${value}"\n`)
mdns.add({
name: 'http',
protocol: 'tcp',
port: 80,
txt: {
yaw: '0.0',
pitch: '0.0',
},
})
initialized = true
}
break
case 2:
trace(`MDNS - failed to claim "${value}", try next\n`)
break
default:
if (message < 0) trace('MDNS - failed to claim, give up\n')
break
}
}
)
Timer.repeat(() => {
let yaw = robot.pose.body.rotation.y
let pitch = robot.pose.body.rotation.p
if (initialized && mdns.services.length > 0) {
let service = mdns.services[0]
service.txt['yaw'] = yaw
service.txt['pitch'] = pitch
mdns.update(service)
}
}, 100)
}
export default {
onRobotCreated,
autoLoop: false,
}