created command line args in flash server

This commit is contained in:
MaximZaitsev
2016-07-12 14:31:21 +03:00
parent 89e626c8f5
commit f0cb9170c2
4 changed files with 47 additions and 67 deletions
+1
View File
@@ -1,4 +1,5 @@
.idea/workspace.xml
.idea/uiDesigner.xml
protobufjs
node_modules
out
+8 -10
View File
@@ -2,29 +2,27 @@
* Created by user on 7/11/16.
*/
const fs = require("fs");
const protoBuf = require("./protobufjs");
const builder = protoBuf.loadProtoFile("./proto/carkot.proto");//todo перенести как аргумент при запуске.
const protoConstructor = builder.build("carkot");
var commandPrefix = "./data/macosx-x86_64/st-flash write";
var binFilePath = "./f.bin";
const main = require("./main.js");
function loadBin(httpContent, response) {
var uploadClass = protoConstructor.Upload;
var uploadClass = main.protoConstructor.Upload;
var uploadObject = uploadClass.decode(httpContent);
fs.writeFile(binFilePath, uploadObject.data.buffer, "binary", function (error) {
var uploadResultClass = protoConstructor.UploadResult;
var uploadResultClass = main.protoConstructor.UploadResult;
var code = 0;
var stdErr = "";
if (error) {
code = 2;
stdErr = error.toString();
} else {
code = 0;
console.log(commandPrefix + " " + binFilePath + " " + uploadObject.base);
console.log(main.commandPrefix + " " + main.binFilePath + " " + uploadObject.base);
}
var resultObject = new uploadResultClass({
"stdOut": "",
"resultCode": code,
"stdErr": ""
"stdErr": stdErr
});
var byteBuffer = resultObject.encode();
var byteArray = [];
@@ -37,7 +35,7 @@ function loadBin(httpContent, response) {
});
}
function other(request, response) {
function other(httpContent, response) {
console.log("other");
response.writeHead(200, {"Content-Type": "text/plain"});
response.end();
+22 -57
View File
@@ -5,67 +5,32 @@
var server = require("./server.js");
var router = require("./router.js");
var handlers = require("./handlers.js");
var commander = require("commander");
const protoBuf = require("protobufjs");
commander
.version('1.0.0')
.option('-p, --protopath [path]', 'path to proto file. default ./proto/carkot.proto')
.option('-b, --binfile [path]', 'path to save bin file with name f.bin. default ./')
// .option('-b, --bbq-sauce', 'Add bbq sauce')
// .option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')
.parse(process.argv);
const builder = protoBuf.loadProtoFile(commander.protopath ? commander.protopath : "./proto/carkot.proto");
const protoConstructor = builder.build("carkot");
if (commander.protopath) {
console.log("pew " + commander.protopath)
}
var handle = {};
handle["/"] = handlers.other;
handle["/loadBin"] = handlers.loadBin;
handle["/other"] = handlers.other;
// UploadR = upRes.UploadResult;
// var res = new UploadR({"error": "test error!"});
// console.log(res.encode());
//
//
// var testBack = UploadR.decode(res.encode());
// console.log(testBack);
// console.log(process.argv);
server.start(router.route, handle);
// var http = require("http");
//
// var global_closure = null;
//
// // nodejs/javascript closures
// http.createServer(function(request, response) {
// // console.log("test");
// global_closure && global_closure();
//
// // console.log(request);
// // response.writeHead(200, {"Content-Type": "text/plain"});
// // response.write("Hello World");
//
// function closure() {
// console.log(request.toString());
// }
// global_closure = closure;
//
// //writeToJournal().getDBData().processDBData().sendResponse().commitJournal();
// function writeToJournal() {
// console.log(request);
// getDBData(processDBData);
// getDBData(function() {});
// }
//
// function getDBData(callback) {
// db.getData({ id : request.query['id'] }, onDbDataReady);
// var i = 0;
//
// function onDbDataReady(err, someDBData) {
// if (err) {
// return response.error();
// }
// console.log(i);
// callback(someDBData);
// }
// }
//
// function processDBData(dbData) {
// function sendResponse() {
//
// }
// }
//
// response.end();
// }).listen(8888);
exports.protoConstructor = protoConstructor;
exports.commandPrefix = "./data/macosx-x86_64/st-flash write";
exports.binFilePath = (commander.binfile ? commander.binfile : "./") + "f.bin";
console.log(exports.binFilePath);
console.log(exports.commandPrefix);
+16
View File
@@ -0,0 +1,16 @@
{
"name": "stflashserver",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node main.js"
},
"author": "maxim",
"license": "ISC",
"dependencies": {
"commander": "^2.9.0",
"protobufjs": "^5.0.1"
}
}