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