changed options processing

makes named pipe socket listener by default
add tcp listener with simple boolean for default or
by giving a port number
master
David Kebler 2018-02-23 13:49:23 -08:00
parent cab186f1f1
commit 8bd22e4023
1 changed files with 5 additions and 4 deletions

View File

@ -20,16 +20,17 @@ const LOG_OPTS = {
export default class Bus extends Base {
constructor(opts) {
log = logger.child(LOG_OPTS)
// TODO make ts options when tcp:true option or tcp:port
if (opts.path) opts.ns ={path:opts.path}
if(!opts.ns) opts.ns = {path: (process.env.SOCKETS_DIR || __dirname) + '/i2c-bus.sock'}
opts.sockets = (opts.sockets ? (opts.sockets+',') : '') + 'ns#s>n'
if(opts.ts) {
opts.ts.port = opts.ts.port || 1776
if(opts.tcp) {
if (typeof opts.tcp==='number') opts.ts ={port:opts.tcp}
else opts.ts ={port:1776}
opts.sockets = (opts.sockets ? (opts.sockets+',') : '') + 'ts#s>t'
}
super(opts)
log.info({opts:opts},'created bus with these opts')
console.log({opts:opts},'created bus with these opts')
console.log({opts:opts},'\n created bus with these opts')
this.busnum = opts.busnum || 1
this.i2cbus = i2c.open(this.busnum, () => {})
this.bus = bus_funcs