modified car net server

This commit is contained in:
MaximZaitsev
2016-07-12 16:02:50 +03:00
parent 457da71cba
commit f5cc890ec7
10 changed files with 73 additions and 17 deletions
@@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="jcommander-1.48">
<CLASSES>
<root url="jar://$USER_HOME$/Downloads/jcommander-1.48.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
@@ -0,0 +1,18 @@
import com.beust.jcommander.Parameter;
/**
* Created by user on 7/12/16.
*/
public class CommandLineArgs {
@Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
public Integer verbose = 1;
@Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
public String groups;
@Parameter(names = "-debug", description = "Debug mode")
public boolean debug = false;
}
+7
View File
@@ -0,0 +1,7 @@
import com.beust.jcommander.JCommander;
/**
* Created by user on 7/12/16.
*/
public class JCom extends JCommander {
}
+6
View File
@@ -1,3 +1,4 @@
import com.beust.jcommander.JCommander
import com.google.protobuf.ByteString
import io.netty.buffer.Unpooled
import io.netty.handler.codec.http.*
@@ -12,6 +13,11 @@ import java.util.*
fun main(args: Array<String>) {
//2 argm path to bin and server ip
//1 option - 0x000...
var asss:ArrayList<String> = ArrayList();
val clArgs:CommandLineArgs = CommandLineArgs();
val jcom = JCommander(clArgs)
val host = "127.0.0.1"
val port = 8888
val base = "0x08000000"
+1
View File
@@ -10,5 +10,6 @@
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" name="netty-all-4.1.2.Final-sources" level="project" />
<orderEntry type="library" name="protobuf-java-3.0.0-beta-3" level="project" />
<orderEntry type="library" name="jcommander-1.48" level="project" />
</component>
</module>
+2
View File
@@ -1,5 +1,7 @@
.idea/workspace.xml
.idea/uiDesigner.xml
.idea/jsLibraryMappings.xml
.idea/libraries/stFlashServer_node_modules.xml
protobufjs
node_modules
out
+1
View File
@@ -4,5 +4,6 @@
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="stFlashServer node_modules" level="project" />
</component>
</module>
+27 -15
View File
@@ -3,12 +3,13 @@
*/
const fs = require("fs");
const main = require("./main.js");
var exec = require('child_process').exec;
function loadBin(httpContent, response) {
var uploadClass = main.protoConstructor.Upload;
var uploadObject = uploadClass.decode(httpContent);
fs.writeFile(binFilePath, uploadObject.data.buffer, "binary", function (error) {
fs.writeFile(main.binFilePath, uploadObject.data.buffer, "binary", function (error) {
var uploadResultClass = main.protoConstructor.UploadResult;
var code = 0;
var stdErr = "";
@@ -17,21 +18,32 @@ function loadBin(httpContent, response) {
stdErr = error.toString();
} else {
code = 0;
console.log(main.commandPrefix + " " + main.binFilePath + " " + uploadObject.base);
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);
}
var resultObject = new uploadResultClass({
"stdOut": stdout.toString(),
"resultCode": code,
"stdErr": stderr.toString()
});
var byteBuffer = resultObject.encode();
var byteArray = [];
for (var i = 0; i < byteBuffer.limit; i++) {
byteArray.push(byteBuffer.buffer[i]);
}
response.writeHead(200, {"Content-Type": "text/plain", "Content-length": byteArray.length});
response.write(new Buffer(byteArray));
response.end();
console.log(shCommand);
});
}
var resultObject = new uploadResultClass({
"stdOut": "",
"resultCode": code,
"stdErr": stdErr
});
var byteBuffer = resultObject.encode();
var byteArray = [];
for (var i = 0; i < byteBuffer.limit; i++) {
byteArray.push(byteBuffer.buffer[i]);
}
response.writeHead(200, {"Content-Type": "text/plain", "Content-length": byteArray.length});
response.write(new Buffer(byteArray));
response.end();
});
}
+1 -1
View File
@@ -30,7 +30,7 @@ handle["/other"] = handlers.other;
server.start(router.route, handle);
exports.protoConstructor = protoConstructor;
exports.commandPrefix = "./data/macosx-x86_64/st-flash write";
exports.commandPrefix = "./st-flash write";
exports.binFilePath = (commander.binfile ? commander.binfile : "./") + "f.bin";
console.log(exports.binFilePath);
console.log(exports.commandPrefix);
+1 -1
View File
@@ -1 +1 @@
./data/macosx-x86_64/st-flash write ./data/fancyblink.bin 0x08000000
./macosx-x86_64/st-flash write ./data/fancyblink.bin 0x08000000