/* * i2c bus unix socket and client in one for demo * */ import Base from '../../uci-base/src/base' const PATH = '/opt/sockets/mcp.sock' const delay = time => new Promise(res=>setTimeout(()=>res(),time)) ; (async () => { let mcpclient = new Base({id:'mcpclient', sockets:'uc#c>n', uc:{path:PATH}}) mcpclient.reply = function (packet) { console.log('for request ',packet._header.request) console.log('mcp status is ',packet.status) } await mcpclient.init() console.log('=============sending============') // const pins='2,3,4' // const pins=3 // const pins='all' // const pins=[1,3,5,7] let packet = {cmd:'pin.cfg', pins:'all'} await mcpclient.send(packet) packet = {cmd:'pin.cfg', pins:'all', port:'B'} await mcpclient.send(packet) packet = {cmd:'pin.state.off', pins:'all' } await mcpclient.send(packet) packet = {cmd:'pin.state.off', pins:'all', port:'B' } await mcpclient.send(packet) packet = {cmd:'pin.state.on', pins:'1,7', port:'B' } await mcpclient.send(packet) packet = {cmd:'pin.state.on', pins:'3,4'} await mcpclient.send(packet) packet = {cmd:'pin.status', pins:'all'} await mcpclient.send(packet) packet = {cmd:'pin.status', pins:'all', port:'B'} await mcpclient.send(packet) // mcpclient.send(packet) // await delay(1000) // packet = {cmd:'pin.state.on', pins:pins} // console.dir(packet) // mcpclient.send(packet) // await delay(1000) // packet = {cmd:'pin.status', reg:'xintf', pins:pins} // console.dir(packet) // mcpclient.send(packet) // await delay(1000) // packet = {cmd:'pin.status', pins:pins} // console.dir(packet) // mcpclient.send(packet) // await delay(1000) // packet = {cmd:'pin.cfg', pins:pins, cfg:'toggle_switch'} // console.dir(packet) // mcpclient.send(packet) // await delay(1000) // packet = {cmd:'pin.cfg', pins:pins} // console.dir(packet) // mcpclient.send(packet) // await delay(1000) // packet = {cmd:'pin.state.on', pins:pins, } // console.dir(packet) // mcpclient.send(packet) // await delay(1000) // packet = {cmd:'pin.state.toggle', pins:pins, } // console.dir(packet) // mcpclient.send(packet) // await delay(1000) // packet = {cmd:'pin.state.toggle', pins:pins, } // console.dir(packet) // mcpclient.send(packet) // packet = {cmd:'pin.cfg', pins:3} // console.dir(packet) // mcpclient.send(packet) await delay(10000) process.kill(process.pid, 'SIGTERM') })().catch(err => { console.error('FATAL: UNABLE TO START SYSTEM!\n',err) })