Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[insteon] improved the handling of duplicate broadcast group messages #8001

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.binding.insteon.internal.device;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.insteon.internal.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -104,16 +105,18 @@ enum State {
private State state = State.EXPECT_BCAST;
private long lastUpdated = 0;
private boolean publish = false;
private byte lastCmd1 = 0;

/**
* Advance the state machine and determine if update is genuine (no duplicate)
*
* @param a the group message (action) that was received
* @param address the address of the device that this state machine belongs to
* @param group the group that this state machine belongs to
* @param cmd1 cmd1 from the message received
* @return true if the group message is not a duplicate
*/
public boolean action(GroupMessage a, InsteonAddress address, int group) {
public boolean action(GroupMessage a, InsteonAddress address, int group, byte cmd1) {
publish = false;
switch (state) {
case EXPECT_BCAST:
Expand All @@ -132,7 +135,15 @@ public boolean action(GroupMessage a, InsteonAddress address, int group) {
case EXPECT_CLEAN:
switch (a) {
case BCAST:
publish = false;
if (lastCmd1 == cmd1) {
publish = false;
} else {
if (logger.isDebugEnabled()) {
logger.debug("{} group {} cmd1 {} is not a dup BCAST, last cmd1 {}", address, group,
Utils.getHexByte(cmd1), Utils.getHexByte(lastCmd1));
}
publish = true;
}
break; // missed(CLEAN, SUCCESS) or dup BCAST
case CLEAN:
publish = false;
Expand Down Expand Up @@ -169,6 +180,7 @@ public boolean action(GroupMessage a, InsteonAddress address, int group) {
break;
}

lastCmd1 = cmd1;
lastUpdated = System.currentTimeMillis();
logger.debug("{} group {} state: {} --{}--> {}, publish: {}", address, group, oldState, a, state, publish);
return (publish);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,10 @@ private void addFeature(String name, DeviceFeature f) {
*
* @param group the insteon group of the broadcast message
* @param a the type of group message came in (action etc)
* @param cmd1 cmd1 from the message received
* @return true if this is message is NOT a duplicate
*/
public boolean getGroupState(int group, GroupMessage a) {
public boolean getGroupState(int group, GroupMessage a, byte cmd1) {
GroupMessageStateMachine m = groupState.get(group);
if (m == null) {
m = new GroupMessageStateMachine();
Expand All @@ -568,7 +569,7 @@ public boolean getGroupState(int group, GroupMessage a) {
}

logger.trace("{} updating group {} state to {}", address, group, a);
return (m.action(a, address, group));
return (m.action(a, address, group, cmd1));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ protected boolean isDuplicate(Msg msg) {
// from the original broadcaster, with which the device
// confirms that it got all cleanup replies successfully.
GroupMessage gm = (cmd1 == 0x06) ? GroupMessage.SUCCESS : GroupMessage.BCAST;
isDuplicate = !feature.getDevice().getGroupState(group, gm);
isDuplicate = !feature.getDevice().getGroupState(group, gm, cmd1);
} else if (t == MsgType.ALL_LINK_CLEANUP) {
// the cleanup messages are direct messages, so the
// group # is not in the toAddress, but in cmd2
int group = msg.getByte("command2") & 0xff;
isDuplicate = !feature.getDevice().getGroupState(group, GroupMessage.CLEAN);
isDuplicate = !feature.getDevice().getGroupState(group, GroupMessage.CLEAN, (byte) 0);
}
} catch (IllegalArgumentException e) {
logger.warn("cannot parse msg: {}", msg, e);
Expand Down