1818import com .fasterxml .jackson .annotation .JsonCreator ;
1919import com .fasterxml .jackson .annotation .JsonProperty ;
2020import com .hivemq .adapter .sdk .api .annotations .ModuleConfigField ;
21- import com .hivemq .adapter .sdk .api .config .ProtocolAdapterConfig ;
21+ import com .hivemq .adapter .sdk .api .config .ProtocolSpecificAdapterConfig ;
2222import org .jetbrains .annotations .NotNull ;
2323import org .jetbrains .annotations .Nullable ;
2424
25- import java .util .List ;
26- import java .util .Objects ;
27- import java .util .Set ;
28- import java .util .stream .Collectors ;
29-
30- public class S7AdapterConfig implements ProtocolAdapterConfig {
25+ public class S7AdapterConfig implements ProtocolSpecificAdapterConfig {
3126
3227 private static final @ NotNull String ID_REGEX = "^([a-zA-Z_0-9-_])*$" ;
3328
3429 private static final int PORT_MIN = 1 ;
3530 private static final int PORT_MAX = 65535 ;
3631
37- public static final String DEFAULT_POLLING_INTERVAL_MS = "1000" ;
38- public static final String DEFAULT_MAX_POLLING_ERRORS = "10" ;
39- public static final String DEFAULT_PUBLISH_CHANGED_DATA_ONLY = "true" ;
4032 public static final String DEFAULT_S7_PORT = "102" ;
4133 public static final String DEFAULT_CONTROLER_TYPE = "S7_300" ;
4234
@@ -47,9 +39,6 @@ public class S7AdapterConfig implements ProtocolAdapterConfig {
4739 public static final String PROPERTY_REMOTE_RACK = "remoteRack" ;
4840 public static final String PROPERTY_REMOTE_SLOT = "remoteSlot" ;
4941 public static final String PROPERTY_PDU_LENGTH = "pduLength" ;
50- public static final String PROPERTY_POLLING_INTERVAL_MILLIS = "pollingIntervalMillis" ;
51- public static final String PROPERTY_MAX_POLLING_ERRORS_BEFORE_REMOVAL = "maxPollingErrorsBeforeRemoval" ;
52- public static final String PROPERTY_PUBLISH_CHANGED_DATA_ONLY = "publishChangedDataOnly" ;
5342 public static final String PROPERTY_S_7_TO_MQTT_MAPPINGS = "s7ToMqttMappings" ;
5443
5544 public enum ControllerType {
@@ -62,36 +51,6 @@ public enum ControllerType {
6251 SINUMERIK_828D
6352 }
6453
65- @ JsonProperty (PROPERTY_POLLING_INTERVAL_MILLIS )
66- @ ModuleConfigField (title = "Polling Interval [ms]" ,
67- description = "Time in millisecond that this endpoint will be polled" ,
68- numberMin = 1 ,
69- defaultValue = DEFAULT_POLLING_INTERVAL_MS )
70- private final int pollingIntervalMillis ;
71-
72- @ JsonProperty (PROPERTY_MAX_POLLING_ERRORS_BEFORE_REMOVAL )
73- @ ModuleConfigField (title = "Max. Polling Errors" ,
74- description = "Max. errors polling the endpoint before the polling daemon is stopped (-1 for unlimited retries)" ,
75- numberMin = -1 ,
76- defaultValue = DEFAULT_MAX_POLLING_ERRORS )
77- private final int maxPollingErrorsBeforeRemoval ;
78-
79- @ JsonProperty (PROPERTY_PUBLISH_CHANGED_DATA_ONLY )
80- @ ModuleConfigField (title = "Only publish data items that have changed since last poll" ,
81- defaultValue = DEFAULT_PUBLISH_CHANGED_DATA_ONLY ,
82- format = ModuleConfigField .FieldType .BOOLEAN )
83- private final boolean publishChangedDataOnly ;
84-
85- @ JsonProperty (value = PROPERTY_ID , required = true )
86- @ ModuleConfigField (title = "Identifier" ,
87- description = "Unique identifier for this protocol adapter" ,
88- format = ModuleConfigField .FieldType .IDENTIFIER ,
89- required = true ,
90- stringPattern = ID_REGEX ,
91- stringMinLength = 1 ,
92- stringMaxLength = 1024 )
93- private final @ NotNull String id ;
94-
9554 @ JsonProperty (value = PROPERTY_PORT , required = true )
9655 @ ModuleConfigField (title = "Port" ,
9756 description = "The port number on the device to connect to" ,
@@ -134,7 +93,7 @@ public enum ControllerType {
13493 @ ModuleConfigField (title = "S7 To MQTT Config" ,
13594 description = "The configuration for a data stream from S7 to MQTT" ,
13695 required = true )
137- private final @ NotNull List < S7ToMqttConfig > s7ToMqttConfig ;
96+ private final @ NotNull S7ToMqttConfig s7ToMqttConfig ;
13897
13998 @ JsonCreator
14099 public S7AdapterConfig (
@@ -145,38 +104,16 @@ public S7AdapterConfig(
145104 @ JsonProperty (value = PROPERTY_REMOTE_RACK ) final @ Nullable Integer remoteRack ,
146105 @ JsonProperty (value = PROPERTY_REMOTE_SLOT ) final @ Nullable Integer remoteSlot ,
147106 @ JsonProperty (value = PROPERTY_PDU_LENGTH ) final @ Nullable Integer pduLength ,
148- @ JsonProperty (value = PROPERTY_POLLING_INTERVAL_MILLIS ) final @ Nullable Integer pollingIntervalMillis ,
149- @ JsonProperty (value = PROPERTY_MAX_POLLING_ERRORS_BEFORE_REMOVAL ) final @ Nullable Integer maxPollingErrorsBeforeRemoval ,
150- @ JsonProperty (value = PROPERTY_PUBLISH_CHANGED_DATA_ONLY ) final @ Nullable Boolean publishChangedDataOnly ,
151- @ JsonProperty (value = PROPERTY_S_7_TO_MQTT_MAPPINGS , required = true ) final @ NotNull List <S7ToMqttConfig > s7ToMqttConfig ) {
152- this .id = id ;
107+ @ JsonProperty (value = PROPERTY_S_7_TO_MQTT_MAPPINGS , required = true ) final @ NotNull S7ToMqttConfig s7ToMqttConfig ) {
153108 this .host = host ;
154109 this .controllerType = controllerType ;
155110 this .port = port ;
156- this .pollingIntervalMillis = Objects .requireNonNullElse (pollingIntervalMillis ,
157- Integer .valueOf (DEFAULT_POLLING_INTERVAL_MS ));
158- this .maxPollingErrorsBeforeRemoval = Objects .requireNonNullElse (maxPollingErrorsBeforeRemoval ,
159- Integer .valueOf (DEFAULT_MAX_POLLING_ERRORS ));
160- this .publishChangedDataOnly = Objects .requireNonNullElse (publishChangedDataOnly ,
161- Boolean .valueOf (DEFAULT_PUBLISH_CHANGED_DATA_ONLY ));
162111 this .remoteRack = remoteRack ;
163112 this .remoteSlot = remoteSlot ;
164113 this .pduLength = pduLength ;
165114 this .s7ToMqttConfig = s7ToMqttConfig ;
166115 }
167116
168- public int getPollingIntervalMillis () {
169- return pollingIntervalMillis ;
170- }
171-
172- public int getMaxPollingErrorsBeforeRemoval () {
173- return maxPollingErrorsBeforeRemoval ;
174- }
175-
176- public boolean getPublishChangedDataOnly () {
177- return publishChangedDataOnly ;
178- }
179-
180117 public int getPort () {
181118 return port ;
182119 }
@@ -197,21 +134,32 @@ public int getPort() {
197134 return controllerType ;
198135 }
199136
200- @ Override
201- public @ NotNull String getId () {
202- return id ;
203- }
204-
205137 public @ NotNull String getHost () {
206138 return host ;
207139 }
208140
209- public @ NotNull List < S7ToMqttConfig > getS7ToMqttMappings () {
141+ public @ NotNull S7ToMqttConfig getS7ToMqttConfig () {
210142 return s7ToMqttConfig ;
211143 }
212144
213145 @ Override
214- public @ NotNull Set <String > calculateAllUsedTags () {
215- return s7ToMqttConfig .stream ().map (S7ToMqttConfig ::getTagName ).collect (Collectors .toSet ());
146+ public String toString () {
147+ return "S7AdapterConfig{" +
148+ "port=" +
149+ port +
150+ ", host='" +
151+ host +
152+ '\'' +
153+ ", controllerType=" +
154+ controllerType +
155+ ", remoteRack=" +
156+ remoteRack +
157+ ", remoteSlot=" +
158+ remoteSlot +
159+ ", pduLength=" +
160+ pduLength +
161+ ", s7ToMqttConfig=" +
162+ s7ToMqttConfig +
163+ '}' ;
216164 }
217165}
0 commit comments