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)
|
|
|
|
// }
|
|
|
|
|
|
|
|
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)
|
|
|
|
// packet = {cmd:'pin.cfg', pin:2, cfg:'toggle_switch'}
|
|
|
|
packet = {cmd:'pin.cfg', pin:2}
|
|
|
|
console.dir(packet)
|
|
|
|
mcpclient.send(packet)
|
|
|
|
await delay(1000)
|
|
|
|
packet = {cmd:'pin.state.off', pin:2, }
|
|
|
|
console.dir(packet)
|
|
|
|
mcpclient.send(packet)
|
|
|
|
await delay(1000)
|
|
|
|
packet = {cmd:'pin.state.on', pin:2, }
|
|
|
|
console.dir(packet)
|
|
|
|
mcpclient.send(packet)
|
|
|
|
await delay(1000)
|
|
|
|
packet = {cmd:'pin.state.toggle', pin:2, }
|
|
|
|
console.dir(packet)
|
|
|
|
mcpclient.send(packet)
|
|
|
|
await delay(1000)
|
|
|
|
packet = {cmd:'pin.state.toggle', pin:2, }
|
|
|
|
console.dir(packet)
|
|
|
|
mcpclient.send(packet)
|
|
|
|
// packet = {cmd:'pin.cfg', pin:3}
|
|
|
|
// 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)
|
|
|
|
})
|