From 25d0f31f22f77a914a50bbc088902e00e28c4889 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期三, 15 七月 2020 11:10:42 +0800 Subject: [PATCH] 根据新的多参数传输协议,修改解析规则 --- src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt b/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt index 4f70a2a..dac72d9 100644 --- a/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt +++ b/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt @@ -1,6 +1,7 @@ package com.flightfeather.uav.socket.decoder.impl import com.flightfeather.uav.socket.bean.AirData +import com.flightfeather.uav.socket.bean.AirDataPackage import com.flightfeather.uav.socket.bean.AirTypeData import com.flightfeather.uav.socket.decoder.DataUnitDecoder import com.flightfeather.uav.socket.eunm.FactorType @@ -14,6 +15,7 @@ private val logger = LoggerFactory.getLogger(javaClass.name) + private val types = mutableListOf<AirTypeData>() override fun getAirConfirmData(b: List<String>): List<AirTypeData> { val resultList = mutableListOf<AirTypeData>() @@ -22,23 +24,61 @@ resultList.add(AirTypeData(f)) } } + types.clear() + types.addAll(resultList) + return resultList } override fun getAirData(b: List<String>): List<AirData> { val resultList = mutableListOf<AirData>() + var i = 0 - while (i < b.size - 3) { - val a = "${b[i]}${b[i + 1]}".toInt(16) - var b1 = b[i + 2].toInt(16).toDouble() - while (b1 >= 1) { - b1 /= 10 + types.forEach { + if (i > b.size - it.factorType.byteLength) { + return@forEach } - val data = a + b1 - resultList.add(AirData().apply { - factorData = data - }) - i += 3 + when (it.factorType.byteLength) { + AirDataPackage.FACTOR_BIT_LENGTH_2 -> { + val a1 = "${b[i]}${b[i + 1]}".toInt(16) + var b1 = b[i + 2].toInt(16).toDouble() + while (b1 >= 1) { + b1 /= 10 + } + val data1 = a1 + b1 + + resultList.add(AirData().apply { + factorId = it.factorType.value?.toString() + factorName = it.factorType.des + factorData = data1 + }) + } + AirDataPackage.FACTOR_BIT_LENGTH_1 -> { + //鏁版嵁瀹為檯鍊硷紙3浣嶅瓧鑺傝〃绀猴級 + val a1 = "${b[i]}${b[i + 1]}".toInt(16) + var b1 = b[i + 2].toInt(16).toDouble() + while (b1 >= 1) { + b1 /= 10 + } + val data1 = a1 + b1 + + //鏁版嵁鐗╃悊閲忥紙3浣嶅瓧鑺傝〃绀猴級 + val a2 = "${b[i]}${b[i + 1]}".toInt(16) + var b2 = b[i + 2].toInt(16).toDouble() + while (b2 >= 1) { + b2 /= 10 + } + val data2 = a2 + b2 + + resultList.add(AirData().apply { + factorId = it.factorType.value?.toString() + factorName = it.factorType.des + factorData = data1 + physicalQuantity = data2 + }) + } + } + i += it.factorType.byteLength } return resultList -- Gitblit v1.9.3