UNPKG

@autocodingsystems/gateway-client

Version:

Library and commandline utility to control the acs gateway - device drivers for the most common industrial production line devices

72 lines (61 loc) 2.04 kB
var api = require('../api'); var globToRegExp = require('glob-to-regexp'); async function list_command(argv, conf, options) { var target = require('../parameters/target')(argv); var subscription = require('../parameters/subscription')(argv); var tag = require('../parameters/tag')(argv); var hideconnection = require('../parameters/hideconnection')(argv); var hideerrors = require('../parameters/hideerrors')(argv); if (!target.value || !subscription.value) { usage(); return; } var stop; try { stop = api(target.value).events( [{subscription: subscription.value, tag: tag.value}], onConnection, onEvents, onError ).stop; } catch (e) { throw e; } process.stdin.pipe(require('split')()) .on('data', (line) => { if (line === 'stop') { stop(); process.exit(0); } }) .on('error', () => { stop(); process.exit(1); }) .on('end', () => { stop(); process.exit(0); }); function onConnection(connection) { if (!hideconnection.value) { console.log(JSON.stringify(Object.assign({}, {msgtype: 'connection'}, connection))); } } function onEvents(event) { console.log(JSON.stringify(Object.assign({}, {msgtype: 'event'}, event))); } function onError(error) { if (!hideerrors.value) { console.log(JSON.stringify(Object.assign({}, {msgtype: 'error'}, error))); } } function usage() { console.log('events: receive events from a gateway: '); console.log(' ' + target.description); console.log(' ' + subscription.description); console.log(' ' + tag.description); console.log(' ' + hideconnection.description); console.log(' ' + hideerrors.description); } } module.exports = list_command;