From 09f411e381f885619b32e05fc89cad26bb20824d Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 01 三月 2021 14:27:56 +0800
Subject: [PATCH] Merge remote-tracking branch 'obdserver2/master'

---
 src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt |   56 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 38 insertions(+), 18 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 1af1944..a5ffbd5 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
@@ -16,26 +16,33 @@
 
     private val logger = LoggerFactory.getLogger(javaClass.name)
 
-    private val types = mutableListOf<AirTypeData>()
+    private val types = mutableMapOf<String?, MutableList<AirTypeData>>()
 
-    override fun getAirConfirmData(b: List<String>): List<AirTypeData> {
+    override fun getAirConfirmData(b: List<String>, deviceCode: String?): List<AirTypeData> {
         val resultList = mutableListOf<AirTypeData>()
         b.forEach {
             FactorType.getByIndex(it.toInt(16))?.let { f->
                 resultList.add(AirTypeData(f))
             }
         }
-        types.clear()
-        types.addAll(resultList)
+        if (!types.containsKey(deviceCode)) {
+            types[deviceCode] = mutableListOf()
+        }
+        types[deviceCode]?.clear()
+        types[deviceCode]?.addAll(resultList)
 
         return resultList
     }
 
-    override fun getAirData(b: List<String>): List<AirData> {
+    override fun getAirData(b: List<String>, deviceCode: String?): List<AirData> {
         val resultList = mutableListOf<AirData>()
 
+        if (!types.containsKey(deviceCode)) {
+            return resultList
+        }
+
         var i = 0
-        types.forEach {
+        types[deviceCode]?.forEach {
             if (i > b.size - it.factorType.byteLength) {
                 return@forEach
             }
@@ -43,13 +50,17 @@
             when (it.factorType) {
                 FactorType.LNG -> {
                     val valid = b[i].toInt(16).toChar()//缁忕含搴︽槸鍚︽湁鏁堬紙鏈夋晥: A; 鏃犳晥: V锛�
-                    val a1 = b[i + 1].toInt(16)
-                    val b1 = b[i + 2].toInt(16)
-                    var b2 = "${b[i + 3]}${b[i + 4]}".toInt(16).toDouble()
-                    while (b2 >= 1) {
-                        b2 /= 10
-                    }
-                    val lng = a1 + (b1 + b2) / 60
+
+                    //缁忕含搴﹀師濮嬪�硷紝渚嬶細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 {
@@ -62,11 +73,12 @@
                 FactorType.LAT -> {
                     val a1 = b[i].toInt(16)
                     val b1 = b[i + 1].toInt(16)
-                    var b2 = "${b[i + 2]}${b[i + 3]}".toInt(16).toDouble()
-                    while (b2 >= 1) {
-                        b2 /= 10
-                    }
-                    val lat = a1 + (b1 + b2) / 60
+                    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()
@@ -131,6 +143,14 @@
                                 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()
+                            })
+                        }
                     }
                 }
             }

--
Gitblit v1.9.3