Skip to content

Commit

Permalink
Fix compile errors in golang opcua driver.
Browse files Browse the repository at this point in the history
Signed-off-by: Łukasz Dywicki <[email protected]>
  • Loading branch information
splatch committed Oct 29, 2024
1 parent b63fe12 commit d04c188
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 211 deletions.
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(readWriteModel.NewRootExtensionObject(opcuaReadRequest, expandedNodeId, identifier), nil, 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 d04c188

Please sign in to comment.