コード例 #1
0
def highlight_search_pattern(data, pattern):
    result = check_bit_shift(data, pattern)

    if result == 0:
        return (True, fg.green + hex_pad(data) + fg.rs)
    elif result > 0:
        return (True, fg.yellow + hex_pad(data) + fg.rs)
    else:
        return (False, hex_pad(data))
コード例 #2
0
 def gbld_cur_to_reg(cls, cur):
     for reg in range(256):
         reg = hex_pad(reg)
         if cls.gbld_reg_to_cur(reg) < cur:
             pass
         else:
             return reg
コード例 #3
0
def check_bit_shift(data, expected=0xc4):
    size = num_of_bit(hex_pad(expected))

    for shift in range(size):
        # We choose to shift DATA (This is chosen to make manipulating OUR
        # hardware more easily).
        if bit_shift(data, shift, size) == expected:
            return shift

    return -1
コード例 #4
0
ファイル: phase.py プロジェクト: umd-lhcb/nanoDAQ
def scan_phase_elink(loop_result,
                     phases=DCB_ELK_VALID_PHASE,
                     selector=scan_phase_elink_selector):
    printout = [list() for _ in range(len(phases) + 1)]
    good_patterns_chs = defaultdict(lambda: defaultdict(list))

    for ph, chs_data in loop_result.items():
        idx = int(ph, base=16)
        printout[idx].append(ph)

        for ch, data in chs_data.items():
            num_of_frame = len(data)
            mode, freq = most_common(data)
            mode_display = hex_pad(mode)
            shift = check_bit_shift(mode)

            selector(mode_display, freq, num_of_frame, shift, idx, ph, ch,
                     printout, good_patterns_chs)

    # Now try to find optimum phases.
    common_patterns = intersect_good_pattern(good_patterns_chs)

    # Local optimal: Picking the longest good phase for the first channel.
    # NOTE: This algorithm should be stable.
    first_ch = next(iter(good_patterns_chs))
    common_patterns_freq = {
        k: len(good_patterns_chs[first_ch][k])
        for k in common_patterns
    }
    pattern = Counter(common_patterns_freq).most_common(1)[0][0]
    phase_per_ch = {
        ch: mid_elem(good_patterns_chs[ch][pattern])
        for ch in good_patterns_chs.keys()
    }

    good_phase_printout = [
        phase_per_ch[i] for i in sorted(phase_per_ch, reverse=True)
    ]

    # Update printout table.
    for idx, ph in enumerate(good_phase_printout):
        ph = int(ph, base=16)
        printout[ph][idx + 1] = fg.li_green + printout[ph][idx + 1] + fg.rs

    return printout, phase_per_ch, int(pattern, base=16)
コード例 #5
0
def highlight_chs(data, ch, chs):
    if ch in chs:
        return (True, fg.blue + hex_pad(data) + fg.rs)
    else:
        return (False, hex_pad(data))
コード例 #6
0
def highlight_non_mode(data, mode):
    if data != mode:
        return (True, fg.blue + hex_pad(data) + fg.rs)
    else:
        return (False, hex_pad(data))
コード例 #7
0
ファイル: phaseadj.py プロジェクト: umd-lhcb/nanoDAQ
    else:
        elk_op = input2bool('Continue to elink phase adjustment?')

    if elk_op:
        print('Generating phase-scanning table, this may take awhile...')
        elk_scan_raw = loop_phase_elk(daq_chs, args.gbt, args.slave)
        elk_scan_tab, elk_adj, elk_pattern = scan_phase_elink(elk_scan_raw)
        print(
            tabulate(elk_scan_tab,
                     headers=['phase'] + daq_chs,
                     colalign=['left'] + ['right'] * len(daq_chs)))

        if len(elk_adj) == len(daq_chs):
            print(
                'Current fixed pattern is {}, adjusting DCB and SALT phase...'.
                format(hex_pad(elk_pattern)))
            adj_dcb_elink_phase(elk_adj, args.gbt, args.slave)
            adj_salt_elink_phase(elk_pattern, args.gbt, args.bus, args.asic)
            success = True

    # Adjust TFC phase #########################################################

    if args.adjust_tfc_phase is not None:
        tfc_op = args.adjust_tfc_phase
    else:
        tfc_op = input2bool('Continue to TFC phase adjustment?')

    if tfc_op:
        salt_tfc_mode(args.gbt, args.bus, args.asic, mode='tfc')
        print('Tuning TFC phase, this may take awhile...')
        success = adj_salt_tfc_phase(daq_chs, args.gbt, args.bus, args.asic)