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,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Real keep-alive HTTP agent
|
|
3
|
+
*
|
|
4
|
+
* The http module's agent implementation only keeps the underlying TCP
|
|
5
|
+
* connection alive, if there are pending requests towards that endpoint in the agent
|
|
6
|
+
* queue. (Not bug, but "feature": https://github.com/joyent/node/issues/1958)
|
|
7
|
+
*
|
|
8
|
+
* You might be in a situation, where you send requests one-by-one, so closing
|
|
9
|
+
* the connection every time simply does not make sense, since you know you will
|
|
10
|
+
* send the next one in a matter of milliseconds.
|
|
11
|
+
*
|
|
12
|
+
* This module provides a modified Agent implementation that does exactly that.
|
|
13
|
+
*
|
|
14
|
+
* TODO: The implementation lacks connection closing: there is no timeout for terminating
|
|
15
|
+
* the connections.
|
|
16
|
+
*
|
|
17
|
+
* http://atimb.me
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
var util = require('util');
|
|
21
|
+
var EventEmitter = require('events').EventEmitter;
|
|
22
|
+
var net = require('net');
|
|
23
|
+
|
|
24
|
+
var Agent = function(options) {
|
|
25
|
+
var self = this;
|
|
26
|
+
self.options = options || {};
|
|
27
|
+
self.requests = {};
|
|
28
|
+
self.sockets = {};
|
|
29
|
+
self.unusedSockets = {};
|
|
30
|
+
self.maxSockets = self.options.maxSockets || Agent.defaultMaxSockets;
|
|
31
|
+
self.on('free', function(socket, host, port) {
|
|
32
|
+
var name = host + ':' + port;
|
|
33
|
+
if (self.requests[name] && self.requests[name].length) {
|
|
34
|
+
self.requests[name].shift().onSocket(socket);
|
|
35
|
+
} else {
|
|
36
|
+
// If there are no pending requests just destroy the
|
|
37
|
+
// socket and it will get removed from the pool. This
|
|
38
|
+
// gets us out of timeout issues and allows us to
|
|
39
|
+
// default to Connection:keep-alive.
|
|
40
|
+
//socket.destroy();
|
|
41
|
+
if (!self.unusedSockets[name]) {
|
|
42
|
+
self.unusedSockets[name] = [];
|
|
43
|
+
}
|
|
44
|
+
self.unusedSockets[name].push(socket);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
self.createConnection = net.createConnection;
|
|
48
|
+
}
|
|
49
|
+
util.inherits(Agent, EventEmitter);
|
|
50
|
+
|
|
51
|
+
Agent.defaultMaxSockets = 5;
|
|
52
|
+
|
|
53
|
+
Agent.prototype.defaultPort = 80;
|
|
54
|
+
Agent.prototype.addRequest = function(req, host, port) {
|
|
55
|
+
var name = host + ':' + port;
|
|
56
|
+
if (this.unusedSockets[name] && this.unusedSockets[name].length) {
|
|
57
|
+
req.onSocket(this.unusedSockets[name].shift());
|
|
58
|
+
//if (!this.unusedSockets[name].length) {
|
|
59
|
+
// delete this.unusedSockets[name];
|
|
60
|
+
//}
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!this.sockets[name]) {
|
|
64
|
+
this.sockets[name] = [];
|
|
65
|
+
}
|
|
66
|
+
if (this.sockets[name].length < this.maxSockets) {
|
|
67
|
+
// If we are under maxSockets create a new one.
|
|
68
|
+
req.onSocket(this.createSocket(name, host, port));
|
|
69
|
+
} else {
|
|
70
|
+
// We are over limit so we'll add it to the queue.
|
|
71
|
+
if (!this.requests[name]) {
|
|
72
|
+
this.requests[name] = [];
|
|
73
|
+
}
|
|
74
|
+
this.requests[name].push(req);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
Agent.prototype.createSocket = function(name, host, port) {
|
|
78
|
+
var self = this;
|
|
79
|
+
var s = self.createConnection(port, host, self.options);
|
|
80
|
+
if (!self.sockets[name]) {
|
|
81
|
+
self.sockets[name] = [];
|
|
82
|
+
}
|
|
83
|
+
this.sockets[name].push(s);
|
|
84
|
+
var onFree = function() {
|
|
85
|
+
self.emit('free', s, host, port);
|
|
86
|
+
}
|
|
87
|
+
s.on('free', onFree);
|
|
88
|
+
var onClose = function(err) {
|
|
89
|
+
// This is the only place where sockets get removed from the Agent.
|
|
90
|
+
// If you want to remove a socket from the pool, just close it.
|
|
91
|
+
// All socket errors end in a close event anyway.
|
|
92
|
+
self.removeSocket(s, name, host, port);
|
|
93
|
+
}
|
|
94
|
+
s.on('close', onClose);
|
|
95
|
+
var onRemove = function() {
|
|
96
|
+
// We need this function for cases like HTTP "upgrade"
|
|
97
|
+
// (defined by WebSockets) where we need to remove a socket from the pool
|
|
98
|
+
// because it'll be locked up indefinitely
|
|
99
|
+
self.removeSocket(s, name, host, port);
|
|
100
|
+
s.removeListener('close', onClose);
|
|
101
|
+
s.removeListener('free', onFree);
|
|
102
|
+
s.removeListener('agentRemove', onRemove);
|
|
103
|
+
}
|
|
104
|
+
s.on('agentRemove', onRemove);
|
|
105
|
+
return s;
|
|
106
|
+
};
|
|
107
|
+
Agent.prototype.removeSocket = function(s, name, host, port) {
|
|
108
|
+
if (this.sockets[name]) {
|
|
109
|
+
var index = this.sockets[name].indexOf(s);
|
|
110
|
+
if (index !== -1) {
|
|
111
|
+
this.sockets[name].splice(index, 1);
|
|
112
|
+
}
|
|
113
|
+
} else if (this.sockets[name] && this.sockets[name].length === 0) {
|
|
114
|
+
// don't leak
|
|
115
|
+
delete this.sockets[name];
|
|
116
|
+
delete this.requests[name];
|
|
117
|
+
}
|
|
118
|
+
if (this.requests[name] && this.requests[name].length) {
|
|
119
|
+
// If we have pending requests and a socket gets closed a new one
|
|
120
|
+
// needs to be created to take over in the pool for the one that closed.
|
|
121
|
+
this.createSocket(name, host, port).emit('free');
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
module.exports = Agent;
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
var x = require('./XMLHttpRequest.js');
|
|
2
|
+
|
|
3
|
+
require('./type.js');
|
|
4
|
+
|
|
5
|
+
var jsonpID = 0,
|
|
6
|
+
document = global.document,
|
|
7
|
+
key,
|
|
8
|
+
name,
|
|
9
|
+
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
10
|
+
scriptTypeRE = /^(?:text|application)\/javascript/i,
|
|
11
|
+
xmlTypeRE = /^(?:text|application)\/xml/i,
|
|
12
|
+
jsonType = 'application/json',
|
|
13
|
+
htmlType = 'text/html',
|
|
14
|
+
blankRE = /^\s*$/
|
|
15
|
+
|
|
16
|
+
var ajax = module.exports = function (options) {
|
|
17
|
+
var settings = extend({}, options || {})
|
|
18
|
+
for (key in ajax.settings) if (settings[key] === undefined) settings[key] = ajax.settings[key]
|
|
19
|
+
|
|
20
|
+
ajaxStart(settings)
|
|
21
|
+
|
|
22
|
+
if (!settings.crossDomain) settings.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) && RegExp.$2 != 'www.dial-a-device.com'
|
|
23
|
+
|
|
24
|
+
var dataType = settings.dataType,
|
|
25
|
+
hasPlaceholder = /=\?/.test(settings.url)
|
|
26
|
+
if (dataType == 'jsonp' || hasPlaceholder) {
|
|
27
|
+
if (!hasPlaceholder) settings.url = appendQuery(settings.url, 'callback=?')
|
|
28
|
+
return ajax.JSONP(settings)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
serializeData(settings)
|
|
33
|
+
|
|
34
|
+
var mime = settings.accepts[dataType],
|
|
35
|
+
baseHeaders = {},
|
|
36
|
+
protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : "http",
|
|
37
|
+
xhr = ajax.settings.xhr(),
|
|
38
|
+
abortTimeout
|
|
39
|
+
|
|
40
|
+
if (!settings.crossDomain) baseHeaders['X-Requested-With'] = 'XMLHttpRequest'
|
|
41
|
+
if (mime) {
|
|
42
|
+
baseHeaders['Accept'] = mime
|
|
43
|
+
if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0]
|
|
44
|
+
xhr.overrideMimeType && xhr.overrideMimeType(mime)
|
|
45
|
+
}
|
|
46
|
+
settings.contentType = 'application/x-www-form-urlencoded; charset=UTF-8'
|
|
47
|
+
if (settings.contentType || (settings.data && settings.type.toUpperCase() != 'GET')) baseHeaders['Content-Type'] = (settings.contentType || 'application/x-www-form-urlencoded')
|
|
48
|
+
settings.headers = extend(baseHeaders, settings.headers || {})
|
|
49
|
+
|
|
50
|
+
xhr.onreadystatechange = function () {
|
|
51
|
+
if (xhr.readyState == 4) {
|
|
52
|
+
clearTimeout(abortTimeout)
|
|
53
|
+
var result, error = false
|
|
54
|
+
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) {
|
|
55
|
+
dataType = dataType || mimeToDataType(xhr.getResponseHeader('content-type'))
|
|
56
|
+
result = xhr.responseText
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
if (dataType == 'script')(1, eval)(result)
|
|
60
|
+
else if (dataType == 'xml') result = xhr.responseXML
|
|
61
|
+
else if (dataType == 'json') result = blankRE.test(result) ? null : JSON.parse(result)
|
|
62
|
+
} catch (e) {
|
|
63
|
+
error = e
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (error) ajaxError(error, 'parsererror', xhr, settings)
|
|
67
|
+
else ajaxSuccess(result, xhr, settings)
|
|
68
|
+
} else {
|
|
69
|
+
ajaxError(null, 'error', xhr, settings)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
var async = 'async' in settings ? settings.async : true
|
|
75
|
+
xhr.open(settings.type, settings.url, async)
|
|
76
|
+
|
|
77
|
+
for (name in settings.headers) xhr.setRequestHeader(name, settings.headers[name])
|
|
78
|
+
|
|
79
|
+
if (ajaxBeforeSend(xhr, settings) === false) {
|
|
80
|
+
xhr.abort()
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (settings.timeout > 0) abortTimeout = setTimeout(function () {
|
|
85
|
+
xhr.onreadystatechange = empty
|
|
86
|
+
xhr.abort()
|
|
87
|
+
ajaxError(null, 'timeout', xhr, settings)
|
|
88
|
+
}, settings.timeout)
|
|
89
|
+
|
|
90
|
+
// avoid sending empty string (#319)
|
|
91
|
+
|
|
92
|
+
xhr.send(settings.data ? settings.data : null)
|
|
93
|
+
return xhr
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
// trigger a custom event and return false if it was cancelled
|
|
98
|
+
function triggerAndReturn(context, eventName, data) {
|
|
99
|
+
//todo: Fire off some events
|
|
100
|
+
//var event = $.Event(eventName)
|
|
101
|
+
//$(context).trigger(event, data)
|
|
102
|
+
return true; //!event.defaultPrevented
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// trigger an Ajax "global" event
|
|
106
|
+
function triggerGlobal(settings, context, eventName, data) {
|
|
107
|
+
if (settings.global) return triggerAndReturn(context || document, eventName, data)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Number of active Ajax requests
|
|
111
|
+
ajax.active = 0
|
|
112
|
+
|
|
113
|
+
function ajaxStart(settings) {
|
|
114
|
+
if (settings.global && ajax.active++ === 0) triggerGlobal(settings, null, 'ajaxStart')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function ajaxStop(settings) {
|
|
118
|
+
if (settings.global && !(--ajax.active)) triggerGlobal(settings, null, 'ajaxStop')
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable
|
|
122
|
+
function ajaxBeforeSend(xhr, settings) {
|
|
123
|
+
var context = settings.context
|
|
124
|
+
if (settings.beforeSend.call(context, xhr, settings) === false || triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false) return false
|
|
125
|
+
|
|
126
|
+
triggerGlobal(settings, context, 'ajaxSend', [xhr, settings])
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function ajaxSuccess(data, xhr, settings) {
|
|
130
|
+
var context = settings.context,
|
|
131
|
+
status = 'success'
|
|
132
|
+
settings.success.call(context, data, status, xhr)
|
|
133
|
+
triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data])
|
|
134
|
+
ajaxComplete(status, xhr, settings)
|
|
135
|
+
}
|
|
136
|
+
// type: "timeout", "error", "abort", "parsererror"
|
|
137
|
+
function ajaxError(error, type, xhr, settings) {
|
|
138
|
+
var context = settings.context
|
|
139
|
+
settings.error.call(context, xhr, type, error)
|
|
140
|
+
triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error])
|
|
141
|
+
ajaxComplete(type, xhr, settings)
|
|
142
|
+
}
|
|
143
|
+
// status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
|
|
144
|
+
function ajaxComplete(status, xhr, settings) {
|
|
145
|
+
var context = settings.context
|
|
146
|
+
settings.complete.call(context, xhr, status)
|
|
147
|
+
triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings])
|
|
148
|
+
ajaxStop(settings)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Empty function, used as default callback
|
|
152
|
+
function empty() {}
|
|
153
|
+
|
|
154
|
+
ajax.JSONP = function (options) {
|
|
155
|
+
if (!('type' in options)) return ajax(options)
|
|
156
|
+
|
|
157
|
+
var callbackName = 'jsonp' + (++jsonpID),
|
|
158
|
+
script = document.createElement('script'),
|
|
159
|
+
abort = function () {
|
|
160
|
+
//todo: remove script
|
|
161
|
+
//$(script).remove()
|
|
162
|
+
if (callbackName in global) global[callbackName] = empty
|
|
163
|
+
ajaxComplete('abort', xhr, options)
|
|
164
|
+
},
|
|
165
|
+
xhr = {
|
|
166
|
+
abort: abort
|
|
167
|
+
}, abortTimeout
|
|
168
|
+
|
|
169
|
+
if (options.error) script.onerror = function () {
|
|
170
|
+
xhr.abort()
|
|
171
|
+
options.error()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
global[callbackName] = function (data) {
|
|
175
|
+
clearTimeout(abortTimeout)
|
|
176
|
+
//todo: remove script
|
|
177
|
+
//$(script).remove()
|
|
178
|
+
delete global[callbackName]
|
|
179
|
+
ajaxSuccess(data, xhr, options)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
serializeData(options)
|
|
183
|
+
script.src = options.url.replace(/=\?/, '=' + callbackName)
|
|
184
|
+
//tood: append to head
|
|
185
|
+
//$('head').append(script)
|
|
186
|
+
|
|
187
|
+
if (options.timeout > 0) abortTimeout = setTimeout(function () {
|
|
188
|
+
xhr.abort()
|
|
189
|
+
ajaxComplete('timeout', xhr, options)
|
|
190
|
+
}, options.timeout)
|
|
191
|
+
|
|
192
|
+
return xhr
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
ajax.settings = {
|
|
196
|
+
// Default type of request
|
|
197
|
+
type: 'GET',
|
|
198
|
+
// Callback that is executed before request
|
|
199
|
+
beforeSend: empty,
|
|
200
|
+
// Callback that is executed if the request succeeds
|
|
201
|
+
success: empty,
|
|
202
|
+
// Callback that is executed the the server drops error
|
|
203
|
+
error: empty,
|
|
204
|
+
// Callback that is executed on request complete (both: error and success)
|
|
205
|
+
complete: empty,
|
|
206
|
+
// The context for the callbacks
|
|
207
|
+
context: null,
|
|
208
|
+
// Whether to trigger "global" Ajax events
|
|
209
|
+
global: true,
|
|
210
|
+
// Transport
|
|
211
|
+
xhr: function () {
|
|
212
|
+
return new x.XMLHttpRequest()
|
|
213
|
+
},
|
|
214
|
+
// MIME types mapping
|
|
215
|
+
accepts: {
|
|
216
|
+
script: 'text/javascript, application/javascript',
|
|
217
|
+
json: jsonType,
|
|
218
|
+
xml: 'application/xml, text/xml',
|
|
219
|
+
html: htmlType,
|
|
220
|
+
text: 'text/plain'
|
|
221
|
+
},
|
|
222
|
+
// Whether the request is to another domain
|
|
223
|
+
crossDomain: false,
|
|
224
|
+
// Default timeout
|
|
225
|
+
timeout: 0
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function mimeToDataType(mime) {
|
|
229
|
+
return mime && (mime == htmlType ? 'html' : mime == jsonType ? 'json' : scriptTypeRE.test(mime) ? 'script' : xmlTypeRE.test(mime) && 'xml') || 'text'
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function appendQuery(url, query) {
|
|
233
|
+
return (url + '&' + query).replace(/[&?]{1,2}/, '?')
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// serialize payload and append it to the URL for GET requests
|
|
237
|
+
function serializeData(options) {
|
|
238
|
+
if (type(options.data) === 'object') options.data = param(options.data)
|
|
239
|
+
if (options.data && (!options.type || options.type.toUpperCase() == 'GET')) options.url = appendQuery(options.url, options.data)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
ajax.get = function (url, success) {
|
|
243
|
+
return ajax({
|
|
244
|
+
url: url,
|
|
245
|
+
success: success
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
ajax.post = function (url, data, success, dataType) {
|
|
250
|
+
if (type(data) === 'function') dataType = dataType || success, success = data, data = null
|
|
251
|
+
return ajax({
|
|
252
|
+
type: 'POST',
|
|
253
|
+
url: url,
|
|
254
|
+
data: data,
|
|
255
|
+
success: success,
|
|
256
|
+
dataType: dataType
|
|
257
|
+
})
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
ajax.getJSON = function (url, success) {
|
|
261
|
+
return ajax({
|
|
262
|
+
url: url,
|
|
263
|
+
success: success,
|
|
264
|
+
dataType: 'json'
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
var escape = encodeURIComponent
|
|
269
|
+
|
|
270
|
+
function serialize(params, obj, traditional, scope) {
|
|
271
|
+
var array = type(obj) === 'array';
|
|
272
|
+
for (var key in obj) {
|
|
273
|
+
var value = obj[key];
|
|
274
|
+
|
|
275
|
+
if (scope) key = traditional ? scope : scope + '[' + (array ? '' : key) + ']'
|
|
276
|
+
// handle data in serializeArray() format
|
|
277
|
+
if (!scope && array) params.add(value.name, value.value)
|
|
278
|
+
// recurse into nested objects
|
|
279
|
+
else if (traditional ? (type(value) === 'array') : (type(value) === 'object')) serialize(params, value, traditional, key)
|
|
280
|
+
else params.add(key, value)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function param(obj, traditional) {
|
|
285
|
+
var params = []
|
|
286
|
+
params.add = function (k, v) {
|
|
287
|
+
this.push(escape(k) + '=' + escape(v))
|
|
288
|
+
}
|
|
289
|
+
serialize(params, obj, traditional)
|
|
290
|
+
return params.join('&').replace('%20', '+')
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function extend(target) {
|
|
294
|
+
var slice = Array.prototype.slice;
|
|
295
|
+
slice.call(arguments, 1).forEach(function (source) {
|
|
296
|
+
for (key in source)
|
|
297
|
+
if (source[key] !== undefined) target[key] = source[key]
|
|
298
|
+
})
|
|
299
|
+
return target
|
|
300
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type = function (obj) {
|
|
2
|
+
return obj == null ? String(obj) : class2type[toString.call(obj)] || "object";
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
class2type = {}
|
|
6
|
+
|
|
7
|
+
var a, t = "Boolean Number String Function Array Date RegExp Object".split(" ");
|
|
8
|
+
for (a in t) {
|
|
9
|
+
class2type["[object " + t[a] + "]"] = t[a].toLowerCase();
|
|
10
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
include "php_serial.class.php";
|
|
4
|
+
header ('Content-type: text/json');
|
|
5
|
+
|
|
6
|
+
header ('Pragma: no-cache');
|
|
7
|
+
header ('Cache-Control: max-age=0');
|
|
8
|
+
|
|
9
|
+
$ser_port = "/dev/ttyUSB0";
|
|
10
|
+
if (array_key_exists("port", $_GET)) $ser_port = $_GET["port"];
|
|
11
|
+
|
|
12
|
+
$ser_baud = "9600";
|
|
13
|
+
if (array_key_exists("baudrate", $_GET)) $ser_baud = $_GET["baudrate"];
|
|
14
|
+
|
|
15
|
+
$ser_parity = "none";
|
|
16
|
+
if (array_key_exists("parity", $_GET)) $ser_parity = $_GET["parity"];
|
|
17
|
+
|
|
18
|
+
$ser_stopbits = "1";
|
|
19
|
+
if (array_key_exists("stopbits", $_GET)) $ser_stopbits = $_GET["stopbits"];
|
|
20
|
+
|
|
21
|
+
$ser_readcount = "128";
|
|
22
|
+
if (array_key_exists("readcount", $_GET)) $ser_readcount = $_GET["readcount"];
|
|
23
|
+
|
|
24
|
+
$ser_request = "pP";
|
|
25
|
+
if (array_key_exists("request", $_GET)) $ser_request = $_GET["request"];
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
$serial = new phpSerial;
|
|
29
|
+
$serial->deviceSet($ser_port);
|
|
30
|
+
$serial->confBaudRate($ser_baud);
|
|
31
|
+
$serial->confParity($ser_parity);
|
|
32
|
+
$serial->confCharacterLength(8);
|
|
33
|
+
$serial->confStopBits($ser_stopbits);
|
|
34
|
+
$serial->deviceOpen();
|
|
35
|
+
|
|
36
|
+
$serial->sendMessage($ser_request . chr(13));
|
|
37
|
+
echo "{";
|
|
38
|
+
echo "\"request\":\"" . $ser_request . "\", ";
|
|
39
|
+
echo "\"port\":\"" . $ser_port . "\", ";
|
|
40
|
+
echo "\"baudrate\":\"" . $ser_baud . "\", ";
|
|
41
|
+
echo "\"parity\":\"" . $ser_parity . "\", ";
|
|
42
|
+
echo "\"stopbits\":\"" . $ser_stopbits . "\", ";
|
|
43
|
+
echo "\"response\":\"";
|
|
44
|
+
$res = $serial->readPort($ser_readcount);
|
|
45
|
+
$res = str_replace (chr(13), "", $res);
|
|
46
|
+
echo $res;
|
|
47
|
+
echo "\"}";
|
|
48
|
+
$serial->deviceClose();
|
|
49
|
+
?>
|