isapi_smart_fieldDetection.go 6.6 KB

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