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
sruehl authored and splatch committed Oct 29, 2024
1 parent d04c188 commit d6e692f
Show file tree
Hide file tree
Showing 2,169 changed files with 46,556 additions and 16,992 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ func (m *_${type.name}) GetTypeName() string {
<#if !type.isDiscriminatedParentTypeDefinition()>
func (m *_${type.name}) GetLengthInBits(ctx context.Context) uint16 {
<#if type.isDiscriminatedChildTypeDefinition()>
lengthInBits := uint16(m.${type.getParentType().orElseThrow().name}Contract.(*_${type.getParentType().orElseThrow().name}).getLengthInBits(ctx))
lengthInBits := uint16(m.${type.getParentType().orElseThrow().name}Contract.(*_${type.getParentType().orElseThrow().name}).GetLengthInBits(ctx))
<#else>
lengthInBits := uint16(0)
</#if>
Expand Down Expand Up @@ -770,7 +770,7 @@ func (m *_${type.name}) GetLengthInBits(ctx context.Context) uint16 {
<#elseif helper.isEnumField(discriminatorField)>
lengthInBits += ${helper.getEnumBaseTypeReference(discriminatorField.type).sizeInBits};
<#else>
lengthInBits += ${discriminatorField.name}.getLengthInBits();
lengthInBits += ${discriminatorField.name}.GetLengthInBits();
</#if>
<#break>
<#case "enum">
Expand Down Expand Up @@ -880,7 +880,7 @@ func (m *_${type.name}) GetLengthInBits(ctx context.Context) uint16 {
</#if>

<#if type.isDiscriminatedParentTypeDefinition()>
func (m *_${type.name}) getLengthInBits(ctx context.Context) uint16 {
func (m *_${type.name}) GetLengthInBits(ctx context.Context) uint16 {
lengthInBits := uint16(0)
<#list type.fields as field>
<#switch field.typeName>
Expand Down
2 changes: 1 addition & 1 deletion plc4go/internal/opcua/Reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (m *Reader) readSync(ctx context.Context, readRequest apiModel.PlcReadReque
nil,
nil)

extObject := readWriteModel.NewExtensiblePayload(readWriteModel.NewRootExtensionObject(opcuaReadRequest, expandedNodeId, identifier), nil, 0)
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 {
Expand Down
50 changes: 27 additions & 23 deletions plc4go/internal/opcua/SecureChannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (
)

var (
SECURITY_POLICY_NONE = readWriteModel.NewPascalString(utils.MakePtr("http://opcfoundation.org/UA/SecurityPolicy#None"))
SECURITY_POLICY_NONE = readWriteModel.NewPascalString(utils.ToPtr("http://opcfoundation.org/UA/SecurityPolicy#None"))
NULL_STRING = readWriteModel.NewPascalString(nil)
NULL_BYTE_STRING = readWriteModel.NewPascalByteString(-1, nil)
NULL_EXPANDED_NODEID = readWriteModel.NewExpandedNodeId(false,
Expand All @@ -65,6 +65,7 @@ var (
nil,
nil,
)
BINARY_ENCODING_MASK = readWriteModel.NewExtensionObjectEncodingMask(false, false, true)
NULL_EXTENSION_OBJECT = readWriteModel.NewNullExtensionObjectWithMask(NULL_EXPANDED_NODEID,
readWriteModel.NewExtensionObjectEncodingMask(false, false, false),
0,
Expand All @@ -73,9 +74,9 @@ var (
INET_ADDRESS_PATTERN = regexp.MustCompile(`(.(?P<transportCode>tcp))?://(?P<transportHost>[\w.-]+)(:(?P<transportPort>\d*))?`)

URI_PATTERN = regexp.MustCompile(`^(?P<protocolCode>opc)` + INET_ADDRESS_PATTERN.String() + `(?P<transportEndpoint>[\w/=]*)[?]?`)
APPLICATION_URI = readWriteModel.NewPascalString(utils.MakePtr("urn:apache:plc4x:client"))
PRODUCT_URI = readWriteModel.NewPascalString(utils.MakePtr("urn:apache:plc4x:client"))
APPLICATION_TEXT = readWriteModel.NewPascalString(utils.MakePtr("OPCUA client for the Apache PLC4X:PLC4J project"))
APPLICATION_URI = readWriteModel.NewPascalString(utils.ToPtr("urn:apache:plc4x:client"))
PRODUCT_URI = readWriteModel.NewPascalString(utils.ToPtr("urn:apache:plc4x:client"))
APPLICATION_TEXT = readWriteModel.NewPascalString(utils.ToPtr("OPCUA client for the Apache PLC4X:PLC4J project"))
DEFAULT_CONNECTION_LIFETIME = uint32(36000000)
)

Expand Down Expand Up @@ -381,8 +382,8 @@ func (s *SecureChannel) onConnectOpenSecureChannel(ctx context.Context, connecti
)

extObject := readWriteModel.NewRootExtensionObject(
openSecureChannelRequest,
expandedNodeId,
openSecureChannelRequest,
identifier,
)

Expand Down Expand Up @@ -505,7 +506,7 @@ func (s *SecureChannel) onConnectCreateSessionRequest(ctx context.Context, conne
applicationName := readWriteModel.NewLocalizedText(
true,
true,
readWriteModel.NewPascalString(utils.MakePtr("en")),
readWriteModel.NewPascalString(utils.ToPtr("en")),
APPLICATION_TEXT)

var discoveryUrls []readWriteModel.PascalString
Expand Down Expand Up @@ -539,8 +540,8 @@ func (s *SecureChannel) onConnectCreateSessionRequest(ctx context.Context, conne
nil)

extObject := readWriteModel.NewRootExtensionObject(
createSessionRequest,
expandedNodeId,
createSessionRequest,
identifier,
)

Expand Down Expand Up @@ -653,8 +654,8 @@ func (s *SecureChannel) onConnectActivateSessionRequest(ctx context.Context, con
nil)

extObject := readWriteModel.NewRootExtensionObject(
activateSessionRequest,
expandedNodeId,
activateSessionRequest,
identifier,
)

Expand Down Expand Up @@ -750,8 +751,8 @@ func (s *SecureChannel) onDisconnect(ctx context.Context, connection *Connection
true)

extObject := readWriteModel.NewRootExtensionObject(
closeSessionRequest,
expandedNodeId,
closeSessionRequest,
closeSessionRequest.GetExtensionId(),
)

Expand Down Expand Up @@ -832,8 +833,8 @@ func (s *SecureChannel) onDisconnectCloseSecureChannel(ctx context.Context, conn
readWriteModel.NewExtensiblePayload(
readWriteModel.NewSequenceHeader(transactionId, transactionId),
readWriteModel.NewRootExtensionObject(
closeSecureChannelRequest,
expandedNodeId,
closeSecureChannelRequest,
identifier,
),
0,
Expand Down Expand Up @@ -973,8 +974,8 @@ func (s *SecureChannel) onDiscoverOpenSecureChannel(ctx context.Context, codec *
)

extObject := readWriteModel.NewRootExtensionObject(
openSecureChannelRequest,
expandedNodeId,
openSecureChannelRequest,
identifier,
)

Expand Down Expand Up @@ -1101,8 +1102,8 @@ func (s *SecureChannel) onDiscoverGetEndpointsRequest(ctx context.Context, codec
)

extObject := readWriteModel.NewRootExtensionObject(
endpointsRequest,
expandedNodeId,
endpointsRequest,
identifier,
)

Expand Down Expand Up @@ -1230,8 +1231,8 @@ func (s *SecureChannel) onDiscoverCloseSecureChannel(ctx context.Context, codec
readWriteModel.NewExtensiblePayload(
readWriteModel.NewSequenceHeader(transactionId, transactionId),
readWriteModel.NewRootExtensionObject(
closeSecureChannelRequest,
expandedNodeId,
closeSecureChannelRequest,
identifier,
),
uint32(0),
Expand Down Expand Up @@ -1337,8 +1338,8 @@ func (s *SecureChannel) keepAlive() {
nil)

extObject := readWriteModel.NewRootExtensionObject(
openSecureChannelRequest,
expandedNodeId,
openSecureChannelRequest,
identifier,
)

Expand Down Expand Up @@ -1560,19 +1561,22 @@ func (s *SecureChannel) getIdentityToken(tokenType readWriteModel.UserTokenType,
switch tokenType {
case readWriteModel.UserTokenType_userTokenTypeAnonymous:
//If we aren't using authentication tell the server we would like to log in anonymously
anonymousIdentityToken := readWriteModel.NewAnonymousIdentityToken(readWriteModel.NewPascalString(policyId))
anonymousIdentityToken, err := readWriteModel.NewAnonymousIdentityTokenBuilder().WithPolicyId(readWriteModel.NewPascalString(policyId)).Build()
if err != nil {
s.log.Error().Err(err).Msg("error creating anonymous authentication token")
return nil
}
extExpandedNodeId := readWriteModel.NewExpandedNodeId(
false, //Namespace Uri Specified
false, //Server Index Specified
readWriteModel.NewNodeIdFourByte(
0, 321 /* TODO: disabled till we have greater segmentation: uint16(readWriteModel.OpcuaNodeIdServices_AnonymousIdentityToken_Encoding_DefaultBinary)*/),
readWriteModel.NewNodeIdFourByte(0, uint16(anonymousIdentityToken.GetExtensionId())),
nil,
nil,
)
return readWriteModel.NewBinaryExtensionObjectWithMask(
anonymousIdentityToken,
extExpandedNodeId,
readWriteModel.NewExtensionObjectEncodingMask(false, false, true),
BINARY_ENCODING_MASK,
anonymousIdentityToken,
anonymousIdentityToken.GetExtensionId(),
false,
)
Expand All @@ -1599,18 +1603,18 @@ func (s *SecureChannel) getIdentityToken(tokenType readWriteModel.UserTokenType,
readWriteModel.NewPascalString(policyId),
readWriteModel.NewPascalString(&s.username),
readWriteModel.NewPascalByteString(int32(len(encryptedPassword)), encryptedPassword),
readWriteModel.NewPascalString(utils.MakePtr(PASSWORD_ENCRYPTION_ALGORITHM)),
readWriteModel.NewPascalString(utils.ToPtr(PASSWORD_ENCRYPTION_ALGORITHM)),
)
extExpandedNodeId := readWriteModel.NewExpandedNodeId(
false, //Namespace Uri Specified
false, //Server Index Specified
readWriteModel.NewNodeIdFourByte(0, 324 /*TODO: disabled till we have greater segmentation: uint16(readWriteModel.OpcuaNodeIdServices_UserNameIdentityToken_Encoding_DefaultBinary)*/),
readWriteModel.NewNodeIdFourByte(0, uint16(userNameIdentityToken.GetExtensionId())),
nil,
nil)
return readWriteModel.NewBinaryExtensionObjectWithMask(
userNameIdentityToken,
extExpandedNodeId,
readWriteModel.NewExtensionObjectEncodingMask(false, false, true),
BINARY_ENCODING_MASK,
userNameIdentityToken,
userNameIdentityToken.GetExtensionId(),
false,
)
Expand Down
10 changes: 7 additions & 3 deletions plc4go/internal/opcua/Subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ func (s *Subscriber) onSubscribeCreateSubscription(ctx context.Context, cycleTim
nil,
nil)

extObject := readWriteModel.NewExtensiblePayload(readWriteModel.NewRootExtensionObject(
createSubscriptionRequest, expandedNodeId, createSubscriptionRequest.GetExtensionId(),
), nil, 0)
extObject := readWriteModel.NewExtensiblePayload(
nil,
readWriteModel.NewRootExtensionObject(
expandedNodeId, createSubscriptionRequest, createSubscriptionRequest.GetExtensionId(),
),
0,
)

buffer := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.LittleEndian))
if err := extObject.SerializeWithWriteBuffer(ctx, buffer); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions plc4go/internal/opcua/SubscriptionHandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func (h *SubscriptionHandle) onSubscribeCreateMonitoredItemsRequest() (readWrite
nil)

extObject := readWriteModel.NewRootExtensionObject(
createMonitoredItemsRequest,
expandedNodeId,
createMonitoredItemsRequest,
identifier,
)

Expand Down Expand Up @@ -273,8 +273,8 @@ func (h *SubscriptionHandle) startSubscriber() {
nil)

extObject := readWriteModel.NewRootExtensionObject(
publishRequest,
extExpandedNodeId,
publishRequest,
identifier,
)

Expand Down Expand Up @@ -384,8 +384,8 @@ func (h *SubscriptionHandle) stopSubscriber() {
)

extObject := readWriteModel.NewRootExtensionObject(
deleteSubscriptionrequest,
extExpandedNodeId,
deleteSubscriptionrequest,
identifier,
)

Expand Down
12 changes: 10 additions & 2 deletions plc4go/internal/opcua/Writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,15 @@ func (m *Writer) WriteSync(ctx context.Context, writeRequest apiModel.PlcWriteRe
nil,
nil)

extObject := readWriteModel.NewExtensiblePayload(readWriteModel.NewRootExtensionObject(opcuaWriteRequest, expandedNodeId, identifier), nil, 0)
extObject := readWriteModel.NewExtensiblePayload(
nil,
readWriteModel.NewRootExtensionObject(
expandedNodeId,
opcuaWriteRequest,
identifier,
),
0,
)
buffer := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.LittleEndian))
if err := extObject.SerializeWithWriteBuffer(ctx, buffer); err != nil {
result <- spiModel.NewDefaultPlcWriteRequestResult(writeRequest, nil, errors.Wrapf(err, "Unable to serialise the ReadRequest"))
Expand Down Expand Up @@ -398,7 +406,7 @@ func (m *Writer) fromPlcValue(tagName string, tag Tag, request apiModel.PlcWrite
case apiValues.WSTRING:
tmpString := make([]readWriteModel.PascalString, length)
for i := uint32(0); i < length; i++ {
tmpString[i] = readWriteModel.NewPascalString(utils.MakePtr(valueObject.GetIndex(i).GetString()))
tmpString[i] = readWriteModel.NewPascalString(utils.ToPtr(valueObject.GetIndex(i).GetString()))
}
var arrayLength *int32
if length != 1 {
Expand Down
4 changes: 2 additions & 2 deletions plc4go/internal/opcua/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func generateNodeId(tag Tag) (readWriteModel.NodeId, error) {
}
nodeId = readWriteModel.NewNodeId(readWriteModel.NewNodeIdGuid( /*TODO: do we want to check for overflow?*/ uint16(tag.GetNamespace()), guidBytes))
} else if tag.GetIdentifierType() == readWriteModel.OpcuaIdentifierType_STRING_IDENTIFIER {
nodeId = readWriteModel.NewNodeId(readWriteModel.NewNodeIdString( /*TODO: do we want to check for overflow?*/ uint16(tag.GetNamespace()), readWriteModel.NewPascalString(utils.MakePtr(tag.GetIdentifier()))))
nodeId = readWriteModel.NewNodeId(readWriteModel.NewNodeIdString( /*TODO: do we want to check for overflow?*/ uint16(tag.GetNamespace()), readWriteModel.NewPascalString(utils.ToPtr(tag.GetIdentifier()))))
}
return nodeId, nil
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func readResponse(localLog zerolog.Logger, readRequestIn apiModel.PlcReadRequest
array := variant.GetValue()
qualifiedNameValues := make([]apiValues.PlcValue, len(array))
for i, t := range array {
qualifiedNameValues[i] = spiValues.NewPlcSTRING(fmt.Sprintf("ns=%d;s=%s", t.GetNamespaceIndex(), t.GetName().GetStringValue()))
qualifiedNameValues[i] = spiValues.NewPlcSTRING(fmt.Sprintf("ns=%d;s=%s", t.GetNamespaceIndex(), *t.GetName().GetStringValue()))
}
value = spiValues.NewPlcList(qualifiedNameValues)
case readWriteModel.VariantExtensionObject:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d6e692f

Please sign in to comment.