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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.flightfeather.uav.socket.decoder
 
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.socket.bean.ElectricMessage
import org.springframework.stereotype.Component
 
@Component
class ElectricDataDecoder:BaseDataDecoder<ElectricMessage>() {
    private val dateUtil = DateUtil.instance
 
    override fun messageClass(): Class<ElectricMessage> = ElectricMessage::class.java
 
    override fun getCpDecode(): List<Decode<ElectricMessage>> = listOf(
        getDataTime,
        getElectricityA, getElectricityB, getElectricityC,
        getVoltageA, getVoltageB, getVoltageC,
        getPowerA, getPowerB, getPowerC
    )
 
    private val getDataTime: Decode<ElectricMessage> = { e, s ->
        val time = getData(s, "DataTime=", ";")
        time.let {
            val date = if (it.length > "yyyyMMddHHmmss".length) {
                dateUtil.StringToDate(it, "yyyyMMddHHmmssSSS")
            } else {
                dateUtil.StringToDate(it, "yyyyMMddHHmmss")
            }
            e.dataTime = date
        }
    }
 
    private val getElectricityA: Decode<ElectricMessage> = { e, s ->
        getData(s, "550-Rtd=", ";").let {
            e.electricityA = it.toDoubleOrNull() ?: INVALID_VALUE
        }
    }
 
    private val getElectricityB: Decode<ElectricMessage> = { e, s ->
        getData(s, "551-Rtd=", ";").let {
            e.electricityB = it.toDoubleOrNull() ?: INVALID_VALUE
        }
    }
 
    private val getElectricityC: Decode<ElectricMessage> = { e, s ->
        getData(s, "552-Rtd=", ";").let {
            e.electricityC = it.toDoubleOrNull() ?: INVALID_VALUE
        }
    }
 
    private val getVoltageA: Decode<ElectricMessage> = { e, s ->
        getData(s, "553-Rtd=", ";").let {
            e.voltageA = it.toDoubleOrNull() ?: INVALID_VALUE
        }
    }
 
    private val getVoltageB: Decode<ElectricMessage> = { e, s ->
        getData(s, "554-Rtd=", ";").let {
            e.voltageB = it.toDoubleOrNull() ?: INVALID_VALUE
        }
    }
 
    private val getVoltageC: Decode<ElectricMessage> = { e, s ->
        getData(s, "555-Rtd=", ";").let {
            e.voltageC = it.toDoubleOrNull() ?: INVALID_VALUE
        }
    }
 
    private val getPowerA: Decode<ElectricMessage> = { e, s ->
        getData(s, "556-Rtd=", ";").let {
            e.powerA = it.toDoubleOrNull() ?: INVALID_VALUE
        }
    }
 
    private val getPowerB: Decode<ElectricMessage> = { e, s ->
        getData(s, "557-Rtd=", ";").let {
            e.powerB = it.toDoubleOrNull() ?: INVALID_VALUE
        }
    }
 
    private val getPowerC: Decode<ElectricMessage> = { e, s ->
        getData(s, "558-Rtd=", ";").let {
            e.powerC = it.toDoubleOrNull() ?: INVALID_VALUE
        }
    }
}