dial_a_device_node 0.0.153
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +674 -0
- data/README.md +94 -0
- data/Rakefile +1 -0
- data/app/assets/images/denver_summit.jpg +0 -0
- data/app/assets/images/eppendorf_innova_42.jpg +0 -0
- data/app/assets/images/heidolph.jpg +0 -0
- data/app/assets/images/ika_ret_control.jpg +0 -0
- data/app/assets/images/kern.jpg +0 -0
- data/app/assets/images/knf_rc900.jpg +0 -0
- data/app/assets/images/knf_sc920.jpg +0 -0
- data/app/assets/images/knf_simdos_02.jpg +0 -0
- data/app/assets/images/pce_balance.jpg +0 -0
- data/app/assets/images/purebeaglebone.jpg +0 -0
- data/app/assets/images/weathercape.jpg +0 -0
- data/app/assets/javascripts/dial_a_device_node/consolelogger.js +176 -0
- data/app/assets/javascripts/dial_a_device_node/deviceconnection.js +225 -0
- data/app/assets/javascripts/dial_a_device_node/devices/denver_summit.js +153 -0
- data/app/assets/javascripts/dial_a_device_node/devices/denver_summit_SIM.js +111 -0
- data/app/assets/javascripts/dial_a_device_node/devices/denver_summit_UI.js +121 -0
- data/app/assets/javascripts/dial_a_device_node/devices/eppendorf_innova_42.js +128 -0
- data/app/assets/javascripts/dial_a_device_node/devices/eppendorf_innova_42_SIM.js +66 -0
- data/app/assets/javascripts/dial_a_device_node/devices/eppendorf_innova_42_UI.js +46 -0
- data/app/assets/javascripts/dial_a_device_node/devices/heidolph.js +62 -0
- data/app/assets/javascripts/dial_a_device_node/devices/heidolph_SIM.js +24 -0
- data/app/assets/javascripts/dial_a_device_node/devices/heidolph_UI.js +17 -0
- data/app/assets/javascripts/dial_a_device_node/devices/ika_ret_control.js +192 -0
- data/app/assets/javascripts/dial_a_device_node/devices/ika_ret_control_SIM.js +233 -0
- data/app/assets/javascripts/dial_a_device_node/devices/ika_ret_control_UI.js +96 -0
- data/app/assets/javascripts/dial_a_device_node/devices/kern.js +137 -0
- data/app/assets/javascripts/dial_a_device_node/devices/kern_SIM.js +118 -0
- data/app/assets/javascripts/dial_a_device_node/devices/kern_UI.js +121 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_rc900.js +289 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_rc900_SIM.js +188 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_rc900_UI.js +179 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_sc920.js +309 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_sc920_SIM.js +298 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_sc920_UI.js +441 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_simdos_02.js +283 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_simdos_02_SIM.js +130 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_simdos_02_UI.js +188 -0
- data/app/assets/javascripts/dial_a_device_node/devices/legacy_vnc.js +106 -0
- data/app/assets/javascripts/dial_a_device_node/devices/legacy_vnc_SIM.js +32 -0
- data/app/assets/javascripts/dial_a_device_node/devices/legacy_vnc_UI.js +26 -0
- data/app/assets/javascripts/dial_a_device_node/devices/pce_balance.js +111 -0
- data/app/assets/javascripts/dial_a_device_node/devices/pce_balance_SIM.js +80 -0
- data/app/assets/javascripts/dial_a_device_node/devices/pce_balance_UI.js +69 -0
- data/app/assets/javascripts/dial_a_device_node/devices/purebeaglebone.js +286 -0
- data/app/assets/javascripts/dial_a_device_node/devices/purebeaglebone_SIM.js +13 -0
- data/app/assets/javascripts/dial_a_device_node/devices/purebeaglebone_UI.js +256 -0
- data/app/assets/javascripts/dial_a_device_node/devices/weathercape.js +75 -0
- data/app/assets/javascripts/dial_a_device_node/devices/weathercape_SIM.js +33 -0
- data/app/assets/javascripts/dial_a_device_node/devices/weathercape_UI.js +42 -0
- data/app/assets/javascripts/dial_a_device_node/folderwatcher.js +43 -0
- data/app/assets/javascripts/dial_a_device_node/helper/WebSocket-Node-wrapper.js +36 -0
- data/app/assets/javascripts/dial_a_device_node/helper/XMLHttpRequest.js +579 -0
- data/app/assets/javascripts/dial_a_device_node/helper/agent.js +125 -0
- data/app/assets/javascripts/dial_a_device_node/helper/ajax.js +300 -0
- data/app/assets/javascripts/dial_a_device_node/helper/type.js +10 -0
- data/app/assets/javascripts/dial_a_device_node/php/comport.php +49 -0
- data/app/assets/javascripts/dial_a_device_node/php/php_serial.class.php +622 -0
- data/app/assets/javascripts/dial_a_device_node/systemstatus.js +124 -0
- data/app/assets/javascripts/dial_a_device_node/webconnection.js +197 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/abstract_connection.js.coffee +45 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/channel.js.coffee +70 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/event.js.coffee +42 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/http_connection.js.coffee +89 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/websocket_connection.js.coffee +37 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/websocket_rails.js.coffee +164 -0
- data/app/views/devices/ui/_denver_summit.html.erb +52 -0
- data/app/views/devices/ui/_eppendorf_innova_42.html.erb +72 -0
- data/app/views/devices/ui/_heidolph.html.erb +54 -0
- data/app/views/devices/ui/_ika_ret_control.html.erb +81 -0
- data/app/views/devices/ui/_kern.html.erb +52 -0
- data/app/views/devices/ui/_knf_rc900.html.erb +143 -0
- data/app/views/devices/ui/_knf_sc920.html.erb +194 -0
- data/app/views/devices/ui/_knf_simdos_02.html.erb +98 -0
- data/app/views/devices/ui/_pce_balance.html.erb +37 -0
- data/app/views/devices/ui/_purebeaglebone.html.erb +137 -0
- data/app/views/devices/ui/_weathercape.html.erb +313 -0
- data/beaglebonechip.js +57 -0
- data/dial-a-device-web.js +84 -0
- data/dial_a_device_node.gemspec +23 -0
- data/dial_a_device_node.js +419 -0
- data/lib/dial_a_device_node.rb +6 -0
- data/lib/dial_a_device_node/version.rb +3 -0
- data/package.json +35 -0
- data/start.js +40 -0
- metadata +161 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
(function (exports) {
|
|
2
|
+
|
|
3
|
+
var device_model = {
|
|
4
|
+
|
|
5
|
+
filedetected: ""
|
|
6
|
+
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
var device_id;
|
|
10
|
+
|
|
11
|
+
exports.init = function (eventbus) {
|
|
12
|
+
|
|
13
|
+
if (typeof String.prototype.startsWith != 'function') {
|
|
14
|
+
String.prototype.startsWith = function (str) {
|
|
15
|
+
return this.indexOf(str) == 0;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
eventbus.on("device.heartbeat", function() {
|
|
20
|
+
|
|
21
|
+
eventbus.emit('ui.update', {
|
|
22
|
+
"component": "all",
|
|
23
|
+
"model": device_model
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
eventbus.emit('device.snapshot', device_model);
|
|
27
|
+
|
|
28
|
+
eventbus.emit("device.assumeconnected");
|
|
29
|
+
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
eventbus.on("device.announce.deviceid", function(data){
|
|
33
|
+
|
|
34
|
+
device_id = data;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
eventbus.on("device.folderwatcher_initialized", function () {
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
eventbus.emit('device.assumeconnected');
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// load all datasets
|
|
44
|
+
|
|
45
|
+
eventbus.emit("folderwatcher.start");
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function matchfile(path) {
|
|
51
|
+
|
|
52
|
+
// detect measurement locally
|
|
53
|
+
|
|
54
|
+
// load from server if not cached
|
|
55
|
+
|
|
56
|
+
// if measurement does not contain this file, upload it
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// console.log(path);
|
|
60
|
+
|
|
61
|
+
// console.log(device_id);
|
|
62
|
+
|
|
63
|
+
device_model.filedetected = path;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
eventbus.emit('ui.update', {
|
|
67
|
+
"component": "all",
|
|
68
|
+
"model": device_model
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
eventbus.on("folderwatcher.event", function(event, path){
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
var fs = require('fs');
|
|
78
|
+
|
|
79
|
+
if (event == "add") {
|
|
80
|
+
|
|
81
|
+
fs.stat(path, function(err, stats) {
|
|
82
|
+
|
|
83
|
+
if ((Date.now() - stats.atime) < 1000* 60* 60 * 24) {
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
matchfile(path);
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
eventbus.emit("device.initialized");
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
})(typeof exports == 'undefined' ? this['device'] = {} : exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
(function (exports) {
|
|
2
|
+
|
|
3
|
+
var device_model_simulation = {
|
|
4
|
+
|
|
5
|
+
filedetected: ""
|
|
6
|
+
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function pad(num, size) {
|
|
10
|
+
var s = num + "";
|
|
11
|
+
while (s.length < size) s = "0" + s;
|
|
12
|
+
return s;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
exports.init = function (eventbus) {
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
eventbus.emit("serial.simulation");
|
|
22
|
+
eventbus.emit("serial.portopened");
|
|
23
|
+
|
|
24
|
+
if (typeof String.prototype.startsWith != 'function') {
|
|
25
|
+
String.prototype.startsWith = function (str) {
|
|
26
|
+
return this.indexOf(str) == 0;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
})(typeof exports == 'undefined' ? this['simulator'] = {} : exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
(function (exports) {
|
|
2
|
+
|
|
3
|
+
var localeventbus;
|
|
4
|
+
var data;
|
|
5
|
+
|
|
6
|
+
exports.init = function (eventbus) {
|
|
7
|
+
|
|
8
|
+
localeventbus = eventbus;
|
|
9
|
+
|
|
10
|
+
if (typeof String.prototype.startsWith != 'function') {
|
|
11
|
+
String.prototype.startsWith = function (str) {
|
|
12
|
+
return this.indexOf(str) == 0;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
eventbus.on("ui.update", function (data) {
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
})(typeof exports == 'undefined' ? this['ui'] = {} : exports);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
(function (exports) {
|
|
2
|
+
|
|
3
|
+
var device_model = {
|
|
4
|
+
|
|
5
|
+
weight: ' 0.0000 g ',
|
|
6
|
+
power: 0
|
|
7
|
+
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.init = function (eventbus) {
|
|
11
|
+
|
|
12
|
+
if (typeof String.prototype.startsWith != 'function') {
|
|
13
|
+
String.prototype.startsWith = function (str) {
|
|
14
|
+
return this.indexOf(str) == 0;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
eventbus.on("device.initialized", function () {
|
|
19
|
+
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
eventbus.on("device.heartbeat", function () {
|
|
24
|
+
|
|
25
|
+
localeventbus.emit("device.command", {
|
|
26
|
+
"command": "get_weight"
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
eventbus.emit('ui.update', {
|
|
31
|
+
"component": "all",
|
|
32
|
+
"model": device_model
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
eventbus.emit('device.snapshot', device_model);
|
|
36
|
+
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
eventbus.on("device.command", function (data) {
|
|
41
|
+
|
|
42
|
+
if (data.command == "get_weight") {
|
|
43
|
+
|
|
44
|
+
eventbus.emit("serial.immediatecommand", "Sx1");
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (data.command == "power") {
|
|
49
|
+
|
|
50
|
+
eventbus.emit("serial.immediatecommand", "SS");
|
|
51
|
+
|
|
52
|
+
if (device_model.power == 1) {
|
|
53
|
+
|
|
54
|
+
device_model.power = 0;
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (data.command == "tare") {
|
|
61
|
+
|
|
62
|
+
eventbus.emit("serial.immediatecommand", "ST");
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if (data.command == "print") {
|
|
68
|
+
|
|
69
|
+
eventbus.emit("serial.immediacommand", "SP");
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
eventbus.on("device.reply", function (lastmessage, data) {
|
|
78
|
+
|
|
79
|
+
eventbus.emit('device.assumeconnected');
|
|
80
|
+
|
|
81
|
+
if (lastmessage.startsWith('heartbeat')) {
|
|
82
|
+
|
|
83
|
+
if (data == "MT") {
|
|
84
|
+
|
|
85
|
+
} else if (data == "MS") {
|
|
86
|
+
|
|
87
|
+
} else if (data == "MZ") {
|
|
88
|
+
|
|
89
|
+
} else {
|
|
90
|
+
|
|
91
|
+
device_model.weight = data;
|
|
92
|
+
|
|
93
|
+
device_model.power = 1;
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
eventbus.emit('ui.update', {
|
|
99
|
+
"component": "all",
|
|
100
|
+
"model": device_model
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
eventbus.emit('device.snapshot', device_model);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
})(typeof exports == 'undefined' ? this['device'] = {} : exports);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
(function (exports) {
|
|
2
|
+
|
|
3
|
+
var device_model_simulation = {
|
|
4
|
+
|
|
5
|
+
weight: " 0.166 g ",
|
|
6
|
+
power: 1
|
|
7
|
+
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function pad(num, size) {
|
|
11
|
+
var s = num + "";
|
|
12
|
+
while (s.length < size) s = "0" + s;
|
|
13
|
+
return s;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
exports.init = function (eventbus) {
|
|
19
|
+
|
|
20
|
+
setInterval(function () {
|
|
21
|
+
|
|
22
|
+
eventbus.emit('ui.update', {
|
|
23
|
+
"component": "all",
|
|
24
|
+
"model": device_model_simulation
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
eventbus.emit('device.snapshot', device_model_simulation);
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
}, 1000);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
eventbus.emit("serial.simulation");
|
|
34
|
+
eventbus.emit("serial.portopened");
|
|
35
|
+
|
|
36
|
+
if (typeof String.prototype.startsWith != 'function') {
|
|
37
|
+
String.prototype.startsWith = function (str) {
|
|
38
|
+
return this.indexOf(str) == 0;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
eventbus.on("device.command", function (data) {
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if (data.command == "power") {
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if (device_model_simulation.power == 1) {
|
|
50
|
+
|
|
51
|
+
device_model_simulation.power = 0;
|
|
52
|
+
|
|
53
|
+
} else {
|
|
54
|
+
|
|
55
|
+
device_model_simulation.power = 1;
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (data.command == "tare") {
|
|
62
|
+
|
|
63
|
+
device_model_simulation.weight = " 0.000 g ";
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if (data.command == "print") {
|
|
69
|
+
|
|
70
|
+
device_model_simulation.weight = " 0.166 g ";
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
})(typeof exports == 'undefined' ? this['simulator'] = {} : exports);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
(function (exports) {
|
|
2
|
+
|
|
3
|
+
var localeventbus;
|
|
4
|
+
var data;
|
|
5
|
+
|
|
6
|
+
exports.init = function (eventbus) {
|
|
7
|
+
|
|
8
|
+
localeventbus = eventbus;
|
|
9
|
+
|
|
10
|
+
if (typeof String.prototype.startsWith != 'function') {
|
|
11
|
+
String.prototype.startsWith = function (str) {
|
|
12
|
+
return this.indexOf(str) == 0;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
eventbus.on("ui.update", function (data) {
|
|
18
|
+
|
|
19
|
+
if (data.model.power == 1) {
|
|
20
|
+
|
|
21
|
+
document.getElementById("iDisplay").innerHTML = data.model.weight;
|
|
22
|
+
} else {
|
|
23
|
+
|
|
24
|
+
document.getElementById("iDisplay").innerHTML = "---";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
switch (data.model.power) {
|
|
29
|
+
|
|
30
|
+
case 0:
|
|
31
|
+
$('#powerbutton').removeClass('active');
|
|
32
|
+
break;
|
|
33
|
+
case 1:
|
|
34
|
+
$('#powerbutton').addClass('active');
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// code for changing the power status either on/off
|
|
43
|
+
exports.togglepower = function togglepower() {
|
|
44
|
+
|
|
45
|
+
localeventbus.emit("ui.command", {
|
|
46
|
+
"command": "power"
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// code for changing to the tare button i.e tare function is called
|
|
52
|
+
exports.tare = function tare() {
|
|
53
|
+
localeventbus.emit("ui.command", {
|
|
54
|
+
"command": "tare"
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// code for changing to the print function i.e print function is called
|
|
60
|
+
exports.print = function print() {
|
|
61
|
+
|
|
62
|
+
localeventbus.emit("ui.command", {
|
|
63
|
+
"command": "print"
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
})(typeof exports == 'undefined' ? this['ui'] = {} : exports);
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
(function (exports) {
|
|
2
|
+
|
|
3
|
+
function hex2a(hexx) {
|
|
4
|
+
var hex = hexx.toString();//force conversion
|
|
5
|
+
var str = '';
|
|
6
|
+
for (var i = 0; i < hex.length; i += 2)
|
|
7
|
+
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
|
|
8
|
+
return str;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
var device_model = {
|
|
12
|
+
|
|
13
|
+
customui: "",
|
|
14
|
+
bbplatform: [],
|
|
15
|
+
lastserialmessage: "",
|
|
16
|
+
usrled0: '0',
|
|
17
|
+
usrled1: '0',
|
|
18
|
+
usrled2: '0',
|
|
19
|
+
usrled3: '0',
|
|
20
|
+
serialstatus: false,
|
|
21
|
+
serialport: "",
|
|
22
|
+
serialbaud: "",
|
|
23
|
+
serialdatabit: 8,
|
|
24
|
+
serialparity: "none",
|
|
25
|
+
serialstopbit: 1,
|
|
26
|
+
seriallinebreak: hex2a('0D'),
|
|
27
|
+
serialsuffix: hex2a('0D'),
|
|
28
|
+
serialprefix: ""
|
|
29
|
+
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.init = function (eventbus) {
|
|
33
|
+
|
|
34
|
+
if (typeof String.prototype.startsWith != 'function') {
|
|
35
|
+
String.prototype.startsWith = function (str) {
|
|
36
|
+
return this.indexOf(str) == 0;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
eventbus.on("device.initialized", function () {
|
|
41
|
+
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
eventbus.on("device.heartbeat", function () {
|
|
46
|
+
|
|
47
|
+
var b = require('bonescript');
|
|
48
|
+
|
|
49
|
+
// device_model.bbplatform = b.getPlatform();
|
|
50
|
+
|
|
51
|
+
eventbus.emit('ui.update', {
|
|
52
|
+
"component": "bbplatform",
|
|
53
|
+
"model": device_model
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
eventbus.emit('device.assumeconnected');
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
eventbus.on("device.command", function (data) {
|
|
62
|
+
|
|
63
|
+
if (data.command == "retrievecustomui") {
|
|
64
|
+
|
|
65
|
+
var b = require('bonescript');
|
|
66
|
+
|
|
67
|
+
b.readTextFile('/var/lib/cloud9/customui.txt', function(x) {
|
|
68
|
+
|
|
69
|
+
if ((x.data != null) && (x.data.length != 0)) {
|
|
70
|
+
|
|
71
|
+
device_model.customui = x.data;
|
|
72
|
+
|
|
73
|
+
eventbus.emit('ui.update', {
|
|
74
|
+
"component": "bbplatform",
|
|
75
|
+
"model": device_model
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
device_model.customui = "";
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (data.command == "setled") {
|
|
87
|
+
|
|
88
|
+
var b = require('bonescript');
|
|
89
|
+
|
|
90
|
+
b.pinMode(data.led, b.OUTPUT);
|
|
91
|
+
b.digitalWrite(data.led, data.value);
|
|
92
|
+
|
|
93
|
+
if (data.led == "USR0") {
|
|
94
|
+
device_model.usrled0 = data.value
|
|
95
|
+
}
|
|
96
|
+
if (data.led == "USR1") {
|
|
97
|
+
device_model.usrled1 = data.value
|
|
98
|
+
}
|
|
99
|
+
if (data.led == "USR2") {
|
|
100
|
+
device_model.usrled2 = data.value
|
|
101
|
+
}
|
|
102
|
+
if (data.led == "USR3") {
|
|
103
|
+
device_model.usrled3 = data.value
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (data.command == "sendserial") {
|
|
108
|
+
|
|
109
|
+
localeventbus.emit("serial.immediatecommand", data.value);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (data.command == "sendraw") {
|
|
113
|
+
|
|
114
|
+
localeventbus.emit("serial.sendraw", data.value);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (data.command == "serialsetport") {
|
|
118
|
+
|
|
119
|
+
localeventbus.emit("serial.set.port", data.value);
|
|
120
|
+
|
|
121
|
+
device_model.serialport = data.value;
|
|
122
|
+
|
|
123
|
+
eventbus.emit('ui.update', {
|
|
124
|
+
"component": "all",
|
|
125
|
+
"model": device_model
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (data.command == "serialsetdatabit") {
|
|
131
|
+
|
|
132
|
+
localeventbus.emit("serial.set.databit", data.value);
|
|
133
|
+
|
|
134
|
+
device_model.serialdatabit = data.value;
|
|
135
|
+
|
|
136
|
+
eventbus.emit('ui.update', {
|
|
137
|
+
"component": "all",
|
|
138
|
+
"model": device_model
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (data.command == "serialsetparity") {
|
|
144
|
+
|
|
145
|
+
localeventbus.emit("serial.set.parity", data.value);
|
|
146
|
+
|
|
147
|
+
device_model.serialparity = data.value;
|
|
148
|
+
|
|
149
|
+
eventbus.emit('ui.update', {
|
|
150
|
+
"component": "all",
|
|
151
|
+
"model": device_model
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (data.command == "serialsetstopbit") {
|
|
157
|
+
|
|
158
|
+
localeventbus.emit("serial.set.stopbit", data.value);
|
|
159
|
+
|
|
160
|
+
device_model.serialstopbit = data.value;
|
|
161
|
+
|
|
162
|
+
eventbus.emit('ui.update', {
|
|
163
|
+
"component": "all",
|
|
164
|
+
"model": device_model
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (data.command == "serialsetbaud") {
|
|
170
|
+
|
|
171
|
+
localeventbus.emit("serial.set.baud", parseInt(data.value));
|
|
172
|
+
|
|
173
|
+
device_model.serialbaud = data.value;
|
|
174
|
+
|
|
175
|
+
eventbus.emit('ui.update', {
|
|
176
|
+
"component": "all",
|
|
177
|
+
"model": device_model
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (data.command == "serialsetlinebreak") {
|
|
182
|
+
|
|
183
|
+
localeventbus.emit("serial.set.linebreak", data.value);
|
|
184
|
+
|
|
185
|
+
device_model.seriallinebreak = data.value;
|
|
186
|
+
|
|
187
|
+
eventbus.emit('ui.update', {
|
|
188
|
+
"component": "all",
|
|
189
|
+
"model": device_model
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (data.command == "serialsetprefix") {
|
|
194
|
+
|
|
195
|
+
localeventbus.emit("serial.set.prefix", data.value);
|
|
196
|
+
|
|
197
|
+
device_model.serialprefix = data.value;
|
|
198
|
+
|
|
199
|
+
eventbus.emit('ui.update', {
|
|
200
|
+
"component": "all",
|
|
201
|
+
"model": device_model
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (data.command == "serialsetsuffix") {
|
|
206
|
+
|
|
207
|
+
localeventbus.emit("serial.set.suffix", data.value);
|
|
208
|
+
|
|
209
|
+
device_model.serialsuffix = data.value;
|
|
210
|
+
|
|
211
|
+
eventbus.emit('ui.update', {
|
|
212
|
+
"component": "all",
|
|
213
|
+
"model": device_model
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (data.command == "serialopen") {
|
|
218
|
+
|
|
219
|
+
localeventbus.emit("serial.connect", data.value);
|
|
220
|
+
|
|
221
|
+
eventbus.emit('ui.update', {
|
|
222
|
+
"component": "all",
|
|
223
|
+
"model": device_model
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (data.command == "serialclose") {
|
|
228
|
+
|
|
229
|
+
localeventbus.emit("serial.close", data.value);
|
|
230
|
+
|
|
231
|
+
eventbus.emit('ui.update', {
|
|
232
|
+
"component": "all",
|
|
233
|
+
"model": device_model
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
eventbus.on("serial.portopened", function(port, baud) {
|
|
240
|
+
|
|
241
|
+
device_model.serialstatus = true;
|
|
242
|
+
device_model.serialport = port;
|
|
243
|
+
device_model.serialbaud = baud;
|
|
244
|
+
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
eventbus.on("serial.portclosed", function(port) {
|
|
248
|
+
|
|
249
|
+
device_model.serialstatus = false;
|
|
250
|
+
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
eventbus.on("serial.retrieve", function (data) {
|
|
254
|
+
|
|
255
|
+
device_model.lastserialmessage = data;
|
|
256
|
+
|
|
257
|
+
eventbus.emit('ui.update', {
|
|
258
|
+
"component": "all",
|
|
259
|
+
"model": device_model
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
device_model.lastserialmessage = "";
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
eventbus.on("serial.rawretrieve", function (data) {
|
|
268
|
+
|
|
269
|
+
device_model.lastserialmessage = data;
|
|
270
|
+
|
|
271
|
+
eventbus.emit('ui.update', {
|
|
272
|
+
"component": "all",
|
|
273
|
+
"model": device_model
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
device_model.lastserialmessage = "";
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
eventbus.emit("device.initialized");
|
|
282
|
+
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
})(typeof exports == 'undefined' ? this['device'] = {} : exports);
|