Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MK2 frames handling #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions mk2driver/mk2.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ const (
)

const (
infoFrameHeader = 0x20
frameHeader = 0xff
infoFrameHeader = 0x20
frameHeader = 0xff
bootupFrameHeader = 0x0
)

const (
Expand Down Expand Up @@ -164,6 +165,7 @@ func (m *mk2Ser) readByte() byte {

// Adds error to error slice.
func (m *mk2Ser) addError(err error) {
logrus.Errorf("Mk2 serial slice error: %q", err.Error())
if m.info.Errors == nil {
m.info.Errors = make([]error, 0)
}
Expand All @@ -183,9 +185,11 @@ func (m *mk2Ser) updateReport() {

// Checks for valid frame and chooses decoding.
func (m *mk2Ser) handleFrame(l byte, frame []byte) {
logrus.Debugf("frame %#v", frame)
logrus.Debugf("[handleFrame] frame %#v", frame)
if checkChecksum(l, frame[0], frame[1:]) {
switch frame[0] {
case bootupFrameHeader:
m.setTarget()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setTarget() is only executed once at startup of invertergui process. this make sure it's executed everytime Victron is started even if invertergui is running while it happens

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should be all

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "should be all" ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I responded to this comment but in the wrong thread :D #44 (comment)

case frameHeader:
switch frame[1] {
case vFrame:
Expand All @@ -196,10 +200,14 @@ func (m *mk2Ser) handleFrame(l byte, frame []byte) {
m.scaleDecode(frame[2:])
case commandReadRAMResponse:
m.stateDecode(frame[2:])
default:
logrus.Warnf("[handleFrame] invalid winmonFrame %v", frame[2:])
}

case ledFrame:
m.ledDecode(frame[2:])
default:
logrus.Warnf("[handleFrame] invalid frameHeader %v", frame[1])
}

case infoFrameHeader:
Expand All @@ -208,10 +216,14 @@ func (m *mk2Ser) handleFrame(l byte, frame []byte) {
m.dcDecode(frame[1:])
case acL1InfoFrame:
m.acDecode(frame[1:])
default:
logrus.Warnf("[handleFrame] invalid infoFrameHeader %v", frame[5])
}
default:
logrus.Warnf("[handleFrame] Invalid frame %v", frame[0])
}
} else {
logrus.Errorf("Invalid incoming frame checksum: %x", frame)
logrus.Errorf("[handleFrame] Invalid incoming frame checksum: %x", frame)
m.frameLock = false
}
}
Expand Down