fix: deviceinfo,catalog xml

This commit is contained in:
pg
2025-02-27 23:50:52 +08:00
committed by pggiroro
parent ae3e76b20b
commit 76e213cbef
3 changed files with 23 additions and 18 deletions
+9 -9
View File
@@ -202,18 +202,18 @@ func (d *Device) send(req *sip.Request) (*sip.Response, error) {
func (d *Device) Go() (err error) {
var response *sip.Response
response, err = d.catalog()
if err != nil {
d.Error("catalog", "err", err)
} else {
d.Debug("catalog", "response", response.String())
}
response, err = d.queryDeviceInfo()
if err != nil {
d.Error("deviceInfo", "err", err)
} else {
d.Debug("deviceInfo", "response", response.String())
}
response, err = d.catalog()
if err != nil {
d.Error("catalog", "err", err)
} else {
d.Debug("catalog", "response", response.String())
}
subTick := time.NewTicker(time.Second * 3600)
defer subTick.Stop()
catalogTick := time.NewTicker(time.Second * 60)
@@ -295,20 +295,20 @@ func (d *Device) catalog() (*sip.Response, error) {
request := d.CreateRequest(sip.MESSAGE, nil)
//d.subscriber.Timeout = time.Now().Add(time.Second * time.Duration(expires))
request.AppendHeader(sip.NewHeader("Expires", "3600"))
request.SetBody(gb28181.BuildCatalogXML(d.SN, d.DeviceID))
request.SetBody(gb28181.BuildCatalogXML(d.Charset, d.SN, d.DeviceID))
return d.send(request)
}
func (d *Device) subscribeCatalog() (*sip.Response, error) {
request := d.CreateRequest(sip.SUBSCRIBE, nil)
request.AppendHeader(sip.NewHeader("Expires", "3600"))
request.SetBody(gb28181.BuildCatalogXML(d.SN, d.DeviceID))
request.SetBody(gb28181.BuildCatalogXML(d.Charset, d.SN, d.DeviceID))
return d.send(request)
}
func (d *Device) queryDeviceInfo() (*sip.Response, error) {
request := d.CreateRequest(sip.MESSAGE, nil)
request.SetBody(gb28181.BuildDeviceInfoXML(d.SN, d.DeviceID))
request.SetBody(gb28181.BuildDeviceInfoXML(d.SN, d.DeviceID, d.Charset))
return d.send(request)
}
+2 -1
View File
@@ -553,7 +553,8 @@ func (gb *GB28181ProPlugin) StoreDevice(deviceid string, req *sip.Request) (d *D
d.Logger = gb.With("deviceid", deviceid)
d.fromHDR.Params.Add("tag", sip.GenerateTagN(16))
d.client, _ = sipgo.NewClient(gb.ua, sipgo.WithClientLogger(zerolog.New(os.Stdout)), sipgo.WithClientHostname(host))
d.client, _ = sipgo.NewClient(gb.ua, sipgo.WithClientLogger(zerolog.New(os.Stdout)), sipgo.WithClientHostname(host), sipgo.WithClientPort(serverPort))
gb.Info("get serverport is ", serverPort)
d.dialogClient = sipgo.NewDialogClient(d.client, d.contactHDR)
d.channels.L = new(sync.RWMutex)
d.Info("StoreDevice", "source", source, "desc", desc, "servIp", servIp, "publicIP", host, "recipient", req.Recipient)
+12 -8
View File
@@ -16,14 +16,16 @@ import (
const (
// CatalogXML 获取设备列表xml样式
CatalogXML = `<?xml version="1.0"?><Query>
CatalogXML = `<?xml version="1.0" encoding="%s"?>
<Query>
<CmdType>Catalog</CmdType>
<SN>%d</SN>
<DeviceID>%s</DeviceID>
</Query>
`
// RecordInfoXML 获取录像文件列表xml样式
RecordInfoXML = `<?xml version="1.0"?><Query>
RecordInfoXML = `<?xml version="1.0"?>
<Query>
<CmdType>RecordInfo</CmdType>
<SN>%d</SN>
<DeviceID>%s</DeviceID>
@@ -34,14 +36,16 @@ const (
</Query>
`
// DeviceInfoXML 查询设备详情xml样式
DeviceInfoXML = `<?xml version="1.0"?><Query>
DeviceInfoXML = `<?xml version="1.0" encoding="%s"?>
<Query>
<CmdType>DeviceInfo</CmdType>
<SN>%d</SN>
<DeviceID>%s</DeviceID>
</Query>
`
// DevicePositionXML 订阅设备位置
DevicePositionXML = `<?xml version="1.0"?><Query>
DevicePositionXML = `<?xml version="1.0"?>
<Query>
<CmdType>MobilePosition</CmdType>
<SN>%d</SN>
<DeviceID>%s</DeviceID>
@@ -82,13 +86,13 @@ func toGB2312(s string) []byte {
}
// BuildDeviceInfoXML 获取设备详情指令
func BuildDeviceInfoXML(sn int, id string) []byte {
return toGB2312(fmt.Sprintf(DeviceInfoXML, sn, id))
func BuildDeviceInfoXML(sn int, id string, charset string) []byte {
return toGB2312(fmt.Sprintf(DeviceInfoXML, charset, sn, id))
}
// BuildCatalogXML 获取NVR下设备列表指令
func BuildCatalogXML(sn int, id string) []byte {
return toGB2312(fmt.Sprintf(CatalogXML, sn, id))
func BuildCatalogXML(charset string, sn int, id string) []byte {
return toGB2312(fmt.Sprintf(CatalogXML, charset, sn, id))
}
// BuildRecordInfoXML 获取录像文件列表指令