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 Nov 6, 2024
1 parent b84a344 commit a132fa0
Show file tree
Hide file tree
Showing 2,169 changed files with 46,630 additions and 17,165 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
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 a132fa0

Please sign in to comment.