From 259512005923831d1221bd49568751bf519dc020 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 18 九月 2019 23:18:10 +0800
Subject: [PATCH] 1. 修复保存obd 信息体方法未被调用的问题

---
 src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt |   12 ++++++------
 src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt   |    4 ++--
 src/test/kotlin/com/flightfeather/obd/Test.kt                                    |   14 +++++++++++++-
 src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt                   |   18 +++++++++++++++++-
 4 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt b/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt
index e413f7d..e57d960 100644
--- a/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt
+++ b/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt
@@ -2,7 +2,10 @@
 
 import com.flightfeather.obd.common.utils.FileUtil
 import com.flightfeather.obd.repository.*
+import com.flightfeather.obd.socket.bean.EngineDataStream
+import com.flightfeather.obd.socket.bean.ObdInfo
 import com.flightfeather.obd.socket.bean.ObdPackageData
+import com.flightfeather.obd.socket.bean.SupplementDataStream
 import com.flightfeather.obd.socket.decoder.VehicleDataDecoder
 import com.flightfeather.obd.socket.decoder.impl.DataPackageDecoderImpl
 import com.flightfeather.obd.socket.eunm.ObdCommandUnit
@@ -84,7 +87,20 @@
         when (packageData.commandUnit) {
             ObdCommandUnit.CarRegister.value -> instance.carLoginRepository.saveCarLogin(packageData)
             ObdCommandUnit.RealTimeData.value,
-            ObdCommandUnit.ReplacementData.value -> instance.dataStreamRepository.saveDataStream(packageData)
+            ObdCommandUnit.ReplacementData.value -> {
+                var done = false
+                for (i in 0 until packageData.dataUnit.size) {
+                    when (packageData.dataUnit[i]) {
+                        is ObdInfo -> instance.obdInfoRepository.saveObdInfo(packageData)
+                        is EngineDataStream,
+                        is SupplementDataStream -> {
+                            instance.dataStreamRepository.saveDataStream(packageData)
+                            done = true
+                        }
+                    }
+                    if (done) break
+                }
+            }
             ObdCommandUnit.CarLogOut.value-> instance.carLogoutRepository.saveCarLogout(packageData)
         }
     }
diff --git a/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt b/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt
index 0645f5a..a2875b4 100644
--- a/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt
+++ b/src/main/kotlin/com/flightfeather/obd/socket/decoder/impl/DataUnitDecoderImpl.kt
@@ -32,10 +32,10 @@
         val time = decodeDataTime(b)
 
         //鍥芥爣娉�: 璧峰瀛楄妭涓�7 寮�濮嬬殑2涓瓧鑺傝〃绀� 娴佹按鍙�
-        val serialNum = "${b[7]}${b[8]}".toInt(16)
+//        val serialNum = "${b[7]}${b[8]}".toInt(16)
 
         //涓婃捣娉�: 璧峰瀛楄妭涓�6 寮�濮嬬殑2涓瓧鑺傝〃绀� 娴佹按鍙�
-//        val serialNum = "${b[6]}${b[7]}".toInt(16)
+        val serialNum = "${b[6]}${b[7]}".toInt(16)
 
         val dataList = mutableListOf<String>().apply { addAll(b) }
         //鍒犲幓鍓�6浣嶆椂闂�
@@ -48,15 +48,15 @@
         * 鍒犲幓娴佹按鍙凤紝寰楀埌淇℃伅鏍囧織涓庝俊鎭綋鐨勭粍鍚�
         * (鍥芥爣娉曪細鍘婚櫎鍓�6浣嶆椂闂村悗锛岃捣濮嬪瓧鑺備负1 寮�濮嬬殑2涓瓧鑺傝〃绀� 娴佹按鍙�)
         */
-        if (dataList.size >= 2) dataList.removeAt(1)
-        if (dataList.size >= 2) dataList.removeAt(1)
+//        if (dataList.size >= 2) dataList.removeAt(1)
+//        if (dataList.size >= 2) dataList.removeAt(1)
 
         /*
         * 鍒犲幓娴佹按鍙凤紝寰楀埌淇℃伅鏍囧織涓庝俊鎭綋鐨勭粍鍚�
         * (涓婃捣娉曪細鍘婚櫎鍓�6浣嶆椂闂村悗锛岃捣濮嬪瓧鑺備负0 寮�濮嬬殑2涓瓧鑺傝〃绀� 娴佹按鍙�)
         */
-//        if (dataList.isNotEmpty()) dataList.removeAt(0)
-//        if (dataList.isNotEmpty()) dataList.removeAt(0)
+        if (dataList.isNotEmpty()) dataList.removeAt(0)
+        if (dataList.isNotEmpty()) dataList.removeAt(0)
 
         val resultList = mutableListOf<RealTimeData>()
 
diff --git a/src/test/kotlin/com/flightfeather/obd/Test.kt b/src/test/kotlin/com/flightfeather/obd/Test.kt
index 0693195..7a7ca8f 100644
--- a/src/test/kotlin/com/flightfeather/obd/Test.kt
+++ b/src/test/kotlin/com/flightfeather/obd/Test.kt
@@ -14,7 +14,8 @@
     @Test
     fun foo1() {
         val b = ByteArray(20) {8}
-        println(b[18])
+        val a = 1
+        println(a.toString(2))
     }
 
     @Test
@@ -127,4 +128,15 @@
 
         println(SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.time))
     }
+
+    @Test
+    fun f0012() {
+        ByteArray(3).forEach {
+            println(it)
+            return
+        }
+
+        println("end")
+
+    }
 }
\ No newline at end of file
diff --git a/src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt b/src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt
index bfdb760..c9cfda5 100644
--- a/src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt
+++ b/src/test/kotlin/com/flightfeather/obd/socket/decoder/VehicleDataDecoderTest.kt
@@ -15,9 +15,9 @@
 
     @Test
     fun decode() {
-        val msg = "23 23 02 31 37 36 39 31 35 33 31 39 30 39 31 32 30 30 30 36 01 01 00 42 13 09 11 08 3b 36 02 00 3a 00 00 d4 00 00 12 c0 09 5e 00 c8 00 c8 00 15 a9 00 00 00 00 00 00 73 00 00 00 b9 1b c7 00 2e e1 24 00 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 dc"
+        val msg = "23 23 02 31 37 36 39 31 35 33 31 39 30 39 31 32 30 30 30 32 01 01 00 85 13 09 12 15 01 2d 00 08 01 00 01 60 00 00 00 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 07 00 00 04 20 00 00 04 20 00 00 c1 13 00 00 00 73 00 00 30 28 00 00 30 25 00 00 30 56 1d"
         val msg2 = "23 23 02 31 37 36 39 31 35 33 31 39 30 39 31 32 30 30 30 36 01 01 00 42 13 09 11 08 3b 36 02 00 3b 00 00 d4 00 00 12 c0 09 5e 00 c8 00 c8 00 15 a9 00 00 00 00 00 00 73 00 00 00 b9 1b c7 00 2e e1 25 00 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 dc"
-        val packageData = vehicleDataDecoder.decode(msg2)
+        val packageData = vehicleDataDecoder.decode(msg)
 
         val obdData = ObdData().apply {
             obdVin = packageData.deviceCode

--
Gitblit v1.9.3