improved opts processing
parent
b6ef63e6bb
commit
8fb4dbd788
|
@ -1,11 +1,17 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"modules": true,
|
||||||
|
"spread" : true,
|
||||||
|
"restParams" : true
|
||||||
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"es6": true,
|
"es6": true,
|
||||||
"node": true,
|
"node": true,
|
||||||
"mocha": true
|
"mocha": true
|
||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 2017
|
"ecmaVersion": 2017,
|
||||||
|
"sourceType": "module"
|
||||||
},
|
},
|
||||||
"extends": "eslint:recommended",
|
"extends": "eslint:recommended",
|
||||||
"rules": {
|
"rules": {
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* i2c bus with both unix and tcp socket using defaults. For TCP that is host OS name and port 8080
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
import Device from '../src/device-packet'
|
||||||
|
// const PATH = ''
|
||||||
|
|
||||||
|
;
|
||||||
|
(async () => {
|
||||||
|
|
||||||
|
let device = new Device({id:'an i2c device', address:0x27, bus:{host:'sbc'} })
|
||||||
|
|
||||||
|
device.reply = function (packet) {
|
||||||
|
console.log('for request ',packet._header)
|
||||||
|
console.log('bus response is ',packet.response)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log((await device.init()).scan)
|
||||||
|
process.kill(process.pid, 'SIGTERM')
|
||||||
|
|
||||||
|
})().catch(err => {
|
||||||
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
||||||
|
process.kill(process.pid, 'SIGTERM')
|
||||||
|
})
|
8
index.js
8
index.js
|
@ -1,8 +0,0 @@
|
||||||
let opts = {
|
|
||||||
dirname: __dirname + '/src',
|
|
||||||
// http://stackoverflow.com/questions/2078915/a-regular-expression-to-exclude-a-word-string
|
|
||||||
filter: /^(?!index)([^\.].*)\.js?$/,
|
|
||||||
recursive: false,
|
|
||||||
merge: true // remove or comment to have each file in /lib be a prop/key in library...see node-require-all
|
|
||||||
}
|
|
||||||
module.exports = require('@uci/require-all')(opts)
|
|
11
package.json
11
package.json
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"name": "@uci/i2c",
|
"name": "@uci/i2c-device",
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"description": "Bus and Device Classes for I2C Interfacing",
|
"description": "Device Classes for I2C Interfacing",
|
||||||
"main": "index.js",
|
"main": "src/",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"testw": "./node_modules/.bin/mocha --reporter list --recursive --watch",
|
"testw": "./node_modules/.bin/mocha --reporter list --recursive --watch",
|
||||||
"test": "istanbul cover ./node_modules/.bin/_mocha test/ --report lcovonly -- -R spec --recursive && codecov || true"
|
"test": "istanbul cover ./node_modules/.bin/_mocha test/ --report lcovonly -- -R spec --recursive && codecov || true"
|
||||||
|
@ -23,9 +23,10 @@
|
||||||
"url": "https://github.com/uCOMmandIt/i2c/issues"
|
"url": "https://github.com/uCOMmandIt/i2c/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/uCOMmandIt/i2c#readme",
|
"homepage": "https://github.com/uCOMmandIt/i2c#readme",
|
||||||
|
"@std/esm": "cjs",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@uci/require-all": "^2.x",
|
"@std/esm": "^0.18.0",
|
||||||
"i2c-bus": "^1.x"
|
"i2c-bus": "^1.x",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
/node_modules/
|
|
@ -15,19 +15,12 @@ const LOG_OPTS = (id) => {
|
||||||
|
|
||||||
export default class Device extends Base {
|
export default class Device extends Base {
|
||||||
constructor(opts) {
|
constructor(opts) {
|
||||||
|
if (!opts.bus) opts.bus ={}
|
||||||
opts.bus.name = opts.bus.name || 'bus' //optional bus socket name
|
opts.bus.name = opts.bus.name || 'bus' //optional bus socket name
|
||||||
opts.sockets = opts.sockets ||''
|
|
||||||
// either device process instance runs on same host (use named pipe) or not (the host of bus must be given)
|
// either device process instance runs on same host (use named pipe) or not (the host of bus must be given)
|
||||||
if (opts[opts.bus.name]) {
|
if (opts[opts.bus.name].host) opts[opts.bus.name].port = opts[opts.bus.name].port || 1776
|
||||||
if (opts[opts.bus.name].host) {
|
else opts[opts.bus.name].path = opts[opts.bus.name].path || (process.env.SOCKETS_DIR || __dirname) + '/i2c-bus.sock'
|
||||||
opts.sockets = opts.sockets + opts.bus.name+'#c>t'
|
opts.sockets = (opts.sockets || '') + opts.bus.name + '#c>' + ((opts[opts.bus.name].path) ? 'n' :'t')
|
||||||
opts[opts.bus.name].port = opts[opts.bus.name].port || 1776
|
|
||||||
}
|
|
||||||
if (opts[opts.bus.name].path) opts.sockets = opts.bus.name+'#c>n'
|
|
||||||
} else {
|
|
||||||
opts[opts.bus.name] = { path : (process.env.SOCKETS_DIR || __dirname) + '/i2c-bus.sock' }
|
|
||||||
opts.sockets = opts.bus.name+'#c>t'
|
|
||||||
}
|
|
||||||
console.log(opts)
|
console.log(opts)
|
||||||
super(opts)
|
super(opts)
|
||||||
log = logger.child(LOG_OPTS(this.id))
|
log = logger.child(LOG_OPTS(this.id))
|
||||||
|
|
Loading…
Reference in New Issue