added proto file to raspberry server. added handler for command from car control
This commit is contained in:
@@ -8,7 +8,7 @@ const exec = require('child_process').exec;
|
||||
function loadBin(httpContent, response) {
|
||||
|
||||
console.log(httpContent.length);
|
||||
var uploadClass = main.protoConstructor.Upload;
|
||||
var uploadClass = main.protoConstructorCarkot.Upload;
|
||||
var uploadObject = uploadClass.decode(httpContent);
|
||||
fs.writeFile(main.binFilePath, uploadObject.data.buffer, "binary", function (error) {
|
||||
var uploadResultClass = main.protoConstructor.UploadResult;
|
||||
@@ -54,5 +54,45 @@ function other(httpContent, response) {
|
||||
response.end();
|
||||
}
|
||||
|
||||
//контроль машинкой, как с пульта управления
|
||||
function control(httpContent, response) {
|
||||
var directionClass = main.protoConstructorControl.Direction;
|
||||
var directionObject = directionClass.decode(httpContent);
|
||||
var resultByte;
|
||||
switch (directionObject.command) {
|
||||
case directionClass.Command.stop :
|
||||
{
|
||||
resultByte = 0;
|
||||
break;
|
||||
}
|
||||
case directionClass.Command.forward :
|
||||
{
|
||||
resultByte = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case directionClass.Command.backward :
|
||||
{
|
||||
resultByte = 2;
|
||||
break;
|
||||
}
|
||||
case directionClass.Command.right :
|
||||
{
|
||||
resultByte = 4;
|
||||
break;
|
||||
}
|
||||
case directionClass.Command.left :
|
||||
{
|
||||
resultByte = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
console.log("byte for car: " + resultByte);
|
||||
response.writeHead(200, {"Content-Type": "text/plain"});
|
||||
response.end();
|
||||
}
|
||||
|
||||
exports.loadBin = loadBin;
|
||||
exports.other = other;
|
||||
exports.other = other;
|
||||
exports.control = control;
|
||||
|
||||
@@ -9,14 +9,27 @@ const protoBuf = require("protobufjs");
|
||||
|
||||
commander
|
||||
.version('1.0.0')
|
||||
.option('-p, --protopath [path]', 'path to proto file. default ./proto/carkot.proto')
|
||||
.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 ./')
|
||||
.parse(process.argv);
|
||||
|
||||
const builder = protoBuf.loadProtoFile(commander.protopath ? commander.protopath : "./proto/carkot.proto");
|
||||
const protoConstructor = builder.build("carkot");
|
||||
//add slash to end of paths if need
|
||||
if (commander.protopath) {
|
||||
if (commander.protopath.substr(commander.protopath.length - 1) != "/") {
|
||||
commander.protopath = commander.protopath + "/";
|
||||
}
|
||||
}
|
||||
if (commander.binfile) {
|
||||
if (commander.binfile.substr(commander.binfile.length - 1) != "/") {
|
||||
commander.binfile = commander.binfile + "/";
|
||||
}
|
||||
}
|
||||
|
||||
exports.protoConstructor = protoConstructor;
|
||||
const builderCarkot = protoBuf.loadProtoFile(commander.protopath ? commander.protopath + "carkot.proto" : "./proto/carkot.proto");//todo!!1 путь до каталога, прото файлы - в нём
|
||||
const builderControl = protoBuf.loadProtoFile(commander.protopath ? commander.protopath + "route.proto" : "./proto/route.proto");
|
||||
|
||||
exports.protoConstructorCarkot = builderCarkot.build("carkot");
|
||||
exports.protoConstructorControl = builderControl.build("carkot");
|
||||
exports.commandPrefix = "./st-flash write";
|
||||
exports.binFilePath = (commander.binfile ? commander.binfile : "./") + "f.bin";
|
||||
|
||||
@@ -24,6 +37,7 @@ var handlers = require("./handlers.js");
|
||||
var handle = {};
|
||||
handle["/"] = handlers.other;
|
||||
handle["/loadBin"] = handlers.loadBin;
|
||||
handle["/control"] = handlers.control;
|
||||
handle["/other"] = handlers.other;
|
||||
|
||||
server.start(router.route, handle);
|
||||
@@ -0,0 +1,25 @@
|
||||
syntax = "proto3";
|
||||
package carkot;
|
||||
|
||||
option java_package = "proto.car";
|
||||
option java_outer_classname = "RouteP";
|
||||
|
||||
message Route {
|
||||
repeated WayPoint way_points = 1;
|
||||
|
||||
message WayPoint {
|
||||
double distance = 2;
|
||||
double angle_delta = 3;
|
||||
}
|
||||
}
|
||||
|
||||
message Direction {
|
||||
enum Command {
|
||||
stop = 0;
|
||||
forward = 1;
|
||||
backward = 2;
|
||||
left = 3;
|
||||
right = 4;
|
||||
}
|
||||
Command command = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user