Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of various handling of S7 types #1259

Merged
merged 22 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b9b9307
Support for reading and writing to STRING type memory areas. Example …
ceos01 Nov 29, 2023
c93b723
fix: Updated the var-length string handling code and made it work wit…
chrisdutz Nov 30, 2023
3c5266c
fix: Major refactoring of mostly the write code.
chrisdutz Nov 30, 2023
cefb32a
fix: Fixed some tests.
chrisdutz Nov 30, 2023
bb19223
fix: Fixed some tests.
chrisdutz Nov 30, 2023
845fd81
fix: Fixed some issues with writing values in S7
chrisdutz Nov 30, 2023
4bfda20
chore: Updated the apache parent to the latest released version
chrisdutz Nov 30, 2023
a5e854d
fix: Fixed some issues with writing values in S7
chrisdutz Nov 30, 2023
a5d850d
chore: Updated KNX manufacturer ids
chrisdutz Nov 30, 2023
bf619ae
chore: Turned on the write-tests per default in the ManualTest
chrisdutz Nov 30, 2023
ccf1ace
feat: Re-added the manual test for my local S7-Modbus and added the M…
chrisdutz Nov 30, 2023
2da3dd4
Corrects reading of the TIME format.
ceos01 Dec 1, 2023
c031ec6
fix: Made it possible to use signed integers for creating PlcTIME val…
chrisdutz Dec 3, 2023
90500e9
Arreglando el manejo de los tipos TIME. modificacion del PlcTIME y s7…
ceos01 Dec 3, 2023
00b58d6
Arreglando el manejo de los tipos TIME. modificacion del PlcTIME y s7…
ceos01 Dec 3, 2023
8239d10
Updating repo.
ceos01 Dec 5, 2023
2faf2a3
Correct reading and writing of TIME type in S7-400.
ceos01 Dec 5, 2023
20c3a25
Fix read/write S5TIME type.
ceos01 Dec 5, 2023
6705810
Fix date deviation for the DATE format (1 day). Need to test with S7-…
ceos01 Dec 5, 2023
a37195d
chore: Updated vendor ids
chrisdutz Dec 7, 2023
4aa7d3d
fix: Made all dates and times use UTC, as we were having issues with …
chrisdutz Dec 7, 2023
a8a98f4
Merge remote-tracking branch 'origin/develop' into feature/s7strings
chrisdutz Dec 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -445,31 +445,31 @@ public String getWriteBufferWriteMethodCall(String logicalName, SimpleTypeRefere
case UINT:
IntegerTypeReference unsignedIntegerTypeReference = (IntegerTypeReference) simpleTypeReference;
if (unsignedIntegerTypeReference.getSizeInBits() <= 8) {
return "writeBuffer.WriteUint8(\"" + logicalName + "\", " + unsignedIntegerTypeReference.getSizeInBits() + ", " + fieldName + writerArgsString + ")";
return "writeBuffer.WriteUint8(\"" + logicalName + "\", " + unsignedIntegerTypeReference.getSizeInBits() + ", uint8(" + fieldName + ")" + writerArgsString + ")";
}
if (unsignedIntegerTypeReference.getSizeInBits() <= 16) {
return "writeBuffer.WriteUint16(\"" + logicalName + "\", " + unsignedIntegerTypeReference.getSizeInBits() + ", " + fieldName + writerArgsString + ")";
return "writeBuffer.WriteUint16(\"" + logicalName + "\", " + unsignedIntegerTypeReference.getSizeInBits() + ", uint16(" + fieldName + ")" + writerArgsString + ")";
}
if (unsignedIntegerTypeReference.getSizeInBits() <= 32) {
return "writeBuffer.WriteUint32(\"" + logicalName + "\", " + unsignedIntegerTypeReference.getSizeInBits() + ", " + fieldName + writerArgsString + ")";
return "writeBuffer.WriteUint32(\"" + logicalName + "\", " + unsignedIntegerTypeReference.getSizeInBits() + ", uint32(" + fieldName + ")" + writerArgsString + ")";
}
if (unsignedIntegerTypeReference.getSizeInBits() <= 64) {
return "writeBuffer.WriteUint64(\"" + logicalName + "\", " + unsignedIntegerTypeReference.getSizeInBits() + ", " + fieldName + writerArgsString + ")";
return "writeBuffer.WriteUint64(\"" + logicalName + "\", " + unsignedIntegerTypeReference.getSizeInBits() + ", uint64(" + fieldName + ")" + writerArgsString + ")";
}
return "writeBuffer.WriteBigInt(\"" + logicalName + "\", " + unsignedIntegerTypeReference.getSizeInBits() + ", " + fieldName + writerArgsString + ")";
case INT:
IntegerTypeReference integerTypeReference = (IntegerTypeReference) simpleTypeReference;
if (integerTypeReference.getSizeInBits() <= 8) {
return "writeBuffer.WriteInt8(\"" + logicalName + "\", " + integerTypeReference.getSizeInBits() + ", " + fieldName + writerArgsString + ")";
return "writeBuffer.WriteInt8(\"" + logicalName + "\", " + integerTypeReference.getSizeInBits() + ", int8(" + fieldName + ")" + writerArgsString + ")";
}
if (integerTypeReference.getSizeInBits() <= 16) {
return "writeBuffer.WriteInt16(\"" + logicalName + "\", " + integerTypeReference.getSizeInBits() + ", " + fieldName + writerArgsString + ")";
return "writeBuffer.WriteInt16(\"" + logicalName + "\", " + integerTypeReference.getSizeInBits() + ", int16(" + fieldName + ")" + writerArgsString + ")";
}
if (integerTypeReference.getSizeInBits() <= 32) {
return "writeBuffer.WriteInt32(\"" + logicalName + "\", " + integerTypeReference.getSizeInBits() + ", " + fieldName + writerArgsString + ")";
return "writeBuffer.WriteInt32(\"" + logicalName + "\", " + integerTypeReference.getSizeInBits() + ", int32(" + fieldName + ")" + writerArgsString + ")";
}
if (integerTypeReference.getSizeInBits() <= 64) {
return "writeBuffer.WriteInt64(\"" + logicalName + "\", " + integerTypeReference.getSizeInBits() + ", " + fieldName + writerArgsString + ")";
return "writeBuffer.WriteInt64(\"" + logicalName + "\", " + integerTypeReference.getSizeInBits() + ", int64(" + fieldName + ")" + writerArgsString + ")";
}
return "writeBuffer.WriteBigInt(\"" + logicalName + "\", " + integerTypeReference.getSizeInBits() + ", " + fieldName + writerArgsString + ")";
case FLOAT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func ${type.name}ParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffe
<#case "TIME">
readBuffer.CloseContext("${type.name}")
<#if helper.hasFieldsWithNames(case.fields, "milliseconds")>
return values.NewPlcTIMEFromMilliseconds(milliseconds), nil
return values.NewPlcTIMEFromMilliseconds(int64(milliseconds)), nil
</#if>
<#break>
<#case "LTIME">
Expand Down
1 change: 1 addition & 0 deletions plc4c/generated-sources/s7/include/transport_size.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum plc4c_s7_read_write_transport_size {
plc4c_s7_read_write_transport_size_STRING = 0x12,
plc4c_s7_read_write_transport_size_WSTRING = 0x13,
plc4c_s7_read_write_transport_size_TIME = 0x14,
plc4c_s7_read_write_transport_size_S5TIME = 0x15,
plc4c_s7_read_write_transport_size_LTIME = 0x16,
plc4c_s7_read_write_transport_size_DATE = 0x17,
plc4c_s7_read_write_transport_size_TIME_OF_DAY = 0x18,
Expand Down
44 changes: 22 additions & 22 deletions plc4c/generated-sources/s7/src/data_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4x_spi_context ctx, plc

*data_item = plc4c_data_create_time_data(milliseconds);

} else if(strcmp(dataProtocolId, "S7_S5TIME") == 0) { /* TIME */

// Manual Field (milliseconds)
uint32_t milliseconds = (uint32_t) (plc4c_s7_read_write_parse_s5_time(readBuffer));

*data_item = plc4c_data_create_time_data(milliseconds);

} else if(strcmp(dataProtocolId, "IEC61131_LTIME") == 0) { /* LTIME */

// Simple Field (nanoseconds)
Expand All @@ -273,14 +280,10 @@ plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4x_spi_context ctx, plc

} else if(strcmp(dataProtocolId, "IEC61131_DATE") == 0) { /* DATE */

// Simple Field (daysSinceSiemensEpoch)
uint16_t daysSinceSiemensEpoch = 0;
_res = plc4c_spi_read_unsigned_short(readBuffer, 16, (uint16_t*) &daysSinceSiemensEpoch);
if(_res != OK) {
return _res;
}
// Manual Field (daysSinceEpoch)
uint16_t daysSinceEpoch = (uint16_t) (plc4c_s7_read_write_parse_tia_date(readBuffer));

*data_item = plc4c_data_create_date_data(daysSinceSiemensEpoch);
*data_item = plc4c_data_create_date_data(daysSinceEpoch);

} else if(strcmp(dataProtocolId, "IEC61131_TIME_OF_DAY") == 0) { /* TIME_OF_DAY */

Expand Down Expand Up @@ -526,6 +529,9 @@ plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4x_spi_context ctx,
if(_res != OK) {
return _res;
}
} else if(strcmp(dataProtocolId, "S7_S5TIME") == 0) { /* TIME */

// Manual Field (milliseconds)
} else if(strcmp(dataProtocolId, "IEC61131_LTIME") == 0) { /* LTIME */

// Simple field (nanoseconds)
Expand All @@ -535,11 +541,7 @@ plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4x_spi_context ctx,
}
} else if(strcmp(dataProtocolId, "IEC61131_DATE") == 0) { /* DATE */

// Simple field (daysSinceSiemensEpoch)
_res = plc4c_spi_write_unsigned_short(writeBuffer, 16, (*data_item)->data.date_value);
if(_res != OK) {
return _res;
}
// Manual Field (daysSinceEpoch)
} else if(strcmp(dataProtocolId, "IEC61131_TIME_OF_DAY") == 0) { /* TIME_OF_DAY */

// Simple field (millisecondsSinceMidnight)
Expand Down Expand Up @@ -687,29 +689,27 @@ uint16_t plc4c_s7_read_write_data_item_length_in_bits(plc4x_spi_context ctx, plc
} else if(strcmp(dataProtocolId, "IEC61131_STRING") == 0) { /* STRING */

// Manual Field (value)
{
char* _value = data_item->data.string_value;
lengthInBits += (plc4c_spi_evaluation_helper_str_len(_value)) + (2);
}
lengthInBits += (((stringLength) * (8))) + (16);
} else if(strcmp(dataProtocolId, "IEC61131_WSTRING") == 0) { /* STRING */

// Manual Field (value)
{
char* _value = data_item->data.string_value;
lengthInBits += (((plc4c_spi_evaluation_helper_str_len(_value)) * (2))) + (2);
}
lengthInBits += (((stringLength) * (16))) + (32);
} else if(strcmp(dataProtocolId, "IEC61131_TIME") == 0) { /* TIME */

// Simple field (milliseconds)
lengthInBits += 32;
} else if(strcmp(dataProtocolId, "S7_S5TIME") == 0) { /* TIME */

// Manual Field (milliseconds)
lengthInBits += 2;
} else if(strcmp(dataProtocolId, "IEC61131_LTIME") == 0) { /* LTIME */

// Simple field (nanoseconds)
lengthInBits += 64;
} else if(strcmp(dataProtocolId, "IEC61131_DATE") == 0) { /* DATE */

// Simple field (daysSinceSiemensEpoch)
lengthInBits += 16;
// Manual Field (daysSinceEpoch)
lengthInBits += 2;
} else if(strcmp(dataProtocolId, "IEC61131_TIME_OF_DAY") == 0) { /* TIME_OF_DAY */

// Simple field (millisecondsSinceMidnight)
Expand Down
67 changes: 56 additions & 11 deletions plc4c/generated-sources/s7/src/transport_size.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ plc4c_s7_read_write_transport_size plc4c_s7_read_write_transport_size_value_of(c
if(strcmp(value_string, "TIME") == 0) {
return plc4c_s7_read_write_transport_size_TIME;
}
if(strcmp(value_string, "S5TIME") == 0) {
return plc4c_s7_read_write_transport_size_S5TIME;
}
if(strcmp(value_string, "LTIME") == 0) {
return plc4c_s7_read_write_transport_size_LTIME;
}
Expand All @@ -144,7 +147,7 @@ plc4c_s7_read_write_transport_size plc4c_s7_read_write_transport_size_value_of(c
}

int plc4c_s7_read_write_transport_size_num_values() {
return 26;
return 27;
}

plc4c_s7_read_write_transport_size plc4c_s7_read_write_transport_size_value_for_index(int index) {
Expand Down Expand Up @@ -210,21 +213,24 @@ plc4c_s7_read_write_transport_size plc4c_s7_read_write_transport_size_value_for_
return plc4c_s7_read_write_transport_size_TIME;
}
case 20: {
return plc4c_s7_read_write_transport_size_LTIME;
return plc4c_s7_read_write_transport_size_S5TIME;
}
case 21: {
return plc4c_s7_read_write_transport_size_DATE;
return plc4c_s7_read_write_transport_size_LTIME;
}
case 22: {
return plc4c_s7_read_write_transport_size_TIME_OF_DAY;
return plc4c_s7_read_write_transport_size_DATE;
}
case 23: {
return plc4c_s7_read_write_transport_size_TOD;
return plc4c_s7_read_write_transport_size_TIME_OF_DAY;
}
case 24: {
return plc4c_s7_read_write_transport_size_DATE_AND_TIME;
return plc4c_s7_read_write_transport_size_TOD;
}
case 25: {
return plc4c_s7_read_write_transport_size_DATE_AND_TIME;
}
case 26: {
return plc4c_s7_read_write_transport_size_DT;
}
default: {
Expand Down Expand Up @@ -295,6 +301,9 @@ bool plc4c_s7_read_write_transport_size_get_supported__s7_300(plc4c_s7_read_writ
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return true;
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return true;
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return false;
}
Expand Down Expand Up @@ -389,6 +398,9 @@ bool plc4c_s7_read_write_transport_size_get_supported__logo(plc4c_s7_read_write_
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return true;
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return true;
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return false;
}
Expand Down Expand Up @@ -483,6 +495,9 @@ uint8_t plc4c_s7_read_write_transport_size_get_code(plc4c_s7_read_write_transpor
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return 11;
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return 4;
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return 0;
}
Expand Down Expand Up @@ -619,6 +634,9 @@ uint8_t plc4c_s7_read_write_transport_size_get_size_in_bytes(plc4c_s7_read_write
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return 4;
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return 2;
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return 8;
}
Expand Down Expand Up @@ -731,6 +749,9 @@ bool plc4c_s7_read_write_transport_size_get_supported__s7_400(plc4c_s7_read_writ
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return true;
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return true;
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return false;
}
Expand Down Expand Up @@ -825,6 +846,9 @@ bool plc4c_s7_read_write_transport_size_get_supported__s7_1200(plc4c_s7_read_wri
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return true;
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return true;
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return false;
}
Expand Down Expand Up @@ -919,6 +943,9 @@ uint8_t plc4c_s7_read_write_transport_size_get_short_name(plc4c_s7_read_write_tr
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return 'X';
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return 'X';
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return 'X';
}
Expand Down Expand Up @@ -1025,6 +1052,9 @@ bool plc4c_s7_read_write_transport_size_get_supported__s7_1500(plc4c_s7_read_wri
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return true;
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return true;
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return true;
}
Expand Down Expand Up @@ -1105,19 +1135,22 @@ plc4c_s7_read_write_data_transport_size plc4c_s7_read_write_transport_size_get_d
return -1;
}
case plc4c_s7_read_write_transport_size_CHAR: { /* '0x10' */
return plc4c_s7_read_write_data_transport_size_BYTE_WORD_DWORD;
return plc4c_s7_read_write_data_transport_size_OCTET_STRING;
}
case plc4c_s7_read_write_transport_size_WCHAR: { /* '0x11' */
return -1;
return plc4c_s7_read_write_data_transport_size_OCTET_STRING;
}
case plc4c_s7_read_write_transport_size_STRING: { /* '0x12' */
return plc4c_s7_read_write_data_transport_size_BYTE_WORD_DWORD;
return plc4c_s7_read_write_data_transport_size_OCTET_STRING;
}
case plc4c_s7_read_write_transport_size_WSTRING: { /* '0x13' */
return -1;
return plc4c_s7_read_write_data_transport_size_OCTET_STRING;
}
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return -1;
return plc4c_s7_read_write_data_transport_size_BYTE_WORD_DWORD;
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return plc4c_s7_read_write_data_transport_size_BYTE_WORD_DWORD;
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return -1;
Expand Down Expand Up @@ -1154,6 +1187,9 @@ plc4c_s7_read_write_transport_size plc4c_s7_read_write_transport_size_get_first_
case plc4c_s7_read_write_transport_size_INT: /* '0x06' */{
return plc4c_s7_read_write_transport_size_INT;
}
case plc4c_s7_read_write_transport_size_CHAR: /* '0x10' */{
return plc4c_s7_read_write_transport_size_CHAR;
}
case plc4c_s7_read_write_transport_size_REAL: /* '0x0E' */{
return plc4c_s7_read_write_transport_size_REAL;
}
Expand Down Expand Up @@ -1228,6 +1264,9 @@ char* plc4c_s7_read_write_transport_size_get_data_protocol_id(plc4c_s7_read_writ
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return "IEC61131_TIME";
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return "S7_S5TIME";
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return "IEC61131_LTIME";
}
Expand Down Expand Up @@ -1325,6 +1364,9 @@ plc4c_s7_read_write_transport_size plc4c_s7_read_write_transport_size_get_first_
if (strcmp(value, "IEC61131_WSTRING") == 0) {
return plc4c_s7_read_write_transport_size_WSTRING;
}
if (strcmp(value, "S7_S5TIME") == 0) {
return plc4c_s7_read_write_transport_size_S5TIME;
}
}

plc4c_s7_read_write_transport_size plc4c_s7_read_write_transport_size_get_base_type(plc4c_s7_read_write_transport_size value) {
Expand Down Expand Up @@ -1389,6 +1431,9 @@ plc4c_s7_read_write_transport_size plc4c_s7_read_write_transport_size_get_base_t
case plc4c_s7_read_write_transport_size_TIME: { /* '0x14' */
return -1;
}
case plc4c_s7_read_write_transport_size_S5TIME: { /* '0x15' */
return -1;
}
case plc4c_s7_read_write_transport_size_LTIME: { /* '0x16' */
return plc4c_s7_read_write_transport_size_TIME;
}
Expand Down
Loading
Loading