Example #1
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd == OnOffType.ON || cmd == OnOffType.OFF) {
       byte cmd1 = (byte) ((cmd == OnOffType.ON) ? 0x11 : 0x13);
       byte value = (byte) ((cmd == OnOffType.ON) ? 0xFF : 0x00);
       int group = s_getGroup(conf);
       if (group == -1) {
         logger.error("no group=xx specified in item {}", conf.getItemName());
         return;
       }
       logger.info(
           "{}: sending {} broadcast to group {}",
           nm(),
           (cmd1 == 0x11) ? "ON" : "OFF",
           s_getGroup(conf));
       Msg m = dev.makeStandardMessage((byte) 0x0f, cmd1, value, group);
       dev.enqueueMessage(m, m_feature);
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #2
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd instanceof DecimalType) {
       int v = ((DecimalType) cmd).intValue();
       int cmd1 = (v != 1) ? 0x17 : 0x18; // start or stop
       int cmd2 = (v == 2) ? 0x01 : 0; // up or down
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) cmd1, (byte) cmd2, s_getGroup(conf));
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: cmd {} sent manual change {} {} to {}",
           nm(),
           v,
           (cmd1 == 0x17) ? "START" : "STOP",
           (cmd2 == 0x01) ? "UP" : "DOWN",
           dev.getAddress());
     } else {
       logger.error("{}: invalid command type: {}", nm(), cmd);
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #3
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     int dc = transform(((DecimalType) cmd).intValue());
     int intFactor = getIntParameter("factor", 1);
     //
     // determine what level should be, and what field it should be in
     //
     int ilevel = dc * intFactor;
     byte level = (byte) (ilevel > 255 ? 0xFF : ((ilevel < 0) ? 0 : ilevel));
     String vfield = getStringParameter("value", "");
     if (vfield == "") {
       logger.error("{} has no value field specified", nm());
     }
     //
     // figure out what cmd1, cmd2, d1, d2, d3 are supposed to be
     // to form a proper message
     //
     int cmd1 = getIntParameter("cmd1", -1);
     if (cmd1 < 0) {
       logger.error("{} has no cmd1 specified!", nm());
       return;
     }
     int cmd2 = getIntParameter("cmd2", 0);
     int ext = getIntParameter("ext", 0);
     Msg m = null;
     if (ext == 1 || ext == 2) {
       byte[] data =
           new byte[] {
             (byte) getIntParameter("d1", 0),
             (byte) getIntParameter("d2", 0),
             (byte) getIntParameter("d3", 0)
           };
       m = dev.makeExtendedMessage((byte) 0x0f, (byte) cmd1, (byte) cmd2, data);
       m.setByte(vfield, level);
       if (ext == 1) m.setCRC();
       else if (ext == 2) m.setCRC2();
     } else {
       m = dev.makeStandardMessage((byte) 0x0f, (byte) cmd1, (byte) cmd2);
       m.setByte(vfield, level);
     }
     dev.enqueueMessage(m, m_feature);
     logger.info("{}: sent msg to change level to {}", nm(), ((DecimalType) cmd).intValue());
     m = null;
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #4
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   String cmdParam = conf.getParameter("cmd");
   if (cmdParam == null) {
     logger.error("{} ignoring cmd {} because no cmd= is configured!", nm(), cmd);
     return;
   }
   try {
     if (cmd == OnOffType.ON) {
       if (cmdParam.equals("reset")) {
         Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x80, (byte) 0x00);
         dev.enqueueMessage(m, m_feature);
         logger.info("{}: sent reset msg to power meter {}", nm(), dev.getAddress());
         m_feature.publish(OnOffType.OFF, StateChangeType.ALWAYS, "cmd", "reset");
       } else if (cmdParam.equals("update")) {
         Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x82, (byte) 0x00);
         dev.enqueueMessage(m, m_feature);
         logger.info("{}: sent update msg to power meter {}", nm(), dev.getAddress());
         m_feature.publish(OnOffType.OFF, StateChangeType.ALWAYS, "cmd", "update");
       } else {
         logger.error(
             "{}: ignoring unknown cmd {} for power meter {}", nm(), cmdParam, dev.getAddress());
       }
     } else if (cmd == OnOffType.OFF) {
       logger.info("{}: ignoring off request for power meter {}", nm(), dev.getAddress());
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #5
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     byte houseCode = dev.getX10HouseCode();
     byte houseUnitCode = (byte) (houseCode << 4 | dev.getX10UnitCode());
     if (cmd == IncreaseDecreaseType.INCREASE || cmd == IncreaseDecreaseType.DECREASE) {
       byte houseCommandCode =
           (byte)
               (houseCode << 4
                   | (cmd == IncreaseDecreaseType.INCREASE
                       ? X10.Command.BRIGHT.code()
                       : X10.Command.DIM.code()));
       Msg munit = dev.makeX10Message(houseUnitCode, (byte) 0x00); // send unit code
       dev.enqueueMessage(munit, m_feature);
       Msg mcmd = dev.makeX10Message(houseCommandCode, (byte) 0x80); // send command code
       dev.enqueueMessage(mcmd, m_feature);
       String bd = cmd == IncreaseDecreaseType.INCREASE ? "BRIGHTEN" : "DIM";
       logger.info("{}: sent msg to switch {} {}", nm(), dev.getAddress(), bd);
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #6
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     //
     // I did not have hardware that would respond to the PRESET_DIM codes.
     // This code path needs testing.
     //
     byte houseCode = dev.getX10HouseCode();
     byte houseUnitCode = (byte) (houseCode << 4 | dev.getX10UnitCode());
     Msg munit = dev.makeX10Message(houseUnitCode, (byte) 0x00); // send unit code
     dev.enqueueMessage(munit, m_feature);
     PercentType pc = (PercentType) cmd;
     logger.debug("{}: changing level of {} to {}", nm(), dev.getAddress(), pc.intValue());
     int level = (pc.intValue() * 32) / 100;
     byte cmdCode =
         (level >= 16) ? X10.Command.PRESET_DIM_2.code() : X10.Command.PRESET_DIM_1.code();
     level = level % 16;
     if (level <= 0) level = 0;
     houseCode = (byte) s_X10CodeForLevel[level];
     cmdCode |= (houseCode << 4);
     Msg mcmd = dev.makeX10Message(cmdCode, (byte) 0x80); // send command code
     dev.enqueueMessage(mcmd, m_feature);
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #7
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     PercentType pc = (PercentType) cmd;
     double ramptime = getRampTime(conf, 0);
     int level = pc.intValue();
     if (level > 0) { // make light on message with given level
       level = getMaxLightLevel(conf, level);
       byte cmd2 = encode(ramptime, level);
       Msg m = dev.makeStandardMessage((byte) 0x0f, getOnCmd(), (byte) cmd2);
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: sent msg to set {} to {} with {} second ramp time.",
           nm(),
           dev.getAddress(),
           level,
           ramptime);
     } else { // switch off
       Msg m = dev.makeStandardMessage((byte) 0x0f, getOffCmd(), (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: sent msg to set {} to zero by switching off with {} ramp time.",
           nm(),
           dev.getAddress(),
           ramptime);
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #8
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd == OnOffType.ON) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x11, (byte) 0xff);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to switch {} on", nm(), dev.getAddress());
     } else if (cmd == OnOffType.OFF) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x13, (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to switch {} off", nm(), dev.getAddress());
     }
     // This used to be configurable, but was made static to make
     // the architecture of the binding cleaner.
     int delay = 2000;
     delay = Math.max(1000, delay);
     delay = Math.min(10000, delay);
     Timer timer = new Timer();
     timer.schedule(
         new TimerTask() {
           @Override
           public void run() {
             Msg m = m_feature.makePollMsg();
             InsteonDevice dev = m_feature.getDevice();
             if (m != null) dev.enqueueMessage(m, m_feature);
           }
         },
         delay);
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error: ", nm(), e);
   }
 }
Example #9
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     int button = this.getIntParameter("button", -1);
     if (cmd == OnOffType.ON) {
       Msg m =
           dev.makeExtendedMessage(
               (byte) 0x1f,
               (byte) 0x2e,
               (byte) 0x00,
               new byte[] {(byte) button, (byte) 0x09, (byte) 0x01});
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to switch {} on", nm(), dev.getAddress());
     } else if (cmd == OnOffType.OFF) {
       Msg m =
           dev.makeExtendedMessage(
               (byte) 0x1f,
               (byte) 0x2e,
               (byte) 0x00,
               new byte[] {(byte) button, (byte) 0x09, (byte) 0x00});
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to switch {} off", nm(), dev.getAddress());
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #10
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     int ext = getIntParameter("ext", 0);
     int direc = 0x00;
     int level = 0x00;
     Msg m = null;
     if (cmd == OnOffType.ON) {
       level = getMaxLightLevel(conf, 0xff);
       direc = 0x11;
       logger.info(
           "{}: sent msg to switch {} to {}",
           nm(),
           dev.getAddress(),
           level == 0xff ? "on" : level);
     } else if (cmd == OnOffType.OFF) {
       direc = 0x13;
       logger.info("{}: sent msg to switch {} off", nm(), dev.getAddress());
     }
     if (ext == 1 || ext == 2) {
       byte[] data =
           new byte[] {
             (byte) getIntParameter("d1", 0),
             (byte) getIntParameter("d2", 0),
             (byte) getIntParameter("d3", 0)
           };
       m = dev.makeExtendedMessage((byte) 0x0f, (byte) direc, (byte) level, data);
       logger.info("{}: was an extended message for device {}", nm(), dev.getAddress());
       if (ext == 1) m.setCRC();
       else if (ext == 2) m.setCRC2();
     } else {
       m = dev.makeStandardMessage((byte) 0x0f, (byte) direc, (byte) level, s_getGroup(conf));
     }
     logger.info("Sending message to {}", dev.getAddress());
     dev.enqueueMessage(m, m_feature);
     // expect to get a direct ack after this!
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #11
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd == IncreaseDecreaseType.INCREASE) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x15, (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to brighten {}", nm(), dev.getAddress());
     } else if (cmd == IncreaseDecreaseType.DECREASE) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x16, (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to dimm {}", nm(), dev.getAddress());
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #12
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     PercentType pc = (PercentType) cmd;
     logger.debug("changing level of {} to {}", dev.getAddress(), pc.intValue());
     int level = (int) Math.ceil((pc.intValue() * 255.0) / 100); // round up
     if (level > 0) { // make light on message with given level
       level = getMaxLightLevel(conf, level);
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x11, (byte) level);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to set {} to {}", nm(), dev.getAddress(), level);
     } else { // switch off
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x13, (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to set {} to zero by switching off", nm(), dev.getAddress());
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #13
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     byte houseCode = dev.getX10HouseCode();
     byte houseUnitCode = (byte) (houseCode << 4 | dev.getX10UnitCode());
     if (cmd == OnOffType.ON || cmd == OnOffType.OFF) {
       byte houseCommandCode =
           (byte)
               (houseCode << 4
                   | (cmd == OnOffType.ON ? X10.Command.ON.code() : X10.Command.OFF.code()));
       Msg munit = dev.makeX10Message(houseUnitCode, (byte) 0x00); // send unit code
       dev.enqueueMessage(munit, m_feature);
       Msg mcmd = dev.makeX10Message(houseCommandCode, (byte) 0x80); // send command code
       dev.enqueueMessage(mcmd, m_feature);
       String onOff = cmd == OnOffType.ON ? "ON" : "OFF";
       logger.info("{}: sent msg to switch {} {}", nm(), dev.getAddress(), onOff);
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #14
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd == OnOffType.ON) {
       double ramptime = getRampTime(conf, 0);
       int ramplevel = getRampLevel(conf, 100);
       byte cmd2 = encode(ramptime, ramplevel);
       Msg m = dev.makeStandardMessage((byte) 0x0f, getOnCmd(), (byte) cmd2, s_getGroup(conf));
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: sent ramp on to switch {} time {} level {} cmd1 {}",
           nm(),
           dev.getAddress(),
           ramptime,
           ramplevel,
           getOnCmd());
     } else if (cmd == OnOffType.OFF) {
       double ramptime = getRampTime(conf, 0);
       int ramplevel = getRampLevel(conf, 0 /*ignored*/);
       byte cmd2 = encode(ramptime, ramplevel);
       Msg m = dev.makeStandardMessage((byte) 0x0f, getOffCmd(), (byte) cmd2, s_getGroup(conf));
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: sent ramp off to switch {} time {} cmd1 {}",
           nm(),
           dev.getAddress(),
           ramptime,
           getOffCmd());
     }
     // expect to get a direct ack after this!
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #15
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd == OnOffType.ON) {
       int level = getMaxLightLevel(conf, 0xff);
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x12, (byte) level, s_getGroup(conf));
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: sent fast on to switch {} level {}",
           nm(),
           dev.getAddress(),
           level == 0xff ? "on" : level);
     } else if (cmd == OnOffType.OFF) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x14, (byte) 0x00, s_getGroup(conf));
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent fast off to switch {}", nm(), dev.getAddress());
     }
     // expect to get a direct ack after this!
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Example #16
0
 /**
  * Factory method
  *
  * @param dt device type after which to model the device
  * @return newly created device
  */
 public static InsteonDevice s_makeDevice(DeviceType dt) {
   InsteonDevice dev = new InsteonDevice();
   dev.instantiateFeatures(dt);
   return dev;
 }