From c122159983bdb6a17eb183870d48538a583c9540 Mon Sep 17 00:00:00 2001 From: MaximZaitsev Date: Thu, 14 Jul 2016 15:58:23 +0300 Subject: [PATCH] added arg for transport file path --- car_net/stFlashServer/handlers.js | 18 ++++++++++-------- car_net/stFlashServer/main.js | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/car_net/stFlashServer/handlers.js b/car_net/stFlashServer/handlers.js index 7f8507d1f44..b08e2c095bc 100644 --- a/car_net/stFlashServer/handlers.js +++ b/car_net/stFlashServer/handlers.js @@ -6,8 +6,6 @@ const main = require("./main.js"); const exec = require('child_process').exec; function loadBin(httpContent, response) { - - console.log(httpContent.length); var uploadClass = main.protoConstructorCarkot.Upload; var uploadObject = uploadClass.decode(httpContent); fs.writeFile(main.binFilePath, uploadObject.data.buffer, "binary", function (error) { @@ -21,8 +19,6 @@ function loadBin(httpContent, response) { code = 0; var shCommand = main.commandPrefix + " " + main.binFilePath + " " + uploadObject.base; exec(shCommand, function (error, stdout, stderr) { - // TODO get program result code and error textual representation and send - // back in the response if (error) { code = 1; console.error(error); @@ -31,7 +27,7 @@ function loadBin(httpContent, response) { var resultObject = new uploadResultClass({ "stdOut": stdout.toString(), "resultCode": code, - "stdErr": stderr.toString() + "stdErr": (stderr.toString() + "\n error:" + error) }); var byteBuffer = resultObject.encode(); var byteArray = []; @@ -86,11 +82,17 @@ function control(httpContent, response) { resultByte = 3; break; } - } console.log("byte for car: " + resultByte); - response.writeHead(200, {"Content-Type": "text/plain"}); - response.end(); + fs.writeFile(main.transportFilePath, resultByte, "binary", function (error) { + if (error) { + console.log(error); + } + //todo ещё нужно считывать ответ от контроллера и анализировать его (0 или 1) и отправлять + response.writeHead(200, {"Content-Type": "text/plain"}); + response.write(new Buffer([0])); + response.end(); + }); } exports.loadBin = loadBin; diff --git a/car_net/stFlashServer/main.js b/car_net/stFlashServer/main.js index 4e4fa0a209f..55cf21a8c8a 100644 --- a/car_net/stFlashServer/main.js +++ b/car_net/stFlashServer/main.js @@ -11,6 +11,7 @@ commander .version('1.0.0') .option('-p, --protopath [path]', 'path to dir with proto files. need here carkot.proto and route.proto. default ./proto/') .option('-b, --binfile [path]', 'path to save bin file with name f.bin. default ./') + .option('-t, --transportfile [path]', 'path to trasport file for connect to mcu default ./mcu') .parse(process.argv); //add slash to end of paths if need @@ -32,6 +33,7 @@ exports.protoConstructorCarkot = builderCarkot.build("carkot"); exports.protoConstructorControl = builderControl.build("carkot"); exports.commandPrefix = "./st-flash write"; exports.binFilePath = (commander.binfile ? commander.binfile : "./") + "f.bin"; +exports.transportFilePath = (commander.transportfile ? commander.transportfile : "./mcu"); var handlers = require("./handlers.js"); var handle = {};