2018-02-13 18:18:03 -08:00
|
|
|
/*
|
|
|
|
* i2c bus unix socket and client in one for demo
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Base from '../../uci-base/src/base'
|
|
|
|
|
|
|
|
const PATH = '/opt/sockets/mcp.sock'
|
|
|
|
|
|
|
|
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
|
|
|
;
|
|
|
|
(async () => {
|
|
|
|
|
|
|
|
let relays = new Base({id:'relays', sockets:'uc#c>n', uc:{path:PATH}})
|
|
|
|
|
|
|
|
relays.reply = function (packet) {
|
|
|
|
// console.log('for request ',packet._header.request)
|
|
|
|
// console.log('mcp status is ',packet.status)
|
|
|
|
}
|
|
|
|
|
|
|
|
await relays.init()
|
|
|
|
console.log('=============sending============')
|
|
|
|
|
|
|
|
await relays.send({cmd:'pin.cfg', pins:'all'})
|
|
|
|
await relays.send({cmd:'pin.state.off', pins:'all' })
|
|
|
|
|
|
|
|
for(let i=1;i<=8;i +=2){
|
|
|
|
await relays.send({cmd:'pin.state.on', pins:i})
|
|
|
|
}
|
|
|
|
console.log((await relays.send({cmd:'pin.status', pins:'all'})).status)
|
|
|
|
console.log((await relays.send({cmd:'pin.status', pins:'3'})).status.pins)
|
|
|
|
await delay(3000)
|
|
|
|
await relays.send({cmd:'pin.state.off', pins:'all'})
|
|
|
|
|
2018-02-14 19:01:08 -08:00
|
|
|
relays.socket.uc.end()
|
2018-02-13 18:18:03 -08:00
|
|
|
process.kill(process.pid, 'SIGTERM')
|
|
|
|
|
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
2018-02-14 19:01:08 -08:00
|
|
|
process.kill(process.pid, 'SIGTERM')
|
2018-02-13 18:18:03 -08:00
|
|
|
})
|