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