Skip to content

Commit

Permalink
Allow set rollershutter position
Browse files Browse the repository at this point in the history
  • Loading branch information
docbender committed Jan 11, 2021
1 parent 4c44135 commit 620795b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public class SimaticChannel {
final private static Pattern dimmerAddressPattern = Pattern
.compile("^(([IQAEM]B)(\\d+))$|^(DB(\\d+)\\.DBB(\\d+))$");
final private static Pattern colorAddressPattern = Pattern.compile("^(([IQAEM]D)(\\d+))$|^(DB(\\d+)\\.DBD(\\d+))$");
final private static Pattern rollershutterAddressPattern = Pattern
.compile("^(([IQAEM]B)(\\d+))$|^(DB(\\d+)\\.DBB(\\d+))$");
final private static Pattern rollershutterStateAddressPattern = Pattern
.compile("^(([IQAEM]B)(\\d+))$|^(DB(\\d+)\\.DB(B)(\\d+))$");
final private static Pattern rollershutterCommandAddressPattern = Pattern
.compile("^(([IQAEM][BW])(\\d+))$|^(DB(\\d+)\\.DB([BW])(\\d+))$");

@Override
public String toString() {
Expand Down Expand Up @@ -100,7 +102,7 @@ public boolean init(SimaticGenericHandler handler) {
return false;
}

if (commandAddress != null && (commandAddressPlc = checkAddress(commandAddress)) == null) {
if (commandAddress != null && (commandAddressPlc = checkAddress(commandAddress, true)) == null) {
return false;
}

Expand All @@ -122,6 +124,17 @@ public void clear() {
* @return
*/
public @Nullable SimaticPLCAddress checkAddress(String address) {
return checkAddress(address, false);
}

/**
* Check string address obtained from configuration
*
* @param address Item address in Simatic syntax
* @param useCommandPattern Use command pattern if exist
* @return
*/
public @Nullable SimaticPLCAddress checkAddress(String address, boolean useCommandPattern) {
final Matcher matcher;
switch (channelType.getId()) {
case SimaticBindingConstants.CHANNEL_NUMBER:
Expand Down Expand Up @@ -246,16 +259,26 @@ public void clear() {
return new SimaticPLCAddress(matcher.group(2), Integer.parseInt(matcher.group(3)));
}
case SimaticBindingConstants.CHANNEL_ROLLERSHUTTER:
matcher = rollershutterAddressPattern.matcher(address);
if (useCommandPattern) {
matcher = rollershutterCommandAddressPattern.matcher(address);
} else {
matcher = rollershutterStateAddressPattern.matcher(address);
}
if (!matcher.matches()) {
error = String.format(
"Unsupported address '%s' for typeID=%s. Supported types BYTE. Address example MB100",
address, channelType.getId());
if (useCommandPattern) {
error = String.format(
"Unsupported address '%s' for typeID=%s. Supported types BYTE, WORD. Address example MB100",
address, channelType.getId());
} else {
error = String.format(
"Unsupported address '%s' for typeID=%s. Supported types BYTE. Address example MB100",
address, channelType.getId());
}
return null;
}
if (matcher.group(1) == null) {
return new SimaticPLCAddress(Integer.parseInt(matcher.group(5)), "B",
Integer.parseInt(matcher.group(6)));
return new SimaticPLCAddress(Integer.parseInt(matcher.group(5)), matcher.group(6),
Integer.parseInt(matcher.group(7)));
} else {
return new SimaticPLCAddress(matcher.group(2), Integer.parseInt(matcher.group(3)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@
<channel-type id="chRollershutter">
<item-type>Rollershutter</item-type>
<label>Rollershutter</label>
<description>Simatic data type is Byte. Status Byte for position (0-100%), command Byte for Stop/Up/Down -
2-Stop,4-Up,8-Down</description>
<description><![CDATA[
Simatic status data type is Byte for position (0-100%). Simatic command data types are Byte or Word.<br/>
Byte for Stop/Up/Down (2-Stop,4-Up,8-Down)<br/>
Word first Byte for Move/Stop/Up/Down (1-Move,2-Stop,4-Up,8-Down) and second Byte for target position (0-100%)]]>
</description>
<config-description>
<parameter name="stateAddress" type="text">
<label>State address</label>
Expand Down

0 comments on commit 620795b

Please sign in to comment.