 c8cb43e9b3
			
		
	
	c8cb43e9b3
	
	
	
		
			
			- 移除 Core 目录下的 CallBack.go、core.go 和 Type.go 文件 - 这些文件包含了未使用的类型定义和函数实现 - 删除冗余代码有助于简化项目结构,提高代码可读性和维护性
		
			
				
	
	
		
			134 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			134 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package HikSDK
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"time"
 | |
| )
 | |
| 
 | |
| type Nvr struct {
 | |
| 	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 := login(Ip, Port, Username, Password)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return &Nvr{
 | |
| 		userId:     userId,
 | |
| 		deviceInfo: deviceInfo,
 | |
| 	}, nil
 | |
| }
 | |
| 
 | |
| func (this *Nvr) GetTimeZone() (int, error) {
 | |
| 	if this == nil {
 | |
| 		return 0, errors.New("Nvr is 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")
 | |
| 	}
 | |
| 	return QueryMonth(this.userId, WORD(Year), BYTE(Month), DWORD(Channel))
 | |
| }
 | |
| 
 | |
| func (this *Nvr) CheckTimeRegionWithDay(Year, Month, Day, Channel uint16) ([]WebTimeRang, error) {
 | |
| 	if this == nil {
 | |
| 		return nil, errors.New("Nvr is nil")
 | |
| 	}
 | |
| 	Handle := QueryDayHandle(this.userId, DWORD(Year), DWORD(Month), DWORD(Day), LONG(Channel))
 | |
| 	res, state, err := QueryDayNextFile(Handle)
 | |
| 	if err != nil {
 | |
| 		return []WebTimeRang{}, err
 | |
| 	}
 | |
| 	ByUTCDiff, err := this.GetTimeZone()
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	var webres []WebTimeRang
 | |
| 	for state > 0 {
 | |
| 		var StartTimeObj time.Time
 | |
| 		var EndTimeObj time.Time
 | |
| 
 | |
| 		if state == 1001 {
 | |
| 			break
 | |
| 		}
 | |
| 		if state == 1003 {
 | |
| 			break
 | |
| 		}
 | |
| 		if state == 1004 {
 | |
| 			break
 | |
| 		}
 | |
| 		if state == 1000 {
 | |
| 			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(res.StartYear), time.Month(res.StartMonth), int(res.StartDay), int(res.StartHour), int(res.StartMinute), int(res.StartSecond), 0, 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(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))
 | |
| 			webres = append(webres, WebTimeRang{
 | |
| 				StartTime: StartTimeObj,
 | |
| 				EndTime:   EndTimeObj,
 | |
| 			})
 | |
| 		}
 | |
| 		if state == 1002 {
 | |
| 			res, state, err = QueryDayNextFile(Handle)
 | |
| 			if err != nil {
 | |
| 				return []WebTimeRang{}, err
 | |
| 			}
 | |
| 			time.Sleep(time.Millisecond * 5)
 | |
| 			continue
 | |
| 		}
 | |
| 		res, state, err = QueryDayNextFile(Handle)
 | |
| 		if err != nil {
 | |
| 			return []WebTimeRang{}, err
 | |
| 		}
 | |
| 		time.Sleep(time.Millisecond * 5)
 | |
| 	}
 | |
| 	err = FindClose(Handle)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return webres, nil
 | |
| }
 | |
| func (this *Nvr) Logout() error {
 | |
| 	if this == nil {
 | |
| 		return errors.New("Nvr is nil")
 | |
| 	}
 | |
| 	return logout(this.userId)
 | |
| }
 | |
| func (this *Nvr) Status() bool {
 | |
| 	if this == nil {
 | |
| 		return false
 | |
| 	}
 | |
| 	return deviceOnline(this.userId)
 | |
| }
 |