def page_read(node, page, num): seq_nos = {} vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=24, data=[node, page, num]) # Page Read while True: response = vscpdif.get_response_match(class1=VSCP_CLASS1_PROTOCOL, type=26) if response: seq_no = response.data[0] seq_nos[seq_no] = response.data #print "seq_no: ", seq_no, " data:", #print ",".join(["%02x"%(el) for el in response.data[1:]]) # print as data arrives else: break # Check that all sequence numbers are there n = int(num / 7) + 1 # number of expected response events if False: for i in range(n): if i not in seq_nos: print "missing seq_no: ", i if True: for i in range(n): try: v = seq_nos[i] print "seq_no: %d " % (i), ",".join(["%02x"%(el) for el in v[1:]]) except KeyError: print "seq_no: %d missing" % (i)
def probe(nn): """Probe for one node with nickname nn""" vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=2, data=[nn]) # Probe response = vscpdif.get_response_match(class1=VSCP_CLASS1_PROTOCOL, type=3, tries=100, delay=0.001) # Probe ACK if response: return True return False
def whoisthere(): guids = {} vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=31, data=[0xff]) # Who is there? while True: response = vscpdif.get_response_match(class1=VSCP_CLASS1_PROTOCOL, type=32, tries=10) if not response: break if response.guid not in guids: print "detected: ", response.guid guids[response.guid] = True return guids
def read_register(node, reg): vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=9, data=[node, reg]) # Read Register response = vscpdif.get_response_match(class1=VSCP_CLASS1_PROTOCOL, type=10) if not response: #print "no response" return None # Decode response and extract register and value register = int(response.data[0]) value = int(response.data[1]) # Cross check if reg <> register: print "ERROR read_register" return None return value
def write_register(node, reg, val): vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=11, data=[node, reg, val]) # Write Register response = vscpdif.get_response_match(class1=VSCP_CLASS1_PROTOCOL, type=10) if not response: print "no response" return False # Decode response and extract register and value register = int(response.data[0]) value = int(response.data[1]) if reg != register: print "ERROR register" return False if val != value: print "ERROR value" return False return True
def discover_nickname(): for i in range(1,255): nn_in_use = False for j in range(5): logger.debug("discover nickname %d/%d" % (i,j)) send_probe(i) response = vscpdif.get_response_match(class1=VSCP_CLASS1_PROTOCOL, type=3) if response: # Nickname in use already. Don't probe this one again. nn_in_use = True break if nn_in_use: # Try next one. continue # Not in use, so it is available send_probe(i) REGISTER[NICKNAME] = i registers_write() logger.info("I'm node: %d", i) break
def discover_nickname(): for i in range(1, 255): nn_in_use = False for j in range(5): logger.debug("discover nickname %d/%d" % (i, j)) send_probe(i) response = vscpdif.get_response_match(class1=VSCP_CLASS1_PROTOCOL, type=3) if response: # Nickname in use already. Don't probe this one again. nn_in_use = True break if nn_in_use: # Try next one. continue # Not in use, so it is available send_probe(i) REGISTER[NICKNAME] = i registers_write() logger.info("I'm node: %d", i) break