use of org.openhab.binding.maxcul.internal.MaxCulBindingConfig in project openhab1-addons by openhab.
the class PairingInitialisationSequence method runSequencer.
@Override
public void runSequencer(BaseMsg msg) {
/*
* This sequence is taken from observations of activity between the MAX!
* Cube and a wall thermostat and refined using some experimentation :)
*/
if (state != PairingInitialisationState.RETX_WAKEUP_ACK) {
// reset counter - ack received
pktLostCount = 0;
}
logger.debug("Sequence State: " + state);
switch(state) {
case INITIAL_PING:
/* get device type */
PairPingMsg ppMsg = new PairPingMsg(msg.rawMsg);
this.deviceType = MaxCulDevice.getDeviceTypeFromInt(ppMsg.type);
/* Send PONG - assumes PING is checked */
logger.debug("Sending PONG");
this.devAddr = msg.srcAddrStr;
messageHandler.sendPairPong(devAddr, this);
state = PairingInitialisationState.PONG_ACKED;
break;
case PONG_ACKED:
if (msg.msgType == MaxCulMsgType.ACK) {
AckMsg ack = new AckMsg(msg.rawMsg);
if (!ack.getIsNack()) {
if (this.deviceType == MaxCulDevice.PUSH_BUTTON) {
/* for a push button we're done now */
state = PairingInitialisationState.FINISHED;
} else {
/* send group id information */
logger.debug("Sending GROUP_ID");
messageHandler.sendSetGroupId(devAddr, group_id, this);
state = PairingInitialisationState.GROUP_ID_ACKED;
}
} else {
logger.error("PAIR_PONG was nacked. Ending sequence");
state = PairingInitialisationState.FINISHED;
}
} else {
logger.error("Received " + msg.msgType + " when expecting ACK");
}
break;
case GROUP_ID_ACKED:
if (msg.msgType == MaxCulMsgType.ACK) {
AckMsg ack = new AckMsg(msg.rawMsg);
if (!ack.getIsNack() && (this.deviceType == MaxCulDevice.RADIATOR_THERMOSTAT || this.deviceType == MaxCulDevice.WALL_THERMOSTAT || this.deviceType == MaxCulDevice.RADIATOR_THERMOSTAT_PLUS)) {
// send temps for comfort/eco etc
messageHandler.sendConfigTemperatures(devAddr, this, config.getComfortTemp(), config.getEcoTemp(), config.getMaxTemp(), config.getMinTemp(), config.getMeasurementOffset(), config.getWindowOpenTemperature(), config.getWindowOpenDuration());
state = PairingInitialisationState.CONFIG_TEMPS_ACKED;
} else {
logger.error("SET_GROUP_ID was nacked. Ending sequence");
state = PairingInitialisationState.FINISHED;
}
} else {
logger.error("Received " + msg.msgType + " when expecting ACK");
}
break;
case CONFIG_TEMPS_ACKED:
if (msg.msgType == MaxCulMsgType.ACK) {
AckMsg ack = new AckMsg(msg.rawMsg);
if (!ack.getIsNack()) {
/*
* associate device with us so we get updates - we pretend
* to be the MAX! Cube
*/
messageHandler.sendAddLinkPartner(devAddr, this, msg.dstAddrStr, MaxCulDevice.CUBE);
/*
* if there are more associations to come then set up
* iterator and goto state to transmit more associations
*/
if (associations != null && associations.isEmpty() == false) {
assocIter = associations.iterator();
state = PairingInitialisationState.SENDING_ASSOCIATIONS;
} else {
logger.debug("No user configured associations");
state = PairingInitialisationState.SENDING_ASSOCIATIONS_ACKED;
}
} else {
logger.error("CONFIG_TEMPERATURES was nacked. Ending sequence");
state = PairingInitialisationState.FINISHED;
}
} else {
logger.error("Received " + msg.msgType + " when expecting ACK");
}
break;
case SENDING_ASSOCIATIONS:
if (msg.msgType == MaxCulMsgType.ACK) {
AckMsg ack = new AckMsg(msg.rawMsg);
if (!ack.getIsNack()) {
if (assocIter.hasNext()) /*
* this should always be true, but
* good to check
*/
{
MaxCulBindingConfig partnerCfg = assocIter.next();
messageHandler.sendAddLinkPartner(this.devAddr, this, partnerCfg.getDevAddr(), partnerCfg.getDeviceType());
/*
* if it's the last association message then wait for
* last ACK
*/
if (assocIter.hasNext()) {
state = PairingInitialisationState.SENDING_ASSOCIATIONS;
} else {
state = PairingInitialisationState.SENDING_ASSOCIATIONS_ACKED;
}
} else {
// TODO NOTE: if further states are added then ensure
// you go to the right state. I.e. when all associations
// are done
state = PairingInitialisationState.FINISHED;
}
} else {
logger.error("SENDING_ASSOCIATIONS was nacked. Ending sequence");
state = PairingInitialisationState.FINISHED;
}
} else {
logger.error("Received " + msg.msgType + " when expecting ACK");
}
break;
case SENDING_ASSOCIATIONS_ACKED:
state = PairingInitialisationState.FINISHED;
break;
case SENDING_WEEK_PROFILE:
// TODO implement this - but where to get a week profile from.
// Meaningless at the moment!
state = PairingInitialisationState.FINISHED;
break;
case FINISHED:
/* done, do nothing */
break;
case RETX_WAKEUP_ACK:
/* here are waiting for an ACK after sending a wakeup message */
if (msg.msgType == MaxCulMsgType.ACK) {
AckMsg ack = new AckMsg(msg.rawMsg);
if (!ack.getIsNack()) {
logger.debug("Attempt retransmission - resuming");
this.useFast = true;
messageHandler.sendMessage(reTxMsg);
// resume back to previous state
state = reTxState;
} else {
logger.error("WAKEUP for ReTx was nacked. Ending sequence");
state = PairingInitialisationState.FINISHED;
}
} else {
logger.error("Received " + msg.msgType + " when expecting ACK");
}
break;
default:
logger.error("Invalid state for PairingInitialisation Message Sequence!");
break;
}
}
Aggregations