You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2019/12/10 14:44:18 UTC
[plc4x] branch feature/ams_ads_mpsec updated: removed bitmask and
parent expression as well as basic work on ads spec
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch feature/ams_ads_mpsec
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/ams_ads_mpsec by this push:
new ca049eb removed bitmask and parent expression as well as basic work on ads spec
ca049eb is described below
commit ca049eb2285db771568c3d34cb0118e3edef2c75
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Dec 10 15:43:41 2019 +0100
removed bitmask and parent expression as well as basic work on ads spec
---
.../plugins/codegenerator/language/mspec/MSpec.g4 | 7 ---
.../language/mspec/expression/Expression.g4 | 1 -
.../mspec/expression/ExpressionStringListener.java | 11 ----
.../expression/ExpressionStringParserTest.java | 18 ------
.../src/test/resources/mspec.example | 67 ++++++++++++++++------
.../main/resources/protocols/amsads/amsads.mspec | 67 ++++++++++++++++------
6 files changed, 98 insertions(+), 73 deletions(-)
diff --git a/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4 b/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
index 5161ba7..de581ab 100644
--- a/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
+++ b/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
@@ -31,7 +31,6 @@ complexType
: 'type' name=idExpression (LBRACKET params=argumentList RBRACKET)? fieldDefinition+
| 'discriminatedType' name=idExpression (LBRACKET params=argumentList RBRACKET)? fieldDefinition+
| 'enum' type=typeReference name=idExpression (LBRACKET params=argumentList RBRACKET)? enumValues=enumValueDefinition+
- | 'bitmask' type=typeReference name=idExpression (LBRACKET params=argumentList RBRACKET)? bitmaskValues=bitmaskValueDefinition+
;
@@ -46,7 +45,6 @@ field
| constField
| discriminatorField
| enumField
- | bitmaskField
| implicitField
| manualArrayField
| manualField
@@ -78,10 +76,6 @@ enumField
: 'enum' type=typeReference name=idExpression
;
-bitmaskField
- : 'bitmask' type=typeReference name=idExpression
- ;
-
implicitField
: 'implicit' type=dataType name=idExpression serializationExpression=expression
;
@@ -173,7 +167,6 @@ innerExpression
| '(' innerExpression ')'
| '"' innerExpression '"'
| '!' innerExpression
- | '../' innerExpression
;
COMMENT
diff --git a/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/Expression.g4 b/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/Expression.g4
index fcda12a..7e8c288 100644
--- a/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/Expression.g4
+++ b/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/Expression.g4
@@ -52,7 +52,6 @@ expression
| identifierSegment #identifierExpression
| String indexes? #stringExpression
| '(' expression ')' indexes? #expressionExpression
- | '../' expression #parentExpression
;
identifierSegment
diff --git a/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/ExpressionStringListener.java b/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/ExpressionStringListener.java
index eb72be7..f4ae9e3 100644
--- a/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/ExpressionStringListener.java
+++ b/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/ExpressionStringListener.java
@@ -187,17 +187,6 @@ public class ExpressionStringListener extends ExpressionBaseListener {
parserContexts.peek().add(ut);
}
- @Override
- public void enterParentExpression(ExpressionParser.ParentExpressionContext ctx) {
- parserContexts.push(new LinkedList<>());
- }
-
- @Override
- public void exitParentExpression(ExpressionParser.ParentExpressionContext ctx) {
- UnaryTerm ut = getUnaryTerm("..", parserContexts.pop());
- parserContexts.peek().add(ut);
- }
-
/////////////////////////////////////////////////////////////////////////////////////////
// Binary Terms
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/build-utils/protocol-base-mspec/src/test/java/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/ExpressionStringParserTest.java b/build-utils/protocol-base-mspec/src/test/java/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/ExpressionStringParserTest.java
index a89065f..d703b1f 100644
--- a/build-utils/protocol-base-mspec/src/test/java/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/ExpressionStringParserTest.java
+++ b/build-utils/protocol-base-mspec/src/test/java/org/apache/plc4x/plugins/codegenerator/language/mspec/expression/ExpressionStringParserTest.java
@@ -140,24 +140,6 @@ class ExpressionStringParserTest {
);
}
- @Test
- void testParentReference() {
- Term term = SUT.parse(IOUtils.toInputStream("../data.lengthInBytes", Charset.defaultCharset()));
- assertThat(term, not(nullValue()));
- assertThat(term, instanceOf(UnaryTerm.class));
- UnaryTerm unaryTerm = (UnaryTerm) term;
- assertThat(unaryTerm.getOperation(), is(".."));
- assertVariableLiteral(
- unaryTerm.getA(),
- "data",
- null,
- variableLiteral -> assertVariableLiteral(
- variableLiteral,
- "lengthInBytes"
- )
- );
- }
-
void assertNumericLiteral(Term term, Number number) {
assertThat(term, not(nullValue()));
assertThat(term, instanceOf(NumericLiteral.class));
diff --git a/build-utils/protocol-base-mspec/src/test/resources/mspec.example b/build-utils/protocol-base-mspec/src/test/resources/mspec.example
index 8d24525..4eb5b33 100644
--- a/build-utils/protocol-base-mspec/src/test/resources/mspec.example
+++ b/build-utils/protocol-base-mspec/src/test/resources/mspec.example
@@ -25,7 +25,7 @@
[reserved uint 16 '0x0000' ]
[implicit uint 32 'packetLength' 'header.lengthInBytes + data.lengthInBytes' ]
[simple AMSHeader 'header' ]
- [simple ADSData 'data' ]
+ [simple ADSData 'data' ['header.commandId', 'header.state.response'] ]
]
[type 'AMSHeader'
@@ -34,11 +34,11 @@
[simple AMSNetId 'sourceAmsNetId' ]
[simple uint 16 'sourceAmsPort' ]
[enum CommandId 'commandId' ]
- [bitmask State 'state' ]
- [implicit uint 32 'dataLength' '../data.lengthInBytes' ]
+ [simple State 'state' ]
+ [simple uint 32 'dataLength' ]
[simple uint 32 'errorCode' ]
// free usable field of 4 bytes
- [array uint 32 'invokeId' ]
+ [simple uint 32 'invokeId' ]
]
[enum uint 16 'CommandId'
@@ -54,16 +54,17 @@
['0x09' ADS_READ_WRITE]
]
-[bitmask uint 16 'State'
- ['0b0000_0000_0000_0001' RESPONSE]
- ['0b0000_0000_0000_0010' NO_RETURN]
- ['0b0000_0000_0000_0100' ADS_COMMAND]
- ['0b0000_0000_0000_1000' SYSTEM_COMMAND]
- ['0b0000_0000_0001_0000' HIGH_PRIORITY_COMMAND]
- ['0b0000_0000_0010_0000' TIMESTAMP_ADDED]
- ['0b0000_0000_0100_0000' UDP_COMMAND]
- ['0b0000_0000_1000_0000' INIT_COMMAND]
- ['0b1000_0000_0000_0000' BROADCAST]
+[type 'State'
+ [simple bit 'broadcast' ]
+ [reserved int 7 '0x0' ]
+ [simple bit 'initCommand' ]
+ [simple bit 'updCommand' ]
+ [simple bit 'timestampAdded' ]
+ [simple bit 'highPriorityCommand' ]
+ [simple bit 'systemCommand' ]
+ [simple bit 'adsCommand' ]
+ [simple bit 'noReturn' ]
+ [simple bit 'response' ]
]
[type 'AMSNetId'
@@ -75,8 +76,38 @@
[simple uint 8 'octet6' ]
]
-[type 'ADSData'
- // TODO: implement me..... arrrrrrrggggggggggggg
- //....
- [simple uint 8 'random' ]
+[discriminatedType 'ADSData' [CommandId 'commandId', bit 'response']
+ [typeSwitch 'commandId', 'response'
+ ['0x00', 'true' AdsInvalidResponse]
+ ['0x00', 'false' AdsInvalidRequest]
+ ['0x01', 'true' AdsReadDeviceInfoResponse
+ // 4 bytes ADS error number.
+ [simple uint 32 'result']
+ // Version 1 byte Major version number
+ [simple uint 8 'majorVersion']
+ // Version 1 byte Minor version number
+ [simple uint 8 'minorVersion']
+ // Build 2 bytes Build number
+ [simple uint 16 'version']
+ // Name 16 bytes Name of ADS device
+ [array int 8 'device' count '16']
+ ]
+ ['0x01', 'false' AdsReadDeviceInfoRequest]
+ ['0x02', 'true' Adstodo4]
+ ['0x02', 'false' Adstodo5]
+ ['0x03', 'true' Adstodo6]
+ ['0x03', 'false' Adstodo7]
+ ['0x04', 'true' Adstodo8]
+ ['0x04', 'false' Adstodo9]
+ ['0x05', 'true' Adstodo06]
+ ['0x05', 'false' Adstodo60]
+ ['0x06', 'true' Adstodo58]
+ ['0x06', 'false' Adstodo45]
+ ['0x07', 'true' Adstodo34]
+ ['0x07', 'false' Adstodo23]
+ ['0x08', 'true' Adstodo12]
+ ['0x08', 'false' Adstodo23]
+ ['0x09', 'true' Adstodo34]
+ ['0x09', 'false' Adstodo45]
+ ]
]
\ No newline at end of file
diff --git a/protocols/amsads/src/main/resources/protocols/amsads/amsads.mspec b/protocols/amsads/src/main/resources/protocols/amsads/amsads.mspec
index aa2aeda..4eb5b33 100644
--- a/protocols/amsads/src/main/resources/protocols/amsads/amsads.mspec
+++ b/protocols/amsads/src/main/resources/protocols/amsads/amsads.mspec
@@ -25,7 +25,7 @@
[reserved uint 16 '0x0000' ]
[implicit uint 32 'packetLength' 'header.lengthInBytes + data.lengthInBytes' ]
[simple AMSHeader 'header' ]
- [simple ADSData 'data' ]
+ [simple ADSData 'data' ['header.commandId', 'header.state.response'] ]
]
[type 'AMSHeader'
@@ -34,11 +34,11 @@
[simple AMSNetId 'sourceAmsNetId' ]
[simple uint 16 'sourceAmsPort' ]
[enum CommandId 'commandId' ]
- [bitmask State 'state' ]
- [implicit uint 32 'dataLength' '../data.lengthInBytes' ]
+ [simple State 'state' ]
+ [simple uint 32 'dataLength' ]
[simple uint 32 'errorCode' ]
// free usable field of 4 bytes
- [array byte 4 'invokeId' ]
+ [simple uint 32 'invokeId' ]
]
[enum uint 16 'CommandId'
@@ -54,16 +54,17 @@
['0x09' ADS_READ_WRITE]
]
-[bitmask byte 2 'State'
- ['0b0000_0000_0000_0001' RESPONSE]
- ['0b0000_0000_0000_0010' NO_RETURN]
- ['0b0000_0000_0000_0100' ADS_COMMAND]
- ['0b0000_0000_0000_1000' SYSTEM_COMMAND]
- ['0b0000_0000_0001_0000' HIGH_PRIORITY_COMMAND]
- ['0b0000_0000_0010_0000' TIMESTAMP_ADDED]
- ['0b0000_0000_0100_0000' UDP_COMMAND]
- ['0b0000_0000_1000_0000' INIT_COMMAND]
- ['0b1000_0000_0000_0000' BROADCAST]
+[type 'State'
+ [simple bit 'broadcast' ]
+ [reserved int 7 '0x0' ]
+ [simple bit 'initCommand' ]
+ [simple bit 'updCommand' ]
+ [simple bit 'timestampAdded' ]
+ [simple bit 'highPriorityCommand' ]
+ [simple bit 'systemCommand' ]
+ [simple bit 'adsCommand' ]
+ [simple bit 'noReturn' ]
+ [simple bit 'response' ]
]
[type 'AMSNetId'
@@ -75,8 +76,38 @@
[simple uint 8 'octet6' ]
]
-[type 'ADSData'
- // TODO: implement me..... arrrrrrrggggggggggggg
- //....
- [simple uint 8 'random' ]
+[discriminatedType 'ADSData' [CommandId 'commandId', bit 'response']
+ [typeSwitch 'commandId', 'response'
+ ['0x00', 'true' AdsInvalidResponse]
+ ['0x00', 'false' AdsInvalidRequest]
+ ['0x01', 'true' AdsReadDeviceInfoResponse
+ // 4 bytes ADS error number.
+ [simple uint 32 'result']
+ // Version 1 byte Major version number
+ [simple uint 8 'majorVersion']
+ // Version 1 byte Minor version number
+ [simple uint 8 'minorVersion']
+ // Build 2 bytes Build number
+ [simple uint 16 'version']
+ // Name 16 bytes Name of ADS device
+ [array int 8 'device' count '16']
+ ]
+ ['0x01', 'false' AdsReadDeviceInfoRequest]
+ ['0x02', 'true' Adstodo4]
+ ['0x02', 'false' Adstodo5]
+ ['0x03', 'true' Adstodo6]
+ ['0x03', 'false' Adstodo7]
+ ['0x04', 'true' Adstodo8]
+ ['0x04', 'false' Adstodo9]
+ ['0x05', 'true' Adstodo06]
+ ['0x05', 'false' Adstodo60]
+ ['0x06', 'true' Adstodo58]
+ ['0x06', 'false' Adstodo45]
+ ['0x07', 'true' Adstodo34]
+ ['0x07', 'false' Adstodo23]
+ ['0x08', 'true' Adstodo12]
+ ['0x08', 'false' Adstodo23]
+ ['0x09', 'true' Adstodo34]
+ ['0x09', 'false' Adstodo45]
+ ]
]
\ No newline at end of file