Exemplo n.º 1
0
def dump_pd_all(pd, num_packets):
    packetnum = 0

    print "index,time(us),PD,cc,status,sop,header,data0 ... dataN,crc"
    print " or"
    print "index,time(us),PD_IV,type,value"

    while (num_packets <= 0 or packetnum < num_packets):
        ret, info, pl, header, crc, data = pd_py.pd_usbpd_read_data(pd, 512)
        if ret != pd_py.PD_READ_EMPTY:
            if ret < 0:
                print('Failed to capture PD on port: %d(%s)' %
                      (ret, pd_py.pd_status_string(ret)))
                break

            print_pd_packets(packetnum, info, pl, header, crc, data)

            packetnum += 1

        ret, info, val = pd_py.pd_usbpd_read_iv(pd)
        if ret != pd_py.PD_READ_EMPTY:
            if ret < 0:
                print('Failed to capture PD on port: %d(%s)' %
                      (ret, pd_py.pd_status_string(ret)))
                break

            print_pd_iv(packetnum, info, val)

            packetnum += 1
Exemplo n.º 2
0
def detect_pd():
    print "Searching for Power Delivery Analyzers..."

    # Find all the attached devices
    ret = pd_py.pd_find_devices_ext(16, 16)
    if type(ret) is int:
        print "Unable to find: %d(%s)" % (ret, pd_py.pd_status_string(ret))
        exit(0)

    (num, ports, unique_ids) = ret

    if num > 0:
        print "%d device(s) found:" % num

        # Print the information on each device
        for i in range(num):
            port      = ports[i]
            unique_id = unique_ids[i]

            # Determine if the device is in-use
            inuse = "(avail)"
            if (port & pd_py.PD_PORT_NOT_FREE):
                inuse = "(in-use)"
                port  = port & ~pd_py.PD_PORT_NOT_FREE

            # Display device port number, in-use status, and serial number
            print "    port = %d   %s  (%04d-%06d)" % \
                (port, inuse, unique_id / 1000000, unique_id % 1000000)

    else:
        print "No devices found."

    return ports, unique_ids
Exemplo n.º 3
0
def dump_pd_data(pd, num_packets):
    packetnum = 0

    print "index,time(us),PD,cc,status,sop,header,data0 ... dataN,crc"

    while (num_packets <= 0 or packetnum < num_packets):
        # maximum bit length of USB PD v3.0 is 2769 bits = 347 bytes
        ret, info, pl, header, crc, data = pd_py.pd_usbpd_read_data(pd, 512)
        if ret == pd_py.PD_READ_EMPTY:
            continue

        if ret < 0:
            print('Failed to capture PD on port: %d(%s)' %
                  (ret, pd_py.pd_status_string(ret)))
            break

        print_pd_packets(packetnum, info, pl, header, crc, data)

        packetnum += 1
Exemplo n.º 4
0
def dump_pd_raw(pd, num_packets):
    packetnum = 0

    print "index,time(us),PD,status,cc,preamble,bits"

    while (num_packets <= 0 or packetnum < num_packets):
        # maximum bit length of USB PD v3.0 is 2769 bits = 347 bytes
        ret, info, bl, pl, bits = pd_py.pd_usbpd_read_bits(pd, 512)
        if ret == pd_py.PD_READ_EMPTY:
            continue

        if ret < 0:
            print('Failed to capture PD on port: %d(%s)' %
                  (ret, pd_py.pd_status_string(ret)))
            break

        print_bits(packetnum, info, bits, pl, bl)

        packetnum += 1
Exemplo n.º 5
0
def capture_usbpd(port=0, mode='iv', num=10, debug=0):
    '''
    if (len(sys.argv) < 3):
        print_usage()
        sys.exit()

    port = int(sys.argv[1])
    mode = sys.argv[2]
    num  = int(sys.argv[3]) if len(sys.argv) == 4 else 0
    '''

    data = []

    # Open the device
    pd = pd_py.pd_open(port)
    if (pd <= 0):
        print('Unable to open PD Analyzer on port %d: %d(%s)' %
              (port, pd, pd_py.pd_status_string(pd)))
        sys.exit(1)
    print 'Opened PD Analyzer on port %d' % port

    # Start capture
    pd_py.pd_capture_start(pd)

    print 'Start capturing'
    if mode == 'raw':
        dump_pd_raw(num)
    if mode == 'data':
        dump_pd_data(num)
    if mode == 'iv':
        data = dump_pd_iv(pd, num, debug)
    if mode == 'all':
        dump_pd_all(num)

    # Stop capture
    pd_py.pd_capture_stop(pd)

    # Close the device
    pd_py.pd_close(pd)

    return data
Exemplo n.º 6
0
def dump_pd_iv(pd, num_packets, debug):
    packetnum = 0
    data = []

    print "index,time(us),PD_IV,type,value"

    while (num_packets <= 0 or packetnum < num_packets):
        ret, info, val, real_time = pd_py.pd_usbpd_read_iv(pd)
        if ret == pd_py.PD_READ_EMPTY:
            continue

        if ret < 0:
            print('Failed to capture PD on port: %d(%s)' %
                  (ret, pd_py.pd_status_string(ret)))
            break

        # Create a list of lists with single data points
        data.append(print_pd_iv(packetnum, info, val, debug, real_time))

        packetnum += 1
    return data