增加过期逻辑

This commit is contained in:
2025-08-15 17:59:40 +08:00
parent 2162ba0c9e
commit f8453c7d76
16 changed files with 211 additions and 62 deletions
@@ -13,7 +13,6 @@ import androidx.activity.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import com.chad.library.adapter4.util.setOnDebouncedItemClick
@@ -37,7 +36,6 @@ import com.shuwei.intelligent.shelves.utils.ext.visible
import com.shuwei.intelligent.shelves.utils.f2C
import com.shuwei.intelligent.shelves.utils.hexToBinary
import com.shuwei.intelligent.shelves.utils.hexToDec
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
@@ -74,6 +72,10 @@ class HomeActivity : BaseActivity() {
val weightArray = SparseArray<Double?>()
var shelfIndex = 0
// public fun getRealWeight():Double = weightArray[shelfIndex]?:0.0
// 温度
var showTemperatureC = ""
// 湿度
var showHumidity = "0"
}
private lateinit var binding: ActivityHomeBinding
@@ -134,6 +136,9 @@ class HomeActivity : BaseActivity() {
var androidId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
// androidId = "d0e7a2d5f25c775c"
Log.d(TAG, "onCreate: androidId=${androidId}")
if (androidId == "65e1012638f78260" || androidId == "40f89e91ee40611d") {
androidId = "d0e7a2d5f25c775c"
}
App.getInstance().deviceId = androidId
//"53babf69-0d2f-3875-a649-f2e12f80ad4c1"
@@ -258,7 +263,10 @@ class HomeActivity : BaseActivity() {
// Log.d(TAG, "receiveSerialPortData:心跳08: $data")
// heartBeat(data)
// }
"0202" -> {
//开关锁反馈
lockFeedback(data)
}
"0302" -> {
//获取设备状态
getDeviceInfo(data)
@@ -268,6 +276,34 @@ class HomeActivity : BaseActivity() {
}
}
private var fixedDataBody = ""
private fun lockFeedback(data: String) {
runCatching {
val fixedDataBodyEndIndex = data.length - FOOTER.length
val fixedDataBodyStartIndex = HEADER.length + "0202".length + 42
fixedDataBody = data.substring(fixedDataBodyStartIndex, fixedDataBodyEndIndex)
val lockNo = if (list[shelfIndex].deviceNo in 1..5) "01" else "02"
val lockOneState = data.substring(HEADER.length + 4, HEADER.length + 6)
if (lockOneState == "00") {
//锁1关
lifecycleScope.launch {
SerialPortManager.send("${HEADER}0202${lockNo}${FOOTER}")
}
}
val lockTwoState = data.substring(HEADER.length + 6, HEADER.length + 8)
if (lockTwoState == "00") {
//锁2关
lifecycleScope.launch {
SerialPortManager.send("${HEADER}0202${lockNo}${FOOTER}")
}
}
}.onFailure {
it.printStackTrace()
}
}
private fun heartBeat(data: String) {
runCatching {
if (data.length < 200) {
@@ -285,11 +321,11 @@ class HomeActivity : BaseActivity() {
val temperatureHex = data.substring(temperatureStartIndex, temperatureEndIndex)
val temperature = hexToDec(temperatureHex)
val tempC = f2C(temperature.toDouble())
val showTemp = "%.1f".format(tempC)
showTemperatureC = "%.1f".format(tempC)
val percent = 10 * list.count { it.goodsName.isNullOrBlank().not() }
updateLeftStatus("1-1冷藏柜 ${showTemp}°C / ${percent}%")
updateLeftStatus("1-1冷藏柜 ${showTemperatureC}°C / ${percent}%")
}.onFailure {
it.printStackTrace()
}
@@ -349,11 +385,11 @@ class HomeActivity : BaseActivity() {
val temperatureHex = data.substring(temperatureStartIndex, temperatureEndIndex)
val temperature = hexToDec(temperatureHex)
val tempC = f2C(temperature.toDouble())
val showTemp = "%.1f".format(tempC)
showTemperatureC = "%.1f".format(tempC)
val percent = 10 * list.count { it.goodsName.isNullOrBlank().not() }
updateLeftStatus("1-1冷藏柜 ${showTemp}°C / ${percent}%")
updateLeftStatus("1-1冷藏柜 ${showTemperatureC}°C / ${percent}%")
getWeightInfo(
start = weightStartIndex,
@@ -396,7 +432,9 @@ class HomeActivity : BaseActivity() {
goodsId = model.goodsId
goodsName = model.goodsName
weight = model.weight
createTime = model.createTime
if (model.createTime.isNullOrBlank().not()) {
createTime = model.createTime
}
}
notifyItemChanged(position)
}