2018-01-31 18:42:11 -08:00
|
|
|
/*
|
|
|
|
* A tcp customer/client to talk with the i2c bus and scan the bus for devices
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-02-07 10:41:56 -08:00
|
|
|
const PATH = '/opt/sockets/i2c-bus.sock'
|
2018-01-31 18:42:11 -08:00
|
|
|
|
|
|
|
import Base from '../../uci-base/src/base'
|
|
|
|
// import Base from '@uci/base'
|
|
|
|
|
|
|
|
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
|
|
|
;
|
|
|
|
(async () => {
|
|
|
|
|
2018-02-04 14:19:44 -08:00
|
|
|
let relays = new Base({id:'pipe-i2c-client', sockets:'uc#c>n', uc:{path:PATH}})
|
2018-01-31 18:42:11 -08:00
|
|
|
|
|
|
|
relays.reply = function (packet) {
|
|
|
|
// console.log(packet.bus)
|
2018-02-01 23:58:54 -08:00
|
|
|
console.log(`response from relays for ${packet.cmd_sent}:`,packet.args, `was ${packet.response}`)
|
2018-01-31 18:42:11 -08:00
|
|
|
}
|
|
|
|
await relays.init()
|
|
|
|
console.log('=============sending============')
|
2018-02-01 23:58:54 -08:00
|
|
|
let packet = {cmd:'read', args:{address:39 ,cmd: 0} }
|
|
|
|
console.dir(packet)
|
2018-01-31 18:42:11 -08:00
|
|
|
await relays.send(packet)
|
2018-02-01 23:58:54 -08:00
|
|
|
packet = {cmd:'write', args:{address:39,cmd: 0, byte:0} }
|
|
|
|
console.dir(packet)
|
2018-01-31 18:42:11 -08:00
|
|
|
await relays.send(packet)
|
2018-02-01 23:58:54 -08:00
|
|
|
packet = {cmd:'read', args:{address:39 ,cmd:0} }
|
|
|
|
console.dir(packet)
|
2018-01-31 18:42:11 -08:00
|
|
|
await relays.send(packet)
|
2018-02-01 23:58:54 -08:00
|
|
|
packet = {cmd:'write', args:{address:39,cmd: 9, byte:255} }
|
|
|
|
console.dir(packet)
|
2018-01-31 18:42:11 -08:00
|
|
|
await relays.send(packet)
|
2018-02-01 23:58:54 -08:00
|
|
|
packet = {cmd:'read', args:{address:39 ,cmd:9} }
|
|
|
|
console.dir(packet)
|
2018-01-31 18:42:11 -08:00
|
|
|
await relays.send(packet)
|
|
|
|
await delay(1000)
|
2018-02-01 23:58:54 -08:00
|
|
|
packet = {cmd:'write', args:{address:39,cmd: 9, byte:0} }
|
|
|
|
console.dir(packet)
|
2018-01-31 18:42:11 -08:00
|
|
|
await relays.send(packet)
|
2018-02-01 23:58:54 -08:00
|
|
|
packet = {cmd:'read', args:{address:39 ,cmd:9} }
|
|
|
|
console.dir(packet)
|
2018-01-31 18:42:11 -08:00
|
|
|
await relays.send(packet)
|
|
|
|
|
|
|
|
await delay(1000)
|
|
|
|
process.kill(process.pid, 'SIGTERM')
|
|
|
|
|
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
})
|