manscdp.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package gb28181
  2. import (
  3. "fmt"
  4. "strconv"
  5. "time"
  6. )
  7. var (
  8. // CatalogXML 获取设备列表xml样式
  9. CatalogXML = `<?xml version="1.0"?><Query>
  10. <CmdType>Catalog</CmdType>
  11. <SN>%d</SN>
  12. <DeviceID>%s</DeviceID>
  13. </Query>
  14. `
  15. // RecordInfoXML 获取录像文件列表xml样式
  16. RecordInfoXML = `<?xml version="1.0"?>
  17. <Query>
  18. <CmdType>RecordInfo</CmdType>
  19. <SN>%d</SN>
  20. <DeviceID>%s</DeviceID>
  21. <StartTime>%s</StartTime>
  22. <EndTime>%s</EndTime>
  23. <Secrecy>0</Secrecy>
  24. <Type>all</Type>
  25. </Query>
  26. `
  27. // DeviceInfoXML 查询设备详情xml样式
  28. DeviceInfoXML = `<?xml version="1.0"?>
  29. <Query>
  30. <CmdType>DeviceInfo</CmdType>
  31. <SN>%d</SN>
  32. <DeviceID>%s</DeviceID>
  33. </Query>
  34. `
  35. // DevicePositionXML 订阅设备位置
  36. DevicePositionXML = `<?xml version="1.0"?>
  37. <Query>
  38. <CmdType>MobilePosition</CmdType>
  39. <SN>%d</SN>
  40. <DeviceID>%s</DeviceID>
  41. <Interval>%d</Interval>
  42. </Query>`
  43. )
  44. func intTotime(t int64) time.Time {
  45. tstr := strconv.FormatInt(t, 10)
  46. if len(tstr) == 10 {
  47. return time.Unix(t, 0)
  48. }
  49. if len(tstr) == 13 {
  50. return time.UnixMilli(t)
  51. }
  52. return time.Now()
  53. }
  54. // BuildDeviceInfoXML 获取设备详情指令
  55. func BuildDeviceInfoXML(sn int, id string) string {
  56. return fmt.Sprintf(DeviceInfoXML, sn, id)
  57. }
  58. // BuildCatalogXML 获取NVR下设备列表指令
  59. func BuildCatalogXML(sn int, id string) string {
  60. return fmt.Sprintf(CatalogXML, sn, id)
  61. }
  62. // BuildRecordInfoXML 获取录像文件列表指令
  63. func BuildRecordInfoXML(sn int, id string, start, end int64) string {
  64. return fmt.Sprintf(RecordInfoXML, sn, id, intTotime(start).Format("2006-01-02T15:04:05"), intTotime(end).Format("2006-01-02T15:04:05"))
  65. }
  66. // BuildDevicePositionXML 订阅设备位置
  67. func BuildDevicePositionXML(sn int, id string, interval int) string {
  68. return fmt.Sprintf(DevicePositionXML, sn, id, interval)
  69. }
  70. // AlarmResponseXML alarm response xml样式
  71. var (
  72. AlarmResponseXML = `<?xml version="1.0"?>
  73. <Response>
  74. <CmdType>Alarm</CmdType>
  75. <SN>17430</SN>
  76. <DeviceID>%s</DeviceID>
  77. </Response>
  78. `
  79. )
  80. // BuildRecordInfoXML 获取录像文件列表指令
  81. func BuildAlarmResponseXML(id string) string {
  82. return fmt.Sprintf(AlarmResponseXML, id)
  83. }