corrected car net server
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import com.google.protobuf.ByteString
|
||||
import com.martiansoftware.jsap.FlaggedOption
|
||||
import com.martiansoftware.jsap.JSAP
|
||||
import com.martiansoftware.jsap.JSAPResult
|
||||
import io.netty.buffer.Unpooled
|
||||
import io.netty.handler.codec.http.*
|
||||
import io.netty.util.CharsetUtil
|
||||
import proto.Carkot
|
||||
import java.io.FileInputStream
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -12,28 +15,42 @@ import java.util.*
|
||||
*/
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
//2 argm path to bin and server ip
|
||||
//1 option - 0x000...
|
||||
|
||||
val jsap:JSAP = JSAP();
|
||||
val optDebug = FlaggedOption("debug").setStringParser(JSAP.BOOLEAN_PARSER).setDefault("false").setRequired(false).setShortFlag('d')
|
||||
val optDebug1 = FlaggedOption("verbose").setStringParser(JSAP.INTEGER_PARSER).setDefault("0").setRequired(true).setShortFlag('v')
|
||||
jsap.registerParameter(optDebug)
|
||||
jsap.registerParameter(optDebug1)
|
||||
val jsap: JSAP = JSAP();
|
||||
val opthost = FlaggedOption("host").setStringParser(JSAP.STRING_PARSER).setRequired(true).setShortFlag('h').setLongFlag("host")
|
||||
val optPort = FlaggedOption("port").setStringParser(JSAP.INTEGER_PARSER).setDefault("8888").setRequired(false).setShortFlag('p').setLongFlag("port")
|
||||
val optBinPath = FlaggedOption("binFile").setStringParser(JSAP.STRING_PARSER).setRequired(true).setShortFlag('f').setLongFlag("binFile")
|
||||
val optmcuSystem = FlaggedOption("mcuSystem").setStringParser(JSAP.STRING_PARSER).setRequired(false).setDefault("0x08000000").setShortFlag('s')
|
||||
val optHelp = FlaggedOption("help").setStringParser(JSAP.BOOLEAN_PARSER).setRequired(false).setDefault("false").setLongFlag("help")
|
||||
jsap.registerParameter(opthost)
|
||||
jsap.registerParameter(optPort)
|
||||
jsap.registerParameter(optBinPath)
|
||||
jsap.registerParameter(optmcuSystem)
|
||||
jsap.registerParameter(optHelp)
|
||||
|
||||
val config = jsap.parse(args)
|
||||
println("verbose ${config.getInt("verbose")}")
|
||||
println("debug ${config.getBoolean("debug")}")
|
||||
println(jsap.getHelp())
|
||||
if (!config.success() || config.getBoolean("help")) {
|
||||
println(jsap.getHelp())
|
||||
return
|
||||
}
|
||||
|
||||
val host = config.getString("host")
|
||||
val port = config.getInt("port")
|
||||
val base = config.getString("mcuSystem")
|
||||
val pathToFile = config.getString("binFile")
|
||||
|
||||
System.exit(-1)
|
||||
val host = "127.0.0.1"
|
||||
val port = 8888
|
||||
val base = "0x08000000"
|
||||
// val client = client.Client
|
||||
val bytesBinTest = Carkot.Upload.newBuilder().setData(ByteString.copyFrom(ByteArray(5, {x->0}))).setBase(base).build().toByteArray()
|
||||
var fileBytes: ByteArray = ByteArray(0);
|
||||
try {
|
||||
FileInputStream(pathToFile).use { fis ->
|
||||
fileBytes = ByteArray(fis.available())
|
||||
fis.read(fileBytes)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
println("error in read file $pathToFile")
|
||||
return;
|
||||
}
|
||||
|
||||
val bytesBinTest = Carkot.Upload.newBuilder().setData(ByteString.copyFrom(fileBytes)).setBase(base).build().toByteArray()
|
||||
val request = DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/loadBin", Unpooled.copiedBuffer(bytesBinTest));
|
||||
request.headers().set(HttpHeaderNames.HOST, host)
|
||||
request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
const fs = require("fs");
|
||||
const main = require("./main.js");
|
||||
var exec = require('child_process').exec;
|
||||
const exec = require('child_process').exec;
|
||||
|
||||
function loadBin(httpContent, response) {
|
||||
|
||||
@@ -53,6 +53,5 @@ function other(httpContent, response) {
|
||||
response.end();
|
||||
}
|
||||
|
||||
|
||||
exports.loadBin = loadBin;
|
||||
exports.other = other;
|
||||
@@ -4,33 +4,26 @@
|
||||
|
||||
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)
|
||||
}
|
||||
exports.protoConstructor = protoConstructor;
|
||||
exports.commandPrefix = "./st-flash write";
|
||||
exports.binFilePath = (commander.binfile ? commander.binfile : "./") + "f.bin";
|
||||
|
||||
var handlers = require("./handlers.js");
|
||||
var handle = {};
|
||||
handle["/"] = handlers.other;
|
||||
handle["/loadBin"] = handlers.loadBin;
|
||||
handle["/other"] = handlers.other;
|
||||
|
||||
server.start(router.route, handle);
|
||||
exports.protoConstructor = protoConstructor;
|
||||
exports.commandPrefix = "./st-flash write";
|
||||
exports.binFilePath = (commander.binfile ? commander.binfile : "./") + "f.bin";
|
||||
console.log(exports.binFilePath);
|
||||
console.log(exports.commandPrefix);
|
||||
server.start(router.route, handle);
|
||||
@@ -11,5 +11,4 @@ function route(handle, pathname, httpContent, response) {
|
||||
response.end();
|
||||
}
|
||||
}
|
||||
|
||||
exports.route = route;
|
||||
Reference in New Issue
Block a user