From 26b47daac29eb203a5f4eb2701d63b8e14d58b78 Mon Sep 17 00:00:00 2001 From: BBIT-Kai <2911862937@qq.com> Date: Wed, 15 Jul 2026 14:20:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E2=80=9DHR-DGWS-485=E2=80=9C?= =?UTF-8?q?=E5=9E=8B=E6=B8=A9=E6=B9=BF=E5=BA=A6=E4=BC=A0=E6=84=9F=E5=99=A8?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E4=BF=AE=E6=94=B9=E6=B8=A9=E6=B9=BF?= =?UTF-8?q?=E5=BA=A6=E3=80=81=E6=9B=B4=E6=94=B9=E4=BC=A0=E6=84=9F=E5=99=A8?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +-- .../iot_controlhost/model/sensor/THSensor.kt | 27 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e69b6a0..797dc46 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.example.iot_controlhost" minSdkVersion 25 targetSdkVersion 30 - versionCode 159 - versionName "3.5.0.159" + versionCode 160 + versionName "3.5.0.160" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" ndk { moduleName "mcu" diff --git a/app/src/main/java/com/example/iot_controlhost/model/sensor/THSensor.kt b/app/src/main/java/com/example/iot_controlhost/model/sensor/THSensor.kt index 0f95a27..5b95d1e 100644 --- a/app/src/main/java/com/example/iot_controlhost/model/sensor/THSensor.kt +++ b/app/src/main/java/com/example/iot_controlhost/model/sensor/THSensor.kt @@ -1,6 +1,8 @@ package com.example.iot_controlhost.model.sensor import com.blankj.utilcode.util.StringUtils +import com.example.iot_controlhost.model.Device.getCRC +import com.example.iot_controlhost.model.sensor.Sensor.serialPortUtil import com.example.iot_controlhost.utils.DataUtils @@ -25,7 +27,7 @@ class THSensor(name: String?) : Sensor(name) { //获得指令 var str = address + "0300000002" val crc = getCRC(str) - str = str + crc + str += crc //利用指令获得数据 val data = serialPortUtil.sendAndReceiveSerialData( this, str @@ -41,8 +43,14 @@ class THSensor(name: String?) : Sensor(name) { initData() } if (DataUtils.CRC16Check(wsd)) { - wd = WDTransform(wsd[3] + wsd[4]) - sd = WDTransform(wsd[5] + wsd[6]) + if (model == models[0]) { + wd = WDTransform(wsd[3] + wsd[4]) + sd = WDTransform(wsd[5] + wsd[6]) + } else if (model == models[1]) { + // HR-DGWS-485 与 TH10S-B 命令基本一致,只是温湿度解析位置不同 + wd = WDTransform(wsd[5] + wsd[6]) + sd = WDTransform(wsd[3] + wsd[4]) + } } if (wd > 100 || sd > 100) { initData() @@ -60,7 +68,7 @@ class THSensor(name: String?) : Sensor(name) { } override fun getModels(): Array { - return arrayOf("TH10S-B") + return arrayOf("TH10S-B", "HR-DGWS-485") } override fun toString(): String { @@ -81,8 +89,15 @@ class THSensor(name: String?) : Sensor(name) { newAddress: String ): Boolean { //修改地址指令 - var editAddress = oldAddress + "06006400" + newAddress - editAddress = editAddress + getCRC(editAddress) + var editAddress = if (model == models[0]) { + oldAddress + "06006400" + newAddress + } else if (model == models[1]) { + oldAddress + "06010000" + newAddress + } else { + // 不会出现这种 + oldAddress + } + editAddress += getCRC(editAddress) return editAddress == serialPortUtil.sendAndReceiveSerialData( this, editAddress )