nodes

package
v0.0.0-...-162ef27 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package nodes with handling of node inputs

Package nodes with node management

Package nodes with updating and publishing of output forecasts

Package nodes with handling of node outputs objects

Package nodes with handling of node output values

Package nodes with management of discovered publishers

Index

Constants

This section is empty.

Variables

View Source
var (
	// UnitValuesAtmosphericPressure unit values for atmospheric pressure
	UnitValuesAtmosphericPressure = fmt.Sprintf("%s, %s, %s", UnitMillibar, UnitMercury, UnitPSI)
	UnitValuesImage               = fmt.Sprintf("%s, %s", UnitJpeg, UnitPng)
	UnitValuesLength              = fmt.Sprintf("%s, %s", UnitMeter, UnitFeet)
	UnitValuesSpeed               = fmt.Sprintf("%s, %s, %s", UnitMetersPerSecond, UnitKmPerHour, UnitMilesPerHour)
	UnitValuesTemperature         = fmt.Sprintf("%s, %s", UnitCelcius, UnitFahrenheit)
	UnitValuesWeight              = fmt.Sprintf("%s, %s", UnitKG, UnitPounds)
	UnitValuesVolume              = fmt.Sprintf("%s, %s", UnitLiter, UnitGallon)
)

Various values for each unit

Functions

func MakeInputDiscoveryAddress

func MakeInputDiscoveryAddress(nodeAddress string, inputType iotc.InputType, instance string) string

MakeInputDiscoveryAddress creates the address for the input discovery

func MakeInputSetAddress

func MakeInputSetAddress(nodeAddress string, ioType string, instance string) string

MakeInputSetAddress creates the address used to update a node input value nodeAddress is an address containing the node.

func MakeNodeAddress

func MakeNodeAddress(domain string, publisherID string, nodeID string, messageType string) string

MakeNodeAddress generates the address of a node: domain/publisherID/nodeID[/messageType].

As per standard, the domain of the domain the node lives in; publisherID of the publisher for this node, unique for the domain; nodeID of the node itself, unique for the publisher; messageType is optional, use "" if it doesn't apply.

func MakeNodeDiscoveryAddress

func MakeNodeDiscoveryAddress(domain string, publisherID string, nodeID string) string

MakeNodeDiscoveryAddress generates the address of a node: domain/publisherID/nodeID/$node. Intended for lookup of nodes in the node list.

func MakeOutputDiscoveryAddress

func MakeOutputDiscoveryAddress(nodeAddress string, outputType iotc.OutputType, instance string) string

MakeOutputDiscoveryAddress for publishing or subscribing nodeAddress is the address containing the node. Any node, input or output address will do

func MakePublisherIdentityAddress

func MakePublisherIdentityAddress(domain string, publisherID string) string

MakePublisherIdentityAddress generates the address of a publisher:

domain/publisherID/$identity

Intended for lookup of nodes in the node list. domain of the domain the node lives in. publisherID of the publisher for this node, unique for the domain

func NewInput

func NewInput(nodeAddr string, inputType iotc.InputType, instance string) *iotc.InputDiscoveryMessage

NewInput instance To add it to the inputlist use 'UpdateInput'

func NewNode

func NewNode(domain string, publisherID string, nodeID string, nodeType iotc.NodeType) *iotc.NodeDiscoveryMessage

NewNode returns a new instance of a node. This node will have default configurations for name and alias.

func NewNodeConfig

func NewNodeConfig(dataType iotc.DataType, description string, defaultValue string) *iotc.ConfigAttr

NewNodeConfig creates a new node configuration instance. Intended for updating additional attributes before updating the actual configuration Use UpdateNodeConfig to update the node with this configuration

dataType of the value. See also iotc.DataType for standard types. description of the value for humans defaultValue to use as default configuration value returns a new Configuration Attribute instance.

func NewOutput

func NewOutput(nodeAddress string, outputType iotc.OutputType, instance string) *iotc.OutputDiscoveryMessage

NewOutput creates a new output for the given node. It is not immediately added to allow for further updates of the ouput definition. To add it to the list use 'UpdateOutput' node is the node that contains the output outputType is one of the predefined output types. See constants in the standard instance is the output instance in case of multiple instances of the same type. Use

Types

type InputList

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

InputList with input management

func NewInputList

func NewInputList() *InputList

NewInputList creates a new instance for input management

func (*InputList) GetAllInputs

func (inputs *InputList) GetAllInputs() []*iotc.InputDiscoveryMessage

GetAllInputs returns the list of inputs

func (*InputList) GetInput

func (inputs *InputList) GetInput(
	nodeAddress string, inputType iotc.InputType, instance string) *iotc.InputDiscoveryMessage

GetInput returns the input of one of this publisher's nodes Returns nil if address has no known input address with node type and instance. The command will be ignored.

func (*InputList) GetInputByAddress

func (inputs *InputList) GetInputByAddress(inputAddr string) *iotc.InputDiscoveryMessage

GetInputByAddress returns an input by its address inputAddr must contain the full input address, eg <zone>/<publisher>/<node>/"$input"/<type>/<instance> Returns nil if address has no known input This method is concurrent safe

func (*InputList) GetUpdatedInputs

func (inputs *InputList) GetUpdatedInputs(clearUpdates bool) []*iotc.InputDiscoveryMessage

GetUpdatedInputs returns the list of discovered inputs that have been updated clear the update on return

func (*InputList) UpdateInput

func (inputs *InputList) UpdateInput(input *iotc.InputDiscoveryMessage)

UpdateInput replaces the input using the node.Address This method is concurrent safe

type NodeList

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

NodeList for concurrency safe node management using Copy on Write.

To serialize the node list use GetAllNodes and UpdateNodes

Nodes are immutable. Any modifications made are applied to a new instance. The old node instance is discarded and replaced with the new instance. To make changes to a node directly, always Clone the node first and use UpdateNode to apply the change.

func NewNodeList

func NewNodeList() *NodeList

NewNodeList creates a new instance for node management.

func (*NodeList) Clone

Clone returns a copy of the node with new Attr, Config and Status maps Intended for updating the node in a concurrent safe manner in combination with UpdateNode() This does clones map values. Any updates to the map must use new instances of the values

func (*NodeList) GetAllNodes

func (nodes *NodeList) GetAllNodes() []*iotc.NodeDiscoveryMessage

GetAllNodes returns a list of nodes

func (*NodeList) GetNodeAttr

func (nodes *NodeList) GetNodeAttr(address string, attrName iotc.NodeAttr) string

GetNodeAttr returns a node attribute value

func (*NodeList) GetNodeByAddress

func (nodes *NodeList) GetNodeByAddress(address string) *iotc.NodeDiscoveryMessage

GetNodeByAddress returns a node by its node address using the domain, publisherID and nodeID address must contain the domain, publisherID and nodeID. Any other fields are ignored. Returns nil if address has no known node

func (*NodeList) GetNodeByID

func (nodes *NodeList) GetNodeByID(domain string, publisherID string, nodeID string) *iotc.NodeDiscoveryMessage

GetNodeByID returns a node by its domain, publisher and node ID Returns nil if address has no known node

func (*NodeList) GetNodeConfigBool

func (nodes *NodeList) GetNodeConfigBool(
	address string, attrName iotc.NodeAttr, defaultValue bool) (value bool, err error)

GetNodeConfigBool returns the node configuration value as a boolean address starts with the node's address This retuns the provided default value if no value is set or no default is configured, or the value is not an integer An error is returned when the node or configuration doesn't exist

func (*NodeList) GetNodeConfigFloat

func (nodes *NodeList) GetNodeConfigFloat(
	address string, attrName iotc.NodeAttr, defaultValue float32) (value float32, err error)

GetNodeConfigFloat returns the node configuration value as an floating point number address starts with the node's address This retuns the provided default value if no value is set or no default is configured, or the value is not an integer An error is returned when the node or configuration doesn't exist or is not an integer

func (*NodeList) GetNodeConfigInt

func (nodes *NodeList) GetNodeConfigInt(
	address string, attrName iotc.NodeAttr, defaultValue int) (value int, err error)

GetNodeConfigInt returns the node configuration value as an integer address starts with the node's address This retuns the provided default value if no value is set or no default is configured, or the value is not an integer An error is returned when the node or configuration doesn't exist or is not an integer

func (*NodeList) GetNodeConfigString

func (nodes *NodeList) GetNodeConfigString(
	address string, attrName iotc.NodeAttr, defaultValue string) (value string, err error)

GetNodeConfigString returns the attribute value of a node in this list address must starts with the node's address: domain/publisher/nodeid. Any suffix is ignored. This retuns the provided default value if no value is set and no default is configured. An error is returned when the node or configuration doesn't exist.

func (*NodeList) GetUpdatedNodes

func (nodes *NodeList) GetUpdatedNodes(clearUpdates bool) []*iotc.NodeDiscoveryMessage

GetUpdatedNodes returns the list of nodes that have been updated clearUpdates clears the list of updates. Intended for publishing only updated nodes.

func (*NodeList) NewNode

func (nodes *NodeList) NewNode(domain string, publisherID string, nodeID string, nodeType iotc.NodeType) string

NewNode creates a node instance and adds it to the list. If the node exists it will remain unchanged This returns the node discovery address

func (*NodeList) NewNodeConfig

func (nodes *NodeList) NewNodeConfig(nodeAddr string, attrName iotc.NodeAttr, dataType iotc.DataType, description string, defaultValue string) *iotc.ConfigAttr

NewNodeConfig creates a new node configuration instance and adds it to the node. If the configuration already exists, its dataType, description and defaultValue are updated nodeAddr is the address of the node to update attrName is the configuration attribute name. See also iotc.NodeAttr for standard IDs dataType of the value. See also iotc.DataType for standard types. description of the value for humans defaultValue to use as default configuration value returns a new Configuration Attribute instance.

func (*NodeList) SetErrorStatus

func (nodes *NodeList) SetErrorStatus(address string, runState string, errorMsg string) (changed bool)

SetErrorStatus sets the node RunState to the given status with a lasterror message Use NodeRunStateError for errors and NodeRunStateReady to clear error This only updates the node if the status or lastError message changes

func (*NodeList) SetNodeAttr

func (nodes *NodeList) SetNodeAttr(address string, attrParams map[iotc.NodeAttr]string) (changed bool)

SetNodeAttr updates node's attributes and publishes the updated node. Node is marked as modified for publication only if one of the attrParams has changes

Use when additional node attributes has been discovered.

address of the node to update
param is the map with key-value pairs of attribute values to update

returns true when node has changed, false if node doesn't exist or attributes haven't changed

func (*NodeList) SetNodeConfigValues

func (nodes *NodeList) SetNodeConfigValues(address string, params map[iotc.NodeAttr]string) (changed bool)

SetNodeConfigValues applies an update to a node's existing configuration. Nodes are immutable. If one or more configuration values have changed then a new node is created and published and the old node instance is discarded.

address is the node discovery address
param is the map with key-value pairs of configuration values to update

returns true if configuration changes, false if configuration doesn't exist

func (*NodeList) SetNodeStatus

func (nodes *NodeList) SetNodeStatus(address string, statusAttr map[iotc.NodeStatus]string) (changed bool)

SetNodeStatus updates one or more node's status attributes. Nodes are immutable. If one or more status values have changed then a new node is created and published. The old node instance is discarded.

address of the node to update
statusAttr is the map with key-value pairs of updated node statusses

func (*NodeList) UpdateNode

func (nodes *NodeList) UpdateNode(node *iotc.NodeDiscoveryMessage)

UpdateNode replaces a node or adds a new node based on node.Address.

Intended to support Node immutability by making changes to a copy of a node and replacing the existing node with the updated node The updated node will be published

func (*NodeList) UpdateNodeConfig

func (nodes *NodeList) UpdateNodeConfig(address string, attrName iotc.NodeAttr, configAttr *iotc.ConfigAttr)

UpdateNodeConfig updates a node's configuration and publishes the updated node.

If a config already exists then its value is retained but its configuration parameters are replaced. Nodes are immutable. A new node is created and published and the old node instance is discarded.

func (*NodeList) UpdateNodes

func (nodes *NodeList) UpdateNodes(updates []*iotc.NodeDiscoveryMessage)

UpdateNodes updates a list of nodes.

Intended to update the list with nodes from persistent storage

type OutputForecast

type OutputForecast []iotc.OutputValue

OutputForecast with forecasted values

type OutputForecastList

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

OutputForecastList with management of forecasts for outputs A forecast is a list of timestamps with projected values

func NewOutputForecastList

func NewOutputForecastList() *OutputForecastList

NewOutputForecastList creates a new instance of a forecast list

func (*OutputForecastList) GetForecast

func (forecastList *OutputForecastList) GetForecast(outputAddress string) OutputForecast

GetForecast returns the output's forecast by output address outputAddress is the discovery address of the output Returns nil if the type or instance is unknown or no forecast is available

func (*OutputForecastList) GetUpdatedForecasts

func (forecastList *OutputForecastList) GetUpdatedForecasts(clearUpdates bool) []string

GetUpdatedForecasts returns a list of output addresses that have updated forecasts clearUpdates clears the update list on return

func (*OutputForecastList) UpdateForecast

func (forecastList *OutputForecastList) UpdateForecast(
	nodeAddress string, outputType iotc.OutputType, instance string, forecast OutputForecast)

UpdateForecast publishes the output forecast list of values outputAddress is the discovery address of the output

type OutputHistory

type OutputHistory []iotc.OutputValue

OutputHistory with history values

type OutputList

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

OutputList with output management

func NewOutputList

func NewOutputList() *OutputList

NewOutputList creates a new instance for output management

func (*OutputList) GetAllOutputs

func (outputs *OutputList) GetAllOutputs() []*iotc.OutputDiscoveryMessage

GetAllOutputs returns the list of outputs

func (*OutputList) GetNodeOutputs

func (outputs *OutputList) GetNodeOutputs(node *iotc.NodeDiscoveryMessage) []*iotc.OutputDiscoveryMessage

GetNodeOutputs returns all outputs for the given node in this list This method is concurrent safe

func (*OutputList) GetOutput

func (outputs *OutputList) GetOutput(
	nodeAddress string, outputType iotc.OutputType, instance string) *iotc.OutputDiscoveryMessage

GetOutput returns the output of one of this publisher's nodes This method is concurrent safe Returns nil if address has no known output

func (*OutputList) GetOutputByAddress

func (outputs *OutputList) GetOutputByAddress(outputAddr string) *iotc.OutputDiscoveryMessage

GetOutputByAddress returns an output by its address outputAddr must contain the full output address, eg <zone>/<publisher>/<node>/"$output"/<type>/<instance> Returns nil if address has no known output This method is concurrent safe

func (*OutputList) GetUpdatedOutputs

func (outputs *OutputList) GetUpdatedOutputs(clearUpdates bool) []*iotc.OutputDiscoveryMessage

GetUpdatedOutputs returns the list of discovered outputs that have been updated clear the update on return

func (*OutputList) UpdateOutput

func (outputs *OutputList) UpdateOutput(output *iotc.OutputDiscoveryMessage)

UpdateOutput replaces the output The output will be added to the list of updated outputs

type OutputValueList

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

OutputValueList with output values for all outputs

func NewOutputValueList

func NewOutputValueList() *OutputValueList

NewOutputValueList creates a new instance for output value and history management

func (*OutputValueList) GetHistory

func (outputValues *OutputValueList) GetHistory(address string) OutputHistory

GetHistory returns the history list Returns nil if the type or instance is unknown

func (*OutputValueList) GetOutputValueByAddress

func (outputValues *OutputValueList) GetOutputValueByAddress(address string) *iotc.OutputValue

GetOutputValueByAddress returns the most recent output value by output discovery address This returns a HistoryValue object with the latest value and timestamp it was updated

func (*OutputValueList) GetOutputValueByType

func (outputValues *OutputValueList) GetOutputValueByType(
	node *iotc.NodeDiscoveryMessage, outputType iotc.OutputType, instance string) *iotc.OutputValue

GetOutputValueByType returns the current output value by output type and instance

func (*OutputValueList) GetUpdatedOutputs

func (outputValues *OutputValueList) GetUpdatedOutputs(clearUpdates bool) []string

GetUpdatedOutputs returns a list of output discovery addresses that have updated values clear the update outputs list on return

func (*OutputValueList) UpdateOutputFloatList

func (outputValues *OutputValueList) UpdateOutputFloatList(address string, values []float32) bool

UpdateOutputFloatList adds a list of floats as the output value in the format: "[value1, value2, ...]"

func (*OutputValueList) UpdateOutputIntList

func (outputValues *OutputValueList) UpdateOutputIntList(address string, values []int) bool

UpdateOutputIntList adds a list of integers as the output value in the format: "[value1, value2, ...]"

func (*OutputValueList) UpdateOutputStringList

func (outputValues *OutputValueList) UpdateOutputStringList(address string, values []string) bool

UpdateOutputStringList adds a list of strings as the output value in the format: "[value1, value2, ...]"

func (*OutputValueList) UpdateOutputValue

func (outputValues *OutputValueList) UpdateOutputValue(address string, newValue string) bool

UpdateOutputValue adds the new node output value to the front of the history If the node has a repeatDelay configured, then the value is only added if

it has changed, or if the previous update was older than the repeatDelay.

The history retains a max of 24 hours returns true if history is updated, false if history has not been updated

type PublisherList

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

PublisherList with discovered and verified publishers

func NewPublisherList

func NewPublisherList() *PublisherList

NewPublisherList creates a new list of discovered publishers

func (*PublisherList) GetAllPublishers

func (pubList *PublisherList) GetAllPublishers() []*iotc.PublisherIdentityMessage

GetAllPublishers returns a list of discovered publishers

func (*PublisherList) GetDSSIdentity

func (pubList *PublisherList) GetDSSIdentity(domain string) *iotc.PublisherPublicIdentity

GetDSSIdentity returns the Domain Security Service publisher identity Returns nil if no DSS was received

func (*PublisherList) GetPublisherByAddress

func (pubList *PublisherList) GetPublisherByAddress(address string) *iotc.PublisherIdentityMessage

GetPublisherByAddress returns a publisher Identity by its identity discovery address Returns nil if address has no known node

func (*PublisherList) GetPublisherKey

func (pubList *PublisherList) GetPublisherKey(publisherAddress string) *ecdsa.PublicKey

GetPublisherKey returns the public key of a publisher for signature verification or encryption publisherAddress starts with domain/publisherId returns public key or nil if publisher public key is not found

func (*PublisherList) UpdatePublisher

func (pubList *PublisherList) UpdatePublisher(pub *iotc.PublisherIdentityMessage)

UpdatePublisher replaces a publisher identity Intended for use within a locked section

type Unit

type Unit string

Unit constants with unit names. These are defined with the sensor type

const (
	UnitNone            Unit = ""
	UnitAmp             Unit = "A"
	UnitCelcius         Unit = "C"
	UnitCandela         Unit = "cd"
	UnitCount           Unit = "#"
	UnitDegree          Unit = "Degree"
	UnitFahrenheit      Unit = "F"
	UnitFeet            Unit = "ft"
	UnitGallon          Unit = "Gal"
	UnitJpeg            Unit = "jpeg"
	UnitKelvin          Unit = "K"
	UnitKmPerHour       Unit = "Kph"
	UnitLiter           Unit = "L"
	UnitMercury         Unit = "hg"
	UnitMeter           Unit = "m"
	UnitMetersPerSecond Unit = "m/s"
	UnitMilesPerHour    Unit = "mph"
	UnitMillibar        Unit = "mbar"
	UnitMole            Unit = "mol"
	UnitPartsPerMillion Unit = "ppm"
	UnitPng             Unit = "png"
	UnitKWH             Unit = "KWh"
	UnitKG              Unit = "kg"
	UnitLux             Unit = "lux"
	UnitPascal          Unit = "Pa"
	UnitPercent         Unit = "%"
	UnitPounds          Unit = "lbs"
	UnitSpeed           Unit = "m/s"
	UnitPSI             Unit = "psi"
	UnitSecond          Unit = "s "
	UnitVolt            Unit = "V"
	UnitWatt            Unit = "W"
)

Unit name constants following ISO standard naming

Jump to

Keyboard shortcuts

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