Skip to content

Commit

Permalink
fix(plc4go/cbus): fixed detection of server error
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 10, 2022
1 parent 0a1817b commit 5fc5d28
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions plc4go/internal/cbus/MessageCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ func (m *MessageCodec) Receive() (spi.Message, error) {
// Fill the buffer
{
if err := ti.FillBuffer(func(_ uint, currentByte byte, reader *bufio.Reader) bool {
hitCr := currentByte == '\r'
if hitCr {
// Make sure we peek one more
_, _ = reader.Peek(1)
switch currentByte {
case '\r':
fallthrough
case '!':
return false
default:
return true
}
return true
}); err != nil {
return nil, err
}
Expand All @@ -130,7 +131,7 @@ func (m *MessageCodec) Receive() (spi.Message, error) {
}

// Check for an isolated error
if bytes, err := ti.PeekReadableBytes(1); err != nil && (bytes[0] == '!') {
if bytes, err := ti.PeekReadableBytes(1); err == nil && (bytes[0] == '!') {
_, _ = ti.Read(1)
return readwriteModel.CBusMessageParse(utils.NewReadBufferByteBased(bytes), true, m.requestContext, m.cbusOptions)
}
Expand Down

0 comments on commit 5fc5d28

Please sign in to comment.