refactor socket options
parent
78397d22bf
commit
cab186f1f1
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"name": "@uci/i2c-bus",
|
"name": "@uci/i2c-bus",
|
||||||
"version": "0.1.0",
|
"version": "0.1.2",
|
||||||
"description": "I2c Bus Classes for Communication to I2C bus via socket or direct call",
|
"description": "I2c Bus Classes for Communication to I2C bus via socket or direct call",
|
||||||
"main": "src/bus",
|
"main": "src/bus-packet.mjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"busa": "node_modules/.bin/nodemon --require @std/esm --watch ../ examples/bus",
|
"busa": "node_modules/.bin/nodemon --require @std/esm --watch ../ examples/bus",
|
||||||
"bus": "SOCKET_DIR=/opt/sockets node_modules/.bin/nodemon --require @std/esm examples/bus",
|
"bus": "SOCKET_DIR=/opt/sockets node_modules/.bin/nodemon --require @std/esm examples/bus",
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
import i2c from 'i2c-bus'
|
import i2c from 'i2c-bus'
|
||||||
import pify from 'pify'
|
import pify from 'pify'
|
||||||
import btc from 'better-try-catch'
|
import btc from 'better-try-catch'
|
||||||
// import Base from '@uci/base'
|
import Base from '@uci/base'
|
||||||
import Base from '../../uci-base/src/base'
|
// import Base from '../../uci-base/src/base'
|
||||||
|
|
||||||
import logger from '../../uci-logger/src/logger'
|
// import logger from '../../uci-logger/src/logger'
|
||||||
|
import logger from '@uci/logger'
|
||||||
let log = {}
|
let log = {}
|
||||||
const LOG_OPTS = {
|
const LOG_OPTS = {
|
||||||
repo:'uci-i2c-bus',
|
repo:'uci-i2c-bus',
|
||||||
|
@ -19,11 +20,16 @@ const LOG_OPTS = {
|
||||||
export default class Bus extends Base {
|
export default class Bus extends Base {
|
||||||
constructor(opts) {
|
constructor(opts) {
|
||||||
log = logger.child(LOG_OPTS)
|
log = logger.child(LOG_OPTS)
|
||||||
opts.sockets = opts.sockets || 'us#s>n,ts#s>t'
|
// TODO make ts options when tcp:true option or tcp:port
|
||||||
opts.ts = opts.ts || { port:1776 }
|
if(!opts.ns) opts.ns = {path: (process.env.SOCKETS_DIR || __dirname) + '/i2c-bus.sock'}
|
||||||
opts.us = opts.us || {path: (process.env.SOCKETS_DIR || __dirname) + '/i2c-bus.sock'}
|
opts.sockets = (opts.sockets ? (opts.sockets+',') : '') + 'ns#s>n'
|
||||||
log.info({opts:opts},'create bus with these opts')
|
if(opts.ts) {
|
||||||
|
opts.ts.port = opts.ts.port || 1776
|
||||||
|
opts.sockets = (opts.sockets ? (opts.sockets+',') : '') + 'ts#s>t'
|
||||||
|
}
|
||||||
super(opts)
|
super(opts)
|
||||||
|
log.info({opts:opts},'created bus with these opts')
|
||||||
|
console.log({opts:opts},'created bus with these opts')
|
||||||
this.busnum = opts.busnum || 1
|
this.busnum = opts.busnum || 1
|
||||||
this.i2cbus = i2c.open(this.busnum, () => {})
|
this.i2cbus = i2c.open(this.busnum, () => {})
|
||||||
this.bus = bus_funcs
|
this.bus = bus_funcs
|
||||||
|
@ -84,8 +90,6 @@ const validateArgs = function (packet) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const bus_funcs = {
|
const bus_funcs = {
|
||||||
scan: function () { return pify(this.i2cbus.scan).bind(this.i2cbus)() },
|
scan: function () { return pify(this.i2cbus.scan).bind(this.i2cbus)() },
|
||||||
close: function () { return pify(this.i2cbus.close).bind(this.i2cbus)() },
|
close: function () { return pify(this.i2cbus.close).bind(this.i2cbus)() },
|
||||||
|
|
Loading…
Reference in New Issue