public Msg makeX10Message(byte rawX10, byte X10Flag) throws FieldException, IOException { Msg m = Msg.s_makeMessage("SendX10Message"); m.setByte("rawX10", rawX10); m.setByte("X10Flag", X10Flag); m.setQuietTime(300L); return m; }
/** * Helper method to make extended message * * @param flags * @param cmd1 * @param cmd2 * @return extended message * @throws FieldException * @throws IOException */ public Msg makeExtendedMessage(byte flags, byte cmd1, byte cmd2) throws FieldException, IOException { Msg m = Msg.s_makeMessage("SendExtendedMessage"); m.setAddress("toAddress", getAddress()); m.setByte("messageFlags", (byte) (((flags & 0xff) | 0x10) & 0xff)); m.setByte("command1", cmd1); m.setByte("command2", cmd2); int checksum = (~(cmd1 + cmd2) + 1) & 0xff; m.setByte("userData14", (byte) checksum); return m; }
@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); } }
/** * Helper method to make standard message, possibly with group * * @param flags * @param cmd1 * @param cmd2 * @param group (-1 if not a group message) * @return standard message * @throws FieldException * @throws IOException */ public Msg makeStandardMessage(byte flags, byte cmd1, byte cmd2, int group) throws FieldException, IOException { Msg m = Msg.s_makeMessage("SendStandardMessage"); InsteonAddress addr = null; if (group != -1) { flags |= 0xc0; // mark message as group message // and stash the group number into the address addr = new InsteonAddress((byte) 0, (byte) 0, (byte) (group & 0xff)); } else { addr = getAddress(); } m.setAddress("toAddress", addr); m.setByte("messageFlags", flags); m.setByte("command1", cmd1); m.setByte("command2", cmd2); return m; }