【开发记录】HIKSDK/RTSP/Ehome视频平台EasyCVR如何通过GB28181协议增加告警功能?

告警功能作为安防视频云服务搭建中的一个新功能,在越来越多的安防场景中发挥了作用。随着TSINGSEE青犀视频开发的国标GB28181协议视频平台EasyGBS内告警功能的成功运用,我们打算逐步在更多的平台内运用告警功能。

因此在EasyCVR的新版本中我们增加了告警功能的调用接口,目前我们开发的告警功能主要是通过GB28181协议进行接收,因此EasyCVR内告警功能同EasyGBS内告警的开发大致相同。EasyCVR接收国标message中的alarm告警消息,然后通过接口展示。

在message添加如下方法:

case "alarm":

		deviceId := ""
		if el := doc.Root().SelectElement("DeviceID"); el != nil {
			deviceId = el.Text()
		}

		limiter := Limiter.GetLimiter(fmt.Sprintf("%s:%s", serial, deviceId))
		if !limiter.Allow() {
			return
		}

		alarmPriority := ""
		if el := doc.Root().SelectElement("AlarmPriority"); el != nil {
			alarmPriority = el.Text()
		}
		alarmMethod := ""
		if el := doc.Root().SelectElement("AlarmMethod"); el != nil {
			alarmMethod = el.Text()
		}
		alarmType := ""
		if el := doc.Root().SelectElement("Info").SelectElement("AlarmType"); el != nil {
			alarmType = el.Text()
		}
		alarmTime := ""
		if el := doc.Root().SelectElement("AlarmTime"); el != nil {
			alarmTime = el.Text()
		}
		body := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
<Response>
<CmdType>Alarm</CmdType>
<SN>%s</SN>
<DeviceID>%s</DeviceID>
<Result>OK</Result>
</Response>
`, sn, deviceId)
		c.Req.MakeResponse().EnsureToTag().SetHeader("Content-Type", "Application/MANSCDP+xml")
		c.Req.MakeResponse().EnsureToTag().SetBody(body)
		channels := models.GetChannel(deviceId, serial)
		if channels == nil {
			log.Println("alarm find channel is nil")
			return
		}

通过以上接口调用查看,可以得到告警列表,测试后满足要求。

EasyCVR的新版本在近期就会上线,到时候大家可以下载试用,如果还想了解更多关于EasyCVR的相关内容,可以关注我们,另外,TSINGSEE青犀视频还开发了多种不同协议的安防视频云服务平台,包括EasyNVR、EasyGBS、EasyDSS等,都可以下载试用,欢迎咨询。

原文地址:https://www.cnblogs.com/TSINGSEE/p/14179802.html