Merge pull request #15 from duiniuluantanqin/main
Add DefaultHeartbeatCount to device configuration
This commit is contained in:
@ -23,6 +23,7 @@ type DeviceInfo struct {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultHeartbeatInterval = 60 * time.Second // 心跳检查间隔时间
|
DefaultHeartbeatInterval = 60 * time.Second // 心跳检查间隔时间
|
||||||
|
DefaultHeartbeatCount = 3 // 心跳检查次数
|
||||||
)
|
)
|
||||||
|
|
||||||
type deviceManager struct {
|
type deviceManager struct {
|
||||||
@ -76,6 +77,9 @@ func (dm *deviceManager) checkHeartbeats() {
|
|||||||
if device.HeartBeatInterval == 0 {
|
if device.HeartBeatInterval == 0 {
|
||||||
device.HeartBeatInterval = int(DefaultHeartbeatInterval)
|
device.HeartBeatInterval = int(DefaultHeartbeatInterval)
|
||||||
}
|
}
|
||||||
|
if device.HeartBeatCount == 0 {
|
||||||
|
device.HeartBeatCount = DefaultHeartbeatCount
|
||||||
|
}
|
||||||
|
|
||||||
// 如果最后心跳时间超过超时时间,则将设备所有通道状态设置为离线
|
// 如果最后心跳时间超过超时时间,则将设备所有通道状态设置为离线
|
||||||
if now.Sub(device.lastHeartbeat) > time.Duration(device.HeartBeatInterval*device.HeartBeatCount)*time.Second {
|
if now.Sub(device.lastHeartbeat) > time.Duration(device.HeartBeatInterval*device.HeartBeatCount)*time.Second {
|
||||||
|
|||||||
Reference in New Issue
Block a user