types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MaxModelLen = 64
	MinModelLen = 3
)
View Source
const (
	WithRandom = curve.ModeDefault
	WithStart  = curve.ModeMinStart
	WithEnd    = curve.ModeMinEnd
)
View Source
const (
	MaxSpeedVal = 1000
	MinSpeedVal = 0
)

Variables

View Source
var (
	// ErrMinBattery indicates that the value is less than 0%.
	ErrMinBattery = errors.New("types/battery: value is less than 0%")
	// ErrMaxBattery indicates that the value greater than 100%.
	ErrMaxBattery = errors.New("types/battery: value greater than 100%")
)
View Source
var (
	// ErrModelTooShort represents an error condition where the model value is too short.
	ErrModelTooShort = errors.New("types/model: model value too short")
	// ErrModelTooLong represents an error condition where the model value is too long.
	ErrModelTooLong = errors.New("types/model: model value too long")
)
View Source
var (
	// ErrMinSpeed indicates that the speed value is less than 0.
	ErrMinSpeed = errors.New("types/speed: value is less than 0")
	// ErrMaxSpeed indicates that the speed value is greater than 1000.
	ErrMaxSpeed = errors.New("types/speed: value of greater than 1000")
	// ErrSpeedMinGreaterMax indicates that the minimum speed value is greater than the maximum speed value.
	ErrSpeedMinGreaterMax = errors.New("types/speed: min value greater than max value")
)
View Source
var (
	// ErrMinAmplitude indicates that the amplitude value is less than 4.
	ErrMinAmplitude = errors.New("types/amplitude: value is less than 4")
	// ErrMaxAmplitude indicates that the amplitude value of greater 512.
	ErrMaxAmplitude = errors.New("types/amplitude: value of greater 512")
)
View Source
var ErrEmptySensorName = errors.New("types/sensor: empty name")

ErrEmptySensorName indicates that the sensor name is empty.

Functions

This section is empty.

Types

type Battery

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

Battery represents a simulated battery object with charge level management and behavior.

func NewBattery

func NewBattery(min, max float64, chargeTime time.Duration) (*Battery, error)

NewBattery creates a new Battery instance with the specified characteristics. The min parameter is the minimum battery charge level (percentage), the max parameter is the maximum battery charge level (percentage), and the chargeTime parameter represents the time duration it takes to fully charge the battery. If the min value is less than 0 or the max value is greater than 100, an error is returned. If the min value is greater than the max value, the min value is adjusted to match the max value. If the chargeTime is less than or equal to zero, it is set to a default value of 9 hours.

func (*Battery) ChargeTime

func (t *Battery) ChargeTime() time.Duration

ChargeTime returns the time duration it takes to fully charge the battery.

func (*Battery) FromSnapshot

func (t *Battery) FromSnapshot(snap *proto.Snapshot_BatteryType)

FromSnapshot restores the Battery instance from a protobuf snapshot.

func (*Battery) IsLow

func (t *Battery) IsLow() bool

IsLow returns true if the battery charge level is at its minimum value, indicating a low battery condition.

func (*Battery) Max

func (t *Battery) Max() float64

Max returns the maximum value of the battery.

func (*Battery) Min

func (t *Battery) Min() float64

Min returns the minimum value of the battery.

func (*Battery) Next

func (t *Battery) Next(seconds float64)

Next updates the battery charge level based on the number of seconds that have passed.

func (*Battery) Reset

func (t *Battery) Reset()

Reset resets the battery charge level to zero.

func (*Battery) Snapshot

func (t *Battery) Snapshot() *proto.Snapshot_BatteryType

Snapshot returns a protobuf snapshot of the Battery instance.

func (*Battery) String

func (t *Battery) String() string

String returns a formatted string representation of the battery object, displaying the battery level as a percentage.

func (*Battery) Value

func (t *Battery) Value() float64

Value returns the current value of the battery.

type Model

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

Model represents the tracker device model.

func NewModel

func NewModel(value string) (Model, error)

NewModel creates a new Model instance with the provided value. It performs length validation on the value and returns an error if it's too short or too long.

func RandomModel

func RandomModel() Model

RandomModel generates and returns a random Model instance. It creates a Model object with a value in the format "RT-" followed by a randomly generated string of length 6.

func (Model) IsEmpty

func (m Model) IsEmpty() bool

IsEmtpy checks whether the model value is empty (i.e., has a length of 0). It returns true if the value is empty, and false otherwise.

func (Model) String

func (m Model) String() string

String returns the string representation of the model.

type Random

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

Random represents a random number generator.

func NewRandom

func NewRandom(min, max int) *Random

NewRandom creates a new Random instance with the specified minimum and maximum values.

func (*Random) Max

func (r *Random) Max() int

Max returns the maximum value.

func (*Random) Min

func (r *Random) Min() int

Min returns the minimum value.

func (*Random) Value

func (r *Random) Value() int

Value generates and returns a random integer value within the range specified by min and max.

type Sensor

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

Sensor structure provides a flexible and extensible way to represent and work with sensors. It allows for generating different values for different tasks, making it suitable for various applications and use cases involving sensor data collection, simulation, or analysis.

func NewSensor

func NewSensor(name string, min, max float64, amplitude int, mode SensorMode) (*Sensor, error)

NewSensor creates a new Sensor instance with the given name, minimum and maximum values, and amplitude. The amplitude is used to generate a random curve for the sensor.

Valid amplitude values from 4 to 512.

func (*Sensor) FromSnapshot

func (t *Sensor) FromSnapshot(snap *SensorSnapshot)

FromSnapshot restores the Sensor instance from a protobuf snapshot.

func (*Sensor) ID

func (t *Sensor) ID() string

ID returns the unique identifier of the sensor.

func (*Sensor) Max

func (t *Sensor) Max() float64

Max returns the maximum value of the sensor.

func (*Sensor) Min

func (t *Sensor) Min() float64

Min returns the minimum value of the sensor.

func (*Sensor) Name

func (t *Sensor) Name() string

Name returns the name of the sensor.

func (*Sensor) Next

func (t *Sensor) Next(tick float64)

Next updates the sensor's values based on the tick value, generating new values using the associated generator object.

Tick in the range from 0 to 1.

func (*Sensor) Shuffle

func (t *Sensor) Shuffle()

func (*Sensor) Snapshot

func (t *Sensor) Snapshot() *SensorSnapshot

Snapshot returns a protobuf snapshot of the Sensor instance.

func (*Sensor) String

func (t *Sensor) String() string

String returns a formatted string representation of the sensor object.

func (*Sensor) ValueX

func (t *Sensor) ValueX() float64

ValueX returns the current value of the sensor along the X-axis.

func (*Sensor) ValueY

func (t *Sensor) ValueY() float64

ValueY returns the current value of the sensor along the Y-axis.

type SensorMode

type SensorMode = curve.CurveMode

type SensorSnapshot

type SensorSnapshot = proto.Snapshot_SensorType

type Speed

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

Speed represents a speed value with a minimum and maximum range and contains a value generator.

func NewSpeed

func NewSpeed(min, max float64, amplitude int) (*Speed, error)

NewSpeed creates a new Speed instance with the specified minimum and maximum values. It also takes an amplitude parameter for generating a random curve. The minimum value is 0 to maximum 1000, and the amplitude parameter must be 4 to 512.

func (*Speed) FromSnapshot

func (t *Speed) FromSnapshot(snap *proto.Snapshot_CommonType)

FromSnapshot restores the Speed instance from a protobuf snapshot.

func (*Speed) Max

func (t *Speed) Max() float64

Max returns the maximum speed value of the Speed instance.

func (*Speed) Min

func (t *Speed) Min() float64

Min returns the minimum speed value of the Speed instance.

func (*Speed) Next

func (t *Speed) Next(tick float64)

Next generates the next speed value based on a given tick value, using the underlying random curve generator.

Tick in the range from 0 to 1.

func (*Speed) Shuffle

func (t *Speed) Shuffle()

Shuffle shuffles the generator of the Speed instance.

func (*Speed) Snapshot

func (t *Speed) Snapshot() *proto.Snapshot_CommonType

Snapshot returns a protobuf snapshot of the Speed instance.

func (*Speed) String

func (t *Speed) String() string

String returns a formatted string representation of the speed value.

func (*Speed) Value

func (t *Speed) Value() float64

Value returns the current speed value of the Speed instance.

Jump to

Keyboard shortcuts

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