zhangzengfei
2024-05-21 29dbb82ed5d96ade6baddde05ec8536e298bb595
添加osd设置功能
1个文件已添加
2个文件已修改
87 ■■■■■ 已修改文件
config/config.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/nvcs.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/osd.go 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
config/config.go
@@ -54,6 +54,7 @@
type nvcs struct {
    Model string `mapstructure:"model"` // 型号
    Port  string `mapstructure:"port"`  // 端口
    OSD   string `mapstructure:"osd"`
}
type rateLimitConfig struct {
service/nvcs.go
@@ -36,6 +36,12 @@
    Elevator []Elevator `json:"Elevator"`
}
const (
    RunStop = iota
    RunUp
    RunDown
)
// 对接网络视频字符叠加器,接收udp发送的楼层信息, 更新device地址
func NVCSA1UDPServer() {
    // 指定监听的端口
@@ -87,6 +93,23 @@
            continue
        }
        // 设置osd  格式 "1F停 固 枪"
        if config.NVCSConf.OSD != "" {
            floorText := data.Elevator[0].Status.FloorName
            if data.Elevator[0].Status.RunDir == RunStop {
                floorText = floorText + "停"
            } else if data.Elevator[0].Status.RunDir == RunUp {
                floorText = floorText + "上"
            } else {
                floorText = floorText + "下"
            }
            floorText = floorText + " " + config.NVCSConf.OSD
            // 调用hik api 将文字添加到osd的左下角
            AddFloorToOSD(floorText)
        }
        if data.Elevator[0].Status.RunDir > 0 {
            continue
        }
service/osd.go
New file
@@ -0,0 +1,63 @@
package service
import (
    "encoding/xml"
    "gat1400Exchange/pkg/logger"
    dac "github.com/xinsnake/go-http-digest-auth-client"
    "io/ioutil"
)
// 设置其他字符的第一个, 位置固定位7
// 摄像机信息暂时固定, 避免泄露
const (
    HikISAPIOverlaySetUrl = "/ISAPI/System/Video/inputs/channels/1/overlays/text/7"
    CameraWebAddr         = "http://192.168.10.11:40080"
    CameraWebUser         = "admin"
    CameraWebPassword     = "a1234567"
)
type TextOverlay struct {
    Id               int64  `xml:"id"`
    Enabled          bool   `xml:"enabled"`
    PositionX        int64  `xml:"positionX"`
    PositionY        int64  `xml:"positionY"`
    DisplayText      string `xml:"displayText"`
    DirectAngle      string `xml:"directAngle"`
    IsPersistentText bool   `xml:"isPersistentText"`
}
func AddFloorToOSD(osdText string) {
    overlay7Url := CameraWebAddr + HikISAPIOverlaySetUrl
    rsp, err := ISAPIRequest(CameraWebUser, CameraWebPassword, "GET", overlay7Url, "")
    if err != nil {
        logger.Warn("Get osd info failure")
        return
    }
    var overlayText TextOverlay
    err = xml.Unmarshal(rsp, &overlayText)
    if err != nil {
        logger.Warn("%s", err.Error())
        return
    }
    overlayText.DisplayText = osdText
    body, _ := xml.Marshal(overlayText)
    _, err = ISAPIRequest(CameraWebUser, CameraWebPassword, "PUT", overlay7Url, string(body))
    if err != nil {
        logger.Warn("Camera osd set failure!!")
        return
    }
}
func ISAPIRequest(username, password, method, url, body string) ([]byte, error) {
    dr := dac.NewRequest(username, password, method, url, body)
    resp, err := dr.Execute()
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()
    return ioutil.ReadAll(resp.Body)
}