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 | 157 +++++++++++++++++++--------------------------------- 1 files changed, 58 insertions(+), 99 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 ef8f26d..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,12 +1,11 @@ package com.flightfeather.uav.socket.decoder.impl -import com.flightfeather.uav.socket.bean.* +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.decoder.RealTimeDataDecoder -import com.flightfeather.uav.socket.eunm.ObdDataType +import com.flightfeather.uav.socket.eunm.FactorType import org.slf4j.LoggerFactory -import java.lang.StringBuilder -import java.util.* /** * @author riku @@ -15,113 +14,73 @@ class DataUnitDecoderImpl : DataUnitDecoder { private val logger = LoggerFactory.getLogger(javaClass.name) - private var realTimeDataDecoder: RealTimeDataDecoder = RealTimeDataDecoderImpl() - override fun getCarRegisterData(b: List<String>): List<CarRegisterData> { - val time = decodeDataTime(b) + private val types = mutableListOf<AirTypeData>() - val serialNum = "${b[6]}${b[7]}".toInt(16) - - val simCode = StringBuilder() - for (i in 10 until b.size) { - simCode.append(b[i].toInt(16).toChar()) - } - - return mutableListOf(CarRegisterData(time, serialNum, simCode.toString())) - } - - override fun getRealTimeData(b: List<String>): List<RealTimeData> { - val time = decodeDataTime(b) - - //鍥芥爣娉�: 璧峰瀛楄妭涓�7 寮�濮嬬殑2涓瓧鑺傝〃绀� 娴佹按鍙� -// val serialNum = "${b[7]}${b[8]}".toInt(16) - - //涓婃捣娉�: 璧峰瀛楄妭涓�6 寮�濮嬬殑2涓瓧鑺傝〃绀� 娴佹按鍙� - val serialNum = "${b[6]}${b[7]}".toInt(16) - - val dataList = mutableListOf<String>().apply { addAll(b) } - //鍒犲幓鍓�6浣嶆椂闂� - for (i in 0..5) { - if (dataList.isNotEmpty()) dataList.removeAt(0) - } - - //fixme 2019.9.15 鐩墠涓ょ瑙勫垯鏈夊啿绐侊紝骞朵笖鍙粠鏁版嵁鍐呭鏃犳硶鍖哄垎銆傛殏鏃朵娇鐢� 鍥芥爣娉� - /* - * 鍒犲幓娴佹按鍙凤紝寰楀埌淇℃伅鏍囧織涓庝俊鎭綋鐨勭粍鍚� - * (鍥芥爣娉曪細鍘婚櫎鍓�6浣嶆椂闂村悗锛岃捣濮嬪瓧鑺備负1 寮�濮嬬殑2涓瓧鑺傝〃绀� 娴佹按鍙�) - */ -// 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) - - val resultList = mutableListOf<RealTimeData>() - - /* - * 鏈�缁堝緱鍒扮殑鏁版嵁缁撴瀯涓� [ 淇℃伅绫诲瀷鏍囧織, 淇℃伅浣�, ...... , 淇℃伅绫诲瀷鏍囧織, 淇℃伅浣� ] - */ - while (dataList.isNotEmpty()) { - //寰楀埌鏈�鍓嶉潰鐨勪竴缁勪俊鎭被鍨�+淇℃伅浣撳垪琛� - val data = realTimeDataDecoder.getDataListByDataType(dataList) - if (data.isNotEmpty()) { - val r = when (data[0].toInt(16)) { - ObdDataType.ObdData.value -> realTimeDataDecoder.getObdData(time, serialNum, data) - ObdDataType.EngineDataFlow.value -> realTimeDataDecoder.getEngineDataStream(time, serialNum, data) - ObdDataType.SupplementDataFlow.value -> realTimeDataDecoder.getSupplementDataStream(time, serialNum, data) - else -> null - } - - if (r != null) { - resultList.add(r) - } - - for (i in 0 until data.size) { - if (dataList.isNotEmpty()) dataList.removeAt(0) - } - }else if (dataList.isNotEmpty()) { - //鎸夌収瑙勫垯娌℃湁鍙栧埌淇℃伅浣擄紝骞朵笖鍘熸暟鎹笉涓虹┖锛岃〃绀哄師鏁版嵁鏍煎紡閿欒锛岄��鍑哄惊鐜� - logger.error("-------鏁版嵁淇℃伅娴佹垨琛ュ厖鏁版嵁娴佹牸寮忛敊璇�") - break + override fun getAirConfirmData(b: List<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) return resultList } - override fun getReplacementData(b: List<String>): List<ReplacementData> = getRealTimeData(b) + override fun getAirData(b: List<String>): List<AirData> { + val resultList = mutableListOf<AirData>() - override fun getCarLogOutData(b: List<String>): List<CarLogOutData> { - val time = decodeDataTime(b) + var i = 0 + types.forEach { + if (i > b.size - it.factorType.byteLength) { + return@forEach + } + 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 - val serialNum = "${b[6]}${b[7]}".toInt(16) + 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 - return mutableListOf(CarLogOutData(time, serialNum)) - } + //鏁版嵁鐗╃悊閲忥紙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 - override fun getTimeCalibrationData(b: List<String>): List<TimeCalibrationData> = emptyList() - - override fun decodeDataTime(b: List<String>): Date? { - if (b.size < 6) { - return null + resultList.add(AirData().apply { + factorId = it.factorType.value?.toString() + factorName = it.factorType.des + factorData = data1 + physicalQuantity = data2 + }) + } + } + i += it.factorType.byteLength } - val year = b[0].toInt(16) + 2000 - if (year < 2000 || year > 2099) return null - val month = b[1].toInt(16) - val day = b[2].toInt(16) - val hour = b[3].toInt(16) - val min = b[4].toInt(16) - val sec = b[5].toInt(16) - val cal = Calendar.getInstance().apply { - set(year, month - 1, day, hour, min, sec) - set(Calendar.MILLISECOND, 0) - } - - return cal.time + return resultList } } \ No newline at end of file -- Gitblit v1.9.3