make cl args for run tests and run server as emulator. fixed errors.

This commit is contained in:
MaximZaitsev
2016-08-23 10:45:35 +03:00
parent fea116a8a5
commit ee5390b0b5
6 changed files with 38 additions and 7 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
#!/bin/bash
cd build/js
node main.js
node main.js $*
-1
View File
@@ -6,7 +6,6 @@ fun setTimeout(callBack: () -> Unit, ms: Int): dynamic = noImpl
fun <T> encodeProtoBuf(protoMessage: T): ByteArray {
val routeBytes: ByteArray
println(protoMessage.toString())
when (protoMessage) {
is LocationResponse -> {
val protoSize = protoMessage.getSizeNoTag()
+22 -3
View File
@@ -20,10 +20,29 @@ fun main(args: Array<String>) {
js("process.exit(1)")
}
val clArgs = js("process.argv")
var runAsEmulator = false
var runTests = false
for (arg in clArgs) {
when (arg) {
"-t" -> runTests = true
"-e" -> runAsEmulator = true
}
}
val carController =
if (runAsEmulator) {
McState.instance.connect("")
ControllerEmulator()
} else {
ControllerToUsb()
}
if (runTests) {
runTests()
}
val handlers: MutableMap<String, AbstractHandler> = mutableMapOf()
val carController = ControllerEmulator()
handlers.put("/rc/control", Control())
handlers.put("/loadBin", LoadBin())
handlers.put("/sonar", GetSonarData(carController))
+3
View File
@@ -49,11 +49,14 @@ private fun testCarEmulator() {
})
}
private var testNum = 1
private fun eq(value1: Double, value2: Double, msg: String, eps: Double) {
if (Math.abs(value1 - value2) > eps) {
println("test failed! $msg")
println("returned: $value1")
println("waited: $value2")
} else {
println("test ${testNum++} ok!")
}
}
@@ -146,6 +146,7 @@ class ControllerEmulator : Controller {
if (currentCommandIdx == commands.size) {
val responseMessage = RouteResponse.BuilderRouteResponse(0).build()
callBack.invoke(encodeProtoBuf(responseMessage))
return
}
val currentCommand = commands.get(currentCommandIdx)
@@ -3,11 +3,20 @@ package net.server.handlers
abstract class AbstractHandler {
fun execute(data: List<Byte>, response: dynamic) {
getBytesResponse(data.toByteArray(), { resultBytes ->
val callBack = { resultBytes: ByteArray ->
val resultBuffer = js("new Buffer(resultBytes)")
response.write(resultBuffer)
response.end()
})
}
try {
getBytesResponse(data.toByteArray(), callBack)
} catch (e: dynamic) {
println("error in executing handler!")
println(e.toString())
callBack.invoke(ByteArray(0))
}
}