dahua

package
v0.0.0-...-72e33f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 55 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxScannerPeriod is longest allowed time range for a mediafilefind query because some devices give invalid data past the MaxScannerPeriod.
	MaxScannerPeriod = 30 * 24 * time.Hour
)

Variables

View Source
var FeatureList []Feature = []Feature{
	{models.DahuaFeature_Camera, "camera", "Camera", "The device has a camera."},
}

Functions

func CountEmails

func CountEmails(ctx context.Context) (int64, error)

func CountEvents

func CountEvents(ctx context.Context) (int64, error)

func CountFiles

func CountFiles(ctx context.Context) (int64, error)

func CreateDevice

func CreateDevice(ctx context.Context, arg CreateDeviceParams) (int64, error)

func CreateEmail

func CreateEmail(ctx context.Context, arg CreateEmailParams) (int64, error)

func CreateEventRule

func CreateEventRule(ctx context.Context, arg repo.DahuaCreateEventRuleParams) (int64, error)

func CreateStorageDestination

func CreateStorageDestination(ctx context.Context, arg StorageDestination) (int64, error)

func DeleteDevice

func DeleteDevice(ctx context.Context, id int64) error

func DeleteEventRule

func DeleteEventRule(ctx context.Context, id int64) error

func DeleteEvents

func DeleteEvents(ctx context.Context) error

func DeleteStorageDestination

func DeleteStorageDestination(ctx context.Context, id int64) error

func DeleteStream

func DeleteStream(ctx context.Context, stream repo.DahuaStream) error

func FeatureFromStrings

func FeatureFromStrings(featureStrings []string) models.DahuaFeature

func FeatureToStrings

func FeatureToStrings(feature models.DahuaFeature) []string

func FileFTPReadCloser

func FileFTPReadCloser(ctx context.Context, filePath string) (io.ReadCloser, error)

func FileLocalDownload

func FileLocalDownload(ctx context.Context, client Client, fileID int64, fileFilePath, fileType string) error

FileLocalDownload downloads file from device and saves it to the afero file system.

func FileLocalReadCloser

func FileLocalReadCloser(ctx context.Context, client Client, filePath string) (io.ReadCloser, error)

func FileSFTPReadCloser

func FileSFTPReadCloser(ctx context.Context, filePath string) (io.ReadCloser, error)

func GetCoaxialCaps

func GetCoaxialCaps(ctx context.Context, rpcClient dahuarpc.Conn, channel int) (models.DahuaCoaxialCaps, error)

func GetCoaxialStatus

func GetCoaxialStatus(ctx context.Context, rpcClient dahuarpc.Conn, channel int) (models.DahuaCoaxialStatus, error)

func GetDahuaDetail

func GetDahuaDetail(ctx context.Context, rpcClient dahuarpc.Conn) (models.DahuaDetail, error)

func GetDevice

func GetDevice(ctx context.Context, id int64) (repo.DahuaDevice, error)

func GetError

func GetError(ctx context.Context, conn dahuarpc.Client) models.DahuaError

func GetLicenseList

func GetLicenseList(ctx context.Context, rpcClient dahuarpc.Conn) ([]models.DahuaLicense, error)

func GetLiveRTSPURL

func GetLiveRTSPURL(arg GetLiveRTSPURLParams) string

func GetRPCStatus

func GetRPCStatus(ctx context.Context, rpcClient dahuarpc.Client) models.DahuaRPCStatus

func GetSoftwareVersion

func GetSoftwareVersion(ctx context.Context, rpcClient dahuarpc.Conn) (models.DahuaSoftwareVersion, error)

func GetStorage

func GetStorage(ctx context.Context, rpcClient dahuarpc.Conn) ([]models.DahuaStorage, error)

func GetUptime

func GetUptime(ctx context.Context, c dahuarpc.Conn) (models.DahuaUptime, error)

func GetUsers

func GetUsers(ctx context.Context, rpcClient dahuarpc.Conn, location *time.Location) ([]models.DahuaUser, error)

func Init

func Init(_app App)

func Level

func Level(ctx context.Context, deviceID int64, level models.DahuaPermissionLevel) (bool, error)

func ListDeviceIDs

func ListDeviceIDs(ctx context.Context) ([]int64, error)

func ListDevices

func ListDevices(ctx context.Context) ([]repo.DahuaDevice, error)

func ListEmailAlarmEvents

func ListEmailAlarmEvents(ctx context.Context) ([]string, error)

func ListEventActions

func ListEventActions(ctx context.Context) ([]string, error)

func ListEventCodes

func ListEventCodes(ctx context.Context) ([]string, error)

func ListEventRules

func ListEventRules(ctx context.Context) ([]repo.DahuaEventRule, error)

func ListLatestFiles

func ListLatestFiles(ctx context.Context, count int) ([]repo.DahuaFile, error)

func ListPresets

func ListPresets(ctx context.Context, clientPTZ ptz.Client, channel int) ([]models.DahuaPreset, error)

func ListStreams

func ListStreams(ctx context.Context, deviceID int64) ([]repo.DahuaStream, error)

func LoginSMTP

func LoginSMTP(ctx context.Context, arg LoginSMTPParams) (repo.DahuaDevice, error)

func NewDahuaEvent

func NewDahuaEvent(v repo.DahuaEvent) models.DahuaEvent

func NewDahuaFile

func NewDahuaFile(file mediafilefind.FindNextFileInfo, affixSeed int, location *time.Location) (models.DahuaFile, error)

func NewDahuaFiles

func NewDahuaFiles(files []mediafilefind.FindNextFileInfo, affixSeed int, location *time.Location) ([]models.DahuaFile, error)

func Normalize

func Normalize(ctx context.Context) error

func ParseStorage

func ParseStorage(storage string) (models.Storage, error)

func PubSubMiddleware

func PubSubMiddleware(ctx context.Context) pubsub.MiddlewareFunc

func PushStreams

func PushStreams(ctx context.Context, deviceID int64) error

PushStreams pushes streams to mediamtx

func Scan

func Scan(ctx context.Context, rpcClient dahuarpc.Conn, device Conn, scanType models.DahuaScanType) error

Scan cannot be called concurrently for the same device.

func ScanReset

func ScanReset(ctx context.Context, deviceID int64) error

ScanReset cannot be called concurrently for the same device.

func ScannerScan

func ScannerScan(
	ctx context.Context,
	rpcClient dahuarpc.Conn,
	scanPeriod ScannerPeriod,
	location *time.Location,
	resC chan<- []mediafilefind.FindNextFileInfo,
) (context.CancelFunc, <-chan error)

func SetPreset

func SetPreset(ctx context.Context, clientPTZ ptz.Client, channel, index int) error

func StorageFromFilePath

func StorageFromFilePath(filePath string) models.Storage

func SupportStream

func SupportStream(feature models.DahuaFeature) bool

func SyncStreams

func SyncStreams(ctx context.Context, deviceID int64, conn dahuarpc.Conn) error

SyncStreams fetches streams from device and sync them with database.

func SyncSunriseSunset

func SyncSunriseSunset(ctx context.Context, c dahuarpc.Conn, loc *time.Location, coordinate models.Coordinate, sunriseOffset, sunsetOffset time.Duration) (models.DahuaSunriseSunset, error)

func TestStorageDestination

func TestStorageDestination(ctx context.Context, arg StorageDestination) error

func UpdateDevice

func UpdateDevice(ctx context.Context, arg UpdateDeviceParams) error

func UpdateDeviceDisabled

func UpdateDeviceDisabled(ctx context.Context, id int64, disable bool) error

func UpdateEventRule

func UpdateEventRule(ctx context.Context, arg repo.DahuaUpdateEventRuleParams) error

func UpdateStorageDestination

func UpdateStorageDestination(ctx context.Context, arg StorageDestination) error

Types

type App

type App struct {
	DB             sqlite.DB
	Hub            *bus.Hub
	AFS            afero.Fs
	Store          *Store
	ScanLocker     ScanLocker
	MediamtxClient *mediamtx.Client
	MediamtxConfig mediamtx.Config
}

type Client

type Client struct {
	Conn Conn
	RPC  dahuarpc.Client
	PTZ  ptz.Client
	CGI  dahuacgi.Client
	File dahuarpc.FileClient
}

func GetClient

func GetClient(ctx context.Context, deviceID int64) (Client, error)

func ListClient

func ListClient(ctx context.Context) ([]Client, error)

func NewClient

func NewClient(conn Conn) Client

func (Client) Close

func (c Client) Close(ctx context.Context) error

func (Client) CloseNoWait

func (c Client) CloseNoWait(ctx context.Context) error

type CoaxialWorker

type CoaxialWorker struct {
	// contains filtered or unexported fields
}

CoaxialWorker publishes coaxial status to the bus.

func NewCoaxialWorker

func NewCoaxialWorker(hooks WorkerHooks, deviceID int64) CoaxialWorker

func (CoaxialWorker) Serve

func (w CoaxialWorker) Serve(ctx context.Context) error

func (CoaxialWorker) String

func (w CoaxialWorker) String() string

type Conn

type Conn struct {
	ID       int64
	URL      *url.URL
	Username string
	Password string
	Location *time.Location
	Feature  models.DahuaFeature
	Seed     int
}

Conn is the bare minumum information required to create a connection to a Dahua device.

func GetConn

func GetConn(ctx context.Context, id int64) (Conn, error)

func ListConn

func ListConn(ctx context.Context) ([]Conn, error)

func (Conn) EQ

func (lhs Conn) EQ(rhs Conn) bool

type CountFilesByMonthResult

type CountFilesByMonthResult struct {
	Month types.Time
	Count int64
}

func CountFilesByMonth

func CountFilesByMonth(ctx context.Context, filter FileFilter) ([]CountFilesByMonthResult, error)

type CreateDeviceParams

type CreateDeviceParams struct {
	Name     string
	URL      *url.URL
	Username string
	Password string
	Location *time.Location
	Feature  models.DahuaFeature
	Email    string
}

type CreateEmailParams

type CreateEmailParams struct {
	DeviceID          int64
	Date              time.Time
	From              string
	To                []string
	Subject           string
	Text              string
	AlarmEvent        string
	AlarmInputChannel int
	AlarmName         string
	Attachments       []CreateEmailParamsAttachment
}

type CreateEmailParamsAttachment

type CreateEmailParamsAttachment struct {
	FileName string
	Content  []byte
}

type DefaultWorkerHooks

type DefaultWorkerHooks struct {
}

func NewDefaultWorkerHooks

func NewDefaultWorkerHooks() DefaultWorkerHooks

func (DefaultWorkerHooks) Connected

func (h DefaultWorkerHooks) Connected(ctx context.Context, w Worker)

func (DefaultWorkerHooks) Serve

func (h DefaultWorkerHooks) Serve(ctx context.Context, w Worker, connected bool, fn func(ctx context.Context) error) error

type Email

type Email struct {
	Message     repo.DahuaEmailMessage
	Attachments []repo.DahuaEmailAttachment
}

type EmailContent

type EmailContent struct {
	AlarmEvent        string
	AlarmInputChannel int
	AlarmDeviceName   string
	AlarmName         string
	IPAddress         string
}

func ParseEmailContent

func ParseEmailContent(text string) EmailContent

type EmailFilter

type EmailFilter struct {
	FilterDeviceIDs   []int64
	FilterAlarmEvents []string
}

type EventFilter

type EventFilter struct {
	FilterDeviceIDs []int64
	FilterCodes     []string
	FilterActions   []string
}

type EventWorker

type EventWorker struct {
	// contains filtered or unexported fields
}

EventWorker publishes events to bus.

func NewEventWorker

func NewEventWorker(hooks WorkerHooks, conn Conn) EventWorker

func (EventWorker) Serve

func (w EventWorker) Serve(ctx context.Context) error

func (EventWorker) String

func (w EventWorker) String() string

type Feature

type Feature struct {
	models.DahuaFeature
	Value       string
	Name        string
	Description string
}

type FileFilter

type FileFilter struct {
	FilterDeviceIDs []int64
	FilterMonth     time.Time
}

type GetEmailAroundParams

type GetEmailAroundParams struct {
	ID int64
	EmailFilter
}

type GetEmailAroundResult

type GetEmailAroundResult struct {
	EmailSeen       int64
	PreviousEmailID int64
	Count           int64
}

type GetEmailParams

type GetEmailParams struct {
	EmailFilter
	ID int64
}

type GetEmailResult

type GetEmailResult struct {
	NextEmailID int64
	Message     repo.DahuaEmailMessage
	Attachments []repo.DahuaListEmailAttachmentsForMessageRow
	Filter      EmailFilter
}

func GetEmail

func GetEmail(ctx context.Context, arg GetEmailParams) (GetEmailResult, error)

type GetEmailResultAttachments

type GetEmailResultAttachments struct {
	repo.DahuaEmailAttachment
	repo.DahuaAferoFile
}

type GetLiveRTSPURLParams

type GetLiveRTSPURLParams struct {
	Username string
	Password string
	Host     string
	Port     int
	Channel  int
	Subtype  int
}

type ListEmailsParams

type ListEmailsParams struct {
	pagination.Page
	EmailFilter
	Ascending bool
}

type ListEmailsResult

type ListEmailsResult struct {
	pagination.PageResult
	Items []ListEmailsResultItems
}

func ListEmails

func ListEmails(ctx context.Context, arg ListEmailsParams) (ListEmailsResult, error)

type ListEmailsResultItems

type ListEmailsResultItems struct {
	repo.DahuaEmailMessage
	DeviceName      string
	AttachmentCount int
}

type ListEventsParams

type ListEventsParams struct {
	pagination.Page
	Ascending bool
	EventFilter
}

type ListEventsResult

type ListEventsResult struct {
	pagination.PageResult
	Items []ListEventsResultItems
}

func ListEvents

func ListEvents(ctx context.Context, arg ListEventsParams) (ListEventsResult, error)

type ListEventsResultItems

type ListEventsResultItems struct {
	repo.DahuaEvent
	DeviceName string
}

type ListFilesParams

type ListFilesParams struct {
	pagination.Page
	Ascending bool
	Filter    FileFilter
}

type ListFilesResult

type ListFilesResult struct {
	pagination.PageResult
	Items []ListFilesResultItems
}

func ListFiles

func ListFiles(ctx context.Context, arg ListFilesParams) (ListFilesResult, error)

type ListFilesResultItems

type ListFilesResultItems struct {
	repo.DahuaFile
	DeviceName string
}

type ListLatestEmailsResult

type ListLatestEmailsResult struct {
	repo.DahuaEmailMessage
	AttachmentCount int64
}

func ListLatestEmails

func ListLatestEmails(ctx context.Context, count int) ([]ListLatestEmailsResult, error)

type LoginSMTPParams

type LoginSMTPParams struct {
	IP   string
	From string
}

type QuickScanWorker

type QuickScanWorker struct {
	// contains filtered or unexported fields
}

QuickScanWorker scans devices for files.

func NewQuickScanWorker

func NewQuickScanWorker(hooks WorkerHooks, pub *pubsub.Pub, deviceID int64) QuickScanWorker

func (QuickScanWorker) Serve

func (w QuickScanWorker) Serve(ctx context.Context) error

func (QuickScanWorker) String

func (w QuickScanWorker) String() string

type ScanLocker

type ScanLocker struct{ *core.LockStore[int64] }

func NewScanLocker

func NewScanLocker() ScanLocker

type ScannerPeriod

type ScannerPeriod struct {
	Start time.Time
	End   time.Time
}

ScannerPeriod is INCLUSIVE Start and EXCLUSIVE End.

type ScannerPeriodIterator

type ScannerPeriodIterator struct {
	// contains filtered or unexported fields
}

ScannerPeriodIterator generates scan periods that are equal to or less than MaxScanPeriod.

func NewScannerPeriodIterator

func NewScannerPeriodIterator(scanRange models.TimeRange) *ScannerPeriodIterator

func (*ScannerPeriodIterator) Cursor

func (s *ScannerPeriodIterator) Cursor() time.Time

func (*ScannerPeriodIterator) Next

func (*ScannerPeriodIterator) Percent

func (s *ScannerPeriodIterator) Percent() float64

type StorageDestination

type StorageDestination struct {
	ID              int64
	Name            string `validate:"required,lte=64"`
	Storage         models.Storage
	ServerAddress   string `validate:"host"`
	Port            int64
	Username        string
	Password        string
	RemoteDirectory string
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds clients.

func NewStore

func NewStore() *Store

func (*Store) Close

func (s *Store) Close()

Close closes all clients.

func (*Store) GetClient

func (s *Store) GetClient(ctx context.Context, deviceID int64) (Client, error)

func (*Store) ListClient

func (s *Store) ListClient(ctx context.Context) ([]Client, error)

func (*Store) Register

func (s *Store) Register(hub *bus.Hub) *Store

func (*Store) String

func (*Store) String() string

type Thumbnail

type Thumbnail struct {
	repo.DahuaThumbnail
	// contains filtered or unexported fields
}

func CreateThumbnail

func CreateThumbnail(ctx context.Context, fk ThumbnailForeignKeys, width, height int64, aferoFileName string) (Thumbnail, error)

func (Thumbnail) Ready

func (f Thumbnail) Ready(ctx context.Context) error

Ready sets the afero file to a ready state.

type ThumbnailForeignKeys

type ThumbnailForeignKeys struct {
	FileID            int64
	EmailAttachmentID int64
}

type UpdateDeviceParams

type UpdateDeviceParams struct {
	ID          int64
	Name        string
	URL         *url.URL
	Username    string
	NewPassword string
	Location    *time.Location
	Feature     models.DahuaFeature
	Email       string
}

type Worker

type Worker struct {
	DeviceID int64
	Type     models.DahuaWorkerType
}

type WorkerFactory

type WorkerFactory = func(ctx context.Context, super *suture.Supervisor, device Conn) []suture.ServiceToken

type WorkerHooks

type WorkerHooks interface {
	Serve(ctx context.Context, w Worker, connected bool, fn func(ctx context.Context) error) error
	Connected(ctx context.Context, w Worker)
}

type WorkerManager

type WorkerManager struct {
	// contains filtered or unexported fields
}

WorkerManager manages devices workers.

func NewWorkerManager

func NewWorkerManager(super *suture.Supervisor, factory WorkerFactory) *WorkerManager

func (*WorkerManager) Bootstrap

func (m *WorkerManager) Bootstrap(ctx context.Context) error

func (*WorkerManager) Delete

func (m *WorkerManager) Delete(id int64) error

func (*WorkerManager) Register

func (m *WorkerManager) Register() *WorkerManager

func (*WorkerManager) String

func (*WorkerManager) String() string

func (*WorkerManager) Upsert

func (m *WorkerManager) Upsert(ctx context.Context, conn Conn) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL