Пример #1
0
def receiveOneDatagram(alias, dest, conection, verbose):
    retval = []
    reply = connection.network.receive()

    if reply == None:
        return None
    if reply.startswith(":X1A"):
        retval = retval + canolcbutils.bodyArray(reply)
        connection.network.send(makereply(alias, dest))
        return retval

    if reply.startswith(":X1B"):
        retval = retval + canolcbutils.bodyArray(reply)
    else:
        print "Unexpected message instead of first datagram segment", reply
        return 3
    while True:
        reply = connection.network.receive()
        if reply == None:
            print "No datagram segment received"
            return 4
        elif reply.startswith(":X1C"):
            retval = retval + canolcbutils.bodyArray(reply)
            continue
        elif reply.startswith(":X1D"):
            retval = retval + canolcbutils.bodyArray(reply)
            connection.network.send(makereply(alias, dest))
            return retval
        else:
            print "Unexpected message instead of datagram segment", reply
            return 3
Пример #2
0
def receiveDatagramReplyAndOneDatagram(alias, dest, conection, verbose) :
    # use after SendOneDatagramNoWait to get both the reply datagram and 
    # the response to the sent datagram, in either order.
    retval = []
    haveReply = False
    haveDatagram = False
    while True :
        reply = connection.network.receive()
        if (reply == None ) : 
            print "Missing response"
            return 4
        elif isOkReply(reply) : 
            haveReply = True
            if haveDatagram : 
                return retval
        elif reply.startswith(":X1B") or reply.startswith(":X1C") :
            retval = retval + canolcbutils.bodyArray(reply)
            continue
        elif reply.startswith(":X1A") or reply.startswith(":X1D") :
            retval = retval + canolcbutils.bodyArray(reply)
            connection.network.send(makereply(alias, dest))
            haveDatagram = True
            if haveReply :
                return retval
        else :
            print "Unexpected message", reply
            return 3
def test(alias, dest, connection, verbose):
    # now execute
    connection.network.send(identifyEventsAddressed.makeframe(alias, dest))
    consumed = []
    produced = []
    while True:
        reply = connection.network.receive()
        if reply == None:
            break
        if reply.startswith(":X194C7") or reply.startswith(":X194C4") or reply.startswith(":X194C5"):
            event = canolcbutils.bodyArray(reply)
            if verbose:
                print "  consumes ", event
            consumed = consumed + [event]
        elif reply.startswith(":X19547") or reply.startswith(":X19544") or reply.startswith(":X19545"):
            event = canolcbutils.bodyArray(reply)
            if verbose:
                print "  produces ", event
            produced = produced + [event]
    # now check consumers and producers individually
    timeout = connection.network.timeout
    connection.network.timeout = 0.25
    if connection.network.verbose:
        print "Start individual checks"
    for c in consumed:
        connection.network.send(identifyConsumers.makeframe(alias, c))
        reply = connection.network.receive()
        if reply == None:
            print "no reply for consumer ", c
            return 20
        elif not (reply.startswith(":X194C7") or reply.startswith(":X194C4") or reply.startswith(":X194C5")):
            print "Unexpected reply " + reply
            return 21
        # here is OK, go around to next
        while True:
            reply = connection.network.receive()
            if reply == None:
                break
            elif not reply.startswith(":X194C7"):
                print "Unexpected reply " + reply
                return 22
    for p in produced:
        connection.network.send(identifyProducers.makeframe(alias, p))
        reply = connection.network.receive()
        if reply == None:
            print "no reply for producer ", p
            return 30
        elif not (reply.startswith(":X19547") or reply.startswith(":X19544") or reply.startswith(":X19545")):
            print "Unexpected reply " + reply
            return 31
        # here is OK, go around to next
        while True:
            reply = connection.network.receive()
            if reply == None:
                break
            elif not reply.startswith(":X19547"):
                print "Unexpected reply " + reply
                return 32
    connection.network.timeout = timeout
    return 0
def receiveOneDatagram(alias, dest, conection, verbose):
    retval = []
    reply = connection.network.receive()

    if reply == None:
        return None
    if reply.startswith(":X1A"):
        retval = retval + canolcbutils.bodyArray(reply)
        connection.network.send(makereply(alias, dest))
        return retval

    if reply.startswith(":X1B"):
        retval = retval + canolcbutils.bodyArray(reply)
    else:
        print "Unexpected message instead of first datagram segment", reply
        return 3
    while True:
        reply = connection.network.receive()
        if (reply == None):
            print "No datagram segment received"
            return 4
        elif reply.startswith(":X1C"):
            retval = retval + canolcbutils.bodyArray(reply)
            continue
        elif reply.startswith(":X1D"):
            retval = retval + canolcbutils.bodyArray(reply)
            connection.network.send(makereply(alias, dest))
            return retval
        else:
            print "Unexpected message instead of datagram segment", reply
            return 3
def test(alias, dest, connection, verbose):
    # now execute
    connection.network.send(identifyEventsAddressed.makeframe(alias, dest))
    consumed = []
    produced = []
    while (True):
        reply = connection.network.receive()
        if (reply == None): break
        if (reply.startswith(":X194C7") or reply.startswith(":X194C4")
                or reply.startswith(":X194C5")):
            event = canolcbutils.bodyArray(reply)
            if verbose: print "  consumes ", event
            consumed = consumed + [event]
        elif (reply.startswith(":X19547") or reply.startswith(":X19544")
              or reply.startswith(":X19545")):
            event = canolcbutils.bodyArray(reply)
            if verbose: print "  produces ", event
            produced = produced + [event]
    # now check consumers and producers individually
    timeout = connection.network.timeout
    connection.network.timeout = 0.25
    if connection.network.verbose: print "Start individual checks"
    for c in consumed:
        connection.network.send(identifyConsumers.makeframe(alias, c))
        reply = connection.network.receive()
        if (reply == None):
            print "no reply for consumer ", c
            return 20
        elif not (reply.startswith(":X194C7") or reply.startswith(":X194C4")
                  or reply.startswith(":X194C5")):
            print "Unexpected reply " + reply
            return 21
        # here is OK, go around to next
        while True:
            reply = connection.network.receive()
            if (reply == None): break
            elif (not reply.startswith(":X194C7")):
                print "Unexpected reply " + reply
                return 22
    for p in produced:
        connection.network.send(identifyProducers.makeframe(alias, p))
        reply = connection.network.receive()
        if (reply == None):
            print "no reply for producer ", p
            return 30
        elif not (reply.startswith(":X19547") or reply.startswith(":X19544")
                  or reply.startswith(":X19545")):
            print "Unexpected reply " + reply
            return 31
        # here is OK, go around to next
        while True:
            reply = connection.network.receive()
            if (reply == None): break
            elif (not reply.startswith(":X19547")):
                print "Unexpected reply " + reply
                return 32
    connection.network.timeout = timeout
    return 0
Пример #6
0
def get(alias, nodeID) :
    connection.network.send(verifyNodeGlobal.makeframe(alias, nodeID))
    while (True) :
        reply = connection.network.receive()
        if (reply == None ) : return None,None
        if (reply.startswith(":X180B7")) :
            return int(reply[7:10],16),canolcbutils.bodyArray(reply)
def test(alias, dest, connection, verbose) :
    connection.network.send(makeframe(alias, dest))
    reply = connection.network.receive()
    if (reply == None ) : 
        print "Expected reply to good request not received"
        return 2
    if not (reply.startswith(":X19668") and int(reply[11:15],16)==alias and int(reply[7:10],16)==dest) :
        print "Unexpected reply received ", reply
        return 1
    if verbose : 
        print "  Node supports:"
        value = canolcbutils.bodyArray(reply)
        if (value[2] & 0x80) != 0 : print "      Protocol Identification"
        if (value[2] & 0x40) != 0 : print "      Datagram Protocol"
        if (value[2] & 0x20) != 0 : print "      Stream Protocol"
        if (value[2] & 0x10) != 0 : print "      Memory Configuration Protocol"
        if (value[2] & 0x08) != 0 : print "      Reservation Protocol"
        if (value[2] & 0x04) != 0 : print "      Event Exchange (P/C) Protocol"
        if (value[2] & 0x02) != 0 : print "      Identification Protocol"
        if (value[2] & 0x01) != 0 : print "      Teaching/Learning Protocol"
        if (value[3] & 0x80) != 0 : print "      Remote Button Protocol"
        if (value[3] & 0x40) != 0 : print "      Abbreviated Default CDI Protocol"
        if (value[3] & 0x20) != 0 : print "      Display Protocol"
        if (value[3] & 0x10) != 0 : print "      Simple Node Information Protocol"
        if (value[3] & 0x08) != 0 : print "      Configuration Description Information"

    if verbose : print "  not addressed, expect no reply"
    connection.network.send(makeframe(alias, (~dest)&0xFFF))
    reply = connection.network.receive()
    if (reply != None ) : 
        print "Unexpected reply received to request to different node ", reply
        return 1

    # test expansion by sending a start-only, then an end-only frame
        
    body = [((dest>>8)&0xFF)|0x10, dest&0xFF,0,0, 0,0,0,0]
    frame = canolcbutils.makeframestring(0x19828000+alias,body)
    connection.network.send(frame)

    reply = connection.network.receive()

    body = [((dest>>8)&0xFF)|0x20, dest&0xFF,0,0, 0,0,0,0]
    frame = canolcbutils.makeframestring(0x19828000+alias,body)
    connection.network.send(frame)

    if (reply == None ) : # if no reply to 1st frame, see if reply to 2nd frame; either OK
        reply = connection.network.receive()

    if (reply == None ) : 
        print "Expected reply to double frame not received"
        return 2
    if not (reply.startswith(":X19668") and int(reply[11:15],16)==alias and int(reply[7:10],16)==dest) :
        print "Unexpected reply received ", reply
        return 1

    reply = connection.network.receive()
    if (reply != None ) : 
        print "  Suggestion: PIP should handle start-end bits in requests for future expansion"

    return 0
Пример #8
0
def get(alias, nodeID, verbose) :
    connection.network.send(verifyNodeGlobal.makeframe(alias, nodeID))
    while (True) :
        reply = connection.network.receive()
        if (reply == None ) : return None,None
        if (reply.startswith(":X19170")) :
            alias,nodeID = int(reply[7:10],16),canolcbutils.bodyArray(reply)
            if verbose : print "Found alias "+str(alias)+" ("+hex(alias)+") for node ID ",nodeID
            return alias,nodeID
Пример #9
0
def get(alias, nodeID, verbose):
    connection.network.send(verifyNodeGlobal.makeframe(alias, nodeID))
    while (True):
        reply = connection.network.receive()
        if (reply == None): return None, None
        if (reply.startswith(":X19170")):
            alias, nodeID = int(reply[7:10], 16), canolcbutils.bodyArray(reply)
            if verbose:
                print "Found alias " + str(alias) + " (" + hex(
                    alias) + ") for node ID ", nodeID
            return alias, nodeID
Пример #10
0
def receiveOneDatagram(alias, dest, conection, verbose) :
    retval = []
    reply = connection.network.receive()

    if reply.startswith(":X1A"):
      if not int(reply[4:7],16) == alias:
        print "Improper dest alias in reply", reply
        return 3
      if not int(reply[7:10],16) == dest:
        print "Improper source alias in reply", reply
        return 3
      retval = retval + canolcbutils.bodyArray(reply)
      connection.network.send(makereply(alias, dest))
      return retval

    if reply.startswith(":X1B"):
      if not int(reply[4:7],16) == alias:
        print "Improper dest alias in reply", reply
        return 3
      if not int(reply[7:10],16) == dest:
        print "Improper source alias in reply", reply
        return 3
      retval = retval + canolcbutils.bodyArray(reply)
    else:
      print "Unexpected message instead of first datagram segment", reply
      return 3
    while True :
        reply = connection.network.receive()
        if (reply == None ) : 
            print "No datagram segment received"
            return 4
        elif reply.startswith(":X1C") :
            retval = retval + canolcbutils.bodyArray(reply)
            continue
        elif reply.startswith(":X1D") :
            retval = retval + canolcbutils.bodyArray(reply)
            connection.network.send(makereply(alias, dest))
            return retval
        else :
            print "Unexpected message instead of datagram segment", reply
            return 3
def test(alias, dest, connection, verbose) :
    connection.network.send(makeframe(alias, dest))
    body = [(alias>>8)&0xFF, alias&0xFF]
    expect = canolcbutils.makeframestring(0x19668000 + dest, body)
    expect = expect[:-1]
    reply = connection.network.expect(startswith=expect)
    if (reply == None) :
        print "Expected reply to good request not received"
        return 2
    if (verbose) : 
        print "  Node supports:"
        value = canolcbutils.bodyArray(reply)
        if (value[2] & 0x80) != 0 : print "      Protocol Identification"
        if (value[2] & 0x40) != 0 : print "      Datagram Protocol"
        if (value[2] & 0x20) != 0 : print "      Stream Protocol"
        if (value[2] & 0x10) != 0 : print "      Memory Configuration Protocol"
        if (value[2] & 0x08) != 0 : print "      Reservation Protocol"
        if (value[2] & 0x04) != 0 : print "      Event Exchange (P/C) Protocol"
        if (value[2] & 0x02) != 0 : print "      Identification Protocol"
        if (value[2] & 0x01) != 0 : print "      Teaching/Learning Protocol"
        if (value[3] & 0x80) != 0 : print "      Remote Button Protocol"
        if (value[3] & 0x40) != 0 : print "      Abbreviated Default CDI Protocol"
        if (value[3] & 0x20) != 0 : print "      Display Protocol"
        if (value[3] & 0x10) != 0 : print "      Simple Node Information Protocol"
        if (value[3] & 0x08) != 0 : print "      Configuration Description Information"
        if (value[3] & 0x04) != 0 : print "      Traction Control Protocol"
        if (value[3] & 0x02) != 0 : print "      Function Description Information"
        if (value[3] & 0x01) != 0 : print "      DCC Command Station Protocol"
        if (value[4] & 0x80) != 0 : print "      SimpleTrain Node Information"
        if (value[4] & 0x40) != 0 : print "      Function Configuration"
        if (value[4] & 0x20) != 0 : print "      Firmware Upgrade Protocol"
        if (value[4] & 0x10) != 0 : print "      Firmware Upgrade Active"

    if (verbose) :
        print "  not addressed, expect no reply"
    connection.network.send(makeframe(alias, (~dest)&0xFFF))
    body = [(alias>>8)&0xFF, alias&0xFF]
    expect = canolcbutils.makeframestring(0x19668000 + dest, body)
    expect = expect[:-1]
    reply = connection.network.expect(startswith=expect)
    if (reply != None ) : 
        print "Unexpected reply received to request to different node ", reply
        return 1

    return 0
def test(alias, dest, connection, verbose):
    if verbose: print "  check valid request"
    connection.network.send(makeframe(alias, dest))

    mfgName = ""
    mfgType = ""
    mfgHVers = ""
    mfgSVers = ""
    userName = ""
    userComment = ""
    fill = 0  # 0 is format byte, 1 is name, 2 is type, 3 is vers

    # assume always sends the same number of frames
    count = 0

    while (True):
        reply = connection.network.receive()
        if reply == None:
            break
        if not (reply.startswith(":X19A08") and int(reply[7:10], 16) == dest
                and int(reply[11:15], 16) == alias):
            print "Unexpected reply received ", reply
            return 1
        # process content
        val = canolcbutils.bodyArray(reply)
        count = count + 1
        for c in val[2:]:
            if fill == 0:
                fill = 1
                if c != 1:
                    print "First byte of first part should have been one, was ", c
                    return 3
            elif fill == 1:
                mfgName = mfgName + chr(c)
            elif fill == 2:
                mfgType = mfgType + chr(c)
            elif fill == 3:
                mfgHVers = mfgHVers + chr(c)
            elif fill == 4:
                mfgSVers = mfgSVers + chr(c)
            elif fill == 5:
                fill = 6
                if c != 1:
                    print "First byte of second part should have been one, was ", c
                    return 4
            elif fill == 6:
                userName = userName + chr(c)
            elif fill == 7:
                userComment = userComment + chr(c)
            else:
                print "Unexpected extra content", c
                return 15
            if c == 0:  # end of string
                fill = fill + 1
    if fill != 8 and fill != 5:
        print "Didn't receive all strings", fill
        return fill + 10
    if verbose:
        print "       Manufacturer: ", mfgName
        print "               Type: ", mfgType
        print "   Hardware Version: ", mfgHVers
        print "   Software Version: ", mfgSVers
        if fill == 8:
            print "          User Name: ", userName
            print "       User Comment: ", userComment

    if verbose: print "  address other node, expect no reply"
    connection.network.send(makeframe(alias, (~dest) & 0xFFF))
    reply = connection.network.receive()
    if reply != None:
        print "Unexpected reply received ", reply

    if verbose: print "  check three simultaneous requests"
    alias2 = (alias + 1) & 0xFFF
    if alias2 == dest: alias2 = (alias2 + 1) & 0xFFF
    alias3 = (alias + 10) & 0xFFF
    if alias3 == dest: alias3 = (alias3 + 10) & 0xFFF

    #frame = makeframe(alias, dest)+makeframe(alias2, dest)+makeframe(alias3, dest)
    #connection.network.send(frame)
    connection.network.send(makeframe(alias, dest))
    connection.network.send(makeframe(alias2, dest))
    connection.network.send(makeframe(alias3, dest))

    count1 = 0
    count2 = 0
    count3 = 0
    while (True):
        reply = connection.network.receive()
        if reply == None:
            break
        if (reply.startswith(":X19A08") and int(reply[7:10], 16) == dest
                and int(reply[11:15], 16) == alias):
            count1 = count1 + 1
        if (reply.startswith(":X19068") and int(reply[7:10], 16) == dest
                and int(reply[11:15], 16) == alias):
            count1 = count1 - 100
        if (reply.startswith(":X19A08") and int(reply[7:10], 16) == dest
                and int(reply[11:15], 16) == alias2):
            count2 = count2 + 1
        if (reply.startswith(":X19068") and int(reply[7:10], 16) == dest
                and int(reply[11:15], 16) == alias2):
            count2 = count2 - 100
        if (reply.startswith(":X19A08") and int(reply[7:10], 16) == dest
                and int(reply[11:15], 16) == alias3):
            count3 = count3 + 1
        if (reply.startswith(":X19068") and int(reply[7:10], 16) == dest
                and int(reply[11:15], 16) == alias3):
            count3 = count3 - 100
    if count != count1 and count1 != -100:
        print "got ", count1, " frames for request 1 instead of ", count
        return 101
    if count != count2 and count2 != -100:
        print "got ", count2, " frames for request 2 instead of ", count
        return 102
    if count != count3 and count3 != -100:
        print "got ", count3, " frames for request 3 instead of ", count
        return 103

    return 0
Пример #13
0
def test(alias, dest, connection, verbose):
    # wait for reset

    # expect RIF sequence (check timing)
    timeout = connection.network.timeout
    connection.network.timeout = 25
    connection.network.connect()
    if verbose: print "Restart node now"
    reply = connection.network.receive()
    if verbose: print "Start checking node output"
    while (True):
        if reply == None:
            print "1st CIM reply not received, did you reset node?"
            return 1
        elif reply.startswith(":X17"):
            break
        elif reply.startswith(":X"):
            if verbose: print "ignoring unexpected frame", reply
        else:
            if verbose: print "ignoring misc characters not a frame: ", reply
        reply = connection.network.receive()

    connection.network.timeout = timeout
    testAlias = reply[7:10]
    if testAlias == "000":
        print "node using alias == 0"
        return 331

    id = reply[4:7]
    start = time.time()

    reply = connection.network.receive()
    if reply == None:
        print "2nd CIM reply not received"
        return 2
    if reply[7:10] != testAlias:
        print "mismatched 2nd CIM source alias"
        return 12
    if not reply.startswith(":X16"):
        print "2nd CIM reply not correct"
        return 32
    id = id + reply[4:7]

    reply = connection.network.receive()
    if reply == None:
        print "3rd CIM reply not received"
        return 3
    if reply[7:10] != testAlias:
        print "mismatched 3rd CIM source alias"
        return 13
    if not reply.startswith(":X15"):
        print "3rd CIM reply not correct"
        return 33
    id = id + reply[4:7]

    reply = connection.network.receive()
    if reply == None:
        print "4th CIM reply not received"
        return 4
    if reply[7:10] != testAlias:
        print "mismatched 4th CIM source alias"
        return 14
    if not reply.startswith(":X14"):
        print "4th CIM reply not correct"
        return 34
    id = id + reply[4:7]

    # expect CIF (check timing)
    connection.network.timeout = 1
    reply = connection.network.receive()
    end = time.time()
    connection.network.timeout = timeout
    if reply == None:
        print "RIM reply not received"
        return 5
    if not reply.startswith(":X10700"):
        print "RIM reply not correct"
        return 35
    if reply[7:10] != testAlias:
        print "mismatched RIM source alias"
        return 15

    if verbose: print "delay was ", end - start

    if end - start < 0.15:
        # some tolerance on check...
        print "did not wait long enough ", end - start
        return 22
    if end - start > .55:
        # some tolerance on check...
        print "waited too long ", end - start
        return 22

    # expect AMD
    reply = connection.network.receive()
    if reply == None:
        print "AMD reply not received"
        return 6
    if not reply.startswith(":X10701"):
        print "AMD reply not correct"
        return 35
    if reply[7:10] != testAlias:
        print "mismatched AMD source alias"
        return 16
    if id != reply[11:23]:
        print "AMD node ID ", reply[
            11:23], " did not match one in CID frames ", id
        return 21

    # expect NodeInit
    reply = connection.network.receive()
    if reply == None:
        print "NodeInit reply not received"
        return 7
    if not reply.startswith(":X19100"):
        print "NodeInit reply not correct"
        return 37
    if reply[7:10] != testAlias:
        print "mismatched NodeInit source alias"
        return 17
    if id != reply[11:23]:
        print "NodeInit node ID did not match", id, reply[11:23]
        return 27

    # expect one or more Produced/Consumed messages

    consumed = []
    produced = []
    while (True):
        reply = connection.network.receive()
        if (reply == None): break
        if (reply.startswith(":X194C")):
            event = canolcbutils.bodyArray(reply)
            if verbose: print "consumes ", event
            consumed = consumed + [event]
        elif (reply.startswith(":X1954")):
            event = canolcbutils.bodyArray(reply)
            if verbose: print "produces ", event
            produced = produced + [event]
        elif (reply.startswith(":X195B4")):
            event = canolcbutils.bodyArray(reply)
            if verbose: print "event produced", event
        else:
            print "Unexpected message"
            return 50
    return 0
Пример #14
0
def test(alias, dest, connection, verbose) :
    # wait for reset
    
    # expect RIF sequence (check timing)
    timeout = connection.network.timeout
    connection.network.timeout = 25
    connection.network.connect()
    if verbose : print "Restart node now"
    reply = connection.network.receive()
    if verbose : print "Start checking node output"
    while (True) :
        if reply == None :
            print "1st CIM reply not received, did you reset node?"
            return 1
        elif reply.startswith(":X17") :
            break
        elif reply.startswith(":X") :
            if verbose: print "ignoring unexpected frame", reply
        else :
            if verbose: print "ignoring misc characters not a frame: ", reply
        reply = connection.network.receive()
        
    connection.network.timeout = timeout
    testAlias = reply[7:10]
    if testAlias == "000" :
        print "node using alias == 0"
        return 331
        
    id = reply[4:7]
    start = time.time()
    
    reply = connection.network.receive()
    if reply == None :
        print "2nd CIM reply not received"
        return 2
    if reply[7:10] != testAlias :
        print "mismatched 2nd CIM source alias"
        return 12
    if not reply.startswith(":X16") :
        print "2nd CIM reply not correct"
        return 32
    id = id+reply[4:7]

    reply = connection.network.receive()
    if reply == None :
        print "3rd CIM reply not received"
        return 3
    if reply[7:10] != testAlias :
        print "mismatched 3rd CIM source alias"
        return 13
    if not reply.startswith(":X15") :
        print "3rd CIM reply not correct"
        return 33
    id = id+reply[4:7]

    reply = connection.network.receive()
    if reply == None :
        print "4th CIM reply not received"
        return 4
    if reply[7:10] != testAlias :
        print "mismatched 4th CIM source alias"
        return 14
    if not reply.startswith(":X14") :
        print "4th CIM reply not correct"
        return 34
    id = id+reply[4:7]
    
    # expect CIF (check timing)
    connection.network.timeout = 1 
    reply = connection.network.receive()
    end = time.time()
    connection.network.timeout = timeout
    if reply == None :
        print "RIM reply not received"
        return 5
    if not reply.startswith(":X10700") :
        print "RIM reply not correct"
        return 35
    if reply[7:10] != testAlias :
        print "mismatched RIM source alias"
        return 15

    if verbose : print "delay was ", end-start

    if end-start < 0.15 :
        # some tolerance on check...
        print "did not wait long enough ", end-start
        return 22
    if end-start > .55 :
        # some tolerance on check...
        print "waited too long ", end-start
        return 22

    # expect AMD
    reply = connection.network.receive()
    if reply == None :
        print "AMD reply not received"
        return 6
    if not reply.startswith(":X10701") :
        print "AMD reply not correct"
        return 35
    if reply[7:10] != testAlias :
        print "mismatched AMD source alias"
        return 16
    if id != reply[11:23] :
        print "AMD node ID ",reply[11:23]," did not match one in CID frames ",id
        return 21
    
    # expect NodeInit
    reply = connection.network.receive()
    if reply == None :
        print "NodeInit reply not received"
        return 7
    if not reply.startswith(":X19100") :
        print "NodeInit reply not correct"
        return 37
    if reply[7:10] != testAlias :
        print "mismatched NodeInit source alias"
        return 17
    if id != reply[11:23] :
        print "NodeInit node ID did not match",id, reply[11:23]
        return 27
    
    # expect one or more Produced/Consumed messages

    consumed = []
    produced = []
    while (True) :
        reply = connection.network.receive()
        if (reply == None ) : break
        if (reply.startswith(":X194C")) :
            event = canolcbutils.bodyArray(reply)
            if verbose : print "consumes ", event
            consumed = consumed+[event]
        elif (reply.startswith(":X1954")) :
            event = canolcbutils.bodyArray(reply)
            if verbose : print "produces ", event
            produced = produced+[event]
        elif (reply.startswith(":X195B4")) :
            event = canolcbutils.bodyArray(reply)
	    if verbose : print "event produced", event
        else :
            print "Unexpected message"
            return 50
    return 0
def test(alias, dest, connection, verbose) :
    if verbose : print "  check valid request" 
    connection.network.send(makeframe(alias, dest))
    
    mfgName = ""
    mfgType = ""
    mfgHVers = ""
    mfgSVers = ""
    userName = ""
    userComment = ""
    fill = 0   # 0 is format byte, 1 is name, 2 is type, 3 is vers
    
    # assume always sends the same number of frames
    count = 0
    
    while (True) :
        reply = connection.network.receive()
        if reply == None :
            break
        if not (reply.startswith(":X19A08") and int(reply[7:10],16)==dest and int(reply[11:15],16)==alias) :
            print "Unexpected reply received ", reply
            return 1
        # process content
        val = canolcbutils.bodyArray(reply)
        count = count + 1
        for c in val[2:] :
            if fill == 0 :
                fill = 1
                if c != 1 :
                    print "First byte of first part should have been one, was ",c
                    return 3
            elif fill == 1 : 
                mfgName = mfgName+chr(c)
            elif fill == 2 :
                mfgType = mfgType+chr(c)         
            elif fill == 3 :
                mfgHVers = mfgHVers+chr(c)         
            elif fill == 4 :
                mfgSVers = mfgSVers+chr(c)         
            elif fill == 5 :
                fill = 6
                if c != 1 :
                    print "First byte of second part should have been one, was ",c
                    return 4
            elif fill == 6 :
                userName = userName+chr(c)         
            elif fill == 7 :
                userComment = userComment+chr(c)         
            else :
                print "Unexpected extra content", c
                return 15
            if c == 0 :   # end of string
                fill = fill + 1
    if fill != 8 and fill != 5:
        print "Didn't receive all strings", fill
        return fill+10
    if verbose :
        print "       Manufacturer: ", mfgName
        print "               Type: ", mfgType
        print "   Hardware Version: ", mfgHVers
        print "   Software Version: ", mfgSVers
        if fill == 8 :
            print "          User Name: ", userName
            print "       User Comment: ", userComment

    if verbose : print "  address other node, expect no reply"
    connection.network.send(makeframe(alias, (~dest)&0xFFF))
    reply = connection.network.receive()
    if reply != None : 
        print "Unexpected reply received ", reply
        
    if verbose : print "  check three simultaneous requests"
    alias2 = (alias+1)&0xFFF
    if alias2 == dest : alias2 = (alias2+1)&0xFFF
    alias3 = (alias+10)&0xFFF
    if alias3 == dest : alias3 = (alias3+10)&0xFFF
    
    #frame = makeframe(alias, dest)+makeframe(alias2, dest)+makeframe(alias3, dest)
    #connection.network.send(frame)
    connection.network.send(makeframe(alias, dest))
    connection.network.send(makeframe(alias2, dest))
    connection.network.send(makeframe(alias3, dest))

    count1 = 0
    count2 = 0
    count3 = 0
    while (True) :
        reply = connection.network.receive()
        if reply == None :
            break
        if (reply.startswith(":X19A08") and int(reply[7:10],16)==dest and int(reply[11:15],16)==alias) :
            count1 = count1+1
        if (reply.startswith(":X19068") and int(reply[7:10],16)==dest and int(reply[11:15],16)==alias) :
            count1 = count1-100
        if (reply.startswith(":X19A08") and int(reply[7:10],16)==dest and int(reply[11:15],16)==alias2) :
            count2 = count2+1
        if (reply.startswith(":X19068") and int(reply[7:10],16)==dest and int(reply[11:15],16)==alias2) :
            count2 = count2-100
        if (reply.startswith(":X19A08") and int(reply[7:10],16)==dest and int(reply[11:15],16)==alias3) :
            count3 = count3+1
        if (reply.startswith(":X19068") and int(reply[7:10],16)==dest and int(reply[11:15],16)==alias3) :
            count3 = count3-100
    if count != count1 and count1 != -100: 
        print "got ",count1," frames for request 1 instead of ",count
        return 101
    if count != count2 and count2 != -100: 
        print "got ",count2," frames for request 2 instead of ",count
        return 102
    if count != count3 and count3 != -100: 
        print "got ",count3," frames for request 3 instead of ",count
        return 103

    return 0