0.2.18 remove old options processing

add on interval reset option
add reconnect listener for sending a reset on reconnect
clean up logging
master
David Kebler 2019-04-26 11:13:50 -07:00
parent 8f22017fd1
commit 378dd51ad1
3 changed files with 15 additions and 50 deletions

View File

@ -1,7 +1,7 @@
{
"name": "@uci/interrupt",
"main": "src",
"version": "0.2.17",
"version": "0.2.18",
"description": "a class for adding interrupt processesing for gpio pins on Raspberry Pi and Similar SBCs",
"scripts": {
"single": "node -r esm examples/single",
@ -28,8 +28,8 @@
},
"homepage": "https://github.com/uCOMmandIt/uci-interrrupt#readme",
"dependencies": {
"@uci-utils/logger": "0.0.13",
"@uci/base": "^0.1.18",
"@uci-utils/logger": "0.0.14",
"@uci/base": "^0.1.20",
"death": "^1.1.0",
"onoff": "^4.1.1"
},

View File

@ -11,42 +11,9 @@ let log = logger({package:'@uci/interrupt', file:'/src/interrupt.js'})
class Interrupt extends Base {
constructor(pin, opts = {}) {
if (typeof pin !=='number') pin = parseInt(pin) // make sure pin is a number!
// opts.conPacket = (opts.resetCmd && !opts.conPacket) ? { cmd: opts.resetCmd, pin: pin } : opts.conPacket // will use either option
// log.debug({conPacket: opts.conPacket, msg:'connection packet for consumers'})
// if (opts.path || opts.itrn) {
// opts.itrn = opts.itrn || {}
// if (opts.path && typeof opts.path !=='boolean') opts.path = opts.path + ':' + pin
// if (typeof opts.path ==='boolean') opts.path = ''
// opts.itrn.path = opts.itrn.path || opts.path || 'interrupt:' + pin
// opts.itrn.conPacket = opts.conPacket
// opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'itrn#s>n'
// }
// if (opts.topic || opts.itrm) {
// opts.itrm = opts.itrm || {}
// opts.itrm.topics = opts.itrm.topic || opts.topic +'/'+ pin || 'interrupt/' + pin
// opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'itrm#s>m'
// }
//
// if (opts.itrw || opts.wport || opts.wport===0 ) {
// opts.itrw = opts.itrw || {}
// if (opts.wport) opts.wport = opts.wport + +pin
// opts.itrw.port = opts.itrw.port || opts.wport || 9100 + +pin
// opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'itrw#s>w'
// }
// // default is a tcp socket server at 9000+pin
// // if (opts.itrt || opts.port || opts.port===0 || !opts.sockets ) {
// if (opts.itrt || opts.port || opts.port===0 ) {
// opts.itrt = opts.itrt || {}
// if (opts.port) opts.port = opts.port + +pin
// opts.itrt.port = opts.itrt.port || opts.port || 9000 + +pin
// opts.itrt.conPacket = opts.conPacket
// opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'itrt#s>t'
// }
super(opts)
this.id = (opts.id || 'interrupt') + ':' + pin
log.info({ pins: pin, opts: opts }, 'created interrupt with these opts')
log.debug({ pins: pin, opts: opts, method:'constructor', line:16, msg:'created interrupt with these opts'})
this.pin_num = pin
this.resetCmd = opts.resetCmd || 'interrupt.reset'
this.resetInterval = opts.resetInterval * 1000 // sets an interval timeout to check on status and send/emit reset command
@ -82,26 +49,24 @@ class Interrupt extends Base {
// TODO devel mock versions for testing on other than sbc with gpios
this.pin = new Gpio(this.pin_num, 'in', this.edge, { debounceTimeout:this.wait })
console.log('initial connect reset sent',await this.reset())
let res = await this.reset()
log.debug({msg:'initial connect interrupt reset packet sent', ressponse:res, method:'init', line:53})
DeadJim( (signal,err) => {
log.warn({signal:signal, error:err, msg:'Interrupt was killed'})
log.warn({signal:signal, method:'init', line:56, error:err, msg:'Interrupt process was killed'})
this.pin.unwatchAll()
this.pin.unexport() // kill the kernel entry
})
log.debug({msg:'new interrupt pin created and watching', num:this.pin_num, status:await this.status() ? 'ready' : 'not ready', pin:this.pin, edge:this.edge,debounce:this.wait})
log.debug({msg:'new interrupt pin created and watching', method:'init', line: 62, num:this.pin_num, status:await this.status() ? 'ready' : 'not ready', pin:this.pin, edge:this.edge,debounce:this.wait})
log.debug('setting reconnect listener')
this.socket.mcp.on('reconnected', () => console.log('test listen reconnected'))
this.consumersListen('reconnected', () => {
log.debug('reconnected to a socket send a reset request')
this.reset()
log.debug({method:'init', line: 62, msg: 'setting reconnect listener'})
this.consumersListen('reconnected', async () => {
let res = await this.reset()
log.debug({msg:'reconnected, interrupt reset packet sent', ressponse:res, method:'init', line:67})
})
this.socket.mcp.emit('reconnected')
if (this.resetInterval) setInterval(this.commands.reset,this.resetInterval)
this.pin.watch( function (err,value) {
@ -114,7 +79,7 @@ class Interrupt extends Base {
// manual firing for testing
async fire(packet={}) {
log.info({msg:`mock manually firing interrupt for pin ${this.pin_num}`})
log.debug({method:'fire', line:82, msg:`mock manually firing interrupt for pin ${this.pin_num}`})
await this._interruptProcess(1)
packet.status = 'fired'
packet.ipin = this.pin_num

View File

@ -11,7 +11,7 @@ class Interrupts {
this.pins = pins
this.interrupt = {}
this.s = { fire:this.fire.bind(this)} // make fire available via consumer packet send
log = logger({ name: 'interrupts', id: this.id })
log = logger({ name: 'interrupts', id: this.id, package:'@uci/interrupt', file:'src/interrupts.js'})
let pinopts = {}
pins.forEach(pin => {
// remove per pin opts and store
@ -22,7 +22,7 @@ class Interrupts {
if (typeof pin !=='number') pin = parseInt(pin)
pinopts[pin] = Object.assign({}, opts, pinopts[pin])
pinopts[pin].id = (opts.id || 'interrupt') + ':' + pin
log.debug({ opts: pinopts[pin] }, `pin options for pin ${pin}`)
log.debug({ opts: pinopts[pin], method:'constructor', line:25, msg:`pin options for pin ${pin}`})
this.interrupt[pin] = new Interrupt(pin, pinopts[pin])
})
}