From 4cb662daa3d2760cc4c892e58f73cbf10b265f6f Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期五, 11 十二月 2020 11:55:56 +0800 Subject: [PATCH] 新增经纬度、和时间的解析逻辑 --- src/main/kotlin/com/flightfeather/uav/socket/MessageManager.kt | 114 +++++++++----------------------------------------------- 1 files changed, 19 insertions(+), 95 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/socket/MessageManager.kt b/src/main/kotlin/com/flightfeather/uav/socket/MessageManager.kt index 51ad90d..504b3ca 100644 --- a/src/main/kotlin/com/flightfeather/uav/socket/MessageManager.kt +++ b/src/main/kotlin/com/flightfeather/uav/socket/MessageManager.kt @@ -2,14 +2,10 @@ import com.flightfeather.uav.common.utils.FileUtil import com.flightfeather.uav.repository.* -import com.flightfeather.uav.socket.bean.EngineDataStream -import com.flightfeather.uav.socket.bean.ObdInfo -import com.flightfeather.uav.socket.bean.ObdPackageData -import com.flightfeather.uav.socket.bean.SupplementDataStream -import com.flightfeather.uav.socket.decoder.VehicleDataDecoder +import com.flightfeather.uav.socket.bean.* +import com.flightfeather.uav.socket.decoder.AirDataDecoder import com.flightfeather.uav.socket.decoder.impl.DataPackageDecoderImpl -import com.flightfeather.uav.socket.eunm.ObdCommandUnit -import io.netty.buffer.Unpooled +import com.flightfeather.uav.socket.eunm.AirCommandUnit import io.netty.channel.ChannelHandlerContext import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component @@ -31,50 +27,29 @@ } @Autowired - lateinit var obdDataRepository: ObdDataRepository - @Autowired - lateinit var originDataRepository: OriginDataRepository - @Autowired - lateinit var obdInfoRepository: ObdInfoRepository - @Autowired - lateinit var dataStreamRepository: DataStreamRepository - @Autowired - lateinit var carLogoutRepository: CarLogoutRepository - @Autowired - lateinit var carLoginRepository: CarLoginRepository + lateinit var airDataRepository: AirDataRepository - val vehicleDataDecoder = VehicleDataDecoder() + val airDataDecoder = AirDataDecoder.instance val dataPackageDecoder = DataPackageDecoderImpl() @PostConstruct fun init() { instance = this - instance.obdDataRepository = this.obdDataRepository - instance.originDataRepository = this.originDataRepository - instance.obdInfoRepository = this.obdInfoRepository - instance.dataStreamRepository = this.dataStreamRepository - instance.carLogoutRepository = this.carLogoutRepository - instance.carLoginRepository = this.carLoginRepository + airDataRepository = this.airDataRepository } fun dealStringMsg(msg: String, ctx: ChannelHandlerContext?) { //瑙e寘 - val packageData = vehicleDataDecoder.decode(msg) + val packageData = airDataDecoder.decode(msg) - saveToTxt(msg) - val isCommand = command(packageData, ctx) - - if (isCommand) { - println("------杩滅▼鎺у埗鎸囦护 [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]") + if (bccCheck(msg)) { + //淇濆瓨 + DeviceSession.saveDevice(packageData.deviceCode, ctx) +// saveToTxt(msg) + saveToDataBase(packageData) } else { - if (bccCheck(msg)) { - //淇濆瓨 - DeviceSession.saveDevice(packageData.deviceCode, ctx) - saveToDataBase(packageData, msg) - } else { - println("------鏁版嵁BCC鏍¢獙澶辫触锛岃垗寮� [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]") - } + println("------鏁版嵁BCC鏍¢獙澶辫触锛岃垗寮� [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]") } } @@ -89,27 +64,9 @@ /** * 淇濆瓨鑷虫暟鎹簱 */ - fun saveToDataBase(packageData: ObdPackageData, msg: String) { -// instance.obdDataRepository.saveObdData(packageData) - instance.originDataRepository.saveOriginData(packageData, msg) - when (packageData.commandUnit) { - ObdCommandUnit.CarRegister.value -> instance.carLoginRepository.saveCarLogin(packageData) - ObdCommandUnit.RealTimeData.value, - 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) + fun saveToDataBase(dataPackage: AirDataPackage) { + when (dataPackage.commandUnit) { + AirCommandUnit.AirData.value -> instance.airDataRepository.saveAirData(dataPackage) } } @@ -119,15 +76,13 @@ fun bccCheck(msg: String):Boolean { val list = mutableListOf<String>().apply { addAll(dataPackageDecoder.toStringList(msg)) - //鍘婚櫎2 浣嶈捣濮嬬 - removeAt(0) - removeAt(0) } //鍙栧緱鏁版嵁鍖呬腑鐨刡cc鏍¢獙缁撴灉 - val oldBcc = list[list.size - 1].toInt(16) + val oldBcc = "${list[list.lastIndex - 1]}${list[list.lastIndex]}".toInt(16) //鍘婚櫎鏍¢獙缁撴灉 - list.removeAt(list.size-1) + list.removeAt(list.lastIndex) + list.removeAt(list.lastIndex) //璁$畻bcc鏍¢獙缁撴灉 var newBcc = 0x00 @@ -139,37 +94,6 @@ return oldBcc == newBcc } - /** - * 杩滅▼鎸囦护 - */ - fun command(packageData: ObdPackageData, ctx: ChannelHandlerContext?): Boolean { - if (packageData.commandUnit == ObdCommandUnit.Update.value) { - val channel = DeviceSession.getDevice(packageData.deviceCode) - if (channel != null) { - val s = getDataPackage(packageData.deviceCode) - if (s == null) { - ctx?.writeAndFlush("[${packageData.deviceCode}] 璁惧缂栧彿涓虹┖") - } else { - val bytes = encodeToBytes(s) - channel.writeAndFlush(Unpooled.copiedBuffer(bytes)) - ctx?.writeAndFlush("[${packageData.deviceCode}] 鎸囦护鍙戦�佹垚鍔�") - } - } else { - ctx?.writeAndFlush("[${packageData.deviceCode}] 璁惧鏈繛鎺ユ垨涓嶅瓨鍦�") - } - return true - } else if (packageData.commandUnit != ObdCommandUnit.CarRegister.value - && packageData.commandUnit != ObdCommandUnit.RealTimeData.value - && packageData.commandUnit != ObdCommandUnit.ReplacementData.value - && packageData.commandUnit != ObdCommandUnit.CarLogOut.value - && packageData.commandUnit != ObdCommandUnit.TimeCalibration.value) { - ctx?.writeAndFlush("[${packageData.deviceCode}] 鍛戒护涓嶅瓨鍦�") - - return true - } else { - return false - } - } fun encodeToBytes(msg:String): ByteArray { val list = msg.split(" ") -- Gitblit v1.9.3