store

package
v0.0.0-...-b02bee7 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: EPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fetch

func Fetch() *[]FetchedMessage

Returns all messages received since the start of the application

Types

type DeviceManager

type DeviceManager struct {
	GroupID       string             // The group this device belongs to
	NodeID        string             // The node this device belongs to
	DeviceID      string             // The device ID
	Online        bool               // Whether the device is online
	LastMessageAt time.Time          // The last time a message was received regarding this device
	Metrics       map[uint64]*Metric // The metrics of this device (Alias -> Metric)
	// contains filtered or unexported fields
}

Manages the state of a single sparkplug device

func NewDeviceManager

func NewDeviceManager(groupID, nodeID, deviceID string) *DeviceManager

Creates a new DeviceManager for the given device

func (*DeviceManager) Fetch

func (dm *DeviceManager) Fetch() *FetchedDevice

Returns the current state of the device

type FetchedDevice

type FetchedDevice struct {
	ID            string          `json:"id"`            // The device ID
	NodeID        string          `json:"nodeId"`        // The node ID
	GroupID       string          `json:"groupId"`       // The group ID
	Online        bool            `json:"online"`        // Whether the device is online
	LastMessageAt time.Time       `json:"lastMessageAt"` // The last time a message was received regarding this device
	Metrics       []FetchedMetric `json:"metrics"`       // The metrics of this device
}

The data structure returned by the Fetch() method

type FetchedGroup

type FetchedGroup struct {
	ID            string        `json:"id"`            // The group ID
	LastMessageAt time.Time     `json:"lastMessageAt"` // The last time a message was received regarding this group
	Nodes         []FetchedNode `json:"nodes"`         // The state of the nodes in the group
}

The data structure returned by the Fetch() method

type FetchedMessage

type FetchedMessage struct {
	GroupID      string    `json:"groupId"`      // The group ID
	NodeID       string    `json:"nodeId"`       // The node ID
	DeviceID     string    `json:"deviceId"`     // The device ID
	Type         Type      `json:"type"`         // The message type
	MetricAmount int       `json:"metricAmount"` // The amount of metrics in the message
	ReceivedAt   time.Time `json:"receivedAt"`   // The time the message was received
}

The data structure returned by the Fetch() method

type FetchedMetric

type FetchedMetric struct {
	Name      string    `json:"name"`
	Alias     uint64    `json:"alias"`
	Stale     bool      `json:"stale"`
	DataType  string    `json:"dataType"`
	Timestamp time.Time `json:"timestamp"`
	IsNull    bool      `json:"isNull"`
	Value     any       `json:"value"`
}

type FetchedNode

type FetchedNode struct {
	ID            string          `json:"id"`            // The node ID
	GroupID       string          `json:"groupId"`       // The group ID
	Online        bool            `json:"online"`        // Whether the node is online
	LastMessageAt time.Time       `json:"lastMessageAt"` // The last time a message was received regarding this node
	Devices       []FetchedDevice `json:"devices"`       // The state of the devices
	Metrics       []FetchedMetric `json:"metrics"`       // The metrics of this node
}

The data structure returned by the Fetch() method

type GroupManager

type GroupManager struct {
	GroupID       string                  // The group ID
	LastMessageAt time.Time               // The last time a message was received regarding this group
	Nodes         map[string]*NodeManager // The node managers for each node in the group
	// contains filtered or unexported fields
}

Manages the state of a single sparkplug group

func NewGroupManager

func NewGroupManager(groupID string) *GroupManager

Creates a new group manager for the given group ID

func (*GroupManager) Fetch

func (gm *GroupManager) Fetch() *FetchedGroup

Returns the current state of the group and its nodes

type Message

type Message struct {
	ReceivedAt time.Time
	GroupID    string
	NodeID     string
	Type       Type
	DeviceID   string
	Payload    *sparkplugb.Payload
}

Represents a sparkplug message

type Metric

type Metric struct {
	Name          string
	Alias         uint64
	DataType      sparkplugb.DataType
	LastTimeStamp *time.Time
	IsNull        bool
	Value         any
}

func NewMetric

func NewMetric(metric *sparkplugb.Payload_Metric) (*Metric, error)

func (*Metric) Fetch

func (m *Metric) Fetch(isStale bool) *FetchedMetric

func (*Metric) Update

func (m *Metric) Update(metric *sparkplugb.Payload_Metric) error

type NodeManager

type NodeManager struct {
	GroupID       string                    // The group this node belongs to
	NodeID        string                    // The node ID
	Online        bool                      // Whether the node is online
	LastMessageAt time.Time                 // The last time a message was received regarding this node
	Devices       map[string]*DeviceManager // The device managers for each device of this node (DeviceID -> DeviceManager)
	Metrics       map[uint64]*Metric        // The metrics of this node (Alias -> Metric)
	// contains filtered or unexported fields
}

Manages the state of a single sparkplug EoN-Node

func NewNodeManager

func NewNodeManager(groupID, nodeID string) *NodeManager

Creates a new NodeManager for the given node

func (*NodeManager) Fetch

func (nm *NodeManager) Fetch() *FetchedNode

Returns the current state of the node and its devices

type StoreManager

type StoreManager struct {
	Groups map[string]*GroupManager
	// contains filtered or unexported fields
}

func NewStoreManager

func NewStoreManager(msgChan <-chan Message) *StoreManager

func (*StoreManager) Fetch

func (sm *StoreManager) Fetch() *[]FetchedGroup

type Type

type Type string

The sparkplug-B message type for node and device messages

const (
	NodeBirth     Type = "NBIRTH"
	NodeDeath     Type = "NDEATH"
	NodeData      Type = "NDATA"
	NodeCommand   Type = "NCMD"
	DeviceBirth   Type = "DBIRTH"
	DeviceDeath   Type = "DDEATH"
	DeviceData    Type = "DDATA"
	DeviceCommand Type = "DCMD"
)

Jump to

Keyboard shortcuts

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