Search in sources :

Example 6 with LcnAddrMod

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

the class VarReset method send.

/** {@inheritDoc} */
@Override
public void send(Connection conn, Item item, Command cmd) {
    try {
        boolean is2013 = !this.forceOld;
        ModInfo info = null;
        if (!this.addr.isGroup()) {
            info = conn.getModInfo((LcnAddrMod) this.addr);
            if (info != null) {
                is2013 = info.getSwAge() >= 0x170206;
            }
        }
        conn.queue(this.addr, !this.addr.isGroup(), PckGenerator.varReset(this.var, is2013));
        // Force a status update
        if (info != null && LcnDefs.Var.shouldPollStatusAfterCommand(this.var, is2013) && info.requestStatusVars.containsKey(this.var)) {
            info.requestStatusVars.get(this.var).nextRequestIn(ModInfo.STATUS_REQUEST_DELAY_AFTER_COMMAND_MSEC, System.nanoTime());
        }
    } catch (IllegalArgumentException ex) {
        logger.warn(String.format("Variable of type %s does not support \"reset to 0\" commands.", this.var));
    }
}
Also used : ModInfo(org.openhab.binding.lcn.connection.ModInfo) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

Example 7 with LcnAddrMod

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

the class VarAbs method send.

/** {@inheritDoc} */
@Override
public void send(Connection conn, Item item, Command cmd) {
    LcnDefs.VarValue value = this.value;
    if (value == null && cmd instanceof DecimalType) {
        value = LcnDefs.VarValue.fromVarUnit(((DecimalType) cmd).doubleValue(), this.unit, true);
    }
    if (value != null) {
        try {
            boolean is2013 = !this.forceOld;
            ModInfo info = null;
            if (!this.addr.isGroup()) {
                info = conn.getModInfo((LcnAddrMod) this.addr);
                if (info != null) {
                    is2013 = info.getSwAge() >= 0x170206;
                }
            }
            if (LcnDefs.Var.toVarId(this.var) != -1) {
                // Absolute commands for variables are not supported.
                if (this.addr.getId() == 4 && this.addr.isGroup()) {
                    // group 4 are status messages
                    conn.queue(this.addr, !this.addr.isGroup(), PckGenerator.updateStatusVar(this.var, value.toNative()));
                } else {
                    // We fake the missing command by using reset and relative commands.
                    conn.queue(this.addr, !this.addr.isGroup(), PckGenerator.varReset(this.var, is2013));
                    conn.queue(this.addr, !this.addr.isGroup(), PckGenerator.varRel(this.var, LcnDefs.RelVarRef.CURRENT, value.toNative(), is2013));
                }
            } else {
                conn.queue(this.addr, !this.addr.isGroup(), PckGenerator.varAbs(this.var, value.toNative()));
            }
            // Force a status update
            if (info != null && LcnDefs.Var.shouldPollStatusAfterCommand(this.var, is2013) && info.requestStatusVars.containsKey(this.var)) {
                info.requestStatusVars.get(this.var).nextRequestIn(ModInfo.STATUS_REQUEST_DELAY_AFTER_COMMAND_MSEC, System.nanoTime());
            }
        } catch (IllegalArgumentException ex) {
            logger.warn(String.format("Variable of type %s does not support \"set absolute\" commands.", this.var));
        }
    }
}
Also used : LcnDefs(org.openhab.binding.lcn.common.LcnDefs) DecimalType(org.openhab.core.library.types.DecimalType) ModInfo(org.openhab.binding.lcn.connection.ModInfo) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

Example 8 with LcnAddrMod

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

the class ModStatusKeyLocks method tryParseInput.

/**
     * Tries to parse the given input received from LCN-PCHK.
     * 
     * @param input the input
     * @return list of {@link ModStatusKeyLocks} (might be empty, but not null}
     */
static Collection<Input> tryParseInput(String input) {
    LinkedList<Input> ret = new LinkedList<Input>();
    try {
        Matcher matcher = PckParser.PATTERN_STATUS_KEYLOCKS.matcher(input);
        if (matcher.matches()) {
            boolean[][] states = new boolean[4][];
            for (int i = 0; i < 4; ++i) {
                String s = matcher.group(String.format("table%d", i));
                states[i] = s != null ? PckParser.getBooleanValue(Integer.parseInt(s)) : new boolean[8];
            }
            ret.add(new ModStatusKeyLocks(new LcnAddrMod(Integer.parseInt(matcher.group("segId")), Integer.parseInt(matcher.group("modId"))), states));
        }
    } catch (IllegalArgumentException ex) {
    }
    return ret;
}
Also used : Matcher(java.util.regex.Matcher) LinkedList(java.util.LinkedList) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

Example 9 with LcnAddrMod

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

the class ModStatusOutput method tryParseInput.

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

Example 10 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