Add DefaultHeartbeatCount to device configuration

This commit is contained in:
haibo.chen
2025-03-13 09:35:12 +08:00
parent c5a526e3b7
commit 15561111a6

View File

@ -23,6 +23,7 @@ type DeviceInfo struct {
const (
DefaultHeartbeatInterval = 60 * time.Second // 心跳检查间隔时间
DefaultHeartbeatCount = 3 // 心跳检查次数
)
type deviceManager struct {
@ -76,6 +77,9 @@ func (dm *deviceManager) checkHeartbeats() {
if device.HeartBeatInterval == 0 {
device.HeartBeatInterval = int(DefaultHeartbeatInterval)
}
if device.HeartBeatCount == 0 {
device.HeartBeatCount = DefaultHeartbeatCount
}
// 如果最后心跳时间超过超时时间,则将设备所有通道状态设置为离线
if now.Sub(device.lastHeartbeat) > time.Duration(device.HeartBeatInterval*device.HeartBeatCount)*time.Second {