Example #1
0
 /** Visualization for {@link StringType} and {@link DecimalType}. {@inheritDoc} */
 @Override
 public boolean visualizationVarStatus(
     ModStatusVar pchkInput, Command cmd, Item item, EventPublisher eventPublisher) {
   // We are actually not meant to visualize anything.
   // But (just in case) someone is really lazy in doing the item-definitions, we try to be helpful
   // by showing the
   // current value.
   if (pchkInput.getLogicalSourceAddr().equals(this.addr) && pchkInput.getVar() == this.var) {
     if (item.getAcceptedDataTypes().contains(StringType.class)) {
       String valueStr =
           pchkInput
               .getValue()
               .toVarUnitString(
                   this.unit,
                   LcnDefs.Var.isLockableRegulatorSource(this.var),
                   LcnDefs.Var.useLcnSpecialValues(this.var));
       eventPublisher.postUpdate(item.getName(), new StringType(valueStr));
       return true;
     } else if (item.getAcceptedDataTypes().contains(DecimalType.class)) {
       eventPublisher.postUpdate(
           item.getName(),
           new DecimalType(
               pchkInput
                   .getValue()
                   .toVarUnit(this.unit, LcnDefs.Var.isLockableRegulatorSource(this.var))));
       return true;
     }
   }
   return false;
 }
Example #2
0
 /** {@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.
         // 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));
     }
   }
 }
Example #3
0
 /**
  * Tries to parse the given input text.
  *
  * @param input the text to parse
  * @return the parsed {@link VarAbs} or null
  */
 static Target tryParseTarget(String input) {
   CmdAndAddressRet header = CmdAndAddressRet.parse(input, true);
   if (header != null) {
     try {
       Matcher matcher;
       switch (header.getCmd().toUpperCase()) {
         case "VAR":
         case "VAR_OLD":
           if ((matcher = PATTERN_VAR_ABS.matcher(header.getRestInput())).matches()) {
             double value =
                 NumberFormat.getInstance(Locale.GERMANY)
                     .parse(matcher.group("value"))
                     .doubleValue();
             LcnDefs.VarUnit unit =
                 matcher.group("modifier") == null
                     ? LcnDefs.VarUnit.NATIVE
                     : LcnDefs.VarUnit.parse(matcher.group("modifier"));
             return new VarAbs(
                 header.getAddr(),
                 LcnDefs.Var.varIdToVar(Integer.parseInt(matcher.group("varId")) - 1),
                 unit,
                 LcnDefs.VarValue.fromVarUnit(value, unit, true),
                 header.getCmd().toUpperCase().endsWith("_OLD"));
           } else if ((matcher = PATTERN_VAR_ABSI.matcher(header.getRestInput())).matches()) {
             LcnDefs.VarUnit unit =
                 matcher.group("modifier") == null
                     ? LcnDefs.VarUnit.NATIVE
                     : LcnDefs.VarUnit.parse(matcher.group("modifier"));
             return new VarAbs(
                 header.getAddr(),
                 LcnDefs.Var.varIdToVar(Integer.parseInt(matcher.group("varId")) - 1),
                 unit,
                 null,
                 header.getCmd().toUpperCase().endsWith("_OLD"));
           }
           break;
         case "SETPOINT":
           if ((matcher = PATTERN_SETPOINT_ABS.matcher(header.getRestInput())).matches()) {
             double value =
                 NumberFormat.getInstance(Locale.GERMANY)
                     .parse(matcher.group("value"))
                     .doubleValue();
             LcnDefs.VarUnit unit =
                 matcher.group("modifier") == null
                     ? LcnDefs.VarUnit.NATIVE
                     : LcnDefs.VarUnit.parse(matcher.group("modifier"));
             return new VarAbs(
                 header.getAddr(),
                 LcnDefs.Var.setPointIdToVar(Integer.parseInt(matcher.group("regId")) - 1),
                 unit,
                 LcnDefs.VarValue.fromVarUnit(value, unit, true),
                 false);
           } else if ((matcher = PATTERN_SETPOINT_ABSI.matcher(header.getRestInput())).matches()) {
             LcnDefs.VarUnit unit =
                 matcher.group("modifier") == null
                     ? LcnDefs.VarUnit.NATIVE
                     : LcnDefs.VarUnit.parse(matcher.group("modifier"));
             return new VarAbs(
                 header.getAddr(),
                 LcnDefs.Var.setPointIdToVar(Integer.parseInt(matcher.group("regId")) - 1),
                 unit,
                 null,
                 false);
           }
           break;
       }
     } catch (ParseException ex) {
     } catch (IllegalArgumentException ex) {
     }
   }
   return null;
 }