Skip to content

Commit 9604f33

Browse files
authored
Oh3.2 (#37)
* Added update mode * Fix reconnect issue #34 * Space between data in one area increased to 128 * Version update
1 parent 25f81a7 commit 9604f33

14 files changed

Lines changed: 467 additions & 249 deletions

File tree

org.openhab.binding.simatic/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.openhab.addons.bundles</groupId>
99
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
10-
<version>3.1.0-SNAPSHOT</version>
10+
<version>3.2.0</version>
1111
</parent>
1212

1313
<artifactId>org.openhab.binding.simatic</artifactId>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<features xmlns="http://karaf.apache.org/xmlns/features/v1.6.0" name="org.openhab.binding.simatic-3.1.0-SNAPSHOT">
2+
<features xmlns="http://karaf.apache.org/xmlns/features/v1.6.0" name="org.openhab.binding.simatic-3.2.0">
33
<feature version="0.0.0">
44
<feature>openhab-runtime-base</feature>
55
<feature>wrap</feature>
6-
<bundle>mvn:org.openhab.addons.bundles/org.openhab.binding.simatic/3.1.0-SNAPSHOT</bundle>
6+
<bundle>mvn:org.openhab.addons.bundles/org.openhab.binding.simatic/3.2.0</bundle>
77
<bundle>wrap:mvn:org.lastnpe.eea/eea-all/2.2.1</bundle>
88
</feature>
99
</features>

org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/config/simaticBridgeConfiguration.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package org.openhab.binding.simatic.internal.config;
1414

15+
import org.openhab.binding.simatic.internal.simatic.SimaticUpdateMode;
16+
1517
/**
1618
* The {@link SimaticBridgeConfiguration} class contains fields mapping thing configuration parameters.
1719
*
@@ -53,4 +55,19 @@ public class SimaticBridgeConfiguration {
5355
* Device poll rate
5456
*/
5557
public int pollRate = 1000;
58+
59+
/**
60+
* Value update mode (OC,PL)
61+
*/
62+
public String updateMode = "OnChange";
63+
64+
/**
65+
* Get Value Update Mode
66+
*
67+
* @return Return Update mode
68+
*/
69+
public SimaticUpdateMode getUpdateMode() {
70+
return SimaticUpdateMode.valueOf(updateMode);
71+
}
72+
5673
}

org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/handler/simaticBridgeHandler.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.openhab.binding.simatic.internal.simatic.SimaticGenericDevice;
2525
import org.openhab.binding.simatic.internal.simatic.SimaticTCP;
2626
import org.openhab.binding.simatic.internal.simatic.SimaticTCP200;
27+
import org.openhab.binding.simatic.internal.simatic.SimaticUpdateMode;
2728
import org.openhab.core.library.types.DecimalType;
2829
import org.openhab.core.library.types.QuantityType;
2930
import org.openhab.core.library.types.StringType;
@@ -96,38 +97,35 @@ public void initialize() {
9697

9798
config = getConfigAs(SimaticBridgeConfiguration.class);
9899

99-
logger.debug("{} - Bridge configuration: Host/IP={},Rack={},Slot={},Comm={},Is200={},Charset={},PollRate={}",
100+
logger.debug(
101+
"{} - Bridge configuration: Host/IP={},Rack={},Slot={},Comm={},Is200={},Charset={},PollRate={},Mode={}",
100102
getThing().getLabel(), config.address, config.rack, config.slot, config.communicationType,
101-
config.isS7200, config.charset, config.pollRate);
103+
config.isS7200, config.charset, config.pollRate, config.updateMode);
102104

103105
// configuration validation
104106
boolean valid = true;
105107

106108
if (config.address == null || config.address.isBlank()) {
107109
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No Host/IP address");
108110
valid = false;
109-
return;
110111
}
111112

112-
if (config.rack < 0 || config.rack > 2) {
113+
if (valid && (config.rack < 0 || config.rack > 2)) {
113114
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
114115
"Invalid Rack number. Valid is 0-2.");
115116
valid = false;
116-
return;
117117
}
118118

119-
if (config.slot < 0 || config.slot > 15) {
119+
if (valid && (config.slot < 0 || config.slot > 15)) {
120120
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
121121
"Invalid Slot number. Valid is 0-15.");
122122
valid = false;
123-
return;
124123
}
125124

126-
if (config.communicationType == null || !(config.communicationType.equals("S7")
127-
|| config.communicationType.equals("PG") || config.communicationType.equals("OP"))) {
125+
if (valid && (config.communicationType == null || !(config.communicationType.equals("S7")
126+
|| config.communicationType.equals("PG") || config.communicationType.equals("OP")))) {
128127
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Invalid communication type.");
129128
valid = false;
130-
return;
131129
}
132130

133131
if (config.pollRate <= 0) {
@@ -136,6 +134,19 @@ public void initialize() {
136134
getThing().getLabel());
137135
}
138136

137+
if (valid && (config.updateMode == null || !SimaticUpdateMode.validate(config.updateMode))) {
138+
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Invalid value update mode.");
139+
valid = false;
140+
}
141+
142+
if (!valid) {
143+
// updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
144+
logger.error("{} - Bridge configuration is invalid. Host/IP={},Rack={},Slot={},Comm={},Is200={},Mode={}",
145+
getThing().getLabel(), config.address, config.rack, config.slot, config.communicationType,
146+
config.isS7200, config.updateMode);
147+
return;
148+
}
149+
139150
Charset charset;
140151
if (config.charset == null || config.charset.isBlank()) {
141152
charset = Charset.defaultCharset();
@@ -149,19 +160,13 @@ public void initialize() {
149160

150161
logger.info("{} - Current charset {}", getThing().getLabel(), charset.name());
151162

152-
if (!valid) {
153-
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
154-
logger.error("{} - Bridge configuration is invalid. Host/IP={},Rack={},Slot={},Comm={},Is200={}",
155-
getThing().getLabel(), config.address, config.rack, config.slot, config.communicationType,
156-
config.isS7200);
157-
}
158-
159163
// S7-200 PLC
160164
if (config.isS7200) {
161-
connection = new SimaticTCP200(config.address, config.rack, config.slot, config.pollRate, charset);
165+
connection = new SimaticTCP200(config.address, config.rack, config.slot, config.pollRate, charset,
166+
SimaticUpdateMode.fromString(config.updateMode));
162167
} else {
163168
connection = new SimaticTCP(config.address, config.rack, config.slot, config.communicationType,
164-
config.pollRate, charset);
169+
config.pollRate, charset, SimaticUpdateMode.fromString(config.updateMode));
165170
}
166171

167172
// react on connection changes

org.openhab.binding.simatic/src/main/java/org/openhab/binding/simatic/internal/handler/simaticGenericHandler.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
*/
1313
package org.openhab.binding.simatic.internal.handler;
1414

15+
import java.nio.charset.Charset;
1516
import java.util.LinkedHashMap;
1617
import java.util.Map;
1718

1819
import org.eclipse.jdt.annotation.NonNullByDefault;
1920
import org.eclipse.jdt.annotation.Nullable;
2021
import org.openhab.binding.simatic.internal.simatic.SimaticChannel;
2122
import org.openhab.binding.simatic.internal.simatic.SimaticGenericDevice;
23+
import org.openhab.binding.simatic.internal.simatic.SimaticUpdateMode;
2224
import org.openhab.core.thing.Channel;
2325
import org.openhab.core.thing.ChannelUID;
2426
import org.openhab.core.thing.Thing;
@@ -71,8 +73,8 @@ public void initialize() {
7173
}
7274

7375
final SimaticChannel chConfig = channel.getConfiguration().as(SimaticChannel.class);
74-
chConfig.channelId = channelUID;
75-
chConfig.channelType = channelTypeUID;
76+
chConfig.setChannelId(channelUID);
77+
chConfig.setChannelType(channelTypeUID);
7678

7779
if (!chConfig.init(this)) {
7880
errors++;
@@ -218,6 +220,9 @@ public void setError(String message) {
218220
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, message);
219221
}
220222

223+
/**
224+
* Clear thing error if necessary
225+
*/
221226
public void clearError() {
222227
// no error
223228
if (getThing().getStatus() == ThingStatus.ONLINE) {
@@ -229,4 +234,30 @@ public void clearError() {
229234
updateStatus(ThingStatus.ONLINE);
230235
}
231236
}
237+
238+
/**
239+
* Get configured code page
240+
*
241+
* @return
242+
*/
243+
public Charset getCharset() {
244+
if (connection != null) {
245+
return connection.getCharset();
246+
}
247+
248+
return Charset.defaultCharset();
249+
}
250+
251+
/**
252+
* Get configured update mode
253+
*
254+
* @return
255+
*/
256+
public SimaticUpdateMode getUpdateMode() {
257+
if (connection != null) {
258+
return connection.getUpdateMode();
259+
}
260+
261+
return SimaticUpdateMode.OnChange;
262+
}
232263
}

0 commit comments

Comments
 (0)