You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/08/10 14:59:24 UTC
[plc4x] branch develop updated: feat(plc4go/cbus): fixed handling single confirmations
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 0b222b02b feat(plc4go/cbus): fixed handling single confirmations
0b222b02b is described below
commit 0b222b02b59d377e587f7aa98a60668f73a96b49
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Aug 10 16:59:17 2022 +0200
feat(plc4go/cbus): fixed handling single confirmations
---
plc4go/internal/cbus/MessageCodec.go | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)
diff --git a/plc4go/internal/cbus/MessageCodec.go b/plc4go/internal/cbus/MessageCodec.go
index dffd970df..9d3a767b2 100644
--- a/plc4go/internal/cbus/MessageCodec.go
+++ b/plc4go/internal/cbus/MessageCodec.go
@@ -99,13 +99,23 @@ func (m *MessageCodec) Send(message spi.Message) error {
func (m *MessageCodec) Receive() (spi.Message, error) {
ti := m.GetTransportInstance()
+ confirmation := false
// Fill the buffer
{
if err := ti.FillBuffer(func(_ uint, currentByte byte, reader *bufio.Reader) bool {
switch currentByte {
- case '\r':
- fallthrough
- case '!':
+ case
+ readwriteModel.ResponseTermination_CR,
+ readwriteModel.ResponseTermination_LF:
+ return false
+ case
+ byte(readwriteModel.ConfirmationType_CONFIRMATION_SUCCESSFUL),
+ byte(readwriteModel.ConfirmationType_NOT_TRANSMITTED_TO_MANY_RE_TRANSMISSIONS),
+ byte(readwriteModel.ConfirmationType_NOT_TRANSMITTED_CORRUPTION),
+ byte(readwriteModel.ConfirmationType_NOT_TRANSMITTED_SYNC_LOSS),
+ byte(readwriteModel.ConfirmationType_NOT_TRANSMITTED_TOO_LONG),
+ byte(readwriteModel.ConfirmationType_CHECKSUM_FAILURE):
+ confirmation = true
return false
default:
return true
@@ -131,19 +141,29 @@ 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] == byte(readwriteModel.ConfirmationType_CHECKSUM_FAILURE)) {
_, _ = ti.Read(1)
return readwriteModel.CBusMessageParse(utils.NewReadBufferByteBased(bytes), true, m.requestContext, m.cbusOptions)
}
- // TODO: we might get a simple confirmation like g# without anything other... so we might need to handle that
peekedBytes, err := ti.PeekReadableBytes(readableBytes)
pciResponse, requestToPci := false, false
indexOfCR := -1
indexOfLF := -1
+ indexOfConfirmation := -1
lookingForTheEnd:
for i, peekedByte := range peekedBytes {
switch peekedByte {
+ case
+ byte(readwriteModel.ConfirmationType_CONFIRMATION_SUCCESSFUL),
+ byte(readwriteModel.ConfirmationType_NOT_TRANSMITTED_TO_MANY_RE_TRANSMISSIONS),
+ byte(readwriteModel.ConfirmationType_NOT_TRANSMITTED_CORRUPTION),
+ byte(readwriteModel.ConfirmationType_NOT_TRANSMITTED_SYNC_LOSS),
+ byte(readwriteModel.ConfirmationType_NOT_TRANSMITTED_TOO_LONG),
+ byte(readwriteModel.ConfirmationType_CHECKSUM_FAILURE):
+ if indexOfConfirmation < 0 {
+ indexOfConfirmation = i
+ }
case '\r':
if indexOfCR >= 0 {
// We found the next <cr> so we know we have a package
@@ -186,7 +206,7 @@ lookingForTheEnd:
}
}
}
- if !pciResponse && !requestToPci {
+ if !pciResponse && !requestToPci && !confirmation {
// Apparently we have not found any message yet
return nil, nil
}
@@ -196,6 +216,9 @@ lookingForTheEnd:
if pciResponse {
packetLength = indexOfLF + 1
}
+ if !pciResponse && !requestToPci {
+ packetLength = indexOfConfirmation + 1
+ }
// Sanity check
if pciResponse && requestToPci {