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; }
/** * Enqueues message to be sent after a delay * * @param m message to be sent * @param f device feature that sent this message (so we can associate the response message with * it) * @param d time (in milliseconds)to delay before enqueuing message */ public void enqueueDelayedMessage(Msg m, DeviceFeature f, long delay) { long now = System.currentTimeMillis(); synchronized (m_requestQueue) { m_requestQueue.add(new QEntry(f, m, now + delay)); } if (!m.isBroadcast()) { m.setQuietTime(QUIET_TIME_DIRECT_MESSAGE); } logger.trace("enqueing direct message with delay {}", delay); RequestQueueManager.s_instance().addQueue(this, now + delay); }
@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; }
@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); } }
/** * 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; }