Skip to content

Commit

Permalink
Changed type of vars for "reverted" para from int to boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
meju25 committed Jun 11, 2016
1 parent 41fb90c commit 70406f9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ public void handleCommand(ChannelUID channelUID, Command command) {
@Override
public void statusUpdateReceived(MySensorsStatusUpdateEvent event) {
MySensorsMessage msg = event.getData();

// logger.debug("updateRecieved: " + msg.getDebugInfo());
// Do we get an ACK?
if (msg.getAck() == 1) {
logger.debug("ACK received!");
logger.debug(String.format("ACK received! Node: %d, Child: %d", msg.nodeId, msg.childId));
mysCon.removeMySensorsOutboundMessage(msg);
}

Expand Down Expand Up @@ -200,7 +200,7 @@ private void answerITimeMessage(MySensorsMessage msg) {
logger.info("I_TIME request received from {}, answering...", msg.nodeId);

String time = Long.toString(System.currentTimeMillis() / 1000);
MySensorsMessage newMsg = new MySensorsMessage(msg.nodeId, msg.childId, MYSENSORS_MSG_TYPE_INTERNAL, 0, 0,
MySensorsMessage newMsg = new MySensorsMessage(msg.nodeId, msg.childId, MYSENSORS_MSG_TYPE_INTERNAL, 0, false,
MYSENSORS_SUBTYPE_I_TIME, time);
mysCon.addMySensorsOutboundMessage(newMsg);

Expand All @@ -214,7 +214,7 @@ private void answerITimeMessage(MySensorsMessage msg) {
private void answerIConfigMessage(MySensorsMessage msg) {
logger.info("I_CONFIG request received from {}, answering...", msg.nodeId);

MySensorsMessage newMsg = new MySensorsMessage(msg.nodeId, msg.childId, MYSENSORS_MSG_TYPE_INTERNAL, 0, 0,
MySensorsMessage newMsg = new MySensorsMessage(msg.nodeId, msg.childId, MYSENSORS_MSG_TYPE_INTERNAL, 0, false,
MYSENSORS_SUBTYPE_I_CONFIG, iConfig);
mysCon.addMySensorsOutboundMessage(newMsg);

Expand All @@ -228,7 +228,7 @@ private void answerIDRequest() {

int newId = getFreeId();
givenIds.add(newId);
MySensorsMessage newMsg = new MySensorsMessage(255, 255, 3, 0, 0, 4, newId + "");
MySensorsMessage newMsg = new MySensorsMessage(255, 255, 3, 0, false, 4, newId + "");
mysCon.addMySensorsOutboundMessage(newMsg);
logger.info("New Node in the MySensors network has requested an ID. ID is: {}", newId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,9 @@ public void handleCommand(ChannelUID channelUID, Command command) {
String msgPayload = "";
int subType = 0;
int int_requestack = 0;
int int_revertstate = 1;
if (requestAck) {
int_requestack = 1;
}
if (!revertState) {
int_revertstate = 0;
logger.debug("revert state false");
} else {
logger.debug("revert state true");
}
if (channelUID.getId().equals(CHANNEL_STATUS)) {

subType = MYSENSORS_SUBTYPE_V_STATUS;
Expand Down Expand Up @@ -190,7 +183,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}

MySensorsMessage newMsg = new MySensorsMessage(nodeId, childId, MYSENSORS_MSG_TYPE_SET, int_requestack,
int_revertstate, subType, msgPayload);
revertState, subType, msgPayload);

String oldPayload = oldMsgContent.get(subType);
if (oldPayload == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@ public void removeMySensorsOutboundMessage(MySensorsMessage msg) {
if (iterator != null) {
while (iterator.hasNext()) {
MySensorsMessage msgInQueue = iterator.next();
logger.debug("Msg in Queue: " + msgInQueue.getDebugInfo());
if (msgInQueue.getNodeId() == msg.getNodeId() && msgInQueue.getChildId() == msg.getChildId()
&& msgInQueue.getMsgType() == msg.getMsgType() && msgInQueue.getSubType() == msg.getSubType()
&& msgInQueue.getAck() == msg.getAck() && msgInQueue.getRevert() == msg.getRevert()
&& msgInQueue.getMsg().equals(msg.getMsg())) {
&& msgInQueue.getAck() == msg.getAck() && msgInQueue.getMsg().equals(msg.getMsg())) {
iterator.remove();
// logger.debug("Message removed: " + msg.getDebugInfo());
} else {
logger.debug("Message NOT removed");
logger.debug("Message NOT removed: " + msg.getDebugInfo());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MySensorsMessage {
public int childId = 0;
public int msgType = 0;
public int ack = 0;
public int revert = 1;
public boolean revert = true;
public int subType = 0;
public String msg = "";
public String oldMsg = "";
Expand All @@ -35,25 +35,24 @@ public MySensorsMessage() {

}

public MySensorsMessage(int nodeId, int childId, int msgType, int ack, int revert, int subType, String msg) {
public MySensorsMessage(int nodeId, int childId, int msgType, int ack, boolean revert, int subType, String msg) {
this.nodeId = nodeId;
this.childId = childId;
this.msgType = msgType;
this.ack = ack;
this.revert = revert;
this.subType = subType;
this.msg = msg;
this.printDebug();
}

public void printDebug() {
logger.debug("nodeId: " + this.nodeId);
logger.debug("childId: " + this.childId);
logger.debug("msgType: " + this.msgType);
logger.debug("ack: " + this.ack);
logger.debug("revert: " + this.revert);
logger.debug("subType: " + this.subType);
logger.debug("msg: " + this.msg);
logger.debug(String.format("nodeId: %d, childId: %d, msgType: %d, ack: %d, revert: %b, subType: %d ,msg: %s",
this.nodeId, this.childId, this.msgType, this.ack, this.revert, this.subType, this.msg));
}

public String getDebugInfo() {
return String.format("nodeId: %d, childId: %d, msgType: %d, ack: %d, revert: %b, subType: %d ,msg: %s",
this.nodeId, this.childId, this.msgType, this.ack, this.revert, this.subType, this.msg);
}

public int getNodeId() {
Expand Down Expand Up @@ -84,7 +83,7 @@ public int getAck() {
return ack;
}

public int getRevert() {
public boolean getRevert() {
return revert;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class MySensorsWriter implements MySensorsUpdateListener, Runnab
protected ExecutorService executor = Executors.newSingleThreadExecutor();
protected Future<?> future = null;

private static final MySensorsMessage I_VERSION_MESSAGE = new MySensorsMessage(0, 0, 3, 0, 0, 2, "");
private static final MySensorsMessage I_VERSION_MESSAGE = new MySensorsMessage(0, 0, 3, 0, false, 2, "");

protected int sendDelay = 0;

Expand Down Expand Up @@ -69,14 +69,14 @@ public void run() {
logger.warn("NO ACK from nodeId: " + msg.getNodeId());
if (msg.getOldMsg().isEmpty()) {
logger.debug("No old status know to revert to!");
} else if (msg.getRevert() == 1) {
} else if (msg.getRevert()) {
logger.debug("Reverting status!");
msg.setMsg(msg.getOldMsg());
MySensorsStatusUpdateEvent event = new MySensorsStatusUpdateEvent(msg);
for (MySensorsUpdateListener mySensorsEventListener : mysCon.updateListeners) {
mySensorsEventListener.statusUpdateReceived(event);
}
} else if (msg.getRevert() == 0) {
} else if (!msg.getRevert()) {
logger.debug("Not reverted due to configuration!");
}
continue;
Expand Down

0 comments on commit 70406f9

Please sign in to comment.