Search in sources :

Example 1 with APICode

use of org.openhab.binding.dscalarm.internal.protocol.APICode 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 APICode

use of org.openhab.binding.dscalarm.internal.protocol.APICode 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)

Aggregations

APICode (org.openhab.binding.dscalarm.internal.protocol.APICode)2 APIMessage (org.openhab.binding.dscalarm.internal.protocol.APIMessage)2