Search in sources :

Example 1 with LcnAddrMod

use of org.openhab.binding.lcn.common.LcnAddrMod in project openhab1-addons by openhab.

the class ModAck method tryParseInput.

/**
     * Tries to parse the given input received from LCN-PCHK.
     * 
     * @param input the input
     * @return list of {@link ModAck} (might be empty, but not null}
     */
static Collection<Input> tryParseInput(String input) {
    LinkedList<Input> ret = new LinkedList<Input>();
    Matcher matcher;
    if ((matcher = PckParser.PATTERN_ACK_POS.matcher(input)).matches()) {
        ret.add(new ModAck(new LcnAddrMod(Integer.parseInt(matcher.group("segId")), Integer.parseInt(matcher.group("modId"))), -1));
    } else if ((matcher = PckParser.PATTERN_ACK_NEG.matcher(input)).matches()) {
        ret.add(new ModAck(new LcnAddrMod(Integer.parseInt(matcher.group("segId")), Integer.parseInt(matcher.group("modId"))), Integer.parseInt(matcher.group("code"))));
    }
    return ret;
}
Also used : Matcher(java.util.regex.Matcher) LinkedList(java.util.LinkedList) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

Example 2 with LcnAddrMod

use of org.openhab.binding.lcn.common.LcnAddrMod in project openhab1-addons by openhab.

the class ModSn method tryParseInput.

/**
     * Tries to parse the given input received from LCN-PCHK.
     * 
     * @param input the input
     * @return list of {@link ModSn} (might be empty, but not null}
     */
static Collection<Input> tryParseInput(String input) {
    LinkedList<Input> ret = new LinkedList<Input>();
    Matcher matcher = PckParser.PATTERN_SN.matcher(input);
    if (matcher.matches()) {
        ret.add(new ModSn(new LcnAddrMod(Integer.parseInt(matcher.group("segId")), Integer.parseInt(matcher.group("modId"))), Integer.parseInt(matcher.group("swAge"), 16)));
    }
    return ret;
}
Also used : Matcher(java.util.regex.Matcher) LinkedList(java.util.LinkedList) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

Example 3 with LcnAddrMod

use of org.openhab.binding.lcn.common.LcnAddrMod in project openhab1-addons by openhab.

the class ModStatusLedsAndLogicOps method tryParseInput.

/**
     * Tries to parse the given input received from LCN-PCHK.
     * 
     * @param input the input
     * @return list of {@link ModStatusLedsAndLogicOps} (might be empty, but not null}
     */
static Collection<Input> tryParseInput(String input) {
    LinkedList<Input> ret = new LinkedList<Input>();
    Matcher matcher = PckParser.PATTERN_STATUS_LEDSANDLOGICOPS.matcher(input);
    if (matcher.matches()) {
        LcnDefs.LedStatus[] statesLeds = new LcnDefs.LedStatus[12];
        for (int i = 0; i < 12; ++i) {
            switch(matcher.group("ledStates").toUpperCase().charAt(i)) {
                case 'A':
                    statesLeds[i] = LcnDefs.LedStatus.OFF;
                    break;
                case 'E':
                    statesLeds[i] = LcnDefs.LedStatus.ON;
                    break;
                case 'B':
                    statesLeds[i] = LcnDefs.LedStatus.BLINK;
                    break;
                case 'F':
                    statesLeds[i] = LcnDefs.LedStatus.FLICKER;
                    break;
                default:
                    throw new Error();
            }
        }
        LcnDefs.LogicOpStatus[] statesLogicOps = new LcnDefs.LogicOpStatus[4];
        for (int i = 0; i < 4; ++i) {
            switch(matcher.group("logicOpStates").toUpperCase().charAt(i)) {
                case 'N':
                    statesLogicOps[i] = LcnDefs.LogicOpStatus.NOT;
                    break;
                case 'T':
                    statesLogicOps[i] = LcnDefs.LogicOpStatus.OR;
                    break;
                case 'V':
                    statesLogicOps[i] = LcnDefs.LogicOpStatus.AND;
                    break;
                default:
                    throw new Error();
            }
        }
        ret.add(new ModStatusLedsAndLogicOps(new LcnAddrMod(Integer.parseInt(matcher.group("segId")), Integer.parseInt(matcher.group("modId"))), statesLeds, statesLogicOps));
    }
    return ret;
}
Also used : Matcher(java.util.regex.Matcher) LinkedList(java.util.LinkedList) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

Example 4 with LcnAddrMod

use of org.openhab.binding.lcn.common.LcnAddrMod in project openhab1-addons by openhab.

the class LcnGenericBindingProvider method processBindingConfiguration.

/**
     * Item processing for the LCN bindings.
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    Matcher matcher = PATTERN_BINDING_GENERAL.matcher(bindingConfig);
    if (!matcher.matches()) {
        throw new BindingConfigParseException(bindingConfig + "' contains no valid binding!");
    }
    matcher.reset();
    LcnBindingConfig bc = new LcnBindingConfig(item);
    while (matcher.find()) {
        String binding = matcher.group(1);
        if (binding != null && !binding.trim().isEmpty()) {
            String openHabCmd = null;
            String connId, lcnTarget;
            Matcher openHabMatcher = PATTERN_BINDING_WITH_OPENHAB.matcher(binding);
            Matcher pureMatcher = PATTERN_BINDING_PURE.matcher(binding);
            if (openHabMatcher.matches()) {
                openHabCmd = openHabMatcher.group(1);
                connId = openHabMatcher.group(2);
                lcnTarget = openHabMatcher.group(3);
            } else if (pureMatcher.matches()) {
                connId = pureMatcher.group(1);
                lcnTarget = pureMatcher.group(2);
            } else {
                throw new BindingConfigParseException("Invalid binding configuration for " + binding + "!");
            }
            String lcnShort = resolveMappings(lcnTarget, openHabCmd);
            if (lcnShort == null || lcnShort.equals(openHabCmd)) {
                lcnShort = lcnTarget;
            }
            Command cmd = openHabCmd == null ? TypeParser.parseCommand(new StringItem("").getAcceptedCommandTypes(), "") : openHabCmd.equals("%i") ? new StringType("%i") : TypeParser.parseCommand(item.getAcceptedCommandTypes(), openHabCmd);
            bc.add(new LcnBindingConfig.Mapping(cmd, connId, lcnShort));
        }
    }
    // Finished
    this.addBindingConfig(item, bc);
    for (LcnAddrMod addr : bc.getRelatedModules()) {
        HashSet<String> l = this.itemNamesByModulCache.get(addr);
        if (l == null) {
            l = new HashSet<String>();
            this.itemNamesByModulCache.put(addr, l);
        }
        l.add(item.getName());
    }
}
Also used : Matcher(java.util.regex.Matcher) Command(org.openhab.core.types.Command) StringType(org.openhab.core.library.types.StringType) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) StringItem(org.openhab.core.library.items.StringItem) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

Example 5 with LcnAddrMod

use of org.openhab.binding.lcn.common.LcnAddrMod in project openhab1-addons by openhab.

the class Connection method update.

/** Must be called periodically to keep the inner logic active. */
void update() {
    long currTime = System.nanoTime();
    // Reconnect logic
    if (this.reconnectTimestamp != 0 && currTime >= this.reconnectTimestamp) {
        this.beginConnect();
        this.reconnectTimestamp = 0;
    } else {
        if (this.isChannelConnected()) {
            // Keep-alive / ping logic
            if (currTime - this.lastPingTimeStamp > PING_INTERVAL_MSEC * 1000000L) {
                this.queue(PckGenerator.ping(++this.pingCounter));
                this.lastPingTimeStamp = currTime;
            }
            // Segment scan logic
            if (this.statusSegmentScan.shouldSendNextRequest(this.sets.getTimeout(), currTime)) {
                this.queue(new LcnAddrGrp(3, 3), false, PckGenerator.segmentCouplerScan());
                this.statusSegmentScan.onRequestSent(currTime);
            } else if (this.statusSegmentScan.isFailed(this.sets.getTimeout(), currTime)) {
                // Give up. Probably no segments available.
                this.setLocalSegId(0);
            }
        }
        // LcnModInfo logic
        this.callback.updateItems(this);
        if (this.isReady()) {
            for (Map.Entry<LcnAddrMod, ModInfo> entry : this.modData.entrySet()) {
                entry.getValue().update(this, this.sets.getTimeout(), currTime);
            }
        }
    }
}
Also used : LcnAddrGrp(org.openhab.binding.lcn.common.LcnAddrGrp) HashMap(java.util.HashMap) Map(java.util.Map) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

Aggregations

LcnAddrMod (org.openhab.binding.lcn.common.LcnAddrMod)11 Matcher (java.util.regex.Matcher)7 LinkedList (java.util.LinkedList)6 ModInfo (org.openhab.binding.lcn.connection.ModInfo)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 LcnAddrGrp (org.openhab.binding.lcn.common.LcnAddrGrp)1 LcnDefs (org.openhab.binding.lcn.common.LcnDefs)1 StringItem (org.openhab.core.library.items.StringItem)1 DecimalType (org.openhab.core.library.types.DecimalType)1 StringType (org.openhab.core.library.types.StringType)1 Command (org.openhab.core.types.Command)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1