model

package
v0.0.0-...-5837768 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package model provides entities for safe device configuration.

By using an extra model layer between the device drivers and network interfaces like HTTP we can control what information we want to expose to the outside world. On the one hand side we can catch invalid device configurations at an early stage on the other side we can hide (complicated) implementation details from the API user.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DDSDeviceValidation

func DDSDeviceValidation(sl validator.StructLevel)

DDSDeviceValidation implements struct level validation.

func DDSParamValidation

func DDSParamValidation(sl validator.StructLevel)

DDSParamValidation implements struct level validation.

func ValidateRange

func ValidateRange(f validator.FieldLevel) bool

ValidateRange checks if an array of size two is a valid range.

This means that the last value should be greater than the first value.

Types

type DDSConst

type DDSConst struct {
	Value float64 `json:"value" validate:"gte=0"`
}

DDSConst is the DDS mode where a DDS controllable parameter is constant.

type DDSDevice

type DDSDevice struct {
	ID          uint8    `json:"id"        validate:"max=31"`
	Name        string   `json:"name"      validate:"required"`
	Amplitude   DDSParam `json:"amplitude"`
	Frequency   DDSParam `json:"frequency"`
	PhaseOffset DDSParam `json:"phase"`
}

DDSDevice is a public entity to a digital synthesizer device.

Instead of exposing an entity for every support operation mode we will decide what mode to use from the defined properties. For example in singletone mode it only makes sense to provide an amplitude and frequency property wherein in sweep mode we expect to have a frequency range defined over a single frequency.

func (*DDSDevice) Validate

func (d *DDSDevice) Validate() (err error)

Validate returns an error if DDSDevice has ambigious configuration.

type DDSDevices

type DDSDevices []DDSDevice

DDSDevices is a collection of DDSDevices.

DDSDevices implements the flag.Value interface so that you can parse a list of device addresses.

func (*DDSDevices) FindByID

func (s *DDSDevices) FindByID(id uint8) int

FindByID returns the first index of the DDSDevice with the given id.

If no device matches -1 is returned.

func (*DDSDevices) FindByIDString

func (s *DDSDevices) FindByIDString(id string) int

FindByIDString returns the first index of the DDSDevice with the given id.

If no device matches -1 is returned.

func (*DDSDevices) FindByName

func (s *DDSDevices) FindByName(name string) int

FindByName returns the first index of the DDSDevice with the given name.

If no device matches -1 is returned.

func (*DDSDevices) Set

func (s *DDSDevices) Set(v string) error

Set implements flag.Value.

func (*DDSDevices) String

func (s *DDSDevices) String() string

String implements flag.Value.

type DDSParam

type DDSParam struct {
	Mode     Mode        `json:"mode"`
	Const    DDSConst    `json:"const" validate:"structonly"`
	Sweep    DDSSweep    `json:"sweep" validate:"structonly"`
	Playback DDSPlayback `json:"playback" validate:"structonly"`
}

DDSParam is the DDS mode in which a DDS controllable parameter runs.

Note that usually only one of the embedded structs will be not nil as it does not make sense to have a constant frequency which we is also swept.

type DDSPlayback

type DDSPlayback struct {
	Trigger  bool      `json:"trigger"`
	Duplex   bool      `json:"duplex"`
	Interval Seconds   `json:"interval" validate:"gt=0"`
	Data     []float64 `json:"data" validate:"required"`
}

DDSPlayback is the DDS mode where a DDS controllable parameter is playbed back from memory.

type DDSSweep

type DDSSweep struct {
	Limits   [2]float64 `json:"limits" validate:"len=2,range,dive,gte=0"`
	NoDwells [2]bool    `json:"nodwells"`
	Duration Seconds    `json:"duration" validate:"required,gt=0"`
}

DDSSweep is the DDS mode where a DDS controllable parameter is swept.

type Mode

type Mode int

Mode is a DDS parameter mode.

const (
	ModeConst Mode = iota
	ModeSweep
	ModePlayback
)

Available DDS parameter modes.

func (Mode) MarshalJSON

func (m Mode) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaller interface.

func (Mode) String

func (m Mode) String() string

String returns the string representation of mode.

func (*Mode) UnmarshalJSON

func (m *Mode) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller interface.

type Seconds

type Seconds float64

Seconds represents a time duration in seconds.

Actually we would use time.Duration for this case but unfortunately time.Duration states strange json requirements which we do not support.

func (Seconds) Duration

func (s Seconds) Duration() time.Duration

Duration returns a time.Duration with the same duration as seconds.

func (*Seconds) Set

func (s *Seconds) Set(v string) error

Set sets the seconds from a duration time string.

func (Seconds) String

func (s Seconds) String() string

String returns the string representation of seconds.

Jump to

Keyboard shortcuts

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