1# SPDX-License-Identifier: GPL-2.0+ 2""" 3This file helps to extract string names of NI signals as included in comedi.h 4between NI_NAMES_BASE and NI_NAMES_BASE+NI_NUM_NAMES. 5""" 6 7# This is simply to aide in creating the entries in the order of the value of 8# the device-global NI signal/terminal constants defined in comedi.h 9import comedi_h 10 11 12ni_macros = ( 13 'NI_PFI', 14 'TRIGGER_LINE', 15 'NI_RTSI_BRD', 16 'NI_CtrSource', 17 'NI_CtrGate', 18 'NI_CtrAux', 19 'NI_CtrA', 20 'NI_CtrB', 21 'NI_CtrZ', 22 'NI_CtrArmStartTrigger', 23 'NI_CtrInternalOutput', 24 'NI_CtrOut', 25 'NI_CtrSampleClock', 26) 27 28def get_ni_names(): 29 name_dict = dict() 30 31 # load all the static names; start with those that do not begin with NI_ 32 name_dict['PXI_Star'] = comedi_h.PXI_Star 33 name_dict['PXI_Clk10'] = comedi_h.PXI_Clk10 34 35 #load all macro values 36 for fun in ni_macros: 37 f = getattr(comedi_h, fun) 38 name_dict.update({ 39 '{}({})'.format(fun,i):f(i) for i in range(1 + f(-1) - f(0)) 40 }) 41 42 #load everything else in ni_common_signal_names enum 43 name_dict.update({ 44 k:v for k,v in comedi_h.__dict__.items() 45 if k.startswith('NI_') and (not callable(v)) and 46 comedi_h.NI_COUNTER_NAMES_MAX < v < (comedi_h.NI_NAMES_BASE + comedi_h.NI_NUM_NAMES) 47 }) 48 49 # now create reverse lookup (value -> name) 50 51 val_dict = {v:k for k,v in name_dict.items()} 52 53 return name_dict, val_dict 54 55name_to_value, value_to_name = get_ni_names() 56