Documentation ¶
Index ¶
- Constants
- Variables
- func IsResponseTimeout(e error) bool
- func NewMockBus(t testing.TB) (*Bus, *MockUart)
- type Bus
- type Device
- func (dev *Device) ErrorCode() int32
- func (dev *Device) Init(bus *Bus, addr uint8, name string, byteOrder binary.ByteOrder)
- func (dev *Device) Keepalive(interval time.Duration, stopch <-chan struct{})
- func (dev *Device) Locked_TxKnown(request Packet, response *Packet) error
- func (dev *Device) Name() string
- func (dev *Device) NewFunLoop(tag string, fun PollFunc, timeout time.Duration) engine.Doer
- func (dev *Device) NewPollLoop(tag string, request Packet, timeout time.Duration, fun PollRequestFunc) engine.Doer
- func (dev *Device) Ready() bool
- func (dev *Device) Reset() error
- func (dev *Device) SetError(e error)
- func (dev *Device) SetOnline()
- func (dev *Device) SetReady()
- func (dev *Device) SetState(new DeviceState)
- func (dev *Device) State() DeviceState
- func (dev *Device) TeleError(e error)
- func (dev *Device) TxCustom(request Packet, response *Packet, opt TxOpt) error
- func (dev *Device) TxKnown(request Packet, response *Packet) error
- func (dev *Device) TxMaybe(request Packet, response *Packet) error
- func (dev *Device) TxSetup() error
- func (dev *Device) ValidateErrorCode() error
- func (dev *Device) ValidateOnline() error
- func (dev *Device) XXX_FIXME_SetAllDelays(d time.Duration)
- type DeviceState
- type FeatureNotSupported
- type InvalidChecksum
- type MockR
- type MockUart
- type Packet
- type PollDelay
- type PollFunc
- type PollRequestFunc
- type TxOpt
- type Uarter
Constants ¶
View Source
const ( DefaultDelayAfterReset = 500 * time.Millisecond DefaultDelayBeforeReset = 0 DefaultDelayIdle = 700 * time.Millisecond DefaultDelayNext = 200 * time.Millisecond DefaultDelayOffline = 10 * time.Second DefaultIdleThreshold = 30 * time.Second )
View Source
const ( DefaultBusResetKeep = 200 * time.Millisecond DefaultBusResetSleep = 500 * time.Millisecond )
View Source
const ErrCodeNone int32 = -1
View Source
const MockContextKey = "test/mdb-mock"
View Source
const MockTimeout = 5 * time.Second
View Source
const (
PacketMaxLength = 40
)
Variables ¶
View Source
var ( ErrStateInvalid = fmt.Errorf("CRITICAL code error state=invalid") ErrStateError = fmt.Errorf("state=error") )
View Source
var ( ErrNak = fmt.Errorf("MDB NAK") ErrBusy = fmt.Errorf("MDB busy") ErrTimeout = fmt.Errorf("MDB timeout") )
View Source
var ( ErrPacketOverflow = errors.New("mdb: operation larger than max packet size") ErrPacketReadonly = errors.New("mdb: packet is readonly") PacketEmpty = &Packet{readonly: true} PacketAck = MustPacketFromHex("00", true) PacketNak = MustPacketFromHex("ff", true) PacketRet = MustPacketFromHex("aa", true) )
Functions ¶
func IsResponseTimeout ¶
Types ¶
type Bus ¶
func (*Bus) ResetDefault ¶
type Device ¶
type Device struct { LastOk *atomic_clock.Clock // last successful tx(), 0 at init, monotonic LastOff *atomic_clock.Clock // last change from online to offline (MDB timeout), 0=online Log *log2.Log Address uint8 ByteOrder binary.ByteOrder PacketReset Packet PacketSetup Packet PacketPoll Packet DoReset engine.Doer DoInit engine.Doer // likely Seq starting with DoReset DelayAfterReset time.Duration DelayBeforeReset time.Duration DelayIdle time.Duration DelayNext time.Duration DelayOffline time.Duration IdleThreshold time.Duration SetupResponse Packet // contains filtered or unexported fields }
func (*Device) Locked_TxKnown ¶
Please make sure it is called under cmdLk or don't use it.
func (*Device) NewFunLoop ¶
Call `fun` until `timeout` or it returns stop=true or error.
func (*Device) NewPollLoop ¶
func (dev *Device) NewPollLoop(tag string, request Packet, timeout time.Duration, fun PollRequestFunc) engine.Doer
Send `request` packets until `timeout` or `fun` returns stop=true or error.
func (*Device) SetState ¶
func (dev *Device) SetState(new DeviceState)
func (*Device) State ¶
func (dev *Device) State() DeviceState
func (*Device) TxKnown ¶
Command is known to be supported, MDB timeout means remote is offline. RESET if appropriate.
func (*Device) TxMaybe ¶
Remote may ignore command with MDB timeout. state=Offline -> RESET state.Ok() required
func (*Device) ValidateErrorCode ¶
func (*Device) ValidateOnline ¶
func (*Device) XXX_FIXME_SetAllDelays ¶
Used by tests to avoid waiting.
type DeviceState ¶
type DeviceState uint32
const ( DeviceInvalid DeviceState = iota // new, not usable DeviceInited // after Init(), usable for Probe DeviceOnline // Probe success, calibration may be required DeviceReady // "ready for useful work", with RESET, configure, calibration done DeviceError // responds but doesn't work well DeviceOffline // does not respond )
func (DeviceState) Ok ¶
func (s DeviceState) Ok() bool
func (DeviceState) Online ¶
func (s DeviceState) Online() bool
func (DeviceState) String ¶
func (i DeviceState) String() string
type FeatureNotSupported ¶
type FeatureNotSupported string
func (FeatureNotSupported) Error ¶
func (fns FeatureNotSupported) Error() string
type InvalidChecksum ¶
func (InvalidChecksum) Error ¶
func (ic InvalidChecksum) Error() string
type MockUart ¶
type MockUart struct {
// contains filtered or unexported fields
}
func MockFromContext ¶
sorry for this ugly convolution working around import cycle on a time budget
func NewMockUart ¶
type Packet ¶
type Packet struct {
// contains filtered or unexported fields
}
func MustPacketFromBytes ¶
func MustPacketFromHex ¶
type PollDelay ¶
type PollDelay struct {
// contains filtered or unexported fields
}
"Idle mode" polling, runs forever until receive on `stopch`. Switches between fast/idle delays. Used by bill/coin devices.
type PollRequestFunc ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package bill incapsulates work with bill validators.
|
Package bill incapsulates work with bill validators. |
Separate package to for hardware/mdb related config structure.
|
Separate package to for hardware/mdb related config structure. |
Package evend incapsulates common parts of MDB protocol for eVend machine devices like conveyor, hopper, cup dispenser, elevator, etc.
|
Package evend incapsulates common parts of MDB protocol for eVend machine devices like conveyor, hopper, cup dispenser, elevator, etc. |
config
Separate package to for hardware/evend related config structure.
|
Separate package to for hardware/evend related config structure. |
Click to show internal directories.
Click to hide internal directories.