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

Support for OPC-UA event subscriptions #1731

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions plc4go/assets/testing/protocols/ads/DriverTestsuite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,18 @@
</PlcResponseItem>
</hurz>
</values>
<metadata isList="true">
<hurz>
<entry>
<key dataType="string" bitLength="17" encoding="UTF-8">receive_timestamp</key>
<value dataType="string" bitLength="13" encoding="UTF-8" plc4x-skip-comparison="true">0</value>
</entry>
<entry>
<key dataType="string" bitLength="16" encoding="UTF-8">timestamp_source</key>
<value dataType="string" bitLength="10" encoding="UTF-8">ASSUMPTION</value>
</entry>
</hurz>
</metadata>
</PlcReadResponse>
</api-response>
</steps>
Expand Down
2,081 changes: 2,014 additions & 67 deletions plc4go/assets/testing/protocols/opcua/DriverTestsuite.xml

Large diffs are not rendered by default.

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
Loading