Documentation
¶
Index ¶
- Constants
- Variables
- func AppendCRC(frame []byte) []byte
- func CRC16(data []byte) uint16
- func NewReadRequest(slaveAddr byte, startReg, count uint16) []byte
- func ParseReadResponse(frame []byte, slaveAddr byte) ([]uint16, error)
- func VerifyCRC(frame []byte) bool
- type BMSInfo
- type DeviceInfo
- type ModbusError
Constants ¶
const ( DefaultSlaveAddr = 0x01 FuncReadHoldingRegisters = 0x03 )
The batteries speak Modbus RTU framed over BLE GATT writes. A request is a standard Modbus read-holding-registers frame written to the write characteristic; the response arrives as a single notification on the notify characteristic. Frames with an invalid CRC are silently ignored by the BMS.
const ( RegVoltage = 0 // pack voltage, 0.01 V RegCurrent = 1 // pack current, int16, 0.1 A (sign/scale unverified: always 0 at idle so far) RegCellBase = 2 // cell voltages, 1 mV, 16 slots (regs 2-17) RegTempBase = 18 // temperature sensors, int16 °C, 3 slots (regs 18-20) RegSOC = 21 // state of charge, % (regs 21/24 track together; 21 assumed SOC) RegSOH = 22 // state of health, % (regs 22/23 track together; 22 assumed SOH) RegCellCount = 36 // number of cells in series RegFullCapacity = 37 // full capacity, 0.1 Ah // StatusRegisterCount is the number of registers the Voltgo app requests // for a status poll (read 0x29 registers from address 0). StatusRegisterCount = 41 // DeviceInfoStart/Count cover the ASCII device-info block (model, // hardware version, manufacture date as NUL-padded strings). DeviceInfoStart = 105 DeviceInfoCount = 32 )
Register map for the status block (holding registers 0-40). Derived from live reads of ZT-25.6V100Ah batteries; entries marked "unverified" have not been observed at a non-trivial value yet.
Variables ¶
Functions ¶
func AppendCRC ¶
AppendCRC returns frame with its CRC-16/MODBUS appended (low byte first, per Modbus RTU convention).
func NewReadRequest ¶
NewReadRequest builds a read-holding-registers request frame. Register addresses and counts are big-endian per Modbus RTU.
func ParseReadResponse ¶
ParseReadResponse validates a read-holding-registers response frame and returns the register values.
Types ¶
type BMSInfo ¶
type BMSInfo struct {
Voltage float64 // pack voltage in volts
Current float64 // pack current in amps (positive=charge, negative=discharge)
CellVoltages []float64 // per-cell voltages in volts
CellCount int // number of cells in series
SOC int // state of charge, percent
SOH int // state of health, percent
Temperatures []int // temperature sensor readings in °C
FullCapacityAh float64 // full capacity in Ah
RawRegisters []uint16 // complete register block for fields not yet mapped
}
BMSInfo contains battery management system data parsed from the status register block.
func ParseBMSInfo ¶
ParseBMSInfo parses the status register block (registers 0-40).
type DeviceInfo ¶
type DeviceInfo struct {
Strings []string // NUL-separated ASCII fields, e.g. model, hw version, date
}
DeviceInfo contains the ASCII identity strings from the device-info register block.
func ParseDeviceInfo ¶
func ParseDeviceInfo(regs []uint16) *DeviceInfo
ParseDeviceInfo extracts printable ASCII fields from the device-info register block (registers 105+).
type ModbusError ¶
ModbusError is a Modbus exception response from the device.
func (*ModbusError) Error ¶
func (e *ModbusError) Error() string