Skip to content

Commit 9d5c3b8

Browse files
committed
Structure
1 parent 3aa42c3 commit 9d5c3b8

File tree

4 files changed

+81
-34
lines changed

4 files changed

+81
-34
lines changed

modules/hivemq-edge-module-s7/src/main/java/com/hivemq/edge/adapters/s7/S7Client.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;
1212

13+
import java.math.BigInteger;
1314
import java.util.List;
1415
import java.util.stream.Collectors;
1516
import java.util.stream.IntStream;
1617

18+
import static com.hivemq.edge.adapters.s7.config.S7Versions.S7_1200;
19+
import static com.hivemq.edge.adapters.s7.config.S7Versions.S7_1500;
20+
import static com.hivemq.edge.adapters.s7.config.S7Versions.S7_300;
21+
import static com.hivemq.edge.adapters.s7.config.S7Versions.S7_400;
22+
1723
public class S7Client {
1824

1925
private static final Logger log = LoggerFactory.getLogger(S7Client.class);
@@ -48,20 +54,34 @@ public List<DataPoint> read(final @NotNull S7DataType type, final @NotNull List<
4854
log.trace("Reading data from addresses {} with type {}", addresses, type);
4955
}
5056
switch (type) {
51-
case BYTE: throw new IllegalArgumentException("Byte data type not supported by this method, use readBytes");
5257
case BOOL: return combine(dataPointFactory, addresses, s7PLC.readBoolean(addresses));
53-
case INT16: return combine(dataPointFactory, addresses, s7PLC.readInt16(addresses));
54-
case UINT16: return combine(dataPointFactory, addresses, s7PLC.readUInt16(addresses));
55-
case INT32: return combine(dataPointFactory, addresses, s7PLC.readInt32(addresses));
56-
case UINT32: return combine(dataPointFactory, addresses, s7PLC.readUInt32(addresses));
57-
case INT64: return combine(dataPointFactory, addresses, s7PLC.readInt64(addresses));
58+
case BYTE: throw new IllegalArgumentException("Byte data type not supported by this method, use readBytes");
59+
case WORD: return null;
60+
case DWORD: return null;
61+
case LWORD: return null;
62+
case USINT: return combine(dataPointFactory, addresses, s7PLC.readUInt16(addresses));
63+
case UINT: return null;
64+
case UDINT: return combine(dataPointFactory, addresses, s7PLC.readUInt32(addresses));
65+
case ULINT: return null;
66+
case SINT: return null;
67+
case INT: return combine(dataPointFactory, addresses, s7PLC.readInt16(addresses));
68+
case DINT: return combine(dataPointFactory, addresses, s7PLC.readInt32(addresses));
69+
case LINT: return combine(dataPointFactory, addresses, s7PLC.readInt64(addresses));
5870
case REAL: return combine(dataPointFactory, addresses, s7PLC.readFloat32(addresses));
5971
case LREAL: return combine(dataPointFactory, addresses, s7PLC.readFloat64(addresses));
72+
case CHAR: return null;
73+
case WCHAR: return null;
6074
case STRING: return combine(dataPointFactory, addresses, addresses.stream().map(s7PLC::readString).collect(Collectors.toList()));
61-
case DATE: return combine(dataPointFactory, addresses, addresses.stream().map(s7PLC::readDate).collect(Collectors.toList()));
62-
case TIME_OF_DAY: return combine(dataPointFactory, addresses, addresses.stream().map(s7PLC::readTimeOfDay).collect(Collectors.toList()));
75+
case WSTRING: return null;
6376
case TIME: return combine(dataPointFactory, addresses, addresses.stream().map(s7PLC::readTime).collect(Collectors.toList()));
64-
case DATE_AND_TIME: return combine(dataPointFactory, addresses, addresses.stream().map(s7PLC::readDTL).collect(Collectors.toList()));
77+
case LTIME: return null;
78+
case DATE: return combine(dataPointFactory, addresses, addresses.stream().map(s7PLC::readDate).collect(Collectors.toList()));
79+
case TOD: return combine(dataPointFactory, addresses, addresses.stream().map(s7PLC::readTimeOfDay).collect(Collectors.toList()));
80+
case LTOD: return null;
81+
case DT: return combine(dataPointFactory, addresses, addresses.stream().map(s7PLC::readDTL).collect(Collectors.toList()));
82+
case LDT: return null;
83+
case DTL: return null;
84+
case ARRAY: return null;
6585
default: {
6686
log.error("Unspported tag-type {} at address {}", type, addresses);
6787
throw new IllegalArgumentException("Unspported tag-type " + type + " at address " + addresses);

modules/hivemq-edge-module-s7/src/main/java/com/hivemq/edge/adapters/s7/config/S7DataType.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.hivemq.edge.adapters.s7.config;
1717

18+
import org.jetbrains.annotations.NotNull;
19+
1820
import java.math.BigInteger;
1921
import java.time.LocalDate;
2022
import java.time.LocalDateTime;
@@ -55,45 +57,28 @@ public enum S7DataType {
5557

5658
TIME(Long.class, 32, List.of(S7_300, S7_400, S7_1200, S7_1500), "IEC Time (ms)", "https://support.industry.siemens.com/cs/mdm/109054417?c=61085966091&lc=en-GE"),
5759
LTIME(BigInteger.class, 64, List.of(S7_1500), "IEC Time (ns)", "https://support.industry.siemens.com/cs/mdm/109054417?c=61410814475&lc=en-GE"),
60+
//TODO S5TIME https://support.industry.siemens.com/cs/mdm/109054417?c=63689295627&lc=en-GE
5861

5962
DATE(Short.class, 8, List.of(S7_300, S7_400, S7_1200, S7_1500), "IEC Date, since 01-01-1990 (Year-Month-Day)", "https://support.industry.siemens.com/cs/mdm/109054417?c=46522046859&lc=en-GE"),
6063
TOD(Long.class, 32, List.of(S7_300, S7_400, S7_1200, S7_1500), "Time Of Day (hours:minutes:seconds.milliseconds)", "https://support.industry.siemens.com/cs/mdm/109054417?c=64869849355&lc=en-GE"),
6164
LTOD(BigInteger.class, 64, List.of(S7_1500), "Time-of-day (hours:minutes:seconds.nanoseconds)", "https://support.industry.siemens.com/cs/mdm/109054417?c=64869390987&lc=en-GE"),
6265
DT(BigInteger.class, 64, List.of(S7_1500), "Date and time (year-month-day-hour:minute:second:millisecond)", "https://support.industry.siemens.com/cs/mdm/109054417?c=61473284875&lc=en-GE"),
6366
LDT(BigInteger.class, 64, List.of(S7_1500), "Date and time (year-month-day-hour:minute:second:nanoseconds)", "https://support.industry.siemens.com/cs/mdm/109054417?c=71834521483&lc=en-GE"),
6467
DTL(BigInteger.class, 64, List.of(S7_1500), "Date and time (year-month-day-hour:minute:second:nanoseconds)", "https://support.industry.siemens.com/cs/mdm/109054417?c=64682916235&lc=en-GE"),
68+
ARRAY(Byte[].class, -1, List.of(S7_300, S7_400, S7_1200, S7_1500), "Array of type", "https://support.industry.siemens.com/cs/mdm/109054417?c=52352205963&lc=en-GE");
69+
//RAW_BYTE_ARRAY TODO: it's not an actual type but is there in the old implementation
6570

66-
67-
/**
68-
* UNSUPPORTED
69-
* S5TIME https://support.industry.siemens.com/cs/mdm/109054417?c=63689295627&lc=en-GE
70-
*/
71-
72-
BYTE_ARRAY(Byte[].class),
73-
INT16(Short.class),
74-
UINT16(Short.class),
75-
INT32(Integer.class),
76-
UINT32(Integer.class),
77-
INT64(Long.class),
78-
REAL(Float.class),
79-
LREAL(Double.class),
80-
STRING(String.class),
81-
DATE(LocalDate.class),
82-
TIME_OF_DAY(LocalTime.class),
83-
DATE_AND_TIME(LocalDateTime.class),
84-
TIME(Long.class);
85-
86-
S7DataType(Class<?> javaType, int lengthInBits, List<S7Versions> availableOn, String description, String docs){
71+
S7DataType(final @NotNull Class<?> javaType, final @NotNull int lengthInBits, final @NotNull List<S7Versions> availableOn, final @NotNull String description, final @NotNull String docs){
8772
this.javaType = javaType;
8873
this.lengthInBits = lengthInBits;
8974
this.availableOn = availableOn;
9075
this.description = description;
9176
this.docs = docs;
9277
}
93-
private Class<?> javaType;
94-
private final int lengthInBits;
95-
private final List<S7Versions> availableOn;
96-
private final String description;
78+
private final @NotNull Class<?> javaType;
79+
private final @NotNull int lengthInBits;
80+
private final @NotNull List<S7Versions> availableOn;
81+
private final @NotNull String description;
9782
private final String docs;
9883

9984
public Class<?> getJavaType() {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.hivemq.edge.adapters.s7.types;
2+
3+
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
4+
import com.hivemq.adapter.sdk.api.data.DataPoint;
5+
import com.hivemq.adapter.sdk.api.factories.DataPointFactory;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import java.util.List;
9+
import java.util.stream.Collectors;
10+
import java.util.stream.IntStream;
11+
12+
public class BoolType<Bool> {
13+
private final @NotNull DataPointFactory dataPointFactory;
14+
private final @NotNull S7PLC client;
15+
16+
public BoolType(@NotNull final DataPointFactory dataPointFactory, @NotNull final S7PLC client) {
17+
this.dataPointFactory = dataPointFactory;
18+
this.client = client;
19+
}
20+
21+
public List<DataPoint> read(final @NotNull List<String> addresses) {
22+
return combine(dataPointFactory, addresses, client.readBoolean(addresses));
23+
}
24+
25+
public static List<DataPoint> combine(final @NotNull DataPointFactory dataPointFactory, final @NotNull List<String> addresses, final @NotNull List<?> values) {
26+
return IntStream
27+
.range(0, addresses.size())
28+
.mapToObj(i -> dataPointFactory.create(addresses.get(i), values.get(i)))
29+
.collect(Collectors.toList());
30+
}
31+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.hivemq.edge.adapters.s7.types;
2+
3+
import com.hivemq.adapter.sdk.api.data.DataPoint;
4+
import com.hivemq.edge.adapters.s7.config.S7DataType;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
import java.util.List;
8+
9+
public interface DatatType<T extends S7DataType> {
10+
List<DataPoint> read(final @NotNull List<String> addresses);
11+
}

0 commit comments

Comments
 (0)