Beispiel #1
0
 /**
  * Tries to parse the given input text.
  *
  * @param input the text to parse
  * @return the parsed {@link LedVisualize} or null
  */
 static Target tryParseTarget(String input) {
   CmdAndAddressRet header = CmdAndAddressRet.parse(input, false);
   if (header != null) {
     Matcher matcher;
     switch (header.getCmd().toUpperCase()) {
       case "LED_STATE":
         if ((matcher = PATTERN_LED.matcher(header.getRestInput())).matches()) {
           int ledId = Integer.parseInt(matcher.group("ledId")) - 1;
           if (ledId < 12) {
             String[] stateTexts =
                 new String[] {
                   "off", "on", "blink", "flicker" // Defaults
                 };
             for (int i = 0; i < 4; ++i) {
               String s = matcher.group(String.format("text%d", i));
               if (s != null) {
                 stateTexts[i] = s;
               }
             }
             return new LedVisualize((LcnAddrMod) header.getAddr(), ledId, stateTexts);
           }
         }
         break;
     }
   }
   return null;
 }
Beispiel #2
0
 /**
  * Tries to parse the given input text.
  *
  * @param input the text to parse
  * @return the parsed {@link PlainPck} or null
  */
 static Target tryParseTarget(String input) {
   CmdAndAddressRet header = CmdAndAddressRet.parse(input, true);
   if (header != null) {
     switch (header.getCmd().toUpperCase()) {
       case "PCK":
         return new PlainPck(header.getAddr(), header.getRestInput());
     }
   }
   return null;
 }
Beispiel #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;
 }