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