This is an automated email from the ASF dual-hosted git repository. cdutz pushed a commit to branch feature/ads-symbol-discovery in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit b288883beb6f40cf034fc4b4ca00a3532036b9b2 Author: Christofer Dutz <[email protected]> AuthorDate: Thu Aug 25 10:32:13 2022 +0200 chore(plc4go): Updated the ADS code to match the latest mspec changes --- plc4go/internal/ads/Reader.go | 92 +++-- plc4go/internal/ads/Writer.go | 35 +- plc4go/internal/bacnetip/Driver.go | 2 +- plc4go/internal/cbus/Discoverer.go | 2 +- plc4go/internal/cbus/Driver.go | 4 +- plc4go/internal/knxnetip/Driver.go | 2 +- plc4go/internal/simulated/Driver.go | 3 + plc4go/internal/simulated/Driver_test.go | 5 +- plc4go/protocols/ads/readwrite/model/AdsData.go | 213 ----------- .../readwrite/model/AdsDataTypeTableChildEntry.go | 19 +- .../ads/readwrite/model/AdsDataTypeTableEntry.go | 19 +- .../model/AdsSignificantGroupAddresses.go | 137 ------- .../ads/readwrite/model/AdsSymbolTableEntry.go | 19 +- plc4go/protocols/ads/readwrite/model/AmsPacket.go | 16 +- plc4go/protocols/ads/readwrite/model/State.go | 399 --------------------- 15 files changed, 108 insertions(+), 859 deletions(-) diff --git a/plc4go/internal/ads/Reader.go b/plc4go/internal/ads/Reader.go index bc0c0e652..34219d6a1 100644 --- a/plc4go/internal/ads/Reader.go +++ b/plc4go/internal/ads/Reader.go @@ -117,17 +117,6 @@ func (m *Reader) singleRead(ctx context.Context, readRequest model.PlcReadReques log.Debug().Msgf("Invalid field item type %T", field) return } - userdata := readWriteModel.NewAmsPacket( - m.targetAmsNetId, - m.targetAmsPort, - m.sourceAmsNetId, - m.sourceAmsPort, - readWriteModel.CommandId_ADS_READ, - readWriteModel.NewState(false, false, false, false, false, true, false, false, false), - 0, - 0, - nil, - ) readLength := uint32(adsField.Datatype.NumBytes()) switch { @@ -148,7 +137,16 @@ func (m *Reader) singleRead(ctx context.Context, readRequest model.PlcReadReques default: readLength = uint32(adsField.Datatype.NumBytes()) } - userdata.Data = readWriteModel.NewAdsReadRequest(adsField.IndexGroup, adsField.IndexOffset, readLength) + userdata := readWriteModel.NewAdsReadRequest( + adsField.IndexGroup, + adsField.IndexOffset, + readLength, + m.targetAmsNetId, + m.targetAmsPort, + m.sourceAmsNetId, + m.sourceAmsPort, + 0, + m.getInvokeId()) m.sendOverTheWire(ctx, userdata, readRequest, result) } @@ -190,18 +188,6 @@ func (m *Reader) multiRead(ctx context.Context, readRequest model.PlcReadRequest expectedResponseDataSize += 4 + (size * field.GetNumberOfElements()) } - userdata := readWriteModel.NewAmsPacket( - m.targetAmsNetId, - m.targetAmsPort, - m.sourceAmsNetId, - m.sourceAmsPort, - readWriteModel.CommandId_ADS_READ_WRITE, - readWriteModel.NewState(false, false, false, false, false, true, false, false, false), - 0, - 0, - nil, - ) - items := make([]readWriteModel.AdsMultiRequestItem, len(readRequest.GetFieldNames())) for i, fieldName := range readRequest.GetFieldNames() { field := readRequest.GetField(fieldName) @@ -240,7 +226,18 @@ func (m *Reader) multiRead(ctx context.Context, readRequest model.PlcReadRequest // With multi-requests, the index-group is fixed and the index offset indicates the number of elements. items[i] = readWriteModel.NewAdsMultiRequestItemRead(adsField.IndexGroup, adsField.IndexOffset, uint32(adsField.GetDatatype().NumBytes())*adsField.NumberOfElements) } - userdata.Data = readWriteModel.NewAdsReadWriteRequest(uint32(readWriteModel.ReservedIndexGroups_ADSIGRP_MULTIPLE_READ), uint32(len(readRequest.GetFieldNames())), expectedResponseDataSize, items, nil) + userdata := readWriteModel.NewAdsReadWriteRequest( + uint32(readWriteModel.ReservedIndexGroups_ADSIGRP_MULTIPLE_READ), + uint32(len(readRequest.GetFieldNames())), + expectedResponseDataSize, + items, + nil, + m.targetAmsNetId, + m.targetAmsPort, + m.sourceAmsNetId, + m.sourceAmsPort, + 0, + m.getInvokeId()) m.sendOverTheWire(ctx, userdata, readRequest, result) } @@ -253,17 +250,6 @@ func (m *Reader) sendOverTheWire(ctx context.Context, userdata readWriteModel.Am atomic.StoreUint32(&m.transactionIdentifier, 1) } log.Debug().Msgf("Calculated transaction identifier %x", transactionIdentifier) - userdata = readWriteModel.NewAmsPacket( - userdata.GetTargetAmsNetId(), - userdata.GetTargetAmsPort(), - userdata.GetSourceAmsNetId(), - userdata.GetSourceAmsPort(), - userdata.GetCommandId(), - userdata.GetState(), - userdata.GetErrorCode(), - transactionIdentifier, - userdata.GetData(), - ) // Assemble the finished tcp paket log.Trace().Msg("Assemble tcp paket") @@ -320,24 +306,18 @@ func (m *Reader) resolveField(ctx context.Context, symbolicField SymbolicPlcFiel if directPlcField, ok := m.fieldMapping[symbolicField]; ok { return directPlcField, nil } - userdata := readWriteModel.NewAmsPacket( - m.targetAmsNetId, - m.targetAmsPort, - m.sourceAmsNetId, - m.sourceAmsPort, - readWriteModel.CommandId_ADS_READ_WRITE, - readWriteModel.NewState(false, false, false, false, false, true, false, false, false), - 0, - 0, - nil, - ) - userdata.Data = readWriteModel.NewAdsReadWriteRequest( + userdata := readWriteModel.NewAdsReadWriteRequest( uint32(readWriteModel.ReservedIndexGroups_ADSIGRP_SYM_HNDBYNAME), 0, 4, nil, []byte(symbolicField.SymbolicAddress+"\000"), - ) + m.targetAmsNetId, + m.targetAmsPort, + m.sourceAmsNetId, + m.sourceAmsPort, + 0, + m.getInvokeId()) result := make(chan model.PlcReadRequestResult) go func() { dummyRequest := plc4goModel.NewDefaultPlcReadRequest(map[string]model.PlcField{"dummy": DirectPlcField{PlcField: PlcField{Datatype: readWriteModel.AdsDataType_UINT32}}}, []string{"dummy"}, nil, nil) @@ -372,7 +352,7 @@ func (m *Reader) resolveField(ctx context.Context, symbolicField SymbolicPlcFiel func (m *Reader) ToPlc4xReadResponse(amsTcpPaket readWriteModel.AmsTCPPacket, readRequest model.PlcReadRequest) (model.PlcReadResponse, error) { var rb utils.ReadBuffer responseCodes := map[string]model.PlcResponseCode{} - switch data := amsTcpPaket.GetUserdata().GetData().(type) { + switch data := amsTcpPaket.GetUserdata().(type) { case readWriteModel.AdsReadResponse: rb = utils.NewLittleEndianReadBufferByteBased(data.GetData()) for _, fieldName := range readRequest.GetFieldNames() { @@ -418,7 +398,7 @@ func (m *Reader) ToPlc4xReadResponse(amsTcpPaket readWriteModel.AmsTCPPacket, re // Decode the data according to the information from the request log.Trace().Msg("decode data") - value, err := readWriteModel.DataItemParse(rb, field.GetDatatype().DataFormatName(), field.GetStringLength()) + value, err := readWriteModel.DataItemParse(rb, field.GetDatatype().PlcValueType(), field.GetStringLength()) if err != nil { log.Error().Err(err).Msg("Error parsing data item") responseCodes[fieldName] = model.PlcResponseCode_INTERNAL_ERROR @@ -432,3 +412,13 @@ func (m *Reader) ToPlc4xReadResponse(amsTcpPaket readWriteModel.AmsTCPPacket, re log.Trace().Msg("Returning the response") return plc4goModel.NewDefaultPlcReadResponse(readRequest, responseCodes, plcValues), nil } + +func (m *Reader) getInvokeId() uint32 { + // Calculate a new transaction identifier + transactionIdentifier := atomic.AddUint32(&m.transactionIdentifier, 1) + if transactionIdentifier > math.MaxUint8 { + transactionIdentifier = 1 + atomic.StoreUint32(&m.transactionIdentifier, 1) + } + return transactionIdentifier +} diff --git a/plc4go/internal/ads/Writer.go b/plc4go/internal/ads/Writer.go index a6f5ba200..7e8ea5d4c 100644 --- a/plc4go/internal/ads/Writer.go +++ b/plc4go/internal/ads/Writer.go @@ -30,7 +30,6 @@ import ( "github.com/rs/zerolog/log" "math" "sync/atomic" - "time" ) type Writer struct { @@ -107,7 +106,7 @@ func (m *Writer) Write(ctx context.Context, writeRequest model.PlcWriteRequest) // Get the value from the request and serialize it to a byte array value := writeRequest.GetValue(fieldName) io := utils.NewLittleEndianWriteBufferByteBased() - if err := readWriteModel.DataItemSerialize(io, value, adsField.Datatype.DataFormatName(), adsField.StringLength); err != nil { + if err := readWriteModel.DataItemSerialize(io, value, adsField.Datatype.PlcValueType(), adsField.StringLength); err != nil { result <- &plc4goModel.DefaultPlcWriteRequestResult{ Request: writeRequest, Response: nil, @@ -115,7 +114,7 @@ func (m *Writer) Write(ctx context.Context, writeRequest model.PlcWriteRequest) } return } - data := io.GetBytes() + /*data := io.GetBytes() userdata := readWriteModel.NewAmsPacket( m.targetAmsNetId, @@ -127,10 +126,10 @@ func (m *Writer) Write(ctx context.Context, writeRequest model.PlcWriteRequest) 0, 0, nil, - ) + )*/ switch adsField.FieldType { case DirectAdsStringField: - userdata.Data = readWriteModel.NewAdsWriteRequest(adsField.IndexGroup, adsField.IndexOffset, data) + //userdata.Data = readWriteModel.NewAdsWriteRequest(adsField.IndexGroup, adsField.IndexOffset, data) panic("implement me") case DirectAdsField: panic("implement me") @@ -146,13 +145,7 @@ func (m *Writer) Write(ctx context.Context, writeRequest model.PlcWriteRequest) } // Calculate a new unit identifier - // TODO: this is not threadsafe as the whole operation is not atomic - transactionIdentifier := atomic.AddUint32(&m.transactionIdentifier, 1) - if transactionIdentifier > math.MaxUint8 { - transactionIdentifier = 0 - atomic.StoreUint32(&m.transactionIdentifier, 0) - } - userdata.InvokeId = transactionIdentifier + /*userdata.InvokeId = m.getInvokeId() // Assemble the finished amsTcpPaket log.Trace().Msg("Assemble amsTcpPaket") @@ -186,7 +179,7 @@ func (m *Writer) Write(ctx context.Context, writeRequest model.PlcWriteRequest) Err: errors.New("got timeout while waiting for response"), } return nil - }, time.Second*1) + }, time.Second*1)*/ }() return result } @@ -197,15 +190,25 @@ func (m *Writer) ToPlc4xWriteResponse(requestTcpPaket readWriteModel.AmsTCPPacke // we default to an error until its proven wrong responseCodes[fieldName] = model.PlcResponseCode_INTERNAL_ERROR - switch responseTcpPaket.GetUserdata().GetData().(type) { + switch responseTcpPaket.GetUserdata().(type) { case readWriteModel.AdsWriteResponse: - resp := readWriteModel.CastAdsWriteResponse(responseTcpPaket.GetUserdata().GetData()) + resp := readWriteModel.CastAdsWriteResponse(responseTcpPaket.GetUserdata()) responseCodes[fieldName] = model.PlcResponseCode(resp.GetResult()) default: - return nil, errors.Errorf("unsupported response type %T", responseTcpPaket.GetUserdata().GetData()) + return nil, errors.Errorf("unsupported response type %T", responseTcpPaket.GetUserdata()) } // Return the response log.Trace().Msg("Returning the response") return plc4goModel.NewDefaultPlcWriteResponse(writeRequest, responseCodes), nil } + +func (m *Writer) getInvokeId() uint32 { + // Calculate a new transaction identifier + transactionIdentifier := atomic.AddUint32(&m.transactionIdentifier, 1) + if transactionIdentifier > math.MaxUint8 { + transactionIdentifier = 1 + atomic.StoreUint32(&m.transactionIdentifier, 1) + } + return transactionIdentifier +} diff --git a/plc4go/internal/bacnetip/Driver.go b/plc4go/internal/bacnetip/Driver.go index f9d40dd7e..33c9d5e24 100644 --- a/plc4go/internal/bacnetip/Driver.go +++ b/plc4go/internal/bacnetip/Driver.go @@ -138,6 +138,6 @@ func (m *Driver) Discover(callback func(event apiModel.PlcDiscoveryItem), discov return m.DiscoverWithContext(context.TODO(), callback, discoveryOptions...) } -func (m *Driver) DiscoverWithContext(ctx context.Context, callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error { +func (m *Driver) DiscoverWithContext(ctx context.Context, callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error { return NewDiscoverer().Discover(ctx, callback, discoveryOptions...) } diff --git a/plc4go/internal/cbus/Discoverer.go b/plc4go/internal/cbus/Discoverer.go index 3ef576304..a3826fcbb 100644 --- a/plc4go/internal/cbus/Discoverer.go +++ b/plc4go/internal/cbus/Discoverer.go @@ -47,7 +47,7 @@ func NewDiscoverer() *Discoverer { return &Discoverer{} } -func (d *Discoverer) Discover(ctx context.Context, callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error { +func (d *Discoverer) Discover(ctx context.Context, callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error { tcpTransport := tcp.NewTransport() allInterfaces, err := net.Interfaces() diff --git a/plc4go/internal/cbus/Driver.go b/plc4go/internal/cbus/Driver.go index 1e7786905..97cb28f77 100644 --- a/plc4go/internal/cbus/Driver.go +++ b/plc4go/internal/cbus/Driver.go @@ -118,10 +118,10 @@ func (m *Driver) SupportsDiscovery() bool { return true } -func (m *Driver) Discover(callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error { +func (m *Driver) Discover(callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error { return m.DiscoverWithContext(context.TODO(), callback, discoveryOptions...) } -func (m *Driver) DiscoverWithContext(ctx context.Context, callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error { +func (m *Driver) DiscoverWithContext(ctx context.Context, callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error { return NewDiscoverer().Discover(ctx, callback, discoveryOptions...) } diff --git a/plc4go/internal/knxnetip/Driver.go b/plc4go/internal/knxnetip/Driver.go index 60deb4fb9..f4405e80b 100644 --- a/plc4go/internal/knxnetip/Driver.go +++ b/plc4go/internal/knxnetip/Driver.go @@ -82,6 +82,6 @@ func (m *Driver) Discover(callback func(event apiModel.PlcDiscoveryItem), discov return m.DiscoverWithContext(context.TODO(), callback, discoveryOptions...) } -func (m *Driver) DiscoverWithContext(ctx context.Context, callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error { +func (m *Driver) DiscoverWithContext(ctx context.Context, callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error { return NewDiscoverer().Discover(ctx, callback, discoveryOptions...) } diff --git a/plc4go/internal/simulated/Driver.go b/plc4go/internal/simulated/Driver.go index 2026bbc35..b5f91e8ed 100644 --- a/plc4go/internal/simulated/Driver.go +++ b/plc4go/internal/simulated/Driver.go @@ -21,8 +21,11 @@ package simulated import ( "github.com/apache/plc4x/plc4go/pkg/api" + "github.com/apache/plc4x/plc4go/pkg/api/model" _default "github.com/apache/plc4x/plc4go/spi/default" + "github.com/apache/plc4x/plc4go/spi/options" "github.com/apache/plc4x/plc4go/spi/transports" + "github.com/pkg/errors" "net/url" ) diff --git a/plc4go/internal/simulated/Driver_test.go b/plc4go/internal/simulated/Driver_test.go index 87f5aa4b1..c23404084 100644 --- a/plc4go/internal/simulated/Driver_test.go +++ b/plc4go/internal/simulated/Driver_test.go @@ -20,6 +20,8 @@ package simulated import ( + "github.com/apache/plc4x/plc4go/pkg/api/model" + "github.com/apache/plc4x/plc4go/spi/options" "github.com/apache/plc4x/plc4go/spi/transports" "github.com/apache/plc4x/plc4go/spi/utils" "net/url" @@ -56,7 +58,6 @@ func TestDriver_CheckQuery(t *testing.T) { func TestDriver_Discover(t *testing.T) { type fields struct { - fieldHandler FieldHandler valueHandler ValueHandler } type args struct { @@ -72,7 +73,6 @@ func TestDriver_Discover(t *testing.T) { { name: "discovery fails", fields: fields{ - fieldHandler: NewFieldHandler(), valueHandler: NewValueHandler(), }, args: args{ @@ -86,7 +86,6 @@ func TestDriver_Discover(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { d := &Driver{ - fieldHandler: tt.fields.fieldHandler, valueHandler: tt.fields.valueHandler, } if err := d.Discover(tt.args.callback, tt.args.discoveryOptions...); (err != nil) != tt.wantErr { diff --git a/plc4go/protocols/ads/readwrite/model/AdsData.go b/plc4go/protocols/ads/readwrite/model/AdsData.go deleted file mode 100644 index f0217f62f..000000000 --- a/plc4go/protocols/ads/readwrite/model/AdsData.go +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package model - -import ( - "github.com/apache/plc4x/plc4go/spi/utils" - "github.com/pkg/errors" -) - -// Code generated by code-generation. DO NOT EDIT. - -// AdsData is the corresponding interface of AdsData -type AdsData interface { - utils.LengthAware - utils.Serializable - // GetCommandId returns CommandId (discriminator field) - GetCommandId() CommandId - // GetResponse returns Response (discriminator field) - GetResponse() bool -} - -// AdsDataExactly can be used when we want exactly this type and not a type which fulfills AdsData. -// This is useful for switch cases. -type AdsDataExactly interface { - AdsData - isAdsData() bool -} - -// _AdsData is the data-structure of this message -type _AdsData struct { - _AdsDataChildRequirements -} - -type _AdsDataChildRequirements interface { - utils.Serializable - GetLengthInBits() uint16 - GetLengthInBitsConditional(lastItem bool) uint16 - GetCommandId() CommandId - GetResponse() bool -} - -type AdsDataParent interface { - SerializeParent(writeBuffer utils.WriteBuffer, child AdsData, serializeChildFunction func() error) error - GetTypeName() string -} - -type AdsDataChild interface { - utils.Serializable - InitializeParent(parent AdsData) - GetParent() *AdsData - - GetTypeName() string - AdsData -} - -// NewAdsData factory function for _AdsData -func NewAdsData() *_AdsData { - return &_AdsData{} -} - -// Deprecated: use the interface for direct cast -func CastAdsData(structType interface{}) AdsData { - if casted, ok := structType.(AdsData); ok { - return casted - } - if casted, ok := structType.(*AdsData); ok { - return *casted - } - return nil -} - -func (m *_AdsData) GetTypeName() string { - return "AdsData" -} - -func (m *_AdsData) GetParentLengthInBits() uint16 { - lengthInBits := uint16(0) - - return lengthInBits -} - -func (m *_AdsData) GetLengthInBytes() uint16 { - return m.GetLengthInBits() / 8 -} - -func AdsDataParse(readBuffer utils.ReadBuffer, commandId CommandId, response bool) (AdsData, error) { - positionAware := readBuffer - _ = positionAware - if pullErr := readBuffer.PullContext("AdsData"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for AdsData") - } - currentPos := positionAware.GetPos() - _ = currentPos - - // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) - type AdsDataChildSerializeRequirement interface { - AdsData - InitializeParent(AdsData) - GetParent() AdsData - } - var _childTemp interface{} - var _child AdsDataChildSerializeRequirement - var typeSwitchError error - switch { - case commandId == CommandId_INVALID && response == bool(false): // AdsInvalidRequest - _childTemp, typeSwitchError = AdsInvalidRequestParse(readBuffer, commandId, response) - case commandId == CommandId_INVALID && response == bool(true): // AdsInvalidResponse - _childTemp, typeSwitchError = AdsInvalidResponseParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_READ_DEVICE_INFO && response == bool(false): // AdsReadDeviceInfoRequest - _childTemp, typeSwitchError = AdsReadDeviceInfoRequestParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_READ_DEVICE_INFO && response == bool(true): // AdsReadDeviceInfoResponse - _childTemp, typeSwitchError = AdsReadDeviceInfoResponseParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_READ && response == bool(false): // AdsReadRequest - _childTemp, typeSwitchError = AdsReadRequestParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_READ && response == bool(true): // AdsReadResponse - _childTemp, typeSwitchError = AdsReadResponseParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_WRITE && response == bool(false): // AdsWriteRequest - _childTemp, typeSwitchError = AdsWriteRequestParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_WRITE && response == bool(true): // AdsWriteResponse - _childTemp, typeSwitchError = AdsWriteResponseParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_READ_STATE && response == bool(false): // AdsReadStateRequest - _childTemp, typeSwitchError = AdsReadStateRequestParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_READ_STATE && response == bool(true): // AdsReadStateResponse - _childTemp, typeSwitchError = AdsReadStateResponseParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_WRITE_CONTROL && response == bool(false): // AdsWriteControlRequest - _childTemp, typeSwitchError = AdsWriteControlRequestParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_WRITE_CONTROL && response == bool(true): // AdsWriteControlResponse - _childTemp, typeSwitchError = AdsWriteControlResponseParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_ADD_DEVICE_NOTIFICATION && response == bool(false): // AdsAddDeviceNotificationRequest - _childTemp, typeSwitchError = AdsAddDeviceNotificationRequestParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_ADD_DEVICE_NOTIFICATION && response == bool(true): // AdsAddDeviceNotificationResponse - _childTemp, typeSwitchError = AdsAddDeviceNotificationResponseParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_DELETE_DEVICE_NOTIFICATION && response == bool(false): // AdsDeleteDeviceNotificationRequest - _childTemp, typeSwitchError = AdsDeleteDeviceNotificationRequestParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_DELETE_DEVICE_NOTIFICATION && response == bool(true): // AdsDeleteDeviceNotificationResponse - _childTemp, typeSwitchError = AdsDeleteDeviceNotificationResponseParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_DEVICE_NOTIFICATION && response == bool(false): // AdsDeviceNotificationRequest - _childTemp, typeSwitchError = AdsDeviceNotificationRequestParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_DEVICE_NOTIFICATION && response == bool(true): // AdsDeviceNotificationResponse - _childTemp, typeSwitchError = AdsDeviceNotificationResponseParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_READ_WRITE && response == bool(false): // AdsReadWriteRequest - _childTemp, typeSwitchError = AdsReadWriteRequestParse(readBuffer, commandId, response) - case commandId == CommandId_ADS_READ_WRITE && response == bool(true): // AdsReadWriteResponse - _childTemp, typeSwitchError = AdsReadWriteResponseParse(readBuffer, commandId, response) - default: - typeSwitchError = errors.Errorf("Unmapped type for parameters [commandId=%v, response=%v]", commandId, response) - } - if typeSwitchError != nil { - return nil, errors.Wrap(typeSwitchError, "Error parsing sub-type for type-switch of AdsData") - } - _child = _childTemp.(AdsDataChildSerializeRequirement) - - if closeErr := readBuffer.CloseContext("AdsData"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for AdsData") - } - - // Finish initializing - _child.InitializeParent(_child) - return _child, nil -} - -func (pm *_AdsData) SerializeParent(writeBuffer utils.WriteBuffer, child AdsData, serializeChildFunction func() error) error { - // We redirect all calls through client as some methods are only implemented there - m := child - _ = m - positionAware := writeBuffer - _ = positionAware - if pushErr := writeBuffer.PushContext("AdsData"); pushErr != nil { - return errors.Wrap(pushErr, "Error pushing for AdsData") - } - - // Switch field (Depending on the discriminator values, passes the serialization to a sub-type) - if _typeSwitchErr := serializeChildFunction(); _typeSwitchErr != nil { - return errors.Wrap(_typeSwitchErr, "Error serializing sub-type field") - } - - if popErr := writeBuffer.PopContext("AdsData"); popErr != nil { - return errors.Wrap(popErr, "Error popping for AdsData") - } - return nil -} - -func (m *_AdsData) isAdsData() bool { - return true -} - -func (m *_AdsData) String() string { - if m == nil { - return "<nil>" - } - writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) - if err := writeBuffer.WriteSerializable(m); err != nil { - return err.Error() - } - return writeBuffer.GetBox().String() -} diff --git a/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableChildEntry.go b/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableChildEntry.go index 7027cfe57..56b52de22 100644 --- a/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableChildEntry.go +++ b/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableChildEntry.go @@ -259,19 +259,19 @@ func (m *_AdsDataTypeTableChildEntry) GetLengthInBitsConditional(lastItem bool) lengthInBits += 16 // Simple field (propertyName) - lengthInBits += uint16(int32(GetSTR_LEN()(m.GetPropertyName())) * int32(int32(8))) + lengthInBits += uint16(int32(uint16(len(m.GetPropertyName()))) * int32(int32(8))) // Const Field (propertyNameTerminator) lengthInBits += 8 // Simple field (dataTypeName) - lengthInBits += uint16(int32(GetSTR_LEN()(m.GetDataTypeName())) * int32(int32(8))) + lengthInBits += uint16(int32(uint16(len(m.GetDataTypeName()))) * int32(int32(8))) // Const Field (dataTypeNameTerminator) lengthInBits += 8 // Simple field (comment) - lengthInBits += uint16(int32(GetSTR_LEN()(m.GetComment())) * int32(int32(8))) + lengthInBits += uint16(int32(uint16(len(m.GetComment()))) * int32(int32(8))) // Const Field (commentTerminator) lengthInBits += 8 @@ -313,6 +313,7 @@ func AdsDataTypeTableChildEntryParse(readBuffer utils.ReadBuffer) (AdsDataTypeTa currentPos := positionAware.GetPos() _ = currentPos var startPos = positionAware.GetPos() + _ = startPos var curPos uint16 // Simple Field (entryLength) @@ -595,21 +596,21 @@ func (m *_AdsDataTypeTableChildEntry) Serialize(writeBuffer utils.WriteBuffer) e } // Implicit Field (propertyNameLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - propertyNameLength := uint16(GetSTR_LEN()(m.GetPropertyName())) + propertyNameLength := uint16(uint16(len(m.GetPropertyName()))) _propertyNameLengthErr := writeBuffer.WriteUint16("propertyNameLength", 16, (propertyNameLength)) if _propertyNameLengthErr != nil { return errors.Wrap(_propertyNameLengthErr, "Error serializing 'propertyNameLength' field") } // Implicit Field (dataTypeNameLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - dataTypeNameLength := uint16(GetSTR_LEN()(m.GetDataTypeName())) + dataTypeNameLength := uint16(uint16(len(m.GetDataTypeName()))) _dataTypeNameLengthErr := writeBuffer.WriteUint16("dataTypeNameLength", 16, (dataTypeNameLength)) if _dataTypeNameLengthErr != nil { return errors.Wrap(_dataTypeNameLengthErr, "Error serializing 'dataTypeNameLength' field") } // Implicit Field (commentLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - commentLength := uint16(GetSTR_LEN()(m.GetComment())) + commentLength := uint16(uint16(len(m.GetComment()))) _commentLengthErr := writeBuffer.WriteUint16("commentLength", 16, (commentLength)) if _commentLengthErr != nil { return errors.Wrap(_commentLengthErr, "Error serializing 'commentLength' field") @@ -631,7 +632,7 @@ func (m *_AdsDataTypeTableChildEntry) Serialize(writeBuffer utils.WriteBuffer) e // Simple Field (propertyName) propertyName := string(m.GetPropertyName()) - _propertyNameErr := writeBuffer.WriteString("propertyName", uint32((GetSTR_LEN()(m.GetPropertyName()))*(8)), "UTF-8", (propertyName)) + _propertyNameErr := writeBuffer.WriteString("propertyName", uint32((uint16(len(m.GetPropertyName())))*(8)), "UTF-8", (propertyName)) if _propertyNameErr != nil { return errors.Wrap(_propertyNameErr, "Error serializing 'propertyName' field") } @@ -644,7 +645,7 @@ func (m *_AdsDataTypeTableChildEntry) Serialize(writeBuffer utils.WriteBuffer) e // Simple Field (dataTypeName) dataTypeName := string(m.GetDataTypeName()) - _dataTypeNameErr := writeBuffer.WriteString("dataTypeName", uint32((GetSTR_LEN()(m.GetDataTypeName()))*(8)), "UTF-8", (dataTypeName)) + _dataTypeNameErr := writeBuffer.WriteString("dataTypeName", uint32((uint16(len(m.GetDataTypeName())))*(8)), "UTF-8", (dataTypeName)) if _dataTypeNameErr != nil { return errors.Wrap(_dataTypeNameErr, "Error serializing 'dataTypeName' field") } @@ -657,7 +658,7 @@ func (m *_AdsDataTypeTableChildEntry) Serialize(writeBuffer utils.WriteBuffer) e // Simple Field (comment) comment := string(m.GetComment()) - _commentErr := writeBuffer.WriteString("comment", uint32((GetSTR_LEN()(m.GetComment()))*(8)), "UTF-8", (comment)) + _commentErr := writeBuffer.WriteString("comment", uint32((uint16(len(m.GetComment())))*(8)), "UTF-8", (comment)) if _commentErr != nil { return errors.Wrap(_commentErr, "Error serializing 'comment' field") } diff --git a/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableEntry.go b/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableEntry.go index 173141ed8..2f3dae2bc 100644 --- a/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableEntry.go +++ b/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableEntry.go @@ -259,19 +259,19 @@ func (m *_AdsDataTypeTableEntry) GetLengthInBitsConditional(lastItem bool) uint1 lengthInBits += 16 // Simple field (dataTypeName) - lengthInBits += uint16(int32(GetSTR_LEN()(m.GetDataTypeName())) * int32(int32(8))) + lengthInBits += uint16(int32(uint16(len(m.GetDataTypeName()))) * int32(int32(8))) // Const Field (dataTypeNameTerminator) lengthInBits += 8 // Simple field (simpleTypeName) - lengthInBits += uint16(int32(GetSTR_LEN()(m.GetSimpleTypeName())) * int32(int32(8))) + lengthInBits += uint16(int32(uint16(len(m.GetSimpleTypeName()))) * int32(int32(8))) // Const Field (simpleTypeNameTerminator) lengthInBits += 8 // Simple field (comment) - lengthInBits += uint16(int32(GetSTR_LEN()(m.GetComment())) * int32(int32(8))) + lengthInBits += uint16(int32(uint16(len(m.GetComment()))) * int32(int32(8))) // Const Field (commentTerminator) lengthInBits += 8 @@ -313,6 +313,7 @@ func AdsDataTypeTableEntryParse(readBuffer utils.ReadBuffer) (AdsDataTypeTableEn currentPos := positionAware.GetPos() _ = currentPos var startPos = positionAware.GetPos() + _ = startPos var curPos uint16 // Simple Field (entryLength) @@ -595,21 +596,21 @@ func (m *_AdsDataTypeTableEntry) Serialize(writeBuffer utils.WriteBuffer) error } // Implicit Field (dataTypeNameLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - dataTypeNameLength := uint16(GetSTR_LEN()(m.GetDataTypeName())) + dataTypeNameLength := uint16(uint16(len(m.GetDataTypeName()))) _dataTypeNameLengthErr := writeBuffer.WriteUint16("dataTypeNameLength", 16, (dataTypeNameLength)) if _dataTypeNameLengthErr != nil { return errors.Wrap(_dataTypeNameLengthErr, "Error serializing 'dataTypeNameLength' field") } // Implicit Field (simpleTypeNameLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - simpleTypeNameLength := uint16(GetSTR_LEN()(m.GetSimpleTypeName())) + simpleTypeNameLength := uint16(uint16(len(m.GetSimpleTypeName()))) _simpleTypeNameLengthErr := writeBuffer.WriteUint16("simpleTypeNameLength", 16, (simpleTypeNameLength)) if _simpleTypeNameLengthErr != nil { return errors.Wrap(_simpleTypeNameLengthErr, "Error serializing 'simpleTypeNameLength' field") } // Implicit Field (commentLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - commentLength := uint16(GetSTR_LEN()(m.GetComment())) + commentLength := uint16(uint16(len(m.GetComment()))) _commentLengthErr := writeBuffer.WriteUint16("commentLength", 16, (commentLength)) if _commentLengthErr != nil { return errors.Wrap(_commentLengthErr, "Error serializing 'commentLength' field") @@ -631,7 +632,7 @@ func (m *_AdsDataTypeTableEntry) Serialize(writeBuffer utils.WriteBuffer) error // Simple Field (dataTypeName) dataTypeName := string(m.GetDataTypeName()) - _dataTypeNameErr := writeBuffer.WriteString("dataTypeName", uint32((GetSTR_LEN()(m.GetDataTypeName()))*(8)), "UTF-8", (dataTypeName)) + _dataTypeNameErr := writeBuffer.WriteString("dataTypeName", uint32((uint16(len(m.GetDataTypeName())))*(8)), "UTF-8", (dataTypeName)) if _dataTypeNameErr != nil { return errors.Wrap(_dataTypeNameErr, "Error serializing 'dataTypeName' field") } @@ -644,7 +645,7 @@ func (m *_AdsDataTypeTableEntry) Serialize(writeBuffer utils.WriteBuffer) error // Simple Field (simpleTypeName) simpleTypeName := string(m.GetSimpleTypeName()) - _simpleTypeNameErr := writeBuffer.WriteString("simpleTypeName", uint32((GetSTR_LEN()(m.GetSimpleTypeName()))*(8)), "UTF-8", (simpleTypeName)) + _simpleTypeNameErr := writeBuffer.WriteString("simpleTypeName", uint32((uint16(len(m.GetSimpleTypeName())))*(8)), "UTF-8", (simpleTypeName)) if _simpleTypeNameErr != nil { return errors.Wrap(_simpleTypeNameErr, "Error serializing 'simpleTypeName' field") } @@ -657,7 +658,7 @@ func (m *_AdsDataTypeTableEntry) Serialize(writeBuffer utils.WriteBuffer) error // Simple Field (comment) comment := string(m.GetComment()) - _commentErr := writeBuffer.WriteString("comment", uint32((GetSTR_LEN()(m.GetComment()))*(8)), "UTF-8", (comment)) + _commentErr := writeBuffer.WriteString("comment", uint32((uint16(len(m.GetComment())))*(8)), "UTF-8", (comment)) if _commentErr != nil { return errors.Wrap(_commentErr, "Error serializing 'comment' field") } diff --git a/plc4go/protocols/ads/readwrite/model/AdsSignificantGroupAddresses.go b/plc4go/protocols/ads/readwrite/model/AdsSignificantGroupAddresses.go deleted file mode 100644 index d4ef38d20..000000000 --- a/plc4go/protocols/ads/readwrite/model/AdsSignificantGroupAddresses.go +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package model - -import ( - "github.com/apache/plc4x/plc4go/spi/utils" - "github.com/pkg/errors" - "github.com/rs/zerolog/log" -) - -// Code generated by code-generation. DO NOT EDIT. - -// AdsSignificantGroupAddresses is an enum -type AdsSignificantGroupAddresses uint32 - -type IAdsSignificantGroupAddresses interface { - Serialize(writeBuffer utils.WriteBuffer) error -} - -const ( - AdsSignificantGroupAddresses_SYMBOL_TABLE AdsSignificantGroupAddresses = 0x0000F00B - AdsSignificantGroupAddresses_DATA_TYPE_TABLE AdsSignificantGroupAddresses = 0x0000F00E - AdsSignificantGroupAddresses_TABLE_SIZES AdsSignificantGroupAddresses = 0x0000F00F -) - -var AdsSignificantGroupAddressesValues []AdsSignificantGroupAddresses - -func init() { - _ = errors.New - AdsSignificantGroupAddressesValues = []AdsSignificantGroupAddresses{ - AdsSignificantGroupAddresses_SYMBOL_TABLE, - AdsSignificantGroupAddresses_DATA_TYPE_TABLE, - AdsSignificantGroupAddresses_TABLE_SIZES, - } -} - -func AdsSignificantGroupAddressesByValue(value uint32) (enum AdsSignificantGroupAddresses, ok bool) { - switch value { - case 0x0000F00B: - return AdsSignificantGroupAddresses_SYMBOL_TABLE, true - case 0x0000F00E: - return AdsSignificantGroupAddresses_DATA_TYPE_TABLE, true - case 0x0000F00F: - return AdsSignificantGroupAddresses_TABLE_SIZES, true - } - return 0, false -} - -func AdsSignificantGroupAddressesByName(value string) (enum AdsSignificantGroupAddresses, ok bool) { - switch value { - case "SYMBOL_TABLE": - return AdsSignificantGroupAddresses_SYMBOL_TABLE, true - case "DATA_TYPE_TABLE": - return AdsSignificantGroupAddresses_DATA_TYPE_TABLE, true - case "TABLE_SIZES": - return AdsSignificantGroupAddresses_TABLE_SIZES, true - } - return 0, false -} - -func AdsSignificantGroupAddressesKnows(value uint32) bool { - for _, typeValue := range AdsSignificantGroupAddressesValues { - if uint32(typeValue) == value { - return true - } - } - return false -} - -func CastAdsSignificantGroupAddresses(structType interface{}) AdsSignificantGroupAddresses { - castFunc := func(typ interface{}) AdsSignificantGroupAddresses { - if sAdsSignificantGroupAddresses, ok := typ.(AdsSignificantGroupAddresses); ok { - return sAdsSignificantGroupAddresses - } - return 0 - } - return castFunc(structType) -} - -func (m AdsSignificantGroupAddresses) GetLengthInBits() uint16 { - return 32 -} - -func (m AdsSignificantGroupAddresses) GetLengthInBytes() uint16 { - return m.GetLengthInBits() / 8 -} - -func AdsSignificantGroupAddressesParse(readBuffer utils.ReadBuffer) (AdsSignificantGroupAddresses, error) { - val, err := readBuffer.ReadUint32("AdsSignificantGroupAddresses", 32) - if err != nil { - return 0, errors.Wrap(err, "error reading AdsSignificantGroupAddresses") - } - if enum, ok := AdsSignificantGroupAddressesByValue(val); !ok { - log.Debug().Msgf("no value %x found for RequestType", val) - return AdsSignificantGroupAddresses(val), nil - } else { - return enum, nil - } -} - -func (e AdsSignificantGroupAddresses) Serialize(writeBuffer utils.WriteBuffer) error { - return writeBuffer.WriteUint32("AdsSignificantGroupAddresses", 32, uint32(e), utils.WithAdditionalStringRepresentation(e.PLC4XEnumName())) -} - -// PLC4XEnumName returns the name that is used in code to identify this enum -func (e AdsSignificantGroupAddresses) PLC4XEnumName() string { - switch e { - case AdsSignificantGroupAddresses_SYMBOL_TABLE: - return "SYMBOL_TABLE" - case AdsSignificantGroupAddresses_DATA_TYPE_TABLE: - return "DATA_TYPE_TABLE" - case AdsSignificantGroupAddresses_TABLE_SIZES: - return "TABLE_SIZES" - } - return "" -} - -func (e AdsSignificantGroupAddresses) String() string { - return e.PLC4XEnumName() -} diff --git a/plc4go/protocols/ads/readwrite/model/AdsSymbolTableEntry.go b/plc4go/protocols/ads/readwrite/model/AdsSymbolTableEntry.go index 3e283f1f1..08428a455 100644 --- a/plc4go/protocols/ads/readwrite/model/AdsSymbolTableEntry.go +++ b/plc4go/protocols/ads/readwrite/model/AdsSymbolTableEntry.go @@ -335,19 +335,19 @@ func (m *_AdsSymbolTableEntry) GetLengthInBitsConditional(lastItem bool) uint16 lengthInBits += 16 // Simple field (name) - lengthInBits += uint16(int32(GetSTR_LEN()(m.GetName())) * int32(int32(8))) + lengthInBits += uint16(int32(uint16(len(m.GetName()))) * int32(int32(8))) // Const Field (nameTerminator) lengthInBits += 8 // Simple field (dataTypeName) - lengthInBits += uint16(int32(GetSTR_LEN()(m.GetDataTypeName())) * int32(int32(8))) + lengthInBits += uint16(int32(uint16(len(m.GetDataTypeName()))) * int32(int32(8))) // Const Field (dataTypeNameTerminator) lengthInBits += 8 // Simple field (comment) - lengthInBits += uint16(int32(GetSTR_LEN()(m.GetComment())) * int32(int32(8))) + lengthInBits += uint16(int32(uint16(len(m.GetComment()))) * int32(int32(8))) // Const Field (commentTerminator) lengthInBits += 8 @@ -373,6 +373,7 @@ func AdsSymbolTableEntryParse(readBuffer utils.ReadBuffer) (AdsSymbolTableEntry, currentPos := positionAware.GetPos() _ = currentPos var startPos = positionAware.GetPos() + _ = startPos var curPos uint16 // Simple Field (entryLength) @@ -809,21 +810,21 @@ func (m *_AdsSymbolTableEntry) Serialize(writeBuffer utils.WriteBuffer) error { } // Implicit Field (nameLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - nameLength := uint16(GetSTR_LEN()(m.GetName())) + nameLength := uint16(uint16(len(m.GetName()))) _nameLengthErr := writeBuffer.WriteUint16("nameLength", 16, (nameLength)) if _nameLengthErr != nil { return errors.Wrap(_nameLengthErr, "Error serializing 'nameLength' field") } // Implicit Field (dataTypeNameLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - dataTypeNameLength := uint16(GetSTR_LEN()(m.GetDataTypeName())) + dataTypeNameLength := uint16(uint16(len(m.GetDataTypeName()))) _dataTypeNameLengthErr := writeBuffer.WriteUint16("dataTypeNameLength", 16, (dataTypeNameLength)) if _dataTypeNameLengthErr != nil { return errors.Wrap(_dataTypeNameLengthErr, "Error serializing 'dataTypeNameLength' field") } // Implicit Field (commentLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content) - commentLength := uint16(GetSTR_LEN()(m.GetComment())) + commentLength := uint16(uint16(len(m.GetComment()))) _commentLengthErr := writeBuffer.WriteUint16("commentLength", 16, (commentLength)) if _commentLengthErr != nil { return errors.Wrap(_commentLengthErr, "Error serializing 'commentLength' field") @@ -831,7 +832,7 @@ func (m *_AdsSymbolTableEntry) Serialize(writeBuffer utils.WriteBuffer) error { // Simple Field (name) name := string(m.GetName()) - _nameErr := writeBuffer.WriteString("name", uint32((GetSTR_LEN()(m.GetName()))*(8)), "UTF-8", (name)) + _nameErr := writeBuffer.WriteString("name", uint32((uint16(len(m.GetName())))*(8)), "UTF-8", (name)) if _nameErr != nil { return errors.Wrap(_nameErr, "Error serializing 'name' field") } @@ -844,7 +845,7 @@ func (m *_AdsSymbolTableEntry) Serialize(writeBuffer utils.WriteBuffer) error { // Simple Field (dataTypeName) dataTypeName := string(m.GetDataTypeName()) - _dataTypeNameErr := writeBuffer.WriteString("dataTypeName", uint32((GetSTR_LEN()(m.GetDataTypeName()))*(8)), "UTF-8", (dataTypeName)) + _dataTypeNameErr := writeBuffer.WriteString("dataTypeName", uint32((uint16(len(m.GetDataTypeName())))*(8)), "UTF-8", (dataTypeName)) if _dataTypeNameErr != nil { return errors.Wrap(_dataTypeNameErr, "Error serializing 'dataTypeName' field") } @@ -857,7 +858,7 @@ func (m *_AdsSymbolTableEntry) Serialize(writeBuffer utils.WriteBuffer) error { // Simple Field (comment) comment := string(m.GetComment()) - _commentErr := writeBuffer.WriteString("comment", uint32((GetSTR_LEN()(m.GetComment()))*(8)), "UTF-8", (comment)) + _commentErr := writeBuffer.WriteString("comment", uint32((uint16(len(m.GetComment())))*(8)), "UTF-8", (comment)) if _commentErr != nil { return errors.Wrap(_commentErr, "Error serializing 'comment' field") } diff --git a/plc4go/protocols/ads/readwrite/model/AmsPacket.go b/plc4go/protocols/ads/readwrite/model/AmsPacket.go index 371900c3d..e5daa7211 100644 --- a/plc4go/protocols/ads/readwrite/model/AmsPacket.go +++ b/plc4go/protocols/ads/readwrite/model/AmsPacket.go @@ -327,7 +327,7 @@ func AmsPacketParse(readBuffer utils.ReadBuffer) (AmsPacket, error) { return nil, errors.Wrap(_initCommandErr, "Error parsing 'initCommand' field of AmsPacket") } if initCommand != AmsPacket_INITCOMMAND { - return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", AmsPacket_INITCOMMAND) + " but got " + fmt.Sprintf("%d", initCommand)) + return nil, errors.New("Expected constant value " + fmt.Sprintf("%t", AmsPacket_INITCOMMAND) + " but got " + fmt.Sprintf("%t", initCommand)) } // Const Field (updCommand) @@ -336,7 +336,7 @@ func AmsPacketParse(readBuffer utils.ReadBuffer) (AmsPacket, error) { return nil, errors.Wrap(_updCommandErr, "Error parsing 'updCommand' field of AmsPacket") } if updCommand != AmsPacket_UPDCOMMAND { - return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", AmsPacket_UPDCOMMAND) + " but got " + fmt.Sprintf("%d", updCommand)) + return nil, errors.New("Expected constant value " + fmt.Sprintf("%t", AmsPacket_UPDCOMMAND) + " but got " + fmt.Sprintf("%t", updCommand)) } // Const Field (timestampAdded) @@ -345,7 +345,7 @@ func AmsPacketParse(readBuffer utils.ReadBuffer) (AmsPacket, error) { return nil, errors.Wrap(_timestampAddedErr, "Error parsing 'timestampAdded' field of AmsPacket") } if timestampAdded != AmsPacket_TIMESTAMPADDED { - return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", AmsPacket_TIMESTAMPADDED) + " but got " + fmt.Sprintf("%d", timestampAdded)) + return nil, errors.New("Expected constant value " + fmt.Sprintf("%t", AmsPacket_TIMESTAMPADDED) + " but got " + fmt.Sprintf("%t", timestampAdded)) } // Const Field (highPriorityCommand) @@ -354,7 +354,7 @@ func AmsPacketParse(readBuffer utils.ReadBuffer) (AmsPacket, error) { return nil, errors.Wrap(_highPriorityCommandErr, "Error parsing 'highPriorityCommand' field of AmsPacket") } if highPriorityCommand != AmsPacket_HIGHPRIORITYCOMMAND { - return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", AmsPacket_HIGHPRIORITYCOMMAND) + " but got " + fmt.Sprintf("%d", highPriorityCommand)) + return nil, errors.New("Expected constant value " + fmt.Sprintf("%t", AmsPacket_HIGHPRIORITYCOMMAND) + " but got " + fmt.Sprintf("%t", highPriorityCommand)) } // Const Field (systemCommand) @@ -363,7 +363,7 @@ func AmsPacketParse(readBuffer utils.ReadBuffer) (AmsPacket, error) { return nil, errors.Wrap(_systemCommandErr, "Error parsing 'systemCommand' field of AmsPacket") } if systemCommand != AmsPacket_SYSTEMCOMMAND { - return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", AmsPacket_SYSTEMCOMMAND) + " but got " + fmt.Sprintf("%d", systemCommand)) + return nil, errors.New("Expected constant value " + fmt.Sprintf("%t", AmsPacket_SYSTEMCOMMAND) + " but got " + fmt.Sprintf("%t", systemCommand)) } // Const Field (adsCommand) @@ -372,7 +372,7 @@ func AmsPacketParse(readBuffer utils.ReadBuffer) (AmsPacket, error) { return nil, errors.Wrap(_adsCommandErr, "Error parsing 'adsCommand' field of AmsPacket") } if adsCommand != AmsPacket_ADSCOMMAND { - return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", AmsPacket_ADSCOMMAND) + " but got " + fmt.Sprintf("%d", adsCommand)) + return nil, errors.New("Expected constant value " + fmt.Sprintf("%t", AmsPacket_ADSCOMMAND) + " but got " + fmt.Sprintf("%t", adsCommand)) } // Const Field (noReturn) @@ -381,7 +381,7 @@ func AmsPacketParse(readBuffer utils.ReadBuffer) (AmsPacket, error) { return nil, errors.Wrap(_noReturnErr, "Error parsing 'noReturn' field of AmsPacket") } if noReturn != AmsPacket_NORETURN { - return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", AmsPacket_NORETURN) + " but got " + fmt.Sprintf("%d", noReturn)) + return nil, errors.New("Expected constant value " + fmt.Sprintf("%t", AmsPacket_NORETURN) + " but got " + fmt.Sprintf("%t", noReturn)) } // Discriminator Field (response) (Used as input to a switch field) @@ -396,7 +396,7 @@ func AmsPacketParse(readBuffer utils.ReadBuffer) (AmsPacket, error) { return nil, errors.Wrap(_broadcastErr, "Error parsing 'broadcast' field of AmsPacket") } if broadcast != AmsPacket_BROADCAST { - return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", AmsPacket_BROADCAST) + " but got " + fmt.Sprintf("%d", broadcast)) + return nil, errors.New("Expected constant value " + fmt.Sprintf("%t", AmsPacket_BROADCAST) + " but got " + fmt.Sprintf("%t", broadcast)) } var reservedField0 *int8 diff --git a/plc4go/protocols/ads/readwrite/model/State.go b/plc4go/protocols/ads/readwrite/model/State.go deleted file mode 100644 index 2cfc91038..000000000 --- a/plc4go/protocols/ads/readwrite/model/State.go +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package model - -import ( - "github.com/apache/plc4x/plc4go/spi/utils" - "github.com/pkg/errors" - "github.com/rs/zerolog/log" -) - -// Code generated by code-generation. DO NOT EDIT. - -// State is the corresponding interface of State -type State interface { - utils.LengthAware - utils.Serializable - // GetInitCommand returns InitCommand (property field) - GetInitCommand() bool - // GetUpdCommand returns UpdCommand (property field) - GetUpdCommand() bool - // GetTimestampAdded returns TimestampAdded (property field) - GetTimestampAdded() bool - // GetHighPriorityCommand returns HighPriorityCommand (property field) - GetHighPriorityCommand() bool - // GetSystemCommand returns SystemCommand (property field) - GetSystemCommand() bool - // GetAdsCommand returns AdsCommand (property field) - GetAdsCommand() bool - // GetNoReturn returns NoReturn (property field) - GetNoReturn() bool - // GetResponse returns Response (property field) - GetResponse() bool - // GetBroadcast returns Broadcast (property field) - GetBroadcast() bool -} - -// StateExactly can be used when we want exactly this type and not a type which fulfills State. -// This is useful for switch cases. -type StateExactly interface { - State - isState() bool -} - -// _State is the data-structure of this message -type _State struct { - InitCommand bool - UpdCommand bool - TimestampAdded bool - HighPriorityCommand bool - SystemCommand bool - AdsCommand bool - NoReturn bool - Response bool - Broadcast bool - // Reserved Fields - reservedField0 *int8 -} - -/////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////// -/////////////////////// Accessors for property fields. -/////////////////////// - -func (m *_State) GetInitCommand() bool { - return m.InitCommand -} - -func (m *_State) GetUpdCommand() bool { - return m.UpdCommand -} - -func (m *_State) GetTimestampAdded() bool { - return m.TimestampAdded -} - -func (m *_State) GetHighPriorityCommand() bool { - return m.HighPriorityCommand -} - -func (m *_State) GetSystemCommand() bool { - return m.SystemCommand -} - -func (m *_State) GetAdsCommand() bool { - return m.AdsCommand -} - -func (m *_State) GetNoReturn() bool { - return m.NoReturn -} - -func (m *_State) GetResponse() bool { - return m.Response -} - -func (m *_State) GetBroadcast() bool { - return m.Broadcast -} - -/////////////////////// -/////////////////////// -/////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////// - -// NewState factory function for _State -func NewState(initCommand bool, updCommand bool, timestampAdded bool, highPriorityCommand bool, systemCommand bool, adsCommand bool, noReturn bool, response bool, broadcast bool) *_State { - return &_State{InitCommand: initCommand, UpdCommand: updCommand, TimestampAdded: timestampAdded, HighPriorityCommand: highPriorityCommand, SystemCommand: systemCommand, AdsCommand: adsCommand, NoReturn: noReturn, Response: response, Broadcast: broadcast} -} - -// Deprecated: use the interface for direct cast -func CastState(structType interface{}) State { - if casted, ok := structType.(State); ok { - return casted - } - if casted, ok := structType.(*State); ok { - return *casted - } - return nil -} - -func (m *_State) GetTypeName() string { - return "State" -} - -func (m *_State) GetLengthInBits() uint16 { - return m.GetLengthInBitsConditional(false) -} - -func (m *_State) GetLengthInBitsConditional(lastItem bool) uint16 { - lengthInBits := uint16(0) - - // Simple field (initCommand) - lengthInBits += 1 - - // Simple field (updCommand) - lengthInBits += 1 - - // Simple field (timestampAdded) - lengthInBits += 1 - - // Simple field (highPriorityCommand) - lengthInBits += 1 - - // Simple field (systemCommand) - lengthInBits += 1 - - // Simple field (adsCommand) - lengthInBits += 1 - - // Simple field (noReturn) - lengthInBits += 1 - - // Simple field (response) - lengthInBits += 1 - - // Simple field (broadcast) - lengthInBits += 1 - - // Reserved Field (reserved) - lengthInBits += 7 - - return lengthInBits -} - -func (m *_State) GetLengthInBytes() uint16 { - return m.GetLengthInBits() / 8 -} - -func StateParse(readBuffer utils.ReadBuffer) (State, error) { - positionAware := readBuffer - _ = positionAware - if pullErr := readBuffer.PullContext("State"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for State") - } - currentPos := positionAware.GetPos() - _ = currentPos - - // Simple Field (initCommand) - _initCommand, _initCommandErr := readBuffer.ReadBit("initCommand") - if _initCommandErr != nil { - return nil, errors.Wrap(_initCommandErr, "Error parsing 'initCommand' field of State") - } - initCommand := _initCommand - - // Simple Field (updCommand) - _updCommand, _updCommandErr := readBuffer.ReadBit("updCommand") - if _updCommandErr != nil { - return nil, errors.Wrap(_updCommandErr, "Error parsing 'updCommand' field of State") - } - updCommand := _updCommand - - // Simple Field (timestampAdded) - _timestampAdded, _timestampAddedErr := readBuffer.ReadBit("timestampAdded") - if _timestampAddedErr != nil { - return nil, errors.Wrap(_timestampAddedErr, "Error parsing 'timestampAdded' field of State") - } - timestampAdded := _timestampAdded - - // Simple Field (highPriorityCommand) - _highPriorityCommand, _highPriorityCommandErr := readBuffer.ReadBit("highPriorityCommand") - if _highPriorityCommandErr != nil { - return nil, errors.Wrap(_highPriorityCommandErr, "Error parsing 'highPriorityCommand' field of State") - } - highPriorityCommand := _highPriorityCommand - - // Simple Field (systemCommand) - _systemCommand, _systemCommandErr := readBuffer.ReadBit("systemCommand") - if _systemCommandErr != nil { - return nil, errors.Wrap(_systemCommandErr, "Error parsing 'systemCommand' field of State") - } - systemCommand := _systemCommand - - // Simple Field (adsCommand) - _adsCommand, _adsCommandErr := readBuffer.ReadBit("adsCommand") - if _adsCommandErr != nil { - return nil, errors.Wrap(_adsCommandErr, "Error parsing 'adsCommand' field of State") - } - adsCommand := _adsCommand - - // Simple Field (noReturn) - _noReturn, _noReturnErr := readBuffer.ReadBit("noReturn") - if _noReturnErr != nil { - return nil, errors.Wrap(_noReturnErr, "Error parsing 'noReturn' field of State") - } - noReturn := _noReturn - - // Simple Field (response) - _response, _responseErr := readBuffer.ReadBit("response") - if _responseErr != nil { - return nil, errors.Wrap(_responseErr, "Error parsing 'response' field of State") - } - response := _response - - // Simple Field (broadcast) - _broadcast, _broadcastErr := readBuffer.ReadBit("broadcast") - if _broadcastErr != nil { - return nil, errors.Wrap(_broadcastErr, "Error parsing 'broadcast' field of State") - } - broadcast := _broadcast - - var reservedField0 *int8 - // Reserved Field (Compartmentalized so the "reserved" variable can't leak) - { - reserved, _err := readBuffer.ReadInt8("reserved", 7) - if _err != nil { - return nil, errors.Wrap(_err, "Error parsing 'reserved' field of State") - } - if reserved != int8(0x0) { - log.Info().Fields(map[string]interface{}{ - "expected value": int8(0x0), - "got value": reserved, - }).Msg("Got unexpected response for reserved field.") - // We save the value, so it can be re-serialized - reservedField0 = &reserved - } - } - - if closeErr := readBuffer.CloseContext("State"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for State") - } - - // Create the instance - return &_State{ - InitCommand: initCommand, - UpdCommand: updCommand, - TimestampAdded: timestampAdded, - HighPriorityCommand: highPriorityCommand, - SystemCommand: systemCommand, - AdsCommand: adsCommand, - NoReturn: noReturn, - Response: response, - Broadcast: broadcast, - reservedField0: reservedField0, - }, nil -} - -func (m *_State) Serialize(writeBuffer utils.WriteBuffer) error { - positionAware := writeBuffer - _ = positionAware - if pushErr := writeBuffer.PushContext("State"); pushErr != nil { - return errors.Wrap(pushErr, "Error pushing for State") - } - - // Simple Field (initCommand) - initCommand := bool(m.GetInitCommand()) - _initCommandErr := writeBuffer.WriteBit("initCommand", (initCommand)) - if _initCommandErr != nil { - return errors.Wrap(_initCommandErr, "Error serializing 'initCommand' field") - } - - // Simple Field (updCommand) - updCommand := bool(m.GetUpdCommand()) - _updCommandErr := writeBuffer.WriteBit("updCommand", (updCommand)) - if _updCommandErr != nil { - return errors.Wrap(_updCommandErr, "Error serializing 'updCommand' field") - } - - // Simple Field (timestampAdded) - timestampAdded := bool(m.GetTimestampAdded()) - _timestampAddedErr := writeBuffer.WriteBit("timestampAdded", (timestampAdded)) - if _timestampAddedErr != nil { - return errors.Wrap(_timestampAddedErr, "Error serializing 'timestampAdded' field") - } - - // Simple Field (highPriorityCommand) - highPriorityCommand := bool(m.GetHighPriorityCommand()) - _highPriorityCommandErr := writeBuffer.WriteBit("highPriorityCommand", (highPriorityCommand)) - if _highPriorityCommandErr != nil { - return errors.Wrap(_highPriorityCommandErr, "Error serializing 'highPriorityCommand' field") - } - - // Simple Field (systemCommand) - systemCommand := bool(m.GetSystemCommand()) - _systemCommandErr := writeBuffer.WriteBit("systemCommand", (systemCommand)) - if _systemCommandErr != nil { - return errors.Wrap(_systemCommandErr, "Error serializing 'systemCommand' field") - } - - // Simple Field (adsCommand) - adsCommand := bool(m.GetAdsCommand()) - _adsCommandErr := writeBuffer.WriteBit("adsCommand", (adsCommand)) - if _adsCommandErr != nil { - return errors.Wrap(_adsCommandErr, "Error serializing 'adsCommand' field") - } - - // Simple Field (noReturn) - noReturn := bool(m.GetNoReturn()) - _noReturnErr := writeBuffer.WriteBit("noReturn", (noReturn)) - if _noReturnErr != nil { - return errors.Wrap(_noReturnErr, "Error serializing 'noReturn' field") - } - - // Simple Field (response) - response := bool(m.GetResponse()) - _responseErr := writeBuffer.WriteBit("response", (response)) - if _responseErr != nil { - return errors.Wrap(_responseErr, "Error serializing 'response' field") - } - - // Simple Field (broadcast) - broadcast := bool(m.GetBroadcast()) - _broadcastErr := writeBuffer.WriteBit("broadcast", (broadcast)) - if _broadcastErr != nil { - return errors.Wrap(_broadcastErr, "Error serializing 'broadcast' field") - } - - // Reserved Field (reserved) - { - var reserved int8 = int8(0x0) - if m.reservedField0 != nil { - log.Info().Fields(map[string]interface{}{ - "expected value": int8(0x0), - "got value": reserved, - }).Msg("Overriding reserved field with unexpected value.") - reserved = *m.reservedField0 - } - _err := writeBuffer.WriteInt8("reserved", 7, reserved) - if _err != nil { - return errors.Wrap(_err, "Error serializing 'reserved' field") - } - } - - if popErr := writeBuffer.PopContext("State"); popErr != nil { - return errors.Wrap(popErr, "Error popping for State") - } - return nil -} - -func (m *_State) isState() bool { - return true -} - -func (m *_State) String() string { - if m == nil { - return "<nil>" - } - writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true) - if err := writeBuffer.WriteSerializable(m); err != nil { - return err.Error() - } - return writeBuffer.GetBox().String() -}
