From 6f6d8349c8f697534ccc1891099716ed57313cd1 Mon Sep 17 00:00:00 2001 From: Vaishnav M A Date: Sat, 9 Jun 2018 23:19:45 +0530 Subject: [PATCH 01/13] Support nodestyle callbacks (#8) * support node-style callbacks based on callback.length * fix digitalRead() on AIN * fix digitalRead on AIN --- src/hw_mainline.js | 27 +++++-- src/index.js | 171 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 159 insertions(+), 39 deletions(-) diff --git a/src/hw_mainline.js b/src/hw_mainline.js index 28f3ca8b..494f356f 100644 --- a/src/hw_mainline.js +++ b/src/hw_mainline.js @@ -62,17 +62,26 @@ var readPinMux = function (pin, mode, callback) { if (err) { mode.err = 'readPinctrl error: ' + err; if (debug) winston.debug(mode.err); - callback(mode); + if (callback.length == 1) + callback(mode); + else + callback(err, data); } mode = parse.modeFromPinctrl(data, muxRegOffset, 0x44e10800, mode); - callback(mode); + if (callback.length == 1) + callback(mode); + else + callback(null, mode); }; var tryPinctrl = function (exists) { if (exists) { fs.readFile(pinctrlFile, 'utf8', readPinctrl); } else { if (debug) winston.debug('getPinMode(' + pin.key + '): no valid mux data'); - callback(mode); + if (callback.length == 1) + callback(mode); + else + callback('getPinMode(' + pin.key + '): no valid mux data', mode); } }; if (callback) { @@ -223,7 +232,10 @@ var readGPIOValue = function (pin, resp, callback) { winston.error(resp.err); } resp.value = parseInt(data, 2); - callback(resp); + if (callback.length == 1) + callback(resp); + else + callback(resp.err, resp.value); }; fs.readFile(gpioFile, readFile); return (true); @@ -259,7 +271,10 @@ var readAIN = function (pin, resp, callback) { winston.error(resp.err); } resp.value = parseInt(data, 10) / maxValue; - callback(resp); + if (callback.length == 1) + callback(resp); + else + callback(resp.err, resp.value); }; fs.readFile(ainFile, readFile); return (resp); @@ -337,7 +352,7 @@ var writePWMFreqAndValue = function (pin, pwm, freq, value, resp, callback) { else tryAgain = false; callback(null); //async.until requires an err first format callback & - } else { //if there is an error iteration stops, so neglect the error if EACCES thrown + } else { //if there is an error iteration stops, so neglect the error if EACCES thrown tryAgain = false; callback(ex2); } diff --git a/src/index.js b/src/index.js index 65eb54a7..dc0c1349 100644 --- a/src/index.js +++ b/src/index.js @@ -148,10 +148,15 @@ f.pinMode = function (pin, direction, mux, pullup, slew, callback) { ) { var err = 'pinMode only supports ANALOG_OUTPUT for PWM pins: ' + pin.key; winston.info(err); - if (callback) callback({ - value: false, - err: err - }); + if (callback) { + if (callback.length == 1) + callback({ + value: false, + err: err + }); + else + callback(err, false); + } return (false); } direction = g.OUTPUT; @@ -182,7 +187,12 @@ f.pinMode = function (pin, direction, mux, pullup, slew, callback) { if (typeof resp.err == 'undefined') { gpio[n] = true; } - if (callback) callback(resp); + if (callback) { + if (callback.length == 1) + callback(resp); + else + callback(resp.err, resp.value); + } return (resp.value); } @@ -200,7 +210,12 @@ f.pinMode = function (pin, direction, mux, pullup, slew, callback) { resp.value = false; winston.info(resp.err); delete gpio[n]; - if (callback) callback(resp); + if (callback) { + if (callback.length == 1) + callback(resp); + else + callback(resp.err, resp.value); + } return (resp.value); } } @@ -220,7 +235,12 @@ f.pinMode = function (pin, direction, mux, pullup, slew, callback) { delete gpio[n]; } - if (callback) callback(resp); + if (callback) { + if (callback.length == 1) + callback(resp); + else + callback(resp.err, resp.value); + } return (resp.value); }; f.pinMode.args = ['pin', 'direction', 'mux', 'pullup', 'slew', 'callback']; @@ -272,8 +292,10 @@ f.digitalRead = function (pin, callback) { } function analogCallback(x) { - x = analogValue(x); - callback(x); + if (callback.length == 1) + callback(analogValue(x)); + else + callback(x.err, analogValue(x).value); } function analogValue(x) { @@ -283,6 +305,7 @@ f.digitalRead = function (pin, callback) { } else { x.value = g.LOW; } + return x; } return (resp.value); @@ -380,7 +403,15 @@ f.attachInterrupt = function (pin, handler, mode, callback) { if (!epoll.exists) { resp.err = 'attachInterrupt: requires Epoll module'; if (debug) winston.debug(resp.err); - if (callback) callback(resp); + if (callback) { + if (callback.length == 1) + callback(resp); + else if (callback.length == 2) { + var err = resp.err; + delete resp.err; + callback(err, resp); + } + } return (resp.attached); } @@ -390,7 +421,15 @@ f.attachInterrupt = function (pin, handler, mode, callback) { if (debug) winston.debug(resp.err); resp.attached = false; resp.configured = false; - if (callback) callback(resp); + if (callback) { + if (callback.length == 1) + callback(resp); + else { + var err = resp.err; + delete resp.err; + callback(err, resp); + } + } return (resp); } @@ -400,7 +439,15 @@ f.attachInterrupt = function (pin, handler, mode, callback) { if (debug) winston.debug(resp.err); resp.attached = false; resp.configured = true; - if (callback) callback(resp); + if (callback) { + if (callback.length == 1) + callback(resp); + else { + var err = resp.err; + delete resp.err; + callback(err, resp); + } + } return (resp.attached); } @@ -418,7 +465,15 @@ f.attachInterrupt = function (pin, handler, mode, callback) { else m.output = { handler: handler }; - if (m.output && (typeof callback == 'function')) callback(m); + if (m.output && (typeof callback == 'function')) { + if (callback.length == 1) + callback(m); + else { + var err = m.err; + delete m.err; + callback(err, m); + } + } }; try { @@ -431,7 +486,15 @@ f.attachInterrupt = function (pin, handler, mode, callback) { resp.err = 'attachInterrupt: GPIO input file not opened: ' + ex; if (debug) winston.debug(resp.err); } - if (callback) callback(resp); + if (callback) { + if (callback.length == 1) + callback(resp); + else { + var err = resp.err; + delete resp.err; + callback(err, resp); + } + } return (resp.attached); }; f.attachInterrupt.args = ['pin', 'handler', 'mode', 'callback']; @@ -441,18 +504,34 @@ f.detachInterrupt = function (pin, callback) { if (debug) winston.debug('detachInterrupt(' + [pin.key] + ');'); var n = pin.gpio; if (typeof gpio[n] == 'undefined' || typeof gpioInt[n] == 'undefined') { - if (callback) callback({ - 'pin': pin, - 'detached': false - }); + if (callback) { + if (callback.length == 1) + callback({ + 'pin': pin, + 'detached': false + }); + else + callback(true, { + 'pin': pin, + 'detached': false + }); + } return (false); } gpioInt[n].epoll.remove(gpioInt[n].valuefd); delete gpioInt[n]; - if (callback) callback({ - 'pin': pin, - 'detached': true - }); + if (callback) { + if (callback.length == 1) + callback({ + 'pin': pin, + 'detached': true + }); + else + callback(null, { + 'pin': pin, + 'detached': true + }); + } return (true); }; f.detachInterrupt.args = ['pin', 'callback']; @@ -524,7 +603,12 @@ f.getEeproms = function (callback) { if (eeproms == {}) { if (debug) winston.debug('No valid EEPROM contents found'); } - if (callback) callback(eeproms); + if (callback) { + if (callback.length == 1) + callback(eeproms); + else + callback(eeproms == {} ? 'No valid EEPROM contents found' : null, eeproms); + } return (eeproms); }; f.getEeproms.args = ['callback']; @@ -537,7 +621,10 @@ f.readTextFile = function (filename, callback) { 'data': data }); }; - fs.readFile(filename, 'ascii', cb); + if (callback.length == 1) + fs.readFile(filename, 'ascii', cb); + else + fs.readFile(filename, 'ascii', callback); } else { return fs.readFileSync(filename, 'ascii'); } @@ -580,16 +667,26 @@ f.getPlatform = function (callback) { platform.os.freemem = os.freemem(); platform.os.networkInterfaces = os.networkInterfaces(); platform = hw.readPlatform(platform); - if (callback) callback(platform); + if (callback) { + if (callback.length == 1) + callback(platform); + else + callback(null, platform); + } return (platform); }; f.getPlatform.args = ['callback']; f.echo = function (data, callback) { winston.info(data); - if (callback) callback({ - 'data': data - }); + if (callback) { + if (callback.length == 1) + callback({ + 'data': data + }); + else + callback(null, data); + } return (data); }; f.echo.args = ['data', 'callback']; @@ -599,11 +696,19 @@ f.setDate = function (date, callback) { function dateResponse(error, stdout, stderr) { if (typeof callback != 'function') return; - else callback({ - 'error': error, - 'stdout': stdout, - 'stderr': stderr - }); + else { + if (callback.length == 1) + callback({ + 'error': error, + 'stdout': stdout, + 'stderr': stderr + }); + else + callback({ + 'error': error, + 'stderr': stderr + }, stdout); + } } }; f.setDate.args = ['date', 'callback']; From 3dd38787c0c60c9c98db3744d109fe95c3f59f40 Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Sun, 10 Jun 2018 10:28:52 +0530 Subject: [PATCH 02/13] make minor modification to readPinMux callback --- src/hw_mainline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hw_mainline.js b/src/hw_mainline.js index 494f356f..ebd4a6b8 100644 --- a/src/hw_mainline.js +++ b/src/hw_mainline.js @@ -65,7 +65,7 @@ var readPinMux = function (pin, mode, callback) { if (callback.length == 1) callback(mode); else - callback(err, data); + callback(mode.err, data); } mode = parse.modeFromPinctrl(data, muxRegOffset, 0x44e10800, mode); if (callback.length == 1) From fbdb18002c6d9b7def46722738b716593d37833b Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Wed, 13 Jun 2018 21:44:44 +0530 Subject: [PATCH 03/13] add deprecation warnings to previous style of callbacks --- src/hw_mainline.js | 25 ++++++++------ src/index.js | 85 +++++++++++++++++++++++++++------------------- 2 files changed, 66 insertions(+), 44 deletions(-) diff --git a/src/hw_mainline.js b/src/hw_mainline.js index ebd4a6b8..540aa672 100644 --- a/src/hw_mainline.js +++ b/src/hw_mainline.js @@ -62,15 +62,17 @@ var readPinMux = function (pin, mode, callback) { if (err) { mode.err = 'readPinctrl error: ' + err; if (debug) winston.debug(mode.err); - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(mode); - else + } else callback(mode.err, data); } mode = parse.modeFromPinctrl(data, muxRegOffset, 0x44e10800, mode); - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(mode); - else + } else callback(null, mode); }; var tryPinctrl = function (exists) { @@ -78,9 +80,10 @@ var readPinMux = function (pin, mode, callback) { fs.readFile(pinctrlFile, 'utf8', readPinctrl); } else { if (debug) winston.debug('getPinMode(' + pin.key + '): no valid mux data'); - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(mode); - else + } else callback('getPinMode(' + pin.key + '): no valid mux data', mode); } }; @@ -232,9 +235,10 @@ var readGPIOValue = function (pin, resp, callback) { winston.error(resp.err); } resp.value = parseInt(data, 2); - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); - else + } else callback(resp.err, resp.value); }; fs.readFile(gpioFile, readFile); @@ -271,9 +275,10 @@ var readAIN = function (pin, resp, callback) { winston.error(resp.err); } resp.value = parseInt(data, 10) / maxValue; - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); - else + } else callback(resp.err, resp.value); }; fs.readFile(ainFile, readFile); diff --git a/src/index.js b/src/index.js index dc0c1349..91415583 100644 --- a/src/index.js +++ b/src/index.js @@ -149,12 +149,13 @@ f.pinMode = function (pin, direction, mux, pullup, slew, callback) { var err = 'pinMode only supports ANALOG_OUTPUT for PWM pins: ' + pin.key; winston.info(err); if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback({ value: false, err: err }); - else + } else callback(err, false); } return (false); @@ -188,9 +189,10 @@ f.pinMode = function (pin, direction, mux, pullup, slew, callback) { gpio[n] = true; } if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); - else + } else callback(resp.err, resp.value); } return (resp.value); @@ -211,9 +213,10 @@ f.pinMode = function (pin, direction, mux, pullup, slew, callback) { winston.info(resp.err); delete gpio[n]; if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); - else + } else callback(resp.err, resp.value); } return (resp.value); @@ -236,9 +239,10 @@ f.pinMode = function (pin, direction, mux, pullup, slew, callback) { } if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); - else + } else callback(resp.err, resp.value); } return (resp.value); @@ -292,9 +296,10 @@ f.digitalRead = function (pin, callback) { } function analogCallback(x) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(analogValue(x)); - else + } else callback(x.err, analogValue(x).value); } @@ -404,9 +409,10 @@ f.attachInterrupt = function (pin, handler, mode, callback) { resp.err = 'attachInterrupt: requires Epoll module'; if (debug) winston.debug(resp.err); if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); - else if (callback.length == 2) { + } else { var err = resp.err; delete resp.err; callback(err, resp); @@ -422,9 +428,10 @@ f.attachInterrupt = function (pin, handler, mode, callback) { resp.attached = false; resp.configured = false; if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); - else { + } else { var err = resp.err; delete resp.err; callback(err, resp); @@ -440,9 +447,10 @@ f.attachInterrupt = function (pin, handler, mode, callback) { resp.attached = false; resp.configured = true; if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); - else { + } else { var err = resp.err; delete resp.err; callback(err, resp); @@ -466,9 +474,10 @@ f.attachInterrupt = function (pin, handler, mode, callback) { handler: handler }; if (m.output && (typeof callback == 'function')) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(m); - else { + } else { var err = m.err; delete m.err; callback(err, m); @@ -487,9 +496,10 @@ f.attachInterrupt = function (pin, handler, mode, callback) { if (debug) winston.debug(resp.err); } if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(resp); - else { + } else { var err = resp.err; delete resp.err; callback(err, resp); @@ -505,12 +515,13 @@ f.detachInterrupt = function (pin, callback) { var n = pin.gpio; if (typeof gpio[n] == 'undefined' || typeof gpioInt[n] == 'undefined') { if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback({ 'pin': pin, 'detached': false }); - else + } else callback(true, { 'pin': pin, 'detached': false @@ -521,12 +532,13 @@ f.detachInterrupt = function (pin, callback) { gpioInt[n].epoll.remove(gpioInt[n].valuefd); delete gpioInt[n]; if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback({ 'pin': pin, 'detached': true }); - else + } else callback(null, { 'pin': pin, 'detached': true @@ -604,9 +616,10 @@ f.getEeproms = function (callback) { if (debug) winston.debug('No valid EEPROM contents found'); } if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(eeproms); - else + } else callback(eeproms == {} ? 'No valid EEPROM contents found' : null, eeproms); } return (eeproms); @@ -621,9 +634,10 @@ f.readTextFile = function (filename, callback) { 'data': data }); }; - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); fs.readFile(filename, 'ascii', cb); - else + } else fs.readFile(filename, 'ascii', callback); } else { return fs.readFileSync(filename, 'ascii'); @@ -668,9 +682,10 @@ f.getPlatform = function (callback) { platform.os.networkInterfaces = os.networkInterfaces(); platform = hw.readPlatform(platform); if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(platform); - else + } else callback(null, platform); } return (platform); @@ -680,11 +695,12 @@ f.getPlatform.args = ['callback']; f.echo = function (data, callback) { winston.info(data); if (callback) { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback({ 'data': data }); - else + } else callback(null, data); } return (data); @@ -697,13 +713,14 @@ f.setDate = function (date, callback) { function dateResponse(error, stdout, stderr) { if (typeof callback != 'function') return; else { - if (callback.length == 1) + if (callback.length == 1) { + winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback({ 'error': error, 'stdout': stdout, 'stderr': stderr }); - else + } else callback({ 'error': error, 'stderr': stderr From 83fb428afe363d2242bca00063bb7b1c0755d0f3 Mon Sep 17 00:00:00 2001 From: Vaishnav M A Date: Thu, 14 Jun 2018 01:50:45 +0530 Subject: [PATCH 04/13] Added test-rpc.js (#9) Some fixes were made such that bonescript.js can run via node.js. I haven't yet verified that it doesn't break the browser. An internal startClient function was created. Added a devDependency on socket.io-client. --- package.json | 3 ++- src/bonescript.js | 28 +++++++++++++++++++++++----- src/server.js | 4 ++++ test/test-rpc.js | 25 +++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 test/test-rpc.js diff --git a/package.json b/package.json index 80006a4f..b7ec2bd2 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,8 @@ "coveralls": "~3.0.1", "js-beautify": "^1.7.5", "jscoverage": "~0.6.0", - "nodeunit": "^0.11.2" + "nodeunit": "^0.11.2", + "socket.io-client": "1.4.5" }, "scripts": { "start": "node server.js", diff --git a/src/bonescript.js b/src/bonescript.js index 077dc5df..5f25a27c 100644 --- a/src/bonescript.js +++ b/src/bonescript.js @@ -14,6 +14,15 @@ _bonescript.on.reconnecting = function () {}; _bonescript.on.initialized = function () {}; (function () { + if (typeof document == 'undefined') { + var io = require('socket.io-client'); + module.exports.startClient = function (host, port, callback) { + _bonescript.on.initialized = callback; + var socket = _onSocketIOLoaded(host, port, io); + } + return; + } + require = myrequire; var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; @@ -23,11 +32,12 @@ _bonescript.on.initialized = function () {}; scriptObj.onload = _onSocketIOLoaded; }()); -function _onSocketIOLoaded() { +function _onSocketIOLoaded(host, port, socketio) { //console.log("socket.io loaded"); - var socket = io.connect('___INSERT_HOST___', { - port: 80 - }); + if (typeof host == 'undefined') host = '___INSERT_HOST___'; + if (typeof port == 'undefined') port = 80; + if (typeof socketio == 'undefined' && typeof io != 'undefined') socketio = io; + var socket = socketio.connect('http://' + host + ':' + port); socket.on('require', getRequireData); socket.on('bonescript', _seqcall); socket.on('connect', _bonescript.on.connect); @@ -85,6 +95,8 @@ function _onSocketIOLoaded() { _bonescript.modules[m.module].socket = socket; _bonescript.on.initialized(); } + + return (socket); } function _seqcall(data) { @@ -97,8 +109,14 @@ function _seqcall(data) { // Require must be synchronous to be able to return data structures and // functions and therefore cannot call socket.io. All exported modules must // be exported ahead of time. -function require(module) { +function myrequire(module) { + if (typeof _bonescript == 'undefined') + throw 'No BoneScript modules are not currently available'; if (typeof _bonescript.modules[module] == 'undefined') throw 'Module "' + module + '" is not currently available'; return (_bonescript.modules[module]); +} + +if (typeof module != 'undefined') { + module.exports.require = myrequire; } \ No newline at end of file diff --git a/src/server.js b/src/server.js index f479230d..e62448f1 100644 --- a/src/server.js +++ b/src/server.js @@ -36,6 +36,10 @@ var serverStart = function (port, directory, callback) { } } + if (callback) { + callback(serverEmitter); + } + return (serverEmitter); }; diff --git a/test/test-rpc.js b/test/test-rpc.js new file mode 100644 index 00000000..3474be39 --- /dev/null +++ b/test/test-rpc.js @@ -0,0 +1,25 @@ +var server = require('../src/server'); +var bonescript = require('../src/bonescript'); +var serverEmitter = null; + +exports.setUp = function (callback) { + server.serverStart(8000, process.cwd(), mycb); + + function mycb(emitter) { + serverEmitter = emitter; + bonescript.startClient('127.0.0.1', 8000, callback); + } +}; + +exports.testRPC1 = function (test) { + test.expect(1); + test.doesNotThrow(function () { + console.log(bonescript); + var b = bonescript.require('bonescript'); + b.getPlatform(function (platform) { + console.log('Name: ' + platform.name); + console.log('Version: ' + platform.bonescript); + }); + }); + test.done(); +}; \ No newline at end of file From e27f6e604e5a2fbcf5493fd26bb225c7ca4f2f9b Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Thu, 14 Jun 2018 03:32:57 +0530 Subject: [PATCH 05/13] modify rpc test --- test/test-rpc.js | 122 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 108 insertions(+), 14 deletions(-) diff --git a/test/test-rpc.js b/test/test-rpc.js index 3474be39..2d13ddc3 100644 --- a/test/test-rpc.js +++ b/test/test-rpc.js @@ -2,24 +2,118 @@ var server = require('../src/server'); var bonescript = require('../src/bonescript'); var serverEmitter = null; -exports.setUp = function (callback) { +exports.testRPC = function (test) { server.serverStart(8000, process.cwd(), mycb); + test.expect(8); - function mycb(emitter) { - serverEmitter = emitter; - bonescript.startClient('127.0.0.1', 8000, callback); - } -}; - -exports.testRPC1 = function (test) { - test.expect(1); - test.doesNotThrow(function () { - console.log(bonescript); + function getPlatformTest() { + console.log('here'); var b = bonescript.require('bonescript'); + //console.log("" + b); b.getPlatform(function (platform) { + console.log("***getPlatformTest***"); + console.log(platform); console.log('Name: ' + platform.name); console.log('Version: ' + platform.bonescript); + test.ok(true); + pinModeTest(); }); - }); - test.done(); -}; \ No newline at end of file + } + + function pinModeTest() { + var b = bonescript.require('bonescript'); + b.pinMode("P8_13", b.OUTPUT, 7, 'pullup', 'fast', printStatus); + + function printStatus(x) { + console.log("***pinModeTest***"); + console.log('value = ' + x.value); + console.log('err = ' + x.err); + test.ok(true); + getPinModeTest(); + } + } + + function getPinModeTest() { + var b = bonescript.require('bonescript'); + b.getPinMode("P8_13", printPinMux); + + function printPinMux(x) { + console.log("***getPinModeTest***"); + console.log('mux = ' + x.mux); + console.log('pullup = ' + x.pullup); + console.log('slew = ' + x.slew); + console.log('options = ' + x.options.join(',')); + console.log('err = ' + x.err); + test.ok(true); + digitalWriteTest(); + } + } + + function digitalWriteTest() { + var b = bonescript.require('bonescript'); + b.digitalWrite('USR0', b.HIGH, printErr); + + function printErr(x) { + console.log("***digitalWriteTest***"); + console.log('err = ' + x.err); + test.ok(true); + digitalReadTest(); + } + } + + function digitalReadTest() { + var b = bonescript.require('bonescript'); + b.digitalRead('P8_19', printStatus); + + function printStatus(x) { + console.log("***digitalReadTest***"); + console.log('x.value = ' + x.value); + console.log('x.err = ' + x.err); + test.ok(true); + analogReadTest(); + } + } + + function analogReadTest() { + var b = bonescript.require('bonescript'); + b.analogRead('P9_36', printStatus); + + function printStatus(x) { + console.log("***analogReadTest***"); + console.log('x.value = ' + x.value); + console.log('x.err = ' + x.err); + test.ok(true); + attachInterruptTest() + } + } + + function attachInterruptTest() { + var b = bonescript.require('bonescript'); + b.attachInterrupt('P8_19', true, b.CHANGE, interruptCallback); + + function interruptCallback(x) { + console.log(JSON.stringify(x)); + test.ok(true); + readTextFileTest(); + } + } + + function readTextFileTest() { + var b = bonescript.require('bonescript'); + b.readTextFile('/etc/fstab', printStatus); + + function printStatus(x) { + console.log('x.data = ' + x.data); + console.log('x.err = ' + x.err); + test.ok(true); + test.done(); + } + } + + + + function mycb(emitter) { + serverEmitter = emitter; + bonescript.startClient('127.0.0.1', 8000, getPlatformTest); + } +} \ No newline at end of file From 4f3ed2b44b74862917f1fc34e72820c9366bb8a3 Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Thu, 14 Jun 2018 03:58:40 +0530 Subject: [PATCH 06/13] add analogWrite() test _ remove unnecessary blank lines --- test/test-rpc.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/test/test-rpc.js b/test/test-rpc.js index 2d13ddc3..4ef6a18e 100644 --- a/test/test-rpc.js +++ b/test/test-rpc.js @@ -4,7 +4,7 @@ var serverEmitter = null; exports.testRPC = function (test) { server.serverStart(8000, process.cwd(), mycb); - test.expect(8); + test.expect(9); function getPlatformTest() { console.log('here'); @@ -70,7 +70,20 @@ exports.testRPC = function (test) { console.log('x.value = ' + x.value); console.log('x.err = ' + x.err); test.ok(true); + analogWriteTest() + } + } + + function analogWriteTest() { + var b = bonescript.require('bonescript'); + b.analogWrite('P9_14', 0.7, 2000, printJSON); + + function printJSON(x) { + console.log("***analogWriteTest***"); + console.log(JSON.stringify(x)); + test.ok(true); analogReadTest(); + } } @@ -92,6 +105,7 @@ exports.testRPC = function (test) { b.attachInterrupt('P8_19', true, b.CHANGE, interruptCallback); function interruptCallback(x) { + console.log("***attachInterruptTest***"); console.log(JSON.stringify(x)); test.ok(true); readTextFileTest(); @@ -103,6 +117,7 @@ exports.testRPC = function (test) { b.readTextFile('/etc/fstab', printStatus); function printStatus(x) { + console.log("***readTextFileTest***"); console.log('x.data = ' + x.data); console.log('x.err = ' + x.err); test.ok(true); @@ -110,8 +125,6 @@ exports.testRPC = function (test) { } } - - function mycb(emitter) { serverEmitter = emitter; bonescript.startClient('127.0.0.1', 8000, getPlatformTest); From fb6ac66ba02505ab5d6db1b466dbe569d82ab331 Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Thu, 14 Jun 2018 16:24:21 +0530 Subject: [PATCH 07/13] fix for browser printing out the socket response from the browser shows the hostname as : http:// [object] [method] :80 --- src/bonescript.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bonescript.js b/src/bonescript.js index 5f25a27c..8dc4983e 100644 --- a/src/bonescript.js +++ b/src/bonescript.js @@ -37,7 +37,13 @@ function _onSocketIOLoaded(host, port, socketio) { if (typeof host == 'undefined') host = '___INSERT_HOST___'; if (typeof port == 'undefined') port = 80; if (typeof socketio == 'undefined' && typeof io != 'undefined') socketio = io; - var socket = socketio.connect('http://' + host + ':' + port); + var socket; + if (typeof host == 'string') + socket = socketio('http://' + host + ':' + port); + else + socket = socketio('___INSERT_HOST___', { + port: 80 + }); socket.on('require', getRequireData); socket.on('bonescript', _seqcall); socket.on('connect', _bonescript.on.connect); @@ -109,7 +115,7 @@ function _seqcall(data) { // Require must be synchronous to be able to return data structures and // functions and therefore cannot call socket.io. All exported modules must // be exported ahead of time. -function myrequire(module) { +var myrequire = function (module) { if (typeof _bonescript == 'undefined') throw 'No BoneScript modules are not currently available'; if (typeof _bonescript.modules[module] == 'undefined') From 5eb2e024deccabaaa4c9ec3278196b06002954c0 Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Fri, 15 Jun 2018 04:57:33 +0530 Subject: [PATCH 08/13] Fix for supporting node_style callback via rpc had to modify both the client and server since the method of translation at the client side will throw the deprecation warning even if node_style callbacks are used,confirmed working of both style callbacks, needs to add test-case --- src/bonescript.js | 6 +++++- src/socket_handlers.js | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/bonescript.js b/src/bonescript.js index 8dc4983e..65b915db 100644 --- a/src/bonescript.js +++ b/src/bonescript.js @@ -89,6 +89,7 @@ function _onSocketIOLoaded(host, port, socketio) { ' if(callback) {\n' + ' _bonescript._callbacks[_bonescript._seqnum] = callback;\n' + ' calldata.seq = _bonescript._seqnum;\n' + + ' calldata.length = callback.length;\n' + ' _bonescript._seqnum++;\n' + ' }\n' + ' socket.emit("' + m.module + '$' + m.data[x].name + '", calldata);\n' + @@ -108,7 +109,10 @@ function _onSocketIOLoaded(host, port, socketio) { function _seqcall(data) { if ((typeof data.seq != 'number') || (typeof _bonescript._callbacks[data.seq] != 'function')) throw "Invalid callback message received: " + JSON.stringify(data); - _bonescript._callbacks[data.seq](data); + if (_bonescript._callbacks[data.seq].length == 1) + _bonescript._callbacks[data.seq](data); + else + _bonescript._callbacks[data.seq](data.err, data.resp); if (data.oneshot) delete _bonescript._callbacks[data.seq]; } diff --git a/src/socket_handlers.js b/src/socket_handlers.js index 2c8f2439..82574c76 100644 --- a/src/socket_handlers.js +++ b/src/socket_handlers.js @@ -69,13 +69,28 @@ var addSocketListeners = function (server, serverEmitter) { if (debug) winston.debug('Sending message "bonescript": ' + JSON.stringify(resp)); socket.emit('bonescript', resp); }; + var myCallback_nodestyle = function (err, resp) { + if (debug) winston.debug(name + ' replied to ' + JSON.stringify(m) + ' with ' + JSON.stringify(resp)); + if (typeof m.seq == 'undefined') return; + // TODO: consider setting 'oneshot' + if (debug) winston.debug('Sending message "bonescript": ' + JSON.stringify(resp)); + socket.emit('bonescript', { + err: err, + resp: resp, + seq: m.seq + }); + }; try { var callargs = []; for (var arg in b[name].args) { var argname = b[name].args[arg]; if (argname == 'callback') { - if (typeof m.seq == 'number') callargs.push(myCallback); - else callargs.push(null); + if (typeof m.seq == 'number') { + if (m.length == 1) + callargs.push(myCallback); + else + callargs.push(myCallback_nodestyle); + } else callargs.push(null); } else if (typeof m[argname] != 'undefined') { callargs.push(m[argname]); } else { From 1767934f9047b6a99880105f544c7ac56e824920 Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Fri, 15 Jun 2018 05:41:36 +0530 Subject: [PATCH 09/13] add some test cases for dual style callback implementation test cases not added for hw_... dependent cases --- test/test-rpc.js | 79 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/test/test-rpc.js b/test/test-rpc.js index 4ef6a18e..620d4966 100644 --- a/test/test-rpc.js +++ b/test/test-rpc.js @@ -4,23 +4,34 @@ var serverEmitter = null; exports.testRPC = function (test) { server.serverStart(8000, process.cwd(), mycb); - test.expect(9); + test.expect(13); - function getPlatformTest() { - console.log('here'); + function getPlatformTest_previous() { var b = bonescript.require('bonescript'); - //console.log("" + b); b.getPlatform(function (platform) { console.log("***getPlatformTest***"); console.log(platform); console.log('Name: ' + platform.name); console.log('Version: ' + platform.bonescript); - test.ok(true); - pinModeTest(); + getPlatformTest_nodestyle(platform); + }); + } + + function getPlatformTest_nodestyle(platform_) { + console.log('here'); + var b = bonescript.require('bonescript'); + b.getPlatform(function (err, platform) { + console.log("***getPlatformTest***"); + console.log(platform); + console.log('Name: ' + platform.name); + console.log('Version: ' + platform.bonescript); + test.equals(platform.name, platform_.name); + test.equals(platform.bonescript, platform_.bonescript); + pinModeTest_previous(); }); } - function pinModeTest() { + function pinModeTest_previous() { var b = bonescript.require('bonescript'); b.pinMode("P8_13", b.OUTPUT, 7, 'pullup', 'fast', printStatus); @@ -28,7 +39,20 @@ exports.testRPC = function (test) { console.log("***pinModeTest***"); console.log('value = ' + x.value); console.log('err = ' + x.err); - test.ok(true); + pinModeTest_nodestyle(x); + } + } + + function pinModeTest_nodestyle(x) { + var b = bonescript.require('bonescript'); + b.pinMode("P8_13", b.OUTPUT, 7, 'pullup', 'fast', printStatus); + + function printStatus(err, value) { + console.log("***pinModeTest***"); + console.log('value = ' + value); + console.log('err = ' + err); + test.equals(x.err, err); + test.equals(x.value, value); getPinModeTest(); } } @@ -96,23 +120,35 @@ exports.testRPC = function (test) { console.log('x.value = ' + x.value); console.log('x.err = ' + x.err); test.ok(true); - attachInterruptTest() + attachInterruptTest_previous() } } - function attachInterruptTest() { + function attachInterruptTest_previous() { var b = bonescript.require('bonescript'); b.attachInterrupt('P8_19', true, b.CHANGE, interruptCallback); function interruptCallback(x) { console.log("***attachInterruptTest***"); console.log(JSON.stringify(x)); - test.ok(true); - readTextFileTest(); + attachInterruptTest_nodestyle(x) + } + } + + function attachInterruptTest_nodestyle(x) { + var b = bonescript.require('bonescript'); + b.attachInterrupt('P8_19', true, b.CHANGE, interruptCallback); + + function interruptCallback(err, resp) { + console.log("***attachInterruptTest***"); + console.log(JSON.stringify(resp)); + test.equals(x.err, err); + test.equals(x.pin.name, resp.pin.name); + readTextFileTest_previous(); } } - function readTextFileTest() { + function readTextFileTest_previous() { var b = bonescript.require('bonescript'); b.readTextFile('/etc/fstab', printStatus); @@ -120,13 +156,26 @@ exports.testRPC = function (test) { console.log("***readTextFileTest***"); console.log('x.data = ' + x.data); console.log('x.err = ' + x.err); - test.ok(true); + readTextFileTest_nodestyle(x); + } + } + + function readTextFileTest_nodestyle(x) { + var b = bonescript.require('bonescript'); + b.readTextFile('/etc/fstab', printStatus); + + function printStatus(err, data) { + console.log("***readTextFileTest***"); + console.log('x.data = ' + data); + console.log('x.err = ' + err); + test.equals(x.data, data); + test.equals(x.err, err); test.done(); } } function mycb(emitter) { serverEmitter = emitter; - bonescript.startClient('127.0.0.1', 8000, getPlatformTest); + bonescript.startClient('127.0.0.1', 8000, getPlatformTest_previous); } } \ No newline at end of file From 9edda683370cdc4e45b80e918c7915193f944f7f Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Fri, 15 Jun 2018 13:19:03 +0530 Subject: [PATCH 10/13] fix error message in readPinMux --- src/hw_mainline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hw_mainline.js b/src/hw_mainline.js index 540aa672..25544b01 100644 --- a/src/hw_mainline.js +++ b/src/hw_mainline.js @@ -84,7 +84,7 @@ var readPinMux = function (pin, mode, callback) { winston.warning("single argument callbacks will be deprecated.please use node-style error-first callbacks: callback(err,response)"); callback(mode); } else - callback('getPinMode(' + pin.key + '): no valid mux data', mode); + callback('readPinMux error: no valid mux data', mode); } }; if (callback) { From fabb59f35368547d36515d3b6d38b3ecda430118 Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Fri, 15 Jun 2018 14:00:34 +0530 Subject: [PATCH 11/13] modify hw_simulator for nodestyle cb, add rpc cb test for remaining cases hw_simulator modified to support nodestyle callbacks,added tests for previously omitted cases --- src/hw_simulator.js | 16 +++++++-- test/test-rpc.js | 85 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 77 insertions(+), 24 deletions(-) diff --git a/src/hw_simulator.js b/src/hw_simulator.js index b74bd897..00328e82 100644 --- a/src/hw_simulator.js +++ b/src/hw_simulator.js @@ -29,7 +29,10 @@ var readGPIODirection = function (n, gpio) { var readPinMux = function (pin, mode, callback) { winston.info('readPinMux(' + [pin.key] + ')'); if (callback) { - callback(mode); + if (callback.length == 1) + callback(mode); + else + callback(null, mode); } return (mode); }; @@ -60,7 +63,11 @@ var writeGPIOValue = function (pin, value, callback) { var readGPIOValue = function (pin, resp, callback) { winston.info('readGPIOValue(' + [pin.key] + ')'); if (callback) { - callback(0); + resp.value = 0; + if (callback.length == 1) + callback(resp); + else + callback(null, resp.value); return (true); } resp.value = 0; @@ -76,7 +83,10 @@ var readAIN = function (pin, resp, callback) { winston.info('readAIN(' + [pin.key] + ')'); resp.value = 0; if (callback) { - callback(resp); + if (callback.length == 1) + callback(resp); + else + callback(null, resp.value); } return (resp); }; diff --git a/test/test-rpc.js b/test/test-rpc.js index 620d4966..7313b7e7 100644 --- a/test/test-rpc.js +++ b/test/test-rpc.js @@ -4,12 +4,12 @@ var serverEmitter = null; exports.testRPC = function (test) { server.serverStart(8000, process.cwd(), mycb); - test.expect(13); + test.expect(16); function getPlatformTest_previous() { var b = bonescript.require('bonescript'); b.getPlatform(function (platform) { - console.log("***getPlatformTest***"); + console.log("***getPlatformTest_previous***"); console.log(platform); console.log('Name: ' + platform.name); console.log('Version: ' + platform.bonescript); @@ -21,7 +21,7 @@ exports.testRPC = function (test) { console.log('here'); var b = bonescript.require('bonescript'); b.getPlatform(function (err, platform) { - console.log("***getPlatformTest***"); + console.log("***getPlatformTest_nodestyle***"); console.log(platform); console.log('Name: ' + platform.name); console.log('Version: ' + platform.bonescript); @@ -36,7 +36,7 @@ exports.testRPC = function (test) { b.pinMode("P8_13", b.OUTPUT, 7, 'pullup', 'fast', printStatus); function printStatus(x) { - console.log("***pinModeTest***"); + console.log("***pinModeTest_previous***"); console.log('value = ' + x.value); console.log('err = ' + x.err); pinModeTest_nodestyle(x); @@ -48,27 +48,45 @@ exports.testRPC = function (test) { b.pinMode("P8_13", b.OUTPUT, 7, 'pullup', 'fast', printStatus); function printStatus(err, value) { - console.log("***pinModeTest***"); + console.log("***pinModeTest_nodestyle***"); console.log('value = ' + value); console.log('err = ' + err); test.equals(x.err, err); test.equals(x.value, value); - getPinModeTest(); + getPinModeTest_previous(); } } - function getPinModeTest() { + function getPinModeTest_previous() { var b = bonescript.require('bonescript'); b.getPinMode("P8_13", printPinMux); function printPinMux(x) { - console.log("***getPinModeTest***"); + console.log("***getPinModeTest_previous***"); console.log('mux = ' + x.mux); console.log('pullup = ' + x.pullup); console.log('slew = ' + x.slew); console.log('options = ' + x.options.join(',')); console.log('err = ' + x.err); - test.ok(true); + getPinModeTest_nodestyle(x) + } + } + + function getPinModeTest_nodestyle(x) { + var b = bonescript.require('bonescript'); + b.getPinMode("P8_13", printPinMux); + + function printPinMux(err, resp) { + console.log("***getPinModeTest_nodestyle***"); + console.log('mux = ' + resp.mux); + console.log('pullup = ' + resp.pullup); + console.log('slew = ' + resp.slew); + console.log('options = ' + resp.options.join(',')); + console.log('err = ' + resp.err); + test.equals(x.mux, resp.mux); + test.equals(x.pullup, resp.pullup); + test.equals(x.slew, resp.slew); + test.equals(x.options.join(','), resp.options.join(',')); digitalWriteTest(); } } @@ -81,23 +99,36 @@ exports.testRPC = function (test) { console.log("***digitalWriteTest***"); console.log('err = ' + x.err); test.ok(true); - digitalReadTest(); + digitalReadTest_previous(); } } - function digitalReadTest() { + function digitalReadTest_previous() { var b = bonescript.require('bonescript'); b.digitalRead('P8_19', printStatus); function printStatus(x) { - console.log("***digitalReadTest***"); + console.log("***digitalReadTest_previous***"); console.log('x.value = ' + x.value); console.log('x.err = ' + x.err); - test.ok(true); + digitalReadTest_nodestyle(x) + } + } + + function digitalReadTest_nodestyle(x) { + var b = bonescript.require('bonescript'); + b.digitalRead('P8_19', printStatus); + + function printStatus(err, value) { + console.log("***digitalReadTest_nodestyle***"); + console.log('x.value = ' + value); + console.log('x.err = ' + err); + test.equals(x.value, value); analogWriteTest() } } + function analogWriteTest() { var b = bonescript.require('bonescript'); b.analogWrite('P9_14', 0.7, 2000, printJSON); @@ -106,20 +137,32 @@ exports.testRPC = function (test) { console.log("***analogWriteTest***"); console.log(JSON.stringify(x)); test.ok(true); - analogReadTest(); + analogReadTest_previous(); } } - function analogReadTest() { + function analogReadTest_previous() { var b = bonescript.require('bonescript'); b.analogRead('P9_36', printStatus); function printStatus(x) { - console.log("***analogReadTest***"); + console.log("***analogReadTest_previous***"); console.log('x.value = ' + x.value); console.log('x.err = ' + x.err); - test.ok(true); + analogReadTest_nodestyle(x); + } + } + + function analogReadTest_nodestyle(x) { + var b = bonescript.require('bonescript'); + b.analogRead('P9_36', printStatus); + + function printStatus(err, value) { + console.log("***analogReadTest_nodestyle***"); + console.log('x.value = ' + value); + console.log('x.err = ' + err); + test.equals(x.value, value); attachInterruptTest_previous() } } @@ -129,7 +172,7 @@ exports.testRPC = function (test) { b.attachInterrupt('P8_19', true, b.CHANGE, interruptCallback); function interruptCallback(x) { - console.log("***attachInterruptTest***"); + console.log("***attachInterruptTest_previous***"); console.log(JSON.stringify(x)); attachInterruptTest_nodestyle(x) } @@ -140,7 +183,7 @@ exports.testRPC = function (test) { b.attachInterrupt('P8_19', true, b.CHANGE, interruptCallback); function interruptCallback(err, resp) { - console.log("***attachInterruptTest***"); + console.log("***attachInterruptTest_nodestyle***"); console.log(JSON.stringify(resp)); test.equals(x.err, err); test.equals(x.pin.name, resp.pin.name); @@ -153,7 +196,7 @@ exports.testRPC = function (test) { b.readTextFile('/etc/fstab', printStatus); function printStatus(x) { - console.log("***readTextFileTest***"); + console.log("***readTextFileTest_previous***"); console.log('x.data = ' + x.data); console.log('x.err = ' + x.err); readTextFileTest_nodestyle(x); @@ -165,7 +208,7 @@ exports.testRPC = function (test) { b.readTextFile('/etc/fstab', printStatus); function printStatus(err, data) { - console.log("***readTextFileTest***"); + console.log("***readTextFileTest_nodestyle***"); console.log('x.data = ' + data); console.log('x.err = ' + err); test.equals(x.data, data); From 57722e1dd3b3cd278de0892064066eed07756f57 Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Mon, 18 Jun 2018 03:36:57 +0530 Subject: [PATCH 12/13] neater fix for test-rpc --- test/test-rpc.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/test-rpc.js b/test/test-rpc.js index 7313b7e7..1613bc9b 100644 --- a/test/test-rpc.js +++ b/test/test-rpc.js @@ -2,10 +2,19 @@ var server = require('../src/server'); var bonescript = require('../src/bonescript'); var serverEmitter = null; -exports.testRPC = function (test) { +exports.setUp = function (callback) { server.serverStart(8000, process.cwd(), mycb); + + function mycb(emitter) { + callback(); + } +}; + +exports.testRPC_callbacks = function (test) { test.expect(16); + bonescript.startClient('127.0.0.1', 8000, getPlatformTest_previous); + function getPlatformTest_previous() { var b = bonescript.require('bonescript'); b.getPlatform(function (platform) { @@ -216,9 +225,4 @@ exports.testRPC = function (test) { test.done(); } } - - function mycb(emitter) { - serverEmitter = emitter; - bonescript.startClient('127.0.0.1', 8000, getPlatformTest_previous); - } } \ No newline at end of file From 0e15de4069de6ee9ca073c1bdd0b8498209df3f8 Mon Sep 17 00:00:00 2001 From: vaishnav98 Date: Fri, 22 Jun 2018 14:19:31 +0530 Subject: [PATCH 13/13] change port from fixed port: 80 on rpc client also changed console messages and function names on test-rpc.js from ..._previous to ..._oldstyle --- src/bonescript.js | 2 +- test/test-rpc.js | 42 +++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/bonescript.js b/src/bonescript.js index 65b915db..bc2e06a0 100644 --- a/src/bonescript.js +++ b/src/bonescript.js @@ -42,7 +42,7 @@ function _onSocketIOLoaded(host, port, socketio) { socket = socketio('http://' + host + ':' + port); else socket = socketio('___INSERT_HOST___', { - port: 80 + port: port }); socket.on('require', getRequireData); socket.on('bonescript', _seqcall); diff --git a/test/test-rpc.js b/test/test-rpc.js index 1613bc9b..6b8fd905 100644 --- a/test/test-rpc.js +++ b/test/test-rpc.js @@ -13,12 +13,12 @@ exports.setUp = function (callback) { exports.testRPC_callbacks = function (test) { test.expect(16); - bonescript.startClient('127.0.0.1', 8000, getPlatformTest_previous); + bonescript.startClient('127.0.0.1', 8000, getPlatformTest_oldstyle); - function getPlatformTest_previous() { + function getPlatformTest_oldstyle() { var b = bonescript.require('bonescript'); b.getPlatform(function (platform) { - console.log("***getPlatformTest_previous***"); + console.log("***getPlatformTest_oldstyle***"); console.log(platform); console.log('Name: ' + platform.name); console.log('Version: ' + platform.bonescript); @@ -36,16 +36,16 @@ exports.testRPC_callbacks = function (test) { console.log('Version: ' + platform.bonescript); test.equals(platform.name, platform_.name); test.equals(platform.bonescript, platform_.bonescript); - pinModeTest_previous(); + pinModeTest_oldstyle(); }); } - function pinModeTest_previous() { + function pinModeTest_oldstyle() { var b = bonescript.require('bonescript'); b.pinMode("P8_13", b.OUTPUT, 7, 'pullup', 'fast', printStatus); function printStatus(x) { - console.log("***pinModeTest_previous***"); + console.log("***pinModeTest_oldstyle***"); console.log('value = ' + x.value); console.log('err = ' + x.err); pinModeTest_nodestyle(x); @@ -62,16 +62,16 @@ exports.testRPC_callbacks = function (test) { console.log('err = ' + err); test.equals(x.err, err); test.equals(x.value, value); - getPinModeTest_previous(); + getPinModeTest_oldstyle(); } } - function getPinModeTest_previous() { + function getPinModeTest_oldstyle() { var b = bonescript.require('bonescript'); b.getPinMode("P8_13", printPinMux); function printPinMux(x) { - console.log("***getPinModeTest_previous***"); + console.log("***getPinModeTest_oldstyle***"); console.log('mux = ' + x.mux); console.log('pullup = ' + x.pullup); console.log('slew = ' + x.slew); @@ -108,16 +108,16 @@ exports.testRPC_callbacks = function (test) { console.log("***digitalWriteTest***"); console.log('err = ' + x.err); test.ok(true); - digitalReadTest_previous(); + digitalReadTest_oldstyle(); } } - function digitalReadTest_previous() { + function digitalReadTest_oldstyle() { var b = bonescript.require('bonescript'); b.digitalRead('P8_19', printStatus); function printStatus(x) { - console.log("***digitalReadTest_previous***"); + console.log("***digitalReadTest_oldstyle***"); console.log('x.value = ' + x.value); console.log('x.err = ' + x.err); digitalReadTest_nodestyle(x) @@ -146,17 +146,17 @@ exports.testRPC_callbacks = function (test) { console.log("***analogWriteTest***"); console.log(JSON.stringify(x)); test.ok(true); - analogReadTest_previous(); + analogReadTest_oldstyle(); } } - function analogReadTest_previous() { + function analogReadTest_oldstyle() { var b = bonescript.require('bonescript'); b.analogRead('P9_36', printStatus); function printStatus(x) { - console.log("***analogReadTest_previous***"); + console.log("***analogReadTest_oldstyle***"); console.log('x.value = ' + x.value); console.log('x.err = ' + x.err); analogReadTest_nodestyle(x); @@ -172,16 +172,16 @@ exports.testRPC_callbacks = function (test) { console.log('x.value = ' + value); console.log('x.err = ' + err); test.equals(x.value, value); - attachInterruptTest_previous() + attachInterruptTest_oldstyle() } } - function attachInterruptTest_previous() { + function attachInterruptTest_oldstyle() { var b = bonescript.require('bonescript'); b.attachInterrupt('P8_19', true, b.CHANGE, interruptCallback); function interruptCallback(x) { - console.log("***attachInterruptTest_previous***"); + console.log("***attachInterruptTest_oldstyle***"); console.log(JSON.stringify(x)); attachInterruptTest_nodestyle(x) } @@ -196,16 +196,16 @@ exports.testRPC_callbacks = function (test) { console.log(JSON.stringify(resp)); test.equals(x.err, err); test.equals(x.pin.name, resp.pin.name); - readTextFileTest_previous(); + readTextFileTest_oldstyle(); } } - function readTextFileTest_previous() { + function readTextFileTest_oldstyle() { var b = bonescript.require('bonescript'); b.readTextFile('/etc/fstab', printStatus); function printStatus(x) { - console.log("***readTextFileTest_previous***"); + console.log("***readTextFileTest_oldstyle***"); console.log('x.data = ' + x.data); console.log('x.err = ' + x.err); readTextFileTest_nodestyle(x);