|
@@ -11,8 +11,12 @@ import com.hboxs.serialport.plc.util.AsciiUtils
|
|
import com.quyunshuo.androidbaseframemvvm.common.util.ByteUtils
|
|
import com.quyunshuo.androidbaseframemvvm.common.util.ByteUtils
|
|
import com.hboxs.serialport.plc.util.HexUtils
|
|
import com.hboxs.serialport.plc.util.HexUtils
|
|
import com.hboxs.serialport.plc.util.HexadecimalUtil
|
|
import com.hboxs.serialport.plc.util.HexadecimalUtil
|
|
|
|
+import com.hboxs.serialport.sbc.SBCHeartbeat
|
|
|
|
+import com.hboxs.serialport.sbc.VBoxMessage
|
|
|
|
+import com.hboxs.serialport.sbc.frame.VboxCommand
|
|
import com.module.backstage.R
|
|
import com.module.backstage.R
|
|
import com.module.backstage.repo.GeneralParamFragmentRepo
|
|
import com.module.backstage.repo.GeneralParamFragmentRepo
|
|
|
|
+import com.quyunshuo.androidbaseframemvvm.base.addressenum.PlcDebugAddressEnum
|
|
import com.quyunshuo.androidbaseframemvvm.base.mvvm.vm.BaseViewModel
|
|
import com.quyunshuo.androidbaseframemvvm.base.mvvm.vm.BaseViewModel
|
|
import com.quyunshuo.androidbaseframemvvm.common.util.ToastUtil
|
|
import com.quyunshuo.androidbaseframemvvm.common.util.ToastUtil
|
|
import com.quyunshuo.androidbaseframemvvm.common.util.UiUtil
|
|
import com.quyunshuo.androidbaseframemvvm.common.util.UiUtil
|
|
@@ -32,7 +36,7 @@ class GeneralParamFragmentVM @Inject constructor(private val mRepo: GeneralParam
|
|
|
|
|
|
//读取到的数据
|
|
//读取到的数据
|
|
// var paramDataList: MutableList<String> = mutableListOf()
|
|
// var paramDataList: MutableList<String> = mutableListOf()
|
|
- var paramDataList = mutableMapOf<String, String>()
|
|
|
|
|
|
+ var paramDataList = mutableMapOf<String, String>()
|
|
|
|
|
|
// val generalParamData: MutableList<String> get() = _generalParamData
|
|
// val generalParamData: MutableList<String> get() = _generalParamData
|
|
private var _readAllDataSuccess = MutableLiveData<Boolean>()//是否读取所有数据成功
|
|
private var _readAllDataSuccess = MutableLiveData<Boolean>()//是否读取所有数据成功
|
|
@@ -53,68 +57,50 @@ class GeneralParamFragmentVM @Inject constructor(private val mRepo: GeneralParam
|
|
return mRepo.arrayList
|
|
return mRepo.arrayList
|
|
}
|
|
}
|
|
|
|
|
|
- fun ack(messageEvent: Message) {
|
|
|
|
- val isContain = PlcParamAddressEnum.valueOf(messageEvent.name) ?: return
|
|
|
|
- ToastUtil.switchToastStyleToSuccess(UiUtil.getStringRes(R.string.backstage_update_success))
|
|
|
|
- mRepo.threadGeneralParam.jobWriteData?.cancel()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- fun response(messageEvent: Message) {
|
|
|
|
- val responseFrame = messageEvent.content as ResponseFrame
|
|
|
|
- //通过校验
|
|
|
|
- val name = messageEvent.name
|
|
|
|
- val result = AsciiUtils.asciiByteArray2HexStr(responseFrame.data)
|
|
|
|
- val results = HexadecimalUtil.flipString(result)
|
|
|
|
- Log.d(TAG, "response name: " + name)
|
|
|
|
- when (name) {
|
|
|
|
|
|
+// fun ack(messageEvent: Message) {
|
|
|
|
+// val isContain = PlcParamAddressEnum.valueOf(messageEvent.name) ?: return
|
|
|
|
+// ToastUtil.switchToastStyleToSuccess(UiUtil.getStringRes(R.string.backstage_update_success))
|
|
|
|
+// mRepo.threadGeneralParam.jobWriteData?.cancel()
|
|
|
|
+// }
|
|
|
|
+// fun response(messageEvent: Message) {
|
|
|
|
+// val responseFrame = messageEvent.content as ResponseFrame
|
|
|
|
+// //通过校验
|
|
|
|
+// val name = messageEvent.name
|
|
|
|
+// val result = AsciiUtils.asciiByteArray2HexStr(responseFrame.data)
|
|
|
|
+// val results = HexadecimalUtil.flipString(result)
|
|
|
|
+// Log.d(TAG, "response name: " + name)
|
|
|
|
+// when (name) {
|
|
// PlcParamAddressEnum.D230.address -> {
|
|
// PlcParamAddressEnum.D230.address -> {
|
|
// D230(results)
|
|
// D230(results)
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
-// PlcParamAddressEnum.D447.address -> {
|
|
|
|
-// D447(results)
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
- else -> {}
|
|
|
|
- }
|
|
|
|
- if (mRepo.threadGeneralParam.isActive230 == false && mRepo.threadGeneralParam.isActive447 == false) {
|
|
|
|
- //关掉一些东西 ,比如:数据展示,关掉加载框,关掉全部的
|
|
|
|
- mRepo.threadGeneralParam.destroy()
|
|
|
|
- //设置readAllDataSuccess为true
|
|
|
|
- _readAllDataSuccess.value = true
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+// else -> {}
|
|
|
|
+// }
|
|
|
|
+// if (mRepo.threadGeneralParam.isActiveParam == false && mRepo.threadGeneralParam.isActive447 == false) {
|
|
|
|
+// //关掉一些东西 ,比如:数据展示,关掉加载框,关掉全部的
|
|
|
|
+// mRepo.threadGeneralParam.destroy()
|
|
|
|
+// //设置readAllDataSuccess为true
|
|
|
|
+// _readAllDataSuccess.value = true
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// }
|
|
//
|
|
//
|
|
|
|
|
|
- private fun D230(results: ArrayList<String>) {
|
|
|
|
- Log.d(TAG, "D230: " + HexadecimalUtil.hex2dec(results[0]).toString())
|
|
|
|
- Log.d(TAG, "D231: " + HexadecimalUtil.hex2dec(results[1]).toString())
|
|
|
|
- Log.d(TAG, "D232: " + HexadecimalUtil.hex2dec(results[2]).toString())
|
|
|
|
- Log.d(TAG, "D233: " + HexadecimalUtil.hex2dec(results[3]).toString())
|
|
|
|
- Log.d(TAG, "D234: " + HexadecimalUtil.hex2dec(results[4]).toString())
|
|
|
|
- Log.d(TAG, "D235: " + HexadecimalUtil.hex2dec(results[5]).toString())
|
|
|
|
- Log.d(TAG, "D236: " + HexadecimalUtil.hex2dec(results[6]).toString())
|
|
|
|
-// paramDataList.put(PlcParamAddressEnum.D230.address, HexadecimalUtil.hex2dec(results[0]).toString())
|
|
|
|
-// paramDataList.put(PlcParamAddressEnum.D231.address, HexadecimalUtil.hex2dec(results[1]).toString())
|
|
|
|
-// paramDataList.put(PlcParamAddressEnum.D232.address, HexadecimalUtil.hex2dec(results[2]).toString())
|
|
|
|
-// paramDataList.put(PlcParamAddressEnum.D233.address, HexadecimalUtil.hex2dec(results[3]).toString())
|
|
|
|
-// paramDataList.put(PlcParamAddressEnum.D234.address, HexadecimalUtil.hex2dec(results[4]).toString())
|
|
|
|
-// paramDataList.put(PlcParamAddressEnum.D235.address, HexadecimalUtil.hex2dec(results[5]).toString())
|
|
|
|
-// paramDataList.put(PlcParamAddressEnum.D236.address, HexadecimalUtil.hex2dec(results[6]).toString())
|
|
|
|
- mRepo.threadGeneralParam.isActive230 = false
|
|
|
|
- mRepo.threadGeneralParam.job230?.cancel()
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private fun D447(results: ArrayList<String>) {
|
|
|
|
- Log.d(TAG, "D447: " + HexadecimalUtil.hex2dec(results[0]).toString())
|
|
|
|
- Log.d(TAG, "D448: " + HexadecimalUtil.hex2dec(results[1]).toString())
|
|
|
|
-// paramDataList.put(PlcParamAddressEnum.D447.address, HexadecimalUtil.hex2dec(results[0]).toString())
|
|
|
|
-// paramDataList.put(PlcParamAddressEnum.D448.address, HexadecimalUtil.hex2dec(results[1]).toString())
|
|
|
|
- mRepo.threadGeneralParam.isActive447 = false
|
|
|
|
- mRepo.threadGeneralParam.job447?.cancel()
|
|
|
|
-
|
|
|
|
|
|
+ private fun getParam(messageEvent: VBoxMessage) {
|
|
|
|
+// paramDataList.put(PlcParamAddressEnum.Param01.address,HexadecimalUtil.hex2dec(messageEvent.data.substring(22, 24)).toString())
|
|
|
|
+// paramDataList.put(PlcParamAddressEnum.Param02.address,HexadecimalUtil.hex2dec(messageEvent.data.substring(24, 26)).toString())
|
|
|
|
+// paramDataList.put(PlcParamAddressEnum.Param03.address,HexadecimalUtil.hex2dec(messageEvent.data.substring(26, 28)).toString())
|
|
|
|
+ paramDataList.put(PlcParamAddressEnum.Param01.address, HexadecimalUtil.hex2dec(SBCHeartbeat.windSpeedLow).toString())
|
|
|
|
+ paramDataList.put(PlcParamAddressEnum.Param02.address, HexadecimalUtil.hex2dec(SBCHeartbeat.windSpeedMid).toString())
|
|
|
|
+ paramDataList.put(PlcParamAddressEnum.Param03.address, HexadecimalUtil.hex2dec(SBCHeartbeat.windSpeedHei).toString())
|
|
|
|
+ paramDataList.put(PlcParamAddressEnum.Param04.address, HexadecimalUtil.hex2dec(messageEvent.data.substring(28, 30)).toString())
|
|
|
|
+ paramDataList.put(PlcParamAddressEnum.Param05.address, HexadecimalUtil.hex2dec(messageEvent.data.substring(30, 32)).toString())
|
|
|
|
+ paramDataList.put(PlcParamAddressEnum.Param06.address, HexadecimalUtil.hex2dec(messageEvent.data.substring(32, 36)).toString())
|
|
|
|
+ paramDataList.put(PlcParamAddressEnum.Param07.address, HexadecimalUtil.hex2dec(messageEvent.data.substring(36, 38)).toString())
|
|
|
|
+ paramDataList.put(PlcParamAddressEnum.Param08.address, HexadecimalUtil.hex2dec(messageEvent.data.substring(38, 40)).toString())
|
|
|
|
+ ToastUtil.switchToastStyleToSuccess(UiUtil.getStringRes(R.string.backstage_update_success))
|
|
|
|
+ mRepo.threadGeneralParam.isActiveParam = false
|
|
|
|
+ mRepo.threadGeneralParam.jobParam?.cancel()
|
|
}
|
|
}
|
|
|
|
|
|
fun getThreadGeneralParam(): LifecycleObserver {
|
|
fun getThreadGeneralParam(): LifecycleObserver {
|
|
@@ -133,15 +119,56 @@ class GeneralParamFragmentVM @Inject constructor(private val mRepo: GeneralParam
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//2进制
|
|
//2进制
|
|
- var bin = HexUtils.hexStr2BinStr(hex)
|
|
|
|
|
|
+// var bin = HexUtils.hexStr2BinStr(hex)
|
|
val plcParamAddressEnum: PlcParamAddressEnum = mRepo.arrayList.get(position)
|
|
val plcParamAddressEnum: PlcParamAddressEnum = mRepo.arrayList.get(position)
|
|
- mRepo.threadGeneralParam.writeData(plcParamAddressEnum.address, bin)
|
|
|
|
|
|
+ getAddressData(plcParamAddressEnum.address)
|
|
|
|
+ mRepo.threadGeneralParam.writeData(plcParamAddressEnum.address, hex)
|
|
}
|
|
}
|
|
- fun writeData(position: Int, data: String) {
|
|
|
|
- //2进制
|
|
|
|
- val plcParamAddressEnum: PlcParamAddressEnum = mRepo.arrayList.get(position)
|
|
|
|
- mRepo.threadGeneralParam.writeData(plcParamAddressEnum.address, data)
|
|
|
|
|
|
+
|
|
|
|
+ private var getAddress = ""
|
|
|
|
+ fun getAddressData(address: String) {
|
|
|
|
+ getAddress = address
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ // fun writeData(position: Int, data: String) {
|
|
|
|
+// //2进制
|
|
|
|
+// val plcParamAddressEnum: PlcParamAddressEnum = mRepo.arrayList.get(position)
|
|
|
|
+// mRepo.threadGeneralParam.writeData(plcParamAddressEnum.address, data)
|
|
|
|
+// }
|
|
|
|
+ fun disposeData(messageEvent: VBoxMessage) {
|
|
|
|
+ when (messageEvent.cmd) {
|
|
|
|
+ VboxCommand.CMD_HEARTBEAT -> {
|
|
|
|
+ Log.d(TAG, "disposeData:1 回来的数据: " + messageEvent.data)
|
|
|
|
+ when (messageEvent.data.substring(2, 4)) {
|
|
|
|
+ "01" -> {
|
|
|
|
+ cmdHeartbeat(messageEvent)
|
|
|
|
+ Log.d(TAG, "disposeData:2 回来的数据: " + messageEvent.data)
|
|
|
|
+ }
|
|
|
|
+ "02" -> {
|
|
|
|
+ if (mRepo.threadGeneralParam.isActiveParam ){
|
|
|
|
+ getParam(messageEvent)
|
|
|
|
+ }
|
|
|
|
+ Log.d(TAG, "disposeData:3 GET_PARAM_ID")
|
|
|
|
+ if (mRepo.threadGeneralParam.isActiveParam == false) {
|
|
|
|
+ //关掉一些东西 ,比如:数据展示,关掉加载框,关掉全部的
|
|
|
|
+ mRepo.threadGeneralParam.destroy()
|
|
|
|
+ //设置readAllDataSuccess为true
|
|
|
|
+ _readAllDataSuccess.value = true
|
|
|
|
+ Log.d(TAG, "disposeData:4 GET_PARAM_ID")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun cmdHeartbeat(messageEvent: VBoxMessage) {
|
|
|
|
+ //调试页的内容
|
|
|
|
+ val data = messageEvent.data.substring(76, 78)
|
|
|
|
+ Log.d(TAG, "CMD_PARAM 修改的参数: " + data + ":" + getAddress)
|
|
|
|
+ if (data == getAddress) {
|
|
|
|
+ mRepo.threadGeneralParam.jobWriteData?.cancel()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|