db

package
v0.0.0-...-138a2ce Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRegistered

func GetRegistered(s *state.State) (map[string]bool, error)

GetRegistered returns the map of microcontrollers UUID that are in the registration table.

func IndexData

func IndexData(s *state.State, uuid string, busAddr int, ts time.Time, payload []byte) error

IndexData is called when the peripheral controller publishes processed data (payload). It will attempt to index the data in the "Data" table.

func Init

func Init(s *state.State) error

Init initializes the Postgres database. If the tables do not already exist, the tables will be created. An error will be returned if the database cannot be queried or if the tables cannot be created.

func QueryData

func QueryData(s *state.State, uuid string, busAddr int, start *time.Time, stop *time.Time) ([]state.WebsocketFrame, error)

QueryData accepts a microcontroller UUID, bus address, and option start and stop times. It will return all data points matching the parameters. An error will be returned if the query cannot be completed.

func QueryProvisioning

func QueryProvisioning(s *state.State, busAddr uint32) (*telemetry.Provisioning, bool, error)

QueryProvisioning will query the "Processor", "ReadDefintion" and "Provisioning" tables using the provided bus address, returning a telemetry Protobuf instance and an indicator if a provisioning record was found. An error will be returned if the query cannot be completed.

func UpsertConfig

func UpsertConfig(s *state.State, config JSONConfig) error

UpsertConfig accepts the JSON configuration from the peripheral controller. will update the "Processor", "ReadDefinition" and "Provisioning" tables with the provided data. It will return an error if the tables cannot be updated.

func UpsertRegistration

func UpsertRegistration(s *state.State, msg *telemetry.Telemetry) error

UpsertRegistration will insert the registration telemetry message into the "registration" and "peripheral" tables.

Types

type JSONConfig

type JSONConfig struct {
	BusAddr         int              `json:"busAddr"`
	Name            string           `json:"name"`
	ReadDefinitions []ReadDefinition `json:"readDefinitions"`
}

JSONConfig is the configuration from the peripheral controller.

type Peripheral

type Peripheral struct {
	BusID    int    `json:"busId"`    // BusID is the bus identifier of the peripheral
	BusAddr  int    `json:"busAddr"`  //BusAddr is the bus address of the peripehral
	CallResp []byte `json:"callResp"` // CallResp is the general call response
}

Peripheral is a peripheral connected to the microcontroller.

type Provisioning

type Provisioning struct {
	BusAddr        int    `json:"busAddr"`        // BusAddr is the bus address of the peripehral
	Name           string `json:"name"`           // Name is common name of peripheral controller
	DefinitionID   int    `json:"definitionId"`   // DefinitionID is a definition UUID
	RegIDLength    int    `json:"regIdLength"`    // RegIDLength is register ID length
	RegID          int    `json:"regId"`          // RegID is register ID
	RegBlockLength int    `json:"regBlockLength"` // RegBlockLenght is register block length
	BytesPerReg    int    `json:"bytesPerReg"`    // BytesPerReg is bytes per register
	ReadPeriod     int    `json:"readPeriod"`     // ReadPeriod is the bus address reading period
}

Provisioning represnts a joined entry from "Provisioning", "Processor", and "ReadDefinition" tables.

func GetProvisioning

func GetProvisioning(s *state.State) ([]Provisioning, error)

GetProvisioning returns a list of active provisionings. An erorr will be returned if the query cannot be completed.

type ReadDefinition

type ReadDefinition struct {
	DefinitionID        int `json:"definitionId"`
	RegisterIDLength    int `json:"registerIdLength"`
	RegisterID          int `json:"registerId"`
	RegisterBlockLength int `json:"registerBlockLength"`
	NumBytesPerRegister int `json:"numBytesPerRegister"`
	ReadPeriod          int `json:"readPeriod"`
}

ReadDefinition is a definition in the controller.

type RegistrationPeripherals

type RegistrationPeripherals struct {
	UUID        string       `json:"uuid"`        // UUID is the microcontroller unique identifier
	Firmware    int          `json:"firmware"`    // Firmware is the microcontroller firmware number
	IPv4        string       `json:"ipv4"`        // IPv4 is the IPv4 address
	IPv6        string       `json:"ipv6"`        // IPv6 is the IPv6 address
	Peripherals []Peripheral `json:"peripherals"` // Peripheral is the list of connected peripherals
}

RegistrationPeripherals is the registration information combined with connected Peripherals.

func GetRegistrationPeripherals

func GetRegistrationPeripherals(s *state.State) ([]RegistrationPeripherals, error)

GetRegistrationPeripherals will join the "Register" and "Peripheral" tables, returning the complete registration information. It will return an error if the

Jump to

Keyboard shortcuts

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