use of org.openhab.binding.maxcul.internal.messages.BaseMsg in project openhab1-addons by openhab.
the class MaxCulMsgHandler method dataReceived.
@Override
public void dataReceived(String data) {
logger.debug("MaxCulSender Received " + data);
if (data.startsWith("Z")) {
if (listenMode) {
listenModeHandler(data);
return;
}
/* Check message is destined for us */
if (BaseMsg.isForUs(data, srcAddr)) {
boolean passToBinding = true;
/* Handle Internal Messages */
MaxCulMsgType msgType = BaseMsg.getMsgType(data);
if (msgType == MaxCulMsgType.ACK) {
passToBinding = false;
AckMsg msg = new AckMsg(data);
if (pendingAckQueue.containsKey(msg.msgCount) && msg.dstAddrStr.compareTo(srcAddr) == 0) {
SenderQueueItem qi = pendingAckQueue.remove(msg.msgCount);
/* verify ACK */
if ((qi.msg.dstAddrStr.equalsIgnoreCase(msg.srcAddrStr)) && (qi.msg.srcAddrStr.equalsIgnoreCase(msg.dstAddrStr))) {
if (msg.getIsNack()) {
/* NAK'd! */
// TODO resend?
logger.error("Message was NAK'd, packet lost");
} else {
logger.debug("Message " + msg.msgCount + " ACK'd ok!");
}
}
} else {
logger.info("Got ACK for message " + msg.msgCount + " but it wasn't in the queue");
}
}
if (sequenceRegister.containsKey(new BaseMsg(data).msgCount)) {
passToBinding = false;
/*
* message found in sequence register, so it will be handled
* by the sequence
*/
BaseMsg bMsg = new BaseMsg(data);
logger.debug("Message " + bMsg.msgCount + " is part of sequence. Running next step in sequence.");
sequenceRegister.get(bMsg.msgCount).runSequencer(bMsg);
sequenceRegister.remove(bMsg.msgCount);
}
if (passToBinding) {
/* pass data to binding for processing */
this.mcbmp.maxCulMsgReceived(data, false);
}
} else if (BaseMsg.isForUs(data, "000000")) {
switch(BaseMsg.getMsgType(data)) {
case PAIR_PING:
case WALL_THERMOSTAT_CONTROL:
case THERMOSTAT_STATE:
case WALL_THERMOSTAT_STATE:
this.mcbmp.maxCulMsgReceived(data, true);
break;
default:
/* TODO handle other broadcast */
logger.debug("Unhandled broadcast message of type " + BaseMsg.getMsgType(data).toString());
break;
}
} else {
// Associated devices send messages that tell of their status to
// the associated
// device. We need to spy on devices we know about to extract
// useful data
boolean passToBinding = false;
BaseMsg bMsg = new BaseMsg(data);
for (MaxCulBindingProvider provider : providers) {
// look up source device configs
List<MaxCulBindingConfig> configs = provider.getConfigsForRadioAddr(bMsg.srcAddrStr);
if (!configs.isEmpty()) {
// get asssociated devices with source device
String serialNum = configs.get(0).getSerialNumber();
HashSet<MaxCulBindingConfig> assocDevs = provider.getAssociations(serialNum);
if (!assocDevs.isEmpty()) {
// message dest
for (MaxCulBindingConfig device : assocDevs) {
if (device.getDevAddr().equalsIgnoreCase(bMsg.dstAddrStr)) {
passToBinding = true;
break;
}
}
}
}
}
if (passToBinding && (BaseMsg.getMsgType(data) != MaxCulMsgType.PAIR_PING && BaseMsg.getMsgType(data) != MaxCulMsgType.ACK)) {
/*
* pass data to binding for processing - pretend it is
* broadcast so as not to ACK
*/
this.mcbmp.maxCulMsgReceived(data, true);
}
}
}
}
use of org.openhab.binding.maxcul.internal.messages.BaseMsg in project openhab1-addons by openhab.
the class MaxCulMsgHandler method listenModeHandler.
private void listenModeHandler(String data) {
switch(BaseMsg.getMsgType(data)) {
case WALL_THERMOSTAT_CONTROL:
new WallThermostatControlMsg(data).printMessage();
break;
case TIME_INFO:
new TimeInfoMsg(data).printMessage();
break;
case SET_TEMPERATURE:
new SetTemperatureMsg(data).printMessage();
break;
case ACK:
new AckMsg(data).printMessage();
break;
case PAIR_PING:
new PairPingMsg(data).printMessage();
break;
case PAIR_PONG:
new PairPongMsg(data).printMessage();
break;
case THERMOSTAT_STATE:
new ThermostatStateMsg(data).printMessage();
break;
case SET_GROUP_ID:
new SetGroupIdMsg(data).printMessage();
break;
case WAKEUP:
new WakeupMsg(data).printMessage();
break;
case WALL_THERMOSTAT_STATE:
new WallThermostatStateMsg(data).printMessage();
break;
case ADD_LINK_PARTNER:
case CONFIG_TEMPERATURES:
case CONFIG_VALVE:
case CONFIG_WEEK_PROFILE:
case PUSH_BUTTON_STATE:
case REMOVE_GROUP_ID:
case REMOVE_LINK_PARTNER:
case RESET:
case SET_COMFORT_TEMPERATURE:
case SET_DISPLAY_ACTUAL_TEMP:
case SET_ECO_TEMPERATURE:
case SHUTTER_CONTACT_STATE:
case UNKNOWN:
default:
BaseMsg baseMsg = new BaseMsg(data);
baseMsg.printMessage();
break;
}
}
Aggregations