diff --git a/tools/robot/clientnet.js b/tools/robot/clientnet.js index 4bd5b299..2d30bcb9 100644 --- a/tools/robot/clientnet.js +++ b/tools/robot/clientnet.js @@ -1,3 +1,4 @@ +const readline = require('readline'); const protobuf = require('protobufjs'); const ws = require('nodejs-websocket'); @@ -19,6 +20,13 @@ class ClientNet { this.recvBuf = Buffer.alloc(0); this.uniqId = 1000; this.msgHandlerMap = new Map(); + this.rl = readline.createInterface({ + input: process.stdin, + //output: process.stdout + }); + this.rl.on("line", (line)=> { + this.parseCmdLine(line); + }); } selfRegisterMsgHandle(msgName) { @@ -174,6 +182,35 @@ class ClientNet { } + parseCmdLine(line) { + const params = line.split(' '); + if (params.length <= 0) { + console.log('unknown command'); + return; + } + const msgName = params[0]; + const msgFields = params.slice(1); + const msgType = this.protoPb.lookupType(msgName); + if (!msgType) { + console.log('unknown command'); + return; + } + const msg = {}; + for (let i = 0; i < msgType.fieldsArray.length; ++i) { + if (i < msgFields.length) { + const name = msgType.fieldsArray[i].name; + const type = msgType.fieldsArray[i].type; + if (['int32', 'int', 'float', 'double'].indexOf(type) >= 0) { + msg[name] = Number(msgFields[i]); + } else { + msg[name] = msgFields[i]; + } + } + } + console.log(msg); + this.sendMsg(msgName, msg); + } + } module.exports = ClientNet;