2019-09-09 13:26:02 -07:00
|
|
|
/*
|
|
|
|
* 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'
|
|
|
|
|
|
|
|
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
|
2019-09-11 18:34:54 -07:00
|
|
|
let {test,reply,error} = await import(`./${DEVICE}`)
|
2019-09-09 13:26:02 -07:00
|
|
|
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
|
2019-09-11 18:34:54 -07:00
|
|
|
client.error = error
|
|
|
|
client.on('pushed', packet => {
|
|
|
|
if (packet.error) {
|
|
|
|
console.log('=======pushed error received=======\n', packet.error)
|
|
|
|
console.log('==================')
|
|
|
|
}
|
|
|
|
})
|
2019-09-09 13:26:02 -07:00
|
|
|
await client.init()
|
|
|
|
await test.call(client,ADDRESS)
|
|
|
|
process.kill(process.pid, 'SIGTERM')
|
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
})
|