From 4d44ed185203088052b10a8d1e3526fcbbc88331 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期日, 15 九月 2019 18:42:31 +0800
Subject: [PATCH] obd 数据解码逻辑完成

---
 src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt |   43 ++++++++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt b/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt
index b709839..6f1a280 100644
--- a/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt
+++ b/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt
@@ -1,12 +1,15 @@
 package com.flightfeather.obd.socket
 
+import com.flightfeather.obd.common.utils.FileUtil
 import com.flightfeather.obd.lightshare.bean.BaseJson
 import com.flightfeather.obd.lightshare.bean.ObdDataVo
 import com.flightfeather.obd.repository.ObdDataRepository
+import com.flightfeather.obd.socket.decoder.VehicleDataDecoder
 import com.google.gson.Gson
 import io.netty.channel.ChannelHandlerContext
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Component
+import org.springframework.util.FileSystemUtils
 import javax.annotation.PostConstruct
 import javax.annotation.Resource
 
@@ -26,24 +29,38 @@
     @Autowired
     lateinit var obdDataRepository: ObdDataRepository
 
+    val vehicleDataDecoder = VehicleDataDecoder()
+
     @PostConstruct
     fun init() {
         instance = this
         instance.obdDataRepository = this.obdDataRepository
     }
 
-    fun dealMsg(msg: String, ctx: ChannelHandlerContext?) {
-        try {
-            val baseJson = Gson().fromJson<BaseJson>(msg, BaseJson::class.java)
-            when (baseJson.cmdCode) {
-                2001 -> {
-                    val data = Gson().fromJson(msg, ObdDataVo::class.java)
-                    DeviceSession.saveDevice(data.obdVin, ctx)
-                    instance.obdDataRepository.saveObdData(data)
-                }
-            }
-        } catch (e: Throwable) {
-//            println("------鏀跺埌鏍煎紡閿欒鐨勬暟鎹細$msg")
-        }
+    fun dealStringMsg(msg: String, ctx: ChannelHandlerContext?) {
+//        try {
+//            val baseJson = Gson().fromJson<BaseJson>(msg, BaseJson::class.java)
+//            when (baseJson.cmdCode) {
+//                2001 -> {
+//                    val data = Gson().fromJson(msg, ObdDataVo::class.java)
+//                    DeviceSession.saveDevice(data.obdVin, ctx)
+//                    instance.obdDataRepository.saveObdData(data)
+//                }
+//            }
+//        } catch (e: Throwable) {
+//        }
+
+        saveToTxt(msg)
+        val packageData = vehicleDataDecoder.decode(msg)
+    }
+
+    fun dealByteArrayMsg(msg: ByteArray, ctx: ChannelHandlerContext?) {
+        val b = ByteArray(20) {19}
+        println(b)
+    }
+
+    fun saveToTxt(msg: String) {
+        val data = "data=> $msg"
+        FileUtil.instance?.saveObdData(data)
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3