Search in sources :

Example 6 with AckMsg

use of org.openhab.binding.maxcul.internal.messages.AckMsg in project openhab1-addons by openhab.

the class TimeUpdateRequestSequence method runSequencer.

@Override
public void runSequencer(BaseMsg msg) {
    pktLostCount = 0;
    switch(state) {
        case RESPOND_TO_REQUEST:
            if (BaseMsg.getMsgType(msg.rawMsg) == MaxCulMsgType.TIME_INFO) {
                TimeInfoMsg timeMsg = new TimeInfoMsg(msg.rawMsg);
                if (isValidDeviation(timeMsg.getTimeInfo(), new GregorianCalendar(), TIME_TOLERANCE)) {
                    messageHandler.sendAck(msg);
                    state = TimeUpdateRequestState.FINISHED;
                } else {
                    messageHandler.sendTimeInfo(msg.srcAddrStr, tzStr, this);
                    state = TimeUpdateRequestState.HANDLE_RESPONSE;
                }
            } else {
                state = TimeUpdateRequestState.FINISHED;
                logger.debug("Got invalid message type for Time Update Sequence");
            }
            break;
        case HANDLE_RESPONSE:
            /* check for ACK */
            if (msg.msgType == MaxCulMsgType.ACK) {
                AckMsg ack = new AckMsg(msg.rawMsg);
                if (ack.getIsNack()) {
                    logger.error("TIME_INFO was nacked. Ending sequence");
                    state = TimeUpdateRequestState.FINISHED;
                } else {
                    state = TimeUpdateRequestState.FINISHED;
                }
            }
            state = TimeUpdateRequestState.FINISHED;
            break;
        case FINISHED:
            /* do nothing */
            break;
        default:
            logger.error("Invalid state for PairingInitialisation Message Sequence!");
            break;
    }
}
Also used : TimeInfoMsg(org.openhab.binding.maxcul.internal.messages.TimeInfoMsg) AckMsg(org.openhab.binding.maxcul.internal.messages.AckMsg) GregorianCalendar(java.util.GregorianCalendar)

Aggregations

AckMsg (org.openhab.binding.maxcul.internal.messages.AckMsg)6 BaseMsg (org.openhab.binding.maxcul.internal.messages.BaseMsg)2 PairPingMsg (org.openhab.binding.maxcul.internal.messages.PairPingMsg)2 TimeInfoMsg (org.openhab.binding.maxcul.internal.messages.TimeInfoMsg)2 GregorianCalendar (java.util.GregorianCalendar)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 MaxCulBindingProvider (org.openhab.binding.maxcul.MaxCulBindingProvider)1 MaxCulBindingConfig (org.openhab.binding.maxcul.internal.MaxCulBindingConfig)1 MaxCulMsgType (org.openhab.binding.maxcul.internal.messages.MaxCulMsgType)1 PairPongMsg (org.openhab.binding.maxcul.internal.messages.PairPongMsg)1 SetGroupIdMsg (org.openhab.binding.maxcul.internal.messages.SetGroupIdMsg)1 SetTemperatureMsg (org.openhab.binding.maxcul.internal.messages.SetTemperatureMsg)1 ThermostatStateMsg (org.openhab.binding.maxcul.internal.messages.ThermostatStateMsg)1 WakeupMsg (org.openhab.binding.maxcul.internal.messages.WakeupMsg)1 WallThermostatControlMsg (org.openhab.binding.maxcul.internal.messages.WallThermostatControlMsg)1 WallThermostatStateMsg (org.openhab.binding.maxcul.internal.messages.WallThermostatStateMsg)1