From b0ce39ec545ef0aa5bfef9c3a2189c6677b4378d Mon Sep 17 00:00:00 2001 From: azw Date: Wed, 16 Aug 2023 21:19:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=B6=88=E6=81=AF=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/robot/clientnet.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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;