car_srw: dirs renaming + small bug fixes
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
from SimpleXMLRPCServer import SimpleXMLRPCServer
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
def getReq():
|
||||
req = {
|
||||
'flash_address': '0x08000000',
|
||||
'data': '',
|
||||
'device': '',
|
||||
'method': 'STLINK'
|
||||
}
|
||||
data = os.path.join(os.getcwd(), 'devloader', 'data', 'fancyblink.bin')
|
||||
with open(data, 'rb') as f:
|
||||
req['data'] = f.read()
|
||||
f.close()
|
||||
print 'Image has', len(req['data']), 'bytes'
|
||||
return req
|
||||
|
||||
|
||||
def getFlasher(method, data, address):
|
||||
flasher = {}
|
||||
os_arch = 'macosx-x86_64'
|
||||
root = os.path.join(os.getcwd(), 'devloader', 'data')
|
||||
if method == 'STLINK':
|
||||
flasher['program'] = os.path.join(root, os_arch, 'st-flash')
|
||||
flasher['args'] = ['write', data, address]
|
||||
else:
|
||||
return None
|
||||
return flasher
|
||||
|
||||
|
||||
def processReq(req):
|
||||
temp = tempfile.mktemp()
|
||||
result = { 'output': '' }
|
||||
with open(temp, 'wb') as f:
|
||||
f.write(req['data'])
|
||||
f.close()
|
||||
flasher = getFlasher(req['method'], temp, req['flash_address'])
|
||||
cmd = ' '.join([flasher['program']] + flasher['args'] + ["2>&1"])
|
||||
with os.popen(cmd, 'r') as pipe:
|
||||
for line in pipe:
|
||||
result['output'] = result['output'] + line
|
||||
print 'res=', result['output']
|
||||
os.unlink(temp)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
class Handler:
|
||||
def __init__(self):
|
||||
# make all of the string functions available through
|
||||
# string.func_name
|
||||
import string
|
||||
self.string = string
|
||||
|
||||
def _listMethods(self):
|
||||
# implement this method so that system.listMethods
|
||||
# knows to advertise the strings methods
|
||||
return list_public_methods(self) + \
|
||||
['string.' + method for method in list_public_methods(self.string)]
|
||||
|
||||
def flash(self, req):
|
||||
return processReq(req)
|
||||
|
||||
server = SimpleXMLRPCServer(("localhost", 8000))
|
||||
server.register_introspection_functions()
|
||||
server.register_instance(Handler())
|
||||
server.serve_forever()
|
||||
|
||||
def main0():
|
||||
req = getReq()
|
||||
processReq(req)
|
||||
|
||||
|
||||
def main():
|
||||
server = SimpleXMLRPCServer(("localhost", 8000))
|
||||
server.register_introspection_functions()
|
||||
server.register_instance(Handler())
|
||||
server.serve_forever()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,10 +0,0 @@
|
||||
var protobuf = require('protocol-buffers')
|
||||
var fs = require('fs')
|
||||
|
||||
var messages = protobuf(fs.readFileSync(__dirname + '/../proto/carkot.proto'))
|
||||
|
||||
var ex = {
|
||||
data: '12345'
|
||||
}
|
||||
|
||||
var buf = messages.Upload.encode(ex)
|
||||
Generated
@@ -58,33 +58,33 @@ function control(httpContent, response) {
|
||||
switch (directionObject.command) {
|
||||
case directionClass.Command.stop :
|
||||
{
|
||||
resultByte = 0;
|
||||
resultByte = "0";
|
||||
break;
|
||||
}
|
||||
case directionClass.Command.forward :
|
||||
{
|
||||
resultByte = 1;
|
||||
resultByte = "1";
|
||||
break;
|
||||
}
|
||||
|
||||
case directionClass.Command.backward :
|
||||
{
|
||||
resultByte = 2;
|
||||
resultByte = "2";
|
||||
break;
|
||||
}
|
||||
case directionClass.Command.right :
|
||||
{
|
||||
resultByte = 4;
|
||||
resultByte = "3";
|
||||
break;
|
||||
}
|
||||
case directionClass.Command.left :
|
||||
{
|
||||
resultByte = 3;
|
||||
resultByte = "4";
|
||||
break;
|
||||
}
|
||||
}
|
||||
console.log("byte for car: " + resultByte);
|
||||
fs.writeFile(main.transportFilePath, resultByte, "binary", function (error) {
|
||||
fs.appendFile(main.transportFilePath, resultByte, "binary", function (error) {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
}
|
||||
@@ -10,9 +10,9 @@ const fs = require("fs");
|
||||
|
||||
commander
|
||||
.version('1.0.0')
|
||||
.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 ./')
|
||||
.option('-t, --transportfile [path]', 'path to trasport file for connect to mcu default ./mcu')
|
||||
.option('-p, --proto [path]', 'path to dir with proto files. need here carkot.proto and route.proto. default ./proto/')
|
||||
.option('-f, --flash [path]', 'path to save bin file with name f.bin. default ./')
|
||||
.option('-s, --serial [path]', 'path to file that represents MCU serial port default ./serial')
|
||||
.parse(process.argv);
|
||||
|
||||
//add slash to end of paths if need
|
||||
@@ -21,9 +21,9 @@ if (commander.protopath) {
|
||||
commander.protopath = commander.protopath + "/";
|
||||
}
|
||||
}
|
||||
if (commander.binfile) {
|
||||
if (commander.binfile.substr(commander.binfile.length - 1) != "/") {
|
||||
commander.binfile = commander.binfile + "/";
|
||||
if (commander.flash) {
|
||||
if (commander.flash.substr(commander.flash.length - 1) != "/") {
|
||||
commander.flash = commander.flash + "/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ var executeShell = "./st-flash";
|
||||
exports.protoConstructorCarkot = builderCarkot.build("carkot");
|
||||
exports.protoConstructorControl = builderControl.build("carkot");
|
||||
exports.commandPrefix = executeShell + " write";
|
||||
exports.binFilePath = (commander.binfile ? commander.binfile : "./") + "f.bin";
|
||||
exports.transportFilePath = (commander.transportfile ? commander.transportfile : "./mcu");
|
||||
exports.binFilePath = (commander.flash ? commander.flash : "./") + "st-flash";
|
||||
exports.transportFilePath = (commander.serial ? commander.serial : "./serial");
|
||||
|
||||
var handlers = require("./handlers.js");
|
||||
var handle = {};
|
||||
@@ -44,10 +44,11 @@ handle["/loadBin"] = handlers.loadBin;
|
||||
handle["/control"] = handlers.control;
|
||||
handle["/other"] = handlers.other;
|
||||
|
||||
fs.access(executeShell, fs.F_OK, function (error) {
|
||||
/*fs.access(executeShell, fs.F_OK, function (error) {
|
||||
if (!error) {
|
||||
server.start(router.route, handle);
|
||||
} else {
|
||||
console.log("file " + executeShell + " not found. Copy this file to server root dir");
|
||||
}
|
||||
});
|
||||
});*/
|
||||
server.start(router.route, handle);
|
||||
Reference in New Issue
Block a user