Exemple #1
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);
   }
 }
Exemple #2
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);
   }
 }