52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
/*
|
|
* A tcp customer/client to talk with the i2c bus and scan the bus for devices
|
|
*
|
|
*/
|
|
|
|
const PATH = 'i2c-bus'
|
|
|
|
import Base from '@uci/base'
|
|
|
|
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
|
;
|
|
(async () => {
|
|
|
|
let relays = new Base({id:'pipe-i2c-client', sockets:'uc#c>n', 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)
|
|
})
|