add sending debug info to web client

This commit is contained in:
MaximZaitsev
2016-08-26 11:21:13 +03:00
parent ea95fac968
commit 76af383e2a
4 changed files with 56 additions and 3 deletions
@@ -1,7 +1,7 @@
syntax = "proto3";
package carkot;
message Response {
message DebugResponse {
repeated int32 A = 1 [packed=true];
repeated int32 B = 2 [packed=true];
repeated int32 C = 3 [packed=true];
+36 -2
View File
@@ -1,14 +1,21 @@
package algorithm
import Waypoints
import algorithm.geometry.Line
import DebugResponse
import objects.Car
object RoomModel {
val point = arrayListOf<Pair<Double, Double>>()
val lines = arrayListOf<Line>()
val linesModel = listOf(Line(0.0, 1.0, -300.0),
Line(1.0, 0.0, 150.0),
Line(0.0, 1.0, 20.0),
Line(1.0, 0.0, -200.0))
// DEBUG BELOW
// DEBUG BELOW
val rng = java.util.Random(42)
var iter = 0
var currentPosition_x = 0
@@ -37,4 +44,31 @@ object RoomModel {
iter++
return Waypoints.BuilderWaypoints(begin_x, begin_y, end_x, end_y, false).build()
}
fun getDebugInfo(): DebugResponse {
val aRef = IntArray(linesModel.size)
val bRef = IntArray(linesModel.size)
val cRef = IntArray(linesModel.size)
val a = IntArray(lines.size)
val b = IntArray(lines.size)
val c = IntArray(lines.size)
val alg = DebugClInterface.algorithmImpl
val car = if (alg == null) Car(0, "", 0) else alg.thisCar
val mult = 1000000
linesModel.forEachIndexed { idx, line ->
aRef[idx] = (line.A * mult).toInt()
bRef[idx] = (line.B * mult).toInt()
cRef[idx] = (line.C * mult).toInt()
}
lines.forEachIndexed { idx, line ->
a[idx] = (line.A * mult).toInt()
b[idx] = (line.B * mult).toInt()
c[idx] = (line.C * mult).toInt()
}
val resultBuilder = DebugResponse.BuilderDebugResponse(a, b, c, car.x, car.y, car.angle, aRef, bRef, cRef)
return resultBuilder.build()
}
}
@@ -4,4 +4,5 @@ object Constants {
val changeModeURL = "/change-mode"
val getWaypointsURL = "/get-waypoints"
val directionOrderURL = "/direction-order"
val getDebug = "/get-debug"
}
@@ -8,6 +8,7 @@ import io.netty.util.CharsetUtil
import GenericResponse
import CodedOutputStream
import CodedInputStream
import algorithm.RoomModel
import java.util.*
class Handler : SimpleChannelInboundHandler<Any>() {
@@ -96,6 +97,23 @@ class Handler : SimpleChannelInboundHandler<Any>() {
response.headers().add("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Content-Length");
ctx.writeAndFlush(response).addListener(io.netty.channel.ChannelFutureListener.CLOSE)
}
Constants.getDebug -> {
val msg = RoomModel.getDebugInfo()
val outs = CodedOutputStream(ByteArray(msg.getSizeNoTag()))
msg.writeTo(outs)
val response = DefaultFullHttpResponse(
HttpVersion.HTTP_1_1,
HttpResponseStatus.OK,
Unpooled.copiedBuffer(Base64.getEncoder().encodeToString(outs.buffer), CharsetUtil.UTF_8)
)
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes())
response.headers().add("Access-Control-Allow-Origin", "*");
response.headers().add("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
response.headers().add("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Content-Length");
ctx.writeAndFlush(response).addListener(io.netty.channel.ChannelFutureListener.CLOSE)
}
}
}