deviceCore

package
v0.0.0-...-12a24cc Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsumeFromDeviceSource

func ConsumeFromDeviceSource(dm DeviceMessage) error

ConsumeFromDeviceSource Handles incoming channel DM message -- Called directly from deviceSources

func Start

func Start(dfg cc.Config, sp DeviceEventProvider, sscp SchedulerProvider, repo Repository, discoveredNetworks []string) (CoreService, *SiteNetworks)

* Start() * * Initialize this service

func Stop

func Stop()

* Stop * Cleans up this service

func TopicsFromDevice

func TopicsFromDevice(dv Device) []string

TopicsFromDevice() decode device into topics -/D/A/P/P -/D/A/P -/D/A -/D/N/P/A -/D/N/P -/D/N/A

Types

type Broadcast

type Broadcast struct {
	ID          string
	ElementType CoreType
	Parent      string
	Topic       string
	Level       string
	Value       string
	Received    time.Time
}

Broadcast Alert Messages on Network

func NewBroadcast

func NewBroadcast(parent, topic, level, value string) Broadcast

NewBroadcast Creates Component

type CoreService

type CoreService interface {
	AllNetworks() SiteNetworks
	PrivateSiteNetworks() *SiteNetworks
	NetworkDevices(networkName string) (map[string]Device, error)
	NetworkByName(networkName string) Network
	DeviceByName(deviceName, networkName string) (Device, error)
	DeviceByID(deviceID string, networkName string) (Device, error)
	RemoveDeviceByID(deviceID string, networkName string) error

	PublishNetworkMessage(dm DeviceMessage)

	AllSchedules() []Schedule
	CreateSchedule(networkName string, deviceID string, transport OTATransport, firmwareID EID) (string, error)
	RemoveSchedule(scheduleID string) error
	ScheduleByID(scheduleID string) Schedule
	ScheduleByDeviceID(deviceID string) *Schedule

	AllFirmwares() []Firmware
	CreateFirmware(srcFile, dstFile string) (EID, error)
	RemoveFirmwareByID(firmwareID EID)
	FirmwareByID(firmwareID EID) (Firmware, error)
	FirmwareByName(firmwareName string) (Firmware, error)

	AllBroadcasts() []Broadcast
	RemoveBroadcastByID(broadcastID string)
	BroadcastByID(broadcastID string) (Broadcast, error)
}

* Interactions with UI

func NewCoreService

func NewCoreService(dfg cc.Config, sp DeviceEventProvider, sscp SchedulerProvider, repo Repository) CoreService

*

  • NewCoreService() *
  • Create a New NewCoreService and initializes it.

type CoreType

type CoreType int

Globals required for DeviceMessage Types

const (
	CoreTypeDevice CoreType = (iota + 10)
	CoreTypeDeviceAttribute
	CoreTypeDeviceAttributeProperty
	CoreTypeDeviceAttributePropertyProperty
	CoreTypeDeviceNode
	CoreTypeDeviceNodeAttribute
	CoreTypeDeviceNodeProperty
	CoreTypeDeviceNodePropertyAttribute
	CoreTypeDeviceDelete
	CoreTypePublishMessage
	CoreTypeBroadcast
	CoreTypeFirmware
	CoreTypeSchedule
	CoreTypeNetwork
	CoreTypeSiteNetworks
)

CoreType Basic object types

type Device

type Device struct {
	ID          string
	Title       string
	ElementType CoreType
	OTAEnabled  bool
	Parent      string
	Name        string
	Attrs       map[string]DeviceAttribute
	Nodes       map[string]DeviceNode
}

Device represent a physical device

func NewDevice

func NewDevice(parent, name string) Device

NewDevice Creates Component read $implementation/ota/enabled -> bool and set the OTAEnabled for Schedules

type DeviceAttribute

type DeviceAttribute struct {
	ID          EID
	ElementType CoreType
	Parent      string
	Name        string
	Value       string
	Props       map[string]DeviceAttributeProperty
}

DeviceAttribute of a Device allowing sub properties, representing a single value or measurement

func NewDeviceAttribute

func NewDeviceAttribute(parent, name, value string) DeviceAttribute

NewDeviceAttribute Creates Component

type DeviceAttributeProperty

type DeviceAttributeProperty struct {
	ID          EID
	ElementType CoreType
	Parent      string
	Name        string
	Value       string
	Props       map[string]DeviceAttributePropertyProperty
}

DeviceAttributeProperty of a Device Attribute, representing a single value or measurement $implementation/ota/status -- where status will be a regular attribute

func NewDeviceAttributeProperty

func NewDeviceAttributeProperty(parent, name, value string) DeviceAttributeProperty

NewDeviceAttributeProperty Creates Component of a Device Attribute, representing a single value or measurement $implementation/fw -- where status will be a regular attribute

$DeviceAttr / Property

type DeviceAttributePropertyProperty

type DeviceAttributePropertyProperty struct {
	ID          EID
	ElementType CoreType
	Parent      string
	Name        string
	Value       string
}

DeviceAttributePropertyProperty of a Device Attribute, representing a single value or measurement $implementation/ota/status -- where status will be a regular attribute

func NewDeviceAttributePropertyProperty

func NewDeviceAttributePropertyProperty(parent, name, value string) DeviceAttributePropertyProperty

NewDeviceAttributePropertyProperty Creates Component of a Device Attribute, representing a single value or measurement $implementation/fw/version -- where status will be a regular attribute

$DeviceAttr / Property / Property

type DeviceEventIntf

type DeviceEventIntf interface {
	String() string
	Schedulable() bool
	Settable() bool
	OTAPublishMessage() bool
	OTAStatus() bool
	OTAActive() bool
	OTACurrent() bool
	OTARejected() bool
	OTAAborted() bool
	OTAFlashError() bool
	OTAFirmwareError() bool
	OTAComplete() bool
	Broadcast() bool
	Parts() []string
	PartsLen() int
}

* Device Management Methods

type DeviceEventProvider

type DeviceEventProvider interface {
	ActivateStreamProvider()
	ApplyDeviceEvent(dm DeviceMessage)
	PublishToStreamProvider(dm DeviceMessage)
	ConsumeDeviceStream(dm DeviceMessage) error
}

* Interactions with DeviceSource

type DeviceMessage

type DeviceMessage struct {
	ID          uint16
	HomieType   CoreType
	OTATrigger  bool
	RetainedB   bool
	Qosb        byte
	NetworkID   []byte
	DeviceID    []byte
	NodeID      []byte
	PropertyID  []byte
	PPropertyID []byte
	AttributeID []byte
	TopicS      string
	Value       []byte
}

* DeviceMessage * Transposed MQTT Message for Internal Use

func NewDeviceMessage

func NewDeviceMessage(topic string, payload []byte, idCounter uint16, retained bool, qos byte, plog log.Logger) (DeviceMessage, error)

NewDeviceMessage()

  • Create a New DeviceMessage and initializes it.
  • Called outside of the service

func NewQueueMessage

func NewQueueMessage(msg QueueMessage, plog log.Logger) (DeviceMessage, error)

NewEventMessage()

  • Create a New DeviceMessage and initializes it.
  • Called outside of the service

func (DeviceMessage) Ack

func (dm DeviceMessage) Ack()

func (*DeviceMessage) Broadcast

func (dm *DeviceMessage) Broadcast() bool

Broadcast() determines if this is a Homie Broadcast message

func (DeviceMessage) Duplicate

func (dm DeviceMessage) Duplicate() bool

func (DeviceMessage) MessageID

func (dm DeviceMessage) MessageID() uint16

func (*DeviceMessage) OTAAborted

func (dm *DeviceMessage) OTAAborted() bool

OTAAborted() determines if device is downloading firmware

func (*DeviceMessage) OTAActive

func (dm *DeviceMessage) OTAActive() bool

OTAactive() determines if device is downloading firmware

func (*DeviceMessage) OTAComplete

func (dm *DeviceMessage) OTAComplete() bool

OTAComplete determines if device has accepted new firmware Filtered on create of event message, use Topic to bypass Filtering

func (*DeviceMessage) OTACurrent

func (dm *DeviceMessage) OTACurrent() bool

OTACurrent() determines if device is downloading firmware

func (*DeviceMessage) OTAFirmwareError

func (dm *DeviceMessage) OTAFirmwareError() bool

func (*DeviceMessage) OTAFlashError

func (dm *DeviceMessage) OTAFlashError() bool

func (*DeviceMessage) OTAPublishMessage

func (dm *DeviceMessage) OTAPublishMessage() bool

OTAactive() determines if device is downloading firmware

func (*DeviceMessage) OTARejected

func (dm *DeviceMessage) OTARejected() bool

OTARejected() determines if device is downloading firmware

func (*DeviceMessage) OTAStatus

func (dm *DeviceMessage) OTAStatus() bool

OTAStatus() determines if device is downloading firmware

func (*DeviceMessage) Parts

func (dm *DeviceMessage) Parts() []string

Parts() returns the individual parts of the original MQTT message

func (*DeviceMessage) PartsLen

func (dm *DeviceMessage) PartsLen() int

PartsLen() returns number of parts in Topic

func (DeviceMessage) Payload

func (dm DeviceMessage) Payload() []byte

func (DeviceMessage) Qos

func (dm DeviceMessage) Qos() byte

func (DeviceMessage) Retained

func (dm DeviceMessage) Retained() bool

func (*DeviceMessage) Schedulable

func (dm *DeviceMessage) Schedulable() bool

Schedulable() also -- $stats/uptime

func (*DeviceMessage) Settable

func (dm *DeviceMessage) Settable() bool

Settable() determine is property is settable

func (*DeviceMessage) String

func (dm *DeviceMessage) String() string

String ToString - utility function

func (DeviceMessage) Topic

func (dm DeviceMessage) Topic() string

* QueueMessage implementation for DeviceMessage

type DeviceNode

type DeviceNode struct {
	ID          EID
	ElementType CoreType
	Parent      string
	Name        string
	Attrs       map[string]DeviceNodeAttribute
	Props       map[string]DeviceNodeProperty
}

DeviceNode representing the capabilities or features of device

func NewDeviceNode

func NewDeviceNode(parent, name string) DeviceNode

NewDeviceNode Creates Component

type DeviceNodeAttribute

type DeviceNodeAttribute struct {
	ID          EID
	ElementType CoreType
	Parent      string
	Name        string
	Value       string
}

DeviceNodeAttribute used by Devices, Nodes, and Properties. Used to describe format

func NewDeviceNodeAttribute

func NewDeviceNodeAttribute(parent, name, value string) DeviceNodeAttribute

NewDeviceNodeAttribute Creates Component

type DeviceNodeProperty

type DeviceNodeProperty struct {
	ID          EID
	ElementType CoreType
	Parent      string
	Name        string
	Value       string
	Attrs       map[string]DeviceNodePropertyAttribute
}

DeviceNodeProperty of a Node, representing a single value or measurement

func NewDeviceNodeProperty

func NewDeviceNodeProperty(parent, name, value string) DeviceNodeProperty

NewDeviceNodeProperty Creates Component

type DeviceNodePropertyAttribute

type DeviceNodePropertyAttribute struct {
	ID          EID
	ElementType CoreType
	Parent      string
	Name        string
	Value       string
}

DeviceNodePropertyAttribute used by Devices, Nodes, and Properties. Used to describe format

func NewDeviceNodePropertyAttribute

func NewDeviceNodePropertyAttribute(parent, name, value string) DeviceNodePropertyAttribute

NewDeviceNodePropertyAttribute Creates Component

type EID

type EID string

EID entity EID

func NewEID

func NewEID() EID

NewEID create a new entity ID

type EntityBuilder

type EntityBuilder interface {
	// contains filtered or unexported methods
}

EntityBuilder - based on Network Entity - manages creation and deletion of components

type Firmware

type Firmware struct {
	ID          EID
	ElementType CoreType
	Name        string
	FileName    string
	Version     string
	Path        string
	Size        int64
	MD5Digest   string
	Brand       string
	Created     time.Time
}

Firmware basic firmware model

func (*Firmware) String

func (f *Firmware) String() string

type FirmwareTools

type FirmwareTools interface {
	String()
}

type Network

type Network struct {
	ID          string
	Title       string
	ElementType CoreType // network name
	Name        string   // any
	Devices     map[string]Device
}

Network contains all known devices in application

func NewNetwork

func NewNetwork(title, name string) Network

NewNetwork Creates Component

type OTATransport

type OTATransport int

OTATransport Flag used to choose OTA transport Format

const (
	Binary OTATransport = iota + 30
	Base64
	Base64Strict
	RFC4648URLSafeWithPadding
	RFC4648URLSafeWithoutPadding
)

OTATransport Flags used to choose OTA transport Format

type QueueMessage

type QueueMessage interface {
	Topic() string
	Payload() []byte
	MessageID() uint16
	Retained() bool
	Qos() byte
	Duplicate() bool
	Ack()
}

QueueMessage maps a mqtt.Message into this domain entity

type Repository

type Repository interface {
	Store(d DeviceMessage) error
	Remove(d DeviceMessage) error
	RestoreNetworkFromDB(networkName string) Network
	LoadSchedules() map[string]Schedule
	StoreSchedule(d Schedule) error
	RemoveSchedule(scheduleID string) error
	LoadBroadcasts(networkName string) []Broadcast
	RemoveAllBroadcasts(networkName string) error
}

Device Source Storage Repository

type Schedule

type Schedule struct {
	ID          string
	ElementType CoreType
	DeviceID    string
	FirmwareID  EID
	State       string
	Status      string
	Retries     int
	Transport   OTATransport
	Scheduled   time.Time
	Completed   time.Time
}

Schedule the ota schedule details

func (*Schedule) String

func (s *Schedule) String() string

type ScheduleTools

type ScheduleTools interface {
	String()
}

type SchedulerProvider

type SchedulerProvider interface {
	ActivateStreamProvider()
	ApplySiteNetworks(sn *SiteNetworks)
	Schedules() []Schedule
	BuildScheduleCatalog() map[string]Schedule
	FindScheduleByDeviceID(deviceID string) *Schedule
	CreateSchedule(networkName string, deviceID string, transport OTATransport, firmwareID EID) (string, error)
	DeleteSchedule(scheduleID string) error
	BuildFirmwareCatalog() []Firmware
	Firmwares() []Firmware
	GetFirmware(id EID) (Firmware, error)
	CreateFirmware(srcFile, dstFile string) (EID, error)
	DeleteFirmware(id EID) error
}

* Interactions with device Scheduling Service

type SiteNetworks

type SiteNetworks struct {
	ID             EID
	ElementType    CoreType // site name
	SiteName       string
	Title          string
	Names          []string // any
	Broadcasts     []Broadcast
	Firmwares      []Firmware
	Schedules      map[string]Schedule // by EID
	DeviceNetworks map[string]Network  // by Device Name
}

SiteNetworks contains all known/valid Collections

func NewSiteNetworks

func NewSiteNetworks(siteName, siteTitle string, networks []string, firmwares []Firmware, schedules map[string]Schedule) *SiteNetworks

NewSiteNetworks Creates Component

Jump to

Keyboard shortcuts

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