diff --git a/Nvr.go b/Nvr.go index ddd6fee..75f1151 100644 --- a/Nvr.go +++ b/Nvr.go @@ -7,6 +7,7 @@ package HikSDK */ import "C" import ( + "errors" "gitea.com/kunmeng/HikNetSDKPkg/Core" "time" "unsafe" @@ -29,6 +30,9 @@ func NewNvr(Ip string, Port int, Username, Password string) (*Nvr, error) { } 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()))) @@ -41,7 +45,9 @@ func (this *Nvr) GetTimeZone() (int, error) { } 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())) @@ -72,6 +78,9 @@ func (this *Nvr) CheckTimeRegionWithMonth(Year, Month, Channel uint16) ([]uint8, } func (this *Nvr) CheckTimeRegionWithDay(Year, Month, Day, Channel uint16) ([]TimeRange, error) { + if this == nil { + return nil, errors.New("Nvr is nil") + } var Data Core.NET_DVR_FILECOND Data.DwFileType = 0xff Data.DwIsLocked = 0xff @@ -163,6 +172,9 @@ func (this *Nvr) CheckTimeRegionWithDay(Year, Month, Day, Channel uint16) ([]Tim return res, nil } func (this *Nvr) Logout() error { + if this == nil { + return errors.New("Nvr is nil") + } return Core.Logout(this.userId) }