Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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
Exemplo n.º 8
0
def send_probe(target):
    vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=2,
                 data=[target])  # New node on line / Probe
Exemplo n.º 9
0
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
Exemplo n.º 10
0
def send_probe(target):
    vscpdif.send(class1=VSCP_CLASS1_PROTOCOL, type=2, data=[target])   # New node on line / Probe
Exemplo n.º 11
0
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