package com.flightfeather.uav.socket.decoder.impl
|
|
import com.flightfeather.uav.socket.bean.AirData
|
import com.flightfeather.uav.socket.bean.AirTypeData
|
import com.flightfeather.uav.socket.decoder.DataUnitDecoder
|
import com.flightfeather.uav.socket.eunm.FactorType
|
import org.slf4j.LoggerFactory
|
|
/**
|
* @author riku
|
* Date: 2019/9/15
|
*/
|
class DataUnitDecoderImpl : DataUnitDecoder {
|
|
private val logger = LoggerFactory.getLogger(javaClass.name)
|
|
|
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))
|
}
|
}
|
return resultList
|
}
|
|
override fun getAirData(b: List<String>): List<AirData> {
|
val resultList = mutableListOf<AirData>()
|
var i = 0
|
while (i < b.size - 3) {
|
val a = "${b[i]}${b[i + 1]}".toInt(16)
|
var b1 = b[i + 2].toInt(16).toDouble()
|
while (b1 >= 1) {
|
b1 /= 10
|
}
|
val data = a + b1
|
resultList.add(AirData().apply {
|
factorData = data
|
})
|
i += 3
|
}
|
|
return resultList
|
}
|
}
|