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 2020/06/20 18:27:38 UTC
[plc4x] branch feature/c-code-generation-tagged-unions updated: -
Implemented more field types for the serialization
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/c-code-generation-tagged-unions
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/c-code-generation-tagged-unions by this push:
new 3f9ed1f - Implemented more field types for the serialization
3f9ed1f is described below
commit 3f9ed1f7b30e21800a6a384b3782a17f69378fd2
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sat Jun 20 20:27:30 2020 +0200
- Implemented more field types for the serialization
---
.../resources/templates/c/pojo-template-c.ftlh | 51 +++++++++-------------
.../modbus/src/modbus_constants.c | 2 +-
.../generated-sources/modbus/src/modbus_pdu.c | 2 +-
.../src/modbus_pdu_read_file_record_request_item.c | 27 +++++++++++-
.../modbus_pdu_read_file_record_response_item.c | 9 +++-
.../modbus_pdu_write_file_record_request_item.c | 21 ++++++++-
.../modbus_pdu_write_file_record_response_item.c | 21 ++++++++-
.../modbus/src/modbus_serial_adu.c | 33 +++++++++++++-
.../generated-sources/modbus/src/modbus_tcp_adu.c | 24 +++++++++-
.../plc4c/generated-sources/s7/src/cotp_packet.c | 7 ++-
.../generated-sources/s7/src/cotp_parameter.c | 2 +-
.../plc4c/generated-sources/s7/src/s7_address.c | 2 +-
.../plc4c/generated-sources/s7/src/s7_message.c | 20 ++++++---
.../plc4c/generated-sources/s7/src/s7_parameter.c | 2 +-
.../s7/src/s7_parameter_user_data_item.c | 2 +-
.../plc4c/generated-sources/s7/src/s7_payload.c | 2 +-
.../s7/src/s7_payload_user_data_item.c | 18 +++++++-
.../s7/src/s7_var_payload_data_item.c | 18 +++++++-
.../s7/src/s7_var_payload_status_item.c | 3 +-
.../s7/src/s7_var_request_parameter_item.c | 2 +-
.../generated-sources/s7/src/szl_data_tree_item.c | 27 +++++++++++-
sandbox/plc4c/generated-sources/s7/src/szl_id.c | 9 +++-
.../plc4c/generated-sources/s7/src/tpkt_packet.c | 15 ++++++-
23 files changed, 246 insertions(+), 73 deletions(-)
diff --git a/build-utils/language-c/src/main/resources/templates/c/pojo-template-c.ftlh b/build-utils/language-c/src/main/resources/templates/c/pojo-template-c.ftlh
index 28d6226..6ff6ba9 100644
--- a/build-utils/language-c/src/main/resources/templates/c/pojo-template-c.ftlh
+++ b/build-utils/language-c/src/main/resources/templates/c/pojo-template-c.ftlh
@@ -93,14 +93,11 @@ plc4c_return_code plc4c_${helper.getCTypeName(type.name)}_parse(plc4c_spi_read_b
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_${helper.getCTypeName(type.name)}));
if(*_message == NULL) {
return NO_MEMORY;
}
-<#if type.getPropertyFields()?has_content>
-
-</#if>
<#macro fieldName baseType field><#if baseType != type>${helper.camelCaseToSnakeCase(baseType.name)}_</#if>${helper.camelCaseToSnakeCase(field.name)}</#macro>
<#macro fieldParser baseType field indentContent>
<#switch field.typeName>
@@ -433,18 +430,19 @@ plc4c_return_code plc4c_${helper.getCTypeName(type.name)}_serialize(plc4c_spi_wr
<#if indentContent> </#if> // Optional Field (${optionalField.name})
<#if indentContent> </#if> if(_message-><@fieldName baseType=baseType field=optionalField/> != NULL) {
-<#if indentContent> </#if> ${helper.getLanguageTypeNameForTypeReference(optionalField.type)}* _value = (${helper.getLanguageTypeNameForTypeReference(optionalField.type)}*) _message-><@fieldName baseType=baseType field=optionalField/>;
<#if helper.isSimpleTypeReference(optionalField.type)>
-<#if indentContent> </#if> ${helper.getWriteBufferWriteMethodCall(optionalField.type, "*_value")};
+<#if indentContent> </#if> ${helper.getLanguageTypeNameForTypeReference(optionalField.type)} _value = _message-><@fieldName baseType=baseType field=optionalField/>;
+<#if indentContent> </#if> ${helper.getWriteBufferWriteMethodCall(optionalField.type, "_value")};
<#else>
-<#if indentContent> </#if> plc4c_return_code _res = plc4c_${helper.getCTypeName(optionalField.type.name)}_serialize(buf, (void*) &_value);
+<#if indentContent> </#if> ${helper.getLanguageTypeNameForTypeReference(optionalField.type)}* _value = _message-><@fieldName baseType=baseType field=optionalField/>;
+<#if indentContent> </#if> plc4c_return_code _res = plc4c_${helper.getCTypeName(optionalField.type.name)}_serialize(buf, _value);
<#if indentContent> </#if> if(_res != OK) {
<#if indentContent> </#if> return _res;
<#if indentContent> </#if> }
</#if>
<#if indentContent> </#if> }
<#break>
- <#--case "padding">
+ <#case "padding">
<#assign paddingField = field>
<#assign simpleTypeReference = paddingField.type>
@@ -452,8 +450,8 @@ plc4c_return_code plc4c_${helper.getCTypeName(type.name)}_serialize(plc4c_spi_wr
<#if indentContent> </#if> {
<#if indentContent> </#if> bool _needsPadding = (bool) ((plc4c_spi_read_has_more(buf, ${helper.getNumBits(paddingField.type)})) && (${helper.toParseExpression(baseType, paddingField, paddingField.paddingCondition, type.parserArguments)}));
<#if indentContent> </#if> if(_needsPadding) {
-<#if indentContent> </#if> // Just read the padding data and ignore it
-<#if indentContent> </#if> ${helper.getReadBufferReadMethodCall(paddingField.type)};
+<#if indentContent> </#if> // Just output the default padding data
+<#if indentContent> </#if> ${helper.getWriteBufferWriteMethodCall(paddingField.type, helper.toParseExpression(baseType, paddingField, paddingField.paddingValue, type.parserArguments))};
<#if indentContent> </#if> }
<#if indentContent> </#if> }
<#break>
@@ -461,30 +459,27 @@ plc4c_return_code plc4c_${helper.getCTypeName(type.name)}_serialize(plc4c_spi_wr
<#assign reservedField = field>
<#assign simpleTypeReference = reservedField.type>
-<#if indentContent> </#if> // Reserved Field (Compartmentalized so the "reserved" variable can't leak)
-<#if indentContent> </#if> {
-<#if indentContent> </#if> ${helper.getLanguageTypeNameForField(field)} _reserved = ${helper.getReadBufferReadMethodCall(reservedField.type)};
-<#if indentContent> </#if> if(_reserved != ${reservedField.referenceValue}) {
-<#if indentContent> </#if> printf("Expected constant value '%d' but got '%d' for reserved field.", ${reservedField.referenceValue}, _reserved);
-<#if indentContent> </#if> }
-<#if indentContent> </#if> }
+<#if indentContent> </#if> // Reserved Field
+<#if indentContent> </#if> ${helper.getWriteBufferWriteMethodCall(reservedField.type, reservedField.referenceValue)};
<#break>
<#case "simple">
<#assign simpleField = field>
<#if indentContent> </#if> // Simple Field (${simpleField.name})
+<#if indentContent> </#if> {
<#if helper.isSimpleTypeReference(simpleField.type)>
-<#if indentContent> </#if> ${helper.getLanguageTypeNameForField(field)} ${simpleField.name} = ${helper.getReadBufferReadMethodCall(simpleField.type)};
+<#if indentContent> </#if> ${helper.getLanguageTypeNameForTypeReference(simpleField.type)} _value = _message-><@fieldName baseType=baseType field=simpleField/>;
+<#if indentContent> </#if> ${helper.getWriteBufferWriteMethodCall(simpleField.type, "_value")};
<#else>
-<#if indentContent> </#if> ${helper.getLanguageTypeNameForField(field)}* ${simpleField.name};
-<#if indentContent> </#if> plc4c_return_code _res = plc4c_${helper.getCTypeName(simpleField.type.name)}_parse(buf<#if simpleField.params?has_content>, <#list simpleField.params as parserTerm>${helper.toParseExpression(baseType, simpleField, parserTerm, type.parserArguments)}<#sep>, </#sep></#list></#if>, (void*) &${simpleField.name});
-<#if indentContent> </#if> if(_res != OK) {
-<#if indentContent> </#if> return _res;
-<#if indentContent> </#if> }
+<#if indentContent> </#if> ${helper.getLanguageTypeNameForTypeReference(simpleField.type)}* _value = _message-><@fieldName baseType=baseType field=simpleField/>;
+<#if indentContent> </#if> plc4c_return_code _res = plc4c_${helper.getCTypeName(simpleField.type.name)}_serialize(buf, _value);
+<#if indentContent> </#if> if(_res != OK) {
+<#if indentContent> </#if> return _res;
+<#if indentContent> </#if> }
</#if>
-<#if indentContent> </#if> (*_message)-><@fieldName baseType=baseType field=simpleField/> = ${simpleField.name};
+<#if indentContent> </#if> }
<#break>
- <#case "switch">
+ <#--case "switch">
<#assign switchField = field>
<#if indentContent> </#if> // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type)
@@ -497,12 +492,6 @@ plc4c_return_code plc4c_${helper.getCTypeName(type.name)}_serialize(plc4c_spi_wr
</#list>
<#if indentContent> </#if> }<#sep> else </#sep>
</#list>
- <#break>
- <#case "virtual">
- <#assign virtualField = field>
-
-<#if indentContent> </#if> // Virtual field (Just declare a local variable so we can access it in the parser)
-<#if indentContent> </#if> ${helper.getLanguageTypeNameForField(field)} ${virtualField.name} = (${helper.getLanguageTypeNameForField(field)}) (${helper.toParseExpression(baseType, virtualField, virtualField.valueExpression, type.parserArguments)});
<#break-->
</#switch>
</#macro>
diff --git a/sandbox/plc4c/generated-sources/modbus/src/modbus_constants.c b/sandbox/plc4c/generated-sources/modbus/src/modbus_constants.c
index 3112267..ac7c426 100644
--- a/sandbox/plc4c/generated-sources/modbus/src/modbus_constants.c
+++ b/sandbox/plc4c/generated-sources/modbus/src/modbus_constants.c
@@ -28,7 +28,7 @@ plc4c_return_code plc4c_modbus_read_write_modbus_constants_parse(plc4c_spi_read_
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_modbus_read_write_modbus_constants));
if(*_message == NULL) {
return NO_MEMORY;
diff --git a/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu.c b/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu.c
index 97b0b06..afa5165 100644
--- a/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu.c
+++ b/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu.c
@@ -111,7 +111,7 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_parse(plc4c_spi_read_buffer
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_modbus_read_write_modbus_pdu));
if(*_message == NULL) {
return NO_MEMORY;
diff --git a/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_request_item.c b/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_request_item.c
index 913c0cb..431ba3d 100644
--- a/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_request_item.c
+++ b/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_request_item.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_read_file_record_request_it
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_modbus_read_write_modbus_pdu_read_file_record_request_item));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Simple Field (referenceType)
uint8_t referenceType = plc4c_spi_read_unsigned_short(buf, 8);
(*_message)->reference_type = referenceType;
@@ -56,5 +55,29 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_read_file_record_request_it
plc4c_return_code plc4c_modbus_read_write_modbus_pdu_read_file_record_request_item_serialize(plc4c_spi_write_buffer* buf, plc4c_modbus_read_write_modbus_pdu_read_file_record_request_item* _message) {
+ // Simple Field (referenceType)
+ {
+ uint8_t _value = _message->reference_type;
+ plc4c_spi_write_unsigned_short(buf, 8, _value);
+ }
+
+ // Simple Field (fileNumber)
+ {
+ uint16_t _value = _message->file_number;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
+ // Simple Field (recordNumber)
+ {
+ uint16_t _value = _message->record_number;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
+ // Simple Field (recordLength)
+ {
+ uint16_t _value = _message->record_length;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
return OK;
}
diff --git a/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_response_item.c b/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_response_item.c
index d821804..66875ca 100644
--- a/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_response_item.c
+++ b/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_response_item.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_read_file_record_response_i
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_modbus_read_write_modbus_pdu_read_file_record_response_item));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Implicit Field (dataLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content)
uint8_t dataLength = plc4c_spi_read_unsigned_short(buf, 8);
@@ -63,6 +62,12 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_read_file_record_response_i
plc4c_return_code plc4c_modbus_read_write_modbus_pdu_read_file_record_response_item_serialize(plc4c_spi_write_buffer* buf, plc4c_modbus_read_write_modbus_pdu_read_file_record_response_item* _message) {
+ // Simple Field (referenceType)
+ {
+ uint8_t _value = _message->reference_type;
+ plc4c_spi_write_unsigned_short(buf, 8, _value);
+ }
+
// Array field (data)
{
uint8_t itemCount = plc4c_utils_list_size(_message->data);
diff --git a/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_write_file_record_request_item.c b/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_write_file_record_request_item.c
index 6f49b0e..05f1fc4 100644
--- a/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_write_file_record_request_item.c
+++ b/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_write_file_record_request_item.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_write_file_record_request_i
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_modbus_read_write_modbus_pdu_write_file_record_request_item));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Simple Field (referenceType)
uint8_t referenceType = plc4c_spi_read_unsigned_short(buf, 8);
(*_message)->reference_type = referenceType;
@@ -71,6 +70,24 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_write_file_record_request_i
plc4c_return_code plc4c_modbus_read_write_modbus_pdu_write_file_record_request_item_serialize(plc4c_spi_write_buffer* buf, plc4c_modbus_read_write_modbus_pdu_write_file_record_request_item* _message) {
+ // Simple Field (referenceType)
+ {
+ uint8_t _value = _message->reference_type;
+ plc4c_spi_write_unsigned_short(buf, 8, _value);
+ }
+
+ // Simple Field (fileNumber)
+ {
+ uint16_t _value = _message->file_number;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
+ // Simple Field (recordNumber)
+ {
+ uint16_t _value = _message->record_number;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
// Array field (recordData)
{
uint8_t itemCount = plc4c_utils_list_size(_message->record_data);
diff --git a/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_write_file_record_response_item.c b/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_write_file_record_response_item.c
index a41c330..53f5586 100644
--- a/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_write_file_record_response_item.c
+++ b/sandbox/plc4c/generated-sources/modbus/src/modbus_pdu_write_file_record_response_item.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_write_file_record_response_
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_modbus_read_write_modbus_pdu_write_file_record_response_item));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Simple Field (referenceType)
uint8_t referenceType = plc4c_spi_read_unsigned_short(buf, 8);
(*_message)->reference_type = referenceType;
@@ -71,6 +70,24 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_write_file_record_response_
plc4c_return_code plc4c_modbus_read_write_modbus_pdu_write_file_record_response_item_serialize(plc4c_spi_write_buffer* buf, plc4c_modbus_read_write_modbus_pdu_write_file_record_response_item* _message) {
+ // Simple Field (referenceType)
+ {
+ uint8_t _value = _message->reference_type;
+ plc4c_spi_write_unsigned_short(buf, 8, _value);
+ }
+
+ // Simple Field (fileNumber)
+ {
+ uint16_t _value = _message->file_number;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
+ // Simple Field (recordNumber)
+ {
+ uint16_t _value = _message->record_number;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
// Array field (recordData)
{
uint8_t itemCount = plc4c_utils_list_size(_message->record_data);
diff --git a/sandbox/plc4c/generated-sources/modbus/src/modbus_serial_adu.c b/sandbox/plc4c/generated-sources/modbus/src/modbus_serial_adu.c
index 08dcaaa..8ceab24 100644
--- a/sandbox/plc4c/generated-sources/modbus/src/modbus_serial_adu.c
+++ b/sandbox/plc4c/generated-sources/modbus/src/modbus_serial_adu.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_modbus_read_write_modbus_serial_adu_parse(plc4c_spi_read
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_modbus_read_write_modbus_serial_adu));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Simple Field (transactionId)
uint16_t transactionId = plc4c_spi_read_unsigned_int(buf, 16);
(*_message)->transaction_id = transactionId;
@@ -68,5 +67,35 @@ plc4c_return_code plc4c_modbus_read_write_modbus_serial_adu_parse(plc4c_spi_read
plc4c_return_code plc4c_modbus_read_write_modbus_serial_adu_serialize(plc4c_spi_write_buffer* buf, plc4c_modbus_read_write_modbus_serial_adu* _message) {
+ // Simple Field (transactionId)
+ {
+ uint16_t _value = _message->transaction_id;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
+ // Reserved Field
+ plc4c_spi_write_unsigned_int(buf, 16, 0x0000);
+
+ // Simple Field (length)
+ {
+ uint16_t _value = _message->length;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
+ // Simple Field (address)
+ {
+ uint8_t _value = _message->address;
+ plc4c_spi_write_unsigned_short(buf, 8, _value);
+ }
+
+ // Simple Field (pdu)
+ {
+ plc4c_modbus_read_write_modbus_pdu* _value = _message->pdu;
+ plc4c_return_code _res = plc4c_modbus_read_write_modbus_pdu_serialize(buf, _value);
+ if(_res != OK) {
+ return _res;
+ }
+ }
+
return OK;
}
diff --git a/sandbox/plc4c/generated-sources/modbus/src/modbus_tcp_adu.c b/sandbox/plc4c/generated-sources/modbus/src/modbus_tcp_adu.c
index a22948b..ef298ce 100644
--- a/sandbox/plc4c/generated-sources/modbus/src/modbus_tcp_adu.c
+++ b/sandbox/plc4c/generated-sources/modbus/src/modbus_tcp_adu.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_modbus_read_write_modbus_tcp_adu_parse(plc4c_spi_read_bu
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_modbus_read_write_modbus_tcp_adu));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Simple Field (transactionIdentifier)
uint16_t transactionIdentifier = plc4c_spi_read_unsigned_int(buf, 16);
(*_message)->transaction_identifier = transactionIdentifier;
@@ -66,8 +65,29 @@ plc4c_return_code plc4c_modbus_read_write_modbus_tcp_adu_parse(plc4c_spi_read_bu
plc4c_return_code plc4c_modbus_read_write_modbus_tcp_adu_serialize(plc4c_spi_write_buffer* buf, plc4c_modbus_read_write_modbus_tcp_adu* _message) {
+ // Simple Field (transactionIdentifier)
+ {
+ uint16_t _value = _message->transaction_identifier;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
// Const Field (protocolIdentifier)
plc4c_spi_write_unsigned_int(buf, 16, MODBUS_READ_WRITE_MODBUS_TCP_ADU_PROTOCOL_IDENTIFIER);
+ // Simple Field (unitIdentifier)
+ {
+ uint8_t _value = _message->unit_identifier;
+ plc4c_spi_write_unsigned_short(buf, 8, _value);
+ }
+
+ // Simple Field (pdu)
+ {
+ plc4c_modbus_read_write_modbus_pdu* _value = _message->pdu;
+ plc4c_return_code _res = plc4c_modbus_read_write_modbus_pdu_serialize(buf, _value);
+ if(_res != OK) {
+ return _res;
+ }
+ }
+
return OK;
}
diff --git a/sandbox/plc4c/generated-sources/s7/src/cotp_packet.c b/sandbox/plc4c/generated-sources/s7/src/cotp_packet.c
index d71ec5e..21f6a2e 100644
--- a/sandbox/plc4c/generated-sources/s7/src/cotp_packet.c
+++ b/sandbox/plc4c/generated-sources/s7/src/cotp_packet.c
@@ -51,13 +51,12 @@ plc4c_return_code plc4c_s7_read_write_cotp_packet_parse(plc4c_spi_read_buffer* b
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_cotp_packet));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Implicit Field (headerLength) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content)
uint8_t headerLength = plc4c_spi_read_unsigned_short(buf, 8);
@@ -221,8 +220,8 @@ plc4c_return_code plc4c_s7_read_write_cotp_packet_serialize(plc4c_spi_write_buff
// Optional Field (payload)
if(_message->payload != NULL) {
- plc4c_s7_read_write_s7_message* _value = (plc4c_s7_read_write_s7_message*) _message->payload;
- plc4c_return_code _res = plc4c_s7_read_write_s7_message_serialize(buf, (void*) &_value);
+ plc4c_s7_read_write_s7_message* _value = _message->payload;
+ plc4c_return_code _res = plc4c_s7_read_write_s7_message_serialize(buf, _value);
if(_res != OK) {
return _res;
}
diff --git a/sandbox/plc4c/generated-sources/s7/src/cotp_parameter.c b/sandbox/plc4c/generated-sources/s7/src/cotp_parameter.c
index d565a67..7bd3d68 100644
--- a/sandbox/plc4c/generated-sources/s7/src/cotp_parameter.c
+++ b/sandbox/plc4c/generated-sources/s7/src/cotp_parameter.c
@@ -49,7 +49,7 @@ plc4c_return_code plc4c_s7_read_write_cotp_parameter_parse(plc4c_spi_read_buffer
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_cotp_parameter));
if(*_message == NULL) {
return NO_MEMORY;
diff --git a/sandbox/plc4c/generated-sources/s7/src/s7_address.c b/sandbox/plc4c/generated-sources/s7/src/s7_address.c
index b60d64b..96ee216 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_address.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_address.c
@@ -41,7 +41,7 @@ plc4c_return_code plc4c_s7_read_write_s7_address_parse(plc4c_spi_read_buffer* bu
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_s7_address));
if(*_message == NULL) {
return NO_MEMORY;
diff --git a/sandbox/plc4c/generated-sources/s7/src/s7_message.c b/sandbox/plc4c/generated-sources/s7/src/s7_message.c
index d837ef0..655464d 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_message.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_message.c
@@ -47,13 +47,12 @@ plc4c_return_code plc4c_s7_read_write_s7_message_parse(plc4c_spi_read_buffer* bu
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_s7_message));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Const Field (protocolId)
uint8_t protocolId = plc4c_spi_read_unsigned_short(buf, 8);
if(protocolId != S7_READ_WRITE_S7_MESSAGE_PROTOCOL_ID) {
@@ -153,10 +152,19 @@ plc4c_return_code plc4c_s7_read_write_s7_message_serialize(plc4c_spi_write_buffe
// Discriminator Field (messageType)
plc4c_spi_write_unsigned_short(buf, 8, plc4c_s7_read_write_s7_message_get_discriminator(_message->_type).messageType);
+ // Reserved Field
+ plc4c_spi_write_unsigned_int(buf, 16, 0x0000);
+
+ // Simple Field (tpduReference)
+ {
+ uint16_t _value = _message->tpdu_reference;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
// Optional Field (parameter)
if(_message->parameter != NULL) {
- plc4c_s7_read_write_s7_parameter* _value = (plc4c_s7_read_write_s7_parameter*) _message->parameter;
- plc4c_return_code _res = plc4c_s7_read_write_s7_parameter_serialize(buf, (void*) &_value);
+ plc4c_s7_read_write_s7_parameter* _value = _message->parameter;
+ plc4c_return_code _res = plc4c_s7_read_write_s7_parameter_serialize(buf, _value);
if(_res != OK) {
return _res;
}
@@ -164,8 +172,8 @@ plc4c_return_code plc4c_s7_read_write_s7_message_serialize(plc4c_spi_write_buffe
// Optional Field (payload)
if(_message->payload != NULL) {
- plc4c_s7_read_write_s7_payload* _value = (plc4c_s7_read_write_s7_payload*) _message->payload;
- plc4c_return_code _res = plc4c_s7_read_write_s7_payload_serialize(buf, (void*) &_value);
+ plc4c_s7_read_write_s7_payload* _value = _message->payload;
+ plc4c_return_code _res = plc4c_s7_read_write_s7_payload_serialize(buf, _value);
if(_res != OK) {
return _res;
}
diff --git a/sandbox/plc4c/generated-sources/s7/src/s7_parameter.c b/sandbox/plc4c/generated-sources/s7/src/s7_parameter.c
index eb6ef05..bde2a93 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_parameter.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_parameter.c
@@ -51,7 +51,7 @@ plc4c_return_code plc4c_s7_read_write_s7_parameter_parse(plc4c_spi_read_buffer*
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_s7_parameter));
if(*_message == NULL) {
return NO_MEMORY;
diff --git a/sandbox/plc4c/generated-sources/s7/src/s7_parameter_user_data_item.c b/sandbox/plc4c/generated-sources/s7/src/s7_parameter_user_data_item.c
index 649c8ba..0aa12d9 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_parameter_user_data_item.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_parameter_user_data_item.c
@@ -41,7 +41,7 @@ plc4c_return_code plc4c_s7_read_write_s7_parameter_user_data_item_parse(plc4c_sp
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_s7_parameter_user_data_item));
if(*_message == NULL) {
return NO_MEMORY;
diff --git a/sandbox/plc4c/generated-sources/s7/src/s7_payload.c b/sandbox/plc4c/generated-sources/s7/src/s7_payload.c
index bb27e35..e7d87ff 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_payload.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_payload.c
@@ -47,7 +47,7 @@ plc4c_return_code plc4c_s7_read_write_s7_payload_parse(plc4c_spi_read_buffer* bu
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_s7_payload));
if(*_message == NULL) {
return NO_MEMORY;
diff --git a/sandbox/plc4c/generated-sources/s7/src/s7_payload_user_data_item.c b/sandbox/plc4c/generated-sources/s7/src/s7_payload_user_data_item.c
index b7d6a0e..f55aab4 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_payload_user_data_item.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_payload_user_data_item.c
@@ -43,13 +43,12 @@ plc4c_return_code plc4c_s7_read_write_s7_payload_user_data_item_parse(plc4c_spi_
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_s7_payload_user_data_item));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Enum field (returnCode)
plc4c_s7_read_write_data_transport_error_code returnCode = plc4c_spi_read_byte(buf, 8);
(*_message)->return_code = returnCode;
@@ -125,5 +124,20 @@ plc4c_return_code plc4c_s7_read_write_s7_payload_user_data_item_serialize(plc4c_
// Enum field (transportSize)
plc4c_spi_write_byte(buf, 8, _message->transport_size);
+ // Simple Field (szlId)
+ {
+ plc4c_s7_read_write_szl_id* _value = _message->szl_id;
+ plc4c_return_code _res = plc4c_s7_read_write_szl_id_serialize(buf, _value);
+ if(_res != OK) {
+ return _res;
+ }
+ }
+
+ // Simple Field (szlIndex)
+ {
+ uint16_t _value = _message->szl_index;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
return OK;
}
diff --git a/sandbox/plc4c/generated-sources/s7/src/s7_var_payload_data_item.c b/sandbox/plc4c/generated-sources/s7/src/s7_var_payload_data_item.c
index 07ec009..59e6868 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_var_payload_data_item.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_var_payload_data_item.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_s7_read_write_s7_var_payload_data_item_parse(plc4c_spi_r
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_s7_var_payload_data_item));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Enum field (returnCode)
plc4c_s7_read_write_data_transport_error_code returnCode = plc4c_spi_read_byte(buf, 8);
(*_message)->return_code = returnCode;
@@ -84,6 +83,12 @@ plc4c_return_code plc4c_s7_read_write_s7_var_payload_data_item_serialize(plc4c_s
// Enum field (transportSize)
plc4c_spi_write_byte(buf, 8, _message->transport_size);
+ // Simple Field (dataLength)
+ {
+ uint16_t _value = _message->data_length;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
// Array field (data)
{
uint8_t itemCount = plc4c_utils_list_size(_message->data);
@@ -93,5 +98,14 @@ plc4c_return_code plc4c_s7_read_write_s7_var_payload_data_item_serialize(plc4c_s
}
}
+ // Padding Field (padding)
+ {
+ bool _needsPadding = (bool) ((plc4c_spi_read_has_more(buf, 8)) && ((!(lastItem)) && (((((plc4c_spi_evaluation_helper_count(data)) % (2))) == (1)))));
+ if(_needsPadding) {
+ // Just output the default padding data
+ plc4c_spi_write_unsigned_short(buf, 8, 0);
+ }
+ }
+
return OK;
}
diff --git a/sandbox/plc4c/generated-sources/s7/src/s7_var_payload_status_item.c b/sandbox/plc4c/generated-sources/s7/src/s7_var_payload_status_item.c
index 099742a..34b888a 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_var_payload_status_item.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_var_payload_status_item.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_s7_read_write_s7_var_payload_status_item_parse(plc4c_spi
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_s7_var_payload_status_item));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Enum field (returnCode)
plc4c_s7_read_write_data_transport_error_code returnCode = plc4c_spi_read_byte(buf, 8);
(*_message)->return_code = returnCode;
diff --git a/sandbox/plc4c/generated-sources/s7/src/s7_var_request_parameter_item.c b/sandbox/plc4c/generated-sources/s7/src/s7_var_request_parameter_item.c
index 3d8800f..cda6c09 100644
--- a/sandbox/plc4c/generated-sources/s7/src/s7_var_request_parameter_item.c
+++ b/sandbox/plc4c/generated-sources/s7/src/s7_var_request_parameter_item.c
@@ -41,7 +41,7 @@ plc4c_return_code plc4c_s7_read_write_s7_var_request_parameter_item_parse(plc4c_
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_s7_var_request_parameter_item));
if(*_message == NULL) {
return NO_MEMORY;
diff --git a/sandbox/plc4c/generated-sources/s7/src/szl_data_tree_item.c b/sandbox/plc4c/generated-sources/s7/src/szl_data_tree_item.c
index 45471c4..d9d6bd2 100644
--- a/sandbox/plc4c/generated-sources/s7/src/szl_data_tree_item.c
+++ b/sandbox/plc4c/generated-sources/s7/src/szl_data_tree_item.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_s7_read_write_szl_data_tree_item_parse(plc4c_spi_read_bu
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_szl_data_tree_item));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Simple Field (itemIndex)
uint16_t itemIndex = plc4c_spi_read_unsigned_int(buf, 16);
(*_message)->item_index = itemIndex;
@@ -73,6 +72,12 @@ plc4c_return_code plc4c_s7_read_write_szl_data_tree_item_parse(plc4c_spi_read_bu
plc4c_return_code plc4c_s7_read_write_szl_data_tree_item_serialize(plc4c_spi_write_buffer* buf, plc4c_s7_read_write_szl_data_tree_item* _message) {
+ // Simple Field (itemIndex)
+ {
+ uint16_t _value = _message->item_index;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
// Array field (mlfb)
{
uint8_t itemCount = plc4c_utils_list_size(_message->mlfb);
@@ -82,5 +87,23 @@ plc4c_return_code plc4c_s7_read_write_szl_data_tree_item_serialize(plc4c_spi_wri
}
}
+ // Simple Field (moduleTypeId)
+ {
+ uint16_t _value = _message->module_type_id;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
+ // Simple Field (ausbg)
+ {
+ uint16_t _value = _message->ausbg;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
+ // Simple Field (ausbe)
+ {
+ uint16_t _value = _message->ausbe;
+ plc4c_spi_write_unsigned_int(buf, 16, _value);
+ }
+
return OK;
}
diff --git a/sandbox/plc4c/generated-sources/s7/src/szl_id.c b/sandbox/plc4c/generated-sources/s7/src/szl_id.c
index bb1c06d..c642548 100644
--- a/sandbox/plc4c/generated-sources/s7/src/szl_id.c
+++ b/sandbox/plc4c/generated-sources/s7/src/szl_id.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_s7_read_write_szl_id_parse(plc4c_spi_read_buffer* buf, p
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_szl_id));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Enum field (typeClass)
plc4c_s7_read_write_szl_module_type_class typeClass = plc4c_spi_read_byte(buf, 4);
(*_message)->type_class = typeClass;
@@ -55,6 +54,12 @@ plc4c_return_code plc4c_s7_read_write_szl_id_serialize(plc4c_spi_write_buffer* b
// Enum field (typeClass)
plc4c_spi_write_byte(buf, 4, _message->type_class);
+ // Simple Field (sublistExtract)
+ {
+ unsigned int _value = _message->sublist_extract;
+ plc4c_spi_write_unsigned_byte(buf, 4, _value);
+ }
+
// Enum field (sublistList)
plc4c_spi_write_byte(buf, 8, _message->sublist_list);
diff --git a/sandbox/plc4c/generated-sources/s7/src/tpkt_packet.c b/sandbox/plc4c/generated-sources/s7/src/tpkt_packet.c
index 6152816..d9df4bd 100644
--- a/sandbox/plc4c/generated-sources/s7/src/tpkt_packet.c
+++ b/sandbox/plc4c/generated-sources/s7/src/tpkt_packet.c
@@ -28,13 +28,12 @@ plc4c_return_code plc4c_s7_read_write_tpkt_packet_parse(plc4c_spi_read_buffer* b
uint16_t startPos = plc4c_spi_read_get_pos(buf);
uint16_t curPos;
- // Pointer to the parsed data structure.
+ // Allocate enough memory to contain this data structure.
(*_message) = malloc(sizeof(plc4c_s7_read_write_tpkt_packet));
if(*_message == NULL) {
return NO_MEMORY;
}
-
// Const Field (protocolId)
uint8_t protocolId = plc4c_spi_read_unsigned_short(buf, 8);
if(protocolId != S7_READ_WRITE_TPKT_PACKET_PROTOCOL_ID) {
@@ -69,5 +68,17 @@ plc4c_return_code plc4c_s7_read_write_tpkt_packet_serialize(plc4c_spi_write_buff
// Const Field (protocolId)
plc4c_spi_write_unsigned_short(buf, 8, S7_READ_WRITE_TPKT_PACKET_PROTOCOL_ID);
+ // Reserved Field
+ plc4c_spi_write_unsigned_short(buf, 8, 0x00);
+
+ // Simple Field (payload)
+ {
+ plc4c_s7_read_write_cotp_packet* _value = _message->payload;
+ plc4c_return_code _res = plc4c_s7_read_write_cotp_packet_serialize(buf, _value);
+ if(_res != OK) {
+ return _res;
+ }
+ }
+
return OK;
}