diff --git a/.gitignore b/.gitignore index 2882970..1a359fd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /coverage/ /syncd/ *.lock +*.travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8ffd227..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: node_js - -node_js: - - '4.0' - - '5.0' - - '6.0' - - 'node' - -sudo: false - -script: npm test - -after_success: - - bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" diff --git a/package.json b/package.json index 83ff848..537da69 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@uci/mcp", "main": "src", - "version": "0.1.28", + "version": "0.1.31", "description": "Classes and Helper Functions for using the MCP chip on I2C Bus", "scripts": { "relays": "node -r esm examples/relays", @@ -29,8 +29,8 @@ }, "homepage": "https://github.com/uCOMmandIt/uci-mcp#readme", "dependencies": { - "@uci/i2c-device": "^0.1.14", - "@uci-utils/logger": "0.0.13", + "@uci/i2c-device": "^0.1.15", + "@uci-utils/logger": "0.0.14", "@uci-utils/byte": "^0.2.2" }, "devDependencies": { diff --git a/src/commands.js b/src/commands.js index d3b64ec..3c2c398 100644 --- a/src/commands.js +++ b/src/commands.js @@ -25,7 +25,7 @@ export default { let byte = _.byteFormat(setting.val, { in: setting.fmt, out: 'DEC' }) if (byte < 128) byte += 128 // make sure BANK=1 remains on let reg = this.chip17 ? 0x0A : 0x05 - log.debug ({msg:'writing chip configuration', chip17:this.chip17, register:reg, id:this.id, address:this.address}) + log.debug ({cmd:'chip.cfg', line:28, msg:'writing chip configuration', chip17:this.chip17, register:reg, id:this.id, address:this.address}) bus = await this.bus.write(reg,byte) if (bus.error) return bus bus = await this.bus.read(0x05) @@ -50,7 +50,7 @@ export default { else cfg = PIN.cfgset[packet.cfg] for(let name of Object.keys(PIN.setting)) { let op = cfg[name] ? 'on' : 'off' - log.debug({msg:'setting pin register', operation:op, registerName:name, resgisterNum:PIN.setting[name]}) + log.debug({cmd:'pin.cfg', line:28, msg:'setting pin register', operation:op, registerName:name, resgisterNum:PIN.setting[name]}) let busreply = await this.commands.pin._state(packet,op,PIN.setting[name]) if (busreply.error) return busreply reply.status[name] = busreply.status @@ -79,7 +79,7 @@ export default { }, _state: async function(packet,op,reg){ reg = (reg!==undefined)? reg : PIN.cmd.gpio - log.debug({msg:'_state change request', operation:op, register:reg, packet:packet}) + log.debug({cmd:'pin._state', line:82, msg:'_state change request', operation:op, register:reg, packet:packet}) let reply = { cmd:'reply'} let pins = parsePins(packet.pins) let state = new _.Byte() @@ -91,7 +91,7 @@ export default { bus = await this.bus.read(sreg(reg,packet.port)) if (bus.error) return bus state.value = bus.response - log.debug({msg:'after setting pin state', prev:state.prv, new:state.value}) + log.debug({cmd:'pin._state', line:94, msg:'after setting pin state', prev:state.prv, new:state.value}) reply.status = state.bwOp(pins.value,'check',{in:'PLC', out:'PLC'}) return reply }, diff --git a/src/mcp230xx.js b/src/mcp230xx.js index 9e23572..e924f1d 100644 --- a/src/mcp230xx.js +++ b/src/mcp230xx.js @@ -26,7 +26,7 @@ class MCP230XX extends Device { await super.init() let res = await this.commands.chip.cfg({cfg:this.chipCfg}) if (res.error) { - log.fatal({msg:'unable to configure mcp chip', error:res.error, cfg:this.chipCfg, address:this.address}) + log.fatal({method:'init', line:82, msg:'unable to configure mcp chip', error:res.error, cfg:this.chipCfg, address:this.address}) throw `${res.error} at address ${this.address}/${this.address.toString(16)}` } await this.commands.pin.cfg({pins:'all'}) //pins are outputs by default diff --git a/src/mcp230xxi.js b/src/mcp230xxi.js index b8284de..c006bd0 100644 --- a/src/mcp230xxi.js +++ b/src/mcp230xxi.js @@ -18,7 +18,7 @@ class MCP230XXi extends MCP230XX { let opts = Object.assign({},options) // don't allow passed options to mutate if (opts.interrupt) delete opts.interrupt.pins // if .interrupt was passed then .pins must be removed delete opts.sockets // .sockets is used by uci base so clear it if was used by enduser and sent by mistake - log.debug({msg:'passed options before setting',options:opts}) + log.debug({method:'constructor', line:21, msg:'passed options before setting',options:opts}) super(opts) this.opts = opts @@ -29,7 +29,7 @@ class MCP230XXi extends MCP230XX { id: this.id }) - log.info({ opts: opts, msg:'mcp interrupt options after calling super() on base'}) + log.debug({ method:'constructor', line:32, opts: opts, msg:'mcp interrupt options after calling super() on base'}) pins.forEach(pin => { this[pin] = opts['i' + pin] || {} @@ -39,7 +39,7 @@ class MCP230XXi extends MCP230XX { this.addNamespace('commands', 'c') // add access via push to same commands this._interruptProcess = process this.ready = false - log.info({ opts: opts, pins: pins }, 'options for mcp interrupt processor') + log.debug({ opts: opts, pins: pins }, 'options for mcp interrupt processor') } async init() { @@ -49,11 +49,11 @@ class MCP230XXi extends MCP230XX { // this will set default type to internal pullup, only need to to change indivial pins to external if desired await this.commands.pin.cfg({port:'A',pins:'all',cfg:'input_interrupt'}) let status = await this._resetInterrupt('A') - log.debug('configure all port A pins as interrupts. Reset port A interrupt', status) + log.debug({method:'init', line:52, msg:'default configure all port A pins as interrupts. Resetting port A interrupt', status:status}) if (this.chip17) { await this.commands.pin.cfg({port:'B',pins:'all',cfg:'input_interrupt'}) let status = await this._resetInterrupt('B') - log.debug('configure all port B pins as interrupts. Reset port B interrupt', status) + log.debug({method:'init', line:52, msg:'default configure all port B pins as interrupts. Resetting port B interrupt', status:status}) } } async _readyInterrupt(port) { @@ -69,9 +69,8 @@ class MCP230XXi extends MCP230XX { } async _resetInterrupt(port) { - log.debug(`resetting interrupt for port ${port || 'A'},${this.id} arg ${port !== 'B' ? 0x08 : 0x18}`) await this.bus.read(port !== 'B' ? 0x08 : 0x18) // 0x08 is intcap interrupt capture register - console.log('reset interrupt==============') + log.debug({method:'_resetInterrupt', line:72, msg: `reset interrupt for port ${port || 'A'},${this.id} arg ${port !== 'B' ? 0x08 : 0x18}`}) return(await this._readyInterrupt(port)) } @@ -112,27 +111,25 @@ const icommands = { reset: async function(packet) { // pin is interrupt pin on sbc for port let port = packet.port || this._getPortByPin(packet.pin) - log.info({ packet: packet, port:port, msg:`remote interrupt reset for port ${port}`}) + log.error({cmd:'interrupt.reset', line:114, packet: packet, port:port, msg:`forced remote interrupt reset for port ${port}`}) await this._resetInterrupt(port) let res = await this._readyInterrupt(port) return {cmd:'reply', request:'interrupt.reset', port:port, ipin:packet.pin, ready:res} }, // given a gpio interrupt then push a packet with cmd: 'pin.interrupt.find' and pin: the gpio pin number find: async function(inter) { - console.log('interrupt find calledxxxxx', inter, this.ready) if (this.ready) { // protects tripped interrupt before it's fully initialized, or interrupt requests arriving before porcessing is complete this.ready = false - log.debug({msg:'raw packet from interrupt, finding pin that caused interrupt', inter:inter}) + log.debug({cmd:'interrupt.find', line:124, msg:'raw packet from interrupt, finding pin that caused interrupt', inter:inter}) let packet = { pins: 'all', reg: 'intf' } packet.port = inter.port || this._getPortByPin(inter.pin) let res = await this.commands.pin.status(packet) // read port interrupt status let status = await this._resetInterrupt(packet.port) - // console.log('interrupt reset ready?', status) - log.debug({interrupt:res, reset:status, msg:'interrupt read and reset'}) this.ready = true + log.debug({cmd:'interrupt.find', line:130, interrupt:res, reset:status, msg:'interrupt read and reset'}) if (!res.status) { - log.warn({inter:inter, msg:'no pin associated with interrupt'}) + log.warn({cmd:'interrupt.find', line:132, inter:inter, msg:'no pin associated with interrupt'}) return { error: 'no pin associated with interrupt' } } let pin = byteFormat(res.status.port, { in: 'ARY', out: 'PLC' }) @@ -147,14 +144,11 @@ const icommands = { delete res.status res.interrupt_ready = status || false res.state = (await this.commands.pin.status(packet)).status.pins[0][1] - // console.log('emitting local on interrupt') this.emit('interrupt',Object.assign({},res)) // emit for end user purposes, don't allow mutation - // this.emit('interrupt') // emit for end user purposes, don't allow mutation - // console.log('============emitted now calling processor=======================================') this._interruptProcess(res) return res } else { - log.warn({inter:inter, msg:'no pin associated with interrupt'}) + log.warn({cmd:'interrupt.find', line:151, inter:inter, msg:'no pin associated with interrupt'}) return { error: 'no pin associated with interrupt' } } }