assets2036go

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatTimestamp

func FormatTimestamp(ts time.Time) string

FormatTimestamp return a standard conform string representation of the given timestamp

func GetJSON

func GetJSON(url string) (string, error)

func StringList

func StringList(topics []Topic) string

StringList returns simetins

func SwitchOnLogging added in v0.3.3

func SwitchOnLogging(on bool)

SwitchOnLogging switches on or off logging for the assets2036 lib

Types

type Asset

type Asset struct {
	Submodels map[string]*Submodel
	Namespace string
	Name      string
	// contains filtered or unexported fields
}

Asset is a base struct for AssetProxy and Asset

func (*Asset) Submodel

func (asset *Asset) Submodel(name string) *Submodel

Submodel returns the Submodel with the given name if existing, otherwise nil

type AssetMgr

type AssetMgr struct {
	Host                  string
	Port                  uint16
	EndpointName          string
	DefaultNamespace      string
	EndpointAsset         *Asset
	ExitWhenConnObsvFails bool
	ConnObsvTimeout       time.Duration
	// contains filtered or unexported fields
}

The AssetMgr is the basic access point to the assets2036go library. Use it to create assets and assetproxys for your assets environment

func CreateAssetMgr

func CreateAssetMgr(host string, port uint16, defaultNamespace, endpointName string, observeConnection bool) (*AssetMgr, error)

CreateAssetMgr creates an instance of AssetMgr and trys to connect it to the given MQTT Server on host:port.

func (*AssetMgr) AddSubmodelObserver

func (mgr *AssetMgr) AddSubmodelObserver(submodelName string, handler func(namespace, name, submodelName string))

AddSubmodelObserver lets you add a callback method which will inbform you, if some new asset supporting the given submodelURL is created

func (*AssetMgr) CloseConnections

func (mgr *AssetMgr) CloseConnections()

CloseConnections kjh

func (*AssetMgr) CreateAsset

func (mgr *AssetMgr) CreateAsset(namespace, name string, submodelUrls ...string) (*Asset, error)

CreateAsset creates an asset which is implemented on this host. If you want to _use_ an existing asset, use CreateAssetProxy because in that case a proxy is what you want.

func (*AssetMgr) CreateAssetProxy

func (mgr *AssetMgr) CreateAssetProxy(namespace, name string, submodelUrls ...string) (*Asset, error)

CreateAssetProxy creates a local proxy to a remotely managed asset to make use of its properties, operations and events without bothering about where it is implemented

func (*AssetMgr) CreateFullAssetProxy

func (mgr *AssetMgr) CreateFullAssetProxy(namespace, name string, waitForSubmodels time.Duration) (asset *Asset, err error)

CreateFullAssetProxy create a proxy only if the asset it is existing already. All submodels are directly read from MQTT

func (*AssetMgr) FindAllEndpointAssets

func (mgr *AssetMgr) FindAllEndpointAssets() (assetNames []Topic, err error)

FindAllEndpointAssets returns ...

func (*AssetMgr) FindAssetsBySubmodelName

func (mgr *AssetMgr) FindAssetsBySubmodelName(submodelName string) (assetNames []Topic, err error)

FindAssetsBySubmodelName returns a slice of strings containing all those assets in the given namespace supporting the subbmodel as defined in subodelName parameter submodelURL

func (*AssetMgr) FindAssetsBySubmodelURL

func (mgr *AssetMgr) FindAssetsBySubmodelURL(submodelURL string) (assetNames []Topic, err error)

FindAssetsBySubmodelURL returns ...

func (*AssetMgr) FindAssetsInNamespace

func (mgr *AssetMgr) FindAssetsInNamespace(namespace string) (assetNames []Topic, err error)

FindAssetsInNamespace returns ...

func (*AssetMgr) GetEndpoint

func (mgr *AssetMgr) GetEndpoint() *Submodel

GetEndpoint return the submodel _endpoint of the automatically created endpoint asset

func (*AssetMgr) GetSubmodelURLs

func (mgr *AssetMgr) GetSubmodelURLs(assetNamespace, assetName string, waitForSubmodels time.Duration) []string

GetSubmodelURLs returns the urls of all submodels supported by given asset

func (*AssetMgr) RemoveTraces

func (mgr *AssetMgr) RemoveTraces(namespace, name string)

RemoveTraces removes all traces (i.e. retained messages) of the given asset from the broker

func (*AssetMgr) SetHealthyCallback

func (mgr *AssetMgr) SetHealthyCallback(cb func() bool)

SetHealthyCallback lets you set a callback function to get some custom healthy information. This healthy infvormation will be publish in the AssetMgr's endpoint asset's submodel _endpoint.

func (*AssetMgr) SetShutdownCallback

func (mgr *AssetMgr) SetShutdownCallback(cb func())

SetShutdownCallback lets you set your local method when your assetmgrendpoint is forced to shutdown

type EventHandler

type EventHandler func(timestamp time.Time, params map[string]interface{})

EventHandler is the callback type for an event

type HandlePropertyModified

type HandlePropertyModified func(sp *SubmodelProperty, newValue interface{})

HandlePropertyModified is the callback type to get informed when the property value changes

type JSONObj

type JSONObj map[string]interface{}

JSONObj is just an alias for the typical JSON obj representation map[string]interface{}

type Submodel

type Submodel struct {
	Operations map[string]*SubmodelOperation `json:"operations"`
	Properties map[string]*SubmodelProperty  `json:"properties"`
	Events     map[string]*SubmodelEvent     `json:"events"`
	Name       string                        `json:"name"`
	Revision   string                        `json:"rev"`
	// contains filtered or unexported fields
}

Submodel is the basis for all submodel instances. It holds the submodel's #Operations, #Properties and #Events. The struct is used for the deserialization of the JSON submodel descriptions from the submodel repository as well as for accessing the submodel elements at runtime.

func (*Submodel) Event

func (sm *Submodel) Event(name string) *SubmodelEvent

Event returns the SubmodelEvent named name of submodel or nil, if no event with given name exists

func (*Submodel) Operation

func (sm *Submodel) Operation(name string) *SubmodelOperation

Operation returns the SubmodelOperation named name of submodel or nil, if no operation with given name exists

func (*Submodel) Property

func (sm *Submodel) Property(name string) *SubmodelProperty

Property returns the SubmodelProperty named name of submodel or nil, if no property with given name exists

type SubmodelEvent

type SubmodelEvent struct {
	Parameters map[string]interface{} `json:"parameters"`
	Handler    EventHandler           `json:"-"`
	// contains filtered or unexported fields
}

SubmodelEvent encapsulates the event type submodel element. Struct is used for json deserialization and for runtime access.

func (*SubmodelEvent) Emit

func (ev *SubmodelEvent) Emit(params map[string]interface{})

Emit emits this event and thereby can be received by all subscribes consumers

func (*SubmodelEvent) Name

func (ev *SubmodelEvent) Name() string

Name returns name of the corresponding event

type SubmodelOperation

type SubmodelOperation struct {
	Parameters map[string]interface{}    `json:"parameters"`
	Response   map[string]interface{}    `json:"response"`
	Callback   SubmodelOperationCallback `json:"-"`
	// contains filtered or unexported fields
}

SubmodelOperation encapsulates submodel operations. The struct is used for runtime access as well as for json deserialization from the submodel description from the submodel repository. To implement a submodel operation on an asset, set the #Callback member to a local function. To call a remotely implemented operation, call the #Invoke or #InvokeTimeout.

func (*SubmodelOperation) Invoke

func (op *SubmodelOperation) Invoke(parameters map[string]interface{}) (interface{}, error)

Invoke runs calls the remote operation on the remote asset andn returns the remotely computed return values in the form of a map[string]interface{} If within default #timeout of 2s no answer is received, method return an error.

func (*SubmodelOperation) InvokeTimeout

func (op *SubmodelOperation) InvokeTimeout(parameters map[string]interface{}, timeout time.Duration) (interface{}, error)

InvokeTimeout runs calls the remote operation on the remote asset and returns the remotely computed return values in the form of a map[string]interface{} If within #timeout no answer is received, method return an error.

func (*SubmodelOperation) Name

func (op *SubmodelOperation) Name() string

Name returns the name of the corresponding submodeloperation

type SubmodelOperationCallback

type SubmodelOperationCallback func(req *SubmodelOperationRequest) (resp interface{}, err error)

SubmodelOperationCallback is the signature of all functions, which can be used as callbacks in an asset implementation

type SubmodelOperationRequest

type SubmodelOperationRequest struct {
	RequestID         string                 `json:"req_id"`
	Parameters        map[string]interface{} `json:"params"`
	SubmodelOperation *SubmodelOperation
}

SubmodelOperationRequest encapsulates the call to a remote submodel operation. It is used for deserialization of the transferred message and in the callback methods implementing the submodel operation. It mainly carries the request #Parameters.

type SubmodelProperty

type SubmodelProperty struct {
	Type string `json:"type"`
	// contains filtered or unexported fields
}

SubmodelProperty encapsulates a submodel's property. To set the property's value on a locally implemented submodel, use #SetValue. To read the property's value of a remotely implemented sumodel, use #Value() or #AddModifiedListener to add a listener which will be called in the case of a remote property value modification.

func (*SubmodelProperty) AddModifiedListener

func (sp *SubmodelProperty) AddModifiedListener(listener HandlePropertyModified)

AddModifiedListener lets you add a listener, whichh will be informed, when the remotely implemented property has modified value.

func (*SubmodelProperty) Name

func (sp *SubmodelProperty) Name() string

Name returns the name of the corresponding submodeloperation

func (*SubmodelProperty) SetValue

func (sp *SubmodelProperty) SetValue(value interface{}) error

SetValue sets the value and publishes it to all remote consumers.

func (*SubmodelProperty) Value

func (sp *SubmodelProperty) Value() interface{}

Value returns the current value of this Property Element

type Topic

type Topic []string

Topic is an assets2036 mqtt topic

func TopicFromElements

func TopicFromElements(elements ...string) Topic

TopicFromElements does stuff

func TopicFromStr

func TopicFromStr(str string) Topic

TopicFromStr create a new topic object

func (Topic) Asset

func (topic Topic) Asset() string

Asset kjasdkajs

func (Topic) AssetAbs

func (topic Topic) AssetAbs() string

AssetAbs kjasdkajs

func (Topic) Namespace

func (topic Topic) Namespace() string

Namespace kjasdkajs

func (Topic) String

func (topic Topic) String() string

func (Topic) Submodel

func (topic Topic) Submodel() string

Submodel asdas

func (Topic) SubmodelElement

func (topic Topic) SubmodelElement() string

SubmodelElement ad asf

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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