2018-02-08 09:19:46 -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 mcpclient = new Base({id:'mcpclient', sockets:'uc#c>n', uc:{path:PATH}})
|
|
|
|
|
|
|
|
await mcpclient.init()
|
|
|
|
console.log('=============sending============')
|
2018-02-10 15:28:51 -08:00
|
|
|
// let packet = {cmd:'chip.ack'}
|
|
|
|
// console.dir(packet)
|
|
|
|
// for (let i=0;i<20;i++){
|
|
|
|
// await delay(100)
|
|
|
|
// packet.num = i
|
|
|
|
// console.log('--------->',i)
|
|
|
|
// mcpclient.send(packet)
|
|
|
|
// }
|
|
|
|
|
2018-02-11 11:41:45 -08:00
|
|
|
// const pins='2,3,4'
|
|
|
|
// const pins=3
|
|
|
|
// const pins='all'
|
|
|
|
const pins=[1,3,5,7]
|
|
|
|
|
2018-02-10 15:28:51 -08:00
|
|
|
let packet = {cmd:'chip.cfg'}
|
2018-02-08 09:19:46 -08:00
|
|
|
console.dir(packet)
|
2018-02-10 15:28:51 -08:00
|
|
|
mcpclient.send(packet)
|
|
|
|
await delay(1000)
|
2018-02-11 11:41:45 -08:00
|
|
|
packet = {cmd:'pin.state.off', pins:'all' }
|
2018-02-10 15:28:51 -08:00
|
|
|
console.dir(packet)
|
|
|
|
mcpclient.send(packet)
|
2018-02-11 11:41:45 -08:00
|
|
|
// await delay(1000)
|
|
|
|
// packet = {cmd:'pin.cfg', pins:pins, cfg:'toggle_switch'}
|
|
|
|
// console.dir(packet)
|
|
|
|
// mcpclient.send(packet)
|
2018-02-10 15:28:51 -08:00
|
|
|
await delay(1000)
|
2018-02-11 11:41:45 -08:00
|
|
|
packet = {cmd:'pin.cfg', pins:pins}
|
2018-02-10 15:28:51 -08:00
|
|
|
console.dir(packet)
|
|
|
|
mcpclient.send(packet)
|
|
|
|
await delay(1000)
|
2018-02-11 11:41:45 -08:00
|
|
|
packet = {cmd:'pin.state.on', pins:pins, }
|
2018-02-10 15:28:51 -08:00
|
|
|
console.dir(packet)
|
|
|
|
mcpclient.send(packet)
|
|
|
|
await delay(1000)
|
2018-02-11 11:41:45 -08:00
|
|
|
packet = {cmd:'pin.state.toggle', pins:pins, }
|
2018-02-10 15:28:51 -08:00
|
|
|
console.dir(packet)
|
|
|
|
mcpclient.send(packet)
|
2018-02-11 11:41:45 -08:00
|
|
|
// await delay(1000)
|
|
|
|
// packet = {cmd:'pin.state.toggle', pins:pins, }
|
|
|
|
// console.dir(packet)
|
|
|
|
// mcpclient.send(packet)
|
|
|
|
// packet = {cmd:'pin.cfg', pins:3}
|
2018-02-10 15:28:51 -08:00
|
|
|
// console.dir(packet)
|
|
|
|
// mcpclient.send(packet)
|
|
|
|
|
2018-02-08 09:19:46 -08:00
|
|
|
|
2018-02-10 15:28:51 -08:00
|
|
|
await delay(10000)
|
2018-02-08 09:19:46 -08:00
|
|
|
process.kill(process.pid, 'SIGTERM')
|
|
|
|
|
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
})
|