-
Notifications
You must be signed in to change notification settings - Fork 0
/
uconfig-device
40 lines (33 loc) · 943 Bytes
/
uconfig-device
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
#!/usr/bin/ucode
'use strict';
import { ulog_open, ulog, ULOG_SYSLOG, ULOG_STDIO, LOG_DAEMON } from 'log';
import * as protocol from 'uconfig.device.protocol';
import * as context from 'uconfig.device.context';
import { settings } from 'uconfig.device.settings';
import * as device from 'uconfig.device';
import * as uloop from 'uloop';
ulog_open(ULOG_SYSLOG | ULOG_STDIO, LOG_DAEMON, 'uconfig.device');
global.uconfig = {
connect: function() {
printf('connect\n');
context.connected();
protocol.connect();
},
disconnect: function() {
printf('disconnect\n');
context.disconnected();
if (context.reconnect)
global.connection.reconnect(context.reconnect);
},
receive: function(msg) {
printf('RX: %.J\n', msg);
},
};
uloop.init();
uloop.timer(30 * 1000, function() {
if (context.active)
protocol.keepalive();
return 30 * 1000;
});
global.connection = device.connect(settings.server, settings.port);
uloop.run();