driver

package
v0.0.1-dev.22 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UpWithAuth    = "UpWithAuth"
	UpWithoutAuth = "UpWithoutAuth"
	Reachable     = "Reachable"
	Unreachable   = "Unreachable"
)

Enumerations for DeviceStatus

View Source
const (
	CustomMetadata       = "CustomMetadata"
	GetCustomMetadata    = "GetCustomMetadata"
	SetCustomMetadata    = "SetCustomMetadata"
	DeleteCustomMetadata = "DeleteCustomMetadata"
)
View Source
const (
	OnvifProtocol      = "Onvif"
	Address            = "Address"
	Port               = "Port"
	SecretPath         = "SecretPath"
	EndpointRefAddress = "EndpointRefAddress"
	LastSeen           = "LastSeen"
	DeviceStatus       = "DeviceStatus"
	MACAddress         = "MACAddress"

	// Service is resource attribute and indicates the web service for the Onvif
	Service = "service"
	// GetFunction is resource attribute and indicates the SOAP action for the specified web service, it is used for the read operation
	GetFunction = "getFunction"
	// SetFunction is resource attribute and indicates the SOAP action for the specified web service, it is used for the write operation
	SetFunction = "setFunction"

	// SubscribeType indicates the way to fetch the event message. The value should be PullPoint or BaseNotification.
	SubscribeType    = "subscribeType"
	PullPoint        = "PullPoint"
	BaseNotification = "BaseNotification"
	// DefaultSubscriptionPolicy is optional, we should check the camera capabilities before using
	DefaultSubscriptionPolicy = "defaultSubscriptionPolicy"
	// DefaultInitialTerminationTime indicates the subscription lifetime with specified duration.  For example, PT1H.
	DefaultInitialTerminationTime = "defaultInitialTerminationTime"
	// DefaultAutoRenew indicates the subscription will auto-renew before out of date. For example, true or false.
	DefaultAutoRenew = "defaultAutoRenew"
	// DefaultTopicFilter indicates the optional XPATH expression to filter the event. For example, tns1:RuleEngine/TamperDetector
	DefaultTopicFilter = "defaultTopicFilter"
	// DefaultMessageContentFilter indicates the optional XPATH expression to filter the event. For example, boolean(//tt:SimpleItem[@Name=”IsTamper”])
	DefaultMessageContentFilter = "defaultMessageContentFilter"
	// DefaultMessageTimeout specify the Timeout for PullMessage. Maximum time to block until this method returns. For example, PT5S
	DefaultMessageTimeout = "defaultMessageTimeout"
	// DefaultMessageLimit specify the MessageLimit for PullMessage. Upper limit for the number of messages to return at once, For example, 10
	DefaultMessageLimit = "defaultMessageLimit"
	// DefaultConsumerURL point to the consumer's network location
	DefaultConsumerURL = "defaultConsumerURL"

	Manufacturer    = "Manufacturer"
	Model           = "Model"
	FirmwareVersion = "FirmwareVersion"
	SerialNumber    = "SerialNumber"
	HardwareId      = "HardwareId"
)
View Source
const (
	AuthModeDigest        string = onvif.DigestAuth
	AuthModeUsernameToken string = onvif.UsernameTokenAuth
	AuthModeBoth          string = onvif.Both
	AuthModeNone          string = onvif.NoAuth
)
View Source
const (
	UsernameKey = "username"
	PasswordKey = "password"
	AuthModeKey = "mode"
)
View Source
const (
	EdgeXWebService        = "EdgeX"
	RebootNeeded           = "RebootNeeded"
	CameraEvent            = "CameraEvent"
	SubscribeCameraEvent   = "SubscribeCameraEvent"
	UnsubscribeCameraEvent = "UnsubscribeCameraEvent"
	GetSnapshot            = "GetSnapshot"
)
View Source
const MinimumInitialTerminationTime = 11

MinimumInitialTerminationTime indicates the minimum InitialTerminationTime because device service sends Renew request every ten second before termination time

View Source
const (
	OnvifEventRestPath = "onvifevent"
)
View Source
const (
	URLRawQuery = "urlRawQuery"
)

Variables

This section is empty.

Functions

func IsAuthModeValid

func IsAuthModeValid(mode string) bool

func SanitizeMACAddress

func SanitizeMACAddress(mac string) (string, error)

SanitizeMACAddress takes in a MAC address in one of the IEEE 802 MAC-48, EUI-48, EUI-64 formats and will return it in the standard go format, using colons and lower case letters: Example: aa:bb:cc:dd:ee:ff

Types

type BaseNotificationManager

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

BaseNotificationManager manages the consumers to renew the subscription

func NewBaseNotificationManager

func NewBaseNotificationManager(lc logger.LoggingClient) *BaseNotificationManager

NewBaseNotificationManager create the new BaseNotificationManager entity

func (*BaseNotificationManager) NewConsumer

func (manager *BaseNotificationManager) NewConsumer(onvifClient *OnvifClient, resourceName string, attributes map[string]interface{}, data []byte) errors.EdgeX

NewConsumer create the new NewConsumer entity and send the subscription request to the camera

func (*BaseNotificationManager) UnsubscribeAll

func (manager *BaseNotificationManager) UnsubscribeAll()

type CameraInfo

type CameraInfo struct {
	Address    string
	Port       int
	SecretPath string
}

CameraInfo holds the camera connection info

func CreateCameraInfo

func CreateCameraInfo(protocols map[string]models.ProtocolProperties) (*CameraInfo, errors.EdgeX)

CreateCameraInfo creates new CameraInfo entity from the protocol properties

type Consumer

type Consumer struct {
	Name string

	// SubscriptionAddress is the reference for the event producer
	SubscriptionAddress string
	// Stopped indicates the Consumer should stop the subscription
	Stopped chan bool
	// contains filtered or unexported fields
}

Consumer holds the subscription info and receive the camera event

func (*Consumer) StartRenewLoop

func (consumer *Consumer) StartRenewLoop()

StartRenewLoop renews the subscription before termination time

type Credentials

type Credentials struct {
	Username string
	Password string
	AuthMode string
}

Credentials encapsulates username, password, and AuthMode attributes. Assign AuthMode to "digest" | "usernametoken" | "both" | "none"

type CustomConfig

type CustomConfig struct {
	CredentialsRetryTime int
	CredentialsRetryWait int
	RequestTimeout       int
	// DefaultSecretPath indicates the secret path to retrieve username and password from secret store.
	DefaultSecretPath string
	// DiscoveryEthernetInterface indicates the target EthernetInterface for discovering. The default value is `en0`, the user can modify it to meet their requirement.
	DiscoveryEthernetInterface string
	// BaseNotificationURL indicates the device service network location
	BaseNotificationURL string

	// DiscoveryMode indicates mode used to discovery devices on the network.
	DiscoveryMode DiscoveryMode
	// DiscoverySubnets indicates the network segments used when discovery is scanning for devices.
	DiscoverySubnets string
	// ProbeAsyncLimit indicates the maximum number of simultaneous network probes.
	ProbeAsyncLimit int
	// ProbeTimeoutMillis indicates the maximum amount of milliseconds to wait for each IP probe before timing out.
	ProbeTimeoutMillis int
	// MaxDiscoverDurationSeconds indicates the amount of seconds discovery will run before timing out.
	MaxDiscoverDurationSeconds int

	// EnableStatusCheck indicates if status checking should be enabled
	EnableStatusCheck bool
	// CheckStatusInterval indicates the interval in seconds at which the device service will check device statuses
	CheckStatusInterval int

	// ProvisionWatcherDir is the location of Provision Watchers
	ProvisionWatcherDir string

	// CredentialsMap is a map of SecretPath -> Comma separated list of mac addresses
	CredentialsMap map[string]string
}

CustomConfig holds the values for the driver configuration

type DeviceSDKService

type DeviceSDKService struct {
	*service.DeviceService
}

DeviceSDKService is the native implementation of ServiceWrapper that uses the actual service.DeviceService struct.

func (*DeviceSDKService) GetLoggingClient

func (s *DeviceSDKService) GetLoggingClient() logger.LoggingClient

GetLoggingClient returns the logger.LoggingClient

func (*DeviceSDKService) GetSecretProvider

func (s *DeviceSDKService) GetSecretProvider() interfaces.SecretProvider

GetSecretProvider returns the SecretProvider

type DiscoveryMode

type DiscoveryMode string
const (
	ModeNetScan   DiscoveryMode = "netscan"
	ModeMulticast DiscoveryMode = "multicast"
	ModeBoth      DiscoveryMode = "both"
)

func (DiscoveryMode) IsMulticastEnabled

func (mode DiscoveryMode) IsMulticastEnabled() bool

func (DiscoveryMode) IsNetScanEnabled

func (mode DiscoveryMode) IsNetScanEnabled() bool

func (DiscoveryMode) IsValid

func (mode DiscoveryMode) IsValid() bool

type Driver

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

Driver implements the sdkModel.ProtocolDriver interface for the device service

func (*Driver) AddDevice

func (d *Driver) AddDevice(deviceName string, protocols map[string]models.ProtocolProperties, adminState models.AdminState) error

AddDevice is a callback function that is invoked when a new Device associated with this Device Service is added

func (*Driver) Discover

func (d *Driver) Discover()

Discover performs a discovery on the network and passes them to EdgeX to get provisioned

func (*Driver) HandleReadCommands

func (d *Driver) HandleReadCommands(deviceName string, protocols map[string]models.ProtocolProperties, reqs []sdkModel.CommandRequest) ([]*sdkModel.CommandValue, error)

HandleReadCommands triggers a protocol Read operation for the specified device.

func (*Driver) HandleWriteCommands

func (d *Driver) HandleWriteCommands(deviceName string, protocols map[string]models.ProtocolProperties, reqs []sdkModel.CommandRequest, params []*sdkModel.CommandValue) error

HandleWriteCommands passes a slice of CommandRequest struct each representing a ResourceOperation for a specific device resource (aka DeviceObject). Since the commands are actuation commands, params provide parameters for the individual command.

func (*Driver) Initialize

func (d *Driver) Initialize(lc logger.LoggingClient, asyncCh chan<- *sdkModel.AsyncValues,
	deviceCh chan<- []sdkModel.DiscoveredDevice) error

Initialize performs protocol-specific initialization for the device service.

func (*Driver) RemoveDevice

func (d *Driver) RemoveDevice(deviceName string, protocols map[string]models.ProtocolProperties) error

RemoveDevice is a callback function that is invoked when a Device associated with this Device Service is removed

func (*Driver) Stop

func (d *Driver) Stop(force bool) error

Stop the protocol-specific DS code to shutdown gracefully, or if the force parameter is 'true', immediately. The driver is responsible for closing any in-use channels, including the channel used to send async readings (if supported).

func (*Driver) UpdateDevice

func (d *Driver) UpdateDevice(deviceName string, protocols map[string]models.ProtocolProperties, adminState models.AdminState) error

UpdateDevice is a callback function that is invoked when a Device associated with this Device Service is updated

type Duration

type Duration struct {
	Y int
	M int
	W int
	D int
	// Time Component
	TH int
	TM int
	TS int
}

Duration represents an ISO8601 Duration

type MACAddressMapper

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

func NewMACAddressMapper

func NewMACAddressMapper(sdkService SDKService) *MACAddressMapper

NewMACAddressMapper creates a new MACAddressMapper object

func (*MACAddressMapper) ListMACAddresses

func (m *MACAddressMapper) ListMACAddresses() []string

ListMACAddresses will return a slice of mac addresses that have been assigned credentials

func (*MACAddressMapper) TryGetSecretPathForMACAddress

func (m *MACAddressMapper) TryGetSecretPathForMACAddress(mac string, defaultSecretPath string) string

TryGetSecretPathForMACAddress will return the secret path associated with the mac address passed if a mapping exists, or the default secret path if the mapping is not found, or the mac address is invalid.

func (*MACAddressMapper) UpdateMappings

func (m *MACAddressMapper) UpdateMappings(raw map[string]string)

UpdateMappings takes the raw map of secret path to csv list of mac addresses and inverts it into a quick lookup map of mac address to secret path.

type MultiErr

type MultiErr []error

func (MultiErr) Error

func (me MultiErr) Error() string

type OnvifClient

type OnvifClient struct {
	DeviceName string

	// RebootNeeded indicates the camera should reboot to apply the configuration change
	RebootNeeded bool
	// CameraEventResource is used to send the async event to north bound
	CameraEventResource models.DeviceResource
	// contains filtered or unexported fields
}

OnvifClient manages the state required to issue ONVIF requests to the specified camera

func (*OnvifClient) CallOnvifFunction

func (onvifClient *OnvifClient) CallOnvifFunction(req sdkModel.CommandRequest, functionType string, data []byte) (cv *sdkModel.CommandValue, edgexErr errors.EdgeX)

CallOnvifFunction send the request to the camera via onvif client

type OnvifProtocolDiscovery

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

OnvifProtocolDiscovery implements netscan.ProtocolSpecificDiscovery

func NewOnvifProtocolDiscovery

func NewOnvifProtocolDiscovery(driver *Driver) *OnvifProtocolDiscovery

func (*OnvifProtocolDiscovery) ConvertProbeResult

func (proto *OnvifProtocolDiscovery) ConvertProbeResult(probeResult netscan.ProbeResult, params netscan.Params) (sdkModel.DiscoveredDevice, error)

ConvertProbeResult takes a raw ProbeResult and transforms it into a processed DiscoveredDevice struct.

func (*OnvifProtocolDiscovery) OnConnectionDialed

func (proto *OnvifProtocolDiscovery) OnConnectionDialed(host string, port string, conn net.Conn, params netscan.Params) ([]netscan.ProbeResult, error)

OnConnectionDialed handles the protocol specific verification if there is actually a valid device or devices at the other end of the connection.

func (*OnvifProtocolDiscovery) ProbeFilter

func (proto *OnvifProtocolDiscovery) ProbeFilter(_ string, ports []string) []string

ProbeFilter takes in a host and a slice of ports to be scanned. It should return a slice of ports to actually scan, or a nil/empty slice if the host is to not be scanned at all. Can be used to filter out known devices from being probed again if required.

type PullPointManager

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

PullPointManager manages the subscribers to pull event from specified PullPoints

func (*PullPointManager) NewSubscriber

func (manager *PullPointManager) NewSubscriber(onvifClient *OnvifClient, resourceName string, attributes map[string]interface{}, data []byte) errors.EdgeX

NewSubscriber creates a new subscriber entity and start pulling the event from the camera

func (*PullPointManager) UnsubscribeAll

func (manager *PullPointManager) UnsubscribeAll()

UnsubscribeAll stops all subscriptions

type RestNotificationHandler

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

RestNotificationHandler handle the notification from the camera and send to async value channel

func NewRestNotificationHandler

func NewRestNotificationHandler(service SDKService, logger logger.LoggingClient, asyncValues chan<- *models.AsyncValues) *RestNotificationHandler

NewRestNotificationHandler create a new RestNotificationHandler entity

func (RestNotificationHandler) AddRoute

func (handler RestNotificationHandler) AddRoute() errors.EdgeX

AddRoute adds route for receiving the notification from the camera

type SDKService

type SDKService interface {

	// AddDeviceAutoEvent adds a new AutoEvent to the Device with given name
	AddDeviceAutoEvent(deviceName string, event models.AutoEvent) error

	// RemoveDeviceAutoEvent removes an AutoEvent from the Device with given name
	RemoveDeviceAutoEvent(deviceName string, event models.AutoEvent) error

	// AddDevice adds a new Device to the Device Service and Core Metadata
	// Returns new Device id or non-nil error.
	AddDevice(device models.Device) (string, error)

	// Devices return all managed Devices from cache
	Devices() []models.Device

	// GetDeviceByName returns the Device by its name if it exists in the cache, or returns an error.
	GetDeviceByName(name string) (models.Device, error)

	// RemoveDeviceByName removes the specified Device by name from the cache and ensures that the
	// instance in Core Metadata is also removed.
	RemoveDeviceByName(name string) error

	// UpdateDevice updates the Device in the cache and ensures that the
	// copy in Core Metadata is also updated.
	UpdateDevice(device models.Device) error

	// UpdateDeviceOperatingState updates the Device's OperatingState with given name
	// in Core Metadata and device service cache.
	UpdateDeviceOperatingState(deviceName string, state string) error

	// AddDeviceProfile adds a new DeviceProfile to the Device Service and Core Metadata
	// Returns new DeviceProfile id or non-nil error.
	AddDeviceProfile(profile models.DeviceProfile) (string, error)

	// DeviceProfiles return all managed DeviceProfiles from cache
	DeviceProfiles() []models.DeviceProfile

	// GetProfileByName returns the Profile by its name if it exists in the cache, or returns an error.
	GetProfileByName(name string) (models.DeviceProfile, error)

	// RemoveDeviceProfileByName removes the specified DeviceProfile by name from the cache and ensures that the
	// instance in Core Metadata is also removed.
	RemoveDeviceProfileByName(name string) error

	// UpdateDeviceProfile updates the DeviceProfile in the cache and ensures that the
	// copy in Core Metadata is also updated.
	UpdateDeviceProfile(profile models.DeviceProfile) error

	// DeviceCommand retrieves the specific DeviceCommand instance from cache according to
	// the Device name and Command name
	DeviceCommand(deviceName string, commandName string) (models.DeviceCommand, bool)

	// DeviceResource retrieves the specific DeviceResource instance from cache according to
	// the Device name and Device Resource name
	DeviceResource(deviceName string, deviceResource string) (models.DeviceResource, bool)

	// AddProvisionWatcher adds a new Watcher to the cache and Core Metadata
	// Returns new Watcher id or non-nil error.
	AddProvisionWatcher(watcher models.ProvisionWatcher) (string, error)

	// ProvisionWatchers return all managed Watchers from cache
	ProvisionWatchers() []models.ProvisionWatcher

	// GetProvisionWatcherByName returns the Watcher by its name if it exists in the cache, or returns an error.
	GetProvisionWatcherByName(name string) (models.ProvisionWatcher, error)

	// RemoveProvisionWatcher removes the specified Watcher by name from the cache and ensures that the
	// instance in Core Metadata is also removed.
	RemoveProvisionWatcher(name string) error

	// UpdateProvisionWatcher updates the Watcher in the cache and ensures that the
	// copy in Core Metadata is also updated.
	UpdateProvisionWatcher(watcher models.ProvisionWatcher) error

	// Name returns the name of this Device Service
	Name() string

	// Version returns the version number of this Device Service
	Version() string

	// AsyncReadings returns a bool value to indicate whether the asynchronous reading is enabled.
	AsyncReadings() bool

	// DeviceDiscovery returns a bool value to indicate whether device discovery is enabled.
	DeviceDiscovery() bool

	// AddRoute allows leveraging the existing internal web server to add routes specific to Device Service.
	AddRoute(route string, handler func(http.ResponseWriter, *http.Request), methods ...string) error

	// Stop shuts down the Service
	Stop(force bool)

	// LoadCustomConfig uses the Config Processor from go-mod-bootstrap to attempt to load service's
	// custom configuration. It uses the same command line flags to process the custom config in the same manner
	// as the standard configuration.
	LoadCustomConfig(customConfig service.UpdatableConfig, sectionName string) error

	// ListenForCustomConfigChanges uses the Config Processor from go-mod-bootstrap to attempt to listen for
	// changes to the specified custom configuration section. LoadCustomConfig must be called previously so that
	// the instance of sdkService.configProcessor has already been set.
	ListenForCustomConfigChanges(configToWatch interface{}, sectionName string, changedCallback func(interface{})) error

	// GetLoggingClient returns the logger.LoggingClient. The name was chosen to avoid conflicts
	// with service.DeviceService.LoggingClient struct field.
	GetLoggingClient() logger.LoggingClient

	// GetSecretProvider returns the interfaces.SecretProvider. The name was chosen to avoid conflicts
	// with service.DeviceService.SecretProvider struct field.
	GetSecretProvider() interfaces.SecretProvider
}

SDKService wraps an EdgeX SDK service.DeviceService so that it can be easily mocked in tests.

type ServiceConfig

type ServiceConfig struct {
	AppCustom CustomConfig
}

ServiceConfig a struct that wraps CustomConfig which holds the values for driver configuration

func (*ServiceConfig) UpdateFromRaw

func (c *ServiceConfig) UpdateFromRaw(rawConfig interface{}) bool

UpdateFromRaw updates the service's full configuration from raw data received from the Service Provider.

type Subscriber

type Subscriber struct {
	Name string

	// SubscriptionAddress is used to pull the event from the camera
	SubscriptionAddress string

	// Stopped indicates the Subscriber should stop the PullMessageLoop
	Stopped chan bool
	// contains filtered or unexported fields
}

func (*Subscriber) StartPullMessageLoop

func (sub *Subscriber) StartPullMessageLoop()

StartPullMessageLoop implements the long-polling strategy to pull the camera event

type SubscriptionRequest

type SubscriptionRequest struct {
	// AutoRenew indicate the device service should renew the subscription
	AutoRenew *bool

	// TopicFilter  indicates the optional XPATH expression to filter the event by topic
	TopicFilter *string
	// TopicFilter  indicates the optional XPATH expression to filter the event by message content
	MessageContentFilter *string
	// SubscriptionPolicy is the camera's subscription policy, the user should check the capability before using it
	SubscriptionPolicy *string
	// InitialTerminationTime indicates the subscription lifetime with specified duration
	InitialTerminationTime *string

	// MessageTimeout indicates the timeout to pull event message
	MessageTimeout *string
	// MessageTimeout indicates the limit for the number of messages to return at once
	MessageLimit *int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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