diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..326df788 --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +--- +Language: Cpp +BasedOnStyle: WebKit +PointerAlignment: Right +--- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..0022d3a0 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,19 @@ +name: Check repository +on: + push: + tags: + - '*' + branches: + - 'master' + + pull_request: + +jobs: + pre_commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - name: Install packages + run: sudo apt update -y && sudo apt install -y pre-commit clang-format + - name: Check pre-commit hooks + run: pre-commit run --show-diff-on-failure --color=always --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..5d4d82bd --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: + - repo: local + hooks: + - id: clang-format + name: clang-format + entry: clang-format -i + language: system + files: ^xspress3App/ + types: + - file + - c++ diff --git a/xspress3App/src/tests/xspress3EpicsTest.cpp b/xspress3App/src/tests/xspress3EpicsTest.cpp index 57a5097a..9a6ff4f7 100644 --- a/xspress3App/src/tests/xspress3EpicsTest.cpp +++ b/xspress3App/src/tests/xspress3EpicsTest.cpp @@ -2,9 +2,9 @@ #define BOOST_TEST_MODULE Fixtures #include -#include -#include "xspress3Epics.h" #include "xspress3.h" +#include "xspress3Epics.h" +#include #define MAX_SPECTRA 4096 #define NUM_CHANNELS 10 @@ -12,12 +12,12 @@ // asynPorts seem to hang around even after the xspress destructor so use a new port name for each test suite. char asynPortHack = 1; -struct xspress3Det -{ +struct xspress3Det { Xspress3 xsp; Xspress3 *pXsp; - - xspress3Det() : xsp(&asynPortHack, NUM_CHANNELS) + + xspress3Det() + : xsp(&asynPortHack, NUM_CHANNELS) { pXsp = &xsp; BOOST_TEST_MESSAGE("setup xspress"); @@ -25,7 +25,7 @@ struct xspress3Det xsp.setWindow(0, 5, 0, 4); asynPortHack++; } - + ~xspress3Det() { if (pXsp == NULL) @@ -44,24 +44,24 @@ BOOST_AUTO_TEST_CASE(createSCAArray) BOOST_AUTO_TEST_CASE(createMCAArrayUInt32) { - size_t dims[2] = {MAX_SPECTRA, NUM_CHANNELS}; + size_t dims[2] = { MAX_SPECTRA, NUM_CHANNELS }; NDArray *pMCA; BOOST_CHECK(xsp.createMCAArray(dims, pMCA, NDUInt32) == false); } BOOST_AUTO_TEST_CASE(createMCAArrayFloat64) { - size_t dims[2] = {MAX_SPECTRA, NUM_CHANNELS}; + size_t dims[2] = { MAX_SPECTRA, NUM_CHANNELS }; NDArray *pMCA; BOOST_CHECK(xsp.createMCAArray(dims, pMCA, NDFloat64) == false); } BOOST_AUTO_TEST_CASE(readFrameDouble) { - size_t dims[2] = {MAX_SPECTRA, NUM_CHANNELS}; + size_t dims[2] = { MAX_SPECTRA, NUM_CHANNELS }; double *pMCAData, *pSCA; - pSCA = (double*)malloc(XSP3_SW_NUM_SCALERS * NUM_CHANNELS * 8); - pMCAData = (double*)malloc(MAX_SPECTRA * NUM_CHANNELS * 8); + pSCA = (double *)malloc(XSP3_SW_NUM_SCALERS * NUM_CHANNELS * 8); + pMCAData = (double *)malloc(MAX_SPECTRA * NUM_CHANNELS * 8); BOOST_CHECK(xsp.readFrame(pSCA, pMCAData, 1, MAX_SPECTRA) == false); free(pSCA); free(pMCAData); @@ -82,16 +82,16 @@ BOOST_AUTO_TEST_CASE(integration) NDArray *pMCA; double *pData; void *pSCA; - size_t dims[2] = {MAX_SPECTRA, NUM_CHANNELS}; + size_t dims[2] = { MAX_SPECTRA, NUM_CHANNELS }; xsp3 = xsp.getXsp3(); xsp.connect(); xsp.createMCAArray(dims, pMCA, NDFloat64); - pData = (double*)pMCA->pData; + pData = (double *)pMCA->pData; xsp.createSCAArray(pSCA); xsp3->histogram_start(xsp.getXsp3Handle(), -1); - xsp.readFrame(static_cast(pSCA), pData, 1, MAX_SPECTRA); + xsp.readFrame(static_cast(pSCA), pData, 1, MAX_SPECTRA); BOOST_CHECK(pData[0] == 1); - for (int i=0; irelease(); @@ -101,4 +101,3 @@ BOOST_AUTO_TEST_CASE(dataTask) { xspress3Config(&++asynPortHack, NUM_CHANNELS, 1, "127.0.0.1", 16, 16, MAX_SPECTRA, -1, -1, 1, 1); } - diff --git a/xspress3App/src/xsp3Api.cpp b/xspress3App/src/xsp3Api.cpp index c49f5dd0..73a6f20b 100644 --- a/xspress3App/src/xsp3Api.cpp +++ b/xspress3App/src/xsp3Api.cpp @@ -3,8 +3,8 @@ #define XSP3IF_DEBUG 0x100 /* Uncomment this line to enable debugging */ -xsp3Api::xsp3Api( asynUser * user ) : - pasynUser(user) +xsp3Api::xsp3Api(asynUser *user) + : pasynUser(user) { } xsp3Api::~xsp3Api() @@ -13,11 +13,11 @@ xsp3Api::~xsp3Api() int xsp3Api::set_sync_mode(int path, int sync_mode, int enb_global_reset, int gr_card) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_sync_mode( %i, %i, %i, %i ) = ", path, sync_mode, enb_global_reset, gr_card ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_sync_mode( %i, %i, %i, %i ) = ", path, sync_mode, enb_global_reset, gr_card); status = xsp3Api_set_sync_mode(path, sync_mode, enb_global_reset, gr_card); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -25,11 +25,11 @@ int xsp3Api::set_sync_mode(int path, int sync_mode, int enb_global_reset, int gr int xsp3Api::clocks_setup(int path, int card, int clk_src, int flags, int tp_type) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_clocks_setup( %d, %d, %d, %x, %d ) = ", path, card, clk_src, flags, tp_type ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_clocks_setup( %d, %d, %d, %x, %d ) = ", path, card, clk_src, flags, tp_type); status = xsp3Api_clocks_setup(path, card, clk_src, flags, tp_type); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -37,23 +37,23 @@ int xsp3Api::clocks_setup(int path, int card, int clk_src, int flags, int tp_typ int xsp3Api::close(int path) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_close( %d ) = ", path ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_close( %d ) = ", path); - status = xsp3Api_close( path ); + status = xsp3Api_close(path); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } -int xsp3Api::config(int ncards, int num_tf, char* baseIPaddress, int basePort, char* baseMACaddress, int nchan, int createmodule, char* modname, int debug, int card_index) +int xsp3Api::config(int ncards, int num_tf, char *baseIPaddress, int basePort, char *baseMACaddress, int nchan, int createmodule, char *modname, int debug, int card_index) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_config( %d, %d, %s, %d, %s, %d, %d, %s, %d, %d ) = ", ncards, num_tf, baseIPaddress, basePort, baseMACaddress, nchan, createmodule, modname, debug, card_index ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_config( %d, %d, %s, %d, %s, %d, %d, %s, %d, %d ) = ", ncards, num_tf, baseIPaddress, basePort, baseMACaddress, nchan, createmodule, modname, debug, card_index); - status = xsp3Api_config( ncards, num_tf, baseIPaddress, basePort, baseMACaddress, nchan, createmodule, modname, debug, card_index ); + status = xsp3Api_config(ncards, num_tf, baseIPaddress, basePort, baseMACaddress, nchan, createmodule, modname, debug, card_index); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -63,47 +63,47 @@ int xsp3Api::format_run(int path, int chan, int aux1_mode, int res_thres, int au int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_format_run( %d, %d, %d, %d, %d, %d, %d, %d ) = ", path, chan, aux1_mode, res_thres, aux2_cont, disables, aux2_mode, nbits_eng); - status = xsp3Api_format_run( path, chan, aux1_mode, res_thres, aux2_cont, disables, aux2_mode, nbits_eng); + status = xsp3Api_format_run(path, chan, aux1_mode, res_thres, aux2_cont, disables, aux2_mode, nbits_eng); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } int xsp3Api::getDeadtimeCorrectionParameters(int path, int chan, int *flags, - double *processDeadTimeAllEventGradient, - double *processDeadTimeAllEventOffset, - double *processDeadTimeInWindowOffset, - double *processDeadTimeInWindowGradient) + double *processDeadTimeAllEventGradient, + double *processDeadTimeAllEventOffset, + double *processDeadTimeInWindowOffset, + double *processDeadTimeInWindowGradient) { int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_getDeadtimeCorrectionParameters( %d, %d, &%d,", - path, chan, *flags ); + path, chan, *flags); - status = xsp3Api_getDeadtimeCorrectionParameters( path, chan, flags, - processDeadTimeAllEventGradient, - processDeadTimeAllEventOffset, - processDeadTimeInWindowOffset, - processDeadTimeInWindowGradient ); + status = xsp3Api_getDeadtimeCorrectionParameters(path, chan, flags, + processDeadTimeAllEventGradient, + processDeadTimeAllEventOffset, + processDeadTimeInWindowOffset, + processDeadTimeInWindowGradient); asynPrint(this->pasynUser, XSP3IF_DEBUG, " &%f, &%f, &%f, &%f ) = %d\n", - *processDeadTimeAllEventGradient, - *processDeadTimeAllEventOffset, - *processDeadTimeInWindowOffset, - *processDeadTimeInWindowGradient, - status ); + *processDeadTimeAllEventGradient, + *processDeadTimeAllEventOffset, + *processDeadTimeInWindowOffset, + *processDeadTimeInWindowGradient, + status); return status; } -char* xsp3Api::get_error_message() +char *xsp3Api::get_error_message() { char *message; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_get_error_message() = " ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_get_error_message() = "); message = xsp3Api_get_error_message(); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%s\n", message ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%s\n", message); return message; } @@ -111,11 +111,11 @@ char* xsp3Api::get_error_message() int xsp3Api::get_good_thres(int path, int chan, uint32_t *good_thres) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_get_good_thres( %d, %d ", path, chan ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_get_good_thres( %d, %d ", path, chan); - status = xsp3Api_get_good_thres( path, chan, good_thres); + status = xsp3Api_get_good_thres(path, chan, good_thres); - asynPrint(this->pasynUser, XSP3IF_DEBUG, ", &%d ) = %d\n", *good_thres, status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, ", &%d ) = %d\n", *good_thres, status); return status; } @@ -123,30 +123,30 @@ int xsp3Api::get_good_thres(int path, int chan, uint32_t *good_thres) int xsp3Api::get_window(int path, int chan, int win, uint32_t *low, uint32_t *high) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_get_window( %d, %d, %d ", path, chan, win ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_get_window( %d, %d, %d ", path, chan, win); - status = xsp3Api_get_window( path, chan, win, low, high); + status = xsp3Api_get_window(path, chan, win, low, high); - asynPrint(this->pasynUser, XSP3IF_DEBUG, ", &%d, &%d ) = %d\n", *low, *high, status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, ", &%d, &%d ) = %d\n", *low, *high, status); return status; } int xsp3Api::hist_dtc_read4d(int path, double *hist_buff, double *scal_buff, unsigned eng, unsigned aux, unsigned chan, unsigned tf, - unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf) + unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf) { int status; - status = xsp3Api_hist_dtc_read4d( path, hist_buff, scal_buff, eng, aux, chan, tf, - num_eng, num_aux, num_chan, num_tf); + status = xsp3Api_hist_dtc_read4d(path, hist_buff, scal_buff, eng, aux, chan, tf, + num_eng, num_aux, num_chan, num_tf); asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_hist_dtc_read4d( %d, [%f, %f, %f...], %p, %u, %u, %u, %u, %u, %u, %u, %u, ) = ", - path, - hist_buff[0],hist_buff[1],hist_buff[2], - scal_buff, eng, aux, chan, tf, - num_eng, num_aux, num_chan, num_tf); + path, + hist_buff[0], hist_buff[1], hist_buff[2], + scal_buff, eng, aux, chan, tf, + num_eng, num_aux, num_chan, num_tf); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -156,9 +156,9 @@ int xsp3Api::histogram_clear(int path, int first_chan, int num_chan, int first_f int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_clear( %d, %d, %d, %d, %d ) = ", path, first_chan, num_chan, first_frame, num_frames); - status = xsp3Api_histogram_clear( path, first_chan, num_chan, first_frame, num_frames); + status = xsp3Api_histogram_clear(path, first_chan, num_chan, first_frame, num_frames); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -166,11 +166,11 @@ int xsp3Api::histogram_clear(int path, int first_chan, int num_chan, int first_f int xsp3Api::histogram_pause(int path, int card) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_pause( %d, %d ) = ", path, card ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_pause( %d, %d ) = ", path, card); - status = xsp3Api_histogram_pause( path, card); + status = xsp3Api_histogram_pause(path, card); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -178,11 +178,11 @@ int xsp3Api::histogram_pause(int path, int card) int xsp3Api::histogram_arm(int path, int card) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_arm( %d, %d ) = ", path, card ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_arm( %d, %d ) = ", path, card); - status = xsp3Api_histogram_arm( path, card); + status = xsp3Api_histogram_arm(path, card); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -190,11 +190,11 @@ int xsp3Api::histogram_arm(int path, int card) int xsp3Api::histogram_continue(int path, int card) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_continue( %d, %d ) = ", path, card ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_continue( %d, %d ) = ", path, card); - status = xsp3Api_histogram_continue( path, card); + status = xsp3Api_histogram_continue(path, card); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -202,11 +202,11 @@ int xsp3Api::histogram_continue(int path, int card) int xsp3Api::histogram_is_any_busy(int path) { int status; -asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_is_any_busy( %d ) = ", path ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_is_any_busy( %d ) = ", path); status = xsp3Api_histogram_is_any_busy(path); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -215,11 +215,11 @@ int xsp3Api::histogram_read4d(int path, uint32_t *buffer, unsigned eng, unsigned { int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_read4d( %d, &%u..., %u, %u, %u, %u, %u, %u, %u, %u, ) = ", - path, *buffer, eng, aux, chan, tf, num_eng, num_aux, num_chan, num_tf); + path, *buffer, eng, aux, chan, tf, num_eng, num_aux, num_chan, num_tf); - status = xsp3Api_histogram_read4d( path, buffer, eng, aux, chan, tf, num_eng, num_aux, num_chan, num_tf); + status = xsp3Api_histogram_read4d(path, buffer, eng, aux, chan, tf, num_eng, num_aux, num_chan, num_tf); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -227,11 +227,11 @@ int xsp3Api::histogram_read4d(int path, uint32_t *buffer, unsigned eng, unsigned int xsp3Api::histogram_start(int path, int card) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_start( %d, %d ) = ", path, card ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_start( %d, %d ) = ", path, card); - status = xsp3Api_histogram_start( path, card); + status = xsp3Api_histogram_start(path, card); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -239,11 +239,11 @@ int xsp3Api::histogram_start(int path, int card) int xsp3Api::histogram_stop(int path, int card) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_stop( %d, %d ) = ", path, card ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_histogram_stop( %d, %d ) = ", path, card); - status = xsp3Api_histogram_stop( path, card); + status = xsp3Api_histogram_stop(path, card); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -251,11 +251,11 @@ int xsp3Api::histogram_stop(int path, int card) int xsp3Api::restore_settings(int path, char *dir_name, int force_mismatch) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_restore_settings( %d, %s, %d ) = ", path, dir_name, force_mismatch ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_restore_settings( %d, %s, %d ) = ", path, dir_name, force_mismatch); - status = xsp3Api_restore_settings( path, dir_name, force_mismatch ); + status = xsp3Api_restore_settings(path, dir_name, force_mismatch); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -263,11 +263,11 @@ int xsp3Api::restore_settings(int path, char *dir_name, int force_mismatch) int xsp3Api::save_settings(int path, char *dir_name) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_save_settings( %d, %s ) = ", path, dir_name ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_save_settings( %d, %s ) = ", path, dir_name); - status = xsp3Api_save_settings( path, dir_name ); + status = xsp3Api_save_settings(path, dir_name); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -275,11 +275,11 @@ int xsp3Api::save_settings(int path, char *dir_name) int xsp3Api::scaler_check_progress(int path) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_scaler_check_progress( %d ) = ", path ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_scaler_check_progress( %d ) = ", path); - status = xsp3Api_scaler_check_progress( path ); + status = xsp3Api_scaler_check_progress(path); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -289,9 +289,9 @@ int xsp3Api::set_glob_timeA(int path, int card, uint32_t time) int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_glob_timeA( %d, %d, %x ) = ", path, card, time); - status = xsp3Api_set_glob_timeA( path, card, time); + status = xsp3Api_set_glob_timeA(path, card, time); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -301,9 +301,9 @@ int xsp3Api::set_glob_timeFixed(int path, int card, uint32_t time) int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_glob_timeFixed( %d, %d, %u ) = ", path, card, time); - status = xsp3Api_set_glob_timeFixed( path, card, time); + status = xsp3Api_set_glob_timeFixed(path, card, time); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -313,9 +313,9 @@ int xsp3Api::set_good_thres(int path, int chan, uint32_t good_thres) int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_good_thres( %d, %d, %u ) = ", path, chan, good_thres); - status = xsp3Api_set_good_thres( path, chan, good_thres); + status = xsp3Api_set_good_thres(path, chan, good_thres); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -325,9 +325,9 @@ int xsp3Api::set_run_flags(int path, int flags) int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_run_flags( %d, 0x%X ) = ", path, flags); - status = xsp3Api_set_run_flags( path, flags); + status = xsp3Api_set_run_flags(path, flags); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -337,9 +337,9 @@ int xsp3Api::set_window(int path, int chan, int win, int low, int high) int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_window( %d, %d, %d, %d. %d ) = ", path, chan, win, low, high); - status = xsp3Api_set_window( path, chan, win, low, high); + status = xsp3Api_set_window(path, chan, win, low, high); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -351,7 +351,7 @@ int xsp3Api::itfg_setup(int path, int card, int num_tf, uint32_t col_time, int t status = xsp3Api_itfg_setup(path, card, num_tf, col_time, trig_mode, gap_mode); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -363,44 +363,43 @@ int xsp3Api::itfg_setup2(int path, int card, int num_tf, uint32_t col_time, int status = xsp3Api_itfg_setup2(path, card, num_tf, col_time, trig_mode, gap_mode, acq_in_pause, marker_period, marker_frame); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } -int xsp3Api::itfg_start(int path, int card) { +int xsp3Api::itfg_start(int path, int card) +{ int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_itfg_start( %d, %d ) = ", path, card); status = xsp3Api_itfg_start(path, card); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } -int xsp3Api::itfg_stop(int path, int card) { +int xsp3Api::itfg_stop(int path, int card) +{ int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_itfg_stop( %d, %d ) = ", path, card); status = xsp3Api_itfg_stop(path, card); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } - - - -int xsp3Api::has_itfg(int path, int card ) +int xsp3Api::has_itfg(int path, int card) { int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_has_itfg( %d, %d ) = ", path, card); status = xsp3Api_has_itfg(path, card); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -412,11 +411,11 @@ int xsp3Api::scaler_read(int path, uint32_t *dest, unsigned scaler, unsigned cha status = xsp3Api_scaler_read(path, dest, scaler, chan, t, n_scalers, n_chan, dt); asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_scaler_read( %d, [%u, %u, %u...], %u, %u, %u, %u, %u, %u ) = ", - path, - dest[0],dest[1],dest[2], - scaler, chan, t, n_scalers, n_chan, dt); + path, + dest[0], dest[1], dest[2], + scaler, chan, t, n_scalers, n_chan, dt); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -428,45 +427,43 @@ int xsp3Api::get_trigger_b(int path, unsigned card, Xspress3_TriggerB *trig_b) status = xsp3Api_get_trigger_b(path, card, trig_b); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } -int xsp3Api::get_dtcfactor(int path, u_int32_t *scaData, double *dtcFactor, double *dtcAllEvent, unsigned chan) +int xsp3Api::get_dtcfactor(int path, u_int32_t *scaData, double *dtcFactor, double *dtcAllEvent, unsigned chan) { int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_get_dtcfactor( %d, %d ) = ", path, chan); status = xsp3Api_get_dtcfactor(path, scaData, dtcFactor, dtcAllEvent, chan); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; - } -int xsp3Api::get_generation(int path, int card) +int xsp3Api::get_generation(int path, int card) { int status; asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_get_generation( %d, %d ) = ", path, card); status = xsp3Api_get_generation(path, card); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; - } int xsp3Api::get_chan_cont(int path, int chan, u_int32_t *chan_cont) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_get_chan_cont( %i, %i, %i ) = ", path, chan, *(chan_cont) ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_get_chan_cont( %i, %i, %i ) = ", path, chan, *(chan_cont)); status = xsp3Api_get_chan_cont(path, chan, chan_cont); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -474,11 +471,11 @@ int xsp3Api::get_chan_cont(int path, int chan, u_int32_t *chan_cont) int xsp3Api::set_chan_cont(int path, int chan, u_int32_t chan_cont) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_chan_cont( %i, %i, %i ) = ", path, chan, chan_cont ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_chan_cont( %i, %i, %i ) = ", path, chan, chan_cont); status = xsp3Api_set_chan_cont(path, chan, chan_cont); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } @@ -486,11 +483,11 @@ int xsp3Api::set_chan_cont(int path, int chan, u_int32_t chan_cont) int xsp3Api::set_chan_cont2(int path, int chan, u_int32_t chan_cont2) { int status; - asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_chan_cont2( %i, %i, %i ) = ", path, chan, chan_cont2 ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "xsp3_set_chan_cont2( %i, %i, %i ) = ", path, chan, chan_cont2); status = xsp3Api_set_chan_cont2(path, chan, chan_cont2); - asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status ); + asynPrint(this->pasynUser, XSP3IF_DEBUG, "%d\n", status); return status; } diff --git a/xspress3App/src/xsp3Api.h b/xspress3App/src/xsp3Api.h index af9438b5..f6dc005a 100644 --- a/xspress3App/src/xsp3Api.h +++ b/xspress3App/src/xsp3Api.h @@ -2,17 +2,17 @@ * Author: Diamond Light Source, Copyright 2014 * * License: This file is part of 'xspress3' - * + * * 'xspress3' is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * 'xspress3' is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with 'xspress3'. If not, see . */ @@ -26,27 +26,29 @@ #ifndef XSPRESS3INTERFACE_H #define XSPRESS3INTERFACE_H +#include "asynDriver.h" #include "inttypes.h" #include "xspress3.h" -#include "asynDriver.h" class xsp3Api { public: - xsp3Api(asynUser * pasynUser); + xsp3Api(asynUser *pasynUser); ~xsp3Api(); protected: virtual int xsp3Api_clocks_setup(int path, int card, int clk_src, int flags, int tp_type) = 0; virtual int xsp3Api_close(int path) = 0; - virtual int xsp3Api_config(int ncards, int num_tf, char* baseIPaddress, int basePort, char* baseMACaddress, int nchan, int createmodule, char* modname, int debug, int card_index) = 0; + virtual int xsp3Api_config(int ncards, int num_tf, char *baseIPaddress, int basePort, char *baseMACaddress, int nchan, int createmodule, char *modname, int debug, int card_index) = 0; virtual int xsp3Api_format_run(int path, int chan, int aux1_mode, int res_thres, int aux2_cont, int disables, int aux2_mode, int nbits_eng) = 0; virtual int xsp3Api_getDeadtimeCorrectionParameters(int path, int chan, int *flags, double *processDeadTimeAllEventGradient, - double *processDeadTimeAllEventOffset, double *processDeadTimeInWindowOffset, double *processDeadTimeInWindowGradient) = 0; - virtual char* xsp3Api_get_error_message() = 0; + double *processDeadTimeAllEventOffset, double *processDeadTimeInWindowOffset, double *processDeadTimeInWindowGradient) + = 0; + virtual char *xsp3Api_get_error_message() = 0; virtual int xsp3Api_get_good_thres(int path, int chan, uint32_t *good_thres) = 0; virtual int xsp3Api_get_window(int path, int chan, int win, uint32_t *low, uint32_t *high) = 0; virtual int xsp3Api_hist_dtc_read4d(int path, double *hist_buff, double *scal_buff, unsigned eng, unsigned aux, unsigned chan, unsigned tf, - unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf) = 0; + unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf) + = 0; virtual int xsp3Api_histogram_clear(int path, int first_chan, int num_chan, int first_frame, int num_frames) = 0; virtual int xsp3Api_histogram_arm(int path, int card) = 0; virtual int xsp3Api_histogram_continue(int path, int card) = 0; @@ -80,15 +82,15 @@ class xsp3Api { public: int clocks_setup(int path, int card, int clk_src, int flags, int tp_type); int close(int path); - int config(int ncards, int num_tf, char* baseIPaddress, int basePort, char* baseMACaddress, int nchan, int createmodule, char* modname, int debug, int card_index); + int config(int ncards, int num_tf, char *baseIPaddress, int basePort, char *baseMACaddress, int nchan, int createmodule, char *modname, int debug, int card_index); int format_run(int path, int chan, int aux1_mode, int res_thres, int aux2_cont, int disables, int aux2_mode, int nbits_eng); int getDeadtimeCorrectionParameters(int path, int chan, int *flags, double *processDeadTimeAllEventGradient, - double *processDeadTimeAllEventOffset, double *processDeadTimeInWindowOffset, double *processDeadTimeInWindowGradient); - char* get_error_message(); + double *processDeadTimeAllEventOffset, double *processDeadTimeInWindowOffset, double *processDeadTimeInWindowGradient); + char *get_error_message(); int get_good_thres(int path, int chan, uint32_t *good_thres); int get_window(int path, int chan, int win, uint32_t *low, uint32_t *high); int hist_dtc_read4d(int path, double *hist_buff, double *scal_buff, unsigned eng, unsigned aux, unsigned chan, unsigned tf, - unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf); + unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf); int histogram_clear(int path, int first_chan, int num_chan, int first_frame, int num_frames); int histogram_pause(int path, int card); int histogram_arm(int path, int card); @@ -120,7 +122,7 @@ class xsp3Api { int set_chan_cont2(int path, int chan, u_int32_t chan_cont2); private: - asynUser * pasynUser; + asynUser *pasynUser; }; #endif /* XSPRESS3INTERFACE_H */ diff --git a/xspress3App/src/xsp3Detector.cpp b/xspress3App/src/xsp3Detector.cpp index 32a9f024..2246bc0f 100644 --- a/xspress3App/src/xsp3Detector.cpp +++ b/xspress3App/src/xsp3Detector.cpp @@ -1,7 +1,7 @@ #include "xsp3Detector.h" -xsp3Detector::xsp3Detector(asynUser * user) : - xsp3Api( user ) +xsp3Detector::xsp3Detector(asynUser *user) + : xsp3Api(user) { } xsp3Detector::~xsp3Detector() @@ -18,40 +18,40 @@ int xsp3Detector::xsp3Api_clocks_setup(int path, int card, int clk_src, int flag int xsp3Detector::xsp3Api_close(int path) { int status; - status = xsp3_close( path, Xsp3Unlink::Xsp3UnlinkAll ); + status = xsp3_close(path, Xsp3Unlink::Xsp3UnlinkAll); return status; } -int xsp3Detector::xsp3Api_config(int ncards, int num_tf, char* baseIPaddress, int basePort, char* baseMACaddress, int nchan, int createmodule, char* modname, int debug, int card_index) +int xsp3Detector::xsp3Api_config(int ncards, int num_tf, char *baseIPaddress, int basePort, char *baseMACaddress, int nchan, int createmodule, char *modname, int debug, int card_index) { int status; - status = xsp3_config( ncards, num_tf, baseIPaddress, basePort, baseMACaddress, nchan, createmodule, modname, debug, card_index ); + status = xsp3_config(ncards, num_tf, baseIPaddress, basePort, baseMACaddress, nchan, createmodule, modname, debug, card_index); return status; } int xsp3Detector::xsp3Api_format_run(int path, int chan, int aux1_mode, int res_thres, int aux2_cont, int disables, int aux2_mode, int nbits_eng) { int status; - status = xsp3_format_run( path, chan, aux1_mode, res_thres, aux2_cont, disables, aux2_mode, nbits_eng); + status = xsp3_format_run(path, chan, aux1_mode, res_thres, aux2_cont, disables, aux2_mode, nbits_eng); return status; } int xsp3Detector::xsp3Api_getDeadtimeCorrectionParameters(int path, int chan, int *flags, - double *processDeadTimeAllEventGradient, - double *processDeadTimeAllEventOffset, - double *processDeadTimeInWindowOffset, - double *processDeadTimeInWindowGradient) + double *processDeadTimeAllEventGradient, + double *processDeadTimeAllEventOffset, + double *processDeadTimeInWindowOffset, + double *processDeadTimeInWindowGradient) { int status; - status = xsp3_getDeadtimeCorrectionParameters( path, chan, flags, - processDeadTimeAllEventGradient, - processDeadTimeAllEventOffset, - processDeadTimeInWindowOffset, - processDeadTimeInWindowGradient ); + status = xsp3_getDeadtimeCorrectionParameters(path, chan, flags, + processDeadTimeAllEventGradient, + processDeadTimeAllEventOffset, + processDeadTimeInWindowOffset, + processDeadTimeInWindowGradient); return status; } -char* xsp3Detector::xsp3Api_get_error_message() +char *xsp3Detector::xsp3Api_get_error_message() { char *message; message = xsp3_get_error_message(); @@ -61,51 +61,51 @@ char* xsp3Detector::xsp3Api_get_error_message() int xsp3Detector::xsp3Api_get_good_thres(int path, int chan, u_int32_t *good_thres) { int status; - status = xsp3_get_good_thres( path, chan, good_thres); + status = xsp3_get_good_thres(path, chan, good_thres); return status; } int xsp3Detector::xsp3Api_get_window(int path, int chan, int win, u_int32_t *low, u_int32_t *high) { int status; - status = xsp3_get_window( path, chan, win, low, high); + status = xsp3_get_window(path, chan, win, low, high); return status; } int xsp3Detector::xsp3Api_hist_dtc_read4d(int path, double *hist_buff, double *scal_buff, unsigned eng, unsigned aux, unsigned chan, unsigned tf, - unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf) + unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf) { int status; - status = xsp3_hist_dtc_read4d( path, hist_buff, scal_buff, eng, aux, chan, tf, - num_eng, num_aux, num_chan, num_tf); + status = xsp3_hist_dtc_read4d(path, hist_buff, scal_buff, eng, aux, chan, tf, + num_eng, num_aux, num_chan, num_tf); return status; } int xsp3Detector::xsp3Api_histogram_clear(int path, int first_chan, int num_chan, int first_frame, int num_frames) { int status; - status = xsp3_histogram_clear( path, first_chan, num_chan, first_frame, num_frames); + status = xsp3_histogram_clear(path, first_chan, num_chan, first_frame, num_frames); return status; } int xsp3Detector::xsp3Api_histogram_continue(int path, int card) { int status; - status = xsp3_histogram_continue( path, card); + status = xsp3_histogram_continue(path, card); return status; } int xsp3Detector::xsp3Api_histogram_arm(int path, int card) { int status; - status = xsp3_histogram_arm( path, card); - return status; + status = xsp3_histogram_arm(path, card); + return status; } int xsp3Detector::xsp3Api_histogram_pause(int path, int card) { int status; - status = xsp3_histogram_pause( path, card); + status = xsp3_histogram_pause(path, card); return status; } @@ -119,77 +119,77 @@ int xsp3Detector::xsp3Api_histogram_is_any_busy(int path) int xsp3Detector::xsp3Api_histogram_read4d(int path, u_int32_t *buffer, unsigned eng, unsigned aux, unsigned chan, unsigned tf, unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf) { int status; - status = xsp3_histogram_read4d( path, buffer, eng, aux, chan, tf, num_eng, num_aux, num_chan, num_tf); + status = xsp3_histogram_read4d(path, buffer, eng, aux, chan, tf, num_eng, num_aux, num_chan, num_tf); return status; } int xsp3Detector::xsp3Api_histogram_start(int path, int card) { int status; - status = xsp3_histogram_start( path, card); + status = xsp3_histogram_start(path, card); return status; } int xsp3Detector::xsp3Api_histogram_stop(int path, int card) { int status; - status = xsp3_histogram_stop( path, card); + status = xsp3_histogram_stop(path, card); return status; } int xsp3Detector::xsp3Api_restore_settings(int path, char *dir_name, int force_mismatch) { int status; - status = xsp3_restore_settings( path, dir_name, force_mismatch ); + status = xsp3_restore_settings(path, dir_name, force_mismatch); return status; } int xsp3Detector::xsp3Api_save_settings(int path, char *dir_name) { int status; - status = xsp3_save_settings( path, dir_name ); + status = xsp3_save_settings(path, dir_name); return status; } int xsp3Detector::xsp3Api_scaler_check_progress(int path) { int status; - status = xsp3_scaler_check_progress( path ); + status = xsp3_scaler_check_progress(path); return status; } int xsp3Detector::xsp3Api_set_glob_timeA(int path, int card, u_int32_t time) { int status; - status = xsp3_set_glob_timeA( path, card, time); + status = xsp3_set_glob_timeA(path, card, time); return status; } int xsp3Detector::xsp3Api_set_glob_timeFixed(int path, int card, u_int32_t time) { int status; - status = xsp3_set_glob_timeFixed( path, card, time); + status = xsp3_set_glob_timeFixed(path, card, time); return status; } int xsp3Detector::xsp3Api_set_good_thres(int path, int chan, u_int32_t good_thres) { int status; - status = xsp3_set_good_thres( path, chan, good_thres); + status = xsp3_set_good_thres(path, chan, good_thres); return status; } int xsp3Detector::xsp3Api_set_run_flags(int path, int flags) { int status; - status = xsp3_set_run_flags( path, flags); + status = xsp3_set_run_flags(path, flags); return status; } int xsp3Detector::xsp3Api_set_window(int path, int chan, int win, int low, int high) { int status; - status = xsp3_set_window( path, chan, win, low, high); + status = xsp3_set_window(path, chan, win, low, high); return status; } @@ -221,7 +221,7 @@ int xsp3Detector::xsp3Api_itfg_stop(int path, int card) return status; } -int xsp3Detector::xsp3Api_has_itfg(int path, int card ) +int xsp3Detector::xsp3Api_has_itfg(int path, int card) { int status; status = xsp3_has_itfg(path, card); diff --git a/xspress3App/src/xsp3Detector.h b/xspress3App/src/xsp3Detector.h index d88a7a26..cc84d72f 100644 --- a/xspress3App/src/xsp3Detector.h +++ b/xspress3App/src/xsp3Detector.h @@ -2,17 +2,17 @@ * Author: Diamond Light Source, Copyright 2014 * * License: This file is part of 'xspress3' - * + * * 'xspress3' is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * 'xspress3' is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with 'xspress3'. If not, see . */ @@ -28,24 +28,24 @@ #include "xsp3Api.h" -class xsp3Detector: public xsp3Api { -// Construction +class xsp3Detector : public xsp3Api { + // Construction public: - xsp3Detector(asynUser * pasynUser); + xsp3Detector(asynUser *pasynUser); virtual ~xsp3Detector(); protected: virtual int xsp3Api_clocks_setup(int path, int card, int clk_src, int flags, int tp_type); virtual int xsp3Api_close(int path); - virtual int xsp3Api_config(int ncards, int num_tf, char* baseIPaddress, int basePort, char* baseMACaddress, int nchan, int createmodule, char* modname, int debug, int card_index); + virtual int xsp3Api_config(int ncards, int num_tf, char *baseIPaddress, int basePort, char *baseMACaddress, int nchan, int createmodule, char *modname, int debug, int card_index); virtual int xsp3Api_format_run(int path, int chan, int aux1_mode, int res_thres, int aux2_cont, int disables, int aux2_mode, int nbits_eng); virtual int xsp3Api_getDeadtimeCorrectionParameters(int path, int chan, int *flags, double *processDeadTimeAllEventGradient, - double *processDeadTimeAllEventOffset, double *processDeadTimeInWindowOffset, double *processDeadTimeInWindowGradient); - virtual char* xsp3Api_get_error_message(); + double *processDeadTimeAllEventOffset, double *processDeadTimeInWindowOffset, double *processDeadTimeInWindowGradient); + virtual char *xsp3Api_get_error_message(); virtual int xsp3Api_get_good_thres(int path, int chan, u_int32_t *good_thres); virtual int xsp3Api_get_window(int path, int chan, int win, u_int32_t *low, u_int32_t *high); virtual int xsp3Api_hist_dtc_read4d(int path, double *hist_buff, double *scal_buff, unsigned eng, unsigned aux, unsigned chan, unsigned tf, - unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf); + unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf); virtual int xsp3Api_histogram_clear(int path, int first_chan, int num_chan, int first_frame, int num_frames); virtual int xsp3Api_histogram_continue(int path, int card); virtual int xsp3Api_histogram_pause(int path, int card); diff --git a/xspress3App/src/xsp3SimElement.cpp b/xspress3App/src/xsp3SimElement.cpp index 35baf4af..e39dcf60 100644 --- a/xspress3App/src/xsp3SimElement.cpp +++ b/xspress3App/src/xsp3SimElement.cpp @@ -8,104 +8,98 @@ #include #include - -static int num_detectors=0; - -xsp3SimElement::xsp3SimElement( int nspectra ) -: threshold(0), - num_spectra(nspectra), - processDeadTimeAllEventGradient(0), - processDeadTimeAllEventOffset(0), - processDeadTimeInWindowOffset(0), - processDeadTimeInWindowGradient(0) +static int num_detectors = 0; + +xsp3SimElement::xsp3SimElement(int nspectra) + : threshold(0) + , num_spectra(nspectra) + , processDeadTimeAllEventGradient(0) + , processDeadTimeAllEventOffset(0) + , processDeadTimeInWindowOffset(0) + , processDeadTimeInWindowGradient(0) { detector = num_detectors++; } -xsp3SimElement::~xsp3SimElement( void ) +xsp3SimElement::~xsp3SimElement(void) { } -void xsp3SimElement::generateRawSpectra( int frame, unsigned int start, unsigned int n_pts, uint32_t * buffer ) +void xsp3SimElement::generateRawSpectra(int frame, unsigned int start, unsigned int n_pts, uint32_t *buffer) { - if ( start+n_pts > num_spectra ) n_pts = num_spectra-start; + if (start + n_pts > num_spectra) + n_pts = num_spectra - start; - switch (detector%3) - { - case 1: - { + switch (detector % 3) { + case 1: { // Delta functions - for (unsigned int i=0; i < n_pts; i++) - { - if ((start+i+frame)%100 ==0) - buffer[i]=100; + for (unsigned int i = 0; i < n_pts; i++) { + if ((start + i + frame) % 100 == 0) + buffer[i] = 100; else - buffer[i]=0; + buffer[i] = 0; } break; } - case 2: - { + case 2: { // Saw tooth - for (unsigned int i=0; i < n_pts; i++) - { - buffer[i]=(start+i+frame)%100; + for (unsigned int i = 0; i < n_pts; i++) { + buffer[i] = (start + i + frame) % 100; } break; } default: // Sine wave with noise - for (unsigned int i=0; i < n_pts; i++) - { - buffer[i] = (sin(static_cast(start+i+frame)/90)+1)*100; + for (unsigned int i = 0; i < n_pts; i++) { + buffer[i] = (sin(static_cast(start + i + frame) / 90) + 1) * 100; } } } -void xsp3SimElement::generateDTCSpectra( int frame, unsigned int start, unsigned int n_pts, double * buffer ) +void xsp3SimElement::generateDTCSpectra(int frame, unsigned int start, unsigned int n_pts, double *buffer) { - if ( start+n_pts > num_spectra ) n_pts = num_spectra-start; + if (start + n_pts > num_spectra) + n_pts = num_spectra - start; uint32_t ibuffer[n_pts]; - generateRawSpectra( frame, start, n_pts, ibuffer ); + generateRawSpectra(frame, start, n_pts, ibuffer); - for (unsigned int i=0; i < n_pts; i++) + for (unsigned int i = 0; i < n_pts; i++) buffer[i] = ibuffer[i]; } -uint32_t xsp3SimElement::generateRawROI( int frame, int win ) +uint32_t xsp3SimElement::generateRawROI(int frame, int win) { - int result=0; - unsigned int start=window[win].low; - unsigned int n_pts =window[win].high-window[win].low+1; + int result = 0; + unsigned int start = window[win].low; + unsigned int n_pts = window[win].high - window[win].low + 1; - if ( start+n_pts > num_spectra ) n_pts = num_spectra-start; + if (start + n_pts > num_spectra) + n_pts = num_spectra - start; uint32_t buffer[n_pts]; - generateRawSpectra( frame, start, n_pts, buffer ); + generateRawSpectra(frame, start, n_pts, buffer); - for (unsigned int i=0; i < n_pts; i++) - result+=buffer[i]; + for (unsigned int i = 0; i < n_pts; i++) + result += buffer[i]; return result; } -double xsp3SimElement::generateDTCROI( int frame, int win ) +double xsp3SimElement::generateDTCROI(int frame, int win) { - double result=0; - unsigned int start=window[win].low; - unsigned int n_pts =window[win].high-window[win].low+1; + double result = 0; + unsigned int start = window[win].low; + unsigned int n_pts = window[win].high - window[win].low + 1; - if ( start+n_pts > num_spectra ) n_pts = num_spectra-start; + if (start + n_pts > num_spectra) + n_pts = num_spectra - start; double buffer[n_pts]; - generateDTCSpectra( frame, start, n_pts, buffer ); + generateDTCSpectra(frame, start, n_pts, buffer); - for (unsigned int i=0; i < n_pts; i++) - result+=buffer[i]; + for (unsigned int i = 0; i < n_pts; i++) + result += buffer[i]; return result; } - - - diff --git a/xspress3App/src/xsp3SimElement.h b/xspress3App/src/xsp3SimElement.h index 5515cf0c..17c774ea 100644 --- a/xspress3App/src/xsp3SimElement.h +++ b/xspress3App/src/xsp3SimElement.h @@ -10,25 +10,23 @@ #include -typedef struct xsp3Window -{ +typedef struct xsp3Window { int low; int high; } xsp3Window_t; -class xsp3SimElement -{ +class xsp3SimElement { private: int detector; public: - xsp3SimElement( int numSpectra ); - ~xsp3SimElement( void ); + xsp3SimElement(int numSpectra); + ~xsp3SimElement(void); - void generateRawSpectra( int frame, unsigned int start, unsigned int stop, uint32_t * buffer ); - void generateDTCSpectra( int frame, unsigned int start, unsigned int stop, double * buffer ); - uint32_t generateRawROI( int frame, int win ); - double generateDTCROI( int frame, int win ); + void generateRawSpectra(int frame, unsigned int start, unsigned int stop, uint32_t *buffer); + void generateDTCSpectra(int frame, unsigned int start, unsigned int stop, double *buffer); + uint32_t generateRawROI(int frame, int win); + double generateDTCROI(int frame, int win); uint32_t threshold; xsp3Window_t window[2]; @@ -39,6 +37,4 @@ class xsp3SimElement double processDeadTimeInWindowGradient; }; - - #endif /* XSP3SIMDATA_H_ */ diff --git a/xspress3App/src/xsp3Simulator.cpp b/xspress3App/src/xsp3Simulator.cpp index c63013f8..f726a2b8 100644 --- a/xspress3App/src/xsp3Simulator.cpp +++ b/xspress3App/src/xsp3Simulator.cpp @@ -1,20 +1,20 @@ #include "xsp3Simulator.h" #include "xsp3SimElement.h" -xsp3Simulator::xsp3Simulator( asynUser * user, int max_detectors, int max_spectra ) : - xsp3Api(user), - num_detectors(max_detectors), - runFlags(0), - frame_time(0.0), - num_frames(0), - current_frame(0) +xsp3Simulator::xsp3Simulator(asynUser *user, int max_detectors, int max_spectra) + : xsp3Api(user) + , num_detectors(max_detectors) + , runFlags(0) + , frame_time(0.0) + , num_frames(0) + , current_frame(0) { detectors.reserve(max_detectors); - for (int i=0; i< max_detectors; i++) + for (int i = 0; i < max_detectors; i++) detectors.push_back(xsp3SimElement(max_spectra)); scanStart = epicsTime::getCurrent(); - this->handle=314158; + this->handle = 314158; } xsp3Simulator::~xsp3Simulator() { @@ -22,16 +22,17 @@ xsp3Simulator::~xsp3Simulator() int xsp3Simulator::xsp3Api_clocks_setup(int path, int card, int clk_src, int flags, int tp_type) { - return XSP3_OK; + return XSP3_OK; } int xsp3Simulator::xsp3Api_close(int path) { - if (path != this->handle) return XSP3_ERROR; + if (path != this->handle) + return XSP3_ERROR; return XSP3_OK; } -int xsp3Simulator::xsp3Api_config(int ncards, int num_tf, char* baseIPaddress, int basePort, char* baseMACaddress, int nchan, int createmodule, char* modname, int debug, int card_index) +int xsp3Simulator::xsp3Api_config(int ncards, int num_tf, char *baseIPaddress, int basePort, char *baseMACaddress, int nchan, int createmodule, char *modname, int debug, int card_index) { return this->handle; } @@ -42,22 +43,22 @@ int xsp3Simulator::xsp3Api_format_run(int path, int chan, int aux1_mode, int res } int xsp3Simulator::xsp3Api_getDeadtimeCorrectionParameters(int path, int chan, int *flags, - double *processDeadTimeAllEventGradient, - double *processDeadTimeAllEventOffset, - double *processDeadTimeInWindowOffset, - double *processDeadTimeInWindowGradient) + double *processDeadTimeAllEventGradient, + double *processDeadTimeAllEventOffset, + double *processDeadTimeInWindowOffset, + double *processDeadTimeInWindowGradient) { - *processDeadTimeAllEventGradient= detectors[chan].processDeadTimeAllEventGradient; - *processDeadTimeAllEventOffset = detectors[chan].processDeadTimeAllEventOffset; - *processDeadTimeInWindowOffset = detectors[chan].processDeadTimeInWindowOffset; - *processDeadTimeInWindowGradient= detectors[chan].processDeadTimeInWindowGradient; + *processDeadTimeAllEventGradient = detectors[chan].processDeadTimeAllEventGradient; + *processDeadTimeAllEventOffset = detectors[chan].processDeadTimeAllEventOffset; + *processDeadTimeInWindowOffset = detectors[chan].processDeadTimeInWindowOffset; + *processDeadTimeInWindowGradient = detectors[chan].processDeadTimeInWindowGradient; return XSP3_OK; } -char* xsp3Simulator::xsp3Api_get_error_message() +char *xsp3Simulator::xsp3Api_get_error_message() { - return (char *) "Simulator is happy"; + return (char *)"Simulator is happy"; } int xsp3Simulator::xsp3Api_get_good_thres(int path, int chan, uint32_t *good_thres) @@ -74,23 +75,20 @@ int xsp3Simulator::xsp3Api_get_window(int path, int chan, int win, uint32_t *low } int xsp3Simulator::xsp3Api_hist_dtc_read4d(int path, double *hist_buff, double *scal_buff, - unsigned eng, unsigned aux, unsigned chan, unsigned tf, - unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf) -{ - for (unsigned int frame = tf; frame < tf + num_tf; frame++ ) - { - for (unsigned int i = chan; i < chan + num_chan; i++) - { - detectors[i].generateDTCSpectra( frame, eng, num_eng, hist_buff ); + unsigned eng, unsigned aux, unsigned chan, unsigned tf, + unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf) +{ + for (unsigned int frame = tf; frame < tf + num_tf; frame++) { + for (unsigned int i = chan; i < chan + num_chan; i++) { + detectors[i].generateDTCSpectra(frame, eng, num_eng, hist_buff); hist_buff += num_eng; - if (scal_buff != NULL) - { - for (int scaler = 0; scaler < XSP3_SW_NUM_SCALERS; scaler++ ) + if (scal_buff != NULL) { + for (int scaler = 0; scaler < XSP3_SW_NUM_SCALERS; scaler++) scal_buff[scaler] = 0.0; - scal_buff[5]=detectors[i].generateDTCROI(frame, 0 ); - scal_buff[6]=detectors[i].generateDTCROI(frame, 1 ); + scal_buff[5] = detectors[i].generateDTCROI(frame, 0); + scal_buff[6] = detectors[i].generateDTCROI(frame, 1); scal_buff += XSP3_SW_NUM_SCALERS; } @@ -122,17 +120,15 @@ int xsp3Simulator::xsp3Api_histogram_arm(int path, int card) int xsp3Simulator::xsp3Api_histogram_is_any_busy(int path) { - //TODO: Occasionally return busy (1). + // TODO: Occasionally return busy (1). return 0; } int xsp3Simulator::xsp3Api_histogram_read4d(int path, uint32_t *buffer, unsigned eng, unsigned aux, unsigned chan, unsigned tf, unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf) { - for (unsigned int frame = tf; frame < tf + num_tf; frame++ ) - { - for (unsigned int i = chan; i < chan + num_chan; i++) - { - detectors[i].generateRawSpectra( frame, eng, num_eng, buffer ); + for (unsigned int frame = tf; frame < tf + num_tf; frame++) { + for (unsigned int i = chan; i < chan + num_chan; i++) { + detectors[i].generateRawSpectra(frame, eng, num_eng, buffer); buffer += num_eng; } } @@ -142,7 +138,7 @@ int xsp3Simulator::xsp3Api_histogram_read4d(int path, uint32_t *buffer, unsigned int xsp3Simulator::xsp3Api_histogram_start(int path, int card) { scanStart = epicsTime::getCurrent(); - current_frame=0; + current_frame = 0; return XSP3_OK; } @@ -163,12 +159,12 @@ int xsp3Simulator::xsp3Api_save_settings(int path, char *dir_name) int xsp3Simulator::xsp3Api_scaler_check_progress(int path) { - if ( timeRegister.trigger == xsp3TimeRegister::Internal ) - { - current_frame = (epicsTime::getCurrent() - scanStart)/frame_time ; - if (current_frame > num_frames) current_frame = num_frames; + if (timeRegister.trigger == xsp3TimeRegister::Internal) { + current_frame = (epicsTime::getCurrent() - scanStart) / frame_time; + if (current_frame > num_frames) + current_frame = num_frames; } else { - current_frame+= ((current_frame+1)%10); + current_frame += ((current_frame + 1) % 10); } return current_frame; } @@ -204,14 +200,14 @@ int xsp3Simulator::xsp3Api_set_window(int path, int chan, int win, int low, int int xsp3Simulator::xsp3Api_itfg_setup(int path, int card, int num_tf, uint32_t col_time, int trig_mode, int gap_mode) { - frame_time = (double) col_time/80E6; + frame_time = (double)col_time / 80E6; num_frames = num_tf; return XSP3_OK; } int xsp3Simulator::xsp3Api_itfg_setup2(int path, int card, int num_tf, uint32_t col_time, int trig_mode, int gap_mode, int acq_in_pause, int marker_period, int marker_frame) { - frame_time = (double) col_time/80E6; + frame_time = (double)col_time / 80E6; num_frames = num_tf; return XSP3_OK; } @@ -226,7 +222,7 @@ int xsp3Simulator::xsp3Api_itfg_stop(int path, int card) return XSP3_OK; } -int xsp3Simulator::xsp3Api_has_itfg(int path, int card ) +int xsp3Simulator::xsp3Api_has_itfg(int path, int card) { return 1; } diff --git a/xspress3App/src/xsp3Simulator.h b/xspress3App/src/xsp3Simulator.h index 1c90a298..f6d814ce 100644 --- a/xspress3App/src/xsp3Simulator.h +++ b/xspress3App/src/xsp3Simulator.h @@ -2,17 +2,17 @@ * Author: Diamond Light Source, Copyright 2014 * * License: This file is part of 'xspress3' - * + * * 'xspress3' is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * 'xspress3' is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with 'xspress3'. If not, see . */ @@ -26,39 +26,39 @@ #ifndef XSP3SIMULATOR_H #define XSP3SIMULATOR_H +#include "epicsTime.h" #include "xsp3Api.h" #include "xsp3SimElement.h" #include "xsp3TimeRegister.h" #include -#include "epicsTime.h" -class xsp3Simulator: public xsp3Api { -// Construction +class xsp3Simulator : public xsp3Api { + // Construction public: - xsp3Simulator( asynUser * user, int max_detectors, int max_spectra); + xsp3Simulator(asynUser *user, int max_detectors, int max_spectra); virtual ~xsp3Simulator(); protected: virtual int xsp3Api_clocks_setup(int path, int card, int clk_src, int flags, int tp_type); virtual int xsp3Api_close(int path); - virtual int xsp3Api_config(int ncards, int num_tf, char* baseIPaddress, int basePort, char* baseMACaddress, int nchan, int createmodule, char* modname, int debug, int card_index); + virtual int xsp3Api_config(int ncards, int num_tf, char *baseIPaddress, int basePort, char *baseMACaddress, int nchan, int createmodule, char *modname, int debug, int card_index); virtual int xsp3Api_format_run(int path, int chan, int aux1_mode, int res_thres, int aux2_cont, int disables, int aux2_mode, int nbits_eng); virtual int xsp3Api_getDeadtimeCorrectionParameters(int path, int chan, int *flags, double *processDeadTimeAllEventGradient, - double *processDeadTimeAllEventOffset, double *processDeadTimeInWindowOffset, double *processDeadTimeInWindowGradient); - virtual char* xsp3Api_get_error_message(); + double *processDeadTimeAllEventOffset, double *processDeadTimeInWindowOffset, double *processDeadTimeInWindowGradient); + virtual char *xsp3Api_get_error_message(); virtual int xsp3Api_get_good_thres(int path, int chan, uint32_t *good_thres); virtual int xsp3Api_get_window(int path, int chan, int win, uint32_t *low, uint32_t *high); virtual int xsp3Api_hist_dtc_read4d(int path, double *hist_buff, double *scal_buff, - unsigned eng, unsigned aux, unsigned chan, unsigned tf, - unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf); + unsigned eng, unsigned aux, unsigned chan, unsigned tf, + unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf); virtual int xsp3Api_histogram_clear(int path, int first_chan, int num_chan, int first_frame, int num_frames); virtual int xsp3Api_histogram_continue(int path, int card); virtual int xsp3Api_histogram_pause(int path, int card); virtual int xsp3Api_histogram_arm(int path, int card); virtual int xsp3Api_histogram_is_any_busy(int path); virtual int xsp3Api_histogram_read4d(int path, uint32_t *buffer, - unsigned eng, unsigned aux, unsigned chan, unsigned tf, - unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf); + unsigned eng, unsigned aux, unsigned chan, unsigned tf, + unsigned num_eng, unsigned num_aux, unsigned num_chan, unsigned num_tf); virtual int xsp3Api_histogram_start(int path, int card); virtual int xsp3Api_histogram_stop(int path, int card); virtual int xsp3Api_restore_settings(int path, char *dir_name, int force_mismatch); diff --git a/xspress3App/src/xsp3TimeRegister.cpp b/xspress3App/src/xsp3TimeRegister.cpp index c62af42f..750ed077 100644 --- a/xspress3App/src/xsp3TimeRegister.cpp +++ b/xspress3App/src/xsp3TimeRegister.cpp @@ -7,35 +7,36 @@ #include "xsp3TimeRegister.h" #include "xspress3.h" -xsp3TimeRegister::xsp3TimeRegister(uint32_t timeRegister) : - trigger(Software), - invert_f0(0), - invert_veto(0), - debounce(0) +xsp3TimeRegister::xsp3TimeRegister(uint32_t timeRegister) + : trigger(Software) + , invert_f0(0) + , invert_veto(0) + , debounce(0) { - this->set( timeRegister ); + this->set(timeRegister); } -xsp3TimeRegister::~xsp3TimeRegister( void ) +xsp3TimeRegister::~xsp3TimeRegister(void) { } -void xsp3TimeRegister::set( uint32_t timeRegister ) +void xsp3TimeRegister::set(uint32_t timeRegister) { - trigger = (xsp3Trigger) XSP3_GLOB_TIMA_TF_SRC(timeRegister); - invert_f0 = ( timeRegister & XSP3_GLOB_TIMA_F0_INV ); - invert_veto = ( timeRegister & XSP3_GLOB_TIMA_VETO_INV ); + trigger = (xsp3Trigger)XSP3_GLOB_TIMA_TF_SRC(timeRegister); + invert_f0 = (timeRegister & XSP3_GLOB_TIMA_F0_INV); + invert_veto = (timeRegister & XSP3_GLOB_TIMA_VETO_INV); debounce = (timeRegister & 0xFF00) >> 16; } -uint32_t xsp3TimeRegister::get( void ) +uint32_t xsp3TimeRegister::get(void) { - uint32_t timeRegister = (uint32_t) trigger; + uint32_t timeRegister = (uint32_t)trigger; - if (invert_f0) timeRegister |= XSP3_GLOB_TIMA_F0_INV; - if (invert_veto) timeRegister |= XSP3_GLOB_TIMA_VETO_INV; + if (invert_f0) + timeRegister |= XSP3_GLOB_TIMA_F0_INV; + if (invert_veto) + timeRegister |= XSP3_GLOB_TIMA_VETO_INV; timeRegister |= XSP3_GLOB_TIMA_DEBOUNCE(debounce); return timeRegister; } - diff --git a/xspress3App/src/xsp3TimeRegister.h b/xspress3App/src/xsp3TimeRegister.h index 4ed008ee..7490eca6 100644 --- a/xspress3App/src/xsp3TimeRegister.h +++ b/xspress3App/src/xsp3TimeRegister.h @@ -12,13 +12,19 @@ class xsp3TimeRegister { public: - enum xsp3Trigger { Software=0, Internal=1, IDC=2, TTL_veto=3, TTL_both=4, LVDS_veto=5, LVDS_both=6 }; + enum xsp3Trigger { Software = 0, + Internal = 1, + IDC = 2, + TTL_veto = 3, + TTL_both = 4, + LVDS_veto = 5, + LVDS_both = 6 }; - xsp3TimeRegister( uint32_t timeRegister=0 ); + xsp3TimeRegister(uint32_t timeRegister = 0); ~xsp3TimeRegister(); void set(uint32_t); - uint32_t get( void ); + uint32_t get(void); xsp3Trigger trigger; bool invert_f0; diff --git a/xspress3App/src/xspress3Epics.cpp b/xspress3App/src/xspress3Epics.cpp index 939bdb0c..a52ed4c8 100644 --- a/xspress3App/src/xspress3Epics.cpp +++ b/xspress3App/src/xspress3Epics.cpp @@ -26,25 +26,25 @@ #include #include -//needs c++11 #include -//needs c++11 #include -#include -#include +// needs c++11 #include +// needs c++11 #include #include "dirent.h" +#include +#include #include #include -#include +#include -//Epics headers -#include -#include +// Epics headers +#include #include #include +#include +#include #include -#include #include -//Xspress3 API header +// Xspress3 API header #include "xspress3.h" #include "xspress3Epics.h" @@ -52,15 +52,15 @@ using std::cout; using std::endl; -//Defining enums for custom trigger modes +// Defining enums for custom trigger modes #ifndef XSP3_GTIMA_SRC_SOFT_INT -#define XSP3_GTIMA_SRC_SOFT_INT 8 //!< Time frame incremented by software and reset by internal timeframe. +#define XSP3_GTIMA_SRC_SOFT_INT 8 //!< Time frame incremented by software and reset by internal timeframe. #endif #ifndef XSP3_GTIMA_SRC_TTL_INT -#define XSP3_GTIMA_SRC_TTL_INT 9 //!< Time frame incremented by TTL and reset by internal timeframe. +#define XSP3_GTIMA_SRC_TTL_INT 9 //!< Time frame incremented by TTL and reset by internal timeframe. #endif -//Definitions of static class data members +// Definitions of static class data members const epicsInt32 Xspress3::ctrlDisable_ = 0; const epicsInt32 Xspress3::ctrlEnable_ = 1; const epicsInt32 Xspress3::runFlag_MCA_SPECTRA_ = 0; @@ -83,7 +83,7 @@ const epicsInt32 Xspress3::ADAcquireTrue_ = 1; const int INTERFACE_MASK = asynInt32Mask | asynInt32ArrayMask | asynFloat64Mask | asynFloat32ArrayMask | asynFloat64ArrayMask | asynDrvUserMask | asynOctetMask | asynGenericPointerMask; const int INTERRUPT_MASK = asynInt32Mask | asynInt32ArrayMask | asynFloat64Mask | asynFloat32ArrayMask | asynFloat64ArrayMask | asynOctetMask | asynGenericPointerMask; -//C Function prototypes to tie in with EPICS +// C Function prototypes to tie in with EPICS static void xsp3DataTaskC(void *drvPvt); /** @@ -102,73 +102,78 @@ static void xsp3DataTaskC(void *drvPvt); * @param circBuffer 0 or 1. Set to run with cirular buffer enabled. Required when more than 12216 frames per acquisition */ Xspress3::Xspress3(const char *portName, int numChannels, int numCards, const char *baseIP, int maxFrames, int maxDriverFrames, int maxSpectra, int maxBuffers, size_t maxMemory, int debug, int simTest, int circBuffer) - : ADDriver(portName, - numChannels, /* maxAddr - channels use different param lists*/ - NUM_DRIVER_PARAMS, - maxBuffers, - maxMemory, - INTERFACE_MASK, - INTERRUPT_MASK, - ASYN_CANBLOCK | ASYN_MULTIDEVICE, /* asynFlags.*/ - 1, /* Autoconnect */ - 0, /* default priority */ - 0), /* Default stack size*/ - debug_(debug), numChannels_(numChannels), simTest_(simTest), baseIP_(baseIP), circBuffer_(circBuffer) + : ADDriver(portName, + numChannels, /* maxAddr - channels use different param lists*/ + NUM_DRIVER_PARAMS, + maxBuffers, + maxMemory, + INTERFACE_MASK, + INTERRUPT_MASK, + ASYN_CANBLOCK | ASYN_MULTIDEVICE, /* asynFlags.*/ + 1, /* Autoconnect */ + 0, /* default priority */ + 0) + , /* Default stack size*/ + debug_(debug) + , numChannels_(numChannels) + , simTest_(simTest) + , baseIP_(baseIP) + , circBuffer_(circBuffer) { - int status = asynSuccess; - const char *functionName = "Xspress3::Xspress3"; - - //strncpy(baseIP_, baseIP, 16); - //baseIP_[16] = '\0'; - - //Create the epicsEvent for signaling to the status task when parameters should have changed. - //This will cause it to do a poll immediately, rather than wait for the poll time period. - startEvent_ = epicsEventMustCreate(epicsEventEmpty); - if (!startEvent_) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s epicsEventCreate failure for start event.\n", functionName); - return; - } - stopEvent_ = epicsEventMustCreate(epicsEventEmpty); - if (!stopEvent_) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s epicsEventCreate failure for start event.\n", functionName); - return; - } - this->createInitialParameters(); - //Initialize non static, non const, data members - xsp3_handle_ = 0; - bool paramStatus = this->setInitialParameters(maxFrames, maxDriverFrames, numCards, maxSpectra); - paramStatus = ((eraseSCAMCAROI() == asynSuccess) && paramStatus); - //Create the thread that reads out the data - status = (epicsThreadCreate("GeDataTask", - epicsThreadPriorityHigh, - epicsThreadGetStackSize(epicsThreadStackMedium), - (EPICSTHREADFUNC)xsp3DataTaskC, - this) == NULL); - if (status) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s epicsThreadCreate failure for data task.\n", functionName); - return; - } - - printf( "Simulation: %d\n", simTest_ ); - if (simTest_) { - paramStatus = ((setStringParam(ADStatusMessage, "Init. Simulation Mode.") == asynSuccess) && paramStatus); - xsp3 = new xsp3Simulator(this->pasynUserSelf,numChannels,maxSpectra); - } else { - paramStatus = ((setStringParam(ADStatusMessage, "Init. System Disconnected.") == asynSuccess) && paramStatus); - xsp3 = new xsp3Detector(this->pasynUserSelf); - } - - callParamCallbacks(); - - if (!paramStatus) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s Unable To Set Driver Parameters In Constructor.\n", functionName); - } - - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s End Of Constructor.\n", functionName); + int status = asynSuccess; + const char *functionName = "Xspress3::Xspress3"; + + // strncpy(baseIP_, baseIP, 16); + // baseIP_[16] = '\0'; + + // Create the epicsEvent for signaling to the status task when parameters should have changed. + // This will cause it to do a poll immediately, rather than wait for the poll time period. + startEvent_ = epicsEventMustCreate(epicsEventEmpty); + if (!startEvent_) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s epicsEventCreate failure for start event.\n", functionName); + return; + } + stopEvent_ = epicsEventMustCreate(epicsEventEmpty); + if (!stopEvent_) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s epicsEventCreate failure for start event.\n", functionName); + return; + } + this->createInitialParameters(); + // Initialize non static, non const, data members + xsp3_handle_ = 0; + bool paramStatus = this->setInitialParameters(maxFrames, maxDriverFrames, numCards, maxSpectra); + paramStatus = ((eraseSCAMCAROI() == asynSuccess) && paramStatus); + // Create the thread that reads out the data + status = (epicsThreadCreate("GeDataTask", + epicsThreadPriorityHigh, + epicsThreadGetStackSize(epicsThreadStackMedium), + (EPICSTHREADFUNC)xsp3DataTaskC, + this) + == NULL); + if (status) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s epicsThreadCreate failure for data task.\n", functionName); + return; + } + + printf("Simulation: %d\n", simTest_); + if (simTest_) { + paramStatus = ((setStringParam(ADStatusMessage, "Init. Simulation Mode.") == asynSuccess) && paramStatus); + xsp3 = new xsp3Simulator(this->pasynUserSelf, numChannels, maxSpectra); + } else { + paramStatus = ((setStringParam(ADStatusMessage, "Init. System Disconnected.") == asynSuccess) && paramStatus); + xsp3 = new xsp3Detector(this->pasynUserSelf); + } + + callParamCallbacks(); + + if (!paramStatus) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s Unable To Set Driver Parameters In Constructor.\n", functionName); + } + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s End Of Constructor.\n", functionName); } - /** +/** * A constructor for the test suite. * * This constructor defines a lot of parameters in it for ease of testing. @@ -177,7 +182,13 @@ Xspress3::Xspress3(const char *portName, int numChannels, int numCards, const ch * @param numChannels The number of channels to simulate. * */ -Xspress3::Xspress3(const char *portName, int numChannels) : ADDriver(portName, numChannels, NUM_DRIVER_PARAMS, -1, -1, INTERFACE_MASK, INTERRUPT_MASK, ASYN_CANBLOCK | ASYN_MULTIDEVICE, 1, 0, 0), debug_(1), numChannels_(numChannels), simTest_(1), baseIP_("127.0.0.1"), circBuffer_(0) +Xspress3::Xspress3(const char *portName, int numChannels) + : ADDriver(portName, numChannels, NUM_DRIVER_PARAMS, -1, -1, INTERFACE_MASK, INTERRUPT_MASK, ASYN_CANBLOCK | ASYN_MULTIDEVICE, 1, 0, 0) + , debug_(1) + , numChannels_(numChannels) + , simTest_(1) + , baseIP_("127.0.0.1") + , circBuffer_(0) { const char *functionName = "Xspress3::Xspress3"; const int maxFrames = 1000; @@ -187,13 +198,13 @@ Xspress3::Xspress3(const char *portName, int numChannels) : ADDriver(portName, n const int simTest = 1; this->lock(); this->createInitialParameters(); - //Initialize non static, non const, data members + // Initialize non static, non const, data members xsp3_handle_ = 0; bool paramStatus = this->setInitialParameters(maxFrames, maxDriverFrames, numCards, maxSpectra); paramStatus = ((eraseSCAMCAROI() == asynSuccess) && paramStatus); if (simTest) { paramStatus = ((setStringParam(ADStatusMessage, "Init. Simulation Mode.") == asynSuccess) && paramStatus); - xsp3 = new xsp3Simulator(this->pasynUserSelf,numChannels,maxSpectra); + xsp3 = new xsp3Simulator(this->pasynUserSelf, numChannels, maxSpectra); } else { paramStatus = ((setStringParam(ADStatusMessage, "Init. System Disconnected.") == asynSuccess) && paramStatus); xsp3 = new xsp3Detector(this->pasynUserSelf); @@ -206,7 +217,6 @@ Xspress3::Xspress3(const char *portName, int numChannels) : ADDriver(portName, n } asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s End Of Constructor.\n", functionName); - } /** @@ -216,8 +226,8 @@ Xspress3::Xspress3(const char *portName, int numChannels) : ADDriver(portName, n */ void Xspress3::createInitialParameters() { - //Add the params to the paramLib - //createParam adds the parameters to all param lists automatically (using maxAddr). + // Add the params to the paramLib + // createParam adds the parameters to all param lists automatically (using maxAddr). createParam(xsp3FirstParamString, asynParamInt32, &xsp3FirstParam); createParam(xsp3ResetParamString, asynParamInt32, &xsp3ResetParam); createParam(xsp3EraseParamString, asynParamInt32, &xsp3EraseParam); @@ -269,7 +279,7 @@ void Xspress3::createInitialParameters() createParam(xsp3ChanDtcAeoParamString, asynParamFloat64, &xsp3ChanDtcAeoParam); createParam(xsp3ChanDtcIwgParamString, asynParamFloat64, &xsp3ChanDtcIwgParam); createParam(xsp3ChanDtcIwoParamString, asynParamFloat64, &xsp3ChanDtcIwoParam); - //These controls calculations + // These controls calculations createParam(xsp3RoiEnableParamString, asynParamInt32, &xsp3RoiEnableParam); createParam(xsp3DtcEnableParamString, asynParamInt32, &xsp3DtcEnableParam); createParam(xsp3EventWidthParamString, asynParamFloat64, &xsp3EventWidthParam); @@ -291,7 +301,7 @@ void Xspress3::createInitialParameters() bool Xspress3::setInitialParameters(int maxFrames, int maxDriverFrames, int numCards, int maxSpectra) { bool paramStatus = true; - //Initialise any paramLib parameters that need passing up to device support + // Initialise any paramLib parameters that need passing up to device support paramStatus = ((setIntegerParam(xsp3NumChannelsParam, numChannels_) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(xsp3MaxNumChannelsParam, numChannels_) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(xsp3TriggerModeParam, 0) == asynSuccess) && paramStatus); @@ -304,16 +314,16 @@ bool Xspress3::setInitialParameters(int maxFrames, int maxDriverFrames, int numC paramStatus = ((setIntegerParam(xsp3NumCardsParam, numCards) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(xsp3FrameCountParam, 0) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(ADStatus, ADStatusDisconnected) == asynSuccess) && paramStatus); - paramStatus = ((setStringParam (ADManufacturer, "Quantum Detectors") == asynSuccess) && paramStatus); - paramStatus = ((setStringParam (ADModel, "Xspress3") == asynSuccess) && paramStatus); + paramStatus = ((setStringParam(ADManufacturer, "Quantum Detectors") == asynSuccess) && paramStatus); + paramStatus = ((setStringParam(ADModel, "Xspress3") == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(ADMaxSizeX, maxSpectra) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(ADMaxSizeY, numChannels_) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(ADSizeX, maxSpectra) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(ADSizeY, numChannels_) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(NDArraySizeX, maxSpectra) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(NDArraySizeY, numChannels_) == asynSuccess) && paramStatus); - paramStatus = ((setIntegerParam(NDArraySize, (maxSpectra * numChannels_ * sizeof(double))) == asynSuccess) && paramStatus); - paramStatus = ((setIntegerParam(NDDataType, NDUInt32) == asynSuccess) && paramStatus); + paramStatus = ((setIntegerParam(NDArraySize, (maxSpectra * numChannels_ * sizeof(double))) == asynSuccess) && paramStatus); + paramStatus = ((setIntegerParam(NDDataType, NDUInt32) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(xsp3TriggerParam, 0) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(xsp3InvertF0Param, 0) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(xsp3InvertVetoParam, 0) == asynSuccess) && paramStatus); @@ -322,7 +332,7 @@ bool Xspress3::setInitialParameters(int maxFrames, int maxDriverFrames, int numC paramStatus = ((setIntegerParam(xsp3ITFGStartParam, 0) == asynSuccess) && paramStatus); paramStatus = ((setIntegerParam(xsp3ITFGStopParam, 0) == asynSuccess) && paramStatus); - for (int chan=0; chanpasynUserSelf, ASYN_TRACE_FLOW, "Xspress3::~Xspress3 Called.\n"); } - /** * Function to connect to the Xspress3 by calling xsp3_config and * some other setup functions. */ asynStatus Xspress3::connect(void) { - asynStatus status = asynSuccess; - int xsp3_num_cards = 0; - int xsp3_num_tf = 0; - int xsp3_status = 0; - int xsp3_num_channels = 0; - int xsp3_erasestart = 1; - char configPath[maxStringSize_] = {0}; - char configSavePath[maxStringSize_] = {0}; - const char *functionName = "Xspress3::connect"; - - getIntegerParam(xsp3NumCardsParam, &xsp3_num_cards); - getIntegerParam(xsp3NumFramesConfigParam, &xsp3_num_tf); - getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); - getIntegerParam(xsp3EraseStartParam, &xsp3_erasestart); - getStringParam(xsp3ConfigPathParam, maxStringSize_, configPath); - getStringParam(xsp3ConfigSavePathParam, maxStringSize_, configSavePath); - - //Set up the xspress3 system - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Calling xsp3_config.\n", functionName); - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Base IP address is: %s\n", functionName, baseIP_.c_str()); - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Number of cards is: %d\n", functionName, xsp3_num_cards); - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Number of frames is: %d\n", functionName, xsp3_num_tf); - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Number of channels is: %d\n", functionName, numChannels_); - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Config path is: %s\n", functionName, configPath); - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Config save path is: %s\n", functionName, configSavePath); - - xsp3_handle_ = xsp3->config(xsp3_num_cards, xsp3_num_tf, const_cast(baseIP_.c_str()), -1, NULL, xsp3_num_channels, 1, NULL, debug_, 0); - if (xsp3_handle_ < 0) { - checkStatus(xsp3_handle_, "xsp3_config", functionName); - status = asynError; - } else { - setIntegerParam(xsp3ConnectedParam, 1); - - int generation = xsp3->get_generation(xsp3_handle_, 0); - int mark = 1; - - if (xsp3_is_xsp3m_plus(0) == 1) { - mark = 2; - } - // Select clock source based on generation/mark - int clock_src = XSP3_CLK_SRC_XTAL; // default - - if (generation == 3) { - clock_src = XSP3M_CLK_SRC_LMK61E2; - } else if (generation == 2) { - if (mark == 2) { - clock_src = XSP4_CLK_SRC_MIDPLN_LMK61E2; - } else { - clock_src = XSP3M_CLK_SRC_CDCM61004; - } - } - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Setting up clocks. Generation: %d Mark: %d Clock source: %d\n", functionName, generation, mark, clock_src); - xsp3_status = xsp3->clocks_setup( - xsp3_handle_, - -1, - clock_src, - XSP3_CLK_FLAGS_MASTER | XSP3_CLK_FLAGS_NO_DITHER, - 0 - ); - if (xsp3_status < 0) { - checkStatus(xsp3_status, "xsp3_clocks_setup", functionName); - status = asynError; - } - printf("xsp3_clocks_setup: Measured frequency %.2f MHz\n", float(xsp3_status)/1.0e6); - - - // Limit frames for Mini > 1 channel - if (generation == 2 && numChannels_ > 1) { - int paramStatus; - if (circBuffer_ == 0) { - paramStatus = ((setIntegerParam(xsp3NumFramesConfigParam, 12216) == asynSuccess) && paramStatus); - paramStatus = ((setIntegerParam(xsp3NumFramesDriverParam, 12216) == asynSuccess) && paramStatus); + asynStatus status = asynSuccess; + int xsp3_num_cards = 0; + int xsp3_num_tf = 0; + int xsp3_status = 0; + int xsp3_num_channels = 0; + int xsp3_erasestart = 1; + char configPath[maxStringSize_] = { 0 }; + char configSavePath[maxStringSize_] = { 0 }; + const char *functionName = "Xspress3::connect"; + + getIntegerParam(xsp3NumCardsParam, &xsp3_num_cards); + getIntegerParam(xsp3NumFramesConfigParam, &xsp3_num_tf); + getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); + getIntegerParam(xsp3EraseStartParam, &xsp3_erasestart); + getStringParam(xsp3ConfigPathParam, maxStringSize_, configPath); + getStringParam(xsp3ConfigSavePathParam, maxStringSize_, configSavePath); + + // Set up the xspress3 system + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Calling xsp3_config.\n", functionName); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Base IP address is: %s\n", functionName, baseIP_.c_str()); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Number of cards is: %d\n", functionName, xsp3_num_cards); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Number of frames is: %d\n", functionName, xsp3_num_tf); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Number of channels is: %d\n", functionName, numChannels_); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Config path is: %s\n", functionName, configPath); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Config save path is: %s\n", functionName, configSavePath); + + xsp3_handle_ = xsp3->config(xsp3_num_cards, xsp3_num_tf, const_cast(baseIP_.c_str()), -1, NULL, xsp3_num_channels, 1, NULL, debug_, 0); + if (xsp3_handle_ < 0) { + checkStatus(xsp3_handle_, "xsp3_config", functionName); + status = asynError; } else { - paramStatus = ((setIntegerParam(xsp3NumFramesConfigParam, 100001) == asynSuccess) && paramStatus); - paramStatus = ((setIntegerParam(xsp3NumFramesDriverParam, 100001) == asynSuccess) && paramStatus); - } + setIntegerParam(xsp3ConnectedParam, 1); - } + int generation = xsp3->get_generation(xsp3_handle_, 0); + int mark = 1; - // Restore settings from a file - if (status == asynSuccess) - status = restoreSettings(); + if (xsp3_is_xsp3m_plus(0) == 1) { + mark = 2; + } + // Select clock source based on generation/mark + int clock_src = XSP3_CLK_SRC_XTAL; // default + + if (generation == 3) { + clock_src = XSP3M_CLK_SRC_LMK61E2; + } else if (generation == 2) { + if (mark == 2) { + clock_src = XSP4_CLK_SRC_MIDPLN_LMK61E2; + } else { + clock_src = XSP3M_CLK_SRC_CDCM61004; + } + } + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Setting up clocks. Generation: %d Mark: %d Clock source: %d\n", functionName, generation, mark, clock_src); + xsp3_status = xsp3->clocks_setup( + xsp3_handle_, + -1, + clock_src, + XSP3_CLK_FLAGS_MASTER | XSP3_CLK_FLAGS_NO_DITHER, + 0); + if (xsp3_status < 0) { + checkStatus(xsp3_status, "xsp3_clocks_setup", functionName); + status = asynError; + } + printf("xsp3_clocks_setup: Measured frequency %.2f MHz\n", float(xsp3_status) / 1.0e6); + + // Limit frames for Mini > 1 channel + if (generation == 2 && numChannels_ > 1) { + int paramStatus; + if (circBuffer_ == 0) { + paramStatus = ((setIntegerParam(xsp3NumFramesConfigParam, 12216) == asynSuccess) && paramStatus); + paramStatus = ((setIntegerParam(xsp3NumFramesDriverParam, 12216) == asynSuccess) && paramStatus); + } else { + paramStatus = ((setIntegerParam(xsp3NumFramesConfigParam, 100001) == asynSuccess) && paramStatus); + paramStatus = ((setIntegerParam(xsp3NumFramesDriverParam, 100001) == asynSuccess) && paramStatus); + } + } - // Set completion status - if (status == asynSuccess) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Finished setting up Xspress3.\n", functionName); - setStringParam(ADStatusMessage, "System Connected"); - setIntegerParam(ADStatus, ADStatusIdle); - setIntegerParam(xsp3ConnectedParam, 1); - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR setting up Xspress3.\n", functionName); - setStringParam(ADStatusMessage, "ERROR: failed to connect"); - setIntegerParam(ADStatus, ADStatusDisconnected); - setIntegerParam(xsp3ConnectedParam, 0); - } - } // End of if xsp3_handle_ < 0 + // Restore settings from a file + if (status == asynSuccess) + status = restoreSettings(); - return status; + // Set completion status + if (status == asynSuccess) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Finished setting up Xspress3.\n", functionName); + setStringParam(ADStatusMessage, "System Connected"); + setIntegerParam(ADStatus, ADStatusIdle); + setIntegerParam(xsp3ConnectedParam, 1); + } else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR setting up Xspress3.\n", functionName); + setStringParam(ADStatusMessage, "ERROR: failed to connect"); + setIntegerParam(ADStatus, ADStatusDisconnected); + setIntegerParam(xsp3ConnectedParam, 0); + } + } // End of if xsp3_handle_ < 0 + + return status; } /** @@ -463,53 +469,53 @@ asynStatus Xspress3::connect(void) */ asynStatus Xspress3::readSCAParams(void) { - asynStatus status = asynSuccess; - int xsp3_num_channels = 0; - int xsp3_status = 0; - u_int32_t xsp3_sca_param1 = 0; - u_int32_t xsp3_sca_param2 = 0; - const char *functionName = "Xspress3::readSCAParams"; - - getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); - - for (int chan=0; changet_window(xsp3_handle_, chan, 0, &xsp3_sca_param1, &xsp3_sca_param2); - if (xsp3_status < XSP3_OK) { - checkStatus(xsp3_status, "xsp3_get_window", functionName); - status = asynError; - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Channel %d, Read back SCA5 window limits: %d, %d\n", - functionName, chan, xsp3_sca_param1, xsp3_sca_param2); - setIntegerParam(chan, xsp3ChanSca5LlmParam, xsp3_sca_param1); - setIntegerParam(chan, xsp3ChanSca5HlmParam, xsp3_sca_param2); - } - //SCA 6 window limits - xsp3_status = xsp3->get_window(xsp3_handle_, chan, 1, &xsp3_sca_param1, &xsp3_sca_param2); - if (xsp3_status < XSP3_OK) { - checkStatus(xsp3_status, "xsp3_get_window", functionName); - status = asynError; - } else { - setIntegerParam(chan, xsp3ChanSca6LlmParam, xsp3_sca_param1); - setIntegerParam(chan, xsp3ChanSca6HlmParam, xsp3_sca_param2); - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Channel %d, Read back SCA6 window limits: %d, %d\n", - functionName, chan, xsp3_sca_param1, xsp3_sca_param2); - } - //SCA 4 threshold limit - xsp3_status = xsp3->get_good_thres(xsp3_handle_, chan, &xsp3_sca_param1); - if (xsp3_status < XSP3_OK) { - checkStatus(xsp3_status, "xsp3_get_good_thres", functionName); - status = asynError; - } else { - setIntegerParam(chan, xsp3ChanSca4ThresholdParam, xsp3_sca_param1); - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Channel %d, Read back SCA4 threshold limit: %d\n", - functionName, chan, xsp3_sca_param1); - } + asynStatus status = asynSuccess; + int xsp3_num_channels = 0; + int xsp3_status = 0; + u_int32_t xsp3_sca_param1 = 0; + u_int32_t xsp3_sca_param2 = 0; + const char *functionName = "Xspress3::readSCAParams"; - callParamCallbacks(chan); - } + getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); + + for (int chan = 0; chan < xsp3_num_channels; chan++) { + // SCA 5 window limits + xsp3_status = xsp3->get_window(xsp3_handle_, chan, 0, &xsp3_sca_param1, &xsp3_sca_param2); + if (xsp3_status < XSP3_OK) { + checkStatus(xsp3_status, "xsp3_get_window", functionName); + status = asynError; + } else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Channel %d, Read back SCA5 window limits: %d, %d\n", + functionName, chan, xsp3_sca_param1, xsp3_sca_param2); + setIntegerParam(chan, xsp3ChanSca5LlmParam, xsp3_sca_param1); + setIntegerParam(chan, xsp3ChanSca5HlmParam, xsp3_sca_param2); + } + // SCA 6 window limits + xsp3_status = xsp3->get_window(xsp3_handle_, chan, 1, &xsp3_sca_param1, &xsp3_sca_param2); + if (xsp3_status < XSP3_OK) { + checkStatus(xsp3_status, "xsp3_get_window", functionName); + status = asynError; + } else { + setIntegerParam(chan, xsp3ChanSca6LlmParam, xsp3_sca_param1); + setIntegerParam(chan, xsp3ChanSca6HlmParam, xsp3_sca_param2); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Channel %d, Read back SCA6 window limits: %d, %d\n", + functionName, chan, xsp3_sca_param1, xsp3_sca_param2); + } + // SCA 4 threshold limit + xsp3_status = xsp3->get_good_thres(xsp3_handle_, chan, &xsp3_sca_param1); + if (xsp3_status < XSP3_OK) { + checkStatus(xsp3_status, "xsp3_get_good_thres", functionName); + status = asynError; + } else { + setIntegerParam(chan, xsp3ChanSca4ThresholdParam, xsp3_sca_param1); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Channel %d, Read back SCA4 threshold limit: %d\n", + functionName, chan, xsp3_sca_param1); + } + + callParamCallbacks(chan); + } - return status; + return status; } /** @@ -517,48 +523,46 @@ asynStatus Xspress3::readSCAParams(void) */ asynStatus Xspress3::readDTCParams(void) { - asynStatus status = asynSuccess; - int xsp3_num_channels = 0; - int xsp3_status = 0; - int xsp3_dtc_flags = 0; - double xsp3_dtc_all_event_grad = 0.0; - double xsp3_dtc_all_event_off = 0.0; - double xsp3_dtc_in_window_grad = 0.0; - double xsp3_dtc_in_window_off = 0.0; - const char *functionName = "Xspress3::readDTCParams"; - - getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); - - for (int chan=0; changetDeadtimeCorrectionParameters(xsp3_handle_, - chan, - &xsp3_dtc_flags, - &xsp3_dtc_all_event_grad, - &xsp3_dtc_all_event_off, - &xsp3_dtc_in_window_off, - &xsp3_dtc_in_window_grad); - if (xsp3_status < XSP3_OK) { - checkStatus(xsp3_status, "xsp3_getDeadtimeCorrectionParameters", functionName); - status = asynError; - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, - "%s Channel %d Dead Time Correction Params: Flags: %d, All Event Grad: %f, All Event Off: %f, In Win Off: %f, In Win Grad: %f\n", - functionName, chan, xsp3_dtc_flags, xsp3_dtc_all_event_grad, xsp3_dtc_all_event_off, xsp3_dtc_in_window_off, xsp3_dtc_in_window_grad); - - setIntegerParam(chan, xsp3ChanDtcFlagsParam, xsp3_dtc_flags); - setDoubleParam(chan, xsp3ChanDtcAegParam, static_cast(xsp3_dtc_all_event_grad)); - setDoubleParam(chan, xsp3ChanDtcAeoParam, static_cast(xsp3_dtc_all_event_off)); - setDoubleParam(chan, xsp3ChanDtcIwgParam, static_cast(xsp3_dtc_in_window_grad)); - setDoubleParam(chan, xsp3ChanDtcIwoParam, static_cast(xsp3_dtc_in_window_off)); - } + asynStatus status = asynSuccess; + int xsp3_num_channels = 0; + int xsp3_status = 0; + int xsp3_dtc_flags = 0; + double xsp3_dtc_all_event_grad = 0.0; + double xsp3_dtc_all_event_off = 0.0; + double xsp3_dtc_in_window_grad = 0.0; + double xsp3_dtc_in_window_off = 0.0; + const char *functionName = "Xspress3::readDTCParams"; - callParamCallbacks(chan); - } + getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); - return status; -} + for (int chan = 0; chan < xsp3_num_channels; chan++) { + xsp3_status = xsp3->getDeadtimeCorrectionParameters(xsp3_handle_, + chan, + &xsp3_dtc_flags, + &xsp3_dtc_all_event_grad, + &xsp3_dtc_all_event_off, + &xsp3_dtc_in_window_off, + &xsp3_dtc_in_window_grad); + if (xsp3_status < XSP3_OK) { + checkStatus(xsp3_status, "xsp3_getDeadtimeCorrectionParameters", functionName); + status = asynError; + } else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, + "%s Channel %d Dead Time Correction Params: Flags: %d, All Event Grad: %f, All Event Off: %f, In Win Off: %f, In Win Grad: %f\n", + functionName, chan, xsp3_dtc_flags, xsp3_dtc_all_event_grad, xsp3_dtc_all_event_off, xsp3_dtc_in_window_off, xsp3_dtc_in_window_grad); + + setIntegerParam(chan, xsp3ChanDtcFlagsParam, xsp3_dtc_flags); + setDoubleParam(chan, xsp3ChanDtcAegParam, static_cast(xsp3_dtc_all_event_grad)); + setDoubleParam(chan, xsp3ChanDtcAeoParam, static_cast(xsp3_dtc_all_event_off)); + setDoubleParam(chan, xsp3ChanDtcIwgParam, static_cast(xsp3_dtc_in_window_grad)); + setDoubleParam(chan, xsp3ChanDtcIwoParam, static_cast(xsp3_dtc_in_window_off)); + } + callParamCallbacks(chan); + } + return status; +} /** * Read the event width for each channel @@ -573,22 +577,22 @@ asynStatus Xspress3::readTrigB(void) int xsp3_num_channels = 0; getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); - for (int chan=0; changet_trigger_b(xsp3_handle_, chan, &trig_b); - printf("xsp_get_trigger_b: chan=%d, status=%d, width=%d\n", chan, xsp3_status, trig_b.event_time); + printf("xsp_get_trigger_b: chan=%d, status=%d, width=%d\n", chan, xsp3_status, trig_b.event_time); if (xsp3_status < XSP3_OK) { checkStatus(xsp3_status, "xsp3_get_trigger_b", functionName); status = asynError; } else { - /* MN 31-Aug-2016, from Stu Fisher: - for detectors with variable width events (and corresponding firmware?), - the following line should be changed to - int width = trig_b.enb_variable_width ? (trig_b.event_time-3) : trig_b.event_time; - */ - double width = trig_b.enb_variable_width ? (trig_b.event_time-3.0) : 1.0*trig_b.event_time; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Channel %d Event Width: %.1f\n", functionName, chan, width); - setDoubleParam(chan, xsp3EventWidthParam, width); + /* MN 31-Aug-2016, from Stu Fisher: + for detectors with variable width events (and corresponding firmware?), + the following line should be changed to + int width = trig_b.enb_variable_width ? (trig_b.event_time-3) : trig_b.event_time; + */ + double width = trig_b.enb_variable_width ? (trig_b.event_time - 3.0) : 1.0 * trig_b.event_time; + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Channel %d Event Width: %.1f\n", functionName, chan, width); + setDoubleParam(chan, xsp3EventWidthParam, width); } callParamCallbacks(chan); } @@ -596,31 +600,30 @@ asynStatus Xspress3::readTrigB(void) return status; } - /** * Disconnect from the xspress3 system. * This simply calls xsp3_close(). */ asynStatus Xspress3::disconnect(void) { - asynStatus status = asynSuccess; - int xsp3_status = 0; - const char *functionName = "Xspress3::disconnect"; + asynStatus status = asynSuccess; + int xsp3_status = 0; + const char *functionName = "Xspress3::disconnect"; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Calling disconnect. This calls xsp3_close().\n", functionName); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Calling disconnect. This calls xsp3_close().\n", functionName); - if ((status = checkConnected()) == asynSuccess) { - xsp3_status = xsp3->close(xsp3_handle_); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_close", functionName); - status = asynError; + if ((status = checkConnected()) == asynSuccess) { + xsp3_status = xsp3->close(xsp3_handle_); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_close", functionName); + status = asynError; + } + setStringParam(ADStatusMessage, "System disconnected."); + setIntegerParam(ADStatus, ADStatusDisconnected); + setIntegerParam(xsp3ConnectedParam, 0); } - setStringParam(ADStatusMessage, "System disconnected."); - setIntegerParam(ADStatus, ADStatusDisconnected); - setIntegerParam(xsp3ConnectedParam, 0); - } - return status; + return status; } /** @@ -629,56 +632,55 @@ asynStatus Xspress3::disconnect(void) */ asynStatus Xspress3::checkConnected(void) { - int xsp3_connected = 0; - const char *functionName = "Xspress3::checkConnected"; + int xsp3_connected = 0; + const char *functionName = "Xspress3::checkConnected"; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Checking connected status.\n", functionName); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Checking connected status.\n", functionName); - getIntegerParam(xsp3ConnectedParam, &xsp3_connected); - if (xsp3_connected != 1) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: We are not connected.\n", functionName); - setStringParam(ADStatusMessage, "ERROR: Not Connected"); - return asynError; - } + getIntegerParam(xsp3ConnectedParam, &xsp3_connected); + if (xsp3_connected != 1) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: We are not connected.\n", functionName); + setStringParam(ADStatusMessage, "ERROR: Not Connected"); + return asynError; + } - return asynSuccess; + return asynSuccess; } - /** * Save the system settings for the xspress3 system. * This simply calls xsp3_save_settings(). */ asynStatus Xspress3::saveSettings(void) { - asynStatus status = asynSuccess; - int xsp3_status = 0; - char configSavePath[maxStringSize_] = {0}; - int connected = 0; - const char *functionName = "Xspress3::saveSettings"; + asynStatus status = asynSuccess; + int xsp3_status = 0; + char configSavePath[maxStringSize_] = { 0 }; + int connected = 0; + const char *functionName = "Xspress3::saveSettings"; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Saving Xspress3 settings. This calls xsp3_save_settings().\n", functionName); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Saving Xspress3 settings. This calls xsp3_save_settings().\n", functionName); - getIntegerParam(xsp3ConnectedParam, &connected); - getStringParam(xsp3ConfigSavePathParam, maxStringSize_, configSavePath); + getIntegerParam(xsp3ConnectedParam, &connected); + getStringParam(xsp3ConfigSavePathParam, maxStringSize_, configSavePath); - if ((configSavePath == NULL) || (connected != 1)) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: No config save path set, or not connected.\n", functionName); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - } else { - xsp3_status = xsp3->save_settings(xsp3_handle_, configSavePath); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_save_settings", functionName); - setStringParam(ADStatusMessage, "Error Saving Configuration."); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; + if ((configSavePath == NULL) || (connected != 1)) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: No config save path set, or not connected.\n", functionName); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; } else { - setStringParam(ADStatusMessage, "Saved Configuration."); + xsp3_status = xsp3->save_settings(xsp3_handle_, configSavePath); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_save_settings", functionName); + setStringParam(ADStatusMessage, "Error Saving Configuration."); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + } else { + setStringParam(ADStatusMessage, "Saved Configuration."); + } } - } - return status; + return status; } /** @@ -687,159 +689,156 @@ asynStatus Xspress3::saveSettings(void) */ asynStatus Xspress3::restoreSettings(void) { - asynStatus status = asynSuccess; - int xsp3_status = 0; - char configPath[maxStringSize_] = {0}; - int connected = 0; - const char *functionName = "Xspress3::restoreSettings"; + asynStatus status = asynSuccess; + int xsp3_status = 0; + char configPath[maxStringSize_] = { 0 }; + int connected = 0; + const char *functionName = "Xspress3::restoreSettings"; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Restoring Xspress3 settings. This calls xsp3_restore_settings().\n", functionName); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Restoring Xspress3 settings. This calls xsp3_restore_settings().\n", functionName); - getIntegerParam(xsp3ConnectedParam, &connected); - getStringParam(xsp3ConfigPathParam, maxStringSize_, configPath); + getIntegerParam(xsp3ConnectedParam, &connected); + getStringParam(xsp3ConfigPathParam, maxStringSize_, configPath); - if ((configPath == NULL) || (connected != 1)) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: No config path set, or not connected.\n", functionName); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - } else { - xsp3_status = xsp3->restore_settings(xsp3_handle_, configPath, 0); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_restore_settings", functionName); - setStringParam(ADStatusMessage, "Error Restoring Configuration."); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; + if ((configPath == NULL) || (connected != 1)) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: No config path set, or not connected.\n", functionName); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; } else { - setStringParam(ADStatusMessage, "Restored Configuration."); + xsp3_status = xsp3->restore_settings(xsp3_handle_, configPath, 0); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_restore_settings", functionName); + setStringParam(ADStatusMessage, "Error Restoring Configuration."); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + } else { + setStringParam(ADStatusMessage, "Restored Configuration."); + } } - } - //Can we do xsp3_format_run here? For normal user operation all the arguments seem to be set to zero. - int xsp3_num_channels; - getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); - for (int chan=0; chanformat_run(xsp3_handle_, chan, 0, 0, 0, 0, 0, 12); - if (xsp3_status < XSP3_OK) { - checkStatus(xsp3_status, "xsp3_format_run", functionName); - status = asynError; - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Channel: %d, Number of time frames configured: %d\n", functionName, chan, xsp3_status); + // Can we do xsp3_format_run here? For normal user operation all the arguments seem to be set to zero. + int xsp3_num_channels; + getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); + for (int chan = 0; chan < xsp3_num_channels; chan++) { + xsp3_status = xsp3->format_run(xsp3_handle_, chan, 0, 0, 0, 0, 0, 12); + if (xsp3_status < XSP3_OK) { + checkStatus(xsp3_status, "xsp3_format_run", functionName); + status = asynError; + } else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Channel: %d, Number of time frames configured: %d\n", functionName, chan, xsp3_status); + } } - } - // Read run flags parameter - int xsp3_run_flags; - getIntegerParam(xsp3RunFlagsParam, &xsp3_run_flags); - if (xsp3_run_flags == runFlag_MCA_SPECTRA_) { - if (circBuffer_ == 0) { - xsp3_status = xsp3->set_run_flags(xsp3_handle_, XSP3_RUN_FLAGS_SCALERS | XSP3_RUN_FLAGS_HIST); + // Read run flags parameter + int xsp3_run_flags; + getIntegerParam(xsp3RunFlagsParam, &xsp3_run_flags); + if (xsp3_run_flags == runFlag_MCA_SPECTRA_) { + if (circBuffer_ == 0) { + xsp3_status = xsp3->set_run_flags(xsp3_handle_, XSP3_RUN_FLAGS_SCALERS | XSP3_RUN_FLAGS_HIST); + } else { + xsp3_status = xsp3->set_run_flags(xsp3_handle_, XSP3_RUN_FLAGS_SCALERS | XSP3_RUN_FLAGS_HIST | XSP3_RUN_FLAGS_CIRCULAR_BUFFER); + } + // + } else if (xsp3_run_flags == runFlag_PLAYB_MCA_SPECTRA_) { + if (circBuffer_ == 0) { + xsp3_status = xsp3->set_run_flags(xsp3_handle_, XSP3_RUN_FLAGS_PLAYBACK | XSP3_RUN_FLAGS_SCALERS | XSP3_RUN_FLAGS_HIST); + } else { + xsp3_status = xsp3->set_run_flags(xsp3_handle_, XSP3_RUN_FLAGS_PLAYBACK | XSP3_RUN_FLAGS_SCALERS | XSP3_RUN_FLAGS_HIST | XSP3_RUN_FLAGS_CIRCULAR_BUFFER); + } } else { - xsp3_status = xsp3->set_run_flags(xsp3_handle_, XSP3_RUN_FLAGS_SCALERS | XSP3_RUN_FLAGS_HIST | XSP3_RUN_FLAGS_CIRCULAR_BUFFER); + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s Invalid run flag option when trying to set xsp3_set_run_flags.\n", functionName); + status = asynError; } - // - } else if (xsp3_run_flags == runFlag_PLAYB_MCA_SPECTRA_) { - if (circBuffer_ == 0) { - xsp3_status = xsp3->set_run_flags(xsp3_handle_, XSP3_RUN_FLAGS_PLAYBACK | XSP3_RUN_FLAGS_SCALERS | XSP3_RUN_FLAGS_HIST); - } else { - xsp3_status = xsp3->set_run_flags(xsp3_handle_, XSP3_RUN_FLAGS_PLAYBACK | XSP3_RUN_FLAGS_SCALERS | XSP3_RUN_FLAGS_HIST | XSP3_RUN_FLAGS_CIRCULAR_BUFFER); - } - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s Invalid run flag option when trying to set xsp3_set_run_flags.\n", functionName); - status = asynError; - } - - if (xsp3_status < XSP3_OK) { - checkStatus(xsp3_status, "xsp3_set_run_flags", functionName); - status = asynError; - } - - if (status == asynSuccess) { - /* - * We need to now update the channel control registers based on whether we want to use - * playback data or real data signals. - * - * This is to handle the case where the settings files includes playback data, but the - * user wants the run flags to get real data. When the settings files are loaded the - * playback data means that the data source for each channel is set to playback data - * only. So if the user wants to use real data we need to override the control registers - * for each channel to set to real ADC data. - */ - - // Reset error status - xsp3_status = 0; - - // Data source we want - u_int32_t data_source; - if (xsp3_run_flags == runFlag_MCA_SPECTRA_) - { - data_source = XSP3_CC_SEL_DATA_NORMAL; - } - else data_source = XSP3_CC_SEL_DATA_PB_CHAN; - - // Apply data source to each channel - u_int32_t chan_cont = 0; - for (epicsInt32 channel = 0; channel < numChannels_; channel++) - { - // Existing control register values (after the settings have been restored) - xsp3_status &= xsp3->get_chan_cont(xsp3_handle_, channel, &chan_cont); - - // Unset all data sources and set the desired source - chan_cont &= ~XSP3_CC_SEL_DATA(0xFF); - chan_cont |= XSP3_CC_SEL_DATA(data_source); - - // Apply the register value - xsp3_status &= xsp3->set_chan_cont(xsp3_handle_, channel, chan_cont); - } - - // Check we succeeded in setting all of the channel data sources + if (xsp3_status < XSP3_OK) { - checkStatus(xsp3_status, "xsp3_set_chan_cont", functionName); - status = asynError; - } - } - - //Need to write the window params, and then read existing SCA params - if (status == asynSuccess) { - int lo_limit, hi_limit; - // Set window for the first Scalar ROI - for (int chan=0; changet_chan_cont(xsp3_handle_, channel, &chan_cont); + + // Unset all data sources and set the desired source + chan_cont &= ~XSP3_CC_SEL_DATA(0xFF); + chan_cont |= XSP3_CC_SEL_DATA(data_source); + + // Apply the register value + xsp3_status &= xsp3->set_chan_cont(xsp3_handle_, channel, chan_cont); + } + + // Check we succeeded in setting all of the channel data sources + if (xsp3_status < XSP3_OK) { + checkStatus(xsp3_status, "xsp3_set_chan_cont", functionName); + status = asynError; + } + } + + // Need to write the window params, and then read existing SCA params + if (status == asynSuccess) { + int lo_limit, hi_limit; + // Set window for the first Scalar ROI + for (int chan = 0; chan < xsp3_num_channels && status == asynSuccess; chan++) { + getIntegerParam(chan, xsp3ChanSca5HlmParam, &hi_limit); + getIntegerParam(chan, xsp3ChanSca5LlmParam, &lo_limit); + status = setWindow(chan, 0, lo_limit, hi_limit); + } + + // Set window for the first Scalar ROI + for (int chan = 0; chan < xsp3_num_channels && status == asynSuccess; chan++) { + getIntegerParam(chan, xsp3ChanSca6HlmParam, &hi_limit); + getIntegerParam(chan, xsp3ChanSca6LlmParam, &lo_limit); + status = setWindow(chan, 1, lo_limit, hi_limit); + } + status = readSCAParams(); + } + + // Set the trigger mode + if (status == asynSuccess) { + int trigger_mode, invert_f0, invert_veto, debounce; + getIntegerParam(xsp3TriggerModeParam, &trigger_mode); + getIntegerParam(xsp3InvertF0Param, &invert_f0); + getIntegerParam(xsp3InvertVetoParam, &invert_veto); + getIntegerParam(xsp3DebounceParam, &debounce); + status = setTriggerMode(trigger_mode, invert_f0, invert_veto, debounce); + } + + // Read the DTC parameters + if (status == asynSuccess) { + status = readDTCParams(); + } + + // Read Trig B for DTC + if (status == asynSuccess) { + status = readTrigB(); + } + + return status; +} /** * Funtion to log an error if any of the Xsp3 functions return an error. @@ -851,31 +850,30 @@ asynStatus Xspress3::restoreSettings(void) void Xspress3::checkStatus(int status, const char *function, const char *parentFunction) { - if (status == XSP3_OK) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s returned XSP3_OK.\n", function); - } else if (status == XSP3_ERROR) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_ERROR.\n", function); - } else if (status == XSP3_INVALID_PATH) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_ILLEGAL_PATH.\n", function); - } else if (status == XSP3_ILLEGAL_CARD) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_ILLEGAL_CARD.\n", function); - } else if (status == XSP3_ILLEGAL_SUBPATH) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_ILLEGAL_SUBPATH.\n", function); - } else if (status == XSP3_INVALID_DMA_STREAM) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_INVALID_DMA_STREAM.\n", function); - } else if (status == XSP3_RANGE_CHECK) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_RANGE_CHECK.\n", function); - } else if (status == XSP3_INVALID_SCOPE_MOD) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_INVALID_SCOPE_MOD.\n", function); - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned unknown XSP3 error code.\n", function); - } - - if (status != XSP3_OK) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "API Error Message: %s.\n", xsp3->get_error_message()); - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "EPICS Driver Calling Function: %s.\n", parentFunction); - } + if (status == XSP3_OK) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s returned XSP3_OK.\n", function); + } else if (status == XSP3_ERROR) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_ERROR.\n", function); + } else if (status == XSP3_INVALID_PATH) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_ILLEGAL_PATH.\n", function); + } else if (status == XSP3_ILLEGAL_CARD) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_ILLEGAL_CARD.\n", function); + } else if (status == XSP3_ILLEGAL_SUBPATH) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_ILLEGAL_SUBPATH.\n", function); + } else if (status == XSP3_INVALID_DMA_STREAM) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_INVALID_DMA_STREAM.\n", function); + } else if (status == XSP3_RANGE_CHECK) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_RANGE_CHECK.\n", function); + } else if (status == XSP3_INVALID_SCOPE_MOD) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned XSP3_INVALID_SCOPE_MOD.\n", function); + } else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s returned unknown XSP3 error code.\n", function); + } + if (status != XSP3_OK) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "API Error Message: %s.\n", xsp3->get_error_message()); + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "EPICS Driver Calling Function: %s.\n", parentFunction); + } } /** @@ -888,30 +886,30 @@ void Xspress3::checkStatus(int status, const char *function, const char *parentF */ asynStatus Xspress3::setWindow(int channel, int sca, int llm, int hlm) { - asynStatus status = asynSuccess; - int xsp3_status = 0; - const char *functionName = "Xspress3::setWindow"; + asynStatus status = asynSuccess; + int xsp3_status = 0; + const char *functionName = "Xspress3::setWindow"; - if ((status = checkConnected()) == asynSuccess) { - if (llm > hlm) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: SCA low limit is higher than high limit.\n", functionName); - setStringParam(ADStatusMessage, "ERROR: SCA low limit is higher than high limit."); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - } else { - xsp3_status = xsp3->set_window(xsp3_handle_, channel, sca, llm, hlm); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_set_window", functionName); - setStringParam(ADStatusMessage, "Error Setting SCA Window."); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - } else { - setStringParam(ADStatusMessage, "Set SCA Window."); - } - } - } - - return status; + if ((status = checkConnected()) == asynSuccess) { + if (llm > hlm) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: SCA low limit is higher than high limit.\n", functionName); + setStringParam(ADStatusMessage, "ERROR: SCA low limit is higher than high limit."); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + } else { + xsp3_status = xsp3->set_window(xsp3_handle_, channel, sca, llm, hlm); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_set_window", functionName); + setStringParam(ADStatusMessage, "Error Setting SCA Window."); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + } else { + setStringParam(ADStatusMessage, "Set SCA Window."); + } + } + } + + return status; } /** @@ -924,43 +922,42 @@ asynStatus Xspress3::setWindow(int channel, int sca, int llm, int hlm) */ asynStatus Xspress3::checkRoi(int channel, int roi, int llm, int hlm) { - asynStatus status = asynSuccess; - int maxSpectra = 0; - const char *functionName = "Xspress3::checkRoi"; + asynStatus status = asynSuccess; + int maxSpectra = 0; + const char *functionName = "Xspress3::checkRoi"; - getIntegerParam(xsp3MaxSpectraParam, &maxSpectra); + getIntegerParam(xsp3MaxSpectraParam, &maxSpectra); - if ((llm < 0) || (hlm < 0)) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Negative ROI limits not allowed.\n", functionName); - setStringParam(ADStatusMessage, "ERROR: Negative ROI limits not allowed."); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - } + if ((llm < 0) || (hlm < 0)) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Negative ROI limits not allowed.\n", functionName); + setStringParam(ADStatusMessage, "ERROR: Negative ROI limits not allowed."); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + } - if ((llm >= maxSpectra) || (hlm > maxSpectra)) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: ROI limits set too high.\n", functionName); - setStringParam(ADStatusMessage, "ERROR: ROI limits set too high."); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - } - - if (llm > hlm) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, - "%s ERROR: ROI %d low limit (%d) is higher than high limit (%d) on channel %d.\n", - functionName, roi, llm, hlm, channel+1); - setStringParam(ADStatusMessage, "ERROR: ROI low limit is higher than high limit."); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - } + if ((llm >= maxSpectra) || (hlm > maxSpectra)) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: ROI limits set too high.\n", functionName); + setStringParam(ADStatusMessage, "ERROR: ROI limits set too high."); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + } - if (status != asynError) { - setStringParam(ADStatusMessage, "Successfully set ROI limit."); - setIntegerParam(ADStatus, ADStatusIdle); - } + if (llm > hlm) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, + "%s ERROR: ROI %d low limit (%d) is higher than high limit (%d) on channel %d.\n", + functionName, roi, llm, hlm, channel + 1); + setStringParam(ADStatusMessage, "ERROR: ROI low limit is higher than high limit."); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + } - return status; -} + if (status != asynError) { + setStringParam(ADStatusMessage, "Successfully set ROI limit."); + setIntegerParam(ADStatus, ADStatusIdle); + } + return status; +} /** * Call xsp3_histogram_clear, and clear scalar data. @@ -968,48 +965,54 @@ asynStatus Xspress3::checkRoi(int channel, int roi, int llm, int hlm) */ asynStatus Xspress3::erase(void) { - asynStatus status = asynSuccess; - int xsp3_status = 0; - int xsp3_time_frames = 0; - int xsp3_used_frames = 0; - int xsp3_curr_frames = 0; - int xsp3_num_channels = 0; - const char *functionName = "Xspress3::erase"; + asynStatus status = asynSuccess; + int xsp3_status = 0; + int xsp3_time_frames = 0; + int xsp3_used_frames = 0; + int xsp3_curr_frames = 0; + int xsp3_num_channels = 0; + const char *functionName = "Xspress3::erase"; - //needs c++11 using namespace std::chrono; - //needs c++11 high_resolution_clock::time_point t1 = high_resolution_clock::now(); + // needs c++11 using namespace std::chrono; + // needs c++11 high_resolution_clock::time_point t1 = high_resolution_clock::now(); - if ((status = checkConnected()) == asynSuccess) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Erase data.\n", functionName); + if ((status = checkConnected()) == asynSuccess) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Erase data.\n", functionName); - getIntegerParam(xsp3NumFramesDriverParam, &xsp3_time_frames); - getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); - getIntegerParam(NDArrayCounter, &xsp3_used_frames); - getIntegerParam(ADNumImages, &xsp3_curr_frames); - - xsp3_curr_frames += 1; - if (xsp3_used_frames == 0) {xsp3_curr_frames = 1;} - if (xsp3_used_frames > xsp3_curr_frames) {xsp3_curr_frames = xsp3_used_frames;} - if (xsp3_curr_frames > xsp3_time_frames) {xsp3_curr_frames = xsp3_time_frames;} - xsp3_status = xsp3->histogram_clear(xsp3_handle_, 0, xsp3_num_channels, 0, xsp3_curr_frames); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_histogram_clear", functionName); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - } else { - status = eraseSCAMCAROI(); - if (status == asynSuccess) { - setStringParam(ADStatusMessage, "Erased Data"); - } else { - setStringParam(ADStatusMessage, "Problem Erasing Data"); - setIntegerParam(ADStatus, ADStatusError); - } - } - } - // needs c++11 high_resolution_clock::time_point t2 = high_resolution_clock::now(); - // needs c++11 duration time_span = t2 - t1; - // needs c++11 std::cout << "erase took " << time_span.count() << " msec " << std::endl; - return status; + getIntegerParam(xsp3NumFramesDriverParam, &xsp3_time_frames); + getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); + getIntegerParam(NDArrayCounter, &xsp3_used_frames); + getIntegerParam(ADNumImages, &xsp3_curr_frames); + + xsp3_curr_frames += 1; + if (xsp3_used_frames == 0) { + xsp3_curr_frames = 1; + } + if (xsp3_used_frames > xsp3_curr_frames) { + xsp3_curr_frames = xsp3_used_frames; + } + if (xsp3_curr_frames > xsp3_time_frames) { + xsp3_curr_frames = xsp3_time_frames; + } + xsp3_status = xsp3->histogram_clear(xsp3_handle_, 0, xsp3_num_channels, 0, xsp3_curr_frames); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_histogram_clear", functionName); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + } else { + status = eraseSCAMCAROI(); + if (status == asynSuccess) { + setStringParam(ADStatusMessage, "Erased Data"); + } else { + setStringParam(ADStatusMessage, "Problem Erasing Data"); + setIntegerParam(ADStatus, ADStatusError); + } + } + } + // needs c++11 high_resolution_clock::time_point t2 = high_resolution_clock::now(); + // needs c++11 duration time_span = t2 - t1; + // needs c++11 std::cout << "erase took " << time_span.count() << " msec " << std::endl; + return status; } /** @@ -1017,157 +1020,151 @@ asynStatus Xspress3::erase(void) */ asynStatus Xspress3::eraseSCAMCAROI(void) { - int status = asynSuccess; - int xsp3_num_channels = 0; - int maxNumFrames = 0; - const char *functionName = "Xspress3::eraseSCAMCAROI"; - - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Clear SCA data, MCA ROI data and all arrays.\n", functionName); - - getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); - getIntegerParam(xsp3NumFramesDriverParam, &maxNumFrames); + int status = asynSuccess; + int xsp3_num_channels = 0; + int maxNumFrames = 0; + const char *functionName = "Xspress3::eraseSCAMCAROI"; - bool paramStatus = true; - paramStatus = ((setIntegerParam(NDArrayCounter, 0) == asynSuccess) && paramStatus); - paramStatus = ((setIntegerParam(xsp3FrameCountParam, 0) == asynSuccess) && paramStatus); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Clear SCA data, MCA ROI data and all arrays.\n", functionName); - for (int chan=0; changetDataType(); + // callParamCallbacks(chan); + } + // Send a blank frame + NDArray *pMCA; + int xsp3_max_spectra = 0; + getIntegerParam(xsp3MaxSpectraParam, &xsp3_max_spectra); - size_t dims[2]; - this->getDims(dims); + NDDataType_t dataType = this->getDataType(); - pMCA= this->pNDArrayPool->alloc(2, dims, dataType, 0, NULL); + size_t dims[2]; + this->getDims(dims); - if (pMCA !=NULL) { - memset(pMCA->pData,0,pMCA->dataSize); - this->setNDArrayAttributes(pMCA, -1); + pMCA = this->pNDArrayPool->alloc(2, dims, dataType, 0, NULL); - this->lock(); + if (pMCA != NULL) { + memset(pMCA->pData, 0, pMCA->dataSize); + this->setNDArrayAttributes(pMCA, -1); - this->callParamCallbacks(); - this->unlock(); - this->doNDCallbacksIfRequired(pMCA); + this->lock(); - pMCA->release(); + this->callParamCallbacks(); + this->unlock(); + this->doNDCallbacksIfRequired(pMCA); - } + pMCA->release(); + } - if (!paramStatus) { - status = asynError; - } + if (!paramStatus) { + status = asynError; + } - if (status != asynSuccess) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR erasing data.\n", functionName); - } + if (status != asynSuccess) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR erasing data.\n", functionName); + } - return static_cast(status); + return static_cast(status); } - /** Report status of the driver. - * Prints details about the detector in us if details>0. - * It then calls the ADDriver::report() method. - * \param[in] fp File pointed passed by caller where the output is written to. - * \param[in] details Controls the level of detail in the report. */ + * Prints details about the detector in us if details>0. + * It then calls the ADDriver::report() method. + * \param[in] fp File pointed passed by caller where the output is written to. + * \param[in] details Controls the level of detail in the report. */ void Xspress3::report(FILE *fp, int details) { - fprintf(fp, "Xspress3::report.\n"); + fprintf(fp, "Xspress3::report.\n"); - fprintf(fp, "Xspress3 port=%s\n", this->portName); - if (details > 0) { - fprintf(fp, "Xspress3 driver details...\n"); - } - - fprintf(fp, "Xspress3 finished.\n"); + fprintf(fp, "Xspress3 port=%s\n", this->portName); + if (details > 0) { + fprintf(fp, "Xspress3 driver details...\n"); + } - //Call the base class method - asynNDArrayDriver::report(fp, details); + fprintf(fp, "Xspress3 finished.\n"); + // Call the base class method + asynNDArrayDriver::report(fp, details); } asynStatus Xspress3::setupITFG(void) { - asynStatus status = asynSuccess; - const char *functionName = "Xspress3::setupITFG"; - int num_frames, trigger_mode, ppt; - double exposureTime; - int xsp3_status=XSP3_OK; - int clock_freq = 80e6; - int actual_clock_freq = xsp3_measure_clock_frequency(0, 0); - if (actual_clock_freq > 0) { - clock_freq = actual_clock_freq; - } - // else printf( - // "Error measuring onboard clock frequency, defaulting to 80MHz. error code: %d\n", - // actual_clock_freq - // ); - - getIntegerParam(xsp3TriggerModeParam, &trigger_mode); - if(trigger_mode == mbboTriggerSOFTINTERNAL_) { - getIntegerParam(ADNumImages, &num_frames); - getDoubleParam(ADAcquireTime, &exposureTime); - xsp3_status = xsp3->itfg_setup2( xsp3_handle_, 0, num_frames, - (u_int32_t) floor(exposureTime*clock_freq+0.5), - XSP3_ITFG_TRIG_MODE_SOFTWARE, XSP3_ITFG_GAP_MODE_1US,0,0,0 ); - xsp3->histogram_arm(0,-1); - } - if(trigger_mode == mbboTriggerTTLINTERNAL_) { - getIntegerParam(ADNumImages, &num_frames); - getDoubleParam(ADAcquireTime, &exposureTime); - xsp3_status = xsp3->itfg_setup2( xsp3_handle_, 0, num_frames, - (u_int32_t) floor(exposureTime*clock_freq+0.5), - XSP3_ITFG_TRIG_MODE_HARDWARE, XSP3_ITFG_GAP_MODE_1US,0,0,0 ); - xsp3->histogram_arm(0,-1); - } - if (trigger_mode == mbboTriggerINTERNAL_ && - xsp3->has_itfg(xsp3_handle_, 0) > 0 ) { - getIntegerParam(ADNumImages, &num_frames); - getDoubleParam(ADAcquireTime, &exposureTime); - xsp3_status = xsp3->itfg_setup( xsp3_handle_, 0, num_frames, - (u_int32_t) floor(exposureTime*clock_freq+0.5), - XSP3_ITFG_TRIG_MODE_BURST, XSP3_ITFG_GAP_MODE_1US ); - } - - getIntegerParam(xsp3PulsePerTriggerParam, &ppt); - if (trigger_mode == mbboTriggerTTLVETO_ && - (xsp3->has_itfg(xsp3_handle_, 0) > 0) && ppt) { - - getIntegerParam(ADNumImages, &num_frames); - // printf("setupIFTG - Pulse per trigger: %d\n", ppt); - xsp3_status = xsp3->itfg_setup2( xsp3_handle_, 0, num_frames, - (u_int32_t) ppt, - XSP3_ITFG_TRIG_MODE_HARDWARE, - XSP3_ITFG_GAP_MODE_1US, XSP3_ITFG_TRIG_ACQ_PAUSED_ALL, 0, 0 ); - } - - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, " xsp3_itfg_setup", functionName); - status = asynError; - } - - return status; + asynStatus status = asynSuccess; + const char *functionName = "Xspress3::setupITFG"; + int num_frames, trigger_mode, ppt; + double exposureTime; + int xsp3_status = XSP3_OK; + int clock_freq = 80e6; + int actual_clock_freq = xsp3_measure_clock_frequency(0, 0); + if (actual_clock_freq > 0) { + clock_freq = actual_clock_freq; + } + // else printf( + // "Error measuring onboard clock frequency, defaulting to 80MHz. error code: %d\n", + // actual_clock_freq + // ); + + getIntegerParam(xsp3TriggerModeParam, &trigger_mode); + if (trigger_mode == mbboTriggerSOFTINTERNAL_) { + getIntegerParam(ADNumImages, &num_frames); + getDoubleParam(ADAcquireTime, &exposureTime); + xsp3_status = xsp3->itfg_setup2(xsp3_handle_, 0, num_frames, + (u_int32_t)floor(exposureTime * clock_freq + 0.5), + XSP3_ITFG_TRIG_MODE_SOFTWARE, XSP3_ITFG_GAP_MODE_1US, 0, 0, 0); + xsp3->histogram_arm(0, -1); + } + if (trigger_mode == mbboTriggerTTLINTERNAL_) { + getIntegerParam(ADNumImages, &num_frames); + getDoubleParam(ADAcquireTime, &exposureTime); + xsp3_status = xsp3->itfg_setup2(xsp3_handle_, 0, num_frames, + (u_int32_t)floor(exposureTime * clock_freq + 0.5), + XSP3_ITFG_TRIG_MODE_HARDWARE, XSP3_ITFG_GAP_MODE_1US, 0, 0, 0); + xsp3->histogram_arm(0, -1); + } + if (trigger_mode == mbboTriggerINTERNAL_ && xsp3->has_itfg(xsp3_handle_, 0) > 0) { + getIntegerParam(ADNumImages, &num_frames); + getDoubleParam(ADAcquireTime, &exposureTime); + xsp3_status = xsp3->itfg_setup(xsp3_handle_, 0, num_frames, + (u_int32_t)floor(exposureTime * clock_freq + 0.5), + XSP3_ITFG_TRIG_MODE_BURST, XSP3_ITFG_GAP_MODE_1US); + } + + getIntegerParam(xsp3PulsePerTriggerParam, &ppt); + if (trigger_mode == mbboTriggerTTLVETO_ && (xsp3->has_itfg(xsp3_handle_, 0) > 0) && ppt) { + + getIntegerParam(ADNumImages, &num_frames); + // printf("setupIFTG - Pulse per trigger: %d\n", ppt); + xsp3_status = xsp3->itfg_setup2(xsp3_handle_, 0, num_frames, + (u_int32_t)ppt, + XSP3_ITFG_TRIG_MODE_HARDWARE, + XSP3_ITFG_GAP_MODE_1US, XSP3_ITFG_TRIG_ACQ_PAUSED_ALL, 0, 0); + } + + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, " xsp3_itfg_setup", functionName); + status = asynError; + } + + return status; } /** @@ -1179,60 +1176,63 @@ asynStatus Xspress3::setupITFG(void) */ asynStatus Xspress3::mapTriggerMode(int mode, int invert_f0, int invert_veto, int debounce, int *apiMode) { - asynStatus status = asynSuccess; - const char *functionName = "Xspress3::mapTriggerMode"; - - if (mode == mbboTriggerFIXED_) { - *apiMode = XSP3_GTIMA_SRC_FIXED; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_FIXED, value: %d\n", - functionName, XSP3_GTIMA_SRC_FIXED); - } else if (mode == mbboTriggerINTERNAL_) { - *apiMode = XSP3_GTIMA_SRC_INTERNAL; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_INTERNAL, value: %d\n", - functionName, XSP3_GTIMA_SRC_INTERNAL); - } else if (mode == mbboTriggerIDC_) { - *apiMode = XSP3_GTIMA_SRC_IDC; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_IDC, value: %d\n", - functionName, XSP3_GTIMA_SRC_IDC); - } else if (mode == mbboTriggerTTLVETO_) { - *apiMode = XSP3_GTIMA_SRC_TTL_VETO_ONLY; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_TTL_VETO_ONLY, value: %d\n", - functionName, XSP3_GTIMA_SRC_TTL_VETO_ONLY); - } else if (mode == mbboTriggerTTLBOTH_) { - *apiMode = XSP3_GTIMA_SRC_TTL_BOTH; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_TTL_BOTH, value: %d\n", - functionName, XSP3_GTIMA_SRC_TTL_BOTH); - } else if (mode == mbboTriggerLVDSVETO_) { - *apiMode = XSP3_GTIMA_SRC_LVDS_VETO_ONLY; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_LVDS_VETO_ONLY, value: %d\n", - functionName, XSP3_GTIMA_SRC_LVDS_VETO_ONLY); - } else if (mode == mbboTriggerLVDSBOTH_) { - *apiMode = XSP3_GTIMA_SRC_LVDS_BOTH; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_LVDS_BOTH, value: %d\n", - functionName, XSP3_GTIMA_SRC_LVDS_BOTH); - } else if (mode == mbboTriggerSOFTINTERNAL_) { - *apiMode = XSP3_GTIMA_SRC_SOFT_INT; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_SOFT_INT , value: %d\n", - functionName, XSP3_GTIMA_SRC_SOFT_INT ); - } else if (mode == mbboTriggerTTLINTERNAL_) { - *apiMode = XSP3_GTIMA_SRC_TTL_INT; - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_TTL_INT , value: %d\n", - functionName, XSP3_GTIMA_SRC_TTL_INT ); - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Mapping an unknown trigger mode. mode: %d\n", functionName, mode); - setStringParam(ADStatusMessage, "ERROR Unknown Trigger Mode"); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - } + asynStatus status = asynSuccess; + const char *functionName = "Xspress3::mapTriggerMode"; + + if (mode == mbboTriggerFIXED_) { + *apiMode = XSP3_GTIMA_SRC_FIXED; + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_FIXED, value: %d\n", + functionName, XSP3_GTIMA_SRC_FIXED); + } else if (mode == mbboTriggerINTERNAL_) { + *apiMode = XSP3_GTIMA_SRC_INTERNAL; + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_INTERNAL, value: %d\n", + functionName, XSP3_GTIMA_SRC_INTERNAL); + } else if (mode == mbboTriggerIDC_) { + *apiMode = XSP3_GTIMA_SRC_IDC; + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_IDC, value: %d\n", + functionName, XSP3_GTIMA_SRC_IDC); + } else if (mode == mbboTriggerTTLVETO_) { + *apiMode = XSP3_GTIMA_SRC_TTL_VETO_ONLY; + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_TTL_VETO_ONLY, value: %d\n", + functionName, XSP3_GTIMA_SRC_TTL_VETO_ONLY); + } else if (mode == mbboTriggerTTLBOTH_) { + *apiMode = XSP3_GTIMA_SRC_TTL_BOTH; + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_TTL_BOTH, value: %d\n", + functionName, XSP3_GTIMA_SRC_TTL_BOTH); + } else if (mode == mbboTriggerLVDSVETO_) { + *apiMode = XSP3_GTIMA_SRC_LVDS_VETO_ONLY; + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_LVDS_VETO_ONLY, value: %d\n", + functionName, XSP3_GTIMA_SRC_LVDS_VETO_ONLY); + } else if (mode == mbboTriggerLVDSBOTH_) { + *apiMode = XSP3_GTIMA_SRC_LVDS_BOTH; + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_LVDS_BOTH, value: %d\n", + functionName, XSP3_GTIMA_SRC_LVDS_BOTH); + } else if (mode == mbboTriggerSOFTINTERNAL_) { + *apiMode = XSP3_GTIMA_SRC_SOFT_INT; + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_SOFT_INT , value: %d\n", + functionName, XSP3_GTIMA_SRC_SOFT_INT); + } else if (mode == mbboTriggerTTLINTERNAL_) { + *apiMode = XSP3_GTIMA_SRC_TTL_INT; + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Trigger Mode XSP3_GTIMA_SRC_TTL_INT , value: %d\n", + functionName, XSP3_GTIMA_SRC_TTL_INT); + } else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Mapping an unknown trigger mode. mode: %d\n", functionName, mode); + setStringParam(ADStatusMessage, "ERROR Unknown Trigger Mode"); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + } - if ( invert_f0 ) *apiMode |= XSP3_GLOB_TIMA_F0_INV; - if ( invert_veto ) *apiMode |= XSP3_GLOB_TIMA_VETO_INV; - if ( debounce ) *apiMode |= XSP3_GLOB_TIMA_DEBOUNCE(debounce); + if (invert_f0) + *apiMode |= XSP3_GLOB_TIMA_F0_INV; + if (invert_veto) + *apiMode |= XSP3_GLOB_TIMA_VETO_INV; + if (debounce) + *apiMode |= XSP3_GLOB_TIMA_DEBOUNCE(debounce); - return status; + return status; } -asynStatus Xspress3::setTriggerMode(int mode, int invert_f0, int invert_veto, int debounce ) +asynStatus Xspress3::setTriggerMode(int mode, int invert_f0, int invert_veto, int debounce) { const char *functionName = "Xspress3::setTriggerMode"; asynStatus status = asynSuccess; @@ -1241,28 +1241,26 @@ asynStatus Xspress3::setTriggerMode(int mode, int invert_f0, int invert_veto, in asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Trigger Mode.\n", functionName); getIntegerParam(xsp3NumCardsParam, &xsp3_num_cards); - for (int card=0; cardset_glob_timeA(xsp3_handle_, card, xsp3_trigger_mode); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_set_glob_timeA", functionName); + status = asynError; } - // probably want to arm the histogram here - status = mapTriggerMode(mode, invert_f0, invert_veto, debounce, &xsp3_trigger_mode); - } - else - { - status = mapTriggerMode(mbboTriggerTTLVETO_, invert_f0, 0, debounce, &xsp3_trigger_mode); - // status = mapTriggerMode(mode, invert_f0, 0, debounce, &xsp3_trigger_mode); - // xsp3_trigger_mode = 0; - } - if (xsp3_is_xsp3m_plus(0) == 1) { - xsp3_trigger_mode = xsp3_trigger_mode | XSP3_GLOB_TIMA_FROM_RADIAL; - } - int xsp3_status = xsp3->set_glob_timeA(xsp3_handle_, card, xsp3_trigger_mode); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_set_glob_timeA", functionName); - status = asynError; - } } return status; } @@ -1272,341 +1270,325 @@ asynStatus Xspress3::setTriggerMode(int mode, int invert_f0, int invert_veto, in */ asynStatus Xspress3::writeInt32(asynUser *pasynUser, epicsInt32 value) { - int function = pasynUser->reason; - int addr = 0; - int xsp3_status = 0; - int xsp3_sca_lim = 0; - int xsp3_time_frames = 0; - int xsp3_time_frames2 =0; - int adStatus = 0; - asynStatus status = asynSuccess; - int xsp3_num_channels = 0; - int xsp3_erasestart = 1; - const char *functionName = "Xspress3::writeInt32"; - - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Calling writeInt32.\n", functionName); - - //Read address (ie. channel number). - status = getAddress(pasynUser, &addr); - if (status!=asynSuccess) { - return(status); - } - - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s asynUser->reason: %d, value: %d, addr: %d\n", functionName, function, value, addr); - - getIntegerParam(ADStatus, &adStatus); - - if (function == xsp3ResetParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s System Reset.\n", functionName); - if ((status = checkConnected()) == asynSuccess) { - //What do we do here? - } - } - else if (function == xsp3EraseParam) { - if (adStatus != ADStatusAcquire) { - status = erase(); - } - } - else if (function == xsp3SoftTriggerParam) { - - // Soft Trigger parameter, 1 to start frame 0 to stop, you need to call both if using itfg mode (manual) - if (value==1) { - xsp3_status = xsp3->histogram_continue(xsp3_handle_,0); - } else if (value==0) { - xsp3_status = xsp3->histogram_pause(xsp3_handle_,0); - } - } - else if (function == ADAcquire) { - if (value) { - if (adStatus != ADStatusAcquire) { - if ((status = checkConnected()) == asynSuccess) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Starting Data Collection.\n", functionName); - //MNewville: explicitly stop histogram before starting. - getIntegerParam(xsp3NumFramesDriverParam, &xsp3_time_frames); - getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); - xsp3_status = xsp3->histogram_stop(xsp3_handle_, -1); - // MNewville Sept 2021, use EraseOnStart to control whether to Erase before Acquire - getIntegerParam(xsp3EraseStartParam, &xsp3_erasestart); - // printf(" erase on start %d\n", xsp3_erasestart); - if (xsp3_erasestart) { - erase(); - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Erased Before Data Collection\n", functionName); - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s No Erase Before Data Collection\n", functionName); + int function = pasynUser->reason; + int addr = 0; + int xsp3_status = 0; + int xsp3_sca_lim = 0; + int xsp3_time_frames = 0; + int xsp3_time_frames2 = 0; + int adStatus = 0; + asynStatus status = asynSuccess; + int xsp3_num_channels = 0; + int xsp3_erasestart = 1; + const char *functionName = "Xspress3::writeInt32"; + + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Calling writeInt32.\n", functionName); + + // Read address (ie. channel number). + status = getAddress(pasynUser, &addr); + if (status != asynSuccess) { + return (status); } - setupITFG(); - xsp3_status = xsp3->histogram_start(xsp3_handle_, -1); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_histogram_start", functionName); - status = asynError; - } else { - if (status == asynSuccess) { - epicsEventSignal(this->startEvent_); - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Started Data Collection.\n", functionName); - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Start Data Collection, failed.\n", functionName); - } - } - } - } - } else { - if (adStatus == ADStatusAcquire) { - if ((status = checkConnected()) == asynSuccess) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Stop Data Collection.\n", functionName); - xsp3_status = xsp3->histogram_stop(xsp3_handle_, -1); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_histogram_stop", functionName); - status = asynError; - } - if (status == asynSuccess) { - epicsEventSignal(this->stopEvent_); - } - } - } - } - } - - else if (function == xsp3NumChannelsParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Number Of Channels.\n", functionName); - getIntegerParam(xsp3MaxNumChannelsParam, &xsp3_num_channels); - if ((value > xsp3_num_channels) || (value < 1)) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Num Channels Out Of Range.\n", functionName); - status = asynError; - } - } - else if (function == xsp3TriggerModeParam || - function == xsp3InvertF0Param || - function == xsp3InvertVetoParam || - function == xsp3DebounceParam ) { - if ((status = checkConnected()) == asynSuccess) { - int trigger_mode, invert_f0, invert_veto, debounce; - getIntegerParam(xsp3TriggerModeParam, &trigger_mode); - getIntegerParam(xsp3InvertF0Param, &invert_f0); - getIntegerParam(xsp3InvertVetoParam, &invert_veto); - getIntegerParam(xsp3DebounceParam, &debounce); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s asynUser->reason: %d, value: %d, addr: %d\n", functionName, function, value, addr); - if (function == xsp3TriggerModeParam) trigger_mode=value; - else if (function == xsp3InvertF0Param) invert_f0=value; - else if (function == xsp3InvertVetoParam) invert_veto=value; - else debounce=value; + getIntegerParam(ADStatus, &adStatus); - status = setTriggerMode(trigger_mode, invert_f0, invert_veto, debounce ); + if (function == xsp3ResetParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s System Reset.\n", functionName); + if ((status = checkConnected()) == asynSuccess) { + // What do we do here? + } + } else if (function == xsp3EraseParam) { + if (adStatus != ADStatusAcquire) { + status = erase(); + } + } else if (function == xsp3SoftTriggerParam) { + + // Soft Trigger parameter, 1 to start frame 0 to stop, you need to call both if using itfg mode (manual) + if (value == 1) { + xsp3_status = xsp3->histogram_continue(xsp3_handle_, 0); + } else if (value == 0) { + xsp3_status = xsp3->histogram_pause(xsp3_handle_, 0); + } + } else if (function == ADAcquire) { + if (value) { + if (adStatus != ADStatusAcquire) { + if ((status = checkConnected()) == asynSuccess) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Starting Data Collection.\n", functionName); + // MNewville: explicitly stop histogram before starting. + getIntegerParam(xsp3NumFramesDriverParam, &xsp3_time_frames); + getIntegerParam(xsp3NumChannelsParam, &xsp3_num_channels); + xsp3_status = xsp3->histogram_stop(xsp3_handle_, -1); + // MNewville Sept 2021, use EraseOnStart to control whether to Erase before Acquire + getIntegerParam(xsp3EraseStartParam, &xsp3_erasestart); + // printf(" erase on start %d\n", xsp3_erasestart); + if (xsp3_erasestart) { + erase(); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Erased Before Data Collection\n", functionName); + } else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s No Erase Before Data Collection\n", functionName); + } + setupITFG(); + xsp3_status = xsp3->histogram_start(xsp3_handle_, -1); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_histogram_start", functionName); + status = asynError; + } else { + if (status == asynSuccess) { + epicsEventSignal(this->startEvent_); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Started Data Collection.\n", functionName); + } else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Start Data Collection, failed.\n", functionName); + } + } + } + } + } else { + if (adStatus == ADStatusAcquire) { + if ((status = checkConnected()) == asynSuccess) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Stop Data Collection.\n", functionName); + xsp3_status = xsp3->histogram_stop(xsp3_handle_, -1); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_histogram_stop", functionName); + status = asynError; + } + if (status == asynSuccess) { + epicsEventSignal(this->stopEvent_); + } + } + } + } } - } - else if (function == xsp3FixedTimeParam) { - if ((status = checkConnected()) == asynSuccess) { - xsp3_status = xsp3->set_glob_timeFixed(xsp3_handle_, -1, value); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_set_glob_timeFixed", functionName); - status = asynError; + + else if (function == xsp3NumChannelsParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Number Of Channels.\n", functionName); + getIntegerParam(xsp3MaxNumChannelsParam, &xsp3_num_channels); + if ((value > xsp3_num_channels) || (value < 1)) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Num Channels Out Of Range.\n", functionName); + status = asynError; } - } - } - else if (function == ADNumImages) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Number Of Frames To Read Out.\n", functionName); - getIntegerParam(xsp3NumFramesDriverParam, &xsp3_time_frames); - getIntegerParam(xsp3MaxFramesParam, &xsp3_time_frames2); - if (value > xsp3_time_frames || value > xsp3_time_frames2) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Num Frames Higher Than Number Configured.\n", functionName); - status = asynError; - } - } - else if (function == xsp3NumFramesConfigParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Number Of Frames For Intial API Configuration.\n", functionName); - getIntegerParam(xsp3MaxFramesParam, &xsp3_time_frames); - if (value > xsp3_time_frames) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Num Frames For Config Too High.\n", functionName); - status = asynError; - } - } - else if (function == xsp3ConnectParam) { - status = connect(); - } - else if (function == xsp3DisconnectParam) { - status = disconnect(); - } - else if (function == xsp3SaveSettingsParam) { - if ((adStatus != ADStatusAcquire)) { - status = saveSettings(); - if (status == asynSuccess) { - //Clear the save path so the user is forced to use a new path next time. - setStringParam(xsp3ConfigSavePathParam, " "); - } - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Saving Not Allowed In This Mode.\n", functionName); - status = asynError; + } else if (function == xsp3TriggerModeParam || function == xsp3InvertF0Param || function == xsp3InvertVetoParam || function == xsp3DebounceParam) { + if ((status = checkConnected()) == asynSuccess) { + int trigger_mode, invert_f0, invert_veto, debounce; + + getIntegerParam(xsp3TriggerModeParam, &trigger_mode); + getIntegerParam(xsp3InvertF0Param, &invert_f0); + getIntegerParam(xsp3InvertVetoParam, &invert_veto); + getIntegerParam(xsp3DebounceParam, &debounce); + + if (function == xsp3TriggerModeParam) + trigger_mode = value; + else if (function == xsp3InvertF0Param) + invert_f0 = value; + else if (function == xsp3InvertVetoParam) + invert_veto = value; + else + debounce = value; + + status = setTriggerMode(trigger_mode, invert_f0, invert_veto, debounce); + } + } else if (function == xsp3FixedTimeParam) { + if ((status = checkConnected()) == asynSuccess) { + xsp3_status = xsp3->set_glob_timeFixed(xsp3_handle_, -1, value); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_set_glob_timeFixed", functionName); + status = asynError; + } + } + } else if (function == ADNumImages) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Number Of Frames To Read Out.\n", functionName); + getIntegerParam(xsp3NumFramesDriverParam, &xsp3_time_frames); + getIntegerParam(xsp3MaxFramesParam, &xsp3_time_frames2); + if (value > xsp3_time_frames || value > xsp3_time_frames2) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Num Frames Higher Than Number Configured.\n", functionName); + status = asynError; + } + } else if (function == xsp3NumFramesConfigParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Number Of Frames For Intial API Configuration.\n", functionName); + getIntegerParam(xsp3MaxFramesParam, &xsp3_time_frames); + if (value > xsp3_time_frames) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Num Frames For Config Too High.\n", functionName); + status = asynError; + } + } else if (function == xsp3ConnectParam) { + status = connect(); + } else if (function == xsp3DisconnectParam) { + status = disconnect(); + } else if (function == xsp3SaveSettingsParam) { + if ((adStatus != ADStatusAcquire)) { + status = saveSettings(); + if (status == asynSuccess) { + // Clear the save path so the user is forced to use a new path next time. + setStringParam(xsp3ConfigSavePathParam, " "); + } + } else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Saving Not Allowed In This Mode.\n", functionName); + status = asynError; + } + } else if (function == xsp3RestoreSettingsParam) { + if ((adStatus != ADStatusAcquire)) { + status = restoreSettings(); + } else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Restoring Not Allowed In This Mode.\n", functionName); + status = asynError; + } + } else if (function == xsp3ChanSca4ThresholdParam) { + + if ((status = checkConnected()) == asynSuccess) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The SCA4 Threshold Register.\n", functionName); + xsp3_status = xsp3->set_good_thres(xsp3_handle_, addr, value); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_set_good_thres", functionName); + status = asynError; + } + } + } else if (function == xsp3TriggerParam) { + if ((status = checkConnected()) == asynSuccess && adStatus == ADStatusAcquire && value) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Triggering Next Frame.\n", functionName); + xsp3_status = xsp3->histogram_continue(xsp3_handle_, -1); + if (xsp3_status != XSP3_OK) { + checkStatus(xsp3_status, "xsp3_histogram_continue", functionName); + status = asynError; + } + } + } else if (function == xsp3ChanSca5HlmParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The SCA5 High Limit.\n", functionName); + getIntegerParam(addr, xsp3ChanSca5LlmParam, &xsp3_sca_lim); + status = setWindow(addr, 0, xsp3_sca_lim, value); + } else if (function == xsp3ChanSca6HlmParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The SCA6 High Limit.\n", functionName); + getIntegerParam(addr, xsp3ChanSca6LlmParam, &xsp3_sca_lim); + status = setWindow(addr, 1, xsp3_sca_lim, value); + } else if (function == xsp3ChanSca5LlmParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The SCA5 Low Limit.\n", functionName); + getIntegerParam(addr, xsp3ChanSca5HlmParam, &xsp3_sca_lim); + status = setWindow(addr, 0, value, xsp3_sca_lim); + } else if (function == xsp3ChanSca6LlmParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The SCA6 Low Limit.\n", functionName); + getIntegerParam(addr, xsp3ChanSca6HlmParam, &xsp3_sca_lim); + status = setWindow(addr, 1, value, xsp3_sca_lim); + } + + else if (function == xsp3RoiEnableParam) { + if (value == ctrlDisable_) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Disabling ROI Calculations.\n", functionName); + } else if (value == ctrlEnable_) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Enabling ROI Calculations.\n", functionName); + } + } else if (function == xsp3RunFlagsParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The Run Flags.\n", functionName); + } + + else if (function == xsp3PulsePerTriggerParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Changing trigger mode for pulse per trigger.\n", functionName); + int trigger_mode, invert_f0, invert_veto, debounce; + + getIntegerParam(xsp3TriggerModeParam, &trigger_mode); + getIntegerParam(xsp3InvertF0Param, &invert_f0); + getIntegerParam(xsp3InvertVetoParam, &invert_veto); + getIntegerParam(xsp3DebounceParam, &debounce); + + if (trigger_mode == mbboTriggerTTLVETO_) { + if (value > 0) { + printf("PPT > 0, setting trigger mode to internal\n"); + status = setTriggerMode(mbboTriggerINTERNAL_, invert_f0, invert_veto, debounce); + } else { + printf("PPT = 0, resetting trigger mode to %d\n", trigger_mode); + status = setTriggerMode(trigger_mode, invert_f0, invert_veto, debounce); + } + } + } - } - else if (function == xsp3RestoreSettingsParam) { - if ((adStatus != ADStatusAcquire)) { - status = restoreSettings(); - } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Restoring Not Allowed In This Mode.\n", functionName); - status = asynError; + + else if (function == xsp3ITFGStartParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Restarting ITFG.\n", functionName); + printf("Restarting ITFG\n"); + xsp3->itfg_start(xsp3_handle_, 0); } - } - else if (function == xsp3ChanSca4ThresholdParam) { - if ((status = checkConnected()) == asynSuccess) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The SCA4 Threshold Register.\n", functionName); - xsp3_status = xsp3->set_good_thres(xsp3_handle_, addr, value); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_set_good_thres", functionName); - status = asynError; - } - } - } - else if (function == xsp3TriggerParam) { - if ((status = checkConnected()) == asynSuccess && adStatus == ADStatusAcquire && value) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Triggering Next Frame.\n", functionName); - xsp3_status = xsp3->histogram_continue(xsp3_handle_, -1); - if (xsp3_status != XSP3_OK) { - checkStatus(xsp3_status, "xsp3_histogram_continue", functionName); - status = asynError; - } - } - } - else if (function == xsp3ChanSca5HlmParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The SCA5 High Limit.\n", functionName); - getIntegerParam(addr, xsp3ChanSca5LlmParam, &xsp3_sca_lim); - status = setWindow(addr, 0, xsp3_sca_lim, value); - } - else if (function == xsp3ChanSca6HlmParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The SCA6 High Limit.\n", functionName); - getIntegerParam(addr, xsp3ChanSca6LlmParam, &xsp3_sca_lim); - status = setWindow(addr, 1, xsp3_sca_lim, value); - } - else if (function == xsp3ChanSca5LlmParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The SCA5 Low Limit.\n", functionName); - getIntegerParam(addr, xsp3ChanSca5HlmParam, &xsp3_sca_lim); - status = setWindow(addr, 0, value, xsp3_sca_lim); - } - else if (function == xsp3ChanSca6LlmParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The SCA6 Low Limit.\n", functionName); - getIntegerParam(addr, xsp3ChanSca6HlmParam, &xsp3_sca_lim); - status = setWindow(addr, 1, value, xsp3_sca_lim); - } - - else if (function == xsp3RoiEnableParam) { - if (value == ctrlDisable_) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Disabling ROI Calculations.\n", functionName); - } else if (value == ctrlEnable_) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Enabling ROI Calculations.\n", functionName); - } - } - else if (function == xsp3RunFlagsParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set The Run Flags.\n", functionName); - } - - else if (function == xsp3PulsePerTriggerParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Changing trigger mode for pulse per trigger.\n", functionName); - int trigger_mode, invert_f0, invert_veto, debounce; + else if (function == xsp3ITFGStopParam) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Pausing ITFG.\n", functionName); + printf("Pausing ITFG\n"); + xsp3->itfg_stop(xsp3_handle_, 0); + } - getIntegerParam(xsp3TriggerModeParam, &trigger_mode); - getIntegerParam(xsp3InvertF0Param, &invert_f0); - getIntegerParam(xsp3InvertVetoParam, &invert_veto); - getIntegerParam(xsp3DebounceParam, &debounce); - - if (trigger_mode == mbboTriggerTTLVETO_) { - if (value > 0) { - printf("PPT > 0, setting trigger mode to internal\n"); - status = setTriggerMode(mbboTriggerINTERNAL_, invert_f0, invert_veto, debounce ); - } else { - printf("PPT = 0, resetting trigger mode to %d\n", trigger_mode); - status = setTriggerMode(trigger_mode, invert_f0, invert_veto, debounce ); - } - } - - } - - else if (function == xsp3ITFGStartParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Restarting ITFG.\n", functionName); - printf("Restarting ITFG\n"); - xsp3->itfg_start(xsp3_handle_, 0); - } - - else if (function == xsp3ITFGStopParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Pausing ITFG.\n", functionName); - printf("Pausing ITFG\n"); - xsp3->itfg_stop(xsp3_handle_, 0); - } - - else if (function == xsp3EraseStartParam) { - getIntegerParam(xsp3EraseStartParam, &xsp3_erasestart); - } + else if (function == xsp3EraseStartParam) { + getIntegerParam(xsp3EraseStartParam, &xsp3_erasestart); + } - else if (function == xsp3DtcEnableParam) { - // Turning on DTC changes array type to float - if (value == 1) setIntegerParam(NDDataType, NDFloat64); - else setIntegerParam(NDDataType, NDUInt32);; - } + else if (function == xsp3DtcEnableParam) { + // Turning on DTC changes array type to float + if (value == 1) + setIntegerParam(NDDataType, NDFloat64); + else + setIntegerParam(NDDataType, NDUInt32); + ; + } - else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s No Matching Parameter In Xspress3 Driver.\n", functionName); - } + else { + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s No Matching Parameter In Xspress3 Driver.\n", functionName); + } - if (status != asynSuccess) { - callParamCallbacks(addr); - return asynError; - } + if (status != asynSuccess) { + callParamCallbacks(addr); + return asynError; + } - //The data readout thread will set ADAcquire back to false. - if (function == ADAcquire) { - if (!value) { - return status; + // The data readout thread will set ADAcquire back to false. + if (function == ADAcquire) { + if (!value) { + return status; + } } - } - status = (asynStatus) setIntegerParam(addr, function, value); - if (status!=asynSuccess) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, + status = (asynStatus)setIntegerParam(addr, function, value); + if (status != asynSuccess) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s Error Setting Parameter. Asyn addr: %d, asynUser->reason: %d, value: %d\n", - functionName, addr, function, value); - return(status); - } + functionName, addr, function, value); + return (status); + } - //Do callbacks so higher layers see any changes - callParamCallbacks(addr); + // Do callbacks so higher layers see any changes + callParamCallbacks(addr); - return status; + return status; } - /** * Reimplementing this function from ADDriver to deal with floating point values. */ asynStatus Xspress3::writeFloat64(asynUser *pasynUser, epicsFloat64 value) { - int function = pasynUser->reason; - int addr = 0; - asynStatus status = asynSuccess; - const char *functionName = "Xspress3::writeFloat64"; - - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Calling writeFloat64.\n", functionName); - //Read address (ie. channel number). - status = getAddress(pasynUser, &addr); - if (status!=asynSuccess) { - return(status); - } - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s asynUser->reason: %d, value: %f, addr: %d\n", functionName, function, value, addr); - - //Set in param lib so the user sees a readback straight away. We might overwrite this in the - //status task, depending on the parameter. - status = (asynStatus) setDoubleParam(function, value); - - //Do callbacks so higher layers see any changes - callParamCallbacks(); - - return status; -} + int function = pasynUser->reason; + int addr = 0; + asynStatus status = asynSuccess; + const char *functionName = "Xspress3::writeFloat64"; + + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Calling writeFloat64.\n", functionName); + // Read address (ie. channel number). + status = getAddress(pasynUser, &addr); + if (status != asynSuccess) { + return (status); + } + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s asynUser->reason: %d, value: %f, addr: %d\n", functionName, function, value, addr); + + // Set in param lib so the user sees a readback straight away. We might overwrite this in the + // status task, depending on the parameter. + status = (asynStatus)setDoubleParam(function, value); + // Do callbacks so higher layers see any changes + callParamCallbacks(); + + return status; +} /** * Reimplementing this function from asynNDArrayDriver to deal with strings. */ asynStatus Xspress3::writeOctet(asynUser *pasynUser, const char *value, - size_t nChars, size_t *nActual) + size_t nChars, size_t *nActual) { int function = pasynUser->reason; asynStatus status = asynSuccess; @@ -1615,20 +1597,20 @@ asynStatus Xspress3::writeOctet(asynUser *pasynUser, const char *value, asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Calling writeOctet.\n", functionName); if (function == xsp3ConfigPathParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Config Path Param.\n", functionName); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Config Path Param.\n", functionName); } else if (function == xsp3ConfigSavePathParam) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Config Save Path Param.\n", functionName); - status = checkSaveDir(value); + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Set Config Save Path Param.\n", functionName); + status = checkSaveDir(value); } else { /* If this parameter belongs to a base class call its method */ - if (function < XSP3_FIRST_DRIVER_COMMAND) { - status = asynNDArrayDriver::writeOctet(pasynUser, value, nChars, nActual); - } + if (function < XSP3_FIRST_DRIVER_COMMAND) { + status = asynNDArrayDriver::writeOctet(pasynUser, value, nChars, nActual); + } } if (status != asynSuccess) { - callParamCallbacks(); - return asynError; + callParamCallbacks(); + return asynError; } /* Set the parameter in the parameter library. */ @@ -1637,9 +1619,9 @@ asynStatus Xspress3::writeOctet(asynUser *pasynUser, const char *value, status = (asynStatus)callParamCallbacks(); if (status) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, - "%s Error Setting Parameter. asynUser->reason: %d\n", - functionName, function); + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, + "%s Error Setting Parameter. asynUser->reason: %d\n", + functionName, function); } *nActual = nChars; @@ -1652,42 +1634,41 @@ asynStatus Xspress3::writeOctet(asynUser *pasynUser, const char *value, */ asynStatus Xspress3::checkSaveDir(const char *dirName) { - asynStatus status = asynSuccess; - int countFiles = 0; - struct dirent *d = NULL; - const char *functionName = "Xspress3::checkSaveDir"; - - DIR *dir = opendir(dirName); - if (dir == NULL) { - //Directory doesn't exist. - perror(functionName); - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Cannot Open Save Dir.\n", functionName); - setStringParam(ADStatusMessage, "ERROR Opening Save Directory."); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - } - if (status != asynError) { - while ((d = readdir(dir)) != NULL) { - if (++countFiles > 2) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Files Already Exist In This Directory.\n", functionName); - setStringParam(ADStatusMessage, "ERROR Files Already Exist In This Directory."); + asynStatus status = asynSuccess; + int countFiles = 0; + struct dirent *d = NULL; + const char *functionName = "Xspress3::checkSaveDir"; + + DIR *dir = opendir(dirName); + if (dir == NULL) { + // Directory doesn't exist. + perror(functionName); + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Cannot Open Save Dir.\n", functionName); + setStringParam(ADStatusMessage, "ERROR Opening Save Directory."); setIntegerParam(ADStatus, ADStatusError); status = asynError; - break; - } } - } - closedir(dir); + if (status != asynError) { + while ((d = readdir(dir)) != NULL) { + if (++countFiles > 2) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: Files Already Exist In This Directory.\n", functionName); + setStringParam(ADStatusMessage, "ERROR Files Already Exist In This Directory."); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + break; + } + } + } + closedir(dir); - if (status != asynError) { - setStringParam(ADStatusMessage, "Set Save Directory."); - setIntegerParam(ADStatus, ADStatusIdle); - } + if (status != asynError) { + setStringParam(ADStatusMessage, "Set Save Directory."); + setIntegerParam(ADStatus, ADStatusIdle); + } - return status; + return status; } - /** * Wait until data collection has finished on all channels. * This function should only be called after stopping histogramming. @@ -1697,38 +1678,38 @@ asynStatus Xspress3::checkSaveDir(const char *dirName) */ asynStatus Xspress3::checkHistBusy(int checkTimes) { - asynStatus status = asynSuccess; - int notBusyCount = 0; - int notBusyChan = 0; - int notBusyTotalCount = 0; - int numChannels = 0; - const char* functionName = "Xspress3::checkHistBusy"; - - //Get the number of channels actually in use. - getIntegerParam(xsp3NumChannelsParam, &numChannels); - - while (notBusyCount<2) { - for (int chan=0; chanhistogram_is_any_busy(xsp3_handle_)) == 0) { - ++notBusyChan; - } - } - if (notBusyChan == numChannels) { - ++notBusyCount; - } - notBusyChan = 0; - notBusyTotalCount++; - /////////TODO - check this works if we force xsp3_histogram_is_busy to fail. - if (notBusyTotalCount==checkTimes) { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: we polled xsp3_histogram_is_busy %d times. Giving up.\n", functionName, checkTimes); - setStringParam(ADStatusMessage, "ERROR: Xspress3 Did Not Stop. Giving Up."); - setIntegerParam(ADStatus, ADStatusError); - status = asynError; - break; - } - } - - return status; + asynStatus status = asynSuccess; + int notBusyCount = 0; + int notBusyChan = 0; + int notBusyTotalCount = 0; + int numChannels = 0; + const char *functionName = "Xspress3::checkHistBusy"; + + // Get the number of channels actually in use. + getIntegerParam(xsp3NumChannelsParam, &numChannels); + + while (notBusyCount < 2) { + for (int chan = 0; chan < numChannels; chan++) { + if ((xsp3->histogram_is_any_busy(xsp3_handle_)) == 0) { + ++notBusyChan; + } + } + if (notBusyChan == numChannels) { + ++notBusyCount; + } + notBusyChan = 0; + notBusyTotalCount++; + /////////TODO - check this works if we force xsp3_histogram_is_busy to fail. + if (notBusyTotalCount == checkTimes) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s ERROR: we polled xsp3_histogram_is_busy %d times. Giving up.\n", functionName, checkTimes); + setStringParam(ADStatusMessage, "ERROR: Xspress3 Did Not Stop. Giving Up."); + setIntegerParam(ADStatus, ADStatusError); + status = asynError; + break; + } + } + + return status; } /** @@ -1736,7 +1717,7 @@ asynStatus Xspress3::checkHistBusy(int checkTimes) * * @param message A string (const char*) to write to ADStatusMessage. */ -void Xspress3::adReportError(const char* message) +void Xspress3::adReportError(const char *message) { setStringParam(ADStatusMessage, message); setIntegerParam(ADStatus, ADStatusError); @@ -1796,30 +1777,30 @@ bool Xspress3::createMCAArray(size_t dims[2], NDArray *&pMCA, NDDataType_t dataT * * @return true if an allocation error occurs otherwise false */ -bool Xspress3::readFrame(double* pSCA, double* pMCAData, int frameNumber, int maxSpectra) +bool Xspress3::readFrame(double *pSCA, double *pMCAData, int frameNumber, int maxSpectra) { bool error = false; int xsp3Status = 0; - const char* functionName = "Xspress3::readFrame"; + const char *functionName = "Xspress3::readFrame"; xsp3Status = xsp3->hist_dtc_read4d(this->xsp3_handle_, pMCAData, pSCA, 0, 0, 0, frameNumber, maxSpectra, 1, this->numChannels_, 1); if (xsp3Status != XSP3_OK) { checkStatus(xsp3Status, "xsp3_hist_dtc_read4d", functionName); error = true; } else { - setIntegerParam(NDArrayCounter, frameNumber+1); + setIntegerParam(NDArrayCounter, frameNumber + 1); } if (circBuffer_ == 1) { - xsp3_histogram_circ_ack(this->xsp3_handle_, 0, frameNumber, this->numChannels_, 1); + xsp3_histogram_circ_ack(this->xsp3_handle_, 0, frameNumber, this->numChannels_, 1); } return error; } -bool Xspress3::readFrame(u_int32_t* pSCA, u_int32_t* pMCAData, int frameNumber, int maxSpectra) +bool Xspress3::readFrame(u_int32_t *pSCA, u_int32_t *pMCAData, int frameNumber, int maxSpectra) { bool error = false; int xsp3Status = 0; - const char* functionName = "Xspress3::readFrame"; + const char *functionName = "Xspress3::readFrame"; xsp3Status = xsp3->histogram_read4d(this->xsp3_handle_, pMCAData, 0, 0, 0, frameNumber, maxSpectra, 1, this->numChannels_, 1); if (xsp3Status != XSP3_OK) { checkStatus(xsp3Status, "xsp3_histogram_read4d", functionName); @@ -1830,15 +1811,13 @@ bool Xspress3::readFrame(u_int32_t* pSCA, u_int32_t* pMCAData, int frameNumber, if (xsp3Status != XSP3_OK) { checkStatus(xsp3Status, "xsp3_scaler_read", functionName); error = true; + } else { + setIntegerParam(NDArrayCounter, frameNumber + 1); } - else - { - setIntegerParam(NDArrayCounter, frameNumber+1); } - } -// xsp3_histogram_circ_ack(this->xsp3_handle_, 0, frameOffset, this->numChannels_, 1); + // xsp3_histogram_circ_ack(this->xsp3_handle_, 0, frameOffset, this->numChannels_, 1); if (circBuffer_ == 1) { - xsp3_histogram_circ_ack(this->xsp3_handle_, 0, frameNumber, this->numChannels_, 1); + xsp3_histogram_circ_ack(this->xsp3_handle_, 0, frameNumber, this->numChannels_, 1); } return error; } @@ -1887,64 +1866,63 @@ const int Xspress3::waitForStartEvent(const char *message) void Xspress3::writeOutScas(void *&pSCA, int numChannels, NDDataType_t dataType) { double allevt, resets, evtwidth, ctime; - double dtperc=0.0; - double dtfact=1.0; + double dtperc = 0.0; + double dtfact = 1.0; if (dataType == NDFloat64) { - double *pScaData = static_cast(pSCA); - for (int chan=0; chansetDoubleParam(chan, this->xsp3ChanSca0Param, static_cast(pScaData[0])); - this->setDoubleParam(chan, this->xsp3ChanSca1Param, static_cast(pScaData[1])); - this->setDoubleParam(chan, this->xsp3ChanSca2Param, static_cast(pScaData[2])); - this->setDoubleParam(chan, this->xsp3ChanSca3Param, static_cast(pScaData[3])); - this->setDoubleParam(chan, this->xsp3ChanSca4Param, static_cast(pScaData[4])); - this->setDoubleParam(chan, this->xsp3ChanSca5Param, static_cast(pScaData[5])); - this->setDoubleParam(chan, this->xsp3ChanSca6Param, static_cast(pScaData[6])); - this->setDoubleParam(chan, this->xsp3ChanSca7Param, static_cast(pScaData[7])); - - // MN set percent deadtime and deadtime correction factor here - ctime = pScaData[0]; - if (ctime > 10) { - getDoubleParam(chan, xsp3EventWidthParam, &evtwidth); - resets = pScaData[1]; - allevt = pScaData[3]; - dtperc = 100.0*(allevt*(evtwidth+1) + resets)/ctime; - dtfact = ctime/(ctime - (allevt*(evtwidth+1) + resets)); - //printf(":D> chan=%i, event_width=%.1f DTpercent=%.3f, DTfactor=%.6f", chan, evtwidth, dtperc, dtfact); - setDoubleParam(chan, xsp3ChanDTPercentParam, static_cast(dtperc)); - setDoubleParam(chan, xsp3ChanDTFactorParam, static_cast(dtfact)); - } + double *pScaData = static_cast(pSCA); + for (int chan = 0; chan < numChannels; ++chan) { + this->setDoubleParam(chan, this->xsp3ChanSca0Param, static_cast(pScaData[0])); + this->setDoubleParam(chan, this->xsp3ChanSca1Param, static_cast(pScaData[1])); + this->setDoubleParam(chan, this->xsp3ChanSca2Param, static_cast(pScaData[2])); + this->setDoubleParam(chan, this->xsp3ChanSca3Param, static_cast(pScaData[3])); + this->setDoubleParam(chan, this->xsp3ChanSca4Param, static_cast(pScaData[4])); + this->setDoubleParam(chan, this->xsp3ChanSca5Param, static_cast(pScaData[5])); + this->setDoubleParam(chan, this->xsp3ChanSca6Param, static_cast(pScaData[6])); + this->setDoubleParam(chan, this->xsp3ChanSca7Param, static_cast(pScaData[7])); + + // MN set percent deadtime and deadtime correction factor here + ctime = pScaData[0]; + if (ctime > 10) { + getDoubleParam(chan, xsp3EventWidthParam, &evtwidth); + resets = pScaData[1]; + allevt = pScaData[3]; + dtperc = 100.0 * (allevt * (evtwidth + 1) + resets) / ctime; + dtfact = ctime / (ctime - (allevt * (evtwidth + 1) + resets)); + // printf(":D> chan=%i, event_width=%.1f DTpercent=%.3f, DTfactor=%.6f", chan, evtwidth, dtperc, dtfact); + setDoubleParam(chan, xsp3ChanDTPercentParam, static_cast(dtperc)); + setDoubleParam(chan, xsp3ChanDTFactorParam, static_cast(dtfact)); + } - pScaData += XSP3_SW_NUM_SCALERS; - } - } - else { - u_int32_t *pScaData = static_cast(pSCA); - for (int chan=0; chansetDoubleParam(chan, this->xsp3ChanSca0Param, static_cast(pScaData[0])); - this->setDoubleParam(chan, this->xsp3ChanSca1Param, static_cast(pScaData[1])); - this->setDoubleParam(chan, this->xsp3ChanSca2Param, static_cast(pScaData[2])); - this->setDoubleParam(chan, this->xsp3ChanSca3Param, static_cast(pScaData[3])); - this->setDoubleParam(chan, this->xsp3ChanSca4Param, static_cast(pScaData[4])); - this->setDoubleParam(chan, this->xsp3ChanSca5Param, static_cast(pScaData[5])); - this->setDoubleParam(chan, this->xsp3ChanSca6Param, static_cast(pScaData[6])); - this->setDoubleParam(chan, this->xsp3ChanSca7Param, static_cast(pScaData[7])); - - // MN set percent deadtime and deadtime correction factor here - ctime = 1.0*pScaData[0]; - if (ctime > 10) { - getDoubleParam(chan, xsp3EventWidthParam, &evtwidth); - resets = 1.0*pScaData[1]; - allevt = 1.0*pScaData[3]; - dtperc = 100.0*(allevt*(evtwidth+1) + resets)/ctime; - dtfact = ctime/(ctime - (allevt*(evtwidth+1) + resets)); - // printf(":I> chan=%i, event_width=%.1f DTpercent=%.3f, DTfactor=%.6f\n", chan, evtwidth, dtperc, dtfact); - // setDoubleParam(chan, xsp3ChanDTPercentParam, static_cast(dtperc)); - // setDoubleParam(chan, xsp3ChanDTFactorParam, static_cast(dtfact)); - setDoubleParam(chan, xsp3ChanDTPercentParam, dtperc); - setDoubleParam(chan, xsp3ChanDTFactorParam, dtfact); + pScaData += XSP3_SW_NUM_SCALERS; + } + } else { + u_int32_t *pScaData = static_cast(pSCA); + for (int chan = 0; chan < numChannels; ++chan) { + this->setDoubleParam(chan, this->xsp3ChanSca0Param, static_cast(pScaData[0])); + this->setDoubleParam(chan, this->xsp3ChanSca1Param, static_cast(pScaData[1])); + this->setDoubleParam(chan, this->xsp3ChanSca2Param, static_cast(pScaData[2])); + this->setDoubleParam(chan, this->xsp3ChanSca3Param, static_cast(pScaData[3])); + this->setDoubleParam(chan, this->xsp3ChanSca4Param, static_cast(pScaData[4])); + this->setDoubleParam(chan, this->xsp3ChanSca5Param, static_cast(pScaData[5])); + this->setDoubleParam(chan, this->xsp3ChanSca6Param, static_cast(pScaData[6])); + this->setDoubleParam(chan, this->xsp3ChanSca7Param, static_cast(pScaData[7])); + + // MN set percent deadtime and deadtime correction factor here + ctime = 1.0 * pScaData[0]; + if (ctime > 10) { + getDoubleParam(chan, xsp3EventWidthParam, &evtwidth); + resets = 1.0 * pScaData[1]; + allevt = 1.0 * pScaData[3]; + dtperc = 100.0 * (allevt * (evtwidth + 1) + resets) / ctime; + dtfact = ctime / (ctime - (allevt * (evtwidth + 1) + resets)); + // printf(":I> chan=%i, event_width=%.1f DTpercent=%.3f, DTfactor=%.6f\n", chan, evtwidth, dtperc, dtfact); + // setDoubleParam(chan, xsp3ChanDTPercentParam, static_cast(dtperc)); + // setDoubleParam(chan, xsp3ChanDTFactorParam, static_cast(dtfact)); + setDoubleParam(chan, xsp3ChanDTPercentParam, dtperc); + setDoubleParam(chan, xsp3ChanDTFactorParam, dtfact); + } + pScaData += XSP3_SW_NUM_SCALERS; } - pScaData += XSP3_SW_NUM_SCALERS; - } } } @@ -2007,7 +1985,7 @@ void Xspress3::setNDArrayAttributes(NDArray *&pMCA, int frameNumber) this->getIntegerParam(NDArrayCallbacks, &arrayCallbacks); epicsTimeGetCurrent(¤tTime); pMCA->uniqueId = frameNumber; - pMCA->timeStamp = currentTime.secPastEpoch + currentTime.nsec/1e9; + pMCA->timeStamp = currentTime.secPastEpoch + currentTime.nsec / 1e9; pMCA->pAttributeList->add("TIMESTAMP", "Host Timestamp", NDAttrFloat64, &(pMCA->timeStamp)); this->getAttributes(pMCA->pAttributeList); } @@ -2050,12 +2028,12 @@ int Xspress3::getMaxNumFrames() return maxnum; } -//int Xspress3::getFrameCounter() +// int Xspress3::getFrameCounter() //{ -// int frame_counter; -// this->getIntegerParam(NDArrayCounter, &frame_counter); -// return frame_counter; -//} +// int frame_counter; +// this->getIntegerParam(NDArrayCounter, &frame_counter); +// return frame_counter; +// } void Xspress3::doNDCallbacksIfRequired(NDArray *pMCA) { @@ -2082,7 +2060,7 @@ int Xspress3::getNumFramesRead() void Xspress3::xspAsynPrint(int asynPrintType, const char *format, ...) { - const int maxMessageLen=1024; + const int maxMessageLen = 1024; va_list pArg; char message[maxMessageLen]; va_start(pArg, format); @@ -2103,13 +2081,13 @@ static void xsp3DataTaskC(void *xspAD) void *pSCA; NDArray *pMCA; NDDataType_t dataType; - bool acquire=false; - bool aborted=false; - bool error=false; - bool notready=false; + bool acquire = false; + bool aborted = false; + bool error = false; + bool notready = false; int notready_count; - int numChannels, maxSpectra, frameNumber, numFrames=0, acquired, lastAcquired; - //int frame_count, last_frame_count, frame_counter, frames_remaining, frame_offset; + int numChannels, maxSpectra, frameNumber, numFrames = 0, acquired, lastAcquired; + // int frame_count, last_frame_count, frame_counter, frames_remaining, frame_offset; size_t dims[2]; const double timeout = 0.00001; const int checkTimes = 20; @@ -2141,18 +2119,18 @@ static void xsp3DataTaskC(void *xspAD) // add check that getNumFrames returns 0 for the 0th frame. // using this counter to indicate "ready to read frame" seems // fragile at frames 0 and 1. - if (acquire && (frameNumber == 0) ) { - notready_count = 0; - notready = pXspAD->getNumFramesRead(); - while (notready) { - usleep(50); + if (acquire && (frameNumber == 0)) { + notready_count = 0; notready = pXspAD->getNumFramesRead(); - notready_count +=1; - if (notready_count > 30000) { - notready = 0; - printf("frames may not be ready.\n"); + while (notready) { + usleep(50); + notready = pXspAD->getNumFramesRead(); + notready_count += 1; + if (notready_count > 30000) { + notready = 0; + printf("frames may not be ready.\n"); + } } - } } while (acquire && (frameNumber < numFrames)) { usleep(2); @@ -2161,10 +2139,9 @@ static void xsp3DataTaskC(void *xspAD) lastAcquired = acquired; if (!pXspAD->createMCAArray(dims, pMCA, dataType)) { if (dataType == NDFloat64) { - error = pXspAD->readFrame(static_cast(pSCA), static_cast(pMCA->pData), frameNumber, maxSpectra); - } - else { - error = pXspAD->readFrame(static_cast(pSCA), static_cast(pMCA->pData), frameNumber, maxSpectra); + error = pXspAD->readFrame(static_cast(pSCA), static_cast(pMCA->pData), frameNumber, maxSpectra); + } else { + error = pXspAD->readFrame(static_cast(pSCA), static_cast(pMCA->pData), frameNumber, maxSpectra); } if (error) { pXspAD->xspAsynPrint(ASYN_TRACE_ERROR, "There was an error during read out %d\n", error); @@ -2180,11 +2157,9 @@ static void xsp3DataTaskC(void *xspAD) pXspAD->unlock(); pXspAD->doNDCallbacksIfRequired(pMCA); pMCA->release(); - } - else { + } else { pXspAD->xspAsynPrint(ASYN_TRACE_ERROR, "Did not create a new array!\n"); } - } if (pXspAD->checkForStopEvent(timeout, "Got stop event.\n") == epicsEventWaitOK) { acquire = false; @@ -2206,8 +2181,6 @@ static void xsp3DataTaskC(void *xspAD) /*************************************************************************************/ /** The following functions have C linkage, and can be called directly or from iocsh */ - - extern "C" { /** @@ -2224,64 +2197,62 @@ extern "C" { * @param debug This debug flag is passed to xsp3_config in the Xspress API (0 or 1) * @param simTest 0 or 1. Set to 1 to run up this driver in simulation mode. */ - int xspress3Config(const char *portName, int numChannels, int numCards, const char *baseIP, int maxFrames, int maxDriverFrames, int maxSpectra, int maxBuffers, size_t maxMemory, int debug, int simTest, int circBuffer) - { +int xspress3Config(const char *portName, int numChannels, int numCards, const char *baseIP, int maxFrames, int maxDriverFrames, int maxSpectra, int maxBuffers, size_t maxMemory, int debug, int simTest, int circBuffer) +{ asynStatus status = asynSuccess; /*Instantiate class.*/ try { - new Xspress3(portName, numChannels, numCards, baseIP, maxFrames, maxDriverFrames, maxSpectra, maxBuffers, maxMemory, debug, simTest, circBuffer); + new Xspress3(portName, numChannels, numCards, baseIP, maxFrames, maxDriverFrames, maxSpectra, maxBuffers, maxMemory, debug, simTest, circBuffer); } catch (...) { - cout << "Unknown exception caught when trying to construct Xspress3." << endl; - status = asynError; - } - - return(status); - } - - /* Code for iocsh registration */ - - /* xspress3Config */ - static const iocshArg xspress3ConfigArg0 = {"Port name", iocshArgString}; - static const iocshArg xspress3ConfigArg1 = {"Num Channels", iocshArgInt}; - static const iocshArg xspress3ConfigArg2 = {"Num Cards", iocshArgInt}; - static const iocshArg xspress3ConfigArg3 = {"Base IP Address", iocshArgString}; - static const iocshArg xspress3ConfigArg4 = {"Max Frames", iocshArgInt}; - static const iocshArg xspress3ConfigArg5 = {"Max driver Frames", iocshArgInt}; - static const iocshArg xspress3ConfigArg6 = {"Max Spectra", iocshArgInt}; - static const iocshArg xspress3ConfigArg7 = {"Max Buffers", iocshArgInt}; - static const iocshArg xspress3ConfigArg8 = {"Max Memory", iocshArgInt}; - static const iocshArg xspress3ConfigArg9 = {"Debug", iocshArgInt}; - static const iocshArg xspress3ConfigArg10 = {"Sim Test", iocshArgInt}; - static const iocshArg xspress3ConfigArg11 = {"Circular Buffer", iocshArgInt}; - static const iocshArg * const xspress3ConfigArgs[] = {&xspress3ConfigArg0, - &xspress3ConfigArg1, - &xspress3ConfigArg2, - &xspress3ConfigArg3, - &xspress3ConfigArg4, - &xspress3ConfigArg5, - &xspress3ConfigArg6, - &xspress3ConfigArg7, - &xspress3ConfigArg8, - &xspress3ConfigArg9, - &xspress3ConfigArg10, - &xspress3ConfigArg11}; - - - static const iocshFuncDef configXspress3 = {"xspress3Config", 12, xspress3ConfigArgs}; - static void configXspress3CallFunc(const iocshArgBuf *args) - { + cout << "Unknown exception caught when trying to construct Xspress3." << endl; + status = asynError; + } + + return (status); +} + +/* Code for iocsh registration */ + +/* xspress3Config */ +static const iocshArg xspress3ConfigArg0 = { "Port name", iocshArgString }; +static const iocshArg xspress3ConfigArg1 = { "Num Channels", iocshArgInt }; +static const iocshArg xspress3ConfigArg2 = { "Num Cards", iocshArgInt }; +static const iocshArg xspress3ConfigArg3 = { "Base IP Address", iocshArgString }; +static const iocshArg xspress3ConfigArg4 = { "Max Frames", iocshArgInt }; +static const iocshArg xspress3ConfigArg5 = { "Max driver Frames", iocshArgInt }; +static const iocshArg xspress3ConfigArg6 = { "Max Spectra", iocshArgInt }; +static const iocshArg xspress3ConfigArg7 = { "Max Buffers", iocshArgInt }; +static const iocshArg xspress3ConfigArg8 = { "Max Memory", iocshArgInt }; +static const iocshArg xspress3ConfigArg9 = { "Debug", iocshArgInt }; +static const iocshArg xspress3ConfigArg10 = { "Sim Test", iocshArgInt }; +static const iocshArg xspress3ConfigArg11 = { "Circular Buffer", iocshArgInt }; +static const iocshArg *const xspress3ConfigArgs[] = { &xspress3ConfigArg0, + &xspress3ConfigArg1, + &xspress3ConfigArg2, + &xspress3ConfigArg3, + &xspress3ConfigArg4, + &xspress3ConfigArg5, + &xspress3ConfigArg6, + &xspress3ConfigArg7, + &xspress3ConfigArg8, + &xspress3ConfigArg9, + &xspress3ConfigArg10, + &xspress3ConfigArg11 }; + +static const iocshFuncDef configXspress3 = { "xspress3Config", 12, xspress3ConfigArgs }; +static void configXspress3CallFunc(const iocshArgBuf *args) +{ xspress3Config(args[0].sval, args[1].ival, args[2].ival, args[3].sval, args[4].ival, args[5].ival, args[6].ival, args[7].ival, args[8].ival, args[9].ival, args[10].ival, args[11].ival); - } +} - static void xspress3Register(void) - { +static void xspress3Register(void) +{ iocshRegister(&configXspress3, configXspress3CallFunc); - } +} - epicsExportRegistrar(xspress3Register); +epicsExportRegistrar(xspress3Register); } // extern "C" - /****************************************************************************************/ diff --git a/xspress3App/src/xspress3Epics.h b/xspress3App/src/xspress3Epics.h index c98bab5e..28d979c7 100644 --- a/xspress3App/src/xspress3Epics.h +++ b/xspress3App/src/xspress3Epics.h @@ -27,25 +27,25 @@ #ifndef XSPRESS3_H #define XSPRESS3_H -#include -#include -#include +#include +#include +#include #include +#include +#include #include -#include +#include #include -#include -#include #include #include -#include -#include +#include #include #include -#include #include -#include +#include +#include +#include #include #include @@ -57,228 +57,224 @@ /* These are the drvInfo strings that are used to identify the parameters. * They are used by asyn clients, including standard asyn device support */ -//System wide settings -#define xsp3FirstParamString "XSP3_FIRST" -#define xsp3LastParamString "XSP3_LAST" -#define xsp3ResetParamString "XSP3_RESET" -#define xsp3EraseParamString "XSP3_ERASE" -#define xsp3EraseStartParamString "XSP3_ERASESTART" -#define xsp3NumChannelsParamString "XSP3_NUM_CHANNELS" -#define xsp3MaxNumChannelsParamString "XSP3_MAX_NUM_CHANNELS" -#define xsp3MaxSpectraParamString "XSP3_MAX_SPECTRA" -#define xsp3MaxFramesParamString "XSP3_MAX_FRAMES" -#define xsp3FrameCountParamString "XSP3_FRAME_COUNT" -#define xsp3TriggerModeParamString "XSP3_TRIGGER_MODE" -#define xsp3SoftTriggerParamString "XSP3_SOFT_TRIGGER" -#define xsp3FixedTimeParamString "XSP3_FIXED_TIME" -#define xsp3NumFramesConfigParamString "XSP3_NUM_FRAMES_CONFIG" -#define xsp3NumFramesDriverParamString "XSP3_NUM_FRAMES_DRIVER" -#define xsp3NumCardsParamString "XSP3_NUM_CARDS" -#define xsp3ConfigPathParamString "XSP3_CONFIG_PATH" -#define xsp3ConfigSavePathParamString "XSP3_CONFIG_SAVE_PATH" -#define xsp3ConnectParamString "XSP3_CONNECT" -#define xsp3ConnectedParamString "XSP3_CONNECTED" -#define xsp3DisconnectParamString "XSP3_DISCONNECT" -#define xsp3SaveSettingsParamString "XSP3_SAVE_SETTINGS" -#define xsp3RestoreSettingsParamString "XSP3_RESTORE_SETTINGS" -#define xsp3RunFlagsParamString "XSP3_RUN_FLAGS" -#define xsp3TriggerParamString "XSP3_TRIGGER" -#define xsp3InvertF0ParamString "XSP3_INVERT_F0" -#define xsp3InvertVetoParamString "XSP3_INVERT_VETO" -#define xsp3DebounceParamString "XSP3_DEBOUNCE" -#define xsp3PulsePerTriggerParamString "XSP3_PPTRIGGER" -#define xsp3ITFGStartParamString "XSP3_ITFG_START" -#define xsp3ITFGStopParamString "XSP3_ITFG_STOP" -//Settings for a channel -#define xsp3ChanSca0ParamString "XSP3_CHAN_SCA0" -#define xsp3ChanSca1ParamString "XSP3_CHAN_SCA1" -#define xsp3ChanSca2ParamString "XSP3_CHAN_SCA2" -#define xsp3ChanSca3ParamString "XSP3_CHAN_SCA3" -#define xsp3ChanSca4ParamString "XSP3_CHAN_SCA4" -#define xsp3ChanSca5ParamString "XSP3_CHAN_SCA5" -#define xsp3ChanSca6ParamString "XSP3_CHAN_SCA6" -#define xsp3ChanSca7ParamString "XSP3_CHAN_SCA7" -#define xsp3ChanSca4ThresholdParamString "XSP3_CHAN_SCA4_THRESHOLD" -#define xsp3ChanSca5HlmParamString "XSP3_CHAN_SCA5_HLM" -#define xsp3ChanSca6HlmParamString "XSP3_CHAN_SCA6_HLM" -#define xsp3ChanSca5LlmParamString "XSP3_CHAN_SCA5_LLM" -#define xsp3ChanSca6LlmParamString "XSP3_CHAN_SCA6_LLM" -#define xsp3ChanDtcFlagsParamString "XSP3_CHAN_DTC_FLAGS" -#define xsp3ChanDtcAegParamString "XSP3_CHAN_DTC_AEG" -#define xsp3ChanDtcAeoParamString "XSP3_CHAN_DTC_AEO" -#define xsp3ChanDtcIwgParamString "XSP3_CHAN_DTC_IWG" -#define xsp3ChanDtcIwoParamString "XSP3_CHAN_DTC_IWO" -//Params to enable or disable calculations -#define xsp3RoiEnableParamString "XSP3_CTRL_MCA_ROI" -#define xsp3DtcEnableParamString "XSP3_CTRL_DTC" -#define xsp3EventWidthParamString "XSP3_EVENT_WIDTH" -#define xsp3ChanDTPercentParamString "XSP3_CHAN_DTPERCENT" -#define xsp3ChanDTFactorParamString "XSP3_CHAN_DTFACTOR" - +// System wide settings +#define xsp3FirstParamString "XSP3_FIRST" +#define xsp3LastParamString "XSP3_LAST" +#define xsp3ResetParamString "XSP3_RESET" +#define xsp3EraseParamString "XSP3_ERASE" +#define xsp3EraseStartParamString "XSP3_ERASESTART" +#define xsp3NumChannelsParamString "XSP3_NUM_CHANNELS" +#define xsp3MaxNumChannelsParamString "XSP3_MAX_NUM_CHANNELS" +#define xsp3MaxSpectraParamString "XSP3_MAX_SPECTRA" +#define xsp3MaxFramesParamString "XSP3_MAX_FRAMES" +#define xsp3FrameCountParamString "XSP3_FRAME_COUNT" +#define xsp3TriggerModeParamString "XSP3_TRIGGER_MODE" +#define xsp3SoftTriggerParamString "XSP3_SOFT_TRIGGER" +#define xsp3FixedTimeParamString "XSP3_FIXED_TIME" +#define xsp3NumFramesConfigParamString "XSP3_NUM_FRAMES_CONFIG" +#define xsp3NumFramesDriverParamString "XSP3_NUM_FRAMES_DRIVER" +#define xsp3NumCardsParamString "XSP3_NUM_CARDS" +#define xsp3ConfigPathParamString "XSP3_CONFIG_PATH" +#define xsp3ConfigSavePathParamString "XSP3_CONFIG_SAVE_PATH" +#define xsp3ConnectParamString "XSP3_CONNECT" +#define xsp3ConnectedParamString "XSP3_CONNECTED" +#define xsp3DisconnectParamString "XSP3_DISCONNECT" +#define xsp3SaveSettingsParamString "XSP3_SAVE_SETTINGS" +#define xsp3RestoreSettingsParamString "XSP3_RESTORE_SETTINGS" +#define xsp3RunFlagsParamString "XSP3_RUN_FLAGS" +#define xsp3TriggerParamString "XSP3_TRIGGER" +#define xsp3InvertF0ParamString "XSP3_INVERT_F0" +#define xsp3InvertVetoParamString "XSP3_INVERT_VETO" +#define xsp3DebounceParamString "XSP3_DEBOUNCE" +#define xsp3PulsePerTriggerParamString "XSP3_PPTRIGGER" +#define xsp3ITFGStartParamString "XSP3_ITFG_START" +#define xsp3ITFGStopParamString "XSP3_ITFG_STOP" +// Settings for a channel +#define xsp3ChanSca0ParamString "XSP3_CHAN_SCA0" +#define xsp3ChanSca1ParamString "XSP3_CHAN_SCA1" +#define xsp3ChanSca2ParamString "XSP3_CHAN_SCA2" +#define xsp3ChanSca3ParamString "XSP3_CHAN_SCA3" +#define xsp3ChanSca4ParamString "XSP3_CHAN_SCA4" +#define xsp3ChanSca5ParamString "XSP3_CHAN_SCA5" +#define xsp3ChanSca6ParamString "XSP3_CHAN_SCA6" +#define xsp3ChanSca7ParamString "XSP3_CHAN_SCA7" +#define xsp3ChanSca4ThresholdParamString "XSP3_CHAN_SCA4_THRESHOLD" +#define xsp3ChanSca5HlmParamString "XSP3_CHAN_SCA5_HLM" +#define xsp3ChanSca6HlmParamString "XSP3_CHAN_SCA6_HLM" +#define xsp3ChanSca5LlmParamString "XSP3_CHAN_SCA5_LLM" +#define xsp3ChanSca6LlmParamString "XSP3_CHAN_SCA6_LLM" +#define xsp3ChanDtcFlagsParamString "XSP3_CHAN_DTC_FLAGS" +#define xsp3ChanDtcAegParamString "XSP3_CHAN_DTC_AEG" +#define xsp3ChanDtcAeoParamString "XSP3_CHAN_DTC_AEO" +#define xsp3ChanDtcIwgParamString "XSP3_CHAN_DTC_IWG" +#define xsp3ChanDtcIwoParamString "XSP3_CHAN_DTC_IWO" +// Params to enable or disable calculations +#define xsp3RoiEnableParamString "XSP3_CTRL_MCA_ROI" +#define xsp3DtcEnableParamString "XSP3_CTRL_DTC" +#define xsp3EventWidthParamString "XSP3_EVENT_WIDTH" +#define xsp3ChanDTPercentParamString "XSP3_CHAN_DTPERCENT" +#define xsp3ChanDTFactorParamString "XSP3_CHAN_DTFACTOR" extern "C" { - int xspress3Config(const char *portName, int numChannels, int numCards, const char *baseIP, int maxFrames, int maxDriverFrames, int maxSpectra, int maxBuffers, size_t maxMemory, int debug, int simTest, int circBuffer); +int xspress3Config(const char *portName, int numChannels, int numCards, const char *baseIP, int maxFrames, int maxDriverFrames, int maxSpectra, int maxBuffers, size_t maxMemory, int debug, int simTest, int circBuffer); } - class Xspress3 : public ADDriver { - public: - Xspress3(const char *portName, int numChannels, int numCards, const char *baseIP, int maxFrames, int maxDriverFrames, int maxSpectra, int maxBuffers, size_t maxMemory, int debug, int simTest, int circBuffer); - Xspress3(const char *portName, int numChannels); - virtual ~Xspress3(); - - /* These are the methods that we override from asynPortDriver */ - virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); - virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value); - virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, - size_t nChars, size_t *nActual); - virtual void report(FILE *fp, int details); +public: + Xspress3(const char *portName, int numChannels, int numCards, const char *baseIP, int maxFrames, int maxDriverFrames, int maxSpectra, int maxBuffers, size_t maxMemory, int debug, int simTest, int circBuffer); + Xspress3(const char *portName, int numChannels); + virtual ~Xspress3(); - const int checkForStopEvent(double timeout, const char *message); - const int waitForStartEvent(const char *message); - void adReportError(const char* message); - bool createMCAArray(size_t dims[2], NDArray *&pMCA, NDDataType_t dataType); - bool createSCAArray(void *&pSCA); - bool readFrame(double* pSCA, double* pMCAData, int frameNumber, int maxSpectra); - bool readFrame(u_int32_t* pSCA, u_int32_t* pMCAData, int frameNumber, int maxSpectra); - void writeOutScas(void *&pSCA, int numChannels, NDDataType_t dataType); - void setStartingParameters(); - const NDDataType_t getDataType(); - void getDims(size_t (&dims)[2]); - asynStatus checkHistBusy(int checkTimes); - const int getXsp3Handle() { return this->xsp3_handle_; } - xsp3Api *getXsp3() { return this->xsp3; } - void setNDArrayAttributes(NDArray *&pMCA, int frameNumber); - void setAcqStopParameters(bool aborted); - int getNumFramesToAcquire(); - int getMaxNumFrames(); - int getFrameCounter(); - void doNDCallbacksIfRequired(NDArray *pMCA); - int getNumFramesRead(); - void xspAsynPrint(int asynPrintType, const char *format, ...); + /* These are the methods that we override from asynPortDriver */ + virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); + virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value); + virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, + size_t nChars, size_t *nActual); + virtual void report(FILE *fp, int details); - private: + const int checkForStopEvent(double timeout, const char *message); + const int waitForStartEvent(const char *message); + void adReportError(const char *message); + bool createMCAArray(size_t dims[2], NDArray *&pMCA, NDDataType_t dataType); + bool createSCAArray(void *&pSCA); + bool readFrame(double *pSCA, double *pMCAData, int frameNumber, int maxSpectra); + bool readFrame(u_int32_t *pSCA, u_int32_t *pMCAData, int frameNumber, int maxSpectra); + void writeOutScas(void *&pSCA, int numChannels, NDDataType_t dataType); + void setStartingParameters(); + const NDDataType_t getDataType(); + void getDims(size_t (&dims)[2]); + asynStatus checkHistBusy(int checkTimes); + const int getXsp3Handle() { return this->xsp3_handle_; } + xsp3Api *getXsp3() { return this->xsp3; } + void setNDArrayAttributes(NDArray *&pMCA, int frameNumber); + void setAcqStopParameters(bool aborted); + int getNumFramesToAcquire(); + int getMaxNumFrames(); + int getFrameCounter(); + void doNDCallbacksIfRequired(NDArray *pMCA); + int getNumFramesRead(); + void xspAsynPrint(int asynPrintType, const char *format, ...); - //Put private functions here - void checkStatus(int status, const char *function, const char *parentFunction); - asynStatus connect(void); - asynStatus disconnect(void); - asynStatus saveSettings(void); - asynStatus restoreSettings(void); - asynStatus checkConnected(void); - asynStatus setWindow(int channel, int sca, int llm, int hlm); - asynStatus checkRoi(int channel, int roi, int llm, int hlm); - asynStatus erase(void); - asynStatus eraseSCAMCAROI(void); - asynStatus checkSaveDir(const char *dirName); - asynStatus readSCAParams(void); - asynStatus readDTCParams(void); - asynStatus readTrigB(void); - asynStatus setupITFG(void); - asynStatus mapTriggerMode(int mode, int invert_f0, int invert_veto, int debounce, int *apiMode); - asynStatus setTriggerMode(int mode, int invert_f0, int invert_veto, int debounce ); - void createInitialParameters(); - bool setInitialParameters(int maxFrames, int maxDriverFrames, int numCards, int maxSpectra); +private: + // Put private functions here + void checkStatus(int status, const char *function, const char *parentFunction); + asynStatus connect(void); + asynStatus disconnect(void); + asynStatus saveSettings(void); + asynStatus restoreSettings(void); + asynStatus checkConnected(void); + asynStatus setWindow(int channel, int sca, int llm, int hlm); + asynStatus checkRoi(int channel, int roi, int llm, int hlm); + asynStatus erase(void); + asynStatus eraseSCAMCAROI(void); + asynStatus checkSaveDir(const char *dirName); + asynStatus readSCAParams(void); + asynStatus readDTCParams(void); + asynStatus readTrigB(void); + asynStatus setupITFG(void); + asynStatus mapTriggerMode(int mode, int invert_f0, int invert_veto, int debounce, int *apiMode); + asynStatus setTriggerMode(int mode, int invert_f0, int invert_veto, int debounce); + void createInitialParameters(); + bool setInitialParameters(int maxFrames, int maxDriverFrames, int numCards, int maxSpectra); - //Put private static data members here - static const epicsInt32 ctrlDisable_; - static const epicsInt32 ctrlEnable_; - static const epicsInt32 runFlag_MCA_SPECTRA_; - static const epicsInt32 runFlag_PLAYB_MCA_SPECTRA_; - static const epicsInt32 maxNumRoi_; - static const epicsInt32 maxStringSize_; - static const epicsInt32 maxCheckHistPolls_; - static const epicsInt32 mbboTriggerFIXED_; - static const epicsInt32 mbboTriggerINTERNAL_; - static const epicsInt32 mbboTriggerIDC_; - static const epicsInt32 mbboTriggerTTLVETO_; - static const epicsInt32 mbboTriggerTTLBOTH_; - static const epicsInt32 mbboTriggerLVDSVETO_; - static const epicsInt32 mbboTriggerLVDSBOTH_; - static const epicsInt32 mbboTriggerSOFTINTERNAL_; - static const epicsInt32 mbboTriggerTTLINTERNAL_; - static const epicsInt32 ADAcquireFalse_; - static const epicsInt32 ADAcquireTrue_; + // Put private static data members here + static const epicsInt32 ctrlDisable_; + static const epicsInt32 ctrlEnable_; + static const epicsInt32 runFlag_MCA_SPECTRA_; + static const epicsInt32 runFlag_PLAYB_MCA_SPECTRA_; + static const epicsInt32 maxNumRoi_; + static const epicsInt32 maxStringSize_; + static const epicsInt32 maxCheckHistPolls_; + static const epicsInt32 mbboTriggerFIXED_; + static const epicsInt32 mbboTriggerINTERNAL_; + static const epicsInt32 mbboTriggerIDC_; + static const epicsInt32 mbboTriggerTTLVETO_; + static const epicsInt32 mbboTriggerTTLBOTH_; + static const epicsInt32 mbboTriggerLVDSVETO_; + static const epicsInt32 mbboTriggerLVDSBOTH_; + static const epicsInt32 mbboTriggerSOFTINTERNAL_; + static const epicsInt32 mbboTriggerTTLINTERNAL_; + static const epicsInt32 ADAcquireFalse_; + static const epicsInt32 ADAcquireTrue_; - //Put private dynamic here - int xsp3_handle_; + // Put private dynamic here + int xsp3_handle_; - xsp3Api* xsp3; + xsp3Api *xsp3; - //Constructor parameters. - const epicsUInt32 debug_; //debug parameter for API - const epicsInt32 numChannels_; //The number of channels - const epicsUInt32 simTest_; //Run in sim mode - const std::string baseIP_; //Constructor param - IP address of host system - const int circBuffer_; //Circular buffer flag to turn on + // Constructor parameters. + const epicsUInt32 debug_; // debug parameter for API + const epicsInt32 numChannels_; // The number of channels + const epicsUInt32 simTest_; // Run in sim mode + const std::string baseIP_; // Constructor param - IP address of host system + const int circBuffer_; // Circular buffer flag to turn on - epicsEventId statusEvent_; - epicsEventId startEvent_; - epicsEventId stopEvent_; + epicsEventId statusEvent_; + epicsEventId startEvent_; + epicsEventId stopEvent_; - //Values used for pasynUser->reason, and indexes into the parameter library. - int xsp3FirstParam; - #define XSP3_FIRST_DRIVER_COMMAND xsp3FirstParam - int xsp3ResetParam; - int xsp3EraseParam; - int xsp3EraseStartParam; - int xsp3NumChannelsParam; - int xsp3MaxNumChannelsParam; - int xsp3MaxSpectraParam; - int xsp3SoftTriggerParam; - int xsp3MaxFramesParam; - int xsp3FrameCountParam; - int xsp3TriggerModeParam; - int xsp3FixedTimeParam; - int xsp3NumFramesConfigParam; - int xsp3NumFramesDriverParam; - int xsp3NumCardsParam; - int xsp3ConfigPathParam; - int xsp3ConfigSavePathParam; - int xsp3ConnectParam; - int xsp3ConnectedParam; - int xsp3DisconnectParam; - int xsp3SaveSettingsParam; - int xsp3RestoreSettingsParam; - int xsp3RunFlagsParam; - int xsp3TriggerParam; - int xsp3InvertF0Param; - int xsp3InvertVetoParam; - int xsp3DebounceParam; - int xsp3ChanSca0Param; - int xsp3ChanSca1Param; - int xsp3ChanSca2Param; - int xsp3ChanSca3Param; - int xsp3ChanSca4Param; - int xsp3ChanSca5Param; - int xsp3ChanSca6Param; - int xsp3ChanSca7Param; - int xsp3ChanSca4ThresholdParam; - int xsp3ChanSca5HlmParam; - int xsp3ChanSca6HlmParam; - int xsp3ChanSca5LlmParam; - int xsp3ChanSca6LlmParam; - int xsp3ChanDtcFlagsParam; - int xsp3ChanDtcAegParam; - int xsp3ChanDtcAeoParam; - int xsp3ChanDtcIwgParam; - int xsp3ChanDtcIwoParam; - int xsp3RoiEnableParam; - int xsp3DtcEnableParam; - int xsp3EventWidthParam; - int xsp3ChanDTPercentParam; - int xsp3ChanDTFactorParam; - int xsp3PulsePerTriggerParam; - int xsp3ITFGStartParam; - int xsp3ITFGStopParam; - int xsp3LastParam; - #define XSP3_LAST_DRIVER_COMMAND xsp3LastParam + // Values used for pasynUser->reason, and indexes into the parameter library. + int xsp3FirstParam; +#define XSP3_FIRST_DRIVER_COMMAND xsp3FirstParam + int xsp3ResetParam; + int xsp3EraseParam; + int xsp3EraseStartParam; + int xsp3NumChannelsParam; + int xsp3MaxNumChannelsParam; + int xsp3MaxSpectraParam; + int xsp3SoftTriggerParam; + int xsp3MaxFramesParam; + int xsp3FrameCountParam; + int xsp3TriggerModeParam; + int xsp3FixedTimeParam; + int xsp3NumFramesConfigParam; + int xsp3NumFramesDriverParam; + int xsp3NumCardsParam; + int xsp3ConfigPathParam; + int xsp3ConfigSavePathParam; + int xsp3ConnectParam; + int xsp3ConnectedParam; + int xsp3DisconnectParam; + int xsp3SaveSettingsParam; + int xsp3RestoreSettingsParam; + int xsp3RunFlagsParam; + int xsp3TriggerParam; + int xsp3InvertF0Param; + int xsp3InvertVetoParam; + int xsp3DebounceParam; + int xsp3ChanSca0Param; + int xsp3ChanSca1Param; + int xsp3ChanSca2Param; + int xsp3ChanSca3Param; + int xsp3ChanSca4Param; + int xsp3ChanSca5Param; + int xsp3ChanSca6Param; + int xsp3ChanSca7Param; + int xsp3ChanSca4ThresholdParam; + int xsp3ChanSca5HlmParam; + int xsp3ChanSca6HlmParam; + int xsp3ChanSca5LlmParam; + int xsp3ChanSca6LlmParam; + int xsp3ChanDtcFlagsParam; + int xsp3ChanDtcAegParam; + int xsp3ChanDtcAeoParam; + int xsp3ChanDtcIwgParam; + int xsp3ChanDtcIwoParam; + int xsp3RoiEnableParam; + int xsp3DtcEnableParam; + int xsp3EventWidthParam; + int xsp3ChanDTPercentParam; + int xsp3ChanDTFactorParam; + int xsp3PulsePerTriggerParam; + int xsp3ITFGStartParam; + int xsp3ITFGStopParam; + int xsp3LastParam; +#define XSP3_LAST_DRIVER_COMMAND xsp3LastParam }; #define NUM_DRIVER_PARAMS (&XSP3_LAST_DRIVER_COMMAND - &XSP3_FIRST_DRIVER_COMMAND + 1) -//static const char *driverName = "Xspress3"; - +// static const char *driverName = "Xspress3"; -#endif //ISC110BL_H +#endif // ISC110BL_H diff --git a/xspress3App/src/xspress3Main.cpp b/xspress3App/src/xspress3Main.cpp index c3d4a813..c09bcd9a 100644 --- a/xspress3App/src/xspress3Main.cpp +++ b/xspress3App/src/xspress3Main.cpp @@ -2,22 +2,21 @@ /* Author: Marty Kraimer Date: 17MAR2000 */ #include +#include #include -#include #include -#include #include "epicsExit.h" #include "epicsThread.h" #include "iocsh.h" -int main(int argc,char *argv[]) +int main(int argc, char *argv[]) { - if(argc>=2) { + if (argc >= 2) { iocsh(argv[1]); epicsThreadSleep(.2); } iocsh(NULL); epicsExit(0); - return(0); + return (0); }