isapi_smart_fieldDetection.go 6.8 KB

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