Search in sources :

Example 1 with APIMessage

use of org.openhab.binding.dscalarm.internal.protocol.APIMessage in project openhab1-addons by openhab.

the class DSCAlarmActiveBinding method dscAlarmEventRecieved.

/**
     * Receives incoming DSC Alarm events
     *
     * @param event
     */
@Override
public void dscAlarmEventRecieved(EventObject event) {
    DSCAlarmEvent dscAlarmEvent = (DSCAlarmEvent) event;
    APIMessage apiMessage = dscAlarmEvent.getAPIMessage();
    APICode apiCode = APICode.getAPICodeValue(apiMessage.getAPICode());
    String apiData = apiMessage.getAPIData();
    boolean suppressPanelMsg = false;
    int state = 0;
    setTimeStampState(apiMessage.getTimeStamp());
    switch(apiCode) {
        case CommandAcknowledge:
            /* 500 */
            dscAlarmItemUpdate.setConnected(true);
            if (apiData.equals("000")) {
                handleDSCAlarmEvent(DSCAlarmItemType.PANEL_CONNECTION, dscAlarmEvent, apiMessage);
            }
            if (suppressAcknowledgementMsgs) {
                suppressPanelMsg = true;
            }
            break;
        case SystemError:
            /* 502 */
            int errorCode = Integer.parseInt(apiData);
            if (errorCode == 23 || errorCode == 24) {
                for (int i = 1; i < 9; i++) {
                    updateItemByItemType(DSCAlarmItemType.PARTITION_ARM_MODE, i, 0, 0);
                }
            }
            handleDSCAlarmEvent(DSCAlarmItemType.PANEL_SYSTEM_ERROR, dscAlarmEvent, apiMessage);
            break;
        case KeypadLEDState:
        /* 510 */
        case KeypadLEDFlashState:
            /* 511 */
            keypadLEDStateEventHandler(event);
            break;
        case TimeDateBroadcast:
            /* 550 */
            updateItemByItemType(DSCAlarmItemType.PANEL_TIME_BROADCAST, 0, 0, 1);
            if (suppressAcknowledgementMsgs) {
                suppressPanelMsg = true;
            }
            handleDSCAlarmEvent(DSCAlarmItemType.PANEL_TIME, dscAlarmEvent, apiMessage);
            break;
        case PartitionReady:
        /* 650 */
        case PartitionNotReady:
        /* 651 */
        case PartitionReadyForceArming:
        /* 653 */
        case SystemArmingInProgress:
            /* 674 */
            handleDSCAlarmEvent(DSCAlarmItemType.PARTITION_STATUS, dscAlarmEvent, apiMessage);
            break;
        case PartitionArmed:
            /* 652 */
            updateItemByItemType(DSCAlarmItemType.PARTITION_ARMED, apiMessage.getPartition(), -1, 1);
            updateItemByItemType(DSCAlarmItemType.PARTITION_ENTRY_DELAY, apiMessage.getPartition(), -1, 0);
            updateItemByItemType(DSCAlarmItemType.PARTITION_EXIT_DELAY, apiMessage.getPartition(), -1, 0);
            setPartitionStatus(apiMessage.getPartition(), 0, apiMessage.getAPIName());
            setSystemErrorCode(0, "No Error");
            handleDSCAlarmEvent(DSCAlarmItemType.PARTITION_ARM_MODE, dscAlarmEvent, apiMessage);
            break;
        case PartitionDisarmed:
            /* 655 */
            updateItemByItemType(DSCAlarmItemType.PARTITION_ARMED, apiMessage.getPartition(), -1, 0);
            updateItemByItemType(DSCAlarmItemType.PARTITION_ENTRY_DELAY, apiMessage.getPartition(), -1, 0);
            updateItemByItemType(DSCAlarmItemType.PARTITION_EXIT_DELAY, apiMessage.getPartition(), -1, 0);
            updateItemByItemType(DSCAlarmItemType.PARTITION_IN_ALARM, apiMessage.getPartition(), -1, 0);
            setPartitionStatus(apiMessage.getPartition(), 0, apiMessage.getAPIName());
            setSystemErrorCode(0, "No Error");
            handleDSCAlarmEvent(DSCAlarmItemType.PARTITION_ARM_MODE, dscAlarmEvent, apiMessage);
            break;
        case PartitionInAlarm:
            /* 654 */
            updateItemByItemType(DSCAlarmItemType.PARTITION_IN_ALARM, apiMessage.getPartition(), -1, 1);
            handleDSCAlarmEvent(DSCAlarmItemType.PARTITION_STATUS, dscAlarmEvent, apiMessage);
            break;
        case ZoneAlarm:
            /* 601 */
            state = 1;
        case ZoneAlarmRestore:
            /* 602 */
            updateItemByItemType(DSCAlarmItemType.ZONE_IN_ALARM, apiMessage.getPartition(), apiMessage.getZone(), state);
            handleDSCAlarmEvent(DSCAlarmItemType.ZONE_ALARM_STATUS, dscAlarmEvent, apiMessage);
            break;
        case ZoneTamper:
            /* 603 */
            state = 1;
        case ZoneTamperRestore:
            /* 604 */
            updateItemByItemType(DSCAlarmItemType.ZONE_TAMPER, apiMessage.getPartition(), apiMessage.getZone(), state);
            handleDSCAlarmEvent(DSCAlarmItemType.ZONE_TAMPER_STATUS, dscAlarmEvent, apiMessage);
            break;
        case ZoneFault:
            /* 605 */
            state = 1;
        case ZoneFaultRestore:
            /* 606 */
            updateItemByItemType(DSCAlarmItemType.ZONE_FAULT, apiMessage.getPartition(), apiMessage.getZone(), state);
            handleDSCAlarmEvent(DSCAlarmItemType.ZONE_FAULT_STATUS, dscAlarmEvent, apiMessage);
            break;
        case ZoneOpen:
            /* 609 */
            state = 1;
        case ZoneRestored:
            /* 610 */
            updateItemByItemType(DSCAlarmItemType.ZONE_TRIPPED, apiMessage.getPartition(), apiMessage.getZone(), state);
            handleDSCAlarmEvent(DSCAlarmItemType.ZONE_GENERAL_STATUS, dscAlarmEvent, apiMessage);
            break;
        case FireKeyAlarm:
            /* 621 */
            state = 1;
        case FireKeyRestored:
            /* 622 */
            updateItemByItemType(DSCAlarmItemType.PANEL_FIRE_KEY_ALARM, apiMessage.getPartition(), apiMessage.getZone(), state);
            break;
        case PanicKeyAlarm:
            /* 625 */
            state = 1;
        case PanicKeyRestored:
            /* 626 */
            updateItemByItemType(DSCAlarmItemType.PANEL_PANIC_KEY_ALARM, apiMessage.getPartition(), apiMessage.getZone(), state);
            break;
        case AuxiliaryKeyAlarm:
            /* 625 */
            state = 1;
        case AuxiliaryKeyRestored:
            /* 626 */
            updateItemByItemType(DSCAlarmItemType.PANEL_AUX_KEY_ALARM, apiMessage.getPartition(), apiMessage.getZone(), state);
            break;
        case AuxiliaryInputAlarm:
            /* 625 */
            state = 1;
        case AuxiliaryInputAlarmRestored:
            /* 631 */
            updateItemByItemType(DSCAlarmItemType.PANEL_AUX_INPUT_ALARM, apiMessage.getPartition(), apiMessage.getZone(), state);
            break;
        case EntryDelayInProgress:
            /* 656 */
            updateItemByItemType(DSCAlarmItemType.PARTITION_ENTRY_DELAY, apiMessage.getPartition(), -1, 1);
            break;
        case ExitDelayInProgress:
            /* 656 */
            updateItemByItemType(DSCAlarmItemType.PARTITION_EXIT_DELAY, apiMessage.getPartition(), -1, 1);
            break;
        case FailureToArm:
            /* 672 */
            updateItemByItemType(DSCAlarmItemType.PARTITION_ARM_MODE, apiMessage.getPartition(), 0, 0);
            handleDSCAlarmEvent(DSCAlarmItemType.PARTITION_STATUS, dscAlarmEvent, apiMessage);
            break;
        case UserClosing:
        /* 700 */
        case SpecialClosing:
        /* 701 */
        case PartialClosing:
        /* 702 */
        case UserOpening:
        /* 750 */
        case SpecialOpening:
            /* 751 */
            handleDSCAlarmEvent(DSCAlarmItemType.PARTITION_OPENING_CLOSING_MODE, dscAlarmEvent, apiMessage);
            break;
        case TroubleLEDOn:
            /* 840 */
            handleDSCAlarmEvent(DSCAlarmItemType.PANEL_TROUBLE_LED, dscAlarmEvent, apiMessage);
            break;
        case TroubleLEDOff:
            /* 841 */
            updateItemByItemType(DSCAlarmItemType.PANEL_SERVICE_REQUIRED, 0, 0, 0);
            updateItemByItemType(DSCAlarmItemType.PANEL_AC_TROUBLE, 0, 0, 0);
            updateItemByItemType(DSCAlarmItemType.PANEL_TELEPHONE_TROUBLE, 0, 0, 0);
            updateItemByItemType(DSCAlarmItemType.PANEL_FTC_TROUBLE, 0, 0, 0);
            updateItemByItemType(DSCAlarmItemType.PANEL_ZONE_FAULT, 0, 0, 0);
            updateItemByItemType(DSCAlarmItemType.PANEL_ZONE_TAMPER, 0, 0, 0);
            updateItemByItemType(DSCAlarmItemType.PANEL_ZONE_LOW_BATTERY, 0, 0, 0);
            updateItemByItemType(DSCAlarmItemType.PANEL_TIME_LOSS, 0, 0, 0);
            handleDSCAlarmEvent(DSCAlarmItemType.PANEL_TROUBLE_LED, dscAlarmEvent, apiMessage);
            break;
        case PanelBatteryTrouble:
        /* 800 */
        case PanelACTrouble:
        /* 802 */
        case SystemBellTrouble:
        /* 806 */
        case TLMLine1Trouble:
        /* 810 */
        case TLMLine2Trouble:
        /* 812 */
        case FTCTrouble:
        /* 814 */
        case GeneralDeviceLowBattery:
        /* 821 */
        case WirelessKeyLowBatteryTrouble:
        /* 825 */
        case HandheldKeypadLowBatteryTrouble:
        /* 827 */
        case GeneralSystemTamper:
        /* 829 */
        case HomeAutomationTrouble:
        /* 831 */
        case KeybusFault:
            /* 896 */
            handleDSCAlarmEvent(DSCAlarmItemType.PANEL_TROUBLE_MESSAGE, dscAlarmEvent, apiMessage);
            break;
        case PanelBatteryTroubleRestore:
        /* 801 */
        case PanelACRestore:
        /* 803 */
        case SystemBellTroubleRestore:
        /* 807 */
        case TLMLine1TroubleRestore:
        /* 811 */
        case TLMLine2TroubleRestore:
        /* 813 */
        case GeneralDeviceLowBatteryRestore:
        /* 822 */
        case WirelessKeyLowBatteryTroubleRestore:
        /* 826 */
        case HandheldKeypadLowBatteryTroubleRestore:
        /* 828 */
        case GeneralSystemTamperRestore:
        /* 830 */
        case HomeAutomationTroubleRestore:
        /* 832 */
        case KeybusFaultRestore:
            /* 897 */
            updateItemByItemType(DSCAlarmItemType.PANEL_TROUBLE_MESSAGE, 0, 0, 0);
            break;
        case VerboseTroubleStatus:
            /* 849 */
            verboseTroubleStatusHandler(event);
            break;
        case CodeRequired:
            /* 900 */
            api.sendCommand(APICode.CodeSend);
            break;
        case LCDUpdate:
            /* 901 */
            handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_LCD_UPDATE, dscAlarmEvent, apiMessage);
            break;
        case LCDCursor:
            /* 902 */
            handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_LCD_CURSOR, dscAlarmEvent, apiMessage);
            break;
        case LEDStatus:
            /* 903 */
            int aData = Integer.parseInt(apiData.substring(0, 1));
            switch(aData) {
                case 1:
                    handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_READY_LED, dscAlarmEvent, apiMessage);
                    break;
                case 2:
                    handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_ARMED_LED, dscAlarmEvent, apiMessage);
                    break;
                case 3:
                    handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_MEMORY_LED, dscAlarmEvent, apiMessage);
                    break;
                case 4:
                    handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_BYPASS_LED, dscAlarmEvent, apiMessage);
                    break;
                case 5:
                    handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_TROUBLE_LED, dscAlarmEvent, apiMessage);
                    break;
                case 6:
                    handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_PROGRAM_LED, dscAlarmEvent, apiMessage);
                    break;
                case 7:
                    handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_FIRE_LED, dscAlarmEvent, apiMessage);
                    break;
                case 8:
                    handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_BACKLIGHT_LED, dscAlarmEvent, apiMessage);
                    break;
                case 9:
                    handleDSCAlarmEvent(DSCAlarmItemType.KEYPAD_AC_LED, dscAlarmEvent, apiMessage);
                    break;
            }
        default:
            break;
    }
    if (!suppressPanelMsg) {
        setPanelMessage(apiMessage.getAPIDescription());
    }
}
Also used : APICode(org.openhab.binding.dscalarm.internal.protocol.APICode) APIMessage(org.openhab.binding.dscalarm.internal.protocol.APIMessage)

Example 2 with APIMessage

use of org.openhab.binding.dscalarm.internal.protocol.APIMessage in project openhab1-addons by openhab.

the class DSCAlarmActiveBinding method handleDSCAlarmEvent.

/**
     * Handle incoming DSC Alarm events
     *
     * @param dscAlarmItemType
     * @param dscAlarmEvent
     * @param apiMessage
     */
private void handleDSCAlarmEvent(DSCAlarmItemType dscAlarmItemType, DSCAlarmEvent dscAlarmEvent, APIMessage apiMessage) {
    logger.debug("handleDSCAlarmEvent(): Event received! Looking for item: {}", dscAlarmItemType);
    DSCAlarmBindingConfig config = null;
    APIMessage.APIMessageType apiMessageType = apiMessage.getAPIMessageType();
    Item item = null;
    String itemName = "";
    int partitionId = apiMessage.getPartition();
    int zoneId = apiMessage.getZone();
    if (dscAlarmItemType != null) {
        for (DSCAlarmBindingProvider prov : providers) {
            for (String iName : prov.getItemNames()) {
                config = prov.getDSCAlarmBindingConfig(iName);
                if (config != null) {
                    switch(apiMessageType) {
                        case PANEL_EVENT:
                            if (dscAlarmItemType == config.getDSCAlarmItemType()) {
                                itemName = iName;
                            }
                            break;
                        case PARTITION_EVENT:
                            if (partitionId == config.getPartitionId() && dscAlarmItemType == config.getDSCAlarmItemType()) {
                                itemName = iName;
                            }
                            break;
                        case ZONE_EVENT:
                            if (zoneId == config.getZoneId() && dscAlarmItemType == config.getDSCAlarmItemType()) {
                                itemName = iName;
                            }
                            break;
                        case KEYPAD_EVENT:
                            if (dscAlarmItemType == config.getDSCAlarmItemType()) {
                                itemName = iName;
                            }
                            break;
                        default:
                            break;
                    }
                }
                if (StringUtils.isNotEmpty(itemName)) {
                    item = prov.getItem(itemName);
                    dscAlarmItemUpdate.updateDeviceItem(item, config, eventPublisher, dscAlarmEvent, 0, "");
                    pollTimeStart = 0;
                    return;
                }
            }
        }
    }
}
Also used : Item(org.openhab.core.items.Item) DSCAlarmBindingProvider(org.openhab.binding.dscalarm.DSCAlarmBindingProvider) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig) APIMessage(org.openhab.binding.dscalarm.internal.protocol.APIMessage)

Example 3 with APIMessage

use of org.openhab.binding.dscalarm.internal.protocol.APIMessage in project openhab1-addons by openhab.

the class DSCAlarmActiveBinding method keypadLEDStateEventHandler.

/**
     * Handle Keypad LED events for the EyezOn Envisalink 3/2DS DSC Alarm Interface
     *
     * @param event
     */
private void keypadLEDStateEventHandler(EventObject event) {
    DSCAlarmEvent dscAlarmEvent = (DSCAlarmEvent) event;
    APIMessage apiMessage = dscAlarmEvent.getAPIMessage();
    DSCAlarmItemType[] dscAlarmItemTypes = { DSCAlarmItemType.KEYPAD_READY_LED, DSCAlarmItemType.KEYPAD_ARMED_LED, DSCAlarmItemType.KEYPAD_MEMORY_LED, DSCAlarmItemType.KEYPAD_BYPASS_LED, DSCAlarmItemType.KEYPAD_TROUBLE_LED, DSCAlarmItemType.KEYPAD_PROGRAM_LED, DSCAlarmItemType.KEYPAD_FIRE_LED, DSCAlarmItemType.KEYPAD_BACKLIGHT_LED };
    String itemName;
    APICode apiCode = APICode.getAPICodeValue(apiMessage.getAPICode());
    int bitField = Integer.decode("0x" + apiMessage.getAPIData());
    int[] masks = { 1, 2, 4, 8, 16, 32, 64, 128 };
    int[] bits = new int[8];
    for (int i = 0; i < 8; i++) {
        bits[i] = bitField & masks[i];
        itemName = getItemName(dscAlarmItemTypes[i], 0, 0);
        if (StringUtils.isNotEmpty(itemName)) {
            switch(apiCode) {
                case KeypadLEDState:
                    /* 510 */
                    updateItem(itemName, bits[i] != 0 ? 1 : 0, "");
                    break;
                case KeypadLEDFlashState:
                    /* 511 */
                    if (bits[i] != 0) {
                        updateItem(itemName, 2, "");
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : APICode(org.openhab.binding.dscalarm.internal.protocol.APICode) APIMessage(org.openhab.binding.dscalarm.internal.protocol.APIMessage)

Example 4 with APIMessage

use of org.openhab.binding.dscalarm.internal.protocol.APIMessage in project openhab1-addons by openhab.

the class SerialConnector method handleIncomingMessage.

/**
     * Handles an incoming message
     * 
     * @param incomingMessage
     */
public synchronized void handleIncomingMessage(String incomingMessage) {
    APIMessage Message = new APIMessage(incomingMessage);
    logger.debug("handleIncomingMessage(): Message received: {} - {}", incomingMessage, Message.toString());
    DSCAlarmEvent event = new DSCAlarmEvent(this);
    event.dscAlarmEventMessage(Message);
    // send message to event listeners
    try {
        Iterator<DSCAlarmEventListener> iterator = _listeners.iterator();
        while (iterator.hasNext()) {
            ((DSCAlarmEventListener) iterator.next()).dscAlarmEventRecieved(event);
        }
    } catch (Exception e) {
        logger.error("handleIncomingMessage(): Event listener invoking error", e);
    }
}
Also used : DSCAlarmEventListener(org.openhab.binding.dscalarm.internal.DSCAlarmEventListener) APIMessage(org.openhab.binding.dscalarm.internal.protocol.APIMessage) DSCAlarmEvent(org.openhab.binding.dscalarm.internal.DSCAlarmEvent) TooManyListenersException(java.util.TooManyListenersException) PortInUseException(gnu.io.PortInUseException) UnsupportedCommOperationException(gnu.io.UnsupportedCommOperationException) IOException(java.io.IOException) NoSuchPortException(gnu.io.NoSuchPortException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with APIMessage

use of org.openhab.binding.dscalarm.internal.protocol.APIMessage in project openhab1-addons by openhab.

the class TCPConnector method handleIncomingMessage.

/**
     * Handles an incoming message
     *
     * @param incomingMessage
     */
public synchronized void handleIncomingMessage(String incomingMessage) {
    APIMessage Message = new APIMessage(incomingMessage);
    logger.debug("handleIncomingMessage(): Message received: {} - {}", incomingMessage, Message.toString());
    DSCAlarmEvent event = new DSCAlarmEvent(this);
    event.dscAlarmEventMessage(Message);
    // send message to event listeners
    try {
        Iterator<DSCAlarmEventListener> iterator = _listeners.iterator();
        while (iterator.hasNext()) {
            ((DSCAlarmEventListener) iterator.next()).dscAlarmEventRecieved(event);
        }
    } catch (Exception e) {
        logger.error("handleIncomingMessage(): Event listener invoking error", e);
    }
}
Also used : DSCAlarmEventListener(org.openhab.binding.dscalarm.internal.DSCAlarmEventListener) APIMessage(org.openhab.binding.dscalarm.internal.protocol.APIMessage) DSCAlarmEvent(org.openhab.binding.dscalarm.internal.DSCAlarmEvent) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SocketException(java.net.SocketException)

Aggregations

APIMessage (org.openhab.binding.dscalarm.internal.protocol.APIMessage)10 StringType (org.openhab.core.library.types.StringType)4 DecimalType (org.openhab.core.library.types.DecimalType)3 IOException (java.io.IOException)2 DSCAlarmEvent (org.openhab.binding.dscalarm.internal.DSCAlarmEvent)2 DSCAlarmEventListener (org.openhab.binding.dscalarm.internal.DSCAlarmEventListener)2 APICode (org.openhab.binding.dscalarm.internal.protocol.APICode)2 NumberItem (org.openhab.core.library.items.NumberItem)2 StringItem (org.openhab.core.library.items.StringItem)2 NoSuchPortException (gnu.io.NoSuchPortException)1 PortInUseException (gnu.io.PortInUseException)1 UnsupportedCommOperationException (gnu.io.UnsupportedCommOperationException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 TooManyListenersException (java.util.TooManyListenersException)1 DSCAlarmBindingConfig (org.openhab.binding.dscalarm.DSCAlarmBindingConfig)1 DSCAlarmBindingProvider (org.openhab.binding.dscalarm.DSCAlarmBindingProvider)1 Item (org.openhab.core.items.Item)1 DateTimeType (org.openhab.core.library.types.DateTimeType)1