roverlib

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(main MainCallback, onTerminate TerminationCallback)

Start the program (main) and handle termination

Types

type Configuration

type Configuration struct {
	// Unique name of this configuration option
	Name *string `json:"name,omitempty"`
	// Whether or not this value can be tuned (ota)
	Tunable *bool `json:"tunable,omitempty"`
	// The type of this configuration option
	Type *Type `json:"type,omitempty"`
	// The value of this configuration option, which can be a string, integer, or float
	Value *Value `json:"value"`
}

type Input

type Input struct {
	// The name of the service for this dependency
	Service *string  `json:"service,omitempty"`
	Streams []Stream `json:"streams,omitempty"`
}

type MainCallback

type MainCallback func(
	s Service,
	config *ServiceConfiguration,
) error

The user main function to run

type Output

type Output struct {
	// The (zmq) socket address that output can be written to
	Address *string `json:"address,omitempty"`
	// Name of the output published by this service
	Name *string `json:"name,omitempty"`
}

type Service

type Service struct {
	Configuration []Configuration `json:"configuration"`
	// The resolved input dependencies
	Inputs []Input `json:"inputs"`
	// The name of the service (only lowercase letters and hyphens)
	Name    *string  `json:"name,omitempty"`
	Outputs []Output `json:"outputs"`
	Tuning  Tuning   `json:"tuning"`
	// The specific version of the service
	Version *string     `json:"version,omitempty"`
	Service interface{} `json:"service"`
}

The object that injected into a rover process by roverd and then parsed by roverlib to be made available for the user process

func UnmarshalService

func UnmarshalService(data []byte) (Service, error)

func (*Service) GetReadStream

func (s *Service) GetReadStream(service string, name string) *ServiceStream

Get a stream that you can read from (i.e. an input stream). This function panics if the stream does not exist, because fetching a non-existent stream should always terminate to avoid undefined behavior.

func (*Service) GetWriteStream

func (s *Service) GetWriteStream(name string) *ServiceStream

Get a stream that you can write to (i.e. an output stream). This function panics if the stream does not exist, because fetching a non-existent stream should always terminate to avoid undefined behavior.

func (*Service) Marshal

func (r *Service) Marshal() ([]byte, error)

type ServiceConfiguration

type ServiceConfiguration struct {
	// contains filtered or unexported fields
}

func NewServiceConfiguration

func NewServiceConfiguration(service Service) *ServiceConfiguration

func (*ServiceConfiguration) GetFloat

func (c *ServiceConfiguration) GetFloat(name string) (float64, error)

Returns the float value of the configuration option with the given name, returns an error if the option does not exist or does not exist for this type Reading is NOT thread-safe, but we accept the risks because we assume that the user program will read the configuration values repeatedly If you want to read the configuration values concurrently, you should use the GetFloatSafe method

func (*ServiceConfiguration) GetFloatSafe

func (c *ServiceConfiguration) GetFloatSafe(name string) (float64, error)

func (*ServiceConfiguration) GetInt

func (c *ServiceConfiguration) GetInt(name string) (int, error)

Returns the integer value of the configuration option with the given name, returns an error if the option does not exist or does not exist for this type Reading is NOT thread-safe, but we accept the risks because we assume that the user program will read the configuration values repeatedly If you want to read the configuration values concurrently, you should use the GetIntSafe method

func (*ServiceConfiguration) GetIntSafe

func (c *ServiceConfiguration) GetIntSafe(name string) (int, error)

func (*ServiceConfiguration) GetString

func (c *ServiceConfiguration) GetString(name string) (string, error)

Returns the string value of the configuration option with the given name, returns an error if the option does not exist or does not exist for this type Reading is NOT thread-safe, but we accept the risks because we assume that the user program will read the configuration values repeatedly If you want to read the configuration values concurrently, you should use the GetStringSafe method

func (*ServiceConfiguration) GetStringSafe

func (c *ServiceConfiguration) GetStringSafe(name string) (string, error)

type ServiceStream

type ServiceStream struct {
	// contains filtered or unexported fields
}

func (*ServiceStream) Read

func (s *ServiceStream) Read() (*rovercom.SensorOutput, error)

Read a rovercom sensor output message from the stream (you will need to switch on the returned message type to cast it to the correct type)

func (*ServiceStream) ReadBytes

func (s *ServiceStream) ReadBytes() ([]byte, error)

Read byte data from the stream

func (*ServiceStream) Write

func (s *ServiceStream) Write(output *rovercom.SensorOutput) error

Write a rovercom sensor output message to the stream

func (*ServiceStream) WriteBytes

func (s *ServiceStream) WriteBytes(data []byte) error

Write byte data to the stream

type Stream

type Stream struct {
	// The (zmq) socket address that input can be read on
	Address *string `json:"address,omitempty"`
	// The name of the stream as outputted by the dependency service
	Name *string `json:"name,omitempty"`
}

type TerminationCallback

type TerminationCallback func(s os.Signal) error

The function to call when the service is terminated or interrupted

type Tuning

type Tuning struct {
	// (If enabled) the (zmq) socket address that tuning data can be read from
	Address *string `json:"address,omitempty"`
	// Whether or not live (ota) tuning is enabled
	Enabled *bool `json:"enabled,omitempty"`
}

type Type

type Type string

The type of this configuration option

const (
	Float  Type = "float"
	Int    Type = "int"
	String Type = "string"
)

type Value

type Value struct {
	Double  *float64
	Integer *int64
	String  *string
}

The value of this configuration option, which can be a string, integer, or float

func (*Value) MarshalJSON

func (x *Value) MarshalJSON() ([]byte, error)

func (*Value) UnmarshalJSON

func (x *Value) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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