| | |
| | | import com.flightfeather.uav.socket.decoder.AirDataDecoder |
| | | import com.flightfeather.uav.socket.decoder.impl.DataPackageDecoderImpl |
| | | import com.flightfeather.uav.socket.eunm.AirCommandUnit |
| | | import io.netty.buffer.Unpooled |
| | | import io.netty.channel.ChannelHandlerContext |
| | | import org.springframework.beans.factory.annotation.Autowired |
| | | import org.springframework.stereotype.Component |
| | |
| | | @Autowired |
| | | lateinit var airDataRepository: AirDataRepository |
| | | |
| | | val vehicleDataDecoder = AirDataDecoder() |
| | | val airDataDecoder = AirDataDecoder.instance |
| | | val dataPackageDecoder = DataPackageDecoderImpl() |
| | | |
| | | @PostConstruct |
| | |
| | | |
| | | fun dealStringMsg(msg: String, ctx: ChannelHandlerContext?) { |
| | | //解包 |
| | | val packageData = vehicleDataDecoder.decode(msg) |
| | | val packageData = airDataDecoder.decode(msg) |
| | | |
| | | |
| | | if (bccCheck(msg)) { |
| | | if (packageData.commandUnit == AirCommandUnit.Confirm.value) { |
| | | val t = mutableListOf<AirTypeData>() |
| | | packageData.dataUnit.forEach { |
| | | if (it is AirTypeData) { |
| | | t.add(it) |
| | | } |
| | | } |
| | | DeviceSession.saveAirType(packageData.deviceCode, t) |
| | | } else if (packageData.commandUnit == AirCommandUnit.AirData.value) { |
| | | val types = DeviceSession.getAirType(packageData.deviceCode) |
| | | } |
| | | //保存 |
| | | DeviceSession.saveDevice(packageData.deviceCode, ctx) |
| | | // saveToTxt(msg) |
| | |
| | | /** |
| | | * 保存至数据库 |
| | | */ |
| | | fun saveToDataBase(packageData: AirPackageData) { |
| | | when (packageData.commandUnit) { |
| | | AirCommandUnit.AirData.value -> instance.airDataRepository.saveAirData(packageData) |
| | | fun saveToDataBase(dataPackage: AirDataPackage) { |
| | | when (dataPackage.commandUnit) { |
| | | AirCommandUnit.AirData.value -> instance.airDataRepository.saveAirData(dataPackage) |
| | | } |
| | | } |
| | | |
| | |
| | | fun bccCheck(msg: String):Boolean { |
| | | val list = mutableListOf<String>().apply { |
| | | addAll(dataPackageDecoder.toStringList(msg)) |
| | | //去除2 位起始符 |
| | | removeAt(0) |
| | | removeAt(0) |
| | | } |
| | | //取得数据包中的bcc校验结果 |
| | | 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 |