Documentation
¶
Overview ¶
Package fakebms is an in-process emulator of a Voltgo battery BMS for testing. It implements the voltgo.Transport interface and speaks the same Modbus RTU frames as the real device, including its signature failure mode: requests with a bad CRC are silently dropped, which the caller observes as a timeout.
Index ¶
- Variables
- type Device
- func (d *Device) CorruptNextResponse()
- func (d *Device) Disconnect() error
- func (d *Device) DropNext(n int)
- func (d *Device) DropRequestsFor(startReg uint16)
- func (d *Device) IsConnected() bool
- func (d *Device) LoadRegisters(start uint16, values []uint16)
- func (d *Device) Request(_ context.Context, frame []byte, _ time.Duration) ([]byte, error)
- func (d *Device) RespondException(code byte)
- func (d *Device) SetRegister(reg, value uint16)
- func (d *Device) TruncateNextResponse()
Constants ¶
This section is empty.
Variables ¶
var LiveDeviceInfoRegisters = []uint16{
0x5443, 0x0000, 0x2d38, 0x5331, 0x3030, 0x2d56, 0x312e, 0x3000,
0x0000, 0x0000, 0x0000, 0x0000, 0x5a30, 0x3154, 0x3230, 0x3230,
0x3234, 0x2d30, 0x312d, 0x3131, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
}
LiveDeviceInfoRegisters is the ASCII device-info block (registers 105-136) from the same battery: "TC", "-8S100-V1.0", serial/date block.
var LiveStatusRegisters = []uint16{
2683,
0,
3350, 3352, 3353, 3356, 3359, 3356, 3355, 3355,
0, 0, 0, 0, 0, 0, 0, 0,
27, 27, 27,
99, 100, 100, 99,
0, 0, 0, 0,
2, 0,
0x1575, 0x2a00, 0x1b1b,
0, 0,
8,
1000,
0, 0, 0,
}
LiveStatusRegisters is the status block (registers 0-40) captured from a ZT-25.6V100Ah battery: 8S LiFePO4, idle at ~100% SOC, 26.83V pack voltage. It matches the frame corpus in protocol/testdata.
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device emulates a battery BMS behind a request/response transport. The zero value is not usable; construct with New.
func New ¶
func New() *Device
New returns a Device preloaded with the register image of an idle ZT-25.6V100Ah battery (see LiveStatusRegisters and LiveDeviceInfoRegisters).
func (*Device) CorruptNextResponse ¶
func (d *Device) CorruptNextResponse()
CorruptNextResponse flips a byte in the next response so its CRC is invalid.
func (*Device) Disconnect ¶
Disconnect implements voltgo.Transport.
func (*Device) DropNext ¶
DropNext makes the device silently ignore the next n requests, as the real BMS does for malformed frames. The caller sees ble.ErrTimeout.
func (*Device) DropRequestsFor ¶
DropRequestsFor makes the device silently ignore any request whose start register is startReg (e.g. protocol.DeviceInfoStart to fail only the device-info read while status reads keep working).
func (*Device) IsConnected ¶
IsConnected implements voltgo.Transport.
func (*Device) LoadRegisters ¶
LoadRegisters writes a block of register values starting at start.
func (*Device) Request ¶
Request implements voltgo.Transport. It decodes the request frame exactly as the device would and returns the matching response frame.
func (*Device) RespondException ¶
RespondException makes the device answer the next request with a Modbus exception response carrying the given code.
func (*Device) SetRegister ¶
SetRegister sets a single register value.
func (*Device) TruncateNextResponse ¶
func (d *Device) TruncateNextResponse()
TruncateNextResponse cuts the next response off mid-payload.