diff --git a/car_fmw/Makefile b/car_fmw/Makefile index d390659b0b2..6578b72cfbb 100644 --- a/car_fmw/Makefile +++ b/car_fmw/Makefile @@ -4,6 +4,7 @@ LIB_DIR=$(PWD)/lib TRANSLATOR_DIR=$(PWD)/../translator KOTSTD_DIR=$(PWD)/../kotstd CAR_HW_DIR=$(PWD)/../car_hw +PROTO_DIR=$(PWD)/../proto/protofiles_sources/out OS_ARCH=linux-x86_64 @@ -22,7 +23,6 @@ KT=$(TRANSLATOR_DIR)/build/libs/translator-1.0.jar LD=arm-none-eabi-ld OBJ_COPY=arm-none-eabi-objcopy GDB=arm-none-eabi-gdb -PROTOC=$(PWD)/../proto/compiler/build/protoc LL=llc-3.6 LLINK=llvm-link-3.6 @@ -69,15 +69,12 @@ $(BIN_DIR)/kotlib.ll: $(LIB_DIR)/app.ll $(LIB_KOTSTD) $(LIB_KOTSTD): cd $(KOTSTD_DIR) && make -$(LIB_DIR)/app.ll: $(SRC_DIR)/**/*.kt $(SRC_DIR)/*.kt +$(LIB_DIR)/app.ll: $(SRC_DIR)/**/*.kt $(SRC_DIR)/*.kt $(PROTO_DIR)/*.kt $(KT_ALL_DEPS) $(KT): cd $(TRANSLATOR_DIR) && ./gradlew jar -proto: - $(PROTOC) -I$(SRC_DIR)/proto --kotlin_out=$(SRC_DIR)/proto_src $(SRC_DIR)/proto/*.proto - flash: $(CAR_FMW_BIN) $(ST_DIR)/st-flash write $(CAR_FMW_BIN) 0x8000000 diff --git a/car_fmw/src/Control.kt b/car_fmw/src/Control.kt index feb78d7030c..b98a6ca5dcf 100644 --- a/car_fmw/src/Control.kt +++ b/car_fmw/src/Control.kt @@ -68,19 +68,38 @@ object Control { private fun sonarTask() { val request = Reader.readSonar() - val size = request.angles.size + val angles = request.angles + val size = angles.size + val attempts = request.attempts + val distances = IntArray(size) - var i = 0 - while (i < size) { - distances[i] = Sonar.getSmoothDistance(request.angles[i]) - i++ + for (i in 0..(size - 1)) { + distances[i] = sonarMeasure(request.smoothing, attempts[i], angles[i], request.windowSize) } val response = SonarResponse.BuilderSonarResponse(distances).build() Writer.writeSonar(response) } + private fun sonarMeasure(smoothing: SonarRequest.Smoothing, attempts: Int, angle: Int, windowSize: Int): Int { + val data = IntArray(attempts) + + for (i in 0..(attempts - 1)) { + data[i] = Sonar.getSmoothDistance(angle, windowSize) + + if (smoothing.id == SonarRequest.Smoothing.NONE.id && data[i] != -1) { + return data[i] + } + } + + return when (smoothing.id) { + SonarRequest.Smoothing.MEAN.id -> data.mean() + SonarRequest.Smoothing.MEDIAN.id -> data.median() + else -> -1 + } + } + private fun sendMemoryStats() { val stats = DebugResponseMemoryStats.BuilderDebugResponseMemoryStats( DebugInfo.getDynamicHeapTail(), diff --git a/car_fmw/src/ProtoRW.kt b/car_fmw/src/ProtoRW.kt index c6acbd25261..7894d2c213a 100644 --- a/car_fmw/src/ProtoRW.kt +++ b/car_fmw/src/ProtoRW.kt @@ -21,7 +21,7 @@ object Reader { fun readSonar(): SonarRequest { val stream = getInputStream() - return SonarRequest.BuilderSonarRequest(IntArray(0)).parseFrom(stream).build() + return SonarRequest.BuilderSonarRequest(IntArray(0), IntArray(0), 0, SonarRequest.Smoothing.NONE, 0).parseFrom(stream).build() } private fun getInputStream(): CodedInputStream { diff --git a/car_fmw/src/Voyager.kt b/car_fmw/src/Voyager.kt index fa003cbb656..eff15a338f9 100644 --- a/car_fmw/src/Voyager.kt +++ b/car_fmw/src/Voyager.kt @@ -1,14 +1,15 @@ object Voyager { - val MAX_ANGLE: Int = 180 // angle - val SEGMENT_SIZE: Int = 30 // centimeter + private val MAX_ANGLE: Int = 180 // angle + private val SEGMENT_SIZE: Int = 30 // centimeter + private var DEFAULT_WINDOW = 10 // angle fun run() { while (true) { - var distance = Sonar.getSmoothDistance(0) + var distance = Sonar.getSmoothDistance(0, DEFAULT_WINDOW) while (distance == -1 || distance > 4 * SEGMENT_SIZE) { Engine.drive(RouteType.FORWARD.id, SEGMENT_SIZE) - distance = Sonar.getSmoothDistance(0) + distance = Sonar.getSmoothDistance(0, DEFAULT_WINDOW) } Engine.drive(RouteType.LEFT.id, 45) diff --git a/car_fmw/src/include/Sonar.kt b/car_fmw/src/include/Sonar.kt index c63b87803e2..e729d7f9156 100644 --- a/car_fmw/src/include/Sonar.kt +++ b/car_fmw/src/include/Sonar.kt @@ -2,26 +2,23 @@ external fun car_sonar_init() external fun car_sonar_get_dist(degree: Byte): Short object Sonar { - private var ATTEMPTS_COUNT = 5 - private var DEVIATION = 10 private var SCAN_STEP = 1 fun init() { car_sonar_init() } - fun getDistance(angle: Int): Int { - return car_sonar_get_dist(angle.toByte()).toInt() - } + fun getDistance(angle: Int): Int = + car_sonar_get_dist(angle.toByte()).toInt() - fun getSmoothDistance(angle: Int): Int { + fun getSmoothDistance(angle: Int, windowSize: Int): Int { val distance = getDistance(angle) - if (distance != -1) { + if (distance != -1 || windowSize == 0) { return distance } - val start = if (angle - DEVIATION < 0) 0 else angle - DEVIATION - return getOneOfRange(start, angle + DEVIATION, SCAN_STEP) + val start = if (angle - windowSize < 0) 0 else angle - windowSize + return getOneOfRange(start, angle + windowSize, SCAN_STEP) } fun getOneOfRange(start: Int, stop: Int, step: Int): Int { diff --git a/car_fmw/src/proto/Debug.proto b/car_fmw/src/proto/Debug.proto deleted file mode 100644 index 7b0e7908729..00000000000 --- a/car_fmw/src/proto/Debug.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; -package carkot; - -message DebugRequest { - - Type type = 1; - - enum Type { - MEMORY_STATS = 0; - } -} - -message DebugResponseMemoryStats { - int32 heapDynamicTail = 1; - int32 heapStaticTail = 2; - int32 heapDynamicMaxBytes = 3; - int32 heapDynamicTotalBytes = 4; -} diff --git a/car_fmw/src/proto/Direction.proto b/car_fmw/src/proto/Direction.proto deleted file mode 100644 index 7b5c1e7a85a..00000000000 --- a/car_fmw/src/proto/Direction.proto +++ /dev/null @@ -1,21 +0,0 @@ -syntax = "proto3"; -package carkot; - -option java_package = "proto.car"; -option java_outer_classname = "Direction"; - -message DirectionRequest { - enum Command { - STOP = 0; - FORWARD = 1; - BACKWARD = 2; - LEFT = 3; - RIGHT = 4; - } - Command command = 1; - int32 sid = 2; -} - -message DirectionResponse { - int32 code = 1; -} diff --git a/car_fmw/src/proto/Route.proto b/car_fmw/src/proto/Route.proto deleted file mode 100644 index fdd7eb0cd9a..00000000000 --- a/car_fmw/src/proto/Route.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; -package carkot; - -message RouteRequest { - repeated int32 times = 1; - repeated int32 directions = 2; -} - -message RouteMetricRequest { - repeated int32 distances = 1; - repeated int32 directions = 2; -} - -message RouteResponse { - int32 code = 1; -} \ No newline at end of file diff --git a/car_fmw/src/proto/Sonar.proto b/car_fmw/src/proto/Sonar.proto deleted file mode 100644 index 086804d029e..00000000000 --- a/car_fmw/src/proto/Sonar.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto3"; -package carkot; - -message SonarRequest { - repeated int32 angles = 1; -} - -message SonarResponse { - repeated int32 distances = 1; -} diff --git a/car_fmw/src/proto/Task.proto b/car_fmw/src/proto/Task.proto deleted file mode 100644 index 8e6384bbb73..00000000000 --- a/car_fmw/src/proto/Task.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; -package carkot; - -message TaskRequest { - - Type type = 1; - - enum Type { - DEBUG = 0; - ROUTE = 1; - SONAR = 2; - ROUTE_METRIC = 3; - } -} diff --git a/car_fmw/src/proto_src/Debug.kt b/car_fmw/src/proto_src/Debug.kt deleted file mode 100644 index aebee97b2f9..00000000000 --- a/car_fmw/src/proto_src/Debug.kt +++ /dev/null @@ -1,388 +0,0 @@ -class DebugRequest private constructor (var type: DebugRequest.Type) { - //========== Properties =========== - //enum type = 1 - - var errorCode: Int = 0 - - //========== Nested enums declarations =========== - enum class Type(val id: Int) { - MEMORY_STATS (0), - Unexpected(1); - - companion object { - fun fromIntToType (ord: Int): Type { - return when (ord) { - 0 -> Type.MEMORY_STATS - else -> Unexpected - } - } - } - } - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //enum type = 1 - if (type.id != DebugRequest.Type.fromIntToType(0).id) { - output.writeEnum (1, type.id) - } - - } - - fun mergeWith (other: DebugRequest) { - type = other.type - this.errorCode = other.errorCode - } - - fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) { - val builder = DebugRequest.BuilderDebugRequest(DebugRequest.Type.fromIntToType(0)) - mergeWith(builder.parseFromWithSize(input, expectedSize).build()) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = DebugRequest.BuilderDebugRequest(DebugRequest.Type.fromIntToType(0)) - mergeWith(builder.parseFrom(input).build()) - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (type != DebugRequest.Type.fromIntToType(0)) { - size += WireFormat.getEnumSize(1, type.id) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (type != DebugRequest.Type.fromIntToType(0)) { - size += WireFormat.getEnumSize(1, type.id) - } - return size - } - - //========== Builder =========== - class BuilderDebugRequest constructor (var type: DebugRequest.Type) { - //========== Properties =========== - //enum type = 1 - fun setType(value: DebugRequest.Type): DebugRequest.BuilderDebugRequest { - type = value - return this - } - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //enum type = 1 - if (type.id != DebugRequest.Type.fromIntToType(0).id) { - output.writeEnum (1, type.id) - } - - } - - //========== Mutating methods =========== - fun build(): DebugRequest { - val res = DebugRequest(type) - res.errorCode = errorCode - return res - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - if (wireType.id != WireType.VARINT.id) { - errorCode = 1 - return false - } - type = DebugRequest.Type.fromIntToType(input.readEnumNoTag()) - } - else -> errorCode = 4 - } - return true - } - - fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): DebugRequest.BuilderDebugRequest { - while(getSizeNoTag() < expectedSize) { - parseFieldFrom(input) - } - if (getSizeNoTag() > expectedSize) { errorCode = 2 } - return this - } - - fun parseFrom(input: CodedInputStream): DebugRequest.BuilderDebugRequest { - while(parseFieldFrom(input)) {} - return this - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (type != DebugRequest.Type.fromIntToType(0)) { - size += WireFormat.getEnumSize(1, type.id) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (type != DebugRequest.Type.fromIntToType(0)) { - size += WireFormat.getEnumSize(1, type.id) - } - return size - } - - } - -} - - -class DebugResponseMemoryStats private constructor (var heapDynamicTail: Int, var heapStaticTail: Int, var heapDynamicMaxBytes: Int, var heapDynamicTotalBytes: Int) { - //========== Properties =========== - //int32 heapDynamicTail = 1 - - //int32 heapStaticTail = 2 - - //int32 heapDynamicMaxBytes = 3 - - //int32 heapDynamicTotalBytes = 4 - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //int32 heapDynamicTail = 1 - if (heapDynamicTail != 0) { - output.writeInt32 (1, heapDynamicTail) - } - - //int32 heapStaticTail = 2 - if (heapStaticTail != 0) { - output.writeInt32 (2, heapStaticTail) - } - - //int32 heapDynamicMaxBytes = 3 - if (heapDynamicMaxBytes != 0) { - output.writeInt32 (3, heapDynamicMaxBytes) - } - - //int32 heapDynamicTotalBytes = 4 - if (heapDynamicTotalBytes != 0) { - output.writeInt32 (4, heapDynamicTotalBytes) - } - - } - - fun mergeWith (other: DebugResponseMemoryStats) { - heapDynamicTail = other.heapDynamicTail - heapStaticTail = other.heapStaticTail - heapDynamicMaxBytes = other.heapDynamicMaxBytes - heapDynamicTotalBytes = other.heapDynamicTotalBytes - this.errorCode = other.errorCode - } - - fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) { - val builder = DebugResponseMemoryStats.BuilderDebugResponseMemoryStats(0, 0, 0, 0) - mergeWith(builder.parseFromWithSize(input, expectedSize).build()) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = DebugResponseMemoryStats.BuilderDebugResponseMemoryStats(0, 0, 0, 0) - mergeWith(builder.parseFrom(input).build()) - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (heapDynamicTail != 0) { - size += WireFormat.getInt32Size(1, heapDynamicTail) - } - if (heapStaticTail != 0) { - size += WireFormat.getInt32Size(2, heapStaticTail) - } - if (heapDynamicMaxBytes != 0) { - size += WireFormat.getInt32Size(3, heapDynamicMaxBytes) - } - if (heapDynamicTotalBytes != 0) { - size += WireFormat.getInt32Size(4, heapDynamicTotalBytes) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (heapDynamicTail != 0) { - size += WireFormat.getInt32Size(1, heapDynamicTail) - } - if (heapStaticTail != 0) { - size += WireFormat.getInt32Size(2, heapStaticTail) - } - if (heapDynamicMaxBytes != 0) { - size += WireFormat.getInt32Size(3, heapDynamicMaxBytes) - } - if (heapDynamicTotalBytes != 0) { - size += WireFormat.getInt32Size(4, heapDynamicTotalBytes) - } - return size - } - - //========== Builder =========== - class BuilderDebugResponseMemoryStats constructor (var heapDynamicTail: Int, var heapStaticTail: Int, var heapDynamicMaxBytes: Int, var heapDynamicTotalBytes: Int) { - //========== Properties =========== - //int32 heapDynamicTail = 1 - fun setHeapDynamicTail(value: Int): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats { - heapDynamicTail = value - return this - } - - //int32 heapStaticTail = 2 - fun setHeapStaticTail(value: Int): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats { - heapStaticTail = value - return this - } - - //int32 heapDynamicMaxBytes = 3 - fun setHeapDynamicMaxBytes(value: Int): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats { - heapDynamicMaxBytes = value - return this - } - - //int32 heapDynamicTotalBytes = 4 - fun setHeapDynamicTotalBytes(value: Int): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats { - heapDynamicTotalBytes = value - return this - } - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //int32 heapDynamicTail = 1 - if (heapDynamicTail != 0) { - output.writeInt32 (1, heapDynamicTail) - } - - //int32 heapStaticTail = 2 - if (heapStaticTail != 0) { - output.writeInt32 (2, heapStaticTail) - } - - //int32 heapDynamicMaxBytes = 3 - if (heapDynamicMaxBytes != 0) { - output.writeInt32 (3, heapDynamicMaxBytes) - } - - //int32 heapDynamicTotalBytes = 4 - if (heapDynamicTotalBytes != 0) { - output.writeInt32 (4, heapDynamicTotalBytes) - } - - } - - //========== Mutating methods =========== - fun build(): DebugResponseMemoryStats { - val res = DebugResponseMemoryStats(heapDynamicTail, heapStaticTail, heapDynamicMaxBytes, heapDynamicTotalBytes) - res.errorCode = errorCode - return res - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - if (wireType.id != WireType.VARINT.id) { - errorCode = 1 - return false - } - heapDynamicTail = input.readInt32NoTag() - } - 2 -> { - if (wireType.id != WireType.VARINT.id) { - errorCode = 1 - return false - } - heapStaticTail = input.readInt32NoTag() - } - 3 -> { - if (wireType.id != WireType.VARINT.id) { - errorCode = 1 - return false - } - heapDynamicMaxBytes = input.readInt32NoTag() - } - 4 -> { - if (wireType.id != WireType.VARINT.id) { - errorCode = 1 - return false - } - heapDynamicTotalBytes = input.readInt32NoTag() - } - else -> errorCode = 4 - } - return true - } - - fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats { - while(getSizeNoTag() < expectedSize) { - parseFieldFrom(input) - } - if (getSizeNoTag() > expectedSize) { errorCode = 2 } - return this - } - - fun parseFrom(input: CodedInputStream): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats { - while(parseFieldFrom(input)) {} - return this - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (heapDynamicTail != 0) { - size += WireFormat.getInt32Size(1, heapDynamicTail) - } - if (heapStaticTail != 0) { - size += WireFormat.getInt32Size(2, heapStaticTail) - } - if (heapDynamicMaxBytes != 0) { - size += WireFormat.getInt32Size(3, heapDynamicMaxBytes) - } - if (heapDynamicTotalBytes != 0) { - size += WireFormat.getInt32Size(4, heapDynamicTotalBytes) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (heapDynamicTail != 0) { - size += WireFormat.getInt32Size(1, heapDynamicTail) - } - if (heapStaticTail != 0) { - size += WireFormat.getInt32Size(2, heapStaticTail) - } - if (heapDynamicMaxBytes != 0) { - size += WireFormat.getInt32Size(3, heapDynamicMaxBytes) - } - if (heapDynamicTotalBytes != 0) { - size += WireFormat.getInt32Size(4, heapDynamicTotalBytes) - } - return size - } - - } - -} - - diff --git a/car_fmw/src/proto_src/Direction.kt b/car_fmw/src/proto_src/Direction.kt deleted file mode 100644 index 615b884b3b1..00000000000 --- a/car_fmw/src/proto_src/Direction.kt +++ /dev/null @@ -1,320 +0,0 @@ -class DirectionRequest private constructor (var command: DirectionRequest.Command, var sid: Int) { - //========== Properties =========== - //enum command = 1 - - //int32 sid = 2 - - var errorCode: Int = 0 - - //========== Nested enums declarations =========== - enum class Command(val id: Int) { - STOP (0), - FORWARD (1), - BACKWARD (2), - LEFT (3), - RIGHT (4), - Unexpected(5); - - companion object { - fun fromIntToCommand (ord: Int): Command { - return when (ord) { - 0 -> Command.STOP - 1 -> Command.FORWARD - 2 -> Command.BACKWARD - 3 -> Command.LEFT - 4 -> Command.RIGHT - else -> Unexpected - } - } - } - } - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //enum command = 1 - if (command.id != DirectionRequest.Command.fromIntToCommand(0).id) { - output.writeEnum (1, command.id) - } - - //int32 sid = 2 - if (sid != 0) { - output.writeInt32 (2, sid) - } - - } - - fun mergeWith (other: DirectionRequest) { - command = other.command - sid = other.sid - this.errorCode = other.errorCode - } - - fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) { - val builder = DirectionRequest.BuilderDirectionRequest(DirectionRequest.Command.fromIntToCommand(0), 0) - mergeWith(builder.parseFromWithSize(input, expectedSize).build()) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = DirectionRequest.BuilderDirectionRequest(DirectionRequest.Command.fromIntToCommand(0), 0) - mergeWith(builder.parseFrom(input).build()) - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (command != DirectionRequest.Command.fromIntToCommand(0)) { - size += WireFormat.getEnumSize(1, command.id) - } - if (sid != 0) { - size += WireFormat.getInt32Size(2, sid) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (command != DirectionRequest.Command.fromIntToCommand(0)) { - size += WireFormat.getEnumSize(1, command.id) - } - if (sid != 0) { - size += WireFormat.getInt32Size(2, sid) - } - return size - } - - //========== Builder =========== - class BuilderDirectionRequest constructor (var command: DirectionRequest.Command, var sid: Int) { - //========== Properties =========== - //enum command = 1 - fun setCommand(value: DirectionRequest.Command): DirectionRequest.BuilderDirectionRequest { - command = value - return this - } - - //int32 sid = 2 - fun setSid(value: Int): DirectionRequest.BuilderDirectionRequest { - sid = value - return this - } - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //enum command = 1 - if (command.id != DirectionRequest.Command.fromIntToCommand(0).id) { - output.writeEnum (1, command.id) - } - - //int32 sid = 2 - if (sid != 0) { - output.writeInt32 (2, sid) - } - - } - - //========== Mutating methods =========== - fun build(): DirectionRequest { - val res = DirectionRequest(command, sid) - res.errorCode = errorCode - return res - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - if (wireType.id != WireType.VARINT.id) { - errorCode = 1 - return false - } - command = DirectionRequest.Command.fromIntToCommand(input.readEnumNoTag()) - } - 2 -> { - if (wireType.id != WireType.VARINT.id) { - errorCode = 1 - return false - } - sid = input.readInt32NoTag() - } - else -> errorCode = 4 - } - return true - } - - fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): DirectionRequest.BuilderDirectionRequest { - while(getSizeNoTag() < expectedSize) { - parseFieldFrom(input) - } - if (getSizeNoTag() > expectedSize) { errorCode = 2 } - return this - } - - fun parseFrom(input: CodedInputStream): DirectionRequest.BuilderDirectionRequest { - while(parseFieldFrom(input)) {} - return this - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (command != DirectionRequest.Command.fromIntToCommand(0)) { - size += WireFormat.getEnumSize(1, command.id) - } - if (sid != 0) { - size += WireFormat.getInt32Size(2, sid) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (command != DirectionRequest.Command.fromIntToCommand(0)) { - size += WireFormat.getEnumSize(1, command.id) - } - if (sid != 0) { - size += WireFormat.getInt32Size(2, sid) - } - return size - } - - } - -} - - -class DirectionResponse private constructor (var code: Int) { - //========== Properties =========== - //int32 code = 1 - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //int32 code = 1 - if (code != 0) { - output.writeInt32 (1, code) - } - - } - - fun mergeWith (other: DirectionResponse) { - code = other.code - this.errorCode = other.errorCode - } - - fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) { - val builder = DirectionResponse.BuilderDirectionResponse(0) - mergeWith(builder.parseFromWithSize(input, expectedSize).build()) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = DirectionResponse.BuilderDirectionResponse(0) - mergeWith(builder.parseFrom(input).build()) - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (code != 0) { - size += WireFormat.getInt32Size(1, code) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (code != 0) { - size += WireFormat.getInt32Size(1, code) - } - return size - } - - //========== Builder =========== - class BuilderDirectionResponse constructor (var code: Int) { - //========== Properties =========== - //int32 code = 1 - fun setCode(value: Int): DirectionResponse.BuilderDirectionResponse { - code = value - return this - } - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //int32 code = 1 - if (code != 0) { - output.writeInt32 (1, code) - } - - } - - //========== Mutating methods =========== - fun build(): DirectionResponse { - val res = DirectionResponse(code) - res.errorCode = errorCode - return res - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - if (wireType.id != WireType.VARINT.id) { - errorCode = 1 - return false - } - code = input.readInt32NoTag() - } - else -> errorCode = 4 - } - return true - } - - fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): DirectionResponse.BuilderDirectionResponse { - while(getSizeNoTag() < expectedSize) { - parseFieldFrom(input) - } - if (getSizeNoTag() > expectedSize) { errorCode = 2 } - return this - } - - fun parseFrom(input: CodedInputStream): DirectionResponse.BuilderDirectionResponse { - while(parseFieldFrom(input)) {} - return this - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (code != 0) { - size += WireFormat.getInt32Size(1, code) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (code != 0) { - size += WireFormat.getInt32Size(1, code) - } - return size - } - - } - -} - - diff --git a/car_fmw/src/proto_src/Route.kt b/car_fmw/src/proto_src/Route.kt deleted file mode 100644 index 24a7c6fa650..00000000000 --- a/car_fmw/src/proto_src/Route.kt +++ /dev/null @@ -1,902 +0,0 @@ -class RouteRequest private constructor (var times: IntArray, var directions: IntArray) { - //========== Properties =========== - //repeated int32 times = 1 - - //repeated int32 directions = 2 - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //repeated int32 times = 1 - if (times.size > 0) { - output.writeTag(1, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (times.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < times.size) { - arraySize += WireFormat.getInt32SizeNoTag(times[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < times.size) { - output.writeInt32NoTag (times[i]) - i += 1 - } - } while(false) - } - - //repeated int32 directions = 2 - if (directions.size > 0) { - output.writeTag(2, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (directions.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < directions.size) { - output.writeInt32NoTag (directions[i]) - i += 1 - } - } while(false) - } - - } - - fun mergeWith (other: RouteRequest) { - times = times.plus((other.times)) - directions = directions.plus((other.directions)) - this.errorCode = other.errorCode - } - - fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) { - val builder = RouteRequest.BuilderRouteRequest(IntArray(0), IntArray(0)) - mergeWith(builder.parseFromWithSize(input, expectedSize).build()) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = RouteRequest.BuilderRouteRequest(IntArray(0), IntArray(0)) - mergeWith(builder.parseFrom(input).build()) - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (times.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < times.size) { - arraySize += WireFormat.getInt32SizeNoTag(times[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - if (directions.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (times.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < times.size) { - arraySize += WireFormat.getInt32SizeNoTag(times[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - if (directions.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - return size - } - - //========== Builder =========== - class BuilderRouteRequest constructor (var times: IntArray, var directions: IntArray) { - //========== Properties =========== - //repeated int32 times = 1 - fun setTimes(value: IntArray): RouteRequest.BuilderRouteRequest { - times = value - return this - } - fun settimesByIndex(index: Int, value: Int): RouteRequest.BuilderRouteRequest { - times[index] = value - return this - } - - //repeated int32 directions = 2 - fun setDirections(value: IntArray): RouteRequest.BuilderRouteRequest { - directions = value - return this - } - fun setdirectionsByIndex(index: Int, value: Int): RouteRequest.BuilderRouteRequest { - directions[index] = value - return this - } - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //repeated int32 times = 1 - if (times.size > 0) { - output.writeTag(1, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (times.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < times.size) { - arraySize += WireFormat.getInt32SizeNoTag(times[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < times.size) { - output.writeInt32NoTag (times[i]) - i += 1 - } - } while(false) - } - - //repeated int32 directions = 2 - if (directions.size > 0) { - output.writeTag(2, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (directions.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < directions.size) { - output.writeInt32NoTag (directions[i]) - i += 1 - } - } while(false) - } - - } - - //========== Mutating methods =========== - fun build(): RouteRequest { - val res = RouteRequest(times, directions) - res.errorCode = errorCode - return res - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - if (wireType.id != WireType.LENGTH_DELIMITED.id) { - errorCode = 1 - return false - } - val expectedByteSize = input.readInt32NoTag() - var readSize = 0 - var arraySize = 0 - input.mark() - do { - var i = 0 - while(readSize < expectedByteSize) { - var tmp = 0 - tmp = input.readInt32NoTag() - arraySize += 1 - readSize += WireFormat.getInt32SizeNoTag(tmp) - } - } while (false) - var newArray = IntArray(arraySize) - input.reset() - do { - var i = 0 - while(i < arraySize) { - newArray[i] = input.readInt32NoTag() - i += 1} - times = newArray - } while (false) - } - 2 -> { - if (wireType.id != WireType.LENGTH_DELIMITED.id) { - errorCode = 1 - return false - } - val expectedByteSize = input.readInt32NoTag() - var readSize = 0 - var arraySize = 0 - input.mark() - do { - var i = 0 - while(readSize < expectedByteSize) { - var tmp = 0 - tmp = input.readInt32NoTag() - arraySize += 1 - readSize += WireFormat.getInt32SizeNoTag(tmp) - } - } while (false) - var newArray = IntArray(arraySize) - input.reset() - do { - var i = 0 - while(i < arraySize) { - newArray[i] = input.readInt32NoTag() - i += 1} - directions = newArray - } while (false) - } - else -> errorCode = 4 - } - return true - } - - fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): RouteRequest.BuilderRouteRequest { - while(getSizeNoTag() < expectedSize) { - parseFieldFrom(input) - } - if (getSizeNoTag() > expectedSize) { errorCode = 2 } - return this - } - - fun parseFrom(input: CodedInputStream): RouteRequest.BuilderRouteRequest { - while(parseFieldFrom(input)) {} - return this - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (times.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < times.size) { - arraySize += WireFormat.getInt32SizeNoTag(times[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - if (directions.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (times.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < times.size) { - arraySize += WireFormat.getInt32SizeNoTag(times[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - if (directions.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - return size - } - - } - -} - - -class RouteMetricRequest private constructor (var distances: IntArray, var directions: IntArray) { - //========== Properties =========== - //repeated int32 distances = 1 - - //repeated int32 directions = 2 - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //repeated int32 distances = 1 - if (distances.size > 0) { - output.writeTag(1, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (distances.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < distances.size) { - output.writeInt32NoTag (distances[i]) - i += 1 - } - } while(false) - } - - //repeated int32 directions = 2 - if (directions.size > 0) { - output.writeTag(2, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (directions.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < directions.size) { - output.writeInt32NoTag (directions[i]) - i += 1 - } - } while(false) - } - - } - - fun mergeWith (other: RouteMetricRequest) { - distances = distances.plus((other.distances)) - directions = directions.plus((other.directions)) - this.errorCode = other.errorCode - } - - fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) { - val builder = RouteMetricRequest.BuilderRouteMetricRequest(IntArray(0), IntArray(0)) - mergeWith(builder.parseFromWithSize(input, expectedSize).build()) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = RouteMetricRequest.BuilderRouteMetricRequest(IntArray(0), IntArray(0)) - mergeWith(builder.parseFrom(input).build()) - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (distances.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - if (directions.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (distances.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - if (directions.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - return size - } - - //========== Builder =========== - class BuilderRouteMetricRequest constructor (var distances: IntArray, var directions: IntArray) { - //========== Properties =========== - //repeated int32 distances = 1 - fun setDistances(value: IntArray): RouteMetricRequest.BuilderRouteMetricRequest { - distances = value - return this - } - fun setdistancesByIndex(index: Int, value: Int): RouteMetricRequest.BuilderRouteMetricRequest { - distances[index] = value - return this - } - - //repeated int32 directions = 2 - fun setDirections(value: IntArray): RouteMetricRequest.BuilderRouteMetricRequest { - directions = value - return this - } - fun setdirectionsByIndex(index: Int, value: Int): RouteMetricRequest.BuilderRouteMetricRequest { - directions[index] = value - return this - } - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //repeated int32 distances = 1 - if (distances.size > 0) { - output.writeTag(1, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (distances.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < distances.size) { - output.writeInt32NoTag (distances[i]) - i += 1 - } - } while(false) - } - - //repeated int32 directions = 2 - if (directions.size > 0) { - output.writeTag(2, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (directions.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < directions.size) { - output.writeInt32NoTag (directions[i]) - i += 1 - } - } while(false) - } - - } - - //========== Mutating methods =========== - fun build(): RouteMetricRequest { - val res = RouteMetricRequest(distances, directions) - res.errorCode = errorCode - return res - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - if (wireType.id != WireType.LENGTH_DELIMITED.id) { - errorCode = 1 - return false - } - val expectedByteSize = input.readInt32NoTag() - var readSize = 0 - var arraySize = 0 - input.mark() - do { - var i = 0 - while(readSize < expectedByteSize) { - var tmp = 0 - tmp = input.readInt32NoTag() - arraySize += 1 - readSize += WireFormat.getInt32SizeNoTag(tmp) - } - } while (false) - var newArray = IntArray(arraySize) - input.reset() - do { - var i = 0 - while(i < arraySize) { - newArray[i] = input.readInt32NoTag() - i += 1} - distances = newArray - } while (false) - } - 2 -> { - if (wireType.id != WireType.LENGTH_DELIMITED.id) { - errorCode = 1 - return false - } - val expectedByteSize = input.readInt32NoTag() - var readSize = 0 - var arraySize = 0 - input.mark() - do { - var i = 0 - while(readSize < expectedByteSize) { - var tmp = 0 - tmp = input.readInt32NoTag() - arraySize += 1 - readSize += WireFormat.getInt32SizeNoTag(tmp) - } - } while (false) - var newArray = IntArray(arraySize) - input.reset() - do { - var i = 0 - while(i < arraySize) { - newArray[i] = input.readInt32NoTag() - i += 1} - directions = newArray - } while (false) - } - else -> errorCode = 4 - } - return true - } - - fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): RouteMetricRequest.BuilderRouteMetricRequest { - while(getSizeNoTag() < expectedSize) { - parseFieldFrom(input) - } - if (getSizeNoTag() > expectedSize) { errorCode = 2 } - return this - } - - fun parseFrom(input: CodedInputStream): RouteMetricRequest.BuilderRouteMetricRequest { - while(parseFieldFrom(input)) {} - return this - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (distances.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - if (directions.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (distances.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - if (directions.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < directions.size) { - arraySize += WireFormat.getInt32SizeNoTag(directions[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - return size - } - - } - -} - - -class RouteResponse private constructor (var code: Int) { - //========== Properties =========== - //int32 code = 1 - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //int32 code = 1 - if (code != 0) { - output.writeInt32 (1, code) - } - - } - - fun mergeWith (other: RouteResponse) { - code = other.code - this.errorCode = other.errorCode - } - - fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) { - val builder = RouteResponse.BuilderRouteResponse(0) - mergeWith(builder.parseFromWithSize(input, expectedSize).build()) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = RouteResponse.BuilderRouteResponse(0) - mergeWith(builder.parseFrom(input).build()) - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (code != 0) { - size += WireFormat.getInt32Size(1, code) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (code != 0) { - size += WireFormat.getInt32Size(1, code) - } - return size - } - - //========== Builder =========== - class BuilderRouteResponse constructor (var code: Int) { - //========== Properties =========== - //int32 code = 1 - fun setCode(value: Int): RouteResponse.BuilderRouteResponse { - code = value - return this - } - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //int32 code = 1 - if (code != 0) { - output.writeInt32 (1, code) - } - - } - - //========== Mutating methods =========== - fun build(): RouteResponse { - val res = RouteResponse(code) - res.errorCode = errorCode - return res - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - if (wireType.id != WireType.VARINT.id) { - errorCode = 1 - return false - } - code = input.readInt32NoTag() - } - else -> errorCode = 4 - } - return true - } - - fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): RouteResponse.BuilderRouteResponse { - while(getSizeNoTag() < expectedSize) { - parseFieldFrom(input) - } - if (getSizeNoTag() > expectedSize) { errorCode = 2 } - return this - } - - fun parseFrom(input: CodedInputStream): RouteResponse.BuilderRouteResponse { - while(parseFieldFrom(input)) {} - return this - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (code != 0) { - size += WireFormat.getInt32Size(1, code) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (code != 0) { - size += WireFormat.getInt32Size(1, code) - } - return size - } - - } - -} - - diff --git a/car_fmw/src/proto_src/Sonar.kt b/car_fmw/src/proto_src/Sonar.kt deleted file mode 100644 index d06ec94ac4f..00000000000 --- a/car_fmw/src/proto_src/Sonar.kt +++ /dev/null @@ -1,478 +0,0 @@ -class SonarRequest private constructor (var angles: IntArray) { - //========== Properties =========== - //repeated int32 angles = 1 - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //repeated int32 angles = 1 - if (angles.size > 0) { - output.writeTag(1, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (angles.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < angles.size) { - arraySize += WireFormat.getInt32SizeNoTag(angles[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < angles.size) { - output.writeInt32NoTag (angles[i]) - i += 1 - } - } while(false) - } - - } - - fun mergeWith (other: SonarRequest) { - angles = angles.plus((other.angles)) - this.errorCode = other.errorCode - } - - fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) { - val builder = SonarRequest.BuilderSonarRequest(IntArray(0)) - mergeWith(builder.parseFromWithSize(input, expectedSize).build()) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = SonarRequest.BuilderSonarRequest(IntArray(0)) - mergeWith(builder.parseFrom(input).build()) - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (angles.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < angles.size) { - arraySize += WireFormat.getInt32SizeNoTag(angles[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (angles.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < angles.size) { - arraySize += WireFormat.getInt32SizeNoTag(angles[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - return size - } - - //========== Builder =========== - class BuilderSonarRequest constructor (var angles: IntArray) { - //========== Properties =========== - //repeated int32 angles = 1 - fun setAngles(value: IntArray): SonarRequest.BuilderSonarRequest { - angles = value - return this - } - fun setanglesByIndex(index: Int, value: Int): SonarRequest.BuilderSonarRequest { - angles[index] = value - return this - } - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //repeated int32 angles = 1 - if (angles.size > 0) { - output.writeTag(1, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (angles.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < angles.size) { - arraySize += WireFormat.getInt32SizeNoTag(angles[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < angles.size) { - output.writeInt32NoTag (angles[i]) - i += 1 - } - } while(false) - } - - } - - //========== Mutating methods =========== - fun build(): SonarRequest { - val res = SonarRequest(angles) - res.errorCode = errorCode - return res - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - if (wireType.id != WireType.LENGTH_DELIMITED.id) { - errorCode = 1 - return false - } - val expectedByteSize = input.readInt32NoTag() - var readSize = 0 - var arraySize = 0 - input.mark() - do { - var i = 0 - while(readSize < expectedByteSize) { - var tmp = 0 - tmp = input.readInt32NoTag() - arraySize += 1 - readSize += WireFormat.getInt32SizeNoTag(tmp) - } - } while (false) - var newArray = IntArray(arraySize) - input.reset() - do { - var i = 0 - while(i < arraySize) { - newArray[i] = input.readInt32NoTag() - i += 1} - angles = newArray - } while (false) - } - else -> errorCode = 4 - } - return true - } - - fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): SonarRequest.BuilderSonarRequest { - while(getSizeNoTag() < expectedSize) { - parseFieldFrom(input) - } - if (getSizeNoTag() > expectedSize) { errorCode = 2 } - return this - } - - fun parseFrom(input: CodedInputStream): SonarRequest.BuilderSonarRequest { - while(parseFieldFrom(input)) {} - return this - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (angles.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < angles.size) { - arraySize += WireFormat.getInt32SizeNoTag(angles[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (angles.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < angles.size) { - arraySize += WireFormat.getInt32SizeNoTag(angles[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - return size - } - - } - -} - - -class SonarResponse private constructor (var distances: IntArray) { - //========== Properties =========== - //repeated int32 distances = 1 - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //repeated int32 distances = 1 - if (distances.size > 0) { - output.writeTag(1, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (distances.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < distances.size) { - output.writeInt32NoTag (distances[i]) - i += 1 - } - } while(false) - } - - } - - fun mergeWith (other: SonarResponse) { - distances = distances.plus((other.distances)) - this.errorCode = other.errorCode - } - - fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) { - val builder = SonarResponse.BuilderSonarResponse(IntArray(0)) - mergeWith(builder.parseFromWithSize(input, expectedSize).build()) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = SonarResponse.BuilderSonarResponse(IntArray(0)) - mergeWith(builder.parseFrom(input).build()) - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (distances.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (distances.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - return size - } - - //========== Builder =========== - class BuilderSonarResponse constructor (var distances: IntArray) { - //========== Properties =========== - //repeated int32 distances = 1 - fun setDistances(value: IntArray): SonarResponse.BuilderSonarResponse { - distances = value - return this - } - fun setdistancesByIndex(index: Int, value: Int): SonarResponse.BuilderSonarResponse { - distances[index] = value - return this - } - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //repeated int32 distances = 1 - if (distances.size > 0) { - output.writeTag(1, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - - if (distances.size != 0) { - do { - var arraySize = 0 - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - arrayByteSize += arraySize - } while(false) - } - output.writeInt32NoTag(arrayByteSize) - - do { - var i = 0 - while (i < distances.size) { - output.writeInt32NoTag (distances[i]) - i += 1 - } - } while(false) - } - - } - - //========== Mutating methods =========== - fun build(): SonarResponse { - val res = SonarResponse(distances) - res.errorCode = errorCode - return res - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - if (wireType.id != WireType.LENGTH_DELIMITED.id) { - errorCode = 1 - return false - } - val expectedByteSize = input.readInt32NoTag() - var readSize = 0 - var arraySize = 0 - input.mark() - do { - var i = 0 - while(readSize < expectedByteSize) { - var tmp = 0 - tmp = input.readInt32NoTag() - arraySize += 1 - readSize += WireFormat.getInt32SizeNoTag(tmp) - } - } while (false) - var newArray = IntArray(arraySize) - input.reset() - do { - var i = 0 - while(i < arraySize) { - newArray[i] = input.readInt32NoTag() - i += 1} - distances = newArray - } while (false) - } - else -> errorCode = 4 - } - return true - } - - fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): SonarResponse.BuilderSonarResponse { - while(getSizeNoTag() < expectedSize) { - parseFieldFrom(input) - } - if (getSizeNoTag() > expectedSize) { errorCode = 2 } - return this - } - - fun parseFrom(input: CodedInputStream): SonarResponse.BuilderSonarResponse { - while(parseFieldFrom(input)) {} - return this - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (distances.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (distances.size != 0) { - do { - var arraySize = 0 - size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) - var i = 0 - while (i < distances.size) { - arraySize += WireFormat.getInt32SizeNoTag(distances[i]) - i += 1 - } - size += arraySize - size += WireFormat.getInt32SizeNoTag(arraySize) - } while(false) - } - return size - } - - } - -} - - diff --git a/car_fmw/src/proto_src/Task.kt b/car_fmw/src/proto_src/Task.kt deleted file mode 100644 index bd2c3a3428c..00000000000 --- a/car_fmw/src/proto_src/Task.kt +++ /dev/null @@ -1,150 +0,0 @@ -class TaskRequest private constructor (var type: TaskRequest.Type) { - //========== Properties =========== - //enum type = 1 - - var errorCode: Int = 0 - - //========== Nested enums declarations =========== - enum class Type(val id: Int) { - DEBUG (0), - ROUTE (1), - SONAR (2), - ROUTE_METRIC (3), - Unexpected(4); - - companion object { - fun fromIntToType (ord: Int): Type { - return when (ord) { - 0 -> Type.DEBUG - 1 -> Type.ROUTE - 2 -> Type.SONAR - 3 -> Type.ROUTE_METRIC - else -> Unexpected - } - } - } - } - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //enum type = 1 - if (type.id != TaskRequest.Type.fromIntToType(0).id) { - output.writeEnum (1, type.id) - } - - } - - fun mergeWith (other: TaskRequest) { - type = other.type - this.errorCode = other.errorCode - } - - fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) { - val builder = TaskRequest.BuilderTaskRequest(TaskRequest.Type.fromIntToType(0)) - mergeWith(builder.parseFromWithSize(input, expectedSize).build()) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = TaskRequest.BuilderTaskRequest(TaskRequest.Type.fromIntToType(0)) - mergeWith(builder.parseFrom(input).build()) - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (type != TaskRequest.Type.fromIntToType(0)) { - size += WireFormat.getEnumSize(1, type.id) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (type != TaskRequest.Type.fromIntToType(0)) { - size += WireFormat.getEnumSize(1, type.id) - } - return size - } - - //========== Builder =========== - class BuilderTaskRequest constructor (var type: TaskRequest.Type) { - //========== Properties =========== - //enum type = 1 - fun setType(value: TaskRequest.Type): TaskRequest.BuilderTaskRequest { - type = value - return this - } - - var errorCode: Int = 0 - - //========== Serialization methods =========== - fun writeTo (output: CodedOutputStream) { - //enum type = 1 - if (type.id != TaskRequest.Type.fromIntToType(0).id) { - output.writeEnum (1, type.id) - } - - } - - //========== Mutating methods =========== - fun build(): TaskRequest { - val res = TaskRequest(type) - res.errorCode = errorCode - return res - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - if (wireType.id != WireType.VARINT.id) { - errorCode = 1 - return false - } - type = TaskRequest.Type.fromIntToType(input.readEnumNoTag()) - } - else -> errorCode = 4 - } - return true - } - - fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): TaskRequest.BuilderTaskRequest { - while(getSizeNoTag() < expectedSize) { - parseFieldFrom(input) - } - if (getSizeNoTag() > expectedSize) { errorCode = 2 } - return this - } - - fun parseFrom(input: CodedInputStream): TaskRequest.BuilderTaskRequest { - while(parseFieldFrom(input)) {} - return this - } - - //========== Size-related methods =========== - fun getSize(fieldNumber: Int): Int { - var size = 0 - if (type != TaskRequest.Type.fromIntToType(0)) { - size += WireFormat.getEnumSize(1, type.id) - } - size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED) - return size - } - - fun getSizeNoTag(): Int { - var size = 0 - if (type != TaskRequest.Type.fromIntToType(0)) { - size += WireFormat.getEnumSize(1, type.id) - } - return size - } - - } - -} - - diff --git a/kotstd/include/IntArray.kt b/kotstd/include/IntArray.kt index b289c4c40f7..89856aa1ea2 100644 --- a/kotstd/include/IntArray.kt +++ b/kotstd/include/IntArray.kt @@ -46,7 +46,6 @@ class IntArray(var size: Int) { } - fun IntArray.print() { var index = 0 print('[') @@ -117,4 +116,46 @@ operator fun IntArray.plus(elements: IntArray): IntArray { } return newInstance -} \ No newline at end of file +} + +fun IntArray.max(from: Int = 0): Int { + var result = from + for (i in (from + 1)..(size - 1)) { + result = if (get(i) > get(result)) i else result + } + + return get(result) +} + +fun IntArray.min(from: Int = 0): Int { + var result = from + for (i in 1..(size - 1)) { + result = if (this.get(i) < this.get(result)) i else result + } + + return this.get(result) +} + +fun IntArray.sum(): Int { + var result = 0 + for (i in 0..(size - 1)) { + result += this.get(i) + } + + return result +} + +fun IntArray.sort(): IntArray { + val result = this.clone() + for (i in 0..(size - 1)) { + result[i] = this.max(i) + } + + return result +} + +fun IntArray.mean(): Int = + this.sum() / this.size + +fun IntArray.median(): Int = + this.sort()[this.size / 2] diff --git a/proto/protofiles_sources/server_car/sonar.proto b/proto/protofiles_sources/server_car/sonar.proto index 8caa566651a..6dfaee77d33 100644 --- a/proto/protofiles_sources/server_car/sonar.proto +++ b/proto/protofiles_sources/server_car/sonar.proto @@ -5,6 +5,7 @@ message SonarRequest { repeated int32 attempts = 2; int32 threshold = 3; Smoothing smoothing = 4; + int32 windowSize = 5; enum Smoothing { NONE = 0;