优化
This commit is contained in:
@@ -19,6 +19,7 @@ import com.shuwei.intelligent.shelves.R
|
||||
import com.shuwei.intelligent.shelves.adapter.ShelfAdapter
|
||||
import com.shuwei.intelligent.shelves.base.BaseActivity
|
||||
import com.shuwei.intelligent.shelves.databinding.ActivityHomeBinding
|
||||
import com.shuwei.intelligent.shelves.dialog.CommonDialog
|
||||
import com.shuwei.intelligent.shelves.model.ClearShelfEvent
|
||||
import com.shuwei.intelligent.shelves.model.SendWeightEvent
|
||||
import com.shuwei.intelligent.shelves.model.ShelfBody
|
||||
@@ -32,7 +33,9 @@ import com.shuwei.intelligent.shelves.net.UiState
|
||||
import com.shuwei.intelligent.shelves.net.apiService
|
||||
import com.shuwei.intelligent.shelves.serial.SerialPortManager
|
||||
import com.shuwei.intelligent.shelves.task.TaskManager
|
||||
import com.shuwei.intelligent.shelves.utils.HexUtils
|
||||
import com.shuwei.intelligent.shelves.utils.binaryToHex
|
||||
import com.shuwei.intelligent.shelves.utils.ext.copyTextToClipboard
|
||||
import com.shuwei.intelligent.shelves.utils.ext.gone
|
||||
import com.shuwei.intelligent.shelves.utils.ext.toJsonString
|
||||
import com.shuwei.intelligent.shelves.utils.ext.toast
|
||||
@@ -52,6 +55,7 @@ class HomeActivity : BaseActivity() {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "HomeActivity"
|
||||
private const val LOG_PREFIX = "receiveSerialPortData:收到"
|
||||
|
||||
private const val MM_DD_EEEE__HH_MM_SS = "MM月dd日 EEEE HH:mm:ss"
|
||||
|
||||
@@ -72,10 +76,16 @@ class HomeActivity : BaseActivity() {
|
||||
|
||||
const val DEVICE_INFO_CMD = "${HEADER}0301000000000000000000000000${FOOTER}"
|
||||
|
||||
//const val START_CMD= "${HEADER}0F01360000${FOOTER}"
|
||||
const val START_TEMP_CTRL_CMD= "${HEADER}0F01360000${FOOTER}"
|
||||
//const val START_CMD= "${HEADER}0F01050020${FOOTER}"
|
||||
//const val ACTIVE_CMD = "${HEADER}000281C5D70A7D428948AD7254FADBB1516738938B4B9CBD73673E9D8E7F2E15062D$FOOTER"
|
||||
const val ACTIVE_CMD = "${HEADER}000281C5D70A7D42894EA17650F5D0BB516838E7863C9ABD766C38958AFF0F3C062D${FOOTER}"
|
||||
const val ACTIVE_CMD =
|
||||
"${HEADER}000281C5D70A7D42894EA17650F5D0BB516838E7863C9ABD766C38958AFF0F3C062D${FOOTER}"
|
||||
|
||||
//华氏温度单位
|
||||
const val F_TEMP_CMD = "${HEADER}0F01390000${FOOTER}"
|
||||
//摄氏温度单位
|
||||
const val C_TEMP_CMD = "${HEADER}0F01390001${FOOTER}"
|
||||
|
||||
//开灯(开 继电器1)
|
||||
const val LIGHT_CLOSE = "${HEADER}020102020102020000000000000000000000000000${FOOTER}"
|
||||
@@ -150,6 +160,12 @@ class HomeActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
//sendCmd(ACTIVE_CMD)
|
||||
|
||||
binding.root.postDelayed({
|
||||
sendCmd(START_TEMP_CTRL_CMD)
|
||||
sendCmd(C_TEMP_CMD)
|
||||
}, 5000)
|
||||
|
||||
TaskManager.startTask()
|
||||
|
||||
// var androidId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
|
||||
@@ -169,36 +185,6 @@ class HomeActivity : BaseActivity() {
|
||||
|
||||
viewModel.getShelfList(deviceId = App.deviceId)
|
||||
|
||||
// repeat(100) {
|
||||
// lifecycleScope.launch {
|
||||
// val data = "D6DADEDB01010C6102000000000000010000000500008000000000060000000500000004000080060000000100000010190080701800800000000000000000000000000000000000000000000000005037414645333633333334333731373056322E313069FFFF"
|
||||
// receiveSerialPortData(data)
|
||||
// delay(500)
|
||||
// }
|
||||
// }
|
||||
|
||||
// lifecycleScope.launch {
|
||||
// repeat(100) {
|
||||
// val sb = StringBuilder().apply {
|
||||
//// 610200000000000001000000050000800000000006000000050000000400008006000000010000001019008070180080
|
||||
// repeat(12) {
|
||||
// val num = (0..99).random()
|
||||
// val num2 = (0..99).random()
|
||||
// val num3 = (0..99).random()
|
||||
// val num4 = (0..1).random()
|
||||
// val numStr = if (num <= 9) "0${num}" else "" + num
|
||||
// val numStr2 = if (num2 <= 9) "0${num2}" else "" + num2
|
||||
// val numStr3 = if (num3 <= 9) "0${num3}" else "" + num3
|
||||
// val numStr4 = if (num4 == 1) "80" else "00"
|
||||
// append(numStr).append(numStr2).append(numStr3).append(numStr4)
|
||||
// }
|
||||
// }
|
||||
// val data =
|
||||
// "${HEADER}0302000000000C${sb}5037414645333633333334333731373056322E313069${FOOTER}"
|
||||
// receiveSerialPortData(data)
|
||||
// delay(500)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private fun getTokenSuccess(data: RespData<*>) {
|
||||
@@ -223,6 +209,9 @@ class HomeActivity : BaseActivity() {
|
||||
return
|
||||
}
|
||||
deviceName = data.data.deviceName
|
||||
|
||||
updateLeftStatus("$deviceName -°C / -%")
|
||||
|
||||
App.canteenId = data.data.placeId
|
||||
val tempList = data.data.containerGoodsList
|
||||
if (tempList.isNullOrEmpty()) {
|
||||
@@ -264,43 +253,73 @@ class HomeActivity : BaseActivity() {
|
||||
private fun receiveSerialPortData(srcData: String) {
|
||||
log("receiveSerialPortData: $srcData")
|
||||
var data = ""
|
||||
if (srcData.startsWith(HEADER) && srcData.contains(FOOTER)) {
|
||||
if (srcData.contains(HEADER) && srcData.contains(FOOTER)) {
|
||||
serialReader.clear()
|
||||
val endIndex = srcData.indexOf(FOOTER) + FOOTER.length
|
||||
serialReader.append(srcData.substring(0, endIndex))
|
||||
val startIndex = srcData.lastIndexOf(HEADER)
|
||||
var endIndex = srcData.indexOf(FOOTER) + FOOTER.length
|
||||
if (endIndex < startIndex) {
|
||||
//类似这种:31314FFFFFD6DADEDB01010C,FOOTER在HEADER前
|
||||
data = srcData.substring(startIndex)
|
||||
if (data.contains(FOOTER)) {
|
||||
endIndex = srcData.indexOf(FOOTER) + FOOTER.length
|
||||
data = data.substring(0, endIndex)
|
||||
handleReceivedData(data)
|
||||
serialReader.clear()
|
||||
return
|
||||
}
|
||||
serialReader.clear()
|
||||
serialReader.append(data).append(",")
|
||||
return
|
||||
}
|
||||
serialReader.append(srcData.substring(startIndex, endIndex))
|
||||
data = serialReader.toString()
|
||||
} else if (srcData.startsWith(HEADER) && srcData.contains(FOOTER).not()) {
|
||||
handleReceivedData(data)
|
||||
serialReader.clear()
|
||||
return
|
||||
}
|
||||
if (srcData.contains(HEADER) && srcData.contains(FOOTER).not()) {
|
||||
serialReader.clear()
|
||||
val startIndex = srcData.lastIndexOf(HEADER)
|
||||
serialReader.append(srcData.substring(startIndex)).append(",")
|
||||
return
|
||||
}
|
||||
if (srcData.contains(HEADER).not() && srcData.contains(FOOTER).not()) {
|
||||
serialReader.append(srcData).append(",")
|
||||
return
|
||||
} else if (srcData.startsWith(HEADER).not() && srcData.contains(FOOTER).not()) {
|
||||
serialReader.append(srcData).append(",")
|
||||
}
|
||||
//if (srcData.contains(HEADER).not() && srcData.contains(FOOTER))
|
||||
val endIndex = srcData.indexOf(FOOTER) + FOOTER.length
|
||||
serialReader.append(srcData.substring(0, endIndex))
|
||||
log("receiveSerialPortData:serialReader: $serialReader")
|
||||
data = serialReader.toString().replace(",", "")
|
||||
handleReceivedData(data)
|
||||
}
|
||||
|
||||
private fun handleReceivedData(data: String) {
|
||||
if (data.isEmpty()) {
|
||||
return
|
||||
} else {
|
||||
val endIndex = srcData.indexOf(FOOTER) + FOOTER.length
|
||||
serialReader.append(srcData.substring(0, endIndex))
|
||||
log("receiveSerialPortData:serialReader: $serialReader")
|
||||
data = serialReader.toString().replace(",", "")
|
||||
}
|
||||
|
||||
val cmd = data.substring(HEADER.length, HEADER.length + 4)
|
||||
val cmdFlag = cmd.substring(0, 2)
|
||||
when (cmd) {
|
||||
"0001" -> {
|
||||
//终端发起激活指令,拿到固定数据体(终端ID-15字节、固件版本-5字节、命令次数-1字节)
|
||||
val reqBody = data.substring(HEADER.length + cmd.length, data.length - FOOTER.length)
|
||||
val reqBody =
|
||||
data.substring(HEADER.length + cmd.length, data.length - FOOTER.length)
|
||||
if (reqBody.length == 44) {
|
||||
terminalId = reqBody.substring(2, 32)
|
||||
terminalVersion = reqBody.substring(32, 42)
|
||||
log("receiveSerialPortData:收到[激活]${cmd.substring(0,2)}指令:${data},终端id:${terminalId},固件版本:${terminalVersion},发送激活命令:$ACTIVE_CMD")
|
||||
log("${LOG_PREFIX}[激活]${cmdFlag}指令:${data},终端id:${terminalId},固件版本:${terminalVersion},发送激活命令:$ACTIVE_CMD")
|
||||
sendCmd(ACTIVE_CMD)
|
||||
}
|
||||
}
|
||||
|
||||
"0101","8101" -> {
|
||||
"0101", "8101" -> {
|
||||
//心跳0102${p1}${p2}${version}
|
||||
//心跳81(终端发起,当终端发送此命令时需要服务端存储串口屏显示信息)
|
||||
val respCmd = "${HEADER}01020106${terminalVersion}$FOOTER"
|
||||
log("receiveSerialPortData:收到[心跳]${cmd.substring(0,2)}指令:${data},发送应答指令:${respCmd}")
|
||||
val respCmd = "${HEADER}01020906${terminalVersion}$FOOTER"
|
||||
log("${LOG_PREFIX}[心跳]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||
sendCmd(respCmd)
|
||||
heartBeat(data)
|
||||
}
|
||||
@@ -308,27 +327,28 @@ class HomeActivity : BaseActivity() {
|
||||
"0202" -> {
|
||||
//开关锁反馈020200${deviceId}${version}
|
||||
val respCmd = "${HEADER}020200${terminalId}${terminalVersion}$FOOTER"
|
||||
log("receiveSerialPortData:收到[开锁]${cmd.substring(0,2)}指令:${data},发送应答指令:${respCmd}")
|
||||
log("${LOG_PREFIX}[开锁]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||
sendCmd(respCmd)
|
||||
//lockFeedback(data)
|
||||
}
|
||||
|
||||
"0302" -> {
|
||||
//获取设备状态
|
||||
log("${LOG_PREFIX}[获取设备状态]${cmdFlag}指令:${data}")
|
||||
getDeviceInfo(data)
|
||||
}
|
||||
|
||||
"0501" -> {
|
||||
//卡号上发
|
||||
val respCmd = "${HEADER}050203$FOOTER"
|
||||
log("receiveSerialPortData:收到[卡号上发]${cmd.substring(0,2)}指令:${data},发送应答指令:${respCmd}")
|
||||
log("${LOG_PREFIX}[卡号上发]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||
sendCmd(respCmd)
|
||||
}
|
||||
|
||||
"0B01" -> {
|
||||
//操作记录上传
|
||||
val respCmd = "${HEADER}0B0203$FOOTER"
|
||||
log("receiveSerialPortData:收到[操作记录上传]${cmd.substring(0,2)}指令:${data},发送应答指令:${respCmd}")
|
||||
log("${LOG_PREFIX}[操作记录上传]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||
sendCmd(respCmd)
|
||||
}
|
||||
|
||||
@@ -336,36 +356,63 @@ class HomeActivity : BaseActivity() {
|
||||
//对时
|
||||
val timeLong = System.currentTimeMillis() / 1000 + (8 * 3600)
|
||||
val timeStr = "0000000" + String.format("%X", timeLong)
|
||||
val time = timeStr.substring(timeStr.length - 8).chunked(2).reversed().joinToString("")
|
||||
val time =
|
||||
timeStr.substring(timeStr.length - 8).chunked(2).reversed().joinToString("")
|
||||
val respCmd = "${HEADER}0B02${time}$FOOTER"
|
||||
log("receiveSerialPortData:收到[对时]${cmd.substring(0,2)}指令:${data},发送应答指令:${respCmd}")
|
||||
log("${LOG_PREFIX}[对时]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||
sendCmd(respCmd)
|
||||
}
|
||||
|
||||
"0E01" -> {
|
||||
//终端位置上报
|
||||
val respCmd = "${HEADER}0E0200$FOOTER"
|
||||
log("receiveSerialPortData:收到[终端位置上报]${cmd.substring(0,2)}指令:${data},发送应答指令:${respCmd}")
|
||||
log("${LOG_PREFIX}[终端位置上报]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||
sendCmd(respCmd)
|
||||
}
|
||||
|
||||
"1001" -> {
|
||||
//温控信息上报
|
||||
val respCmd = "${HEADER}100200$FOOTER"
|
||||
log("receiveSerialPortData:收到[温控信息上报]${cmd.substring(0,2)}指令:${data},发送应答指令:${respCmd}")
|
||||
val logMsg = "${LOG_PREFIX}[温控信息上报]${cmdFlag}指令:${data},发送应答指令:${respCmd}"
|
||||
log(logMsg)
|
||||
sendCmd(respCmd)
|
||||
val tempC = HexUtils.signedHexToDec(data.substring(0, 4)) * 0.1
|
||||
updateLeftStatus("$deviceName ${"%.1f".format(tempC)}°C / -%")
|
||||
|
||||
//D6DADEDB1001015D020000000027001E00020000001E001C00B40000000000010000000100040000001900440003000F00000000000FFFE6000200010002FFD80044000300010005001E0001FFD80056001400280000000000000000008300090000003C00D2000000000000007F003700000000A100000031323136334238423134303233303456322E313100FFFF
|
||||
runOnUiThread {
|
||||
if (tipDialog == null) {
|
||||
CommonDialog(this).apply {
|
||||
dialogTitle = "温馨提示"
|
||||
// dialogContent = logMsg
|
||||
confirmBlock = {
|
||||
logMsg?.copyTextToClipboard(this@HomeActivity)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tipDialog?.isShowing == false) {
|
||||
tipDialog?.dialogContent = logMsg
|
||||
tipDialog?.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"1002" -> {
|
||||
log("receiveSerialPortData,温控信息应答1002数据:${data}")
|
||||
log("${LOG_PREFIX}[温控信息应答]1002数据:${data}")
|
||||
}
|
||||
|
||||
"0F02" -> {
|
||||
log("receiveSerialPortData,温控信息应答0F02数据:${data}")
|
||||
log("${LOG_PREFIX}[温控信息应答]0F02数据:${data}")
|
||||
//D6DADEDB0F020331323136334238423134303233303456322E31313EFFFF00000055010000000000002707000001000000220100000000000091040000120100000100000095140080611400800000000000000000000000000000000000000000010100005031323136334238423134303233303456322E31313EFFFF
|
||||
runOnUiThread { }
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
private var tipDialog: CommonDialog? = null
|
||||
|
||||
private var fixedDataBody = ""
|
||||
|
||||
// private fun lockFeedback(data: String) {
|
||||
@@ -404,14 +451,14 @@ class HomeActivity : BaseActivity() {
|
||||
)
|
||||
val temperatureStartIndex = 158
|
||||
val temperatureEndIndex = temperatureStartIndex + 2
|
||||
val temperatureHex = data.substring(temperatureStartIndex, temperatureEndIndex)
|
||||
val temperature = hexToDec(temperatureHex)
|
||||
val tempC = f2C(temperature.toDouble())
|
||||
showTemperatureC = "%.1f".format(tempC)
|
||||
// val temperatureHex = data.substring(temperatureStartIndex, temperatureEndIndex)
|
||||
// val temperature = hexToDec(temperatureHex)
|
||||
// val tempC = f2C(temperature.toDouble())
|
||||
// showTemperatureC = "%.1f".format(tempC)
|
||||
|
||||
//val percent = 10 * list.count { it.goodsName.isNullOrBlank().not() }
|
||||
|
||||
updateLeftStatus("${deviceName} [$temperatureHex] ${showTemperatureC}°C / -%")
|
||||
// updateLeftStatus("${deviceName} [$temperatureHex] ${showTemperatureC}°C / -%")
|
||||
|
||||
getFixDataBody(data, temperatureEndIndex)
|
||||
}.onFailure {
|
||||
@@ -477,13 +524,17 @@ class HomeActivity : BaseActivity() {
|
||||
e.printStackTrace()
|
||||
return
|
||||
}
|
||||
val temperature = hexToDec(temperatureHex)
|
||||
val tempC = f2C(temperature.toDouble())
|
||||
showTemperatureC = "%.1f".format(tempC)
|
||||
// val temperature = hexToDec(temperatureHex)
|
||||
// val tempC = f2C(temperature.toDouble())
|
||||
// showTemperatureC = "%.1f".format(tempC)
|
||||
|
||||
//val percent = 10 * list.count { it.goodsName.isNullOrBlank().not() }
|
||||
|
||||
updateLeftStatus("${deviceName} ${showTemperatureC}°C / -%")
|
||||
// updateLeftStatus("${deviceName} ${showTemperatureC}°C / -%")
|
||||
|
||||
|
||||
// val tempC = HexUtils.signedHexToDec(temperatureHex) * 0.1
|
||||
updateLeftStatus("$deviceName -°C / -% $temperatureHex")
|
||||
|
||||
getWeightInfo(
|
||||
start = weightStartIndex,
|
||||
@@ -494,13 +545,13 @@ class HomeActivity : BaseActivity() {
|
||||
getFixDataBody(data, temperatureEndIndex)
|
||||
}
|
||||
|
||||
fun getFixDataBody(data:String, temperatureEndIndex: Int) {
|
||||
fun getFixDataBody(data: String, temperatureEndIndex: Int) {
|
||||
try {
|
||||
if (terminalId.isNotBlank() && terminalVersion.isNotBlank()) {
|
||||
return
|
||||
}
|
||||
val fixDataBodyStartIndex = temperatureEndIndex + 1
|
||||
val fixDataBody = data.substring(fixDataBodyStartIndex, data.length- FOOTER.length)
|
||||
val fixDataBody = data.substring(fixDataBodyStartIndex, data.length - FOOTER.length)
|
||||
if (fixDataBody.length == 42) {
|
||||
terminalId = fixDataBody.substring(0, 30)
|
||||
terminalVersion = fixDataBody.substring(30, 40)
|
||||
|
||||
@@ -7,7 +7,10 @@ import com.shuwei.intelligent.shelves.base.BaseActivity
|
||||
import com.shuwei.intelligent.shelves.databinding.ActivityLogListBinding
|
||||
import com.shuwei.intelligent.shelves.dialog.CommonDialog
|
||||
import com.shuwei.intelligent.shelves.utils.ext.copyTextToClipboard
|
||||
import com.shuwei.intelligent.shelves.utils.ext.gone
|
||||
import com.shuwei.intelligent.shelves.utils.ext.startActivity
|
||||
import com.shuwei.intelligent.shelves.utils.ext.toast
|
||||
import com.shuwei.intelligent.shelves.utils.ext.visible
|
||||
|
||||
class LogActivity : BaseActivity() {
|
||||
|
||||
@@ -69,6 +72,22 @@ class LogActivity : BaseActivity() {
|
||||
it.layoutManager = LinearLayoutManager(this)
|
||||
it.adapter = logAdapter
|
||||
}
|
||||
binding.btnFind.run {
|
||||
if (isLogDir) gone() else visible()
|
||||
}
|
||||
binding.btnFind.setOnClickListener {
|
||||
if (isLogDir) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
val list = logList.filter { it.contains("${HomeActivity.HEADER}1001") }
|
||||
if (list.isEmpty()) {
|
||||
toast("未找到到1001指令")
|
||||
return@setOnClickListener
|
||||
}
|
||||
logList.clear()
|
||||
logList.addAll(list)
|
||||
logAdapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -157,10 +157,13 @@ open class BaseActivity : AppCompatActivity() {
|
||||
switchLight(tag.not())
|
||||
}
|
||||
binding.tvRightStatus.clickWithDebounce {
|
||||
//startActivity<SettingActivity> { }
|
||||
startActivity<LogActivity> {
|
||||
putExtra(LogActivity.IS_LOG_DIR, true)
|
||||
if (this is HomeActivity) {
|
||||
startActivity<LogActivity> {
|
||||
putExtra(LogActivity.IS_LOG_DIR, true)
|
||||
}
|
||||
return@clickWithDebounce
|
||||
}
|
||||
startActivity<SettingActivity> { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.shuwei.intelligent.shelves.utils;
|
||||
|
||||
|
||||
public class HexUtils {
|
||||
|
||||
/**
|
||||
* 将有符号十六进制字符串转换为十进制整数
|
||||
* @param hex 十六进制字符串(支持负数补码表示)
|
||||
* @return 对应的十进制整数
|
||||
*/
|
||||
public static int signedHexToDec(String hex) {
|
||||
// 验证输入格式
|
||||
if (hex == null || hex.isEmpty()) {
|
||||
throw new IllegalArgumentException("输入不能为空");
|
||||
}
|
||||
|
||||
if (!hex.matches("[0-9A-Fa-f]+")) {
|
||||
throw new IllegalArgumentException("无效的十六进制格式: " + hex);
|
||||
}
|
||||
|
||||
// 转换为无符号长整型
|
||||
long unsignedValue = Long.parseLong(hex, 16);
|
||||
|
||||
// 判断是否为负数(最高位为1)
|
||||
int bitLength = hex.length() * 4; // 每个十六进制字符对应4位
|
||||
long signBitMask = 1L << (bitLength - 1);
|
||||
|
||||
if ((unsignedValue & signBitMask) != 0) {
|
||||
// 负数:计算补码
|
||||
long maxValue = (1L << bitLength) - 1;
|
||||
return (int) (unsignedValue - (maxValue + 1));
|
||||
} else {
|
||||
// 正数:直接转换
|
||||
return (int) unsignedValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试方法
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// 测试用例
|
||||
String[] testCases = {
|
||||
"FF", // -1 (8位)
|
||||
"FFFE", // -2 (16位)
|
||||
"FFFFFFFE", // -2 (32位)
|
||||
"7F", // 127
|
||||
"80", // -128
|
||||
"7FFF", // 32767
|
||||
"8000" // -32768
|
||||
};
|
||||
|
||||
System.out.println("有符号十六进制转换测试:");
|
||||
for (String hex : testCases) {
|
||||
try {
|
||||
int result = signedHexToDec(hex);
|
||||
System.out.println(hex + " -> " + result);
|
||||
} catch (Exception e) {
|
||||
System.out.println(hex + " -> 错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+282
@@ -0,0 +1,282 @@
|
||||
package com.shuwei.intelligent.shelves.utils;
|
||||
|
||||
//import cn.hutool.core.util.HexUtil;
|
||||
//import cn.hutool.core.util.StrUtil;
|
||||
//import com.chengyi.framework.utils.HexUtils;
|
||||
//import lombok.Data;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @Author: NThink
|
||||
* @Date: 2021/12/10
|
||||
* @Description: 鸿科HK70温控器信息消息解包
|
||||
*/
|
||||
public class TemperatureInfoHK70MsgBodyUnpack {
|
||||
|
||||
// 柜温探头温度
|
||||
private Double gwttTemp;
|
||||
|
||||
// 蒸发探头温度
|
||||
private Double zfttTemp;
|
||||
|
||||
// 冷凝探头温度
|
||||
private Double lnttTemp;
|
||||
|
||||
// 停机温度
|
||||
private Double tjTemp;
|
||||
|
||||
// 开机温度回差
|
||||
private Double kjTempRange;
|
||||
|
||||
// 压缩机启动延时
|
||||
private Integer ysjStartDelay;
|
||||
|
||||
// 首次通电压缩机启动延时
|
||||
private Integer ysjStartDelayFirst;
|
||||
|
||||
// 柜温探头补偿
|
||||
private Double gwttbcTemp;
|
||||
|
||||
// 停机温度可设置的最小值
|
||||
private Double tjTempMin;
|
||||
|
||||
// 停机温度可设置的最大值
|
||||
private Double tjTempMax;
|
||||
|
||||
// 压缩机最大待机时间
|
||||
private Integer ysjMaxWait;
|
||||
|
||||
// 压缩机最短运行时间
|
||||
private Integer ysjMinWork;
|
||||
|
||||
// 蒸发器探头状态
|
||||
private Integer zfttStatus;
|
||||
|
||||
// 自动除霜周期
|
||||
private Integer zdcszq;
|
||||
|
||||
// 除霜过程显示
|
||||
private Integer csWorkShow;
|
||||
|
||||
// 除霜最长时间
|
||||
private Integer cszcsj;
|
||||
|
||||
// 除霜中止温度
|
||||
private Double cszzTemp;
|
||||
|
||||
// 除霜类型
|
||||
private Integer csType;
|
||||
|
||||
// 风机运行模式
|
||||
private Integer fanWorkType;
|
||||
|
||||
// 风机首次启动延时
|
||||
private Integer fanFirstStartDelay;
|
||||
|
||||
// 滴水后风机启动延时
|
||||
private Integer fanStartDelayAfterDrip;
|
||||
|
||||
// 开关机状态
|
||||
private String powerStatus;
|
||||
|
||||
// 制冷状态
|
||||
private String coolStatus;
|
||||
|
||||
// 除霜状态
|
||||
private String csStatus;
|
||||
|
||||
// 滴水状态
|
||||
private String dsStatus;
|
||||
|
||||
// 柜温探头报警
|
||||
private String gwttAlarm;
|
||||
|
||||
// 除霜探头报警
|
||||
private String csttAlarm;
|
||||
|
||||
// 冷凝探头报警
|
||||
private String lnttAlarm;
|
||||
|
||||
// 终端ID
|
||||
private String imei;
|
||||
|
||||
// 固件版本
|
||||
private String version;
|
||||
|
||||
// 命令次数
|
||||
private Integer cmdCount;
|
||||
|
||||
public TemperatureInfoHK70MsgBodyUnpack(String body) {
|
||||
// ===================== 寄存器内容:110字节 =====================
|
||||
String jcqContent = body.substring(0, 220);
|
||||
// 柜温探头温度 [0, 4]
|
||||
double gwttTemp = Double.parseDouble(String.format("%.1f", HexUtils.signedHexToDec(jcqContent.substring(0, 4)) * 0.1));
|
||||
// setGwttTemp(gwttTemp);
|
||||
// // 蒸发探头温度 [4, 8]
|
||||
// double zfttTemp = Double.parseDouble(String.format("%.1f", HexUtils.signedHexToDec(jcqContent.substring(4, 8)) * 0.1));
|
||||
// setZfttTemp(zfttTemp);
|
||||
// // 冷凝探头温度 [8, 12]
|
||||
// double lnttTemp = Double.parseDouble(String.format("%.1f", HexUtils.signedHexToDec(jcqContent.substring(8, 12)) * 0.1));
|
||||
// setLnttTemp(lnttTemp);
|
||||
// // 停机温度 [12, 16]
|
||||
// double tjTemp = Double.parseDouble(String.format("%.1f", HexUtils.signedHexToDec(jcqContent.substring(12, 16)) * 1.0));
|
||||
// setTjTemp(tjTemp);
|
||||
// // 开机温度回差 [16, 20]
|
||||
// double kjwdhc = Double.parseDouble(String.format("%.1f", HexUtils.signedHexToDec(jcqContent.substring(16, 20)) * 0.1));
|
||||
// setKjTempRange(kjwdhc);
|
||||
// // 压缩机启动延时 [20, 24]
|
||||
// int ysjqdys = Integer.parseInt(jcqContent.substring(20, 24), 16);
|
||||
// setYsjStartDelay(ysjqdys);
|
||||
// // 首次通电压缩机启动延时 [24, 28]
|
||||
// int ysjqdysFirst = Integer.parseInt(jcqContent.substring(24, 28), 16);
|
||||
// setYsjStartDelayFirst(ysjqdysFirst);
|
||||
// // 柜温探头补偿 [28, 32]
|
||||
// double gwttbc = Double.parseDouble(String.format("%.1f", HexUtils.signedHexToDec(jcqContent.substring(28, 32)) * 0.1));
|
||||
// setGwttbcTemp(gwttbc);
|
||||
// // 停机温度可设置的最小值 [32, 36]
|
||||
// double tjTempMin = Double.parseDouble(String.format("%.1f", HexUtils.signedHexToDec(jcqContent.substring(32, 36)) * 1.0));
|
||||
// setTjTempMin(tjTempMin);
|
||||
// // 停机温度可设置的最大值 [36, 40]
|
||||
// double tjTempMax = Double.parseDouble(String.format("%.1f", HexUtils.signedHexToDec(jcqContent.substring(36, 40)) * 1.0));
|
||||
// setTjTempMin(tjTempMax);
|
||||
// // 压缩机最大待机时间 [40, 44]
|
||||
// int ysjzddjsj = Integer.parseInt(jcqContent.substring(40, 44), 16);
|
||||
// setYsjMaxWait(ysjzddjsj);
|
||||
// // 压缩机最短运行时间 [44, 48]
|
||||
// int ysjzdyxsj = Integer.parseInt(jcqContent.substring(44, 48), 16);
|
||||
// setYsjMinWork(ysjzdyxsj);
|
||||
// // 蒸发器探头选择 [48, 52]
|
||||
// int zfqtt = Integer.parseInt(jcqContent.substring(48, 52), 16);
|
||||
// setZfttStatus(zfqtt);
|
||||
// // TODO 蒸发器探头补偿 [52, 56]
|
||||
// // TODO 自动除霜周期计算方式 [56, 60]
|
||||
// // 自动除霜周期 [60, 64]
|
||||
// int zdcszq = Integer.parseInt(jcqContent.substring(60, 64), 16);
|
||||
// setZdcszq(zdcszq);
|
||||
// // 除霜过程显示选择 [64, 68]
|
||||
// int csgcxx = Integer.parseInt(jcqContent.substring(64, 68), 16);
|
||||
// setCsWorkShow(csgcxx);
|
||||
// // 除霜最长时间 [68, 72]
|
||||
// int cszcsj = Integer.parseInt(jcqContent.substring(68, 72), 16);
|
||||
// setCszcsj(cszcsj);
|
||||
// // 除霜终止温度 [72, 76]
|
||||
// double cszzwd = Double.parseDouble(String.format("%.1f", HexUtils.signedHexToDec(jcqContent.substring(72, 76)) * 1.0));
|
||||
// setCszzTemp(cszzwd);
|
||||
// // TODO 除霜滴水时间 [76, 80]
|
||||
// // TODO 除霜后柜温显示延时 [80, 84]
|
||||
// // TODO 除霜启动延迟 [84, 88]
|
||||
// // 除霜类型选择 [88, 92]
|
||||
// int cslx = Integer.parseInt(jcqContent.substring(88, 92), 16);
|
||||
// setCsType(cslx);
|
||||
// // TODO 辅热提前启动时间 [92, 96]
|
||||
// // TODO 强制除霜温度 [96, 100]
|
||||
// // 风机运行模式 [100, 104]
|
||||
// int fjyxms = Integer.parseInt(jcqContent.substring(100, 104), 16);
|
||||
// setFanWorkType(fjyxms);
|
||||
// // 风机首次启动延时 [104, 108]
|
||||
// int fjscqdys = Integer.parseInt(jcqContent.substring(104, 108), 16);
|
||||
// setFanFirstStartDelay(fjscqdys);
|
||||
// // 滴水后风机启动延时 [108, 112]
|
||||
// int dshfjqdys = Integer.parseInt(jcqContent.substring(108, 112), 16);
|
||||
// setFanStartDelayAfterDrip(dshfjqdys);
|
||||
// // TODO 风机工作最低温度 [112, 116]
|
||||
// // TODO 风机工作最高温度 [116, 120]
|
||||
// // TODO 风机循环开启时间 [120, 124]
|
||||
// // TODO 风机循环关闭时间 [124, 128]
|
||||
// // TODO 比例制冷压缩机停止时间 [128, 132]
|
||||
// // TODO 比例制冷压缩机运行时间 [132, 136]
|
||||
// // TODO 蜂鸣音报警 [136, 140]
|
||||
// // TODO 柜温低温报警(绝对温度) [140, 144]
|
||||
// // TODO 柜温高温报警(绝对温度) [144, 148]
|
||||
// // TODO 柜温报警延时 [148, 152]
|
||||
// // TODO 上电首次柜温报警延时 [152, 156]
|
||||
// // TODO 辅助继电器功能选择 [156, 160]
|
||||
// // TODO 门开关控制输出选择 [160, 164]
|
||||
// // TODO 开门时蜂鸣器响应延时 [164, 168]
|
||||
// // TODO 第三探头功能选择 [168, 172]
|
||||
// // TODO 冷凝器高温报警启动值 [172, 176]
|
||||
// // TODO 冷凝器高温报警下回差 [176, 180]
|
||||
// // TODO 冷凝器高温保护启动值 [180, 184]
|
||||
// // TODO 实时时钟功能开关 [不上报]
|
||||
// // TODO 非营业模式开启时间 [不上报]
|
||||
// // TODO 非营业模式关闭时间 [不上报]
|
||||
// // TODO 非营业模式温度增量 [不上报]
|
||||
// // TODO 非营业模式灯光开启时间 [不上报]
|
||||
// // TODO 节假日设置 [不上报]
|
||||
// // TODO 节假日非营业模式开启时间 [不上报]
|
||||
// // TODO 除雾自动控制模式 [184, 188]
|
||||
// // TODO 除雾自动开启时间 [188, 192]
|
||||
// // TODO 除雾自动关闭时间 [192, 196]
|
||||
// // TODO 开关机自动控制模式 [不上报]
|
||||
// // TODO 自动开机时间 [不上报]
|
||||
// // TODO 自动关机时间 [不上报]
|
||||
// // TODO 单位选择 [196, 200]
|
||||
// // TODO 柜温每升高 1℃显示延时 [204, 208]
|
||||
// // TODO 显示分辨率选择 [208, 212]
|
||||
// // TODO 机器地址 [212, 216]
|
||||
// // TODO 管理员密码设定 [216, 220]
|
||||
//
|
||||
// // ===================== 状态位解析:4字节 =====================
|
||||
// // 1.状态信息
|
||||
// String statusHexStr = body.substring(220, 224);
|
||||
// statusHexStr = HexUtils.reverse(statusHexStr);
|
||||
// String statusBitStr = HexUtils.hexString2binaryString(statusHexStr);
|
||||
// statusBitStr = StrUtil.reverse(statusBitStr);
|
||||
// // 机组运行状态 0:停止 1:运行 [0, 1]
|
||||
// String powerStatus = "0".equals(statusBitStr.substring(0, 1)) ? "close" : "open";
|
||||
// setPowerStatus(powerStatus);
|
||||
// // TODO 自检状态 0:停止 1:运行 [1, 2]
|
||||
// // 压缩机运行状态 0:停止 1:运行 [2, 3]
|
||||
// String coolStatus = "0".equals(statusBitStr.substring(3, 4)) ? "close" : "open";
|
||||
// setCoolStatus(coolStatus);
|
||||
// // 除霜状态 0:停止 1:运行 [3, 4]
|
||||
// String csStatus = "0".equals(statusBitStr.substring(10, 11)) ? "close" : "open";
|
||||
// setCsStatus(csStatus);
|
||||
// // 滴水状态 0:关闭 1:运行中 [4, 5]
|
||||
// String dsStatus = "0".equals(statusBitStr.substring(12, 13)) ? "close" : "open";
|
||||
// setDsStatus(dsStatus);
|
||||
// // TODO 风机状态 0:停止 1:运行 [5, 6]
|
||||
// // TODO 除露状态 0:停止 1:运行 [6, 7]
|
||||
// // TODO 灯光状态 0:停止 1:运行 [7, 8]
|
||||
// // TODO 除霜加热或电磁阀状态 0:停止 1:运行 [8, 9]
|
||||
// // TODO 辅助加热状态 0:停止 1:运行 [9, 10]
|
||||
// // TODO 报警状态 0:停止 1:运行 [10, 11]
|
||||
// // TODO 开门状态 0:停止 1:运行 [11, 12]
|
||||
// // TODO 非营业(节能)状态 0:停止 1:运行 [12, 13]
|
||||
// // TODO 节假日状态 0:停止 1:运行 [13, 14]
|
||||
// // TODO 保留 0:停止 1:运行 [14, 15]
|
||||
// // TODO 保留 0:停止 1:运行 [15, 16]
|
||||
//
|
||||
// // 2.报警信息
|
||||
// String alarmHexStr = body.substring(224, 228);
|
||||
// String alarmBitStr = HexUtils.hexString2binaryString(alarmHexStr);
|
||||
// alarmBitStr = StrUtil.reverse(alarmBitStr);
|
||||
// // 柜温探头故障 0:无报警 1:报警
|
||||
// String gwttAlarm = "0".equals(alarmBitStr.substring(0, 1)) ? "normal" : "alarm";
|
||||
// setGwttAlarm(gwttAlarm);
|
||||
// // 除霜探头故障 0:无报警 1:报警
|
||||
// String csAlarm = "0".equals(alarmBitStr.substring(1, 2)) ? "normal" : "alarm";
|
||||
// setCsttAlarm(csAlarm);
|
||||
// // 冷凝探头故障 0:无报警 1:报警
|
||||
// String lnttAlarm = "0".equals(alarmBitStr.substring(2, 3)) ? "normal" : "alarm";
|
||||
// setLnttAlarm(lnttAlarm);
|
||||
// // TODO 柜温高温报警 0:无报警 1:报警
|
||||
// // TODO 柜温低温报警 0:无报警 1:报警
|
||||
// // TODO 冷凝高温报警 0:无报警 1:报警
|
||||
// // TODO 冷凝保护报警 0:无报警 1:报警
|
||||
// // TODO 门打开报警 0:无报警 1:报警
|
||||
// // TODO 时钟故障报警 0:无报警 1:报警
|
||||
//
|
||||
// // 终端ID 15字节
|
||||
// setImei(HexUtil.decodeHexStr(body.substring(228, 258)));
|
||||
// // 固件版本 5字节
|
||||
// setVersion(HexUtil.decodeHexStr(body.substring(258, 268)));
|
||||
// // 命令次数
|
||||
// setCmdCount(Integer.parseInt(body.substring(268, 270), 16));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// String reverse = HexUtils.reverse("8000");
|
||||
// System.out.println(reverse);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,14 @@
|
||||
android:textColor="@color/black"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnFind"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:textSize="18sp"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:text="查找1001指令"/>
|
||||
</FrameLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivEmptyIcon"
|
||||
android:layout_width="270dp"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_empty_gray"
|
||||
android:adjustViewBounds="true"
|
||||
@@ -21,8 +21,8 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/black999"
|
||||
android:layout_marginTop="60dp"
|
||||
android:textSize="60sp"
|
||||
android:layout_marginTop="50dp"
|
||||
android:textSize="50sp"
|
||||
android:text="暂无数据"
|
||||
tools:ignore="HardcodedText" />
|
||||
</LinearLayout>
|
||||
@@ -29,6 +29,14 @@
|
||||
android:textColor="@color/black"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnFind"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:textSize="12sp"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:text="查找1001指令"/>
|
||||
</FrameLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
@@ -48,14 +48,14 @@
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etInputCmdPrefix"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:hint="请输入命令"
|
||||
android:maxLines="1"
|
||||
android:text=""
|
||||
android:textSize="22sp" />
|
||||
<!-- <EditText-->
|
||||
<!-- android:id="@+id/etInputCmdPrefix"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="60dp"-->
|
||||
<!-- android:hint="请输入命令"-->
|
||||
<!-- android:maxLines="1"-->
|
||||
<!-- android:text=""-->
|
||||
<!-- android:textSize="22sp" />-->
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etInputCmd"
|
||||
|
||||
Reference in New Issue
Block a user