output

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2022 License: GPL-3.0 Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Color = Output{
	Name: "color",
	Type: "color",
}

Color is an output type for color readings. This output has no unit.

A color reading is generally a string which represents some kind of color. This can be the name ("red"), a hex string ("ff0000"), an RBG string ("255,0,0"), or anything else.

View Source
var Count = Output{
	Name: "count",
	Type: "count",
}

Count is an output type for counts of things. This output has no unit.

View Source
var Direction = Output{
	Name: "direction",
	Type: "direction",
}

Direction is an output type for directionality (e.g. the direction in which a fan may be spinning). This output has no unit.

View Source
var ElectricCurrent = Output{
	Name:      "electric-current",
	Type:      "current",
	Precision: 3,
	Unit: &Unit{
		Name:   "ampere",
		Symbol: "A",
	},
}

ElectricCurrent is an output type for electrical current readings, measured in Amperes.

View Source
var ElectricResistance = Output{
	Name:      "electric-resistance",
	Type:      "resistance",
	Precision: 2,
	Unit: &Unit{
		Name:   "ohm",
		Symbol: "Ω",
	},
}

ElectricResistance is an output type for electrical resistance readings, measured in Ohms.

View Source
var Frequency = Output{
	Name:      "frequency",
	Type:      "frequency",
	Precision: 2,
	Unit: &Unit{
		Name:   "hertz",
		Symbol: "Hz",
	},
}

Frequency is an output type for frequency readings, measured in Hertz.

View Source
var Humidity = Output{
	Name:      "humidity",
	Type:      "humidity",
	Precision: 2,
	Unit: &Unit{
		Name:   "percent humidity",
		Symbol: "%",
	},
}

Humidity is an output type for humidity readings, measured as a percentage.

View Source
var Kilojoule = Output{
	Name:      "kilojoule",
	Type:      "energy",
	Precision: 3,
	Unit: &Unit{
		Name:   "kilojoule",
		Symbol: "kJ",
	},
}

Kilojoule is an output type for energy readings, measured in kilojoules.

View Source
var KilowattHour = Output{
	Name:      "kilowatt-hour",
	Type:      "energy",
	Precision: 3,
	Unit: &Unit{
		Name:   "kilowatt-hour",
		Symbol: "kWh",
	},
}

KilowattHour is an output type for energy readings, measured in kilowatt-hours.

View Source
var Microseconds = Output{
	Name:      "microseconds",
	Type:      "duration",
	Precision: 6,
	Unit: &Unit{
		Name:   "microseconds",
		Symbol: "µs",
	},
}

Microseconds is an output type for a duration, measured in seconds.

View Source
var Milliseconds = Output{
	Name:      "milliseconds",
	Type:      "duration",
	Precision: 6,
	Unit: &Unit{
		Name:   "milliseconds",
		Symbol: "ms",
	},
}

Milliseconds is an output type for a duration, measured in milliseconds.

View Source
var Minutes = Output{
	Name:      "minutes",
	Type:      "duration",
	Precision: 6,
	Unit: &Unit{
		Name:   "minutes",
		Symbol: "min",
	},
}

Minutes is an output type for a duration, measured in minutes.

View Source
var Nanoseconds = Output{
	Name:      "nanoseconds",
	Type:      "duration",
	Precision: 6,
	Unit: &Unit{
		Name:   "nanoseconds",
		Symbol: "ns",
	},
}

Nanoseconds is an output type for a duration, measured in seconds.

View Source
var Number = Output{
	Name:      "number",
	Type:      "number",
	Precision: 2,
}

Number is an output type for some number of things. This output has no unit.

An example of what a number could be include: an index into something, the number of rows/columns of a table, etc.

The Number output is intended to provide context for numeric values which do not have any unit associated with them. The value itself could be a signed/unsigned int, float, or complex number. This output just tells upstream consumers that the value is numeric and there is no unit associated with the value.

View Source
var PSI = Output{
	Name:      "psi",
	Type:      "pressure",
	Precision: 3,
	Unit: &Unit{
		Name:   "pounds per square inch",
		Symbol: "psi",
	},
}

PSI is an output type for pressure readings, measured in PSI.

View Source
var Pascal = Output{
	Name:      "pascal",
	Type:      "pressure",
	Precision: 3,
	Unit: &Unit{
		Name:   "pascal",
		Symbol: "Pa",
	},
}

Pascal is an output type for pressure readings, measured in Pascals.

View Source
var Percentage = Output{
	Name: "percentage",
	Type: "percentage",
	Unit: &Unit{
		Name:   "percent",
		Symbol: "%",
	},
}

Percentage is an output type for general percentages.

View Source
var RPM = Output{
	Name:      "rpm",
	Type:      "frequency",
	Precision: 2,
	Unit: &Unit{
		Name:   "revolutions per minute",
		Symbol: "RPM",
	},
}

RPM is an output type for frequency readings, measured in revolutions per minute.

View Source
var Seconds = Output{
	Name:      "seconds",
	Type:      "duration",
	Precision: 3,
	Unit: &Unit{
		Name:   "seconds",
		Symbol: "s",
	},
}

Seconds is an output type for a duration, measured in seconds.

View Source
var State = Output{
	Name: "state",
	Type: "state",
}

State is an output type for state readings. This output has no unit.

A state reading is generally a string which represents some kind of state (e.g. "on"/"off").

View Source
var Status = Output{
	Name: "status",
	Type: "status",
}

Status is an output type for status readings. This output has no unit.

A status reading is generally a string which describes the status of a device, e.g. "operational".

View Source
var String = Output{
	Name: "string",
	Type: "string",
}

String is an output type for string data. This output has no unit.

A string can be anything. Some examples include identifiers, descriptions, version numbers, etc.

View Source
var Switch = Output{
	Name:      "switch",
	Type:      "state",
	Precision: 1,
}

Switch is an output type for a boolean switch (on/off, high/low, true/false) reading. This output has no unit.

This unit is similar to "state", and "state" could be used in place of this if desired. The "state" output is more general, applying to any state, where this "switch" state is more focused on a two-state reading. This distinction is semantic though, as the SDK does not encode nor enforce the above statements in any way.

View Source
var Temperature = Output{
	Name:      "temperature",
	Type:      "temperature",
	Precision: 2,
	Unit: &Unit{
		Name:   "celsius",
		Symbol: "C",
	},
}

Temperature is an output type for temperature readings, measured in degrees Celsius.

View Source
var Timestamp = Output{
	Name: "timestamp",
	Type: "timestamp",
}

Timestamp is an output type for a string describing a timestamp. This output has no unit. The timestamp may have any format.

View Source
var Velocity = Output{
	Name:      "velocity",
	Type:      "velocity",
	Precision: 3,
	Unit: &Unit{
		Name:   "meters per second",
		Symbol: "m/s",
	},
}

Velocity is an output type for velocity readings, measured in meters per second.

View Source
var VoltSecond = Output{
	Name:      "volt-second",
	Type:      "flux",
	Precision: 3,
	Unit: &Unit{
		Name:   "volt second",
		Symbol: "Vs",
	},
}

VoltSecond is an output type for magnetic flux readings, measured in Volt seconds.

Note that:

Wb = kg•m²/s²•A = Ω•C = V•s = H•A = T•m² = J/A

That means this output can be used in place of a Weber, for example.

View Source
var Voltage = Output{
	Name:      "voltage",
	Type:      "voltage",
	Precision: 5,
	Unit: &Unit{
		Name:   "volt",
		Symbol: "V",
	},
}

Voltage is an output type for voltage readings, measured in volts.

View Source
var Watt = Output{
	Name:      "watt",
	Type:      "power",
	Precision: 3,
	Unit: &Unit{
		Name:   "watt",
		Symbol: "W",
	},
}

Watt is an output type for power readings, measured in watts.

View Source
var Weber = Output{
	Name:      "weber",
	Type:      "flux",
	Precision: 3,
	Unit: &Unit{
		Name:   "weber",
		Symbol: "Wb",
	},
}

Weber is an output type for magnetic flux readings, measured in Webers.

Note that:

Wb = kg•m²/s²•A = Ω•C = V•s = H•A = T•m² = J/A

That means this output can be used in place of a Volt-second, for example.

Functions

func Register

func Register(output ...*Output) error

Register registers new outputs to the tracked outputs.

Types

type Output

type Output struct {
	// Name is the name of the output. Output names should be unique, as
	// outputs can be referenced by name.
	Name string

	// Precision is the precision that the reading will take with this output,
	// e.g. the number of decimal places to round to. This is only used when
	// the reading value is a float.
	Precision int

	// Type is the type that an output will assign to a reading which is
	// generated from it.
	Type string

	// The unit applied to all readings for the output.
	Unit *Unit
}

Output defines the output information associated with a device reading.

func Get

func Get(name string) *Output

Get gets an Output by name. If an output with the specified name is not found, nil is returned.

func GetBuiltins

func GetBuiltins() []*Output

GetBuiltins returns a list of all the built-in outputs supplied by the SDK.

func (*Output) Encode

func (output *Output) Encode() *synse.V3DeviceOutput

Encode translates the Output to its corresponding gRPC message.

func (*Output) MakeReading

func (output *Output) MakeReading(value interface{}) (reading *Reading, err error)

MakeReading makes a new Reading for the provided value, applying the pertinent output data to the reading.

type Reading

type Reading struct {
	// Timestamp is the RFC3339-formatted time at which the reading was taken.
	Timestamp string

	// Type is the type of the reading, as defined by the Reading's output.
	Type string

	// Unit describes the unit of measure for the reading.
	Unit *Unit

	// Value is the reading value itself.
	Value interface{}

	// Context provides an arbitrary key-value mapping which can be used to
	// provide contextual information about the reading. This is not required
	// but can be useful if a device provides multiple readings from the
	// same output, or readings which are meaningless on their own.
	Context map[string]string
	// contains filtered or unexported fields
}

Reading describes a single device reading at a given time. The timestamp for a reading is represented using the RFC3339 layout.

func (*Reading) Encode

func (reading *Reading) Encode() *synse.V3Reading

Encode translates the Reading to its corresponding gRPC message.

func (*Reading) GetOutput

func (reading *Reading) GetOutput() *Output

GetOutput gets the associated output for a Reading.

func (*Reading) Scale

func (reading *Reading) Scale(factor float64) error

Scale multiplies the given scaling factor to the Reading value and updates the Value with the new scaled value.

The scaling factor is defined in the device config, so this is applied by the SDK by the scheduler upon receiving the reading. The scaling factor is applied after any other transformation functions (see the sdk/funcs package) have been applied.

func (*Reading) WithContext

func (reading *Reading) WithContext(ctx map[string]string) *Reading

WithContext adds a context to the reading. This is useful when creating a reading from an output and you wish to in-line the setting of the reading context, e.g.

SomeOutput.MakeReading(3).WithContext(map[string]string{"source": "foo"})

This will merge the provided context with any existing context. If there is a conflict, the context value provided here will override the pre-existing value.

type Unit

type Unit struct {
	// Name is the full name of the unit.
	Name string

	// Symbol is the symbolic representation of the unit.
	Symbol string
}

Unit is the unit of measure for a device reading.

func (*Unit) Encode

func (unit *Unit) Encode() *synse.V3OutputUnit

Encode translates the Unit to its corresponding gRPC message.

Jump to

Keyboard shortcuts

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