Skip to content

Commit

Permalink
fix(plc4go/opcua): OPC-UA driver updates and checkin of generated code.
Browse files Browse the repository at this point in the history
Signed-off-by: Łukasz Dywicki <[email protected]>
  • Loading branch information
splatch committed Nov 6, 2024
1 parent 9d2b947 commit 40a3bc8
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 239 deletions.
4 changes: 2 additions & 2 deletions plc4go/internal/opcua/EncryptionHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (h *EncryptionHandler) encodeMessage(ctx context.Context, pdu readWriteMode
numberOfBlocks := preEncryptedLength / PREENCRYPTED_BLOCK_LENGTH
encryptedLength := numberOfBlocks*256 + positionFirstBlock
buf := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.LittleEndian))
if err := readWriteModel.NewOpcuaAPU(pdu, false).SerializeWithWriteBuffer(ctx, buf); err != nil {
if err := readWriteModel.NewOpcuaAPU(pdu, false, true).SerializeWithWriteBuffer(ctx, buf); err != nil {
return nil, errors.Wrap(err, "error serializing")
}
paddingByte := byte(paddingSize)
Expand Down Expand Up @@ -168,7 +168,7 @@ func (h *EncryptionHandler) decodeMessage(ctx context.Context, pdu readWriteMode
}

readBuffer := utils.NewReadBufferByteBased(buf.GetBytes(), utils.WithByteOrderForReadBufferByteBased(binary.LittleEndian))
return readWriteModel.OpcuaAPUParseWithBuffer(ctx, readBuffer, true)
return readWriteModel.OpcuaAPUParseWithBuffer(ctx, readBuffer, true, true)
default:
h.log.Trace().Msg("unmapped security policy")
return pdu, nil
Expand Down
4 changes: 2 additions & 2 deletions plc4go/internal/opcua/MessageCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (m *MessageCodec) Send(message spi.Message) error {
opcuaApu, ok := message.(readWriteModel.OpcuaAPU)
if !ok {
if message, ok := message.(readWriteModel.MessagePDU); ok {
opcuaApu = readWriteModel.NewOpcuaAPU(message, false)
opcuaApu = readWriteModel.NewOpcuaAPU(message, false, true)
} else {
return errors.Errorf("Invalid message type %T", message)
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (m *MessageCodec) Receive() (spi.Message, error) {
}
ctxForModel := options.GetLoggerContextForModel(context.Background(), m.log, options.WithPassLoggerToModel(m.passLogToModel))
rbbb := utils.NewReadBufferByteBased(readBytes, utils.WithByteOrderForReadBufferByteBased(binary.LittleEndian))
opcuaAPU, err := readWriteModel.OpcuaAPUParseWithBuffer(ctxForModel, rbbb, true)
opcuaAPU, err := readWriteModel.OpcuaAPUParseWithBuffer(ctxForModel, rbbb, true, true)
if err != nil {
return nil, errors.New("Could not parse pdu")
}
Expand Down
21 changes: 5 additions & 16 deletions plc4go/internal/opcua/Reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"context"
"encoding/binary"
"runtime/debug"
"strconv"

"github.com/pkg/errors"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -73,7 +72,7 @@ func (m *Reader) readSync(ctx context.Context, readRequest apiModel.PlcReadReque
REQUEST_TIMEOUT_LONG,
NULL_EXTENSION_OBJECT,
)
readValueArray := make([]readWriteModel.ExtensionObjectDefinition, len(readRequest.GetTagNames()))
readValueArray := make([]readWriteModel.ReadValueId, len(readRequest.GetTagNames()))
for i, tagName := range readRequest.GetTagNames() {
tag := readRequest.GetTag(tagName).(Tag)

Expand All @@ -94,35 +93,25 @@ func (m *Reader) readSync(ctx context.Context, readRequest apiModel.PlcReadReque
requestHeader,
0.0,
readWriteModel.TimestampsToReturn_timestampsToReturnNeither,
int32(len(readValueArray)),
readValueArray)

identifier, err := strconv.ParseUint(opcuaReadRequest.GetIdentifier(), 10, 16)
if err != nil {
result <- spiModel.NewDefaultPlcReadRequestResult(readRequest, nil, errors.Wrapf(err, "error parsing identifier"))
return
}

identifier := opcuaReadRequest.GetExtensionId()
expandedNodeId := readWriteModel.NewExpandedNodeId(false, //Namespace Uri Specified
false, //Server Index Specified
readWriteModel.NewNodeIdFourByte(0, uint16(identifier)),
nil,
nil)

extObject := readWriteModel.NewExtensionObject(
expandedNodeId,
nil,
opcuaReadRequest,
false)
extObject := readWriteModel.NewExtensiblePayload(nil, readWriteModel.NewRootExtensionObject(expandedNodeId, opcuaReadRequest, identifier), 0)

buffer := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.LittleEndian))
if err = extObject.SerializeWithWriteBuffer(ctx, buffer); err != nil {
if err := extObject.SerializeWithWriteBuffer(ctx, buffer); err != nil {
result <- spiModel.NewDefaultPlcReadRequestResult(readRequest, nil, errors.Wrapf(err, "Unable to serialise the ReadRequest"))
return
}

consumer := func(opcuaResponse []byte) {
reply, err := readWriteModel.ExtensionObjectParseWithBuffer(ctx, utils.NewReadBufferByteBased(opcuaResponse, utils.WithByteOrderForReadBufferByteBased(binary.LittleEndian)), false)
reply, err := readWriteModel.ExtensionObjectParseWithBuffer[readWriteModel.ExtensionObject](ctx, utils.NewReadBufferByteBased(opcuaResponse, utils.WithByteOrderForReadBufferByteBased(binary.LittleEndian)), false)
if err != nil {
result <- spiModel.NewDefaultPlcReadRequestResult(readRequest, nil, errors.Wrapf(err, "Unable to read the reply"))
return
Expand Down
Loading

0 comments on commit 40a3bc8

Please sign in to comment.