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 2021/10/05 07:52:42 UTC
[plc4x] branch feature/mspec-ng updated: - Made the expression for
the length of 'vstring' fields optional - Updated all places where we had
lengths of "-1" (mostly in arguments) to use vstring instead.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/mspec-ng
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/mspec-ng by this push:
new b23f493 - Made the expression for the length of 'vstring' fields optional - Updated all places where we had lengths of "-1" (mostly in arguments) to use vstring instead.
b23f493 is described below
commit b23f4939be8abe925f2528da529fc0962ce48654
Author: cdutz <ch...@c-ware.de>
AuthorDate: Tue Oct 5 09:51:35 2021 +0200
- Made the expression for the length of 'vstring' fields optional
- Updated all places where we had lengths of "-1" (mostly in arguments) to use vstring instead.
---
.../plugins/codegenerator/language/mspec/MSpec.g4 | 2 +-
.../mspec/parser/MessageFormatListener.java | 8 +++-
.../plc4go/ads/readwrite/model/DataItem.go | 26 ++++++++++++
.../ads/src/main/resources/protocols/ads/ads.mspec | 12 +++---
.../resources/protocols/knxnetip/knxnetip.mspec | 4 +-
.../resources/protocols/profinet/profinet.mspec | 46 +++++++++++-----------
.../s7/src/main/resources/protocols/s7/s7.mspec | 8 ++--
.../resources/protocols/simulated/simulated.mspec | 2 +-
8 files changed, 69 insertions(+), 39 deletions(-)
diff --git a/code-generation/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4 b/code-generation/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
index 07ee8e2..0a3edd4 100644
--- a/code-generation/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
+++ b/code-generation/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
@@ -143,7 +143,7 @@ typeReference
;
caseStatement
- : LBRACKET (discriminatorValues=multipleExpressions)? name=IDENTIFIER_LITERAL (LBRACKET params=argumentList RBRACKET)? fieldDefinition* RBRACKET
+ : LBRACKET (discriminatorValues=multipleExpressions)? name=IDENTIFIER_LITERAL (LBRACKET params=argumentList RBRACKET)? (fieldDefinition|batchSetDefinition)* RBRACKET
;
dataType
diff --git a/code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java b/code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
index 39838a4..9bddc5a 100644
--- a/code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
+++ b/code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
@@ -480,8 +480,12 @@ public class MessageFormatListener extends MSpecBaseListener {
if ((simpleBaseType == SimpleTypeReference.SimpleBaseType.STRING) ||
(simpleBaseType == SimpleTypeReference.SimpleBaseType.VSTRING)) {
if (simpleBaseType == SimpleTypeReference.SimpleBaseType.VSTRING) {
- Term lengthExpression = getExpressionTerm(ctx.length.getText().substring(1, ctx.length.getText().length() - 1));
- return new DefaultStringTypeReference(simpleBaseType, lengthExpression, "UTF-8");
+ if(ctx.length != null) {
+ Term lengthExpression = getExpressionTerm(ctx.length.getText().substring(1, ctx.length.getText().length() - 1));
+ return new DefaultStringTypeReference(simpleBaseType, lengthExpression, "UTF-8");
+ } else {
+ return new DefaultStringTypeReference(simpleBaseType, null, "UTF-8");
+ }
} else {
int size = Integer.parseInt(ctx.size.getText());
return new DefaultStringTypeReference(simpleBaseType, new DefaultNumericLiteral(size), "UTF-8");
diff --git a/plc4go/internal/plc4go/ads/readwrite/model/DataItem.go b/plc4go/internal/plc4go/ads/readwrite/model/DataItem.go
index 6943796..3ed8ff0 100644
--- a/plc4go/internal/plc4go/ads/readwrite/model/DataItem.go
+++ b/plc4go/internal/plc4go/ads/readwrite/model/DataItem.go
@@ -164,7 +164,23 @@ func DataItemParse(readBuffer utils.ReadBuffer, dataFormatName string, stringLen
readBuffer.CloseContext("DataItem")
return values.NewPlcLREAL(value), nil
case dataFormatName == "IEC61131_CHAR": // STRING
+
+ // Simple Field (value)
+ value, _valueErr := readBuffer.ReadString("value", uint32((8)))
+ if _valueErr != nil {
+ return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ }
+ readBuffer.CloseContext("DataItem")
+ return values.NewPlcSTRING(value), nil
case dataFormatName == "IEC61131_WCHAR": // STRING
+
+ // Simple Field (value)
+ value, _valueErr := readBuffer.ReadString("value", uint32((16)))
+ if _valueErr != nil {
+ return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ }
+ readBuffer.CloseContext("DataItem")
+ return values.NewPlcSTRING(value), nil
case dataFormatName == "IEC61131_STRING": // STRING
// Manual Field (value)
@@ -327,7 +343,17 @@ func DataItemSerialize(writeBuffer utils.WriteBuffer, value api.PlcValue, dataFo
return errors.Wrap(_err, "Error serializing 'value' field")
}
case dataFormatName == "IEC61131_CHAR": // STRING
+
+ // Simple Field (value)
+ if _err := writeBuffer.WriteString("value", uint8((8)), "TF-", value.GetString()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'value' field")
+ }
case dataFormatName == "IEC61131_WCHAR": // STRING
+
+ // Simple Field (value)
+ if _err := writeBuffer.WriteString("value", uint8((16)), "TF-", value.GetString()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'value' field")
+ }
case dataFormatName == "IEC61131_STRING": // STRING
// Manual Field (value)
diff --git a/protocols/ads/src/main/resources/protocols/ads/ads.mspec b/protocols/ads/src/main/resources/protocols/ads/ads.mspec
index bf5c9ae..e72c6cf 100644
--- a/protocols/ads/src/main/resources/protocols/ads/ads.mspec
+++ b/protocols/ads/src/main/resources/protocols/ads/ads.mspec
@@ -386,7 +386,7 @@
[array int 8 'data' count 'sampleSize']
]
-[dataIo 'DataItem' [string 8 'dataFormatName', int 32 'stringLength']
+[dataIo 'DataItem' [vstring 'dataFormatName', int 32 'stringLength']
[typeSwitch 'dataFormatName'
// -----------------------------------------
// Bit
@@ -458,18 +458,18 @@
// Characters & Strings
// -----------------------------------------
['IEC61131_CHAR' STRING
-// [simple string 8 'value']
+ [simple string 8 'value']
]
['IEC61131_WCHAR' STRING
-// [simple string 16 'value' encoding='"UTF-16"']
+ [simple string 16 'value' encoding='"UTF-16"']
]
['IEC61131_STRING' STRING
// TODO: Fix this length
- [manual string 8 'value' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.parseAmsString", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.serializeAmsString", writeBuffer, _value, stringLength, _type.encoding)' 'stringLength + 1']
+ [manual vstring 'value' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.parseAmsString", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.serializeAmsString", writeBuffer, _value, stringLength, _type.encoding)' 'stringLength + 1']
]
['IEC61131_WSTRING' STRING
// TODO: Fix this length
- [manual string 8 'value' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.parseAmsString", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.serializeAmsString", writeBuffer, _value, stringLength, _type.encoding)' '(stringLength * 2) + 2' encoding='"UTF-16"']
+ [manual vstring 'value' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.parseAmsString", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.serializeAmsString", writeBuffer, _value, stringLength, _type.encoding)' '(stringLength * 2) + 2' encoding='"UTF-16"']
]
// -----------------------------------------
@@ -498,7 +498,7 @@
]
]
-[enum int 8 'AdsDataType' [uint 16 'numBytes', string 8 'dataFormatName']
+[enum int 8 'AdsDataType' [uint 16 'numBytes', vstring 'dataFormatName']
['0x01' BOOL ['1', 'IEC61131_BOOL']]
['0x02' BIT ['1', 'IEC61131_BOOL']]
['0x03' BIT8 ['1', 'IEC61131_BOOL']]
diff --git a/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec b/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
index e512b57..8f9f895 100644
--- a/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
+++ b/protocols/knxnetip/src/main/resources/protocols/knxnetip/knxnetip.mspec
@@ -683,7 +683,7 @@
['0x20' MEDIUM_KNX_IP]
]
-[enum uint 8 'SupportedPhysicalMedia' [string 8 'description', bit 'knxSupport']
+[enum uint 8 'SupportedPhysicalMedia' [vstring 'description', bit 'knxSupport']
['0x00' OTHER ['used_for_undefined_physical_medium', 'true']]
['0x01' OIL_METER ['measures_volume_of_oil', 'true']]
['0x02' ELECTRICITY_METER ['measures_electric_energy', 'true']]
@@ -775,7 +775,7 @@
['0x5705' KNX_IP_SYSTEM7 ['KNX_IP', 'SYSTEM_7' ]]
]
-[enum uint 4 'AccessLevel' [string 8 'purpose', bit 'needsAuthentication']
+[enum uint 4 'AccessLevel' [vstring 'purpose', bit 'needsAuthentication']
['0x0' Level0 ['"system manufacturer"', 'true' ]]
['0x1' Level1 ['"product manufacturer"', 'true' ]]
['0x2' Level2 ['"configuration"', 'true' ]]
diff --git a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
index 39e3b4a..cf6f7ea 100644
--- a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
+++ b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
@@ -568,28 +568,28 @@
[simple uint 8 'blockVersionLow' ]
[typeSwitch 'blockType'
['AR_BLOCK_REQ' PnIoCm_Block_ArReq
- [simple PnIoCm_ArType 'arType' ]
- [simple Uuid 'arUuid' ]
- [simple uint 16 'sessionKey' ]
- [simple MacAddress 'cmInitiatorMacAddr' ]
- [simple Uuid 'cmInitiatorObjectUuid' ]
+ [simple PnIoCm_ArType 'arType' ]
+ [simple Uuid 'arUuid' ]
+ [simple uint 16 'sessionKey' ]
+ [simple MacAddress 'cmInitiatorMacAddr' ]
+ [simple Uuid 'cmInitiatorObjectUuid' ]
// Begin ARProperties
- [simple bit 'pullModuleAlarmAllowed' ]
- [simple bit 'nonLegacyStartupMode' ]
- [simple bit 'combinedObjectContainerUsed' ]
- [reserved uint 17 '0x00000' ]
- [simple bit 'acknowledgeCompanionAr' ]
- [simple PnIoCm_CompanionArType 'companionArType' ]
- [simple bit 'deviceAccess' ]
- [reserved uint 3 '0x0' ]
- [simple bit 'cmInitiator' ]
- [simple bit 'supervisorTakeoverAllowed' ]
- [simple PnIoCm_State 'state' ]
+ [simple bit 'pullModuleAlarmAllowed' ]
+ [simple bit 'nonLegacyStartupMode' ]
+ [simple bit 'combinedObjectContainerUsed' ]
+ [reserved uint 17 '0x00000' ]
+ [simple bit 'acknowledgeCompanionAr' ]
+ [simple PnIoCm_CompanionArType 'companionArType' ]
+ [simple bit 'deviceAccess' ]
+ [reserved uint 3 '0x0' ]
+ [simple bit 'cmInitiator' ]
+ [simple bit 'supervisorTakeoverAllowed' ]
+ [simple PnIoCm_State 'state' ]
// End ARProperties
- [simple uint 16 'cmInitiatorActivityTimeoutFactor' ]
- [simple uint 16 'cmInitiatorUdpRtPort' ]
- [implicit uint 16 'stationNameLength' 'STR_LEN(cmInitiatorStationName)' ]
- [simple vstring 'stationNameLength * 8' 'cmInitiatorStationName' ]
+ [simple uint 16 'cmInitiatorActivityTimeoutFactor' ]
+ [simple uint 16 'cmInitiatorUdpRtPort' ]
+ [implicit uint 16 'stationNameLength' 'STR_LEN(cmInitiatorStationName)']
+ [simple vstring 'stationNameLength * 8' 'cmInitiatorStationName' ]
]
['AR_BLOCK_RES' PnIoCm_Block_ArRes
[simple PnIoCm_ArType 'arType' ]
@@ -659,9 +659,9 @@
[array PnIoCm_ModuleDiffBlockApi 'apis' count 'numberOfApis' ]
]
['AR_SERVER_BLOCK' PnIoCm_Block_ArServer
- //[implicit uint 16 'stationNameLength' 'STR_LEN(cmInitiatorStationName)']
- //[simple string 'stationNameLength * 8' 'cmInitiatorStationName' ]
- //[padding byte '0x00' ]
+ //[implicit uint 16 'stationNameLength' 'STR_LEN(cmInitiatorStationName)']
+ //[simple vstring 'stationNameLength * 8' 'cmInitiatorStationName' ]
+ //[padding byte '0x00' ]
]
]
]
diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index 8544d08..fb01c18 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -521,7 +521,7 @@
]
]
-[dataIo 'DataItem' [string 8 'dataProtocolId', int 32 'stringLength']
+[dataIo 'DataItem' [vstring 'dataProtocolId', int 32 'stringLength']
[typeSwitch 'dataProtocolId'
// -----------------------------------------
// Bit
@@ -604,11 +604,11 @@
]
['IEC61131_STRING' STRING
// TODO: Fix this length
- [manual string 8 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", writeBuffer, _value, stringLength, _type.encoding)' 'STR_LEN(_value) + 2']
+ [manual vstring 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", writeBuffer, _value, stringLength, _type.encoding)' 'STR_LEN(_value) + 2']
]
['IEC61131_WSTRING' STRING
// TODO: Fix this length
- [manual string 16 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", writeBuffer, _value, stringLength, _type.encoding)' '(STR_LEN(_value) * 2) + 2' encoding='"UTF-16"']
+ [manual vstring 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", writeBuffer, _value, stringLength, _type.encoding)' '(STR_LEN(_value) * 2) + 2' encoding='"UTF-16"']
]
// -----------------------------------------
@@ -681,7 +681,7 @@
['0x03' OTHERS ]
]
-[enum int 8 'TransportSize' [uint 8 'code', uint 8 'shortName', uint 8 'sizeInBytes', TransportSize 'baseType', DataTransportSize 'dataTransportSize', string 8 'dataProtocolId', bit 'supported_S7_300', bit 'supported_S7_400', bit 'supported_S7_1200', bit 'supported_S7_1500', bit 'supported_LOGO']
+[enum int 8 'TransportSize' [uint 8 'code', uint 8 'shortName', uint 8 'sizeInBytes', TransportSize 'baseType', DataTransportSize 'dataTransportSize', vstring 'dataProtocolId', bit 'supported_S7_300', bit 'supported_S7_400', bit 'supported_S7_1200', bit 'supported_S7_1500', bit 'supported_LOGO']
// Bit Strings
['0x01' BOOL ['0x01' , 'X' , '1' , 'null' , 'BIT' , 'IEC61131_BOOL' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
['0x02' BYTE ['0x02' , 'B' , '1' , 'null' , 'BYTE_WORD_DWORD' , 'IEC61131_BYTE' , 'true' , 'true' , 'true' , 'true' , 'true' ]]
diff --git a/protocols/simulated/src/main/resources/protocols/simulated/simulated.mspec b/protocols/simulated/src/main/resources/protocols/simulated/simulated.mspec
index b3c44f3..d31fbf6 100644
--- a/protocols/simulated/src/main/resources/protocols/simulated/simulated.mspec
+++ b/protocols/simulated/src/main/resources/protocols/simulated/simulated.mspec
@@ -23,7 +23,7 @@
[simple uint 16 'dummy']
]
-[dataIo 'DataItem' [string 8 'dataType', uint 16 'numberOfValues']
+[dataIo 'DataItem' [vstring 'dataType', uint 16 'numberOfValues']
[typeSwitch 'dataType','numberOfValues'
['BOOL','1' BOOL
[simple bit 'value']