You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2022/08/14 18:31:19 UTC
[plc4x] 03/03: chore(plc4j/ads): Introduced a data-type child type as it seems things were arranged a bit different there (the name being the property-name and the data-type-name being locaded in the other field.
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 bd11621939e5b876e39fd2b017543418e9e06a89
Author: Christofer Dutz <ch...@rivian.com>
AuthorDate: Sun Aug 14 20:31:06 2022 +0200
chore(plc4j/ads): Introduced a data-type child type as it seems things were arranged a bit different there (the name being the property-name and the data-type-name being locaded in the other field.
---
plc4go/protocols/ads/readwrite/ParserHelper.go | 2 ++
plc4go/protocols/ads/readwrite/XmlParserHelper.go | 2 ++
.../ads/readwrite/model/AdsDataTypeArrayInfo.go | 2 +-
.../ads/readwrite/model/AdsDataTypeTableEntry.go | 16 ++++-----
.../model/AdsSignificantGroupAddresses.go | 2 +-
.../ads/readwrite/model/AdsSymbolTableEntry.go | 2 +-
.../protocols/ads/readwrite/model/AdsTableSizes.go | 2 +-
.../plc4x/java/ads/protocol/AdsProtocolLogic.java | 8 ++---
.../ads/src/main/resources/protocols/ads/ads.mspec | 38 ++++++++++++++++++++--
9 files changed, 55 insertions(+), 19 deletions(-)
diff --git a/plc4go/protocols/ads/readwrite/ParserHelper.go b/plc4go/protocols/ads/readwrite/ParserHelper.go
index fd8861425..d56304775 100644
--- a/plc4go/protocols/ads/readwrite/ParserHelper.go
+++ b/plc4go/protocols/ads/readwrite/ParserHelper.go
@@ -71,6 +71,8 @@ func (m AdsParserHelper) Parse(typeName string, arguments []string, io utils.Rea
return model.AdsStampHeaderParse(io)
case "AmsSerialResetFrame":
return model.AmsSerialResetFrameParse(io)
+ case "AdsDataTypeTableChildEntry":
+ return model.AdsDataTypeTableChildEntryParse(io)
case "AdsConstants":
return model.AdsConstantsParse(io)
case "AdsNotificationSample":
diff --git a/plc4go/protocols/ads/readwrite/XmlParserHelper.go b/plc4go/protocols/ads/readwrite/XmlParserHelper.go
index 9d83f29a9..15cbe3bf4 100644
--- a/plc4go/protocols/ads/readwrite/XmlParserHelper.go
+++ b/plc4go/protocols/ads/readwrite/XmlParserHelper.go
@@ -78,6 +78,8 @@ func (m AdsXmlParserHelper) Parse(typeName string, xmlString string, parserArgum
return model.AdsStampHeaderParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
case "AmsSerialResetFrame":
return model.AmsSerialResetFrameParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
+ case "AdsDataTypeTableChildEntry":
+ return model.AdsDataTypeTableChildEntryParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
case "AdsConstants":
return model.AdsConstantsParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
case "AdsNotificationSample":
diff --git a/plc4go/protocols/ads/readwrite/model/AdsDataTypeArrayInfo.go b/plc4go/protocols/ads/readwrite/model/AdsDataTypeArrayInfo.go
index 9d997e1ba..5750d636f 100644
--- a/plc4go/protocols/ads/readwrite/model/AdsDataTypeArrayInfo.go
+++ b/plc4go/protocols/ads/readwrite/model/AdsDataTypeArrayInfo.go
@@ -20,7 +20,7 @@
package model
import (
- "github.com/apache/plc4x/plc4go/internal/spi/utils"
+ "github.com/apache/plc4x/plc4go/spi/utils"
"github.com/pkg/errors"
)
diff --git a/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableEntry.go b/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableEntry.go
index 2372be332..8a9905d06 100644
--- a/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableEntry.go
+++ b/plc4go/protocols/ads/readwrite/model/AdsDataTypeTableEntry.go
@@ -21,7 +21,7 @@ package model
import (
"fmt"
- "github.com/apache/plc4x/plc4go/internal/spi/utils"
+ "github.com/apache/plc4x/plc4go/spi/utils"
"github.com/pkg/errors"
)
@@ -65,7 +65,7 @@ type AdsDataTypeTableEntry interface {
// GetArrayInfo returns ArrayInfo (property field)
GetArrayInfo() []AdsDataTypeArrayInfo
// GetChildren returns Children (property field)
- GetChildren() []AdsDataTypeTableEntry
+ GetChildren() []AdsDataTypeTableChildEntry
// GetRest returns Rest (property field)
GetRest() []byte
}
@@ -93,7 +93,7 @@ type _AdsDataTypeTableEntry struct {
DataTypeName string
Comment string
ArrayInfo []AdsDataTypeArrayInfo
- Children []AdsDataTypeTableEntry
+ Children []AdsDataTypeTableChildEntry
Rest []byte
}
@@ -158,7 +158,7 @@ func (m *_AdsDataTypeTableEntry) GetArrayInfo() []AdsDataTypeArrayInfo {
return m.ArrayInfo
}
-func (m *_AdsDataTypeTableEntry) GetChildren() []AdsDataTypeTableEntry {
+func (m *_AdsDataTypeTableEntry) GetChildren() []AdsDataTypeTableChildEntry {
return m.Children
}
@@ -193,7 +193,7 @@ func (m *_AdsDataTypeTableEntry) GetCommentTerminator() uint8 {
///////////////////////////////////////////////////////////
// NewAdsDataTypeTableEntry factory function for _AdsDataTypeTableEntry
-func NewAdsDataTypeTableEntry(entryLength uint32, version uint32, hashValue uint32, typeHashValue uint32, size uint32, offset uint32, dataType uint32, flags uint32, arrayDimensions uint16, numChildren uint16, name string, dataTypeName string, comment string, arrayInfo []AdsDataTypeArrayInfo, children []AdsDataTypeTableEntry, rest []byte) *_AdsDataTypeTableEntry {
+func NewAdsDataTypeTableEntry(entryLength uint32, version uint32, hashValue uint32, typeHashValue uint32, size uint32, offset uint32, dataType uint32, flags uint32, arrayDimensions uint16, numChildren uint16, name string, dataTypeName string, comment string, arrayInfo []AdsDataTypeArrayInfo, children []AdsDataTypeTableChildEntry, rest []byte) *_AdsDataTypeTableEntry {
return &_AdsDataTypeTableEntry{EntryLength: entryLength, Version: version, HashValue: hashValue, TypeHashValue: typeHashValue, Size: size, Offset: offset, DataType: dataType, Flags: flags, ArrayDimensions: arrayDimensions, NumChildren: numChildren, Name: name, DataTypeName: dataTypeName, Comment: comment, ArrayInfo: arrayInfo, Children: children, Rest: rest}
}
@@ -482,18 +482,18 @@ func AdsDataTypeTableEntryParse(readBuffer utils.ReadBuffer) (AdsDataTypeTableEn
return nil, errors.Wrap(pullErr, "Error pulling for children")
}
// Count array
- children := make([]AdsDataTypeTableEntry, numChildren)
+ children := make([]AdsDataTypeTableChildEntry, numChildren)
// This happens when the size is set conditional to 0
if len(children) == 0 {
children = nil
}
{
for curItem := uint16(0); curItem < uint16(numChildren); curItem++ {
- _item, _err := AdsDataTypeTableEntryParse(readBuffer)
+ _item, _err := AdsDataTypeTableChildEntryParse(readBuffer)
if _err != nil {
return nil, errors.Wrap(_err, "Error parsing 'children' field of AdsDataTypeTableEntry")
}
- children[curItem] = _item.(AdsDataTypeTableEntry)
+ children[curItem] = _item.(AdsDataTypeTableChildEntry)
}
}
if closeErr := readBuffer.CloseContext("children", utils.WithRenderAsList(true)); closeErr != nil {
diff --git a/plc4go/protocols/ads/readwrite/model/AdsSignificantGroupAddresses.go b/plc4go/protocols/ads/readwrite/model/AdsSignificantGroupAddresses.go
index 8f70a6bba..d4ef38d20 100644
--- a/plc4go/protocols/ads/readwrite/model/AdsSignificantGroupAddresses.go
+++ b/plc4go/protocols/ads/readwrite/model/AdsSignificantGroupAddresses.go
@@ -20,7 +20,7 @@
package model
import (
- "github.com/apache/plc4x/plc4go/internal/spi/utils"
+ "github.com/apache/plc4x/plc4go/spi/utils"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)
diff --git a/plc4go/protocols/ads/readwrite/model/AdsSymbolTableEntry.go b/plc4go/protocols/ads/readwrite/model/AdsSymbolTableEntry.go
index 352ab0900..fdc007bfd 100644
--- a/plc4go/protocols/ads/readwrite/model/AdsSymbolTableEntry.go
+++ b/plc4go/protocols/ads/readwrite/model/AdsSymbolTableEntry.go
@@ -21,7 +21,7 @@ package model
import (
"fmt"
- "github.com/apache/plc4x/plc4go/internal/spi/utils"
+ "github.com/apache/plc4x/plc4go/spi/utils"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)
diff --git a/plc4go/protocols/ads/readwrite/model/AdsTableSizes.go b/plc4go/protocols/ads/readwrite/model/AdsTableSizes.go
index ebd3d2b1a..f90f2100a 100644
--- a/plc4go/protocols/ads/readwrite/model/AdsTableSizes.go
+++ b/plc4go/protocols/ads/readwrite/model/AdsTableSizes.go
@@ -20,7 +20,7 @@
package model
import (
- "github.com/apache/plc4x/plc4go/internal/spi/utils"
+ "github.com/apache/plc4x/plc4go/spi/utils"
"github.com/pkg/errors"
)
diff --git a/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java b/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
index 558184d9c..8ceade36f 100644
--- a/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
+++ b/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
@@ -197,7 +197,7 @@ public class AdsProtocolLogic extends Plc4xProtocolBase<AmsTCPPacket> implements
LOGGER.error("Error fetching symbol and datatype table sizes");
} else {
for (AdsDataTypeTableEntry dataType : dataTypes) {
- dataTypeTable.put(dataType.getName(), dataType);
+ dataTypeTable.put(dataType.getDataTypeName(), dataType);
}
for (AdsSymbolTableEntry symbol : symbols) {
symbolTable.put(symbol.getName(), symbol);
@@ -239,15 +239,15 @@ public class AdsProtocolLogic extends Plc4xProtocolBase<AmsTCPPacket> implements
}
List<PlcBrowseItem> values = new ArrayList<>(dataType.getNumChildren());
- for (AdsDataTypeTableEntry child : dataType.getChildren()) {
- values.add(new DefaultPlcBrowseItem(basePath + "." + child.getName(), child.getDataTypeName()));
+ for (AdsDataTypeTableChildEntry child : dataType.getChildren()) {
+ values.add(new DefaultPlcBrowseItem(basePath + "." + child.getPropertyName(), child.getDataTypeName()));
AdsDataTypeTableEntry childDataType = dataTypeTable.get(child.getDataTypeName());
if(childDataType == null) {
System.out.printf("couldn't find datatype: %s%n", child.getDataTypeName());
continue;
}
// Recursively add all children of the current datatype.
- values.addAll(getBrowseItems(child.getName(), baseGroupId, baseOffset + child.getOffset(), childDataType));
+ values.addAll(getBrowseItems(child.getDataTypeName(), baseGroupId, baseOffset + child.getOffset(), childDataType));
}
return values;
}
diff --git a/protocols/ads/src/main/resources/protocols/ads/ads.mspec b/protocols/ads/src/main/resources/protocols/ads/ads.mspec
index c938e4f26..f8421ba02 100644
--- a/protocols/ads/src/main/resources/protocols/ads/ads.mspec
+++ b/protocols/ads/src/main/resources/protocols/ads/ads.mspec
@@ -800,6 +800,38 @@
// https://gitlab.com/xilix-systems-llc/go-native-ads/-/blob/master/symbols.go#L15
[discriminatedType AdsDataTypeTableEntry byteOrder='LITTLE_ENDIAN'
+ [simple uint 32 entryLength ]
+ [simple uint 32 version ]
+ [simple uint 32 hashValue ]
+ [simple uint 32 typeHashValue ]
+ [simple uint 32 size ]
+ [simple uint 32 offset ]
+ [simple uint 32 dataType ]
+ [simple uint 32 flags ]
+ [implicit uint 16 dataTypeNameLength 'STR_LEN(dataTypeName)' ]
+ [implicit uint 16 simpleTypeNameLength 'STR_LEN(simpleTypeName)' ]
+ [implicit uint 16 commentLength 'STR_LEN(comment)' ]
+ [simple uint 16 arrayDimensions ]
+ [simple uint 16 numChildren ]
+ [simple vstring 'dataTypeNameLength * 8' dataTypeName ]
+ [const uint 8 dataTypeNameTerminator 0x00 ]
+ [simple vstring 'simpleTypeNameLength * 8' simpleTypeName ]
+ [const uint 8 simpleTypeNameTerminator 0x00 ]
+ [simple vstring 'commentLength * 8' comment ]
+ [const uint 8 commentTerminator 0x00 ]
+ [array AdsDataTypeArrayInfo arrayInfo count 'arrayDimensions' ]
+ [array AdsDataTypeTableChildEntry children count 'numChildren' ]
+ // Gobbling up the rest, but it seems there is content in here, when looking
+ // at the data in wireshark, it seems to be related to the flags field.
+ // Will have to continue searching for more details on how to decode this.
+ // I would assume that we'll have some "optional" fields here which depend
+ // on values in the flags section.
+ [array byte rest length 'entryLength - curPos']
+]
+
+// In data-type child entries, the name seems to be used by the property name and the data-type name seems to contain
+// what in the parent case the "name" attribute seems to use.
+[discriminatedType AdsDataTypeTableChildEntry byteOrder='LITTLE_ENDIAN'
[simple uint 32 entryLength ]
[simple uint 32 version ]
[simple uint 32 hashValue ]
@@ -808,13 +840,13 @@
[simple uint 32 offset ]
[simple uint 32 dataType ]
[simple uint 32 flags ]
- [implicit uint 16 nameLength 'STR_LEN(name)' ]
+ [implicit uint 16 propertyNameLength 'STR_LEN(propertyName)' ]
[implicit uint 16 dataTypeNameLength 'STR_LEN(dataTypeName)' ]
[implicit uint 16 commentLength 'STR_LEN(comment)' ]
[simple uint 16 arrayDimensions ]
[simple uint 16 numChildren ]
- [simple vstring 'nameLength * 8' name ]
- [const uint 8 nameTerminator 0x00 ]
+ [simple vstring 'propertyNameLength * 8' propertyName ]
+ [const uint 8 propertyNameTerminator 0x00 ]
[simple vstring 'dataTypeNameLength * 8' dataTypeName ]
[const uint 8 dataTypeNameTerminator 0x00 ]
[simple vstring 'commentLength * 8' comment ]