import "."
Overview
Index
Subdirectories

Overview ▾

This package provides a basic EdgeX Foundry device service implementation meant to be embedded in an application, similar in approach to the builtin net/http package.

Index ▾

Constants
func GetConsulClient(serviceName string, config *Config) (*registry.ConsulClient, error)
type CommandRequest
type CommandResult
    func NewBoolResult(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value bool) (cr *CommandResult)
    func NewFloat32Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value float32) (cr *CommandResult)
    func NewFloat64Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value float64) (cr *CommandResult)
    func NewInt16Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value int16) (cr *CommandResult)
    func NewInt32Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value int32) (cr *CommandResult)
    func NewInt64Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value int64) (cr *CommandResult)
    func NewInt8Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value int8) (cr *CommandResult)
    func NewStringResult(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value string) (cr *CommandResult)
    func NewUint16Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value uint16) (cr *CommandResult)
    func NewUint32Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value uint32) (cr *CommandResult)
    func NewUint64Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value uint64) (cr *CommandResult)
    func NewUint8Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value uint8) (cr *CommandResult)
    func (cr *CommandResult) Reading(devName string, doName string) *models.Reading
    func (cr *CommandResult) String() (str string)
    func (cr *CommandResult) Transform() error
    func (cr *CommandResult) TransformResult(models.PropertyValue) bool
type Config
    func LoadConfig(profile string, configDir string) (config *Config, err error)
type DeviceInfo
type LoggingInfo
type ProtocolDiscovery
type ProtocolDriver
type ResultType
type ScheduleCache
    func (s *ScheduleCache) AddSchedule(schedule *models.Schedule)
    func (s *ScheduleCache) AddScheduleEvent(scheduleEvent *models.ScheduleEvent)
    func (s *ScheduleCache) GetAllScheduleEvents() *[]models.ScheduleEvent
    func (s *ScheduleCache) GetAllSchedules() *[]models.Schedule
    func (s *ScheduleCache) GetScheduleByName(name string) (*models.Schedule, error)
    func (s *ScheduleCache) GetScheduleEventByName(name string) (*models.ScheduleEvent, error)
    func (s *ScheduleCache) RemoveSchedule(schedule *models.Schedule) error
    func (s *ScheduleCache) RemoveScheduleEvent(scheduleEvent *models.ScheduleEvent) error
    func (s *ScheduleCache) UpdateSchedule(schedule *models.Schedule) error
    func (s *ScheduleCache) UpdateScheduleEvent(scheduleEvent *models.ScheduleEvent) error
type ScheduleCacheInterface
type ScheduleEventInfo
type Service
    func NewService(name string, version string, proto ProtocolDriver) (*Service, error)
    func (s *Service) AddDevice(dev models.Device) (id string, err error)
    func (s *Service) GetDevices() []model.Device
    func (s *Service) RemoveDevice(id string) error
    func (s *Service) RemoveDeviceByName(name string) error
    func (s *Service) UpdateDevice(dev models.Device) error
    func (s *Service) AddDeviceProfile(dev models.DeviceProfile) (id string, err error)
    func (s *Service) GetDeviceProfiles() []model.DeviceProfile
    func (s *Service) RemoveDeviceProfile(id string) error
    func (s *Service) RemoveDeviceProfileByName(name string) error
    func (s *Service) UpdateDeviceProfile(dev models.DeviceProfile) error
    func (s *Service) Start(useRegistry bool, profile string, confDir string) (err error)
    func (s *Service) Stop(force bool) error
type ServiceInfo
type WatcherInfo
type Watchers

Package files

async.go clientinitializer.go command.go commandrequest.go commandresult.go config.go control.go devices.go profiles.go protocoldiscovery.go protocoldriver.go schedules.go service.go status.go update.go utils.go watchers.go

Constants

const (
    ClientData     = "Data"
    ClientMetadata = "Metadata"
)

func GetConsulClient

func GetConsulClient(serviceName string, config *Config) (*registry.ConsulClient, error)

type CommandRequest

type CommandRequest struct {
    // RO is a ResourceOperation
    RO models.ResourceOperation
    // DeviceObject (aka device resource) represents the device resource
    // to be read or set. It can be used to access the attributes map,
    // PropertyValue, and PropertyUnit structs.
    DeviceObject models.DeviceObject
}

type CommandResult

type CommandResult struct {
    // DeviceId identifies the device that produced this result.
    DeviceId string
    // DeviceName identifies the device that produced this result.
    DeviceName string
    // RO is a pointer to the ResourceOperation that triggered the
    // CommandResult to be returned from the ProtocolDriver instance.
    RO *models.ResourceOperation
    // VDR is a pointer to the associated ValueDescriptor.
    VDR *models.ValueDescriptor
    // Origin is an int64 value which indicates the time the reading
    // contained in the CommandResult was read by the ProtocolDriver
    // instance.
    Origin int64
    // Type is a ResultType value which indicates what type of
    // result was returned from the ProtocolDriver instance in
    // response to HandleCommand being called to handle a single
    // ResourceOperation.
    Type ResultType
    // NumericResult is a byte slice with a maximum capacity of
    // 64 bytes, used to hold a numeric result returned by a
    // ProtocolDriver instance. The value can be converted to
    // its native type by referring to the the value of ResType.
    NumericResult []byte
    // StringResult is a string value returned as a result by a ProtocolDriver instance.
    StringResult string
    // BoolResult is a bool value returned as a result by a ProtocolDriver instance.
    BoolResult bool
}

func NewBoolResult

func NewBoolResult(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value bool) (cr *CommandResult)

func NewFloat32Result

func NewFloat32Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value float32) (cr *CommandResult)

NewFloat32Result creates a CommandResult of Type Float32 with the given value.

func NewFloat64Result

func NewFloat64Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value float64) (cr *CommandResult)

NewFloat64Result creates a CommandResult of Type Float64 with the given value.

func NewInt16Result

func NewInt16Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value int16) (cr *CommandResult)

NewInt16Result creates a CommandResult of Type Int16 with the given value.

func NewInt32Result

func NewInt32Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value int32) (cr *CommandResult)

NewInt32Result creates a CommandResult of Type Int32 with the given value.

func NewInt64Result

func NewInt64Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value int64) (cr *CommandResult)

NewInt64Result creates a CommandResult of Type Int64 with the given value.

func NewInt8Result

func NewInt8Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value int8) (cr *CommandResult)

NewInt8Result creates a CommandResult of Type Int8 with the given value.

func NewStringResult

func NewStringResult(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value string) (cr *CommandResult)

func NewUint16Result

func NewUint16Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value uint16) (cr *CommandResult)

NewUint16Result creates a CommandResult of Type Uint16 with the given value.

func NewUint32Result

func NewUint32Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value uint32) (cr *CommandResult)

NewUint32Result creates a CommandResult of Type Uint32 with the given value.

func NewUint64Result

func NewUint64Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value uint64) (cr *CommandResult)

NewUint64Result creates a CommandResult of Type Uint64 with the given value.

func NewUint8Result

func NewUint8Result(ro *models.ResourceOperation, vdr *models.ValueDescriptor, origin int64, value uint8) (cr *CommandResult)

NewUint8Result creates a CommandResult of Type Uint8 with the given value.

func (*CommandResult) Reading

func (cr *CommandResult) Reading(devName string, doName string) *models.Reading

Reading returns a new Reading instance created from the the given CommandResult.

func (*CommandResult) String

func (cr *CommandResult) String() (str string)

String returns a string representation of a CommandResult instance.

func (*CommandResult) Transform

func (cr *CommandResult) Transform() error

Transform applies any transform attributes contained in the CommandResult's ValueDescriptor to the result. If the transform operations result in an overflow for the specified type, an error is returned.

func (*CommandResult) TransformResult

func (cr *CommandResult) TransformResult(models.PropertyValue) bool

TransformResult applies transforms specified in the given PropertyValue instance.

type Config

type Config struct {
    // Service contains service-specific settings.
    Service ServiceInfo
    // Registry contains registry-specific settings.
    Registry service
    // Clients is a map of services used by a DS.
    Clients map[string]service
    // Device contains device-specific coniguration settings.
    Device DeviceInfo
    // Logging contains logging-specific configuration settings.
    Logging LoggingInfo
    // Schedules is created on startup.
    Schedules []models.Schedule
    // SchedulesEvents is created on startup.
    ScheduleEvents []models.ScheduleEvent
    // Watchers is a map provisionwatchers to be created on startup.
    Watchers map[string]WatcherInfo
}

Config is a struct which contains all of a DS's configuration settings.

func LoadConfig

func LoadConfig(profile string, configDir string) (config *Config, err error)

LoadConfig loads the local configuration file based upon the specified parameters and returns a pointer to the global Config struct which holds all of the local configuration settings for the DS.

type DeviceInfo

type DeviceInfo struct {
    // DataTransform specifies whether or not the DS perform transformations
    // specified by valuedescriptor on a actuation or query command.
    DataTransform bool
    // InitCmd specifies a device resource command which is automatically
    // generated whenever a new device is added to the DS.
    InitCmd string
    // InitCmdArgs specify arguments to be used when building the InitCmd.
    InitCmdArgs string
    // MaxCmdOps defines the maximum number of resource operations that
    // can be sent to a ProtocolDriver in a single command.
    MaxCmdOps int
    // MaxCmdValueLen is the maximum string length of a command parameter or
    // result (including the valuedescriptor name) that can be returned
    // by a ProtocolDriver.
    MaxCmdValueLen int
    // InitCmd specifies a device resource command which is automatically
    // generated whenever a new device is removed from the DS.
    RemoveCmd string
    // RemoveCmdArgs specify arguments to be used when building the RemoveCmd.
    RemoveCmdArgs string
    // ProfilesDir specifies a directory which contains deviceprofile
    // files which should be imported on startup.
    ProfilesDir string
    // SendReaingsOnChanged can be used to cause a DS to only send readings
    // to Core Data when the reading has changed (based on comparison to an
    // existing reading in the cache, if present).
    SendReadingsOnChanged bool
}

DeviceInfo is a struct which contains device specific configuration settings.

type LoggingInfo

type LoggingInfo struct {
    // File is the pathname of a local log file to be created.
    File string
    // RemoteURL is the URL of the support logging service.
    // TODO: make this just another client!
    RemoteURL string
}

LoggingInfo is a struct which contains logging specific configuration settings.

type ProtocolDiscovery

type ProtocolDiscovery interface {
    // Discover triggers protocol specific device discovery, which is
    // a synchronous operation which returns a list of new devices
    // which may be added to the device service based on service
    // configuration. This function may also optionally trigger sensor
    // discovery, which could result in dynamic device profile creation.
    //
    // TODO: add models.ScanList (or define locally) for devices
    Discover() (devices *interface{}, err error)
}

ProtocolDiscovery is a low-level device-specific interface implemented by device services that support dynamic device discovery.

type ProtocolDriver

type ProtocolDriver interface {

    // DisconnectDevice is when a device is removed from the device
    // service. This function allows for protocol specific disconnection
    // logic to be performed.  Device services which don't require this
    // function should just return 'nil'.
    //
    // TODO: the Java code uses this signature, with the addressable
    // appearing to be that of the device service itself. I'm not sure
    // how this gets tied by the driver code to an actual device. Maybe
    // this should be *models.Device?
    //
    DisconnectDevice(address *models.Addressable) error

    // Initialize performs protocol-specific initialization for the device
    // service. The given *CommandResult channel can be used to push asynchronous
    // events and readings to Core Data.
    Initialize(s *Service, lc logger.LoggingClient, asyncCh <-chan *CommandResult) error

    // HandleCommands passes a slice of CommandRequest structs each representing
    // a ResourceOperation for a specific device resource (aka DeviceObject).
    // If commands are actuation commands, then params may be used to provide
    // an optional JSON encoded string specifying paramters for the individual
    // commands.
    //
    // TODO: add param to CommandRequest and have command endpoint parse the params.
    HandleCommands(d models.Device, reqs []CommandRequest, params string) ([]CommandResult, error)

    // Stop instructs 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).
    Stop(force bool) error
}

ProtocolDriver is a low-level device-specific interface used by by other components of an EdgeX device service to interact with a specific class of devices.

type ResultType

type ResultType int

ResultType indicates the type of result being passed back from a ProtocolDriver instance.

const (
    // Bool indicates that the result is a bool,
    // stored in CommandResult's boolRes member.
    Bool ResultType = iota
    // String indicates that the result is a string,
    // stored in CommandResult's stringRes member.
    String
    // Uint8 indicates that the result is a uint8 that
    // is stored in CommandResult's NumericRes member.
    Uint8
    // Uint16 indicates that the result is a uint16 that
    // is stored in CommandResult's NumericRes member.
    Uint16
    // Uint32 indicates that the result is a uint32 that
    // is stored in CommandResult's NumericRes member.
    Uint32
    // Uint64 indicates that the result is a uint64 that
    // is stored in CommandResult's NumericRes member.
    Uint64
    // Int8 indicates that the result is a int8 that
    // is stored in CommandResult's NumericRes member.
    Int8
    // Int16 indicates that the result is a int16 that
    // is stored in CommandResult's NumericRes member.
    Int16
    // Int32 indicates that the result is a int32 that
    // is stored in CommandResult's NumericRes member.
    Int32
    // Int64 indicates that the result is a int64 that
    // is stored in CommandResult's NumericRes member.
    Int64
    // Float32 indicates that the result is a float32 that
    // is stored in CommandResult's NumericRes member.
    Float32
    // Float64 indicates that the result is a float64 that
    // is stored in CommandResult's NumericRes member.
    Float64
)

type ScheduleCache

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

ScheduleCache is a local cache of scheduleCache and scheduleevents, usually loaded into Core Metadata, however existing scheduleCache scheduleevents can be used to seed this cache.

func (*ScheduleCache) AddSchedule

func (s *ScheduleCache) AddSchedule(schedule *models.Schedule)

func (*ScheduleCache) AddScheduleEvent

func (s *ScheduleCache) AddScheduleEvent(scheduleEvent *models.ScheduleEvent)

func (*ScheduleCache) GetAllScheduleEvents

func (s *ScheduleCache) GetAllScheduleEvents() *[]models.ScheduleEvent

func (*ScheduleCache) GetAllSchedules

func (s *ScheduleCache) GetAllSchedules() *[]models.Schedule

func (*ScheduleCache) GetScheduleByName

func (s *ScheduleCache) GetScheduleByName(name string) (*models.Schedule, error)

func (*ScheduleCache) GetScheduleEventByName

func (s *ScheduleCache) GetScheduleEventByName(name string) (*models.ScheduleEvent, error)

func (*ScheduleCache) RemoveSchedule

func (s *ScheduleCache) RemoveSchedule(schedule *models.Schedule) error

func (*ScheduleCache) RemoveScheduleEvent

func (s *ScheduleCache) RemoveScheduleEvent(scheduleEvent *models.ScheduleEvent) error

func (*ScheduleCache) UpdateSchedule

func (s *ScheduleCache) UpdateSchedule(schedule *models.Schedule) error

func (*ScheduleCache) UpdateScheduleEvent

func (s *ScheduleCache) UpdateScheduleEvent(scheduleEvent *models.ScheduleEvent) error

type ScheduleCacheInterface

type ScheduleCacheInterface interface {
    GetScheduleByName(name string) (*models.Schedule, error)
    GetAllSchedules() *[]models.Schedule
    AddSchedule(schedule *models.Schedule)
    UpdateSchedule(schedule *models.Schedule) error
    RemoveSchedule(schedule *models.Schedule) error

    GetScheduleEventByName(name string) (*models.ScheduleEvent, error)
    GetAllScheduleEvents() *[]models.ScheduleEvent
    AddScheduleEvent(scheduleEvent *models.ScheduleEvent)
    UpdateScheduleEvent(scheduleEvent *models.ScheduleEvent) error
    RemoveScheduleEvent(scheduleEvent *models.ScheduleEvent) error
}

type ScheduleEventInfo

type ScheduleEventInfo struct {
    // Schedule is the name of the associated schedule.
    Schedule string
    // Path is the endpoint of the DS to be called when the
    // ScheduleEvent is triggered.
    Path string
    // Service is the DS service name.
    Service string
}

ScheduleEventInfo is a struct which contains event schedule specific configuration settings.

type Service

type Service struct {
    Name          string
    Version       string
    Discovery     ProtocolDiscovery
    AsyncReadings bool
    // contains filtered or unexported fields
}

A Service listens for requests and routes them to the right command

func NewService

func NewService(name string, version string, proto ProtocolDriver) (*Service, error)

NewService create a new device service instance with the given name, version and ProtocolDriver, which cannot be nil. Note - this function is a singleton, if called more than once, it will alwayd return an error.

func (*Service) AddDevice

func (s *Service) AddDevice(dev models.Device) (id string, err error)

AddDevice adds a new device to the device service. Returns new device id or non-nil error.

func (*Service) GetDevices

func (s *Service) GetDevices() []models.Device

func (*Service) RemoveDevice

func (s *Service) RemoveDevice(id string) err error 

func (*Service) RemoveDeviceByName

func (s *Service) RemoveDeviceByName(name string) err error 

func (*Service) UpdateDevice

func (s *Service) UpdateDevice(dev models.Device) error 

func (*Service) AddDeviceProfile

func (s *Service) AddDeviceProfile(dev models.Device) (id string, err error)

AddDeviceProfile adds a new device profile to the device service. Returns new DeviceProfile id or non-nil error.

func (*Service) GetDeviceProfiles

func (s *Service) GetDeviceProfiles() []models.DeviceProfile

func (*Service) RemoveDeviceProfile

func (s *Service) RemoveDeviceProfile(id string) err error 

func (*Service) RemoveDeviceProfileByName

func (s *Service) RemoveDeviceProfileByName(name string) err error 

func (*Service) UpdateDeviceProfile

func (s *Service) UpdateDeviceProfile(dev models.DeviceProfile) error 

func (*Service) Start

func (s *Service) Start(useRegistry bool, profile string, confDir string) (err error)

Start the device service. The bool useRegisty indicates whether the registry should be used to read initial configuration settings. This also controls whether the service registers itself the registry. The profile and confDir are used to locate the local TOML configuration file.

func (*Service) Stop

func (s *Service) Stop(force bool) error

Stop shuts down the Service

type ServiceInfo

type ServiceInfo struct {
    // Host is the hostname or IP address of the service.
    Host string
    // Port is the HTTP port of the service.
    Port int
    // ConnectRetries is the number of times the DS will try
    // to connect to Core Metadata to either register itself
    // and provision it's objects, or use existing data. If
    // this limit is exceeded, the DS will exit.
    ConnectRetries int
    // HealthCheck is a URL specifying a healthcheck REST
    // endpoint used by the Registry to determine if the
    // service is available.
    HealthCheck string
    // Labels are...
    Labels []string
    // OpenMsg specifies a string logged on DS startup.
    OpenMsg string
    // ReadMaxLimit specifies the maximum size list supported
    // in response to REST calls to other services.
    ReadMaxLimit int
    // Timeout specifies a timeout (in milliseconds) for
    // processing REST calls from other services.
    Timeout int
}

ServiceInfo is a struct which contains service related configuration settings.

type WatcherInfo

type WatcherInfo struct {
    Profile     string
    Key         string
    MatchString string

WatcherInfo is a struct which contains provisionwatcher configuration settings.

type Watchers

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

Subdirectories

Name Synopsis
..
examples
mock
registry