Add optional debug logging for frame decoding.
This commit is contained in:
@@ -27,10 +27,8 @@ Usage:
|
||||
invertergui [OPTIONS]
|
||||
|
||||
Application Options:
|
||||
--address= The IP/DNS and port of the machine that the application is running on. (default: :8080)
|
||||
[$ADDRESS]
|
||||
--data.source= Set the source of data for the inverter gui. "serial", "tcp" or "mock" (default: serial)
|
||||
[$DATA_SOURCE]
|
||||
--address= The IP/DNS and port of the machine that the application is running on. (default: :8080) [$ADDRESS]
|
||||
--data.source= Set the source of data for the inverter gui. "serial", "tcp" or "mock" (default: serial) [$DATA_SOURCE]
|
||||
--data.host= Host to connect when source is set to tcp. (default: localhost:8139) [$DATA_HOST]
|
||||
--data.device= TTY device to use when source is set to serial. (default: /dev/ttyUSB0) [$DATA_DEVICE]
|
||||
--cli.enabled Enable CLI output. [$CLI_ENABLED]
|
||||
@@ -40,6 +38,7 @@ Application Options:
|
||||
--mqtt.topic= Set the MQTT topic updates published to. (default: invertergui/updates) [$MQTT_TOPIC]
|
||||
--mqtt.username= Set the MQTT username [$MQTT_USERNAME]
|
||||
--mqtt.password= Set the MQTT password [$MQTT_PASSWORD]
|
||||
--loglevel= The log level to generate logs at. ("panic", "fatal", "error", "warn", "info", "debug", "trace") (default: info) [$LOGLEVEL]
|
||||
|
||||
Help Options:
|
||||
-h, --help Show this help message
|
||||
|
||||
@@ -22,6 +22,7 @@ type config struct {
|
||||
Username string `long:"mqtt.username" env:"MQTT_USERNAME" default:"" description:"Set the MQTT username"`
|
||||
Password string `long:"mqtt.password" env:"MQTT_PASSWORD" default:"" description:"Set the MQTT password"`
|
||||
}
|
||||
Loglevel string `long:"loglevel" env:"LOGLEVEL" default:"info" description:"The log level to generate logs at. (\"panic\", \"fatal\", \"error\", \"warn\", \"info\", \"debug\", \"trace\")"`
|
||||
}
|
||||
|
||||
func parseConfig() (*config, error) {
|
||||
|
||||
@@ -58,6 +58,11 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
log.Info("Starting invertergui")
|
||||
logLevel, err := logrus.ParseLevel(conf.Loglevel)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not parse log level: %v", err)
|
||||
}
|
||||
logrus.SetLevel(logLevel)
|
||||
|
||||
mk2, err := getMk2Device(conf.Data.Source, conf.Data.Host, conf.Data.Device)
|
||||
if err != nil {
|
||||
|
||||
@@ -183,6 +183,7 @@ func (m *mk2Ser) updateReport() {
|
||||
|
||||
// Checks for valid frame and chooses decoding.
|
||||
func (m *mk2Ser) handleFrame(l byte, frame []byte) {
|
||||
logrus.Debugf("frame %#v", frame)
|
||||
if checkChecksum(l, frame[0], frame[1:]) {
|
||||
switch frame[0] {
|
||||
case frameHeader:
|
||||
@@ -243,7 +244,7 @@ func int16Abs(in int16) uint16 {
|
||||
// Decode the scale factor frame.
|
||||
func (m *mk2Ser) scaleDecode(frame []byte) {
|
||||
tmp := scaling{}
|
||||
logrus.Infof("Scale frame(%d): 0x%x", len(frame), frame)
|
||||
logrus.Debugf("Scale frame(%d): 0x%x", len(frame), frame)
|
||||
if len(frame) < 6 {
|
||||
tmp.supported = false
|
||||
logrus.Warnf("Skiping scaling factors for: %d", m.scaleCount)
|
||||
@@ -269,6 +270,7 @@ func (m *mk2Ser) scaleDecode(frame []byte) {
|
||||
tmp.scale = float64(scale)
|
||||
}
|
||||
}
|
||||
logrus.Debugf("scalecount %v: %#v \n", m.scaleCount, tmp)
|
||||
m.scales = append(m.scales, tmp)
|
||||
m.scaleCount++
|
||||
if m.scaleCount < ramVarMaxOffset {
|
||||
@@ -280,6 +282,7 @@ func (m *mk2Ser) scaleDecode(frame []byte) {
|
||||
|
||||
// Decode the version number
|
||||
func (m *mk2Ser) versionDecode(frame []byte) {
|
||||
logrus.Debugf("versiondecode %v", frame)
|
||||
m.info.Version = 0
|
||||
m.info.Valid = true
|
||||
for i := 0; i < 4; i++ {
|
||||
@@ -344,6 +347,7 @@ func (m *mk2Ser) dcDecode(frame []byte) {
|
||||
m.info.BatCurrent = usedC - chargeC
|
||||
|
||||
m.info.OutFrequency = 10 / (m.applyScale(float64(frame[13]), ramVarInverterPeriod))
|
||||
logrus.Debugf("dcDecode %#v", m.info)
|
||||
|
||||
// Send L1 status request
|
||||
cmd := make([]byte, 2)
|
||||
@@ -364,6 +368,7 @@ func (m *mk2Ser) acDecode(frame []byte) {
|
||||
} else {
|
||||
m.info.InFrequency = 10 / (m.applyScale(float64(frame[13]), ramVarMainPeriod))
|
||||
}
|
||||
logrus.Debugf("acDecode %#v", m.info)
|
||||
|
||||
// Send status request
|
||||
cmd := make([]byte, 1)
|
||||
@@ -374,6 +379,7 @@ func (m *mk2Ser) acDecode(frame []byte) {
|
||||
// Decode charge state of battery.
|
||||
func (m *mk2Ser) stateDecode(frame []byte) {
|
||||
m.info.ChargeState = m.applyScaleAndSign(frame[1:3], ramVarChargeState)
|
||||
logrus.Debugf("battery state decode %#v", m.info)
|
||||
m.updateReport()
|
||||
}
|
||||
|
||||
@@ -420,6 +426,7 @@ func (m *mk2Ser) sendCommand(data []byte) {
|
||||
}
|
||||
dataOut[l+2] = cr
|
||||
|
||||
logrus.Debugf("sendCommand %#v", dataOut)
|
||||
_, err := m.p.Write(dataOut)
|
||||
if err != nil {
|
||||
m.addError(fmt.Errorf("Write error: %v", err))
|
||||
|
||||
Reference in New Issue
Block a user