refactor: 删除未使用的代码文件

- 移除 Core 目录下的 CallBack.go、core.go 和 Type.go 文件
- 这些文件包含了未使用的类型定义和函数实现
- 删除冗余代码有助于简化项目结构,提高代码可读性和维护性
This commit is contained in:
kunmeng
2025-05-30 14:15:24 +08:00
parent b4c50572d8
commit c8cb43e9b3
123 changed files with 161431 additions and 53914 deletions

150
Nvr.go
View File

@@ -1,25 +1,36 @@
package HikSDK
/*
#cgo LDFLAGS: -Wl,--allow-multiple-definition
#include <stdio.h>
#include <string.h>
*/
import "C"
import (
"errors"
"gitea.com/kunmeng/HikNetSDKPkg/Core"
"time"
"unsafe"
)
type Nvr struct {
userId Core.LONG
deviceInfo Core.NET_DVR_DEVICEINFO_V30
userId LONG
deviceInfo NET_DVR_DEVICEINFO
}
type TimeRange struct {
StartYear DWORD
StartMonth DWORD
StartDay DWORD
StartHour DWORD
StartMinute DWORD
StartSecond DWORD
EndYear DWORD
EndMonth DWORD
EndDay DWORD
EndHour DWORD
EndMinute DWORD
EndSecond DWORD
}
type WebTimeRang struct {
StartTime time.Time
EndTime time.Time
}
func NewNvr(Ip string, Port int, Username, Password string) (*Nvr, error) {
userId, deviceInfo, err := Core.Login(Ip, Port, Username, Password)
userId, deviceInfo, err := login(Ip, Port, Username, Password)
if err != nil {
return nil, err
}
@@ -33,92 +44,30 @@ func (this *Nvr) GetTimeZone() (int, error) {
if this == nil {
return 0, errors.New("Nvr is nil")
}
var data Core.NET_DVR_NETAPPCFG
var dataPtr = unsafe.Pointer(data.GetCPtr())
err := Core.GetDVRConfig(this.userId, 222, 0, dataPtr, Core.DWORD(unsafe.Sizeof(data.GetC())))
if err != nil {
return 0, err
}
data.Go()
return int(data.StruNtpClientParam.CTimeDifferenceH)*60 + int(data.StruNtpClientParam.CTimeDifferenceM)*map[int8]int{-1: -1, 0: 1}[data.StruNtpClientParam.CTimeDifferenceH>>7], nil
return getTimeZone(this.userId), nil
}
func (this *Nvr) CheckTimeRegionWithMonth(Year, Month, Channel uint16) ([]uint8, error) {
if this == nil {
return nil, errors.New("Nvr is nil")
}
// //// 查当月
var struSearchParam Core.NET_DVR_MRD_SEARCH_PARAM
struSearchParam.DwSize = Core.DWORD(unsafe.Sizeof(struSearchParam.GetC()))
struSearchParam.WYear = Core.WORD(Year)
struSearchParam.ByMonth = Core.BYTE(Month)
struSearchParam.StruStreamInfo.DwChannel = Core.DWORD(32 + Channel)
struSearchParam.ByLocalOrUTC = 1
struSearchParam.ByDrawFrame = 0
struSearchParam.ByStreamType = 0
var dataPtr = unsafe.Pointer(struSearchParam.GetCPtr())
var ResData Core.NET_DVR_MRD_SEARCH_RESULT
var ResDataPtr = unsafe.Pointer(ResData.GetCPtr())
err := Core.GetDVRDeviceConfig(this.userId, 6164, 0, dataPtr, Core.DWORD(unsafe.Sizeof(struSearchParam.GetC())), nil, ResDataPtr, Core.DWORD(unsafe.Sizeof(ResData.GetC())))
if err != nil {
return nil, err
}
ResData.Go()
var res []uint8
for i := 0; i < 32; i++ {
if ResData.ByRecordDistribution[i] != 0 {
res = append(res, uint8(i+1))
}
}
return res, nil
return QueryMonth(this.userId, WORD(Year), BYTE(Month), DWORD(Channel))
}
func (this *Nvr) CheckTimeRegionWithDay(Year, Month, Day, Channel uint16) ([]TimeRange, error) {
func (this *Nvr) CheckTimeRegionWithDay(Year, Month, Day, Channel uint16) ([]WebTimeRang, error) {
if this == nil {
return nil, errors.New("Nvr is nil")
}
var Data Core.NET_DVR_FILECOND
Data.DwFileType = 0xff
Data.DwIsLocked = 0xff
Data.DwUseCardNo = 0
Data.LChannel = Core.LONG(32 + Channel)
StartTime := Core.NET_DVR_TIME{
DwYear: Core.DWORD(Year),
DwMonth: Core.DWORD(Month),
DwDay: Core.DWORD(Day),
DwHour: 0,
DwMinute: 0,
DwSecond: 0,
}
StopTime := Core.NET_DVR_TIME{
DwYear: Core.DWORD(Year),
DwMonth: Core.DWORD(Month),
DwDay: Core.DWORD(Day),
DwHour: 23,
DwMinute: 59,
DwSecond: 59,
}
Data.StruStartTime = StartTime
Data.StruStopTime = StopTime
QueryHandle, err := Core.NET_DVR_FindFile_V30(this.userId, Data)
Handle := QueryDayHandle(this.userId, DWORD(Year), DWORD(Month), DWORD(Day), LONG(Channel))
res, state, err := QueryDayNextFile(Handle)
if err != nil {
return nil, err
}
var FindData Core.NET_DVR_FINDDATA_V30
var state Core.LONG
state, err = Core.NET_DVR_FindNextFile_V30(QueryHandle, &FindData)
if err != nil {
return nil, err
return []WebTimeRang{}, err
}
ByUTCDiff, err := this.GetTimeZone()
if err != nil {
return nil, err
}
var res []TimeRange
var webres []WebTimeRang
for state > 0 {
var StartTimeObj time.Time
var EndTimeObj time.Time
@@ -133,59 +82,52 @@ func (this *Nvr) CheckTimeRegionWithDay(Year, Month, Day, Channel uint16) ([]Tim
break
}
if state == 1000 {
if uint16(FindData.StruStartTime.DwDay) != Day {
StartTimeObj = time.Date(int(FindData.StruStartTime.DwYear), time.Month(FindData.StruStartTime.DwMonth), int(FindData.StruStartTime.DwDay+1), 0, 0, 0, 0, time.UTC)
if uint16(res.StartDay) != Day {
StartTimeObj = time.Date(int(res.StartYear), time.Month(res.StartMonth), int(res.StartDay+1), 0, 0, 0, 0, time.UTC)
} else {
StartTimeObj = time.Date(int(FindData.StruStartTime.DwYear), time.Month(FindData.StruStartTime.DwMonth), int(FindData.StruStartTime.DwDay), int(FindData.StruStartTime.DwHour), int(FindData.StruStartTime.DwMinute), int(FindData.StruStartTime.DwSecond), 0, time.UTC)
StartTimeObj = time.Date(int(res.StartYear), time.Month(res.StartMonth), int(res.StartDay), int(res.StartHour), int(res.StartMinute), int(res.StartSecond), 0, time.UTC)
}
if uint16(FindData.StruStopTime.DwDay) != Day {
EndTimeObj = time.Date(int(FindData.StruStopTime.DwYear), time.Month(FindData.StruStopTime.DwMonth), int(FindData.StruStopTime.DwDay-1), 23, 59, 59, 59, time.UTC)
if uint16(res.EndDay) != Day {
EndTimeObj = time.Date(int(res.EndYear), time.Month(res.EndMonth), int(res.EndDay-1), 23, 59, 59, 59, time.UTC)
} else {
EndTimeObj = time.Date(int(FindData.StruStopTime.DwYear), time.Month(FindData.StruStopTime.DwMonth), int(FindData.StruStopTime.DwDay), int(FindData.StruStopTime.DwHour), int(FindData.StruStopTime.DwMinute), int(FindData.StruStopTime.DwSecond), 0, time.UTC)
EndTimeObj = time.Date(int(res.EndYear), time.Month(res.EndMonth), int(res.EndDay), int(res.EndHour), int(res.EndMinute), int(res.EndSecond), 0, time.UTC)
}
StartTimeObj = StartTimeObj.Add(time.Minute * time.Duration(-ByUTCDiff))
EndTimeObj = EndTimeObj.Add(time.Minute * time.Duration(-ByUTCDiff))
res = append(res, TimeRange{
webres = append(webres, WebTimeRang{
StartTime: StartTimeObj,
EndTime: EndTimeObj,
})
}
if state == 1002 {
FindData = Core.NET_DVR_FINDDATA_V30{}
state, err = Core.NET_DVR_FindNextFile_V30(QueryHandle, &FindData)
res, state, err = QueryDayNextFile(Handle)
if err != nil {
return []WebTimeRang{}, err
}
time.Sleep(time.Millisecond * 5)
continue
}
FindData = Core.NET_DVR_FINDDATA_V30{}
state, err = Core.NET_DVR_FindNextFile_V30(QueryHandle, &FindData)
res, state, err = QueryDayNextFile(Handle)
if err != nil {
return res, err
return []WebTimeRang{}, err
}
time.Sleep(time.Millisecond * 5)
}
err = Core.NET_DVR_FindClose_V30(QueryHandle)
err = FindClose(Handle)
if err != nil {
return nil, err
}
return res, nil
return webres, nil
}
func (this *Nvr) Logout() error {
if this == nil {
return errors.New("Nvr is nil")
}
return Core.Logout(this.userId)
return logout(this.userId)
}
func (this *Nvr) Status() bool {
if this == nil {
return false
}
return Core.NET_DVR_RemoteControl(this.userId)
}
type TimeRange struct {
StartTime time.Time
EndTime time.Time
return deviceOnline(this.userId)
}