Merge pull request #15 from duiniuluantanqin/main

Add DefaultHeartbeatCount to device configuration
This commit is contained in:
Haibo Chen(陈海博)
2025-03-13 09:36:08 +08:00
committed by GitHub

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 {