2018-03-04 15:09:18 -08:00
|
|
|
import Interrupts from '../src/interrupts'
|
|
|
|
|
2020-01-06 23:26:12 -08:00
|
|
|
const PINS = [9,10]
|
2018-03-04 15:09:18 -08:00
|
|
|
|
2019-12-23 14:15:50 -08:00
|
|
|
const EDGE = process.env.EDGE || 'both'
|
|
|
|
const REMOTE_HOST = process.env.REMOTE_HOST || 'sbc'
|
2020-01-06 23:26:12 -08:00
|
|
|
const REMOTE_PORT = process.env.REMOTE_PORT || 9001
|
2019-08-15 14:05:30 -07:00
|
|
|
|
2020-01-06 23:26:12 -08:00
|
|
|
let interrupts = new Interrupts(PINS, { id:'multi-interrupt', cmd:'interrupt.find', resetCmd:'interrupt.reset', resetInterval:0, edge:EDGE })
|
2019-12-23 14:15:50 -08:00
|
|
|
|
2020-01-06 23:26:12 -08:00
|
|
|
interrupts.amendConsumerCommands( {reply:() => {}} )
|
2019-08-15 14:05:30 -07:00
|
|
|
|
2019-12-23 14:15:50 -08:00
|
|
|
interrupts.on('log', ev => {
|
2020-01-06 23:26:12 -08:00
|
|
|
if (ev.level !== 'debug' && ev.level !== 'trace') console.log(`LOG:'--${ev.level}-- ${ev.msg}`)
|
|
|
|
// console.log(`LOG:'--${ev.level}-- ${ev.msg}`)
|
|
|
|
})
|
2018-03-04 15:09:18 -08:00
|
|
|
|
2019-12-23 14:15:50 -08:00
|
|
|
interrupts.on('connection:socket', ev => {
|
2020-01-06 23:26:12 -08:00
|
|
|
console.log(`remote socket connection event ${ev.socketName}: ${ev.state}`)
|
2019-08-15 14:05:30 -07:00
|
|
|
})
|
2018-03-04 15:09:18 -08:00
|
|
|
|
|
|
|
;
|
|
|
|
(async () => {
|
|
|
|
|
2020-01-06 23:26:12 -08:00
|
|
|
interrupts.registerSocket('interrupt','c','t',{host:REMOTE_HOST, port:REMOTE_PORT, name:'interrupt', data:{pins:PINS, type:'interrupt'}})
|
|
|
|
// interrupts.registerSocket('listen','s','t',{port:1777})
|
2018-03-04 15:09:18 -08:00
|
|
|
await interrupts.init()
|
2019-12-23 14:15:50 -08:00
|
|
|
await interrupts.socketsInit()
|
2018-03-04 15:09:18 -08:00
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
// process.kill(process.pid, 'SIGTERM')
|
|
|
|
})
|