isapi_smart_fieldDetection.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package isapi
  2. import (
  3. "encoding/json"
  4. "encoding/xml"
  5. "fmt"
  6. "github.com/sirupsen/logrus"
  7. )
  8. //能力
  9. //http://192.168.110.165/ISAPI/Smart/FieldDetection/1/capabilities
  10. //http://192.168.110.165/ISAPI/Smart/channels/1/calibrations/capabilities
  11. // FieldDetection 区域入侵
  12. type FieldDetectionCap struct {
  13. XMLName xml.Name `xml:"FieldDetection"json:"FieldDetection"`
  14. Xmlns string `xml:"xmlns,attr"json:"xmlns"`
  15. Version string `xml:"version,attr"json:"version"`
  16. ID string `xml:"id"json:"id"`
  17. Enabled string `xml:"enabled"json:"enabled"`
  18. StartTriggerTime string `xml:"startTriggerTime"json:"startTriggerTime"`
  19. EndTriggerTime string `xml:"endTriggerTime"json:"endTriggerTime"`
  20. NormalizedScreenSize struct {
  21. NormalizedScreenWidth string `xml:"normalizedScreenWidth"json:"normalizedScreenWidth"`
  22. NormalizedScreenHeight string `xml:"normalizedScreenHeight"json:"normalizedScreenHeight"`
  23. } `xml:"normalizedScreenSize"json:"normalizedScreenSize"`
  24. FieldDetectionRegionList struct {
  25. Size string `xml:"size,attr"json:"size"`
  26. FieldDetectionRegion []struct {
  27. ID string `xml:"id"json:"id"`
  28. Enabled string `xml:"enabled"json:"enabled"`
  29. SensitivityLevel string `xml:"sensitivityLevel"json:"sensitivityLevel"`
  30. TimeThreshold string `xml:"timeThreshold"json:"timeThreshold"`
  31. DetectionTarget string `xml:"detectionTarget"json:"detectionTarget"`
  32. AlarmConfidence struct {
  33. Opt string `xml:"opt,attr"json:"opt"`
  34. } `xml:"alarmConfidence"json:"alarmConfidence"`
  35. RegionCoordinatesList struct {
  36. RegionCoordinates []struct {
  37. PositionX string `xml:"positionX"json:"positionX"`
  38. PositionY string `xml:"positionY"json:"positionY"`
  39. } `xml:"RegionCoordinates"json:"RegionCoordinates"`
  40. } `xml:"RegionCoordinatesList"json:"RegionCoordinatesList"`
  41. } `xml:"FieldDetectionRegion"json:"FieldDetectionRegion"`
  42. } `xml:"FieldDetectionRegionList"json:"FieldDetectionRegionList"`
  43. IsSupportMultiScene string `xml:"isSupportMultiScene"json:"isSupportMultiScene"`
  44. IsSupportHumanMisinfoFilter string `xml:"isSupportHumanMisinfoFilter"json:"isSupportHumanMisinfoFilter"`
  45. IsSupportVehicleMisinfoFilter string `xml:"isSupportVehicleMisinfoFilter"json:"isSupportVehicleMisinfoFilter"`
  46. }
  47. func (c *Client) GetFieldDetectionCap() (resp FieldDetectionCap, err error) {
  48. bytes, err := c.CommonGet("/ISAPI/Smart/FieldDetection/1/capabilities")
  49. if err != nil {
  50. logrus.Error("请求出错", err)
  51. return
  52. }
  53. err = xml.Unmarshal(bytes, &resp)
  54. return
  55. }
  56. func (c *Client) GetSizeFd() (resp SmartCalibrationList, err error) {
  57. bytes, err := c.CommonGet("/ISAPI/Smart/channels/1/calibrations/FieldDetection")
  58. if err != nil {
  59. logrus.Error("请求出错", err)
  60. return
  61. }
  62. err = xml.Unmarshal(bytes, &resp)
  63. fmt.Printf("%+v\n", string(bytes))
  64. fmt.Printf("%+v\n", resp)
  65. return
  66. }
  67. func (c *Client) PutSizeFd(data []byte) (resp ResponseStatus, err error) {
  68. var info SmartCalibrationList
  69. err = json.Unmarshal(data, &info)
  70. if err != nil {
  71. logrus.Error(err)
  72. return ResponseStatus{}, err
  73. }
  74. marshal, err := xml.Marshal(info)
  75. if err != nil {
  76. logrus.Error(err)
  77. return ResponseStatus{}, err
  78. }
  79. respData, err := c.CommonPut(marshal, "/ISAPI/Smart/channels/1/calibrations/FieldDetection")
  80. if err != nil {
  81. logrus.Error(err)
  82. return ResponseStatus{}, err
  83. }
  84. err = xml.Unmarshal(respData, &resp)
  85. if err != nil {
  86. logrus.Error(err)
  87. return ResponseStatus{}, err
  88. }
  89. return
  90. }
  91. // PutFieldDetection 设置区域入侵报警区域
  92. func (c *Client) PutFieldDetection(data []byte) (resp ResponseStatus, err error) {
  93. var info FieldDetectionParam
  94. err = json.Unmarshal(data, &info)
  95. if err != nil {
  96. logrus.Error(err)
  97. return ResponseStatus{}, err
  98. }
  99. marshal, err := xml.Marshal(info)
  100. if err != nil {
  101. logrus.Error(err)
  102. return ResponseStatus{}, err
  103. }
  104. respData, err := c.CommonPut(marshal, "/ISAPI/Smart/FieldDetection/1")
  105. if err != nil {
  106. logrus.Error(err)
  107. return ResponseStatus{}, err
  108. }
  109. err = xml.Unmarshal(respData, &resp)
  110. if err != nil {
  111. logrus.Error(err)
  112. return ResponseStatus{}, err
  113. }
  114. return
  115. }
  116. // GetFieldDetection 获取报警区域
  117. func (c *Client) GetFieldDetection() (resp FieldDetectionParam, err error) {
  118. bytes, err := c.CommonGet("/ISAPI/Smart/FieldDetection/1")
  119. if err != nil {
  120. logrus.Error("请求出错", err)
  121. return
  122. }
  123. err = xml.Unmarshal(bytes, &resp)
  124. return
  125. }
  126. // FieldDetectionParam 查询,配置 进入区域参数
  127. type FieldDetectionParam struct {
  128. ID string `xml:"id" json:"id"`
  129. Enabled string `xml:"enabled" json:"enabled"`
  130. NormalizedScreenSize struct {
  131. NormalizedScreenWidth string `xml:"normalizedScreenWidth" json:"normalizedScreenWidth"`
  132. NormalizedScreenHeight string `xml:"normalizedScreenHeight" json:"normalizedScreenHeight"`
  133. } `xml:"normalizedScreenSize" json:"normalizedScreenSize"`
  134. FieldDetectionRegionList struct {
  135. Size string `xml:"size,attr" json:"size"`
  136. FieldDetectionRegion []struct {
  137. ID string `xml:"id" json:"id"`
  138. Enabled string `xml:"enabled" json:"enabled"`
  139. SensitivityLevel string `xml:"sensitivityLevel" json:"sensitivityLevel"`
  140. TimeThreshold string `xml:"timeThreshold" json:"timeThreshold"`
  141. DetectionTarget string `xml:"detectionTarget" json:"detectionTarget"`
  142. AlarmConfidence string `xml:"alarmConfidence"json:"alarmConfidence"`
  143. RegionCoordinatesList struct {
  144. RegionCoordinates []struct {
  145. PositionX string `xml:"positionX" json:"positionX"`
  146. PositionY string `xml:"positionY" json:"positionY"`
  147. } `xml:"RegionCoordinates" json:"RegionCoordinates"`
  148. } `xml:"RegionCoordinatesList" json:"RegionCoordinatesList"`
  149. } `xml:"FieldDetectionRegion" json:"FieldDetectionRegion"`
  150. } `xml:"FieldDetectionRegionList" json:"FieldDetectionRegionList"`
  151. IsSupportMultiScene string `xml:"isSupportMultiScene" json:"isSupportMultiScene"`
  152. IsSupportHumanMisinfoFilter string `xml:"isSupportHumanMisinfoFilter" json:"isSupportHumanMisinfoFilter"`
  153. IsSupportVehicleMisinfoFilter string `xml:"isSupportVehicleMisinfoFilter" json:"isSupportVehicleMisinfoFilter"`
  154. }