diff --git a/lib/onoffsim/Readme.md b/lib/onoffsim/Readme.md index 1825111..b2bc825 100644 --- a/lib/onoffsim/Readme.md +++ b/lib/onoffsim/Readme.md @@ -8,7 +8,7 @@ Object representing a fake onoff Gpio class ### onoffsim.Gpio(no, dir, additional) ⇒ object Gpio() - -Create's a Gpio class in the case of running on a dev machine +Returns a Gpio class in the case of running on a dev machine **Kind**: static method of [onoffsim](#onoffsim) **Returns**: object - Fake Gpio object diff --git a/lib/onoffsim/index.js b/lib/onoffsim/index.js index cd3ca77..dba05d1 100644 --- a/lib/onoffsim/index.js +++ b/lib/onoffsim/index.js @@ -12,7 +12,6 @@ const onoffsim = { * @returns {object} Fake Gpio object */ Gpio : function (no, dir = 'in', additional = 'none') { - // return { no : no, dir : dir, diff --git a/lib/wifi/Readme.md b/lib/wifi/Readme.md index e69de29..7d4ef84 100644 --- a/lib/wifi/Readme.md +++ b/lib/wifi/Readme.md @@ -0,0 +1,109 @@ + + +## Wifi +Class representing the wifi features + +**Kind**: global class + +* [Wifi](#Wifi) + * [.list(callback)](#Wifi+list) + * [._readConfigCb(err, data)](#Wifi+_readConfigCb) + * [._writeConfigCb(err)](#Wifi+_writeConfigCb) + * [._reconfigureCb(err, stdout, stderr)](#Wifi+_reconfigureCb) + * [._refreshCb(err, stdout, stderr)](#Wifi+_refreshCb) + * [.setNetwork(ssid, pwd, callback)](#Wifi+setNetwork) + * [.getNetwork(callback)](#Wifi+getNetwork) + + + +### wifi.list(callback) +Wifi.list() - +List available wifi access points + +**Kind**: instance method of [Wifi](#Wifi) + +| Param | Type | Description | +| --- | --- | --- | +| callback | function | Function which gets invoked after list is returned | + + + +### wifi._readConfigCb(err, data) +Wifi._readConfigCb() - +(internal function) Invoked after config file is read, +then invokes file write on the config file + +**Kind**: instance method of [Wifi](#Wifi) + +| Param | Type | Description | +| --- | --- | --- | +| err | object | (optional) Error object only present if problem reading config file | +| data | string | Contents of the config file | + + + +### wifi._writeConfigCb(err) +Wifi._writeConfigCb() - +(internal function) Invoked after config file is written, +then executes reconfiguration command + +**Kind**: instance method of [Wifi](#Wifi) + +| Param | Type | Description | +| --- | --- | --- | +| err | object | (optional) Error object only present if problem writing config file | + + + +### wifi._reconfigureCb(err, stdout, stderr) +Wifi._reconfigureCb() - +(internal function) Invoked after reconfiguration command is complete + +**Kind**: instance method of [Wifi](#Wifi) + +| Param | Type | Description | +| --- | --- | --- | +| err | object | (optional) Error object only present if configuration command fails | +| stdout | string | Standard output from reconfiguration command | +| stderr | string | Error output from command if fails | + + + +### wifi._refreshCb(err, stdout, stderr) +Wifi._refreshCb() - +(internal function) Invoked after wifi refresh command is complete + +**Kind**: instance method of [Wifi](#Wifi) + +| Param | Type | Description | +| --- | --- | --- | +| err | object | (optional) Error object only present if refresh command fails | +| stdout | string | Standard output from refresh command | +| stderr | string | Error output from command if fails | + + + +### wifi.setNetwork(ssid, pwd, callback) +Wifi.setNetwork() - +Function which initializes the processes for adding a wifi access point authentication + +**Kind**: instance method of [Wifi](#Wifi) + +| Param | Type | Description | +| --- | --- | --- | +| ssid | string | SSID of network to configure | +| pwd | string | Password of access point, plaintext | +| callback | function | Function invoked after process is complete, or fails | + + + +### wifi.getNetwork(callback) +Wifi.getNetwork() - +Executes command which gets the currently connected network + +**Kind**: instance method of [Wifi](#Wifi) + +| Param | Type | Description | +| --- | --- | --- | +| callback | function | Function which is invoked after command is completed | + diff --git a/lib/wifi/index.js b/lib/wifi/index.js index f330df4..22096b6 100644 --- a/lib/wifi/index.js +++ b/lib/wifi/index.js @@ -12,12 +12,19 @@ const iwgetid = '/sbin/iwgetid' const exec = require('child_process').exec const fs = require('fs') -class wifi { +/** Class representing the wifi features */ +class Wifi { constructor () { this._callback = () => {} this._entry = null this._ssid = null } + /** + * Wifi.list() - + * List available wifi access points + * + * @param {function} callback Function which gets invoked after list is returned + */ list (callback) { exec(iwlist, (err, stdout, stderr) => { if (err) { @@ -37,6 +44,14 @@ class wifi { return callback(null, output) }) } + /** + * Wifi._readConfigCb() - + * (internal function) Invoked after config file is read, + * then invokes file write on the config file + * + * @param {object} err (optional) Error object only present if problem reading config file + * @param {string} data Contents of the config file + */ _readConfigCb (err, data) { if (err) { console.error(err) @@ -50,6 +65,13 @@ class wifi { this._entry = null fs.writeFile(filePath, data, 'utf8', this._writeConfigCb) } + /** + * Wifi._writeConfigCb() - + * (internal function) Invoked after config file is written, + * then executes reconfiguration command + * + * @param {object} err (optional) Error object only present if problem writing config file + */ _writeConfigCb (err) { if (err) { console.error(err) @@ -57,6 +79,14 @@ class wifi { } exec(reconfigure, this._reconfigureCb) } + /** + * Wifi._reconfigureCb() - + * (internal function) Invoked after reconfiguration command is complete + * + * @param {object} err (optional) Error object only present if configuration command fails + * @param {string} stdout Standard output from reconfiguration command + * @param {string} stderr Error output from command if fails + */ _reconfigureCb (err, stdout, stderr) { if (err) { console.error(err) @@ -65,6 +95,14 @@ class wifi { console.log('Wifi reconfigured') exec(refresh, this._refreshCb) } + /** + * Wifi._refreshCb() - + * (internal function) Invoked after wifi refresh command is complete + * + * @param {object} err (optional) Error object only present if refresh command fails + * @param {string} stdout Standard output from refresh command + * @param {string} stderr Error output from command if fails + */ _refreshCb (err, stdout, stderr) { if (err) { console.error(err) @@ -74,12 +112,26 @@ class wifi { //this._callback(null, { ssid : ssid, pwd : pwd.length }) this._callback = () => {} } + /** + * Wifi.setNetwork() - + * Function which initializes the processes for adding a wifi access point authentication + * + * @param {string} ssid SSID of network to configure + * @param {string} pwd Password of access point, plaintext + * @param {function} callback Function invoked after process is complete, or fails + */ setNetwork (ssid, pwd, callback) { this._entry = `network={\n\tssid="${ssid}"\n\tpsk="${pwd}"\n}\n` this._callback = callback this._ssid = ssid fs.readFile(filePath, 'utf8', this._readConfigCb) } + /** + * Wifi.getNetwork() - + * Executes command which gets the currently connected network + * + * @param {function} callback Function which is invoked after command is completed + */ getNetwork (callback) { exec(iwgetid, (err, stdout, stderr) => { if (err) { @@ -90,4 +142,4 @@ class wifi { } } -module.exports = new wifi() \ No newline at end of file +module.exports = new Wifi() \ No newline at end of file