add link to proto src, add protokot lib to dependies, fixed code for new protokot lib
This commit is contained in:
Generated
+13
-3
@@ -4,6 +4,9 @@
|
||||
<output url="file://$MODULE_DIR$/../../build/classes/main" />
|
||||
<output-test url="file://$MODULE_DIR$/../../build/classes/test" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/../../../proto">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../../proto/protofiles_sources/out" isTestSource="false" />
|
||||
</content>
|
||||
<content url="file://$MODULE_DIR$/../..">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/kotlin" isTestSource="false" />
|
||||
@@ -17,9 +20,16 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.0.3" level="project" />
|
||||
<orderEntry type="library" name="Gradle: io.netty:netty-all:4.1.2.Final" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-runtime:1.0.3" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: junit:junit:4.11" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" name="Gradle: io.netty:netty-all:4.1.2.Final" level="project" />
|
||||
<orderEntry type="module-library">
|
||||
<library name="Gradle: protokot-runtime">
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../../../proto/compiler/build/protokot-runtime.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
+5
-9
@@ -21,13 +21,11 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
task compileProto(type: Exec) {
|
||||
/*
|
||||
* XXX Kotlin proto compiler calling convention will change soon.
|
||||
* It would provide fixed path to protoc in its project directory.
|
||||
*/
|
||||
executable "./compileProto.sh"
|
||||
sourceSets {
|
||||
main.kotlin.srcDirs += 'src/main/java'
|
||||
main.kotlin.srcDirs += '../proto/protofiles_sources/out'
|
||||
}
|
||||
|
||||
task buildProtoLib(type: Copy) {
|
||||
/*
|
||||
* XXX Will need to rework.
|
||||
@@ -54,8 +52,6 @@ task getDeps(type: Copy) {
|
||||
}
|
||||
|
||||
build.dependsOn getDeps
|
||||
compileKotlin.dependsOn compileProto
|
||||
compileProto.dependsOn buildProtoLib
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
@@ -70,5 +66,5 @@ jar {
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
compile "io.netty:netty-all:4.1.2.Final"
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
compile files ("../proto/compiler/build/protokot-runtime.jar")
|
||||
}
|
||||
|
||||
@@ -66,15 +66,19 @@ fun main(args: Array<String>) {
|
||||
if (car != null) {
|
||||
println("print way points in polar coordinate als [distance] [rotation angle] in metres and degrees. after enter all points print \"done\". for reset route print \"reset\"")
|
||||
println("e.g. for move from (x,y) to (x+1,y) and back to (x,y) u need enter: 1 0[press enter] 1 180[press enter] done")
|
||||
val routeBuilder = RouteRequest.BuilderRouteRequest()
|
||||
|
||||
val distances = arrayListOf<Int>()
|
||||
val angles = arrayListOf<Int>()
|
||||
while (true) {
|
||||
val wayPointInputString = readLine()!!
|
||||
if (wayPointInputString.equals("reset", true)) {
|
||||
break
|
||||
} else if (wayPointInputString.equals("done", true)) {
|
||||
val requestBytes = ByteArrayOutputStream()
|
||||
routeBuilder.build().writeTo(CodedOutputStream(requestBytes))
|
||||
val request = DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, setRouteUrl, Unpooled.copiedBuffer(requestBytes.toByteArray()))
|
||||
val routeBuilder = RouteRequest.BuilderRouteRequest(distances.toIntArray(), angles.toIntArray())
|
||||
val requestObject = routeBuilder.build()
|
||||
val requestBytes = ByteArray(requestObject.getSizeNoTag())
|
||||
requestObject.writeTo(CodedOutputStream(requestBytes))
|
||||
val request = DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, setRouteUrl, Unpooled.copiedBuffer(requestBytes))
|
||||
request.headers().set(HttpHeaderNames.HOST, car.host)
|
||||
request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE)
|
||||
request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes())
|
||||
@@ -88,17 +92,17 @@ fun main(args: Array<String>) {
|
||||
break
|
||||
} else {
|
||||
val wayPointData = wayPointInputString.split(" ")
|
||||
val distance: Double
|
||||
val angle: Double
|
||||
val distance: Int
|
||||
val angle: Int
|
||||
try {
|
||||
distance = wayPointData[0].toDouble()
|
||||
angle = wayPointData[1].toDouble()
|
||||
distance = wayPointData[0].toInt()
|
||||
angle = wayPointData[1].toInt()
|
||||
} catch (e: NumberFormatException) {
|
||||
println("error in convertion angle or distance to double. try again")
|
||||
continue
|
||||
}
|
||||
val wayPoint = RouteRequest.WayPoint.BuilderWayPoint().setDistance(distance).setAngle_delta(angle).build()
|
||||
routeBuilder.addWayPoint(wayPoint)
|
||||
distances.add(distance)
|
||||
angles.add(angle)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package car.client
|
||||
|
||||
import CodedInputStream
|
||||
import InvalidProtocolBufferException
|
||||
import LocationResponse
|
||||
import getLocationUrl
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
@@ -9,8 +8,6 @@ import io.netty.channel.SimpleChannelInboundHandler
|
||||
import io.netty.handler.codec.http.DefaultHttpContent
|
||||
import io.netty.util.AttributeKey
|
||||
import objects.Environment
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by user on 7/8/16.
|
||||
@@ -27,22 +24,18 @@ class ClientHandler : SimpleChannelInboundHandler<Any> {
|
||||
val environment = Environment.instance
|
||||
when (url) {
|
||||
getLocationUrl -> {
|
||||
try {
|
||||
val response = LocationResponse.BuilderLocationResponse().build()
|
||||
response.mergeFrom(CodedInputStream(ByteArrayInputStream(contentBytes)))
|
||||
val response = LocationResponse.BuilderLocationResponse(LocationResponse.LocationData.BuilderLocationData(0, 0, 0).build(), 0).build()
|
||||
response.mergeFrom(CodedInputStream(contentBytes))
|
||||
|
||||
if (response.code == 0) {
|
||||
val data = response.locationResponseData
|
||||
synchronized(environment, {
|
||||
val car = environment.map.get(carUid)
|
||||
if (car != null) {
|
||||
car.x = data.x
|
||||
car.y = data.y
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch (e: InvalidProtocolBufferException) {
|
||||
println("invalic proto format!")
|
||||
if (response.code == 0) {
|
||||
val data = response.locationResponseData
|
||||
synchronized(environment, {
|
||||
val car = environment.map.get(carUid)
|
||||
if (car != null) {
|
||||
car.x = data.x
|
||||
car.y = data.y
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
|
||||
@@ -4,7 +4,6 @@ import CodedInputStream
|
||||
import CodedOutputStream
|
||||
import ConnectionRequest
|
||||
import ConnectionResponse
|
||||
import InvalidProtocolBufferException
|
||||
import RouteDoneRequest
|
||||
import RouteDoneResponse
|
||||
import connectUrl
|
||||
@@ -15,8 +14,6 @@ import io.netty.channel.SimpleChannelInboundHandler
|
||||
import io.netty.handler.codec.http.*
|
||||
import objects.Environment
|
||||
import routeDoneUrl
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
/**
|
||||
* Created by user on 7/6/16.
|
||||
@@ -30,28 +27,22 @@ class Handler : SimpleChannelInboundHandler<Any>() {
|
||||
|
||||
val environment = Environment.instance
|
||||
var success = true;
|
||||
val answer: ByteArrayOutputStream = ByteArrayOutputStream()
|
||||
var answer = ByteArray(0)
|
||||
when (url) {
|
||||
connectUrl -> {
|
||||
val data = ConnectionRequest.BuilderConnectionRequest().build();
|
||||
try {
|
||||
data.mergeFrom(CodedInputStream(ByteArrayInputStream(contentBytes)))
|
||||
} catch (e: InvalidProtocolBufferException) {
|
||||
success = false;
|
||||
ConnectionResponse.BuilderConnectionResponse().setCode(1).setErrorMsg("invalid protobuf request").build().writeTo(CodedOutputStream(answer))
|
||||
}
|
||||
val data = ConnectionRequest.BuilderConnectionRequest(IntArray(0), 0).build();
|
||||
data.mergeFrom(CodedInputStream(contentBytes))
|
||||
if (success) {
|
||||
val uid = environment.connectCar(data.ip, data.port)
|
||||
ConnectionResponse.BuilderConnectionResponse().setUid(uid).build().writeTo(CodedOutputStream(answer))
|
||||
val ipStr = data.ipValues.map { elem -> elem.toString() }.reduce { elem1, elem2 -> elem1 + "." + elem2 }
|
||||
val uid = environment.connectCar(ipStr, data.port)
|
||||
val responseObject = ConnectionResponse.BuilderConnectionResponse(uid, 0).build()
|
||||
answer = ByteArray(responseObject.getSizeNoTag())
|
||||
responseObject.writeTo(CodedOutputStream(answer))
|
||||
}
|
||||
}
|
||||
routeDoneUrl -> {
|
||||
val data = RouteDoneRequest.BuilderRouteDoneRequest().build()
|
||||
try {
|
||||
data.mergeFrom(CodedInputStream(ByteArrayInputStream(contentBytes)))
|
||||
} catch (e: InvalidProtocolBufferException) {
|
||||
success = false;
|
||||
}
|
||||
val data = RouteDoneRequest.BuilderRouteDoneRequest(0).build()
|
||||
data.mergeFrom(CodedInputStream(contentBytes))
|
||||
if (success) {
|
||||
val id = data.uid
|
||||
synchronized(environment.map, {
|
||||
@@ -59,10 +50,14 @@ class Handler : SimpleChannelInboundHandler<Any>() {
|
||||
if (car != null) {
|
||||
car.free = true
|
||||
car.lastAction = System.currentTimeMillis()
|
||||
RouteDoneResponse.BuilderRouteDoneResponse().setCode(0).setErrorMsg("").build().writeTo(CodedOutputStream(answer))
|
||||
val responseObject = RouteDoneResponse.BuilderRouteDoneResponse(0).build()
|
||||
answer = ByteArray(responseObject.getSizeNoTag())
|
||||
responseObject.writeTo(CodedOutputStream(answer))
|
||||
} else {
|
||||
success = false
|
||||
RouteDoneResponse.BuilderRouteDoneResponse().setCode(2).setErrorMsg("car not found by id").build().writeTo(CodedOutputStream(answer))
|
||||
val responseObject = RouteDoneResponse.BuilderRouteDoneResponse(2).build()
|
||||
answer = ByteArray(responseObject.getSizeNoTag())
|
||||
responseObject.writeTo(CodedOutputStream(answer))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -71,7 +66,7 @@ class Handler : SimpleChannelInboundHandler<Any>() {
|
||||
success = false
|
||||
}
|
||||
}
|
||||
val response = DefaultFullHttpResponse(HttpVersion.HTTP_1_1, if (success) HttpResponseStatus.OK else HttpResponseStatus.BAD_REQUEST, Unpooled.copiedBuffer(answer.toByteArray()))
|
||||
val response = DefaultFullHttpResponse(HttpVersion.HTTP_1_1, if (success) HttpResponseStatus.OK else HttpResponseStatus.BAD_REQUEST, Unpooled.copiedBuffer(answer))
|
||||
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes())
|
||||
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
||||
@@ -12,16 +12,16 @@ class Car constructor(uid: Int, host: String, port: Int) {
|
||||
var free: Boolean
|
||||
var lastAction: Long
|
||||
|
||||
var x: Double
|
||||
var y: Double
|
||||
var x: Int
|
||||
var y: Int
|
||||
|
||||
init {
|
||||
this.uid = uid
|
||||
this.host = host
|
||||
this.port = port
|
||||
this.free = true
|
||||
x = 0.toDouble()
|
||||
y = 0.toDouble()
|
||||
x = 0
|
||||
y = 0
|
||||
this.lastAction = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user