/* * A tcp customer/client to talk with the i2c bus and scan the bus for devices * */ const PATH = '/opt/uci/uci-base/src/unix.sock' import Base from '../../uci-base/src/base' // import Base from '@uci/base' const delay = time => new Promise(res=>setTimeout(()=>res(),time)) ; (async () => { let relays = new Base({sockets:'uc', path:PATH}) relays.reply = function (packet) { // console.log(packet.bus) console.log(`response from relays for ${packet.cmd_sent}:`,packet.args, `was ${packet.response}`) } await relays.init() console.log('=============sending============') let packet = {cmd:'read', args:{address:39 ,cmd: 0} } console.dir(packet) await relays.send(packet) packet = {cmd:'write', args:{address:39,cmd: 0, byte:0} } console.dir(packet) await relays.send(packet) packet = {cmd:'read', args:{address:39 ,cmd:0} } console.dir(packet) await relays.send(packet) packet = {cmd:'write', args:{address:39,cmd: 9, byte:255} } console.dir(packet) await relays.send(packet) packet = {cmd:'read', args:{address:39 ,cmd:9} } console.dir(packet) await relays.send(packet) await delay(1000) packet = {cmd:'write', args:{address:39,cmd: 9, byte:0} } console.dir(packet) await relays.send(packet) packet = {cmd:'read', args:{address:39 ,cmd:9} } console.dir(packet) await relays.send(packet) await delay(1000) process.kill(process.pid, 'SIGTERM') })().catch(err => { console.error('FATAL: UNABLE TO START SYSTEM!\n',err) })