def print_event(response_str): ev = vscpdif.vscp_rx_event(response_str) print ev, "\t", ev.guid
def process_event(response_str): ev = vscpdif.vscp_rx_event(response_str) if ev.class1 == VSCP_CLASS1_PROTOCOL: # Protocol event if ev.type == 2: # Probe if ev.data[0] != REGISTER[NICKNAME]: return logger.info("I'm being probed!") vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=3) # Probe ACK return if ev.type == 6: # Set nickname if ev.data[0] != REGISTER[NICKNAME]: return REGISTER[NICKNAME] = ev.data[1] vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=7) # Nickname id accepted logger.info("Set nickname to: %d" % (ev.data[1])) registers_write() return if ev.type == 8: # Drop nickname if ev.data[0] != REGISTER[NICKNAME]: return REGISTER[NICKNAME] = 0xff logger.info("Drop nickname") discover_nickname() registers_write() return if ev.type == 9: # Read register if ev.data[0] != REGISTER[NICKNAME]: return reg = ev.data[1] val = REGISTER[reg] vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=10, data=[reg, val]) # Read/Write response logger.info("Read register(%d) => %d" % (reg, val)) return if ev.type == 11: # Write register if ev.data[0] != REGISTER[NICKNAME]: return reg = ev.data[1] val = ev.data[2] REGISTER[reg] = val vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=10, data=[reg, REGISTER[reg]]) # Read/Write response registers_write() logger.info("Write register(%d) = %d" % (reg, val)) return if ev.type == 12: # Enter boot loader mode if ev.data[0] != REGISTER[NICKNAME]: return vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=14, data=[]) # NACK boot loader mode logger.info("Enter boot load mode: not implemented") return if ev.type == 24: # Page read if ev.data[0] != REGISTER[NICKNAME]: return logger.warning("Page read: not implemented") if ev.type == 31: # Who is there? if ev.data[0] != 0xff: if ev.data[0] != REGISTER[NICKNAME]: return logger.info("Who is there?") for i in range(7): row = i * 7 if i == 6: data = [ i, REGISTER[208 + row], REGISTER[209 + row], REGISTER[210 + row], REGISTER[211 + row], REGISTER[212 + row], REGISTER[213 + row] ] else: data = [ i, REGISTER[208 + row], REGISTER[209 + row], REGISTER[210 + row], REGISTER[211 + row], REGISTER[212 + row], REGISTER[213 + row], REGISTER[214 + row] ] vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=32, data=data) return
def process_event(response_str): ev = vscpdif.vscp_rx_event(response_str) if ev.class1 == VSCP_CLASS1_PROTOCOL: # Protocol event if ev.type == 2: # Probe if ev.data[0] != REGISTER[NICKNAME]: return logger.info("I'm being probed!") vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=3) # Probe ACK return if ev.type == 6: # Set nickname if ev.data[0] != REGISTER[NICKNAME]: return REGISTER[NICKNAME] = ev.data[1] vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=7) # Nickname id accepted logger.info("Set nickname to: %d" % (ev.data[1])) registers_write() return if ev.type == 8: # Drop nickname if ev.data[0] != REGISTER[NICKNAME]: return REGISTER[NICKNAME] = 0xff logger.info("Drop nickname") discover_nickname() registers_write() return if ev.type == 9: # Read register if ev.data[0] != REGISTER[NICKNAME]: return reg = ev.data[1] val = REGISTER[reg] vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=10, data=[reg, val]) # Read/Write response logger.info("Read register(%d) => %d" % (reg, val)) return if ev.type == 11: # Write register if ev.data[0] != REGISTER[NICKNAME]: return reg = ev.data[1] val = ev.data[2] REGISTER[reg] = val vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=10, data=[reg, REGISTER[reg]]) # Read/Write response registers_write() logger.info("Write register(%d) = %d" % (reg, val)) return if ev.type == 12: # Enter boot loader mode if ev.data[0] != REGISTER[NICKNAME]: return vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=14, data=[]) # NACK boot loader mode logger.info("Enter boot load mode: not implemented") return if ev.type == 24: # Page read if ev.data[0] != REGISTER[NICKNAME]: return logger.warning("Page read: not implemented") if ev.type == 31: # Who is there? if ev.data[0] != 0xff: if ev.data[0] != REGISTER[NICKNAME]: return logger.info("Who is there?") for i in range(7): row = i * 7 if i == 6: data = [i, REGISTER[208+row], REGISTER[209+row], REGISTER[210+row], REGISTER[211+row], REGISTER[212+row], REGISTER[213+row]] else: data = [i, REGISTER[208+row], REGISTER[209+row], REGISTER[210+row], REGISTER[211+row], REGISTER[212+row], REGISTER[213+row], REGISTER[214+row]] vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=32, data=data) return