diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 21c02761a..f38ad61f0 100755 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -29,6 +29,7 @@ set( PYTHON_FILES decorators.py detector_property.py detector.py + defines.py eiger.py enums.py errors.py diff --git a/python/scripts/generate_enums.py b/python/scripts/generate_enums.py index b75062eb4..3d20e59b5 100644 --- a/python/scripts/generate_enums.py +++ b/python/scripts/generate_enums.py @@ -11,7 +11,7 @@ enums.cpp import re import subprocess -from parse import remove_comments +from parse import remove_comments, remove_ifdefs allow_bitwise_op = ["streamingInterface", "M3_GainCaps"] @@ -98,25 +98,25 @@ def generate_enum_string(enums): return ''.join(data) -def remove_ifdefs(lines): - """Keeps C++ version of the code""" - out = [] - it = iter(lines) - skip = False - for line in it: +# def remove_ifdefs(lines): +# """Keeps C++ version of the code""" +# out = [] +# it = iter(lines) +# skip = False +# for line in it: - if "#ifdef __cplusplus" in line: - line = next(it) +# if "#ifdef __cplusplus" in line: +# line = next(it) - if "#else" in line: - skip = True +# if "#else" in line: +# skip = True - if "#endif" in line: - skip = False +# if "#endif" in line: +# skip = False - if not skip and "#endif" not in line: - out.append(line) - return out +# if not skip and "#endif" not in line: +# out.append(line) +# return out with open('../../slsSupportLib/include/sls/sls_detector_defs.h') as f: diff --git a/python/scripts/generate_pydef.py b/python/scripts/generate_pydef.py new file mode 100644 index 000000000..bfe715a2d --- /dev/null +++ b/python/scripts/generate_pydef.py @@ -0,0 +1,30 @@ + + +import re +import subprocess + +from parse import remove_comments, remove_ifdefs + +with open('../../slsSupportLib/include/sls/sls_detector_defs.h') as f: + data = f.read() + +data = remove_comments(data) +data = data.splitlines() +# data = remove_ifdefs(data) + + +ignore = ['#define MYROOT', '#define __cplusplus'] + +defines = {} +for i, line in enumerate(data): + if line.startswith('#define') and line not in ignore: + _, name, value = line.split(maxsplit = 2) + print(f'{name}={value}') + defines[name]=value + + +warning = '#WARINING This file is auto generated any edits might be overwritten without warning\n\n' +with open('../slsdet/defines.py', 'w') as f: + f.write(warning) + for key, value in defines.items(): + f.write(f'{key}={value}\n') \ No newline at end of file diff --git a/python/scripts/parse.py b/python/scripts/parse.py index 19dd8d4d3..f620ab5e5 100644 --- a/python/scripts/parse.py +++ b/python/scripts/parse.py @@ -25,7 +25,25 @@ def remove_comments(text): ) return re.sub(pattern, replacer, text) +def remove_ifdefs(lines): + """Keeps C++ version of the code""" + out = [] + it = iter(lines) + skip = False + for line in it: + + if "#ifdef __cplusplus" in line: + line = next(it) + if "#else" in line: + skip = True + + if "#endif" in line: + skip = False + + if not skip and "#endif" not in line: + out.append(line) + return out #based on ccsyspath: https://github.com/AndrewWalker/ccsyspath diff --git a/python/slsdet/__init__.py b/python/slsdet/__init__.py index 4055393e8..efdb9aa6d 100755 --- a/python/slsdet/__init__.py +++ b/python/slsdet/__init__.py @@ -17,8 +17,9 @@ import _slsdet xy = _slsdet.xy defs = _slsdet.slsDetectorDefs +#Make enums and #defines available at top level from .enums import * - +from .defines import * IpAddr = _slsdet.IpAddr MacAddr = _slsdet.MacAddr diff --git a/python/slsdet/defines.py b/python/slsdet/defines.py new file mode 100644 index 000000000..699a287ee --- /dev/null +++ b/python/slsdet/defines.py @@ -0,0 +1,29 @@ +#WARINING This file is auto generated any edits might be overwritten without warning + +BIT32_MASK=0xFFFFFFFF +MAX_RX_DBIT=64 +DEFAULT_PORTNO=1952 +DEFAULT_UDP_PORTNO=50001 +DEFAULT_ZMQ_CL_PORTNO=30001 +DEFAULT_ZMQ_RX_PORTNO=30001 +DEFAULT_UDP_SRC_PORTNO=32410 +DEFAULT_UDP_DST_PORTNO=50001 +MAX_UDP_DESTINATION=32 +SLS_DETECTOR_HEADER_VERSION=0x2 +SLS_DETECTOR_JSON_HEADER_VERSION=0x4 +UDP_PACKET_DATA_BYTES=(1344) +MAX_TRIMEN=100 +MAX_BLACKFIN_PROGRAM_SIZE=(128 * 1024) +GET_FLAG=-1 +DEFAULT_DET_MAC="00:aa:bb:cc:dd:ee" +DEFAULT_DET_IP="129.129.202.45" +DEFAULT_DET_MAC2="00:aa:bb:cc:dd:ff" +DEFAULT_DET_IP2="129.129.202.46" +LOCALHOST_IP="127.0.0.1" +MAX_STR_LENGTH=1000 +SHORT_STR_LENGTH=20 +MAX_PATTERN_LENGTH=0x2000 +DEFAULT_STREAMING_TIMER_IN_MS=500 +NUM_RX_THREAD_IDS=9 +MAX_NUM_PACKETS=512 +TRIMBITMASK=0x3f