Documentation
¶
Index ¶
- type Inverter
- func (m *Inverter) Close() error
- func (m *Inverter) Connect() error
- func (m *Inverter) GetRegister(addr uint16) (uint16, bool)
- func (m *Inverter) ReadRegisters(startAddr uint16, count uint16) ([]uint16, error)
- func (m *Inverter) SetRegister(addr, value uint16)
- func (m *Inverter) WriteMultipleRegisters(startAddr uint16, values []uint16) error
- func (m *Inverter) WriteSingleRegister(addr uint16, value uint16) error
- type Sim
- func (s *Sim) ClearFaults()
- func (s *Sim) SetGridVoltage(volts float64)
- func (s *Sim) SetLoad(watts float64)
- func (s *Sim) SetPV(pv1Watts, pv2Watts float64)
- func (s *Sim) SetParallelMode(mode uint16)
- func (s *Sim) SetSOC(pct float64)
- func (s *Sim) Start(interval time.Duration)
- func (s *Sim) Stop()
- func (s *Sim) Tick()
- func (s *Sim) TriggerFault(code uint16)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Inverter ¶
type Inverter struct {
// ReadCount tracks total ReadRegisters calls for test assertions.
ReadCount int
// WriteCount tracks total write calls for test assertions.
WriteCount int
// ReadHook is called on every ReadRegisters call before returning data.
// Return a non-nil error to simulate a device error for that range.
ReadHook func(startAddr, count uint16) error
// WriteHook is called on every write call before committing.
WriteHook func(addr, value uint16) error
// contains filtered or unexported fields
}
Inverter is an in-memory MODBUS device for testing. It implements the modbus.Client interface with a configurable register map.
func NewInverter ¶
NewInverter creates a mock Inverter with the given initial register values.
func (*Inverter) GetRegister ¶
GetRegister reads a register value directly.
func (*Inverter) ReadRegisters ¶
func (*Inverter) SetRegister ¶
SetRegister sets a register value directly (bypasses hooks).
func (*Inverter) WriteMultipleRegisters ¶
type Sim ¶
type Sim struct {
*Inverter
// contains filtered or unexported fields
}
Sim is a live-simulated inverter that ticks internally, updating registers to mimic a real ASP48100U200-H. Embeds Inverter for the modbus.Client interface.
In addition to the time-based background simulation (Start/Tick), Sim supports deterministic "poke" methods (SetSOC, SetPV, SetLoad, etc.) that immediately update all related registers without jitter. This makes Sim usable both as a live simulator and as a deterministic test fixture.
func NewSim ¶
func NewSim() *Sim
NewSim creates a Sim pre-loaded with realistic register values for an ASP48100U200-H (48V LiFePO4, split-phase 120/240V).
func (*Sim) ClearFaults ¶
func (s *Sim) ClearFaults()
ClearFaults resets all fault registers to zero.
func (*Sim) SetGridVoltage ¶
SetGridVoltage sets the grid input voltage (0 = off-grid) and updates registers.
func (*Sim) SetPV ¶
SetPV sets PV1 and PV2 power in watts and updates all related registers. This overrides the time-based PV curve until the next Tick/Start cycle.
func (*Sim) SetParallelMode ¶
SetParallelMode sets the parallel mode register value.
func (*Sim) Start ¶
Start begins the background simulation tick at the given interval. Call Stop() to clean up.
func (*Sim) Tick ¶
func (s *Sim) Tick()
Tick advances the simulation by one step manually (for deterministic tests).
func (*Sim) TriggerFault ¶
TriggerFault queues a fault code to be applied on the next tick.