All checks were successful
continuous-integration/drone/push Build is passing
159 lines
4.1 KiB
Go
159 lines
4.1 KiB
Go
package mk2driver
|
|
|
|
import "time"
|
|
|
|
type Led int
|
|
|
|
const (
|
|
LedMain Led = iota
|
|
LedAbsorption
|
|
LedBulk
|
|
LedFloat
|
|
LedInverter
|
|
LedOverload
|
|
LedLowBattery
|
|
LedTemperature
|
|
)
|
|
|
|
var LedNames = map[Led]string{
|
|
LedTemperature: "led_over_temp",
|
|
LedLowBattery: "led_bat_low",
|
|
LedOverload: "led_overload",
|
|
LedInverter: "led_inverter",
|
|
LedFloat: "led_float",
|
|
LedBulk: "led_bulk",
|
|
LedAbsorption: "led_absorb",
|
|
LedMain: "led_mains",
|
|
}
|
|
|
|
type LEDstate int
|
|
|
|
const (
|
|
LedOff LEDstate = iota
|
|
LedOn
|
|
LedBlink
|
|
)
|
|
|
|
var StateNames = map[LEDstate]string{
|
|
LedOff: "off",
|
|
LedOn: "on",
|
|
LedBlink: "blink",
|
|
}
|
|
|
|
type Mk2Info struct {
|
|
// Will be marked as false if an error is detected.
|
|
Valid bool
|
|
|
|
Version uint32
|
|
|
|
BatVoltage float64
|
|
// Positive current == charging
|
|
// Negative current == discharging
|
|
BatCurrent float64
|
|
|
|
// Input AC parameters
|
|
InVoltage float64
|
|
InCurrent float64
|
|
InFrequency float64
|
|
|
|
// Output AC parameters
|
|
OutVoltage float64
|
|
OutCurrent float64
|
|
OutFrequency float64
|
|
|
|
// Charge state 0.0 to 1.0
|
|
ChargeState float64
|
|
|
|
// List LEDs
|
|
LEDs map[Led]LEDstate
|
|
|
|
Errors []error
|
|
|
|
Timestamp time.Time
|
|
}
|
|
|
|
type Mk2 interface {
|
|
C() chan *Mk2Info
|
|
Close()
|
|
}
|
|
|
|
type PanelSwitchState byte
|
|
|
|
const (
|
|
// PanelSwitchChargerOnly enables charging only.
|
|
PanelSwitchChargerOnly PanelSwitchState = 0x01
|
|
// PanelSwitchInverterOnly enables inverter output and disables charging.
|
|
PanelSwitchInverterOnly PanelSwitchState = 0x02
|
|
// PanelSwitchOn enables both inverter and charger.
|
|
PanelSwitchOn PanelSwitchState = 0x03
|
|
// PanelSwitchOff disables inverter and charger.
|
|
PanelSwitchOff PanelSwitchState = 0x04
|
|
)
|
|
|
|
type SettingsWriter interface {
|
|
// WriteRAMVar writes a signed 16-bit value to a RAM variable id.
|
|
WriteRAMVar(id uint16, value int16) error
|
|
// WriteSetting writes a signed 16-bit value to a setting id.
|
|
WriteSetting(id uint16, value int16) error
|
|
// SetPanelState sends the MK2 "S" command using a virtual panel switch state.
|
|
// If currentLimitA is nil, the command does not update the AC current limit.
|
|
SetPanelState(switchState PanelSwitchState, currentLimitA *float64) error
|
|
// SetStandby configures the remote panel standby line.
|
|
// When enabled, the inverter is prevented from sleeping while switched off.
|
|
SetStandby(enabled bool) error
|
|
}
|
|
|
|
type DeviceState byte
|
|
|
|
const (
|
|
// DeviceStateChargerOnly enables charging only.
|
|
DeviceStateChargerOnly DeviceState = 0x02
|
|
// DeviceStateInverterOnly enables inverter output and disables charging.
|
|
DeviceStateInverterOnly DeviceState = 0x03
|
|
// DeviceStateOn enables both inverter and charger.
|
|
DeviceStateOn DeviceState = 0x04
|
|
// DeviceStateOff disables inverter and charger.
|
|
DeviceStateOff DeviceState = 0x05
|
|
)
|
|
|
|
var DeviceStateNames = map[DeviceState]string{
|
|
DeviceStateChargerOnly: "charger_only",
|
|
DeviceStateInverterOnly: "inverter_only",
|
|
DeviceStateOn: "on",
|
|
DeviceStateOff: "off",
|
|
}
|
|
|
|
type RAMVarInfo struct {
|
|
ID uint16
|
|
Scale int16
|
|
Offset int16
|
|
Factor float64
|
|
Signed bool
|
|
Supported bool
|
|
}
|
|
|
|
// ProtocolControl exposes protocol 3.14 command paths for direct MK2 control.
|
|
type ProtocolControl interface {
|
|
SettingsWriter
|
|
// GetDeviceState returns the current VE.Bus state using command 0x0E.
|
|
GetDeviceState() (DeviceState, error)
|
|
// SetDeviceState sets the VE.Bus state using command 0x0E.
|
|
SetDeviceState(state DeviceState) error
|
|
// ReadRAMVarByID reads a RAM variable via command 0x30.
|
|
ReadRAMVarByID(id uint16) (int16, error)
|
|
// ReadSettingByID reads a setting via command 0x31.
|
|
ReadSettingByID(id uint16) (int16, error)
|
|
// SelectRAMVar selects a RAM variable for follow-up read-selected/write-selected paths.
|
|
SelectRAMVar(id uint16) error
|
|
// SelectSetting selects a setting for follow-up read-selected/write-selected paths.
|
|
SelectSetting(id uint16) error
|
|
// ReadSelected reads the currently selected value via command 0x35.
|
|
ReadSelected() (int16, error)
|
|
// ReadRAMVarInfo reads RAM variable metadata via command 0x36.
|
|
ReadRAMVarInfo(id uint16) (RAMVarInfo, error)
|
|
// WriteSettingByID writes a setting via command 0x37.
|
|
WriteSettingByID(id uint16, value int16) error
|
|
// WriteRAMVarByID writes a RAM variable via command 0x38.
|
|
WriteRAMVarByID(id uint16, value int16) error
|
|
}
|