0.1.18 update deps, clean up logging

master
David Kebler 2019-04-26 11:07:40 -07:00
parent f257831d1a
commit b665379223
2 changed files with 12 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@uci/i2c-bus", "name": "@uci/i2c-bus",
"version": "0.1.17", "version": "0.1.18",
"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",
"scripts": { "scripts": {
@ -32,8 +32,8 @@
"i2c-bus": "^4.0.7" "i2c-bus": "^4.0.7"
}, },
"dependencies": { "dependencies": {
"@uci/base": "^0.1.18", "@uci/base": "^0.1.20",
"@uci-utils/logger": "^0.0.13", "@uci-utils/logger": "^0.0.14",
"better-try-catch": "^0.6.2", "better-try-catch": "^0.6.2",
"pify": "^4.0.1" "pify": "^4.0.1"
}, },

View File

@ -24,7 +24,7 @@ class I2CBus extends Base {
opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'ts#s>t' opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'ts#s>t'
} }
super(opts) super(opts)
log.info({ opts: opts }, 'created bus with these opts') log.debug({ 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
@ -35,9 +35,10 @@ class I2CBus extends Base {
await super.init() await super.init()
} }
// TODO see if default processing of base can handle this now // TODO use the resplacement method instead of replacing _packetPorcess
// if none of these then call the default processor // or refactor bus_funcs and add to a namespace so default processing can be used
// could use the default if it included a validation hook plugin // which will allow adding more command to the this module
// can use a packet Hook to do validation.
async _packetProcess(sname, packet) { async _packetProcess(sname, packet) {
if (!packet.cmd) return { error: 'no cmd: key in packet', packet: packet } if (!packet.cmd) return { error: 'no cmd: key in packet', packet: packet }
if (this.bus[packet.cmd]) { if (this.bus[packet.cmd]) {
@ -48,11 +49,12 @@ class I2CBus extends Base {
packet.response = res || '' packet.response = res || ''
packet.cmd = 'reply' packet.cmd = 'reply'
return packet return packet
} else } else {
return { return {
error: 'no i2c bus function available for packet command', error: 'no i2c bus function available for packet command',
packet: packet packet: packet
} }
}
} }
} // end of Bus Packet Class } // end of Bus Packet Class
@ -114,11 +116,11 @@ const bus_funcs = {
) )
}, },
read: function(args) { read: function(args) {
// console.log('read: address, cmd', address, cmd) log.debug({msg:'read i2c bus', method:'read', line:118, args:args})
return pify(this.i2cbus.readByte).bind(this.i2cbus)(args.address, args.cmd) return pify(this.i2cbus.readByte).bind(this.i2cbus)(args.address, args.cmd)
}, },
write: function(args) { write: function(args) {
// console.log('write: address, cmd, byte', args.address, args.cmd, args.byte) log.debug({msg:'write i2c bus', method:'write', line:122, args:args})
return pify(this.i2cbus.writeByte.bind(this.i2cbus))( return pify(this.i2cbus.writeByte.bind(this.i2cbus))(
args.address, args.address,
args.cmd, args.cmd,