Skip to content

Commit

Permalink
refactor: Finished porting the Data-IO template. Also got All S7-1200…
Browse files Browse the repository at this point in the history
… data-types working and all but the last two L-types for S7-1500
  • Loading branch information
chrisdutz committed Feb 1, 2024
1 parent bf7acb0 commit ee21b13
Show file tree
Hide file tree
Showing 19 changed files with 1,001 additions and 463 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ public String getDataIoPropertyValue(PropertyField propertyField) {
return "_value.getDateTime().toEpochSecond(OffsetDateTime.now().getOffset())";
case "milliseconds":
return "_value.getDuration().toMillis()";
case "millisecondsOfSecond":
return "_value.getTime().get(ChronoField.MILLI_OF_SECOND)";
case "millisecondsSinceMidnight":
if(simpleTypeReference.getSizeInBits() <= 63) {
return "_value.getTime().getLong(ChronoField.MILLI_OF_DAY)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ public class ${type.name} {
</#if>
<#break>
<#case "DATE_AND_TIME">
<#if helper.hasFieldsWithNames(case.fields, "year", "month", "day", "hour", "minutes", "seconds", "milliseconds")>
return PlcDATE_AND_TIME.ofSegments(year, (month == 0) ? 1 : month, (day == 0) ? 1 : day, hour, minutes, seconds, milliseconds);
<#if helper.hasFieldsWithNames(case.fields, "year", "month", "day", "hour", "minutes", "seconds", "millisecondsOfSecond")>
return PlcDATE_AND_TIME.ofSegments(year, (month == 0) ? 1 : month, (day == 0) ? 1 : day, hour, minutes, seconds, millisecondsOfSecond);
<#elseif helper.hasFieldsWithNames(case.fields, "secondsSinceEpoch")>
return PlcDATE_AND_TIME.ofSecondsSinceEpoch(secondsSinceEpoch);
</#if>
Expand Down
2 changes: 2 additions & 0 deletions plc4c/drivers/s7/include/plc4c/driver_s7_static.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ time_t plc4c_s7_read_write_parse_tia_time_of_day(plc4c_spi_read_buffer* io);

time_t plc4c_s7_read_write_parse_tia_date_time(plc4c_spi_read_buffer* io);

uint8_t plc4c_s7_read_write_parse_siemens_year(plc4c_spi_read_buffer* io);

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions plc4c/drivers/s7/src/driver_s7_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,7 @@ plc4c_return_code plc4c_s7_read_write_int_to_s7msec(plc4c_spi_write_buffer* writ
return 0;
}

uint8_t plc4c_s7_read_write_parse_siemens_year(plc4c_spi_read_buffer* io) {
return 0;
}

14 changes: 10 additions & 4 deletions plc4c/generated-sources/s7/include/transport_size.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ enum plc4c_s7_read_write_transport_size {
plc4c_s7_read_write_transport_size_WCHAR = 0x11,
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_S5TIME = 0x14,
plc4c_s7_read_write_transport_size_TIME = 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,
plc4c_s7_read_write_transport_size_TOD = 0x19,
plc4c_s7_read_write_transport_size_DATE_AND_TIME = 0x1A,
plc4c_s7_read_write_transport_size_DT = 0x1B
plc4c_s7_read_write_transport_size_LTIME_OF_DAY = 0x1A,
plc4c_s7_read_write_transport_size_LTOD = 0x1B,
plc4c_s7_read_write_transport_size_DATE_AND_TIME = 0x1C,
plc4c_s7_read_write_transport_size_DT = 0x1D,
plc4c_s7_read_write_transport_size_LDATE_AND_TIME = 0x1E,
plc4c_s7_read_write_transport_size_LDT = 0x1F,
plc4c_s7_read_write_transport_size_DATE_AND_LTIME = 0x20,
plc4c_s7_read_write_transport_size_DTL = 0x21
};
typedef enum plc4c_s7_read_write_transport_size plc4c_s7_read_write_transport_size;

Expand Down
30 changes: 11 additions & 19 deletions plc4c/generated-sources/s7/src/data_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,8 @@ plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4x_spi_context ctx, plc

} else if(strcmp(dataProtocolId, "IEC61131_DATE_AND_TIME") == 0) { /* DATE_AND_TIME */

// Simple Field (year)
uint8_t year = 0;
_res = plc4c_spi_read_unsigned_byte(readBuffer, 8, (uint8_t*) &year);
if(_res != OK) {
return _res;
}
// Manual Field (year)
uint8_t year = (uint8_t) (plc4c_s7_read_write_parse_siemens_year(readBuffer));

*data_item = plc4c_data_create_date_and_time_data(year);

Expand Down Expand Up @@ -369,14 +365,14 @@ plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4x_spi_context ctx, plc
*data_item = plc4c_data_create_date_and_time_data(seconds);


// Simple Field (milliseconds)
uint16_t milliseconds = 0;
_res = plc4c_spi_read_unsigned_short(readBuffer, 12, (uint16_t*) &milliseconds);
// Simple Field (millisecondsOfSecond)
uint16_t millisecondsOfSecond = 0;
_res = plc4c_spi_read_unsigned_short(readBuffer, 12, (uint16_t*) &millisecondsOfSecond);
if(_res != OK) {
return _res;
}

*data_item = plc4c_data_create_date_and_time_data(milliseconds);
*data_item = plc4c_data_create_date_and_time_data(millisecondsOfSecond);


// Simple Field (dayOfWeek)
Expand Down Expand Up @@ -558,11 +554,7 @@ plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4x_spi_context ctx,
}
} else if(strcmp(dataProtocolId, "IEC61131_DATE_AND_TIME") == 0) { /* DATE_AND_TIME */

// Simple field (year)
_res = plc4c_spi_write_unsigned_byte(writeBuffer, 8, (*data_item)->data.date_and_time_value);
if(_res != OK) {
return _res;
}
// Manual Field (year)

// Simple field (month)
_res = plc4c_spi_write_unsigned_byte(writeBuffer, 8, (*data_item)->data.date_and_time_value);
Expand Down Expand Up @@ -594,7 +586,7 @@ plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4x_spi_context ctx,
return _res;
}

// Simple field (milliseconds)
// Simple field (millisecondsOfSecond)
_res = plc4c_spi_write_unsigned_short(writeBuffer, 12, (*data_item)->data.date_and_time_value);
if(_res != OK) {
return _res;
Expand Down Expand Up @@ -709,7 +701,7 @@ uint16_t plc4c_s7_read_write_data_item_length_in_bits(plc4x_spi_context ctx, plc
} else if(strcmp(dataProtocolId, "IEC61131_DATE") == 0) { /* DATE */

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

// Simple field (millisecondsSinceMidnight)
Expand All @@ -720,7 +712,7 @@ uint16_t plc4c_s7_read_write_data_item_length_in_bits(plc4x_spi_context ctx, plc
lengthInBits += 64;
} else if(strcmp(dataProtocolId, "IEC61131_DATE_AND_TIME") == 0) { /* DATE_AND_TIME */

// Simple field (year)
// Manual Field (year)
lengthInBits += 8;

// Simple field (month)
Expand All @@ -738,7 +730,7 @@ uint16_t plc4c_s7_read_write_data_item_length_in_bits(plc4x_spi_context ctx, plc
// Simple field (seconds)
lengthInBits += 8;

// Simple field (milliseconds)
// Simple field (millisecondsOfSecond)
lengthInBits += 12;

// Simple field (dayOfWeek)
Expand Down
Loading

0 comments on commit ee21b13

Please sign in to comment.