From 8fc27dba6719041402e3e3c099e2f3e01d9d52c7 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期三, 16 七月 2025 17:30:56 +0800
Subject: [PATCH] 2025.7.16 1. 修改动态溯源异常判断逻辑
---
src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 156 insertions(+), 11 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt b/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt
index ce26095..2961874 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt
@@ -2,7 +2,9 @@
import com.flightfeather.uav.socket.bean.*
import com.flightfeather.uav.socket.eunm.AirCommandUnit
-import java.util.*
+import com.flightfeather.uav.socket.eunm.FactorType
+import org.slf4j.LoggerFactory
+import java.text.SimpleDateFormat
/**
* uav 绗簩灞傛暟鎹崟鍏冭В鐮佸櫒
@@ -11,18 +13,161 @@
*
* 鏁版嵁鍗曞厓鎸夌収鍛戒护鍗曞厓鐨勭被鍨嬪叡鏈変互涓嬪嚑绉嶇被鍨嬶細
* 鍛戒护鍗曞厓 @see [AirCommandUnit]
- * 缂栫爜(byte) 瀹氫箟
- * 0x01 杞﹁締鐧诲叆
- * 0x02 瀹炴椂淇℃伅涓婃姤
- * 0x03 琛ュ彂淇℃伅涓婃姤
- * 0x04 杞﹁締鐧诲嚭
- * 0x05 缁堢鏍℃椂
- * 0x06~0x7f 涓婅鏁版嵁绯荤粺棰勭暀
*/
-interface DataUnitDecoder {
+class DataUnitDecoder {
- fun getAirConfirmData(b: List<String>): List<AirTypeData>
+ private val logger = LoggerFactory.getLogger(javaClass.name)
- fun getAirData(b: List<String>): List<AirData>
+ private val types = mutableMapOf<String?, MutableList<AirTypeData>>()
+
+ fun getAirConfirmData(b: List<String>, deviceCode: String?): List<AirTypeData> {
+ val resultList = mutableListOf<AirTypeData>()
+ b.forEach {
+ FactorType.getByValue(it.toInt(16))?.let { f->
+ resultList.add(AirTypeData(f))
+ }
+ }
+ if (!types.containsKey(deviceCode)) {
+ types[deviceCode] = mutableListOf()
+ }
+ types[deviceCode]?.clear()
+ types[deviceCode]?.addAll(resultList)
+
+ return resultList
+ }
+
+ fun getAirData(b: List<String>, deviceCode: String?): List<AirData> {
+ val resultList = mutableListOf<AirData>()
+
+ if (!types.containsKey(deviceCode)) {
+ return resultList
+ }
+
+ var i = 0
+ types[deviceCode]?.forEach {
+ if (i > b.size - it.factorType.byteLength) {
+ return@forEach
+ }
+
+ when (it.factorType) {
+ FactorType.LNG -> {
+ val valid = b[i].toInt(16).toChar()//缁忕含搴︽槸鍚︽湁鏁堬紙鏈夋晥: A; 鏃犳晥: V锛�
+
+ //缁忕含搴﹀師濮嬪�硷紝渚嬶細121掳30.0411鈥诧紝鍏朵腑 121 瀵瑰簲a1锛�30瀵瑰簲b1锛�04瀵瑰簲b2锛�11瀵瑰簲b3
+ val a1 = b[i + 1].toInt(16)//搴�
+ val b1 = b[i + 2].toInt(16)//鍒嗭紙鏁存暟锛�
+ var b2 = b[i + 3].toInt(16).toDouble()//鍒嗭紙灏忔暟閮ㄥ垎鍓嶄袱浣嶏級
+ var b3 = b[i + 4].toInt(16).toDouble()//鍒嗭紙灏忔暟閮ㄥ垎鍚庝袱浣嶏級
+
+// var b2 = "${b[i + 3]}${b[i + 4]}".toInt(16).toDouble()
+ b2 /= 100
+ b3 /= 10000
+ val lng = a1 + (b1 + b2 + b3) / 60
+ val s = b[i + 5].toInt(16).toChar()
+
+ resultList.add(AirData().apply {
+ factorId = it.factorType.value?.toString()
+ factorName = it.factorType.des
+ factorData = lng
+ statusList = listOf(valid.toString(), s.toString())
+ })
+ }
+ FactorType.LAT -> {
+ val a1 = b[i].toInt(16)
+ val b1 = b[i + 1].toInt(16)
+ var b2 = b[i + 2].toInt(16).toDouble()//鍒嗭紙灏忔暟閮ㄥ垎鍓嶄袱浣嶏級
+ var b3 = b[i + 3].toInt(16).toDouble()//鍒嗭紙灏忔暟閮ㄥ垎鍚庝袱浣嶏級
+
+ b2 /= 100
+ b3 /= 10000
+ val lat = a1 + (b1 + b2 + b3) / 60
+ val s = b[i + 4].toInt(16).toChar()
+ resultList.add(AirData().apply {
+ factorId = it.factorType.value.toString()
+ factorName = it.factorType.des
+ factorData = lat
+ statusList = listOf(s.toString())
+ })
+ }
+ FactorType.TIME -> {
+ val year = b[i].toInt(16).toString().run { numberFormat(this) }
+ val month = b[i + 1].toInt(16).toString().run { numberFormat(this) }
+ val day = b[i + 2].toInt(16).toString().run { numberFormat(this) }
+ val hour = b[i + 3].toInt(16).toString().run { numberFormat(this) }
+ val minute = b[i + 4].toInt(16).toString().run { numberFormat(this) }
+ val second = b[i + 5].toInt(16).toString().run { numberFormat(this) }
+ val date = "20$year-$month-$day $hour:$minute:$second"
+ val time = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date).time
+ resultList.add(AirData().apply {
+ factorId = it.factorType.value.toString()
+ factorName = it.factorType.des
+ factorData = time.toDouble()
+ statusList = listOf(date)
+ })
+ }
+ else -> {
+ 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+3]}${b[i + 4]}".toInt(16)
+ var b2 = b[i + 5].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
+ })
+ }
+ AirDataPackage.FACTOR_BIT_LENGTH_3 -> {
+ val data = "${b[i]}${b[i + 1]}".toInt(16)
+ resultList.add(AirData().apply {
+ factorId = it.factorType.value.toString()
+ factorName = it.factorType.des
+ factorData = data.toDouble()
+ })
+ }
+ }
+ }
+ }
+
+ i += it.factorType.byteLength
+ }
+
+ return resultList
+ }
+
+ private fun numberFormat(num: String) =
+ if (num.length < 2) {
+ "0$num"
+ } else {
+ num
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3