/* * i2c bus unix socket and client in one for demo * */ import Base from '../../uci-base/src/base' const PATH = '/opt/uci/uci-base/src/unix.sock' const delay = time => new Promise(res=>setTimeout(()=>res(),time)) ; (async () => { let scanner = new Base({id:'pipe-i2c-client', sockets:'uc', path:PATH}) scanner.reply = function (packet) { let addresses = packet.response.map(device => { return device.toString(16)}) // console.log(packet) console.log('==== device hex addreses on i2cbus ===\n',addresses) } await scanner.init() console.log('=============sending============') let packet = {cmd:'scan'} console.dir(packet) await scanner.send(packet) await delay(3000) process.kill(process.pid, 'SIGTERM') })().catch(err => { console.error('FATAL: UNABLE TO START SYSTEM!\n',err) })