Hikvision.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package gitea.com/kunmeng/HikNetSDKPkg
  2. import (
  3. "fmt"
  4. "github.com/ebitengine/purego"
  5. "runtime"
  6. "unsafe"
  7. )
  8. var libc uintptr
  9. var (
  10. DVR_Init func() bool
  11. newHIKBallCamera func() unsafe.Pointer
  12. initBallCamera func(core unsafe.Pointer, ip string, port string, username string, password string, BallMachineType string) bool
  13. ptzTo func(core unsafe.Pointer, Action int, P float32, T float32, Z float32) bool
  14. ptzGet func(unsafe.Pointer, unsafe.Pointer, unsafe.Pointer, unsafe.Pointer) bool
  15. stopBus func(unsafe.Pointer, int) bool
  16. startBus func(unsafe.Pointer, int, int) bool
  17. newHIKNvr func() unsafe.Pointer
  18. initNvr func(unsafe.Pointer, string, string, string, string, int) bool
  19. checkTimeRegionWithMonth func(core unsafe.Pointer, year int, month int) string
  20. checkTimeRegionWithDay func(core unsafe.Pointer, year int, month int, day int) string
  21. )
  22. func init() {
  23. var err error
  24. libc, err = openLibrary(getSystemLibrary())
  25. if err != nil {
  26. panic(err)
  27. }
  28. purego.RegisterLibFunc(&DVR_Init, libc, "DVR_Init")
  29. purego.RegisterLibFunc(&newHIKBallCamera, libc, "NewHIKBallCamera")
  30. purego.RegisterLibFunc(&initBallCamera, libc, "InitBallCamera")
  31. purego.RegisterLibFunc(&ptzTo, libc, "PtzGotoPut")
  32. purego.RegisterLibFunc(&ptzGet, libc, "PtzGet")
  33. purego.RegisterLibFunc(&stopBus, libc, "StopBus")
  34. purego.RegisterLibFunc(&startBus, libc, "StartBus")
  35. purego.RegisterLibFunc(&newHIKNvr, libc, "NewHIKNvr")
  36. purego.RegisterLibFunc(&initNvr, libc, "InitNvr")
  37. purego.RegisterLibFunc(&checkTimeRegionWithMonth, libc, "CheckTimeRegionWithMonth")
  38. purego.RegisterLibFunc(&checkTimeRegionWithDay, libc, "CheckTimeRegionWithDay")
  39. }
  40. func getSystemLibrary() string {
  41. switch runtime.GOOS {
  42. case "linux":
  43. return "libc.so.6"
  44. case "windows":
  45. return "Hikvision_Network_SDK_Packaging_Library.dll"
  46. default:
  47. panic(fmt.Errorf("GOOS=%s is not supported", runtime.GOOS))
  48. }
  49. }
  50. type HIKBallCamera struct {
  51. core unsafe.Pointer
  52. }
  53. func NewHIKBallCamera() *HIKBallCamera {
  54. return &HIKBallCamera{
  55. core: newHIKBallCamera(),
  56. }
  57. }
  58. func (h *HIKBallCamera) Login(ip string, port string, username string, password string, BallMachineType string) bool {
  59. return initBallCamera(h.core, ip, port, username, password, BallMachineType)
  60. }
  61. func (h *HIKBallCamera) PtzTo(Action int, P, T, Z float32) bool {
  62. return ptzTo(h.core, Action, P, T, Z)
  63. }
  64. func (h *HIKBallCamera) PTZGet(P, T, Z *float32) bool {
  65. return ptzGet(h.core, unsafe.Pointer(P), unsafe.Pointer(T), unsafe.Pointer(Z))
  66. }
  67. func (h *HIKBallCamera) StopBus(Direction int) bool {
  68. return stopBus(h.core, Direction)
  69. }
  70. func (h *HIKBallCamera) StartBus(Direction, Speed int) bool {
  71. return startBus(h.core, Direction, Speed)
  72. }
  73. type HIKNvr struct {
  74. core unsafe.Pointer
  75. }
  76. func NewHIKNvr() *HIKNvr {
  77. return &HIKNvr{
  78. core: newHIKNvr(),
  79. }
  80. }
  81. func (h *HIKNvr) Login(ip string, port string, username string, password string, nvrType int) bool {
  82. return initNvr(h.core, ip, port, username, password, nvrType)
  83. }
  84. func (h *HIKNvr) CheckTimeRegionWithMonth(year int, month int) string {
  85. return checkTimeRegionWithMonth(h.core, year, month)
  86. }
  87. func (h *HIKNvr) CheckTimeRegionWithDay(year int, month int, day int) string {
  88. return checkTimeRegionWithDay(h.core, year, month, day)
  89. }