| | |
| | | package com.flightfeather.uav.socket.processor |
| | | |
| | | import com.flightfeather.uav.repository.AirDataRepository |
| | | import com.flightfeather.uav.biz.FactorFilter |
| | | import com.flightfeather.uav.biz.sourcetrace.RealTimeExceptionAnalysisController |
| | | import com.flightfeather.uav.common.location.LocationRoadNearby |
| | | import com.flightfeather.uav.domain.entity.BaseRealTimeData |
| | | import com.flightfeather.uav.model.epw.EPWDataPrep |
| | | import com.flightfeather.uav.domain.repository.AirDataRep |
| | | import com.flightfeather.uav.domain.repository.RealTimeDataRep |
| | | import com.flightfeather.uav.domain.repository.SceneInfoRep |
| | | import com.flightfeather.uav.domain.repository.SegmentInfoRep |
| | | import com.flightfeather.uav.socket.bean.AirDataPackage |
| | | import com.flightfeather.uav.socket.decoder.AirDataDecoder |
| | | import com.flightfeather.uav.socket.decoder.DataPackageDecoder |
| | | import com.flightfeather.uav.socket.eunm.AirCommandUnit |
| | | import com.flightfeather.uav.socket.eunm.FactorType |
| | | import com.flightfeather.uav.socket.eunm.UWDeviceType |
| | | import com.flightfeather.uav.socket.handler.UnderwayWebSocketServerHandler |
| | | import io.netty.channel.ChannelHandlerContext |
| | | import org.springframework.beans.factory.annotation.Autowired |
| | | import org.springframework.stereotype.Component |
| | |
| | | */ |
| | | |
| | | @Component |
| | | class UnderwayProcessor : BaseProcessor() { |
| | | class UnderwayProcessor( |
| | | private val airDataRep: AirDataRep, |
| | | private val sceneInfoRep: SceneInfoRep, |
| | | ) : BaseProcessor() { |
| | | |
| | | companion object { |
| | | private lateinit var instance: UnderwayProcessor |
| | | |
| | | private const val TAG = "UAV" |
| | | } |
| | | |
| | | @Autowired |
| | | lateinit var airDataRepository: AirDataRepository |
| | | private val airDataDecoder = AirDataDecoder.instance |
| | | private val dataPackageDecoder = DataPackageDecoder() |
| | | |
| | | val airDataDecoder = AirDataDecoder.instance |
| | | val dataPackageDecoder = DataPackageDecoder() |
| | | // 数据预处理函数 |
| | | private val dataProcessMap = mutableMapOf<String?, EPWDataPrep>() |
| | | |
| | | @PostConstruct |
| | | fun init() { |
| | | instance = this |
| | | } |
| | | // 实时走航污染溯源处理器 |
| | | private val realTimeExceptionAnalysisMap = mutableMapOf<String?, RealTimeExceptionAnalysisController>() |
| | | |
| | | override var tag: String = "走航监测" |
| | | |
| | |
| | | //保存 |
| | | deviceSession.saveDevice(packageData.deviceCode, ctx) |
| | | saveToTxt(msg) |
| | | saveToDataBase(packageData) |
| | | saveToDataBase(packageData)?.takeIf { it.isNotEmpty() }?.get(0)?.let { |
| | | // 每台设备有各自单独的异常数据处理器 |
| | | if (!realTimeExceptionAnalysisMap.containsKey(it.deviceCode)) { |
| | | realTimeExceptionAnalysisMap[it.deviceCode] = RealTimeExceptionAnalysisController(sceneInfoRep) |
| | | } |
| | | // 将走航数据传入异常处理器 |
| | | realTimeExceptionAnalysisMap[it.deviceCode]?.addOneData(it) |
| | | } |
| | | |
| | | } else { |
| | | println("------${TAG}数据BCC校验失败,舍弃 [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]") |
| | | } |
| | |
| | | /** |
| | | * 保存至数据库 |
| | | */ |
| | | fun saveToDataBase(dataPackage: AirDataPackage) { |
| | | fun saveToDataBase(dataPackage: AirDataPackage): List<BaseRealTimeData>? { |
| | | when (dataPackage.commandUnit) { |
| | | AirCommandUnit.AirData.value -> instance.airDataRepository.saveAirData(dataPackage) |
| | | AirCommandUnit.AirData.value -> { |
| | | // 以json格式存储原始数据 |
| | | airDataRep.saveAirData(dataPackage) |
| | | // 进行预处理后,存储至对应数据表 |
| | | if (!dataProcessMap.containsKey(dataPackage.deviceCode)) { |
| | | // 每台设备有单独的数据预处理对象 |
| | | dataProcessMap[dataPackage.deviceCode] = EPWDataPrep(UWDeviceType.getType(dataPackage.deviceCode)) |
| | | } |
| | | return dataProcessMap[dataPackage.deviceCode]?.run { |
| | | val list = this.mDataPrep2(dataPackage)// 数据平滑处理 |
| | | airDataRep.savePrepData2(list)// 按照设备类型存储至对应数据表 |
| | | } |
| | | } |
| | | |
| | | else -> return emptyList() |
| | | } |
| | | } |
| | | |
| | |
| | | fun encodeToBytes(msg: String): ByteArray { |
| | | val list = msg.split(" ") |
| | | val bytes = ByteArray(list.size) |
| | | for (i in 0 until list.size) { |
| | | for (i in list.indices) { |
| | | bytes[i] = list[i].toInt(16).toByte() |
| | | } |
| | | |