Skip to content

Commit 760e5cc

Browse files
committed
refactor: Simplified the datatypes in ADS and updated the Browse API intercept mode to not only pass in the item, but also the tag.
1 parent 316d8bb commit 760e5cc

File tree

17 files changed

+239
-1777
lines changed

17 files changed

+239
-1777
lines changed

plc4go/internal/ads/Browser.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (m *Connection) filterDataTypes(parentName string, currentType driverModel.
127127
SymbolicAddress: parentName,
128128
},
129129
parentName,
130-
currentType.GetDataTypeName(),
130+
currentType.GetSecondaryName(),
131131
false,
132132
false,
133133
false,
@@ -140,13 +140,13 @@ func (m *Connection) filterDataTypes(parentName string, currentType driverModel.
140140
currentAddressSegment := remainingAddressSegments[0]
141141
remainingAddressSegments = remainingAddressSegments[1:]
142142
for _, child := range currentType.GetChildren() {
143-
if child.GetPropertyName() == currentAddressSegment {
144-
childTypeName := child.GetDataTypeName()
143+
if child.GetMainName() == currentAddressSegment {
144+
childTypeName := child.GetSecondaryName()
145145
if symbolDataType, ok := m.driverContext.dataTypeTable[childTypeName]; !ok {
146146
// TODO: Couldn't find data type with the name defined in the protperty.
147147
return nil
148148
} else {
149-
return m.filterDataTypes(parentName+"."+child.GetPropertyName(), symbolDataType,
149+
return m.filterDataTypes(parentName+"."+child.GetMainName(), symbolDataType,
150150
currentPath+"."+currentAddressSegment, remainingAddressSegments)
151151
}
152152
}

plc4go/internal/ads/Connection.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func (m *Connection) readDataTypeTable(ctx context.Context, dataTableSize uint32
302302
if err != nil {
303303
return nil, fmt.Errorf("error parsing table: %v", err)
304304
}
305-
dataTypes[dataType.GetDataTypeName()] = dataType
305+
dataTypes[dataType.GetSecondaryName()] = dataType
306306
}
307307
return dataTypes, nil
308308
}
@@ -380,23 +380,23 @@ func (m *Connection) resolveSymbolicAddress(ctx context.Context, addressParts []
380380
curAddressPart := addressParts[0]
381381
restAddressParts := addressParts[1:]
382382
for _, child := range curDataType.GetChildren() {
383-
if child.GetPropertyName() == curAddressPart {
384-
childDataTypeName := child.GetDataTypeName()
383+
if child.GetMainName() == curAddressPart {
384+
childDataTypeName := child.GetSecondaryName()
385385
childDataType, ok := m.driverContext.dataTypeTable[childDataTypeName]
386386
if !ok {
387387
return nil, fmt.Errorf("couldn't find data type %s for property %s of data type %s",
388-
childDataTypeName, curAddressPart, curDataType.GetDataTypeName())
388+
childDataTypeName, curAddressPart, curDataType.GetSecondaryName())
389389
}
390390
return m.resolveSymbolicAddress(ctx, restAddressParts, childDataType, indexGroup, indexOffset+child.GetOffset())
391391
}
392392
}
393393
return nil, fmt.Errorf("couldn't find property named %s for data type %s",
394-
curAddressPart, curDataType.GetDataTypeName())
394+
curAddressPart, curDataType.GetSecondaryName())
395395
}
396396

397397
func (m *Connection) getPlcValueForAdsDataTypeTableEntry(entry readWriteModel.AdsDataTypeTableEntry) (apiValues.PlcValueType, int32) {
398398
stringLength := -1
399-
dataTypeName := entry.GetDataTypeName()
399+
dataTypeName := entry.GetSecondaryName()
400400
if strings.HasPrefix(dataTypeName, "STRING(") {
401401
var err error
402402
stringLength, err = strconv.Atoi(dataTypeName[7 : len(dataTypeName)-1])

plc4go/internal/ads/DriverContext.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ func (m *DriverContext) resolveDirectTag(remainingSegments []string, currentData
108108
currentSegment := remainingSegments[0]
109109
remainingSegments = remainingSegments[1:]
110110
for _, child := range currentDatatype.GetChildren() {
111-
if child.GetPropertyName() == currentSegment {
112-
childDataType, ok := m.dataTypeTable[child.GetDataTypeName()]
111+
if child.GetMainName() == currentSegment {
112+
childDataType, ok := m.dataTypeTable[child.GetSecondaryName()]
113113
if !ok {
114-
return nil, fmt.Errorf("couldn't find data type with name %s", child.GetDataTypeName())
114+
return nil, fmt.Errorf("couldn't find data type with name %s", child.GetSecondaryName())
115115
}
116116
return m.resolveDirectTag(remainingSegments, childDataType, indexGroup, indexOffset+child.GetOffset())
117117
}
118118
}
119-
return nil, fmt.Errorf("couldn't find child with name %s in type %s", currentSegment, currentDatatype.GetDataTypeName())
119+
return nil, fmt.Errorf("couldn't find child with name %s in type %s", currentSegment, currentDatatype.GetSecondaryName())
120120
}
121121

122122
func (m *DriverContext) getDataTypeForDataTypeTableEntry(entry driverModel.AdsDataTypeTableEntry) apiValues.PlcValueType {
@@ -126,7 +126,7 @@ func (m *DriverContext) getDataTypeForDataTypeTableEntry(entry driverModel.AdsDa
126126
if entry.GetNumChildren() > 0 {
127127
return apiValues.Struct
128128
}
129-
dataTypeName := entry.GetDataTypeName()
129+
dataTypeName := entry.GetSecondaryName()
130130
if strings.HasPrefix(dataTypeName, "STRING(") {
131131
dataTypeName = "STRING"
132132
} else if strings.HasPrefix(dataTypeName, "WSTRING(") {
@@ -137,7 +137,7 @@ func (m *DriverContext) getDataTypeForDataTypeTableEntry(entry driverModel.AdsDa
137137
}
138138

139139
func (m *DriverContext) getStringLengthForDataTypeTableEntry(entry driverModel.AdsDataTypeTableEntry) int32 {
140-
dataTypeName := entry.GetDataTypeName()
140+
dataTypeName := entry.GetSecondaryName()
141141
if strings.HasPrefix(dataTypeName, "STRING(") {
142142
lenStr := dataTypeName[7 : len(dataTypeName)-1]
143143
lenVal, err := strconv.Atoi(lenStr)

plc4go/internal/ads/Reader.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (m *Connection) parsePlcValue(dataType driverModel.AdsDataTypeTableEntry, a
265265
if len(arrayInfo) > 0 {
266266
// This is an Array/List type.
267267
curArrayInfo := arrayInfo[0]
268-
arrayItemTypeName := dataType.GetDataTypeName()[strings.Index(dataType.GetDataTypeName(), " OF ")+4:]
268+
arrayItemTypeName := dataType.GetSecondaryName()[strings.Index(dataType.GetSecondaryName(), " OF ")+4:]
269269
arrayItemType, ok := m.driverContext.dataTypeTable[arrayItemTypeName]
270270
if !ok {
271271
return nil, fmt.Errorf("couldn't resolve array item type %s", arrayItemTypeName)
@@ -286,10 +286,10 @@ func (m *Connection) parsePlcValue(dataType driverModel.AdsDataTypeTableEntry, a
286286
startPos := uint32(rb.GetPos())
287287
curPos := uint32(0)
288288
for _, child := range dataType.GetChildren() {
289-
childName := child.GetPropertyName()
290-
childDataType, ok := m.driverContext.dataTypeTable[child.GetDataTypeName()]
289+
childName := child.GetMainName()
290+
childDataType, ok := m.driverContext.dataTypeTable[child.GetSecondaryName()]
291291
if !ok {
292-
return nil, fmt.Errorf("couldn't find data type named %s for property %s of type %s", child.GetDataTypeName(), childName, dataType.GetDataTypeName())
292+
return nil, fmt.Errorf("couldn't find data type named %s for property %s of type %s", child.GetSecondaryName(), childName, dataType.GetSecondaryName())
293293
}
294294
if child.GetOffset() > curPos {
295295
skipBytes := child.GetOffset() - curPos
@@ -299,7 +299,7 @@ func (m *Connection) parsePlcValue(dataType driverModel.AdsDataTypeTableEntry, a
299299
}
300300
childValue, err := m.parsePlcValue(childDataType, childDataType.GetArrayInfo(), rb)
301301
if err != nil {
302-
return nil, errors.Wrap(err, fmt.Sprintf("error parsing propery %s of type %s", childName, dataType.GetDataTypeName()))
302+
return nil, errors.Wrap(err, fmt.Sprintf("error parsing propery %s of type %s", childName, dataType.GetSecondaryName()))
303303
}
304304
plcValues[childName] = childValue
305305
curPos = uint32(rb.GetPos()) - startPos
@@ -309,7 +309,7 @@ func (m *Connection) parsePlcValue(dataType driverModel.AdsDataTypeTableEntry, a
309309
// This is a primitive type.
310310
valueType, stringLength := m.getPlcValueForAdsDataTypeTableEntry(dataType)
311311
if valueType == apiValues.NULL {
312-
return nil, errors.New(fmt.Sprintf("error converting %s into plc4x plc-value type", dataType.GetDataTypeName()))
312+
return nil, errors.New(fmt.Sprintf("error converting %s into plc4x plc-value type", dataType.GetSecondaryName()))
313313
}
314314

315315
adsValueType, ok := apiValues.PlcValueTypeByName(valueType.String())

plc4go/internal/ads/ValueHandler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ func (t ValueHandler) AdsParseStructType(dataType readWriteModel.AdsDataTypeTabl
132132
childValues := plcStruct.GetStruct()
133133

134134
for _, childTypeEntry := range dataType.GetChildren() {
135-
childName := childTypeEntry.GetPropertyName()
136-
childType := t.driverContext.dataTypeTable[childTypeEntry.GetDataTypeName()]
135+
childName := childTypeEntry.GetMainName()
136+
childType := t.driverContext.dataTypeTable[childTypeEntry.GetSecondaryName()]
137137
childArrayInfo := childType.GetArrayInfo()
138-
childValue, ok := childValues[childTypeEntry.GetPropertyName()]
138+
childValue, ok := childValues[childTypeEntry.GetMainName()]
139139
if !ok {
140140
return nil, fmt.Errorf("missing child value named %s", childName)
141141
}
@@ -151,10 +151,10 @@ func (t ValueHandler) AdsParseStructType(dataType readWriteModel.AdsDataTypeTabl
151151
parsedValues := map[string]apiValues.PlcValue{}
152152

153153
for _, childTypeEntry := range dataType.GetChildren() {
154-
childName := childTypeEntry.GetPropertyName()
155-
childType := t.driverContext.dataTypeTable[childTypeEntry.GetDataTypeName()]
154+
childName := childTypeEntry.GetMainName()
155+
childType := t.driverContext.dataTypeTable[childTypeEntry.GetSecondaryName()]
156156
childArrayInfo := childType.GetArrayInfo()
157-
childValue, ok := simpleMap[childTypeEntry.GetPropertyName()]
157+
childValue, ok := simpleMap[childTypeEntry.GetMainName()]
158158
if !ok {
159159
return nil, fmt.Errorf("missing child value named %s", childName)
160160
}

plc4go/internal/ads/Writer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func (m *Connection) serializePlcValue(dataType driverModel.AdsDataTypeTableEntr
242242
return fmt.Errorf("expecting exactly %d items in the list", len(plcValues))
243243
}
244244

245-
arrayItemTypeName := dataType.GetDataTypeName()[strings.Index(dataType.GetDataTypeName(), " OF ")+4:]
245+
arrayItemTypeName := dataType.GetSecondaryName()[strings.Index(dataType.GetSecondaryName(), " OF ")+4:]
246246
arrayItemType, ok := m.driverContext.dataTypeTable[arrayItemTypeName]
247247
if !ok {
248248
return fmt.Errorf("couldn't resolve array item type %s", arrayItemTypeName)
@@ -271,10 +271,10 @@ func (m *Connection) serializePlcValue(dataType driverModel.AdsDataTypeTableEntr
271271
startPos := uint32(wb.GetPos())
272272
curPos := uint32(0)
273273
for _, child := range dataType.GetChildren() {
274-
childName := child.GetPropertyName()
275-
childDataType, ok := m.driverContext.dataTypeTable[child.GetDataTypeName()]
274+
childName := child.GetMainName()
275+
childDataType, ok := m.driverContext.dataTypeTable[child.GetSecondaryName()]
276276
if !ok {
277-
return fmt.Errorf("couldn't find data type named %s for property %s of type %s", child.GetDataTypeName(), childName, dataType.GetDataTypeName())
277+
return fmt.Errorf("couldn't find data type named %s for property %s of type %s", child.GetSecondaryName(), childName, dataType.GetSecondaryName())
278278
}
279279
if child.GetOffset() > curPos {
280280
skipBytes := child.GetOffset() - curPos
@@ -291,7 +291,7 @@ func (m *Connection) serializePlcValue(dataType driverModel.AdsDataTypeTableEntr
291291
}
292292
err := m.serializePlcValue(childDataType, childArrayInfo, plcValues[childName], wb)
293293
if err != nil {
294-
return errors.Wrap(err, fmt.Sprintf("error parsing propery %s of type %s", childName, dataType.GetDataTypeName()))
294+
return errors.Wrap(err, fmt.Sprintf("error parsing propery %s of type %s", childName, dataType.GetSecondaryName()))
295295
}
296296
curPos = uint32(wb.GetPos()) - startPos
297297
}
@@ -300,7 +300,7 @@ func (m *Connection) serializePlcValue(dataType driverModel.AdsDataTypeTableEntr
300300
// This is a primitive type.
301301
valueType, stringLength := m.getPlcValueForAdsDataTypeTableEntry(dataType)
302302
if valueType == apiValues.NULL {
303-
return errors.New(fmt.Sprintf("error converting %s into plc4x plc-value type", dataType.GetDataTypeName()))
303+
return errors.New(fmt.Sprintf("error converting %s into plc4x plc-value type", dataType.GetSecondaryName()))
304304
}
305305
adsValueType, ok := apiValues.PlcValueTypeByName(valueType.String())
306306
if !ok {

plc4go/protocols/ads/readwrite/ParserHelper.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plc4go/protocols/ads/readwrite/XmlParserHelper.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)