/* * A tcp customer/client to talk with the i2c bus manipulate an i2c device * */ const DEVICE = (process.env.BUS_DEVICE || 'scan') const TRANSPORT = (process.env.TRANSPORT || 'tcp') import Base from '@uci/base' // import {test, reply } from './relays' const HOST = (process.env.BUS_HOST || 'sbc') const PORT = (process.env.BUS_PORT || 1776) const ADDRESS = 39 let options = {id:'i2c-client', useRootNS:true} ; (async () => { // import not supported by eslint, but esm does so ignore parsing error let {test,reply} = await import(`./${DEVICE}`) let client = new Base(options) if (TRANSPORT==='tcp') client.addSocket('tcp','c','t',{host:HOST, port:1776}) else client.addSocket('np','c','n',{path:'i2c-bus'}) client.reply = reply // add reply processor await client.init() await test.call(client,ADDRESS) process.kill(process.pid, 'SIGTERM') })().catch(err => { console.error('FATAL: UNABLE TO START SYSTEM!\n',err) })