Documentation ¶
Index ¶
- Constants
- Variables
- type Battery
- func (t *Battery) ChargeTime() time.Duration
- func (t *Battery) FromSnapshot(snap *proto.Snapshot_BatteryType)
- func (t *Battery) IsLow() bool
- func (t *Battery) Max() float64
- func (t *Battery) Min() float64
- func (t *Battery) Next(seconds float64)
- func (t *Battery) Reset()
- func (t *Battery) Snapshot() *proto.Snapshot_BatteryType
- func (t *Battery) String() string
- func (t *Battery) Value() float64
- type Model
- type Random
- type Sensor
- func (t *Sensor) FromSnapshot(snap *SensorSnapshot)
- func (t *Sensor) ID() string
- func (t *Sensor) Max() float64
- func (t *Sensor) Min() float64
- func (t *Sensor) Name() string
- func (t *Sensor) Next(tick float64)
- func (t *Sensor) Shuffle()
- func (t *Sensor) Snapshot() *SensorSnapshot
- func (t *Sensor) String() string
- func (t *Sensor) ValueX() float64
- func (t *Sensor) ValueY() float64
- type SensorMode
- type SensorSnapshot
- type Speed
- func (t *Speed) FromSnapshot(snap *proto.Snapshot_CommonType)
- func (t *Speed) Max() float64
- func (t *Speed) Min() float64
- func (t *Speed) Next(tick float64)
- func (t *Speed) Shuffle()
- func (t *Speed) Snapshot() *proto.Snapshot_CommonType
- func (t *Speed) String() string
- func (t *Speed) Value() float64
Constants ¶
const ( MaxModelLen = 64 MinModelLen = 3 )
const ( WithRandom = curve.ModeDefault WithStart = curve.ModeMinStart WithEnd = curve.ModeMinEnd )
const ( MaxSpeedVal = 1000 MinSpeedVal = 0 )
Variables ¶
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%") )
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") )
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") )
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") )
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 ¶
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 ¶
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 ¶
IsLow returns true if the battery charge level is at its minimum value, indicating a low battery condition.
func (*Battery) Next ¶
Next updates the battery charge level based on the number of seconds that have passed.
func (*Battery) Snapshot ¶
func (t *Battery) Snapshot() *proto.Snapshot_BatteryType
Snapshot returns a protobuf snapshot of the Battery instance.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model represents the tracker device model.
func NewModel ¶
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.
type Random ¶
type Random struct {
// contains filtered or unexported fields
}
Random represents a random number generator.
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 ¶
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) Next ¶
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) Snapshot ¶
func (t *Sensor) Snapshot() *SensorSnapshot
Snapshot returns a protobuf snapshot of the Sensor instance.
type SensorMode ¶
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 ¶
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) Next ¶
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.