uci-mcp/examples/ipc-test.mjs

105 lines
2.6 KiB
JavaScript

/*
* 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============')
// 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)
// }
// const pins='2,3,4'
const pins=3
// const pins='all'
// const pins=[1,3,5,7]
let packet = {cmd:'pin.cfg', pins:'all'}
console.dir(packet)
mcpclient.send(packet)
await delay(1000)
packet = {cmd:'pin.cfg', pins:'all', port:'B'}
console.dir(packet)
mcpclient.send(packet)
await delay(1000)
packet = {cmd:'pin.state.off', pins:'all' }
console.dir(packet)
await delay(1000)
mcpclient.send(packet)
packet = {cmd:'pin.state.off', pins:'all', port:'B' }
console.dir(packet)
mcpclient.send(packet)
await delay(1000)
// packet = {cmd:'pin.state.on', pins:pins}
// console.dir(packet)
// mcpclient.send(packet)
packet = {cmd:'pin.state.on', pins:'1,7', port:'B' }
console.dir(packet)
mcpclient.send(packet)
packet = {cmd:'pin.state.on', pins:'3,4'}
console.dir(packet)
mcpclient.send(packet)
// mcpclient.send(packet)
// await delay(1000)
// packet = {cmd:'pin.state.on', pins:pins}
// console.dir(packet)
// mcpclient.send(packet)
// await delay(1000)
// packet = {cmd:'pin.status', reg:'xintf', pins:pins}
// console.dir(packet)
// mcpclient.send(packet)
// await delay(1000)
// packet = {cmd:'pin.status', pins:pins}
// console.dir(packet)
// mcpclient.send(packet)
// await delay(1000)
// packet = {cmd:'pin.cfg', pins:pins, cfg:'toggle_switch'}
// console.dir(packet)
// mcpclient.send(packet)
// await delay(1000)
// packet = {cmd:'pin.cfg', pins:pins}
// console.dir(packet)
// mcpclient.send(packet)
// await delay(1000)
// packet = {cmd:'pin.state.on', pins:pins, }
// console.dir(packet)
// mcpclient.send(packet)
// await delay(1000)
// packet = {cmd:'pin.state.toggle', pins:pins, }
// console.dir(packet)
// mcpclient.send(packet)
// await delay(1000)
// packet = {cmd:'pin.state.toggle', pins:pins, }
// console.dir(packet)
// mcpclient.send(packet)
// packet = {cmd:'pin.cfg', pins:3}
// console.dir(packet)
// mcpclient.send(packet)
await delay(10000)
process.kill(process.pid, 'SIGTERM')
})().catch(err => {
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
})