/* * * */ import { MCP230XXi } from '../src' const HOST = process.env.BUS_HOST const PATH = process.env.BUS_PATH const PORT = process.env.BUS_PORT || 1776 const ADDRESS = process.env.DEVICE_ADDR || 0x26 const CHIP17 = !!process.env.CHIP17 || true const LISTEN_PORT = process.env.PORT || 9001 let switches = new MCP230XXi([9,10],{id:'switches', chip17:CHIP17, path:PATH, host:HOST, port:PORT, address:ADDRESS, iport:LISTEN_PORT}) // switches.registerSocket('interrupt','c','t',{host:'switchesd.local', port:1777}) ; (async () => { if (process.env.VERBOSE==='true') { switches.on('log', async log => { if (log.level!=='trace') { console.log( 'LOG:',log.level,':', log.msg, 'socket:',log.socketName, ) if (log.packet) console.dir(log.packet) } }) switches.on('connection:socket', async ev => { console.log('connection event: outbound > ', ev.state,'to socket',ev.socketName)// if (ev.state ==='connected') switches.duplex = true }) switches.on('connection:consumer', async ev => { // console.log(ev) console.log('connection event: inbound >', ev.state,'from consumer',ev.name)// if (ev.state ==='connected') switches.duplex = true }) } console.log('ready observers for switches', switches.ready.observerNames) switches.ready.addObserverDetails('bus',{msg:'this is some details related to bus observer'}) switches.ready.subscribe(x=>{ console.log('=====================switches ready================?',x ? 'YES':'NO') console.log('what has failed: ',switches.ready.failure,' details:', switches.ready.details.get(switches.ready.failure)||'none') }) // this.ready.subscribe('interrupt:connected',(res)=>console.log('interrupt connected............',res)) // this.ready.subscribe('mcp',(res)=>console.log('mcp............',res)) // this.ready.subscribe('interrupt:reset',(res)=>console.log('interrupt reset............',res)) let res = await switches.socketsInit() if (res.errors) console.log(res) })().catch(err => { console.error('FATAL: UNABLE TO START SYSTEM!\n',err) })