Search in sources :

Example 1 with BaseMsg

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);
            }
        }
    }
}
Also used : BaseMsg(org.openhab.binding.maxcul.internal.messages.BaseMsg) AckMsg(org.openhab.binding.maxcul.internal.messages.AckMsg) MaxCulBindingProvider(org.openhab.binding.maxcul.MaxCulBindingProvider) LinkedList(java.util.LinkedList) List(java.util.List) MaxCulMsgType(org.openhab.binding.maxcul.internal.messages.MaxCulMsgType) HashSet(java.util.HashSet)

Example 2 with BaseMsg

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;
    }
}
Also used : WallThermostatStateMsg(org.openhab.binding.maxcul.internal.messages.WallThermostatStateMsg) PairPongMsg(org.openhab.binding.maxcul.internal.messages.PairPongMsg) PairPingMsg(org.openhab.binding.maxcul.internal.messages.PairPingMsg) BaseMsg(org.openhab.binding.maxcul.internal.messages.BaseMsg) SetTemperatureMsg(org.openhab.binding.maxcul.internal.messages.SetTemperatureMsg) ThermostatStateMsg(org.openhab.binding.maxcul.internal.messages.ThermostatStateMsg) WallThermostatStateMsg(org.openhab.binding.maxcul.internal.messages.WallThermostatStateMsg) TimeInfoMsg(org.openhab.binding.maxcul.internal.messages.TimeInfoMsg) AckMsg(org.openhab.binding.maxcul.internal.messages.AckMsg) WallThermostatControlMsg(org.openhab.binding.maxcul.internal.messages.WallThermostatControlMsg) SetGroupIdMsg(org.openhab.binding.maxcul.internal.messages.SetGroupIdMsg) WakeupMsg(org.openhab.binding.maxcul.internal.messages.WakeupMsg)

Aggregations

AckMsg (org.openhab.binding.maxcul.internal.messages.AckMsg)2 BaseMsg (org.openhab.binding.maxcul.internal.messages.BaseMsg)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 MaxCulBindingProvider (org.openhab.binding.maxcul.MaxCulBindingProvider)1 MaxCulMsgType (org.openhab.binding.maxcul.internal.messages.MaxCulMsgType)1 PairPingMsg (org.openhab.binding.maxcul.internal.messages.PairPingMsg)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 TimeInfoMsg (org.openhab.binding.maxcul.internal.messages.TimeInfoMsg)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