added arg for transport file path

This commit is contained in:
MaximZaitsev
2016-07-14 15:58:23 +03:00
parent 5cc56e9831
commit c122159983
2 changed files with 12 additions and 8 deletions
+10 -8
View File
@@ -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;
+2
View File
@@ -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 = {};