def cancelLinking(self): """cancelLinking() takes modem out of linking or unlinking mode""" self.querier = Querier(InsteonAddress("00.00.00")) self.querier.setMsgHandler(DefaultMsgHandler("cancel linking")) msg = Msg.s_makeMessage("CancelALLLinking") self.querier.sendMsg(msg)
def createExtendedMsg(adr, cmd1, cmd2, data, flags = 0x1f): msg = Msg.s_makeMessage("SendExtendedMessage") populateMsg(msg, adr, cmd1, cmd2, data) msg.setByte("messageFlags", flags | 0x10) checksum = (~(cmd1 + cmd2 + sum(data)) + 1) & 0xFF msg.setByte("userData14", checksum) return msg
def getid(self): """getid() get modem id data""" self.querier = Querier(InsteonAddress("00.00.00")) self.querier.setMsgHandler(IMInfoMsgHandler("getid")) msg = Msg.s_makeMessage("GetIMInfo") self.querier.sendMsg(msg)
def __bcast(self, group, cmd1, cmd2): msg = Msg.s_makeMessage("SendStandardMessage") flags = 0xCF adr = InsteonAddress(0x00, 0x00, group & 0xFF) msg.setAddress("toAddress", adr) msg.setByte("messageFlags", flags) msg.setByte("command1", cmd1) msg.setByte("command2", cmd2) iofun.writeMsg(msg)
def createExtendedMsg2(adr, cmd1, cmd2, data, flags = 0x1f): msg = Msg.s_makeMessage("SendExtendedMessage") populateMsg(msg, adr, cmd1, cmd2, data) msg.setByte("messageFlags", flags | 0x10) crc = calcCRC(msg) crcLow = crc & 0xFF crcHigh = (crc >> 8) & 0xFF msg.setByte("userData13", int(crcHigh & 0xFF)) msg.setByte("userData14", int(crcLow & 0xFF)) return msg
def createStdMsg(adr, flags, cmd1, cmd2, group): msg = Msg.s_makeMessage("SendStandardMessage") if group != -1: flags |= 0xc0 adr = InsteonAddress(0x00, 0x00, group & 0xFF) msg.setAddress("toAddress", adr) msg.setByte("messageFlags", flags) msg.setByte("command1", cmd1) msg.setByte("command2", cmd2) return msg
def __makeModMsg(self, addr, group, controlCode, recordFlags, data, txt): msg = Msg.s_makeMessage("ManageALLLinkRecord"); msg.setByte("controlCode", controlCode); # mod. first ctrl found or add msg.setByte("recordFlags", recordFlags); msg.setByte("ALLLinkGroup", group); msg.setAddress("linkAddress", InsteonAddress(addr)); msg.setByte("linkData1", data[0] & 0xFF) msg.setByte("linkData2", data[1] & 0xFF) msg.setByte("linkData3", data[2] & 0xFF) return msg;
def unlinkAsController(self, otherDevice, group): """unlinkAsController(otherDevice, group) puts modem in unlink mode to unlink as controller from device "otherDevice" on group "group" """ addr = InsteonAddress(otherDevice) self.querier = Querier(addr) self.querier.setMsgHandler(DefaultMsgHandler("unlink as controller")) msg = Msg.s_makeMessage("StartALLLinking") msg.setByte("LinkCode", 0xFF) msg.setByte("ALLLinkGroup", group) self.querier.sendMsg(msg)
def linkAsResponder(self, otherDevice, group): """linkAsResponder(otherDevice, group) puts modem in link mode to respond to device "otherDevice" on group "group" """ addr = InsteonAddress(otherDevice) self.querier = Querier(addr) self.querier.setMsgHandler(DefaultMsgHandler("start linking")) msg = Msg.s_makeMessage("StartALLLinking") msg.setByte("LinkCode", 0x00) msg.setByte("ALLLinkGroup", group) self.querier.sendMsg(msg)
def msgReceived(self, msg): if msg.isPureNack(): return; if msg.getByte("Cmd") == 0x69 or msg.getByte("Cmd") == 0x6a : if msg.getByte("ACK/NACK") == 0x15: self.done() elif msg.getByte("Cmd") == 0x57: self.dbMsg(msg) iofun.writeMsg(Msg.s_makeMessage("GetNextALLLinkRecord")) else: out("got unexpected msg: " + msg.toString())
def makeMsg(self, offset, laddr, group, linkType, data): msg = Msg.s_makeMessage("SendExtendedMessage") msg.setAddress("toAddress", InsteonAddress(self.getAddress())) msg.setByte("messageFlags", 0x1f) msg.setByte("command1", 0x2f) msg.setByte("command2", 0x00) msg.setByte("userData1", 0x00) # don't care info msg.setByte("userData2", 0x02) # set database msg.setByte("userData3", offset >> 8) # high byte msg.setByte("userData4", offset & 0xff) # low byte msg.setByte("userData5", 8) # number of bytes set: 1...8 msg.setByte("userData6", linkType) msg.setByte("userData7", group) msg.setByte("userData8", laddr.getHighByte()) msg.setByte("userData9", laddr.getMiddleByte()) msg.setByte("userData10", laddr.getLowByte()) # depends on mode: could be e.g. trigger point msg.setByte("userData11", data[0]) msg.setByte("userData12", data[1]) # unused? msg.setByte("userData13", data[2]) # unused? rb = msg.getBytes("command1", 15); checksum = (~sum(rb) + 1) & 0xFF msg.setByte("userData14", checksum) return msg
def start(self): self.db.clear() self.keepRunning = True iofun.addListener(self) iofun.writeMsg(Msg.s_makeMessage("GetFirstALLLinkRecord"))