32 lines
860 B
JavaScript
32 lines
860 B
JavaScript
/*
|
|
* A tcp customer/client to talk with the i2c bus and scan the bus for devices
|
|
*
|
|
*/
|
|
import Base from '@uci/base'
|
|
const HOST = (process.env.BUS_HOST || 'sbc')
|
|
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
|
;
|
|
(async () => {
|
|
|
|
let scanner = new Base({id:'tcp-i2c-client', sockets:'tc#c>t', tc:{host:HOST,port: 1776}})
|
|
|
|
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)
|
|
})
|