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
|
}
|
}
|
}
|