riku
2020-06-11 585fb9b67dc81f9e14f2cbf59f1c3a02eb4fe98f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
    }
}