Compare commits

..

51 Commits

Author SHA1 Message Date
ec9f8305e9 not export gui 2020-03-18 08:41:25 +01:00
3307bfab1b fix 2020-03-17 19:11:29 +01:00
ce2c62000d include cmake in build 2020-03-17 18:57:19 +01:00
cf817c4ec1 WIP 2020-03-17 18:29:51 +01:00
bd01a5f2d2 cmake pkg 2020-03-16 19:36:18 +01:00
b059ba7c90 Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer 2020-03-16 15:43:55 +01:00
89d70097f6 WIP 2020-03-16 15:43:46 +01:00
41d115a394 Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer 2020-03-13 19:36:38 +01:00
45c1d3a553 gotthard2: burst mode fix for all the registers 2020-03-13 19:36:23 +01:00
17227be4df gotthard2: burst mode fix 2020-03-13 17:39:16 +01:00
7f4f8e8f09 help bug emax 2020-03-13 09:56:11 +01:00
6809bd6567 removed header 2020-03-12 12:38:00 +01:00
711d40a56e added sendToReceiver 2020-03-12 11:45:12 +01:00
81911fae3c new version of send to detector 2020-03-11 19:18:26 +01:00
f940397e3a cleaning 2020-03-11 18:10:37 +01:00
dc53887a48 minor clean 2020-03-11 17:49:32 +01:00
5784ce8231 slsDetector -> Module 2020-03-11 16:16:15 +01:00
012c66bbbf minor 2020-03-11 15:57:10 +01:00
3dbd6a33f7 removed genericSocket 2020-03-11 13:39:40 +01:00
0de0d82a1a replaced old logger 2020-03-11 12:40:12 +01:00
4aeb8bf62e introducing new logger 2020-03-11 10:54:55 +01:00
2acf64b09c gui changes (#87) 2020-03-11 10:08:30 +01:00
dea8cba985 changes from 4.2.0-rc: eiger check for max trimbits; end of eigerserver: if detector ip, set activate; update both control and stop server for activate 2020-03-10 16:49:08 +01:00
9467b4c610 Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer 2020-03-10 16:25:15 +01:00
2cb09a590a gotthard2, mythen3: firmware type check added, others: minor print 2020-03-10 16:25:07 +01:00
5900403f20 Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer 2020-03-10 16:10:09 +01:00
53749c3b77 clean 2020-03-10 16:09:59 +01:00
1d2f4a8af0 Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer 2020-03-10 15:59:35 +01:00
df2512fb1c all servers: eiger, jungfrau, gotthard, ctb, moench, mythen3, gotthard2 updated 2020-03-10 15:57:27 +01:00
e4942a5c8d virtual servers warnings fixed 2020-03-10 15:53:44 +01:00
ac1c40d6f9 virtual servers: redundant declarations fixed 2020-03-10 15:50:33 +01:00
8ba0ef093e cmap 2020-03-10 15:50:14 +01:00
cb268aa43f cmap 2020-03-10 15:49:54 +01:00
5192dae9c5 removed virtual server warnings 2020-03-10 15:15:09 +01:00
d818e2570f clang-tidy nullptr 2020-03-10 15:06:51 +01:00
ee799b540a removed redundant includes etc. 2020-03-10 11:12:00 +01:00
ae3189d836 changed cxx to cpp 2020-03-10 10:28:27 +01:00
9ede0629ef clang format on gui 2020-03-10 10:18:52 +01:00
bd6529a64c warnings for virtual servers 2020-03-10 09:27:23 +01:00
758afad02c ctb, moench, eiger, gotthard: get number of channels for moench and ctb, others removed unnecessary variables in shm, added moench virtual sever (#86) 2020-03-10 09:08:08 +01:00
013836bea5 Merge pull request #85 from slsdetectorgroup/qwtifdef
Version defs and checking pointer before delete
2020-03-09 18:06:25 +01:00
de6808b170 Update CMakeLists.txt
qwt minimum 6.1
2020-03-09 18:05:27 +01:00
4c4ee3ae25 Merge pull request #83 from slsdetectorgroup/logger
New logger
2020-03-09 17:46:18 +01:00
0e171f291d added std::flush 2020-03-09 13:57:50 +01:00
bd47c969dd WIP 2020-03-09 12:49:24 +01:00
e4a86e544a WIP 2020-03-09 12:42:57 +01:00
a4fa9ff480 gui: scroll area uniquie pointers to remove mem leak 2020-03-06 19:44:44 +01:00
c6ddd19c0f WIP 2020-03-04 15:38:21 +01:00
661adaf4ed WIP 2020-03-04 15:25:49 +01:00
ff9c37701b WIP 2020-03-04 12:35:41 +01:00
3431752649 WIP 2020-03-03 17:01:45 +01:00
150 changed files with 9186 additions and 9512 deletions

View File

@ -17,7 +17,8 @@ Checks: '*,
-google-runtime-references,
-google-readability-todo,
-google-readability-braces-around-statements,
-modernize-use-trailing-return-type'
-modernize-use-trailing-return-type,
-readability-isolate-declaration'
HeaderFilterRegex: \.h
AnalyzeTemporaryDtors: false

View File

@ -167,7 +167,7 @@ endif (SLS_USE_RECEIVER)
if (SLS_USE_GUI)
find_package(Qt4 REQUIRED)
find_package(Qwt 6 REQUIRED)
find_package(Qwt 6.1 REQUIRED)
if (QT4_FOUND AND QWT_FOUND)
add_subdirectory(slsDetectorGui)
endif()
@ -203,11 +203,9 @@ if(SLS_BUILD_DOCS)
add_subdirectory(docs)
endif(SLS_BUILD_DOCS)
if(SLS_MASTER_PROJECT)
# Set install dir CMake packages
set(CMAKE_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/cmake/sls)
set(CMAKE_INSTALL_DIR "share/cmake/${PROJECT_NAME}")
# Set the list of exported targets
set(PROJECT_LIBRARIES slsSupportLib slsDetectorShared slsReceiverShared)
# Generate and install package config file and version

View File

@ -15,17 +15,20 @@ configure_package_config_file(
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
COMPATIBILITY SameMajorVersion
)
install(FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}-config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}-config-version.cmake"
COMPONENT devel
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME_LOWER})
DESTINATION ${CMAKE_INSTALL_DIR}
)
if (PROJECT_LIBRARIES OR PROJECT_STATIC_LIBRARIES)
install(
EXPORT "${TARGETS_EXPORT_NAME}"
FILE ${PROJECT_NAME_LOWER}-targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME_LOWER})
DESTINATION ${CMAKE_INSTALL_DIR}
)
endif ()

View File

@ -5,18 +5,20 @@ mkdir $PREFIX/include
mkdir $PREFIX/include/slsDetectorPackage
#Shared and static libraries
cp build/bin/libSlsDetector.so $PREFIX/lib/.
cp build/bin/libSlsReceiver.so $PREFIX/lib/.
cp build/bin/libSlsSupport.so $PREFIX/lib/.
# cp build/bin/libSlsDetector.so $PREFIX/lib/.
# cp build/bin/libSlsReceiver.so $PREFIX/lib/.
# cp build/bin/libSlsSupport.so $PREFIX/lib/.
cp build/install/lib/* $PREFIX/lib/
#Binaries
cp build/bin/sls_detector_acquire $PREFIX/bin/.
cp build/bin/sls_detector_get $PREFIX/bin/.
cp build/bin/sls_detector_put $PREFIX/bin/.
cp build/bin/sls_detector_help $PREFIX/bin/.
cp build/bin/slsReceiver $PREFIX/bin/.
cp build/bin/slsMultiReceiver $PREFIX/bin/.
cp build/install/bin/sls_detector_acquire $PREFIX/bin/.
cp build/install/bin/sls_detector_get $PREFIX/bin/.
cp build/install/bin/sls_detector_put $PREFIX/bin/.
cp build/install/bin/sls_detector_help $PREFIX/bin/.
cp build/install/bin/slsReceiver $PREFIX/bin/.
cp build/install/bin/slsMultiReceiver $PREFIX/bin/.
#Which headers do we need for development??
cp build/install/include/* $PREFIX/include/slsDetectorPackage/
# cp include/some_lib.h $PREFIX/include/.
cp build/install/include/* $PREFIX/include/
cp -r build/install/share/ $PREFIX/share

View File

@ -7,7 +7,7 @@ source:
- path: ..
build:
number: 2
number: 0
binary_relocation: True
rpaths:
- lib/

View File

@ -3,7 +3,7 @@ find_package(Sphinx)
if (DOXYGEN_FOUND AND SPHINX_FOUND)
message(${CMAKE_PROJECT_SORURCE_DIR}/slsDetectorSoftware/src)
# message(${CMAKE_PROJECT_SORURCE_DIR}/slsDetectorSoftware/src)
# Utility to generate command line documentation
add_executable(gendoc src/gendoc.cpp)
# This is a bit hacky, but better than exposing stuff?
@ -30,6 +30,7 @@ if (DOXYGEN_FOUND AND SPHINX_FOUND)
set(SPHINX_SOURCE_FILES
src/commandline.rst
src/container_utils.rst
src/consuming.rst
src/dependencies.rst
src/detector.rst
src/index.rst
@ -41,6 +42,7 @@ if (DOXYGEN_FOUND AND SPHINX_FOUND)
src/result.rst
src/type_traits.rst
src/ToString.rst
src/examples.rst
)

95
docs/src/consuming.rst Normal file
View File

@ -0,0 +1,95 @@
Consuming slsDetectorPackage
===============================
Depending on how you want to build your integration with
slsDetectorPackage there are a few different ways to
consume our package. The recommended way is to use one of the
CMake approaches.
CMake: slsDetectorPackage as submodule in your project
---------------------------------------
If you are using CMake to build your integration and want to build everything
in one go, we support adding slsDetectorPackage as a subfolder in your cmake project.
A minimal CMakeLists.txt could look like this:
.. code-block:: cmake
project(myDetectorIntegration)
cmake_minimum_required(VERSION 3.12)
add_subdirectory(slsDetectorPackage)
#Add your executable
add_executable(example main.cpp)
target_compile_features(example PRIVATE cxx_std_11)
#Link towards slsDetectorShared
target_link_libraries(example slsDetectorShared)
A fully working example can be found at:
https://github.com/slsdetectorgroup/cmake-subfolder-example
CMake: find_package(slsDetectorPackage)
------------------------------------------
If you have compiled and installed slsDetectorPackage we also support
find_package in CMake. If installed in a system wide location no path
should be needed, otherwise specify cmake prefix path.
.. code-block:: cmake
cmake_minimum_required(VERSION 3.12)
project(myintegration)
find_package(slsDetectorPackage 5.0 REQUIRED)
add_executable(example main.cpp)
target_link_libraries(example slsDetectorShared)
Then assuming the slsDetectorPackage is installed in /path/to/sls/install
you should be able to configure and build your project in this way.
.. code-block:: bash
cmake ../path/to/your/source -DCMAKE_PREFIX_PATH=/path/to/sls/install
make
A minimal example is available at: https://github.com/slsdetectorgroup/minimal-cmake
No tools minimal approach
-----------------------------
While not recommended it is still possible to specify the include and library paths
manually when invoking g++. This can sometimes be handy for a quick try.
.. code-block:: cpp
#include "Detector.h"
#include <iostream>
int main(){
sls::Detector det;
//Get all values and print them
std::cout << "Hostname: " << det.getHostname() << "\n";
std::cout << "Type: " << det.getDetectorType() << "\n";
std::cout << "Udp ip: " << det.getSourceUDPIP() << "\n";
//Get mac addr
const int module = 0;
auto mac = det.getSourceUDPMAC()[module];
std::cout << "Mac addr of module "<< module << " is " << mac.str() << '\n';
}
.. code-block:: bash
g++ -I/install/path/include/ -L/install/path/lib64/ myapp.cpp -lSlsDetector -lSlsSupport -Wl,-rpath=../install/path/lib64

View File

@ -13,7 +13,7 @@ To use the basic building blocks, meaning sls_detector_get/put and
the shared libraries these are needed:
* Linux, preferably recent kernel (currently no cross platform support)
* CMake > 3.9
* CMake > 3.12
* C++11 compatible compiler. (We test with gcc and clang)
* ZeroMQ version 4
@ -24,7 +24,7 @@ GUI
The GUI is currently using Qt4 but watch out for an upgrade to 5.
* Qt 4.8
* Qwt 6
* Qwt 6.1
-----------------------
Python bindings

115
docs/src/examples.rst Normal file
View File

@ -0,0 +1,115 @@
Examples
===========
Setup
------------
The examples here assume that you have compiled and installed slsDetectorPackage
to ~/sls/install and that the option for SLS_USE_SIMULATOR was enabled. This also builds
the virtual detector servers that we will be using for testing.
We also add ~/sls/detector/install/bin to the path for convenience.
Compile examples
-------------------
The source code of the examples is available at:
https://github.com/slsdetectorgroup/api-examples
.. code-block:: bash
git clone https://github.com/slsdetectorgroup/api-examples.git
mkdir build && cd build
cmake ../api-examples -DCMAKE_PREFIX_PATH=~/sls/detector/install
make
Below follows a short description of what is included in the examples.
Running a config file [e1]
-----------------------------
.. code-block:: cpp
#include "Detector.h"
...
sls::Detector det;
det.loadConfig("path/to/config/file.config");
To configure the connection between PC and detector the easiest
is to run a config file. For this example we first launch a virtual Jungfrau server and
then set up the detector.
**Launch a virtual detector server**
.. code-block:: bash
jungfrauDetectorServer_virtual
This launches a virtual Jungfrau detector server. As default is uses port 1952 and 1953
for communication over TCP. Most commands go on 1952 and only stop and status on 1953.
**Run example to configure**
.. code-block:: bash
./e1-config one_det_no_receiver.config
- 12:01:06.371 INFO: Shared memory deleted /slsDetectorPackage_multi_0_sls_0
- 12:01:06.371 INFO: Shared memory deleted /slsDetectorPackage_multi_0
- 12:01:06.372 INFO: Shared memory created /slsDetectorPackage_multi_0
- 12:01:06.376 INFO: Loading configuration file: one_det_no_receiver.config
- 12:01:06.376 INFO: Adding detector localhost
- 12:01:06.377 INFO: Shared memory created /slsDetectorPackage_multi_0_sls_0
- 12:01:06.377 INFO: Checking Detector Version Compatibility
- 12:01:06.378 INFO: Detector connecting - updating!
hostname [localhost]
Jungfrau detector with 1 modules configured
Using the return type sls::Result [e2]
-----------------------------------------
Since many our detectors have multiple modules we cannot return
a single value when reading from the Detector. Hostname, Ip and also
for example exposure time can differ between modules.
Therefore we return Result<T> which is a thin wrapper around
std::vector.
.. code-block:: cpp
sls::Result<int> res1{1, 1, 1};
std::cout << "res1: " << res1 << '\n';
res1.squash();
res1.squash(-1);
Setting exposure time [e3]
-----------------------------------------
For setting times, like exposure time, period, delay etc.
we use std::chrono::duration.
Example 3 shows how to set and read exposure time as well
as converting to floating point.
.. code-block:: cpp
#include "Detector.h"
#include <chrono>
...
std::chrono::microseconds t0{500};
det.setExptime(t0);

View File

@ -6,12 +6,18 @@
Welcome to slsDetectorPackage's documentation!
==============================================
.. note ::
This is the documentation for the latest development version of slsDetectorPackage
For documentation on current and previous releases visit the official page: https://www.psi.ch/en/detectors/documentation
.. toctree::
:maxdepth: 1
:caption: Installation:
installation
dependencies
consuming
.. toctree::
:caption: C++ API
@ -20,6 +26,7 @@ Welcome to slsDetectorPackage's documentation!
detector
result
receiver
examples
.. toctree::
:caption: Python API

View File

@ -2,4 +2,24 @@
Installation
==============================================
get the source etc.
Build from source using CMake
---------------------------------
.. note ::
The default branch of our git repository is developer. It contains the
latest development version. It is expected to compile and work but
features might be added or tweaked. In some cases the API might also change
without being communicated. If absolute stability of the API is needed please
use one of the release versions.
.. code-block:: bash
git clone https://github.com/slsdetectorgroup/slsDetectorPackage.git
mkdir build && cd build
cmake ../slsDetectorPackage -DCMAKE_INSTALL_PREFIX=/your/install/path
make -j12
make install

View File

@ -1,9 +1,9 @@
Detector
=====================================================
.. py:currentmodule:: sls_detector
.. py:currentmodule:: slsdet
.. autoclass:: ExperimentalDetector
.. autoclass:: Detector
:members:
:undoc-members:
:show-inheritance:

View File

@ -4,7 +4,7 @@
#include "ClientSocket.h"
#include "logger.h"
#include "DetectorImpl.h"
#include "slsDetector.h"
#include "Module.h"
#include "sls_detector_defs.h"
#include "Timer.h"
@ -23,10 +23,10 @@
// extern dt type;
TEST_CASE("Single detector no receiver", "[.integration][.single]") {
auto t = slsDetector::getTypeFromDetector(test::hostname);
auto t = Module::getTypeFromDetector(test::hostname);
CHECK(t == test::type);
slsDetector d(t);
Module d(t);
CHECK(d.getDetectorTypeAsEnum() == t);
CHECK(d.getDetectorTypeAsString() == test::detector_type);
@ -51,7 +51,7 @@ TEST_CASE("Set control port then create a new object with this control port",
int new_cport = 1993;
int new_sport = 2000;
{
slsDetector d(test::type);
Module d(test::type);
d.setHostname(test::hostname);
CHECK(d.getControlPort() == old_cport);
d.setControlPort(new_cport);
@ -60,7 +60,7 @@ TEST_CASE("Set control port then create a new object with this control port",
d.freeSharedMemory();
}
{
slsDetector d(test::type);
Module d(test::type);
d.setHostname(test::hostname);
d.setControlPort(new_cport);
d.setStopPort(new_sport);
@ -73,7 +73,7 @@ TEST_CASE("Set control port then create a new object with this control port",
d.freeSharedMemory();
}
slsDetector d(test::type);
Module d(test::type);
d.setHostname(test::hostname);
CHECK(d.getStopPort() == DEFAULT_PORTNO + 1);
d.freeSharedMemory();
@ -86,11 +86,11 @@ TEST_CASE("single EIGER detector no receiver basic set and get",
SingleDetectorConfig c;
// Read type by connecting to the detector
auto type = slsDetector::getTypeFromDetector(c.hostname);
auto type = Module::getTypeFromDetector(c.hostname);
CHECK(type == c.type_enum);
// Create slsDetector of said type and set hostname and detector online
slsDetector d(type);
// Create Module of said type and set hostname and detector online
Module d(type);
CHECK(d.getDetectorTypeAsEnum() == type);
CHECK(d.getDetectorTypeAsString() == c.type_string);
@ -133,7 +133,7 @@ TEST_CASE("single EIGER detector no receiver basic set and get",
TEST_CASE("Locking mechanism and last ip", "[.integration][.single]") {
slsDetector d(test::type);
Module d(test::type);
d.setHostname(test::hostname);
// Check that detector server is unlocked then lock
@ -155,7 +155,7 @@ TEST_CASE("Locking mechanism and last ip", "[.integration][.single]") {
}
TEST_CASE("Set settings", "[.integration][.single]"){
slsDetector d(test::type);
Module d(test::type);
d.setHostname(test::hostname);
CHECK(d.setSettings(defs::STANDARD) == defs::STANDARD);
}
@ -185,7 +185,7 @@ TEST_CASE("Timer functions", "[.integration][cli]") {
// MEASURED_SUBPERIOD, /**< measured subperiod */
// MAX_TIMERS
slsDetector d(test::type);
Module d(test::type);
d.setHostname(test::hostname);
// Number of frames
@ -226,8 +226,8 @@ TEST_CASE("Timer functions", "[.integration][cli]") {
// TEST_CASE("Aquire", "[.integration][eiger]"){
// SingleDetectorConfig c;
// auto type = slsDetector::getTypeFromDetector(c.hostname);
// slsDetector d(type);
// auto type = Module::getTypeFromDetector(c.hostname);
// Module d(type);
// d.setHostname(c.hostname);
// auto period = 1000000000;

View File

@ -45,7 +45,7 @@ ext_modules = [
# get_pybind_include(),
# get_pybind_include(user=True),
os.path.join('../libs/pybind11/include'),
os.path.join(get_conda_path(), 'include/slsDetectorPackage'),
os.path.join(get_conda_path(), 'include'),
],
libraries=['SlsDetector', 'SlsReceiver', 'zmq'],

View File

@ -1,36 +1,35 @@
add_executable(a api.cpp)
target_link_libraries(a
slsDetectorShared
add_executable(using_logger using_logger.cpp)
target_link_libraries(using_logger
slsSupportLib
pthread
rt
)
set_target_properties(a PROPERTIES
set_target_properties(using_logger PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
add_executable(result useResult.cpp)
target_link_libraries(result
slsDetectorShared
)
# add_executable(result useResult.cpp)
# target_link_libraries(result
# slsDetectorShared
# )
set_target_properties(result PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
# set_target_properties(result PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
# )
add_executable(udp udp.cpp)
target_link_libraries(udp
slsDetectorShared
slsSupportLib
pthread
rt
fmt
)
# add_executable(udp udp.cpp)
# target_link_libraries(udp
# slsDetectorShared
# slsSupportLib
# pthread
# rt
# fmt
# )
set_target_properties(udp PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
# set_target_properties(udp PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
# )

42
sample/using_logger.cpp Normal file
View File

@ -0,0 +1,42 @@
#include "logger.h"
#include <iostream>
#include <chrono>
int main() {
//compare old and new
std::cout << "Compare output between old and new:\n";
LOG(logINFO) << "Some info message";
LOG(logERROR) << "This is an error";
LOG(logWARNING) << "While this is only a warning";
//Logging level can be configure at runtime
std::cout << "\n\n";
std::cout << "The default macro controlled level is: "
<< sls::Logger::ToString(LOG_MAX_REPORTING_LEVEL) << '\n';
sls::Logger::ReportingLevel() = logERROR;
LOG(logINFO) << "Now this is not written";
LOG(logWARNING) << "and also not this";
sls::Logger::ReportingLevel() = logINFO;
LOG(logINFO) << "But now we can see it";
//The output can be redirected to another buffer
std::ostringstream local;
auto clog_buff = std::clog.rdbuf();
std::clog.rdbuf(local.rdbuf());
LOG(logINFOBLUE) << "A message";
LOG(logWARNING) << "And another one";
std::clog.rdbuf(clog_buff); // restore
std::cout << "local buf:\n" << local.str();
LOG(logINFO) << "After reset we should print directly";
LOG(logINFOBLUE) << "some infoBLUE text";
LOG(logINFOGREEN) << "some infoGREEN text";
LOG(logINFORED) << "some infoRED text";
}

View File

@ -4,10 +4,10 @@ find_package(PNG REQUIRED)
find_package(ZLIB REQUIRED)
set(SOURCES
slsDetectorPlotting/src/SlsQt1DPlot.cxx
slsDetectorPlotting/src/SlsQt1DZoomer.cxx
slsDetectorPlotting/src/SlsQt2DHist.cxx
slsDetectorPlotting/src/SlsQt2DPlot.cxx
slsDetectorPlotting/src/SlsQt1DPlot.cpp
slsDetectorPlotting/src/SlsQt1DZoomer.cpp
slsDetectorPlotting/src/SlsQt2DHist.cpp
slsDetectorPlotting/src/SlsQt2DPlot.cpp
src/qDetectorMain.cpp
src/qDrawPlot.cpp
src/qCloneWidget.cpp
@ -103,10 +103,10 @@ set_target_properties(slsDetectorGui PROPERTIES
)
install(TARGETS slsDetectorGui
EXPORT "${TARGETS_EXPORT_NAME}"
# EXPORT "${TARGETS_EXPORT_NAME}"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
# PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

17
slsDetectorGui/include/qCloneWidget.h Executable file → Normal file
View File

@ -1,25 +1,20 @@
#pragma once
#include "ui_form_cloneplot.h"
#include <QMainWindow>
#include <QString>
class SlsQtH1D;
class SlsQt1DPlot;
class SlsQt2DPlot;
#include <QMainWindow>
#include <QString>
#include <iostream>
#include <string>
class qCloneWidget : public QMainWindow, private Ui::ClonePlotObject {
Q_OBJECT
public:
qCloneWidget(QWidget *parent, SlsQt1DPlot *p1, SlsQt2DPlot *p2, SlsQt1DPlot *gp1, SlsQt2DPlot *gp,
QString title, QString filePath, QString fileName,
int64_t aIndex, bool displayStats, QString min, QString max,
QString sum);
qCloneWidget(QWidget *parent, SlsQt1DPlot *p1, SlsQt2DPlot *p2,
SlsQt1DPlot *gp1, SlsQt2DPlot *gp, QString title,
QString filePath, QString fileName, int64_t aIndex,
bool displayStats, QString min, QString max, QString sum);
~qCloneWidget();

7
slsDetectorGui/include/qDacWidget.h Executable file → Normal file
View File

@ -1,17 +1,15 @@
#pragma once
#include "ui_form_dac.h"
#include "Detector.h"
#include "sls_detector_defs.h"
#include <string>
class qDacWidget : public QWidget, private Ui::WidgetDacObject {
Q_OBJECT
public:
qDacWidget(QWidget *parent, sls::Detector* detector, bool d, std::string n, slsDetectorDefs::dacIndex i);
qDacWidget(QWidget *parent, sls::Detector *detector, bool d, std::string n,
slsDetectorDefs::dacIndex i);
~qDacWidget();
void SetDetectorIndex(int id);
@ -30,4 +28,3 @@ private:
slsDetectorDefs::dacIndex index;
int detectorIndex{-1};
};

70
slsDetectorGui/include/qDefs.h Executable file → Normal file
View File

@ -5,22 +5,29 @@
#include <QAbstractButton>
#include <QMessageBox>
#include <chrono>
#include <iostream>
#include <ostream>
#include <stdint.h>
#include <cstdint>
#include <string>
#include <chrono>
using std::chrono::duration;
using std::chrono::duration_cast;
using std::chrono::nanoseconds;
using std::chrono::hours;
using std::chrono::microseconds;
using std::chrono::milliseconds;
using std::chrono::seconds;
using std::chrono::minutes;
using std::chrono::hours;
using std::chrono::nanoseconds;
using std::chrono::seconds;
#define CATCH_DISPLAY(m, s) catch(...) { qDefs::DisplayExceptions(m, s); }
#define CATCH_HANDLE(...) catch(...) { qDefs::HandleExceptions(__VA_ARGS__); }
#define CATCH_DISPLAY(m, s) \
catch (...) { \
qDefs::DisplayExceptions(m, s); \
}
#define CATCH_HANDLE(...) \
catch (...) { \
qDefs::HandleExceptions(__VA_ARGS__); \
}
class qDefs : public QWidget {
public:
@ -47,8 +54,8 @@ class qDefs : public QWidget {
template <class CT> struct NonDeduced { using type = CT; };
template <class S, typename RT, typename... CT>
static void HandleExceptions(const std::string emsg, const std::string src, S* s,
RT (S::*somefunc)(CT...),
static void HandleExceptions(const std::string emsg, const std::string src,
S *s, RT (S::*somefunc)(CT...),
typename NonDeduced<CT>::type... Args) {
try {
throw;
@ -74,13 +81,20 @@ class qDefs : public QWidget {
static const char *getQFunctionNameFromEnum(enum qFuncNames func) {
switch (func) {
case QF_GET_DETECTOR_STATUS: return "QF_GET_DETECTOR_STATUS";
case QF_START_ACQUISITION: return "QF_START_ACQUISITION";
case QF_STOP_ACQUISITION: return "QF_STOP_ACQUISITION";
case QF_START_AND_READ_ALL: return "QF_START_AND_READ_ALL";
case QF_EXIT_SERVER: return "QF_EXIT_SERVER";
case QF_NUM_FUNCTIONS: return "QF_NUM_FUNCTIONS";
default: return "Unknown Function";
case QF_GET_DETECTOR_STATUS:
return "QF_GET_DETECTOR_STATUS";
case QF_START_ACQUISITION:
return "QF_START_ACQUISITION";
case QF_STOP_ACQUISITION:
return "QF_STOP_ACQUISITION";
case QF_START_AND_READ_ALL:
return "QF_START_AND_READ_ALL";
case QF_EXIT_SERVER:
return "QF_EXIT_SERVER";
case QF_NUM_FUNCTIONS:
return "QF_NUM_FUNCTIONS";
default:
return "Unknown Function";
}
};
@ -111,11 +125,16 @@ class qDefs : public QWidget {
static std::string getRangeAsString(enum range r) {
switch (r) {
case XMIN: return "XMIN";
case XMAX: return "XMAX";
case YMIN: return "YMIN";
case YMAX: return "YMAX";
default: return "Unknown";
case XMIN:
return "XMIN";
case XMAX:
return "XMAX";
case YMIN:
return "YMIN";
case YMAX:
return "YMAX";
default:
return "Unknown";
}
};
@ -190,7 +209,8 @@ class qDefs : public QWidget {
MINUTES);
}
return std::make_pair(
duration_cast<duration<double, std::ratio<3600>>>(tns).count(), HOURS);
duration_cast<duration<double, std::ratio<3600>>>(tns).count(),
HOURS);
}
/** returns the value in ns */
@ -299,7 +319,9 @@ class qDefs : public QWidget {
static int ExceptionMessage(std::string message,
std::string exceptionMessage,
std::string source) {
return Message(qDefs::WARNING, message + std::string("\nCaught exception:\n") + exceptionMessage, source);
return Message(qDefs::WARNING,
message + std::string("\nCaught exception:\n") +
exceptionMessage,
source);
}
};

42
slsDetectorGui/include/qDetectorMain.h Executable file → Normal file
View File

@ -1,8 +1,9 @@
#pragma once
#include "ui_form_detectormain.h"
#include "qDefs.h"
#include "Detector.h"
#include <QTabWidget>
class qDrawPlot;
class qTabMeasurement;
class qTabDataOutput;
@ -12,17 +13,15 @@ class qTabSettings;
class qTabDebugging;
class qTabDeveloper;
class qTabMessages;
#include "Detector.h"
#include <QTabWidget>
class QScrollArea;
class QResizeEvent;
/** To Over-ride the QTabWidget class to get the tabBar */
/** To Over-ride the QTabWidget class to get the tabBar protected
* methodTabWidget */
class MyTabWidget : public QTabWidget {
public:
MyTabWidget(QWidget *parent = 0) { setParent(parent); }
/** Overridden method from QTabWidget */
/** Overridden protected method from QTabWidget */
QTabBar *tabBar() { return QTabWidget::tabBar(); }
};
@ -30,7 +29,7 @@ class qDetectorMain : public QMainWindow, private Ui::DetectorMainObject {
Q_OBJECT
public:
qDetectorMain(int multiId, std::string fname, bool isDevel);
qDetectorMain(int multiId, const std::string& fname, bool isDevel);
~qDetectorMain();
private slots:
@ -52,9 +51,9 @@ class qDetectorMain : public QMainWindow, private Ui::DetectorMainObject {
private:
void SetUpWidgetWindow();
void SetUpDetector(const std::string fName, int multiID);
void SetUpDetector(const std::string& config_file, int multiID);
void Initialization();
void LoadConfigFile(const std::string fName);
void LoadConfigFile(const std::string& config_file);
/** enumeration of the tabs */
enum {
@ -70,16 +69,17 @@ class qDetectorMain : public QMainWindow, private Ui::DetectorMainObject {
};
slsDetectorDefs::detectorType detType;
std::unique_ptr<sls::Detector> det;
std::unique_ptr<qDrawPlot> plot;
std::unique_ptr<MyTabWidget> tabs;
std::unique_ptr<qTabMeasurement> tabMeasurement;
std::unique_ptr<qTabDataOutput> tabDataOutput;
std::unique_ptr<qTabPlot> tabPlot;
std::unique_ptr<qTabSettings> tabSettings;
std::unique_ptr<qTabAdvanced> tabAdvanced;
std::unique_ptr<qTabDebugging> tabDebugging;
std::unique_ptr<qTabDeveloper> tabDeveloper;
std::unique_ptr<qTabMessages> tabMessages;
qDrawPlot *plot;
MyTabWidget* tabs;
std::unique_ptr<QScrollArea> scroll[NumberOfTabs];
qTabMeasurement *tabMeasurement;
qTabDataOutput *tabDataOutput;
qTabPlot *tabPlot;
qTabSettings *tabSettings;
qTabAdvanced *tabAdvanced;
qTabDebugging *tabDebugging;
qTabDeveloper *tabDeveloper;
qTabMessages *tabMessages;
int isDeveloper;
int heightPlotWindow;
int heightCentralWidget;

23
slsDetectorGui/include/qDrawPlot.h Executable file → Normal file
View File

@ -1,20 +1,16 @@
#pragma once
#include "ui_form_plot.h"
#include "qDefs.h"
#include "Detector.h"
#include <mutex>
class SlsQt1DPlot;
class SlsQtH1D;
class SlsQt2DPlot;
class qCloneWidget;
class detectorData;
#include "Detector.h"
class QResizeEvent;
#include <mutex>
class qDrawPlot : public QWidget, private Ui::PlotObject {
Q_OBJECT
@ -78,11 +74,16 @@ class qDrawPlot : public QWidget, private Ui::PlotObject {
void SetupPlots();
void GetStatistics(double &min, double &max, double &sum);
void DetachHists();
static void GetAcquisitionFinishedCallBack(double currentProgress, int detectorStatus, void *this_pointer);
static void GetDataCallBack(detectorData *data, uint64_t frameIndex, uint32_t subFrameIndex, void *this_pointer);
static void GetAcquisitionFinishedCallBack(double currentProgress,
int detectorStatus,
void *this_pointer);
static void GetDataCallBack(detectorData *data, uint64_t frameIndex,
uint32_t subFrameIndex, void *this_pointer);
void AcquisitionFinished(double currentProgress, int detectorStatus);
void GetData(detectorData *data, uint64_t frameIndex, uint32_t subFrameIndex);
void toDoublePixelData(double *dest, char *source, int size, int databytes, int dr, double *gaindest = NULL);
void GetData(detectorData *data, uint64_t frameIndex,
uint32_t subFrameIndex);
void toDoublePixelData(double *dest, char *source, int size, int databytes,
int dr, double *gaindest = NULL);
void Get1dData(double *rawData);
void Get2dData(double *rawData);
void Update1dPlot();

6
slsDetectorGui/include/qTabAdvanced.h Executable file → Normal file
View File

@ -1,11 +1,9 @@
#pragma once
#include "ui_form_tab_advanced.h"
#include "Detector.h"
class qDrawPlot;
#include "Detector.h"
class qTabAdvanced : public QWidget, private Ui::TabAdvancedObject {
Q_OBJECT
@ -65,5 +63,3 @@ private:
sls::Detector *det;
qDrawPlot *plot;
};

8
slsDetectorGui/include/qTabDataOutput.h Executable file → Normal file
View File

@ -1,7 +1,5 @@
#pragma once
#include "ui_form_tab_dataoutput.h"
#include "Detector.h"
class qTabDataOutput : public QWidget, private Ui::TabDataOutputObject {
@ -42,9 +40,5 @@ public:
// Button group for radiobuttons for rate
QButtonGroup *btnGroupRate;
// enum for the Eiger Parallel flag
enum {
PARALLEL,
NONPARALLEL
enum { PARALLEL, NONPARALLEL };
};
};

3
slsDetectorGui/include/qTabDebugging.h Executable file → Normal file
View File

@ -1,7 +1,5 @@
#pragma once
#include "ui_form_tab_debugging.h"
#include "Detector.h"
class QTreeWidget;
@ -33,4 +31,3 @@ private:
QLabel *lblDetectorFirmware;
QLabel *lblDetectorSoftware;
};

21
slsDetectorGui/include/qTabDeveloper.h Executable file → Normal file
View File

@ -1,14 +1,11 @@
#pragma once
#include "ui_form_tab_developer.h"
class qDacWidget;
#include "Detector.h"
#include "sls_detector_defs.h"
#include <string>
#include <vector>
class qDacWidget;
class qTabDeveloper : public QWidget, private Ui::TabDeveloperObject {
Q_OBJECT
@ -27,23 +24,15 @@ private:
void Initialization();
void PopulateDetectors();
void GetHighVoltage();
slsDetectorDefs::dacIndex getSLSIndex(slsDetectorDefs::detectorType detType, int index);
slsDetectorDefs::dacIndex getSLSIndex(slsDetectorDefs::detectorType detType,
int index);
sls::Detector *det;
std::vector<qDacWidget *> dacWidgets;
std::vector<qDacWidget *> adcWidgets;
enum hvVals {
HV_0,
HV_90,
HV_110,
HV_120,
HV_150,
HV_180,
HV_200
};
enum hvVals { HV_0, HV_90, HV_110, HV_120, HV_150, HV_180, HV_200 };
int hvmin;
static const int HV_MIN = 60;
static const int HV_MAX = 200;
};

14
slsDetectorGui/include/qTabMeasurement.h Executable file → Normal file
View File

@ -1,11 +1,8 @@
#pragma once
#include "ui_form_tab_measurement.h"
class qDrawPlot;
#include "Detector.h"
class qDrawPlot;
class QStandardItemModel;
class qTabMeasurement : public QWidget, private Ui::TabMeasurementObject {
@ -74,17 +71,12 @@ private:
signals:
void EnableTabsSignal(bool);
void FileNameChangedSignal(QString);
private:
sls::Detector *det;
qDrawPlot *plot;
// enum for the timing mode
enum{
AUTO,
TRIGGER,
GATED,
BURST_TRIGGER,
NUMTIMINGMODES
};
enum { AUTO, TRIGGER, GATED, BURST_TRIGGER, NUMTIMINGMODES };
QTimer *progressTimer;
// tool tip variables
QString acqPeriodTip;

2
slsDetectorGui/include/qTabMessages.h Executable file → Normal file
View File

@ -1,5 +1,4 @@
#pragma once
#include "ui_form_tab_messages.h"
class QProcess;
@ -33,4 +32,3 @@ private:
QProcess *process;
QStringList lastCommand;
};

7
slsDetectorGui/include/qTabPlot.h Executable file → Normal file
View File

@ -1,11 +1,8 @@
#pragma once
#include "ui_form_tab_plot.h"
class qDrawPlot;
#include "Detector.h"
class qDrawPlot;
class QButtonGroup;
class qTabPlot : public QWidget, private Ui::TabPlotObject {
@ -59,5 +56,3 @@ private:
static QString defaultImageYAxisTitle;
static QString defaultImageZAxisTitle;
};

9
slsDetectorGui/include/qTabSettings.h Executable file → Normal file
View File

@ -1,7 +1,5 @@
#pragma once
#include "ui_form_tab_settings.h"
#include "Detector.h"
class qTabSettings : public QWidget, private Ui::TabSettingsObject {
@ -53,10 +51,5 @@ private:
UNINITIALIZED,
NUMSETTINGS
};
enum {
DYNAMICRANGE_32,
DYNAMICRANGE_16,
DYNAMICRANGE_8,
DYNAMICRANGE_4
};
enum { DYNAMICRANGE_32, DYNAMICRANGE_16, DYNAMICRANGE_8, DYNAMICRANGE_4 };
};

View File

@ -1,33 +1,12 @@
/**
* @author Ian Johnson
* @version 1.0
* Modifications:
* 19.06.2012: {Some functions have been added by Dhanya to enable zooming in and out
* without using mouse control:
* DisableZoom,
* SetXMinMax,SetYMinMax,
* GetXMinimum,GetXMaximum,GetYMinimum,GetYMaximum}
* */
#ifndef SLSQT1DPLOT_H
#define SLSQT1DPLOT_H
typedef double double32_t;
typedef float float32_t;
typedef int int32_t;
#include "ansi.h"
#include "SlsQt1DZoomer.h"
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_marker.h>
#include <qwt_scale_div.h>
#include "SlsQt1DZoomer.h"
#include <iostream>
class QPen;
class SlsQt1DPlot;
@ -71,8 +50,6 @@ class SlsQtH1D:public QwtPlotCurve{
SlsQtH1D *Add(double v);
private:
int ndata;
int n_array;
@ -87,7 +64,6 @@ class SlsQtH1D:public QwtPlotCurve{
QPen *pen_ptr{nullptr};
};
class SlsQtH1DList {
public:
SlsQtH1DList(SlsQtH1D *hist = 0);
@ -100,13 +76,11 @@ class SlsQtH1DList{
SlsQtH1D *Hist() { return the_hist; } // if no hist returns 0
SlsQtH1DList *Next() { return the_next; }
private:
SlsQtH1DList *the_next;
SlsQtH1D *the_hist;
};
class SlsQt1DPlot : public QwtPlot {
Q_OBJECT
@ -126,31 +100,41 @@ class SlsQt1DPlot:public QwtPlot{
void InsertVLine(double v);
void RemoveVLine();
/** This group of functions have been added by Dhanya on 19.06.2012 to be able to
use zooming functionality without mouse control*/
/** This group of functions have been added by Dhanya on 19.06.2012 to be
able to use zooming functionality without mouse control*/
void DisableZoom(bool disable);
void EnableXAutoScaling() {setAxisAutoScale(QwtPlot::xBottom, true);Update();};
void EnableYAutoScaling() {setAxisAutoScale(QwtPlot::yLeft, true);Update();};
void EnableXAutoScaling() {
setAxisAutoScale(QwtPlot::xBottom, true);
Update();
};
void EnableYAutoScaling() {
setAxisAutoScale(QwtPlot::yLeft, true);
Update();
};
void SetYStep(int step) { ystep = step; };
void SetXMinMax(double min,double max){setAxisScale(QwtPlot::xBottom,min,max);};
void SetYMinMax(double min,double max){setAxisScale(QwtPlot::yLeft,min,max);};
void SetXMinMax(double min, double max) {
setAxisScale(QwtPlot::xBottom, min, max);
};
void SetYMinMax(double min, double max) {
setAxisScale(QwtPlot::yLeft, min, max);
};
double GetXMinimum() { return hist_list->Hist()->GetXMin(); };
double GetXMaximum() { return hist_list->Hist()->GetXMax(); };
double GetYMinimum() { return hist_list->Hist()->GetYMin(); };
double GetYMaximum() { return hist_list->Hist()->GetYMax(); };
/**---*/
void SetZoom(double xmin, double ymin, double x_width, double y_width);
void SetZoomBase(double xmin,double ymin,double x_width, double y_width){ zoomer->SetZoomBase(xmin,ymin,x_width,y_width);}
void SetZoomBase(double xmin, double ymin, double x_width, double y_width) {
zoomer->SetZoomBase(xmin, ymin, x_width, y_width);
}
void alignScales();
void SetLogX(bool yes = 1);
void SetLogY(bool yes = 1);
private:
private:
SlsQtH1DList *hist_list{nullptr};
SlsQt1DZoomer *zoomer{nullptr};
QwtPlotPanner *panner{nullptr};
@ -173,11 +157,9 @@ class SlsQt1DPlot:public QwtPlot{
friend void SlsQtH1D::Attach(SlsQt1DPlot *p);
friend void SlsQtH1D::Detach(SlsQt1DPlot *p);
public slots:
void UnZoom();
void Update();
};
#endif

View File

@ -1,15 +1,10 @@
/**
* @author Ian Johnson
* @version 1.0
*/
#ifndef SLSQT1DZOOMER_H
#define SLSQT1DZOOMER_H
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include <qwt_global.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_zoomer.h>
class SlsQtH1D;
@ -20,11 +15,7 @@ class SlsQt1DZoomer:public QwtPlotZoomer{
bool xIsLog, yIsLog;
public:
#if QWT_VERSION < 0x060100
SlsQt1DZoomer(QwtPlotCanvas *canvas):QwtPlotZoomer(canvas){
#else
SlsQt1DZoomer(QWidget *canvas) : QwtPlotZoomer(canvas) {
#endif
setTrackerMode(AlwaysOn);
xIsLog = yIsLog = 0;
}
@ -47,28 +38,15 @@ class SlsQt1DZoomer:public QwtPlotZoomer{
bool SetLogX(bool yes) { return xIsLog = yes; }
bool SetLogY(bool yes) { return yIsLog = yes; }
#if QWT_VERSION<0x060000
virtual QwtText trackerText(const QwtDoublePoint &pos) const{
#else
using QwtPlotPicker::trackerText;
virtual QwtText trackerText(const QPoint &pos) const {
#endif
QColor bg(Qt::white);
#if QT_VERSION >= 0x040300
bg.setAlpha(200);
#endif
#if QWT_VERSION<0x060000
QwtText text = QwtPlotZoomer::trackerText(pos);
#else
QwtText text = QwtPlotPicker::trackerText(pos);
#endif
text.setBackgroundBrush(QBrush(bg));
return text;
}
};
#endif

View File

@ -1,27 +1,15 @@
/**
* @author Ian Johnson
* @version 1.0
*/
#ifndef SLSQT2DHIST_H
#define SLSQT2DHIST_H
#if QT_VERSION >= 0x040000
#include <qprintdialog.h>
#endif
#include <qwt_color_map.h>
#include <qwt_plot_spectrogram.h>
#include <qwt_scale_widget.h>
#include <qwt_scale_draw.h>
#include <qwt_scale_widget.h>
class SlsQt2DHist : public QwtRasterData {
private:
double x_min, x_max, y_min, y_max;
double x_width, y_width;
@ -34,12 +22,15 @@ class SlsQt2DHist: public QwtRasterData{
bool interp;
static double value_between_points(double p1,double v1,double p2,double v2,double p){ //linear extrap
static double value_between_points(double p1, double v1, double p2,
double v2, double p) { // linear extrap
return (v2 - v1) / (p2 - p1) * (p - p1) + v1;
}
public:
SlsQt2DHist(int nbinsx=10, double xmin=0, double xmax=10, int nbinsy=10, double ymin=0, double ymax=10, double* d=0,double zmin=0,double zmax=-1);
SlsQt2DHist(int nbinsx = 10, double xmin = 0, double xmax = 10,
int nbinsy = 10, double ymin = 0, double ymax = 10,
double *d = 0, double zmin = 0, double zmax = -1);
virtual ~SlsQt2DHist();
double GetXMin() { return x_min; }
@ -60,7 +51,8 @@ class SlsQt2DHist: public QwtRasterData{
void Interpolate(bool on = 1) { interp = on; }
void SetBinValue(int bx, int by, double v);
void SetData(int nbinsx, double xmin, double xmax, int nbinsy,double ymin, double ymax,double *d,double zmin=0, double zmax=-1);
void SetData(int nbinsx, double xmin, double xmax, int nbinsy, double ymin,
double ymax, double *d, double zmin = 0, double zmax = -1);
double SetMinimumToFirstGreaterThanZero();
void SetMinimum(double zmin) { z_min = zmin; }
@ -69,17 +61,13 @@ class SlsQt2DHist: public QwtRasterData{
int FindBinIndex(double x, double y);
virtual QwtRasterData *copy() const {
// this function does not create a new SlsQt2DHistData instance,
//just passes a pointer so that data is common to both the copy and the original instance
// just passes a pointer so that data is common to both the copy and the
// original instance
return (QwtRasterData *)this;
}
#if QWT_VERSION<0x060000
virtual QwtDoubleInterval range() const{ return QwtDoubleInterval(z_min,z_max);}
#else
virtual QwtInterval range() const { return QwtInterval(z_min, z_max); }
virtual QwtInterval interval(Qt::Axis axis) const {
switch (axis) {
@ -93,22 +81,27 @@ class SlsQt2DHist: public QwtRasterData{
return QwtInterval(z_min, z_max);
};
};
#endif
virtual double value(double x, double y) const {
// if(!interp){ //default is box like plot
int index = int((x-x_min)/x_width) + int((y-y_min)/y_width)*nx;
if(index<0||index>nb) index = nb;
if(!interp) return data[index];
int index =
int((x - x_min) / x_width) + int((y - y_min) / y_width) * nx;
if (index < 0 || index > nb)
index = nb;
if (!interp)
return data[index];
//}
int x_int = int((x - x_min) / x_width - 0.5);
if(x_int<0) x_int = 0; else if(x_int>nx-2) x_int = nx-2;
if (x_int < 0)
x_int = 0;
else if (x_int > nx - 2)
x_int = nx - 2;
int y_int = int((y - y_min) / y_width - 0.5);
if(y_int<0) y_int = 0; else if(y_int>ny-2) y_int = ny-2;
if (y_int < 0)
y_int = 0;
else if (y_int > ny - 2)
y_int = ny - 2;
int b00 = x_int * ny + y_int;
int b01 = x_int * ny + y_int + 1;
@ -122,16 +115,12 @@ class SlsQt2DHist: public QwtRasterData{
double right_v = value_between_points(y0, data[b10], y1, data[b11], y);
// horazontal extrap
return 0.5;
return value_between_points(x_min + (x_int + 0.5) * x_width, left_v,
x_min+(x_int+1.5)*x_width,right_v,x);
x_min + (x_int + 1.5) * x_width, right_v,
x);
}
};
#endif

View File

@ -1,20 +1,14 @@
#pragma once
#include <qwt_plot.h>
#include <qlist.h>
#include <qwt_plot_spectrogram.h>
#include "SlsQt2DZoomer.h"
#include "SlsQt2DHist.h"
#include "SlsQt2DZoomer.h"
#include <qlist.h>
#include <qwt_plot.h>
#include <qwt_plot_spectrogram.h>
class QwtPlotPanner;
class QwtScaleWidget;
class QwtLinearColorMap;
class SlsQt2DPlot : public QwtPlot {
Q_OBJECT
@ -35,8 +29,12 @@ public:
void DisableZoom(bool disable);
void EnableXAutoScaling() { setAxisAutoScale(QwtPlot::xBottom, true); };
void EnableYAutoScaling() { setAxisAutoScale(QwtPlot::yLeft, true); };
void SetXMinMax(double min,double max){setAxisScale(QwtPlot::xBottom,min,max);};
void SetYMinMax(double min,double max){setAxisScale(QwtPlot::yLeft,min,max);};
void SetXMinMax(double min, double max) {
setAxisScale(QwtPlot::xBottom, min, max);
};
void SetYMinMax(double min, double max) {
setAxisScale(QwtPlot::yLeft, min, max);
};
double GetXMinimum() { return hist->GetXMin(); };
double GetXMaximum() { return hist->GetXMax(); };
double GetYMinimum() { return hist->GetYMin(); };
@ -44,10 +42,13 @@ public:
double GetZMinimum() { return hist->GetMinimum(); }
double GetZMaximum() { return hist->GetMaximum(); }
void SetZMinMax(double zmin = 0, double zmax = -1);
void SetZMinimumToFirstGreaterThanZero(){hist->SetMinimumToFirstGreaterThanZero();}
void SetZMinimumToFirstGreaterThanZero() {
hist->SetMinimumToFirstGreaterThanZero();
}
double GetZMean() { return hist->GetMean(); }
void SetData(int nbinsx, double xmin, double xmax, int nbinsy,double ymin, double ymax,double *d,double zmin=0, double zmax=-1){
void SetData(int nbinsx, double xmin, double xmax, int nbinsy, double ymin,
double ymax, double *d, double zmin = 0, double zmax = -1) {
hist->SetData(nbinsx, xmin, xmax, nbinsy, ymin, ymax, d, zmin, zmax);
}
@ -65,12 +66,9 @@ public:
void SetZRange(bool isMin, bool isMax, double min, double max);
void LogZ(bool on = 1);
public slots:
void showSpectrogram(bool on);
private:
void SetupZoom();
void SetupColorMap();
@ -82,17 +80,8 @@ private:
SlsQt2DZoomer *zoomer{nullptr};
QwtPlotPanner *panner{nullptr};
QwtScaleWidget *rightAxis{nullptr};
QwtLinearColorMap* colorMapLinearScale{nullptr};
QwtLinearColorMap* colorMapLogScale{nullptr};
#if QWT_VERSION<0x060000
QwtValueList* contourLevelsLinear{nullptr};
QwtValueList* contourLevelsLog{nullptr};
#else
QList<double> contourLevelsLinear;
QList<double> contourLevelsLog;
#endif
bool disableZoom{false};
int isLog;
};

View File

@ -1,69 +1,37 @@
/**
* @author Ian Johnson
* @version 1.0
* Dhanya-05.12.2012- included an additional header
*/
#ifndef SLSQT2DZOOMER_H
#define SLSQT2DZOOMER_H
/**included by Dhanya on 05.12.2012 to avoid compile time errors with the latest gcc*/
#include <cstdio>
/**end of Change by Dhanya*/
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include "SlsQt2DHist.h"
#include <qwt_plot_panner.h>
#include <qwt_plot_zoomer.h>
#include <cstdio>
class SlsQt2DZoomer : public QwtPlotZoomer {
private:
SlsQt2DHist *hist;
public:
#if QWT_VERSION < 0x060100
SlsQt2DZoomer(QwtPlotCanvas *canvas):QwtPlotZoomer(canvas){
#else
SlsQt2DZoomer(QWidget *canvas) : QwtPlotZoomer(canvas) {
#endif
setTrackerMode(AlwaysOn);
}
void SetHist(SlsQt2DHist* h){
hist=h;
}
void SetHist(SlsQt2DHist *h) { hist = h; }
#if QWT_VERSION<0x060000
virtual QwtText trackerText(const QwtDoublePoint &pos) const{
#else
virtual QwtText trackerTextF(const QPointF &pos) const {
#endif
QColor bg(Qt::white);
#if QT_VERSION >= 0x040300
bg.setAlpha(200);
#endif
// QwtText text = QwtPlotZoomer::trackerText(pos);
static QwtText text;
if (hist) {
static char t[200];
sprintf(t,"%3.2f, %3.2f, %3.2f",pos.x(),pos.y(),hist->value(pos.x(),pos.y()));
sprintf(t, "%3.2f, %3.2f, %3.2f", pos.x(), pos.y(),
hist->value(pos.x(), pos.y()));
text.setText(t);
} else {
#if QWT_VERSION<0x060000
QwtText text = QwtPlotZoomer::trackerText(pos);
#else
QPoint p = pos.toPoint();
QwtText text = QwtPlotZoomer::trackerText(p);
#endif
}
text.setBackgroundBrush(QBrush(bg));
return text;

View File

@ -1,11 +1,7 @@
/**
* @author Ian Johnson
* @version 1.0
*/
/* TODO! short description */
#include "SlsQt1DPlot.h"
#include <iostream>
#include <qwt_symbol.h>
#include <qwt_legend.h>
#include <qwt_math.h>
#include <qwt_painter.h>
@ -14,19 +10,19 @@
#include <qwt_scale_draw.h>
#include <qwt_scale_engine.h>
#include <qwt_scale_widget.h>
#include "qwt_symbol.h"
#include <stdlib.h>
#include <iostream>
#if QWT_VERSION >= 0x060100
#define QwtLog10ScaleEngine QwtLogScaleEngine
#endif
#define QwtLog10ScaleEngine QwtLogScaleEngine // hmm
SlsQtH1D::SlsQtH1D(QString title, int n, double min, double max, double *data) : QwtPlotCurve(title), x(nullptr), y(nullptr), pen_ptr(nullptr) {
SlsQtH1D::SlsQtH1D(QString title, int n, double min, double max, double *data)
: QwtPlotCurve(title), x(nullptr), y(nullptr), pen_ptr(nullptr) {
Initailize();
SetData(n, min, max, data);
}
SlsQtH1D::SlsQtH1D(QString title, int n, double *data_x, double *data_y) : QwtPlotCurve(title) {
SlsQtH1D::SlsQtH1D(QString title, int n, double *data_x, double *data_y)
: QwtPlotCurve(title) {
Initailize();
SetData(n, data_x, data_y);
}
@ -39,11 +35,11 @@ void SlsQtH1D::Initailize() {
}
SlsQtH1D::~SlsQtH1D() {
if (x)
delete[] x;
if (y)
delete[] y;
if (pen_ptr)
delete pen_ptr;
}
@ -138,11 +134,7 @@ void SlsQtH1D::setSymbolMarkers(bool isMarker) {
marker->setStyle(QwtSymbol::Cross);
marker->setSize(5, 5);
}
#if QWT_VERSION < 0x060000
setSymbol(*marker);
#else
setSymbol(marker);
#endif
}
void SlsQtH1D::SetData(int n, double xmin, double xmax, double *data) {
@ -173,11 +165,7 @@ void SlsQtH1D::SetData(int n, double xmin, double xmax, double *data) {
firstYgt0 = y[i];
}
#if QWT_VERSION < 0x060000
setRawData(x, y, ndata);
#else
setRawSamples(x, y, ndata);
#endif
}
void SlsQtH1D::SetData(int n, double *data_x, double *data_y) {
@ -206,12 +194,7 @@ void SlsQtH1D::SetData(int n, double *data_x, double *data_y) {
if (y[b] > 0 && (firstYgt0 < 0 || firstYgt0 > y[b]))
firstYgt0 = y[b];
}
// #if QWT_VERSION<0x060000
// setRawData(x,y,ndata);
// #else
setRawSamples(x, y, ndata);
// #endif
}
int SlsQtH1D::SetUpArrays(int n) {
@ -219,9 +202,9 @@ int SlsQtH1D::SetUpArrays(int n) {
if (n + 1 > n_array) {
n_array = n + 1;
if (x)
delete x;
if (y)
delete y;
x = new double[n_array];
y = new double[n_array];
@ -234,7 +217,9 @@ double SlsQtH1D::FillBin(int bx, double v) {
bx = CheckIndex(bx);
return SetBinContent(bx, y[bx] + v);
}
double SlsQtH1D::Fill(double x, double v) { return FillBin(FindBinIndex(x), v); }
double SlsQtH1D::Fill(double x, double v) {
return FillBin(FindBinIndex(x), v);
}
double SlsQtH1D::SetBinContent(int bx, double v) {
bx = CheckIndex(bx);
@ -250,7 +235,9 @@ double SlsQtH1D::SetBinContent(int bx, double v) {
return y[bx];
}
double SlsQtH1D::SetContent(double x, double v) { return SetBinContent(FindBinIndex(x), v); }
double SlsQtH1D::SetContent(double x, double v) {
return SetBinContent(FindBinIndex(x), v);
}
int SlsQtH1D::FindBinIndex(double px) {
if (dx > 0)
@ -270,7 +257,9 @@ int SlsQtH1D::FindBinIndex(double px) {
return b;
}
int SlsQtH1D::CheckIndex(int bx) { return (bx < 0 || bx > ndata) ? ndata : bx; } //ndata is the overflow bin
int SlsQtH1D::CheckIndex(int bx) {
return (bx < 0 || bx > ndata) ? ndata : bx;
} // ndata is the overflow bin
SlsQtH1D *SlsQtH1D::Add(double v) {
for (int bx = 0; bx < ndata; bx++)
@ -281,13 +270,10 @@ SlsQtH1D *SlsQtH1D::Add(double v) {
// 1d hist list stuff
SlsQtH1DList::SlsQtH1DList(SlsQtH1D *hist) {
the_hist = hist;
the_next = 0;
the_next = nullptr;
}
SlsQtH1DList::~SlsQtH1DList() {
if (the_next)
delete the_next;
}
SlsQtH1DList::~SlsQtH1DList() { delete the_next; }
SlsQtH1D *SlsQtH1DList::Add(SlsQtH1D *hist) {
SlsQtH1DList *hl = this;
@ -313,7 +299,8 @@ void SlsQtH1DList::Print() {
SlsQtH1DList *hl = this;
int i = 0;
while (hl) {
std::cout << " " << i++ << ") " << hl << " " << hl->the_hist << " " << hl->the_next << '\n';
std::cout << " " << i++ << ") " << hl << " " << hl->the_hist << " "
<< hl->the_next << '\n';
hl = hl->the_next;
if (i > 10)
break;
@ -327,12 +314,12 @@ void SlsQtH1DList::Remove(SlsQtH1D *hist) {
hl = hl->the_next;
else { // match
if (!hl->the_next)
hl->the_hist = 0; // first the_hist is zero when there's no next
hl->the_hist = nullptr; // first the_hist is zero when there's no next
else {
SlsQtH1DList *t = hl->the_next;
hl->the_hist = t->the_hist;
hl->the_next = t->the_next;
t->the_next = 0;
t->the_next = nullptr;
delete t;
}
}
@ -342,7 +329,7 @@ void SlsQtH1DList::Remove(SlsQtH1D *hist) {
// 1d plot stuff
SlsQt1DPlot::SlsQt1DPlot(QWidget *parent) : QwtPlot(parent) {
// n_histograms_attached=0;
hline = vline = 0;
hline = vline = nullptr;
hist_list = new SlsQtH1DList();
UnknownStuff();
@ -361,15 +348,15 @@ SlsQt1DPlot::SlsQt1DPlot(QWidget *parent) : QwtPlot(parent) {
}
SlsQt1DPlot::~SlsQt1DPlot() {
if (hist_list)
delete hist_list;
if (hline)
delete hline;
if (vline)
delete vline;
if (zoomer)
delete zoomer;
if (panner)
delete panner;
}
@ -398,13 +385,9 @@ void SlsQt1DPlot::HistogramDetached(SlsQtH1D *h) {
Update();
}
void SlsQt1DPlot::Update() {
replot();
}
void SlsQt1DPlot::Update() { replot(); }
void SlsQt1DPlot::SetTitle(QString title) {
setTitle(title);
}
void SlsQt1DPlot::SetTitle(QString title) { setTitle(title); }
void SlsQt1DPlot::SetXTitle(QString title) {
setAxisTitle(QwtPlot::xBottom, title);
@ -443,7 +426,8 @@ void SlsQt1DPlot::SetLog(int axisId, bool yes) {
zoomer->ResetZoomBase(); // needs to be done before setting Engine
//the old ones are deleted by in the setAxisScaleFunction() function see: 128 of file qwt_plot_axis.cpp
// the old ones are deleted by in the setAxisScaleFunction() function see:
// 128 of file qwt_plot_axis.cpp
if (yes)
setAxisScaleEngine(axisId, new QwtLog10ScaleEngine());
else
@ -459,11 +443,13 @@ void SlsQt1DPlot::UnZoom() {
setAxisScale(QwtPlot::xBottom, zoomer->x(), zoomer->x() + zoomer->w());
setAxisScale(QwtPlot::yLeft, zoomer->y(), zoomer->y() + zoomer->h());
zoomer->setZoomBase(); //Call replot for the attached plot before initializing the zoomer with its scales.
zoomer->setZoomBase(); // Call replot for the attached plot before
// initializing the zoomer with its scales.
Update();
}
void SlsQt1DPlot::SetZoom(double xmin, double ymin, double x_width, double y_width) {
void SlsQt1DPlot::SetZoom(double xmin, double ymin, double x_width,
double y_width) {
setAxisScale(QwtPlot::xBottom, xmin, xmin + x_width);
setAxisScale(QwtPlot::yLeft, ymin, ymin + y_width);
Update();
@ -473,7 +459,7 @@ void SlsQt1DPlot::RemoveHLine() {
if (hline)
hline->detach();
delete hline;
hline = 0;
hline = nullptr;
}
void SlsQt1DPlot::InsertHLine(double y) {
@ -490,7 +476,7 @@ void SlsQt1DPlot::RemoveVLine() {
if (vline)
vline->detach();
delete vline;
vline = 0;
vline = nullptr;
}
void SlsQt1DPlot::InsertVLine(double x) {
@ -510,12 +496,9 @@ void SlsQt1DPlot::SetupZoom() {
// Ctrl+RighButton: zoom out to full size
zoomer = new SlsQt1DZoomer(canvas());
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton,
Qt::ControlModifier);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
panner = new QwtPlotPanner((QwtPlotCanvas *)canvas());
@ -554,58 +537,40 @@ void SlsQt1DPlot::alignScales() {
}
void SlsQt1DPlot::UnknownStuff() {
#if QWT_VERSION < 0x060000
// Disable polygon clipping
//not supported for version 6
QwtPainter::setDeviceClipping(false);
canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
#else
// We don't need the cache here
((QwtPlotCanvas *)canvas())->setPaintAttribute(QwtPlotCanvas::BackingStore, false);
#endif
#if QT_VERSION >= 0x040000
((QwtPlotCanvas *)canvas())
->setPaintAttribute(QwtPlotCanvas::BackingStore, false);
#ifdef Q_WS_X11
// Qt::WA_PaintOnScreen is only supported for X11, but leads
// to substantial bugs with Qt 4.2.x/Windows
canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
#endif
#endif
}
//Added by Dhanya on 19.06.2012 to disable zooming when any of the axes range has been set
// Added by Dhanya on 19.06.2012 to disable zooming when any of the axes range
// has been set
void SlsQt1DPlot::DisableZoom(bool disable) {
if (disableZoom != disable) {
disableZoom = disable;
#ifdef VERBOSE
if (disable)
std::cout << "Disabling zoom\n";
else
std::cout << "Enabling zoom\n";
#endif
if (disable) {
if (zoomer) {
zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::NoButton);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::NoButton, Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::NoButton, Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::NoButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect1,
Qt::NoButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::NoButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Qt::NoButton);
}
if (panner)
panner->setMouseButton(Qt::NoButton);
} else {
if (zoomer) {
zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::LeftButton);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect1,
Qt::LeftButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Qt::RightButton);
}
if (panner)
panner->setMouseButton(Qt::MidButton);

View File

@ -0,0 +1,93 @@
/* TODO! short description */
#include "SlsQt1DZoomer.h"
#include "SlsQt1DPlot.h"
#include <qwt_plot.h>
#include <qwt_scale_div.h>
#include <iostream>
void SlsQt1DZoomer::ResetZoomBase() {
SetZoomBase(x0, y0, x1 - x0,
y1 - y0); // for going between log and nonlog plots
}
void SlsQt1DZoomer::SetZoomBase(double xmin, double ymin, double x_width,
double y_width) {
if (xIsLog && xmin <= 0) {
double xmax = xmin + x_width;
xmin = firstXgt0 * 0.98;
if (xmax <= xmin)
x_width = firstXgt0;
else
x_width = xmax - xmin;
}
if (yIsLog && ymin <= 0) {
double ymax = ymin + y_width;
ymin = firstYgt0 * 0.98;
if (ymax <= ymin)
y_width = firstYgt0;
else
y_width = ymax - ymin;
}
if (plot()) {
if (xIsLog) {
double xmin_curr =
plot()->axisScaleDiv(QwtPlot::xBottom).lowerBound();
double xmax_curr =
plot()->axisScaleDiv(QwtPlot::xBottom).upperBound();
if (xmin_curr < xmin)
xmin_curr = xmin;
if (xmax_curr > xmin + x_width)
xmax_curr = xmin + x_width;
plot()->setAxisScale(QwtPlot::xBottom, xmin_curr, xmax_curr);
}
if (yIsLog) {
double ymin_curr =
plot()->axisScaleDiv(QwtPlot::yLeft).lowerBound();
double ymax_curr =
plot()->axisScaleDiv(QwtPlot::yLeft).upperBound();
if (ymin_curr < ymin)
ymin_curr = ymin;
if (ymax_curr > ymin + y_width)
ymax_curr = ymin + y_width;
plot()->setAxisScale(QwtPlot::yLeft, ymin_curr, ymax_curr);
}
plot()->replot();
}
setZoomBase(QRectF(xmin, ymin, x_width, y_width));
}
void SlsQt1DZoomer::SetZoomBase(SlsQtH1D *h) {
x0 = h->GetXMin() < 0 ? h->GetXMin() * 1.02 : h->GetXMin() / 1.02;
x1 = h->GetXMax() < 0 ? h->GetXMax() / 1.02 : h->GetXMax() * 1.02;
y0 = h->GetYMin() < 0 ? h->GetYMin() * 1.02 : h->GetYMin() / 1.02;
y1 = h->GetYMax() < 0 ? h->GetYMax() / 1.02 : h->GetYMax() * 1.02;
firstXgt0 = h->GetFirstXgtZero(); // for log plots
firstYgt0 = h->GetFirstYgtZero(); // for log plots
ResetZoomBase();
}
void SlsQt1DZoomer::ExtendZoomBase(SlsQtH1D *h) {
double h_x0 = h->GetXMin() < 0 ? h->GetXMin() * 1.02 : h->GetXMin() / 1.02;
double h_x1 = h->GetXMax() < 0 ? h->GetXMax() / 1.02 : h->GetXMax() * 1.02;
double h_y0 = h->GetYMin() < 0 ? h->GetYMin() * 1.02 : h->GetYMin() / 1.02;
double h_y1 = h->GetYMax() < 0 ? h->GetYMax() / 1.02 : h->GetYMax() * 1.02;
if (h_x0 < x0)
x0 = h_x0;
if (h_x1 > x1)
x1 = h_x1;
if (h_y0 < y0)
y0 = h_y0;
if (h_y1 > y1)
y1 = h_y1;
if (h->GetFirstXgtZero() < firstXgt0)
firstXgt0 = h->GetFirstXgtZero();
if (h->GetFirstYgtZero() < firstYgt0)
firstYgt0 = h->GetFirstYgtZero();
ResetZoomBase();
}

View File

@ -1,106 +0,0 @@
/**
* @author Ian Johnson
* @version 1.0
*/
#include <iostream>
#include <qwt_plot.h>
#include <qwt_scale_div.h>
#include "SlsQt1DPlot.h"
#include "SlsQt1DZoomer.h"
void SlsQt1DZoomer::ResetZoomBase(){
SetZoomBase(x0,y0,x1-x0,y1-y0); //for going between log and nonlog plots
}
void SlsQt1DZoomer::SetZoomBase(double xmin,double ymin,double x_width, double y_width){
if(xIsLog&&xmin<=0){
double xmax = xmin+x_width;
xmin = firstXgt0*0.98;
if(xmax<=xmin) x_width=firstXgt0;
else x_width=xmax-xmin;
}
if(yIsLog&&ymin<=0){
double ymax = ymin+y_width;
ymin = firstYgt0*0.98;
if(ymax<=ymin) y_width=firstYgt0;
else y_width=ymax-ymin;
}
if(plot()){
if(xIsLog){
#if QWT_VERSION < 0x50200
double xmin_curr = plot()->axisScaleDiv(QwtPlot::xBottom)->lBound();
double xmax_curr = plot()->axisScaleDiv(QwtPlot::xBottom)->hBound();
#elif QWT_VERSION < 0x060100
double xmin_curr = plot()->axisScaleDiv(QwtPlot::xBottom)->lowerBound();
double xmax_curr = plot()->axisScaleDiv(QwtPlot::xBottom)->upperBound();
#else
double xmin_curr = plot()->axisScaleDiv(QwtPlot::xBottom).lowerBound();
double xmax_curr = plot()->axisScaleDiv(QwtPlot::xBottom).upperBound();
#endif
if(xmin_curr<xmin) xmin_curr=xmin;
if(xmax_curr>xmin+x_width) xmax_curr=xmin+x_width;
plot()->setAxisScale(QwtPlot::xBottom,xmin_curr,xmax_curr);
}
if(yIsLog){
#if QWT_VERSION < 0x50200
double ymin_curr = plot()->axisScaleDiv(QwtPlot::yLeft)->lBound();
double ymax_curr = plot()->axisScaleDiv(QwtPlot::yLeft)->hBound();
#elif QWT_VERSION < 0x060100
double ymin_curr = plot()->axisScaleDiv(QwtPlot::yLeft)->lowerBound();
double ymax_curr = plot()->axisScaleDiv(QwtPlot::yLeft)->upperBound();
#else
double ymin_curr = plot()->axisScaleDiv(QwtPlot::yLeft).lowerBound();
double ymax_curr = plot()->axisScaleDiv(QwtPlot::yLeft).upperBound();
#endif
if(ymin_curr<ymin) ymin_curr=ymin;
if(ymax_curr>ymin+y_width) ymax_curr=ymin+y_width;
plot()->setAxisScale(QwtPlot::yLeft,ymin_curr,ymax_curr);
}
plot()->replot();
}
#if QWT_VERSION<0x060000
setZoomBase(QwtDoubleRect(xmin,ymin,x_width,y_width));
#else
setZoomBase(QRectF(xmin,ymin,x_width,y_width));
#endif
}
void SlsQt1DZoomer::SetZoomBase(SlsQtH1D* h){
x0 = h->GetXMin()<0 ? h->GetXMin()*1.02 : h->GetXMin()/1.02;
x1 = h->GetXMax()<0 ? h->GetXMax()/1.02 : h->GetXMax()*1.02;
y0 = h->GetYMin()<0 ? h->GetYMin()*1.02 : h->GetYMin()/1.02;
y1 = h->GetYMax()<0 ? h->GetYMax()/1.02 : h->GetYMax()*1.02;
firstXgt0 = h->GetFirstXgtZero(); //for log plots
firstYgt0 = h->GetFirstYgtZero(); //for log plots
ResetZoomBase();
}
void SlsQt1DZoomer::ExtendZoomBase(SlsQtH1D* h){
double h_x0 = h->GetXMin()<0 ? h->GetXMin()*1.02 : h->GetXMin()/1.02;
double h_x1 = h->GetXMax()<0 ? h->GetXMax()/1.02 : h->GetXMax()*1.02;
double h_y0 = h->GetYMin()<0 ? h->GetYMin()*1.02 : h->GetYMin()/1.02;
double h_y1 = h->GetYMax()<0 ? h->GetYMax()/1.02 : h->GetYMax()*1.02;
if(h_x0<x0) x0 = h_x0;
if(h_x1>x1) x1 = h_x1;
if(h_y0<y0) y0 = h_y0;
if(h_y1>y1) y1 = h_y1;
if(h->GetFirstXgtZero()<firstXgt0) firstXgt0 = h->GetFirstXgtZero();
if(h->GetFirstYgtZero()<firstYgt0) firstYgt0 = h->GetFirstYgtZero();
ResetZoomBase();
}

View File

@ -0,0 +1,143 @@
/* TODO! short description */
#include "SlsQt2DHist.h"
#include "ansi.h"
#include <cmath>
#include <iostream>
using std::cout;
using std::endl;
SlsQt2DHist::SlsQt2DHist(int nbinsx, double xmin, double xmax, int nbinsy,
double ymin, double ymax, double *d, double zmin,
double zmax)
: QwtRasterData() {
x_min = 0;
x_max = 0;
y_min = 0;
y_max = 0;
interp = 0;
nx_array = ny_array = 0;
data = nullptr;
SetData(nbinsx, xmin, xmax, nbinsy, ymin, ymax, d, zmin, zmax);
}
SlsQt2DHist::~SlsQt2DHist() { delete[] data; }
int SlsQt2DHist::GetBinIndex(int bx, int by) {
int b = bx * ny + by;
if (b < 0 || b >= nb) {
cout << "GetBinIndex:: Incorrect indicies bx and by returning overflow "
"bin;"
<< endl;
return nb;
}
return b;
}
int SlsQt2DHist::FindBinIndex(double x, double y) {
return GetBinIndex(int((x - x_min) / x_width), int((y - y_min) / y_width));
}
double SlsQt2DHist::GetBinValue(int bx, int by) {
return data[GetBinIndex(bx, by)];
}
void SlsQt2DHist::SetBinValue(int bx, int by, double v) {
z_mean_has_been_calculated = 0;
data[GetBinIndex(bx, by)] = v;
}
void SlsQt2DHist::SetData(int nbinsx, double xmin, double xmax, int nbinsy,
double ymin, double ymax, double *d, double zmin,
double zmax) {
z_mean_has_been_calculated = 0;
if (xmax < xmin || ymax < ymin)
cout << "Warning input range invalid." << endl;
x_width = (xmax - xmin) / nbinsx;
y_width = (ymax - ymin) / nbinsy;
if (x_min != xmin || x_max != xmax || y_min != ymin || y_max != ymax) {
x_min = xmin;
x_max = xmax;
y_min = ymin;
y_max = ymax;
setInterval(Qt::XAxis, QwtInterval(xmin, xmax));
setInterval(Qt::YAxis, QwtInterval(ymin, ymax));
}
if (nbinsx * nbinsy < 1) {
cout << "Exitting: SlsQt2DHist::SetData() number of bins must be "
"greater than zero."
<< endl;
exit(1);
}
if (nbinsx * nbinsy > nx_array * ny_array) {
delete[] data;
data = new double[nbinsx * nbinsy + 1]; // one for under/overflow bin
nx_array = nbinsx;
ny_array = nbinsy;
}
nx = nbinsx;
ny = nbinsy;
nb = nx * ny;
data[nb] = 0; // set over flow to zero
if (d) {
memcpy(data, d, nb * sizeof(double));
SetMinMax(zmin, zmax);
}
}
void SlsQt2DHist::SetMinMax(double zmin, double zmax) {
/* if(zmin<zmax){ edited out to test*/
if (zmax != -1) {
z_min = zmin;
z_max = zmax;
} else {
z_mean_has_been_calculated = 1;
z_min = data[0];
z_mean = 0;
z_max = data[0];
for (int i = 0; i < nb; i++) {
if (data[i] < z_min)
z_min = data[i];
if (data[i] > z_max)
z_max = data[i];
z_mean += data[i];
}
z_mean /= nb;
if (z_min > 0)
z_min /= 1.02;
else
z_min *= 1.02;
if (z_max > 0)
z_max *= 1.02;
else
z_max /= 1.02;
}
setInterval(Qt::ZAxis, QwtInterval(z_min, z_max));
}
double SlsQt2DHist::GetMean() {
if (!z_mean_has_been_calculated) {
z_mean_has_been_calculated = 1;
z_mean = 0;
for (int i = 0; i < nb; i++)
z_mean += data[i];
z_mean /= nb;
}
return z_mean;
}
double SlsQt2DHist::SetMinimumToFirstGreaterThanZero() {
z_min = fabs(z_max) + 1;
for (int i = 0; i < nb; i++) {
if (data[i] > 0 && data[i] < z_min)
z_min = data[i];
}
setInterval(Qt::ZAxis, QwtInterval(z_min, z_max));
return z_min;
}

View File

@ -1,144 +0,0 @@
/**
* @author Ian Johnson
* @version 1.0
*/
#include "ansi.h"
#include <iostream>
#include <cmath>
#include "SlsQt2DHist.h"
using std::cout;
using std::endl;
SlsQt2DHist::SlsQt2DHist(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double* d,double zmin,double zmax):QwtRasterData(){
x_min=0;x_max=0;y_min=0;y_max=0;
interp=0;
nx_array=ny_array=0;data=0;
SetData(nbinsx,xmin,xmax,nbinsy,ymin,ymax,d,zmin,zmax);
}
SlsQt2DHist::~SlsQt2DHist(){if(data) delete [] data;}
int SlsQt2DHist::GetBinIndex(int bx, int by){
int b = bx*ny+by;
if(b<0 || b>=nb){
cout<<"GetBinIndex:: Incorrect indicies bx and by returning overflow bin;"<<endl;
return nb;
}
return b;
}
int SlsQt2DHist::FindBinIndex(double x, double y){
return GetBinIndex(int((x-x_min)/x_width),int((y-y_min)/y_width));
}
double SlsQt2DHist::GetBinValue(int bx,int by){
return data[GetBinIndex(bx,by)];
}
void SlsQt2DHist::SetBinValue(int bx,int by,double v){
z_mean_has_been_calculated = 0;
data[GetBinIndex(bx,by)] = v;
}
void SlsQt2DHist::SetData(int nbinsx, double xmin, double xmax, int nbinsy,double ymin, double ymax, double *d,double zmin,double zmax){
z_mean_has_been_calculated = 0;
if(xmax<xmin||ymax<ymin) cout<<"Warning input range invalid."<<endl;
x_width = (xmax - xmin)/nbinsx;
y_width = (ymax - ymin)/nbinsy;
if(x_min!=xmin||x_max!=xmax||y_min!=ymin||y_max!=ymax){
x_min=xmin;x_max=xmax;
y_min=ymin;y_max=ymax;
#if QWT_VERSION<0x060000
setBoundingRect(QRectF(xmin,ymin,x_max-x_min,y_max-y_min));
#else
setInterval( Qt::XAxis,QwtInterval(xmin,xmax));
setInterval( Qt::YAxis,QwtInterval(ymin,ymax));
// setInterval( Qt::ZAxis,QwtInterval(zmin,zmax));
//setInterval( Qt::ZAxis,QwtInterval(0.,1.));
#endif
}
if(nbinsx*nbinsy<1){
cout<<"Exitting: SlsQt2DHist::SetData() number of bins must be greater than zero."<<endl;
exit(1);
}
if(nbinsx*nbinsy>nx_array*ny_array){
if(data) delete [] data;
data = new double [nbinsx*nbinsy+1]; //one for under/overflow bin
nx_array = nbinsx;
ny_array = nbinsy;
}
nx=nbinsx;
ny=nbinsy;
nb=nx*ny;
data[nb]=0;//set over flow to zero
if(d){
memcpy(data,d,nb*sizeof(double));
SetMinMax(zmin,zmax);
}
}
void SlsQt2DHist::SetMinMax(double zmin,double zmax){
/* if(zmin<zmax){ edited out to test*/
if(zmax != -1){
z_min=zmin;
z_max=zmax;
}else{
z_mean_has_been_calculated = 1;
z_min=data[0];
z_mean=0;
z_max=data[0];
for(int i=0;i<nb;i++){
if(data[i]<z_min) z_min=data[i];
if(data[i]>z_max) z_max=data[i];
z_mean+=data[i];
}
z_mean/=nb;
if(z_min>0) z_min/=1.02; else z_min*=1.02;
if(z_max>0) z_max*=1.02; else z_max/=1.02;
}
#if QWT_VERSION<0x060000
;
#else
setInterval( Qt::ZAxis,QwtInterval(z_min,z_max));
#endif
}
double SlsQt2DHist::GetMean(){
if(!z_mean_has_been_calculated){
z_mean_has_been_calculated = 1;
z_mean=0;
for(int i=0;i<nb;i++) z_mean+=data[i];
z_mean/=nb;
}
return z_mean;
}
double SlsQt2DHist::SetMinimumToFirstGreaterThanZero(){
z_min=fabs(z_max)+1;
for(int i=0;i<nb;i++){
if(data[i]>0 && data[i]<z_min) z_min=data[i];
}
#if QWT_VERSION<0x060000
;
#else
setInterval( Qt::ZAxis,QwtInterval(z_min,z_max));
#endif
return z_min;
}

View File

@ -1,15 +1,9 @@
#include "SlsQt2DPlot.h"
#include "ansi.h"
#include <cmath>
#include <iostream>
#include <qlist.h>
#include <qprinter.h>
#include <qtoolbutton.h>
#if QT_VERSION >= 0x040000
#include <qprintdialog.h>
#endif
#include <qwt_color_map.h>
#include <qwt_plot_layout.h>
#include <qwt_plot_panner.h>
@ -19,68 +13,27 @@
#include <qwt_scale_engine.h>
#include <qwt_scale_widget.h>
#if QWT_VERSION >= 0x060100
#define QwtLog10ScaleEngine QwtLogScaleEngine
#endif
#include <cmath>
#include <iostream>
SlsQt2DPlot::SlsQt2DPlot(QWidget *parent) : QwtPlot(parent) {
isLog = 0;
axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Floating);
axisScaleEngine(QwtPlot::xBottom)->setAttribute(QwtScaleEngine::Floating);
d_spectrogram = new QwtPlotSpectrogram();
hist = new SlsQt2DHist();
SetupZoom();
SetupColorMap();
#if QWT_VERSION < 0x060000
d_spectrogram->setData(*hist);
#else
d_spectrogram->setData(hist);
#endif
d_spectrogram->attach(this);
plotLayout()->setAlignCanvasToScales(true);
FillTestPlot();
Update();
}
SlsQt2DPlot::~SlsQt2DPlot() = default;
SlsQt2DPlot::~SlsQt2DPlot() {
if (d_spectrogram) {
d_spectrogram->detach();
//delete d_spectrogram;
}
if (hist) {
delete hist;
}
if (colorMapLinearScale)
delete colorMapLinearScale;
if (colorMapLogScale)
delete colorMapLogScale;
if (zoomer)
delete zoomer;
if (panner)
delete panner;
#if QWT_VERSION<0x060000
if (contourLevelsLinear)
delete contourLevelsLinear;
if (contourLevelsLog)
delete contourLevelsLog;
#endif
}
void SlsQt2DPlot::SetTitle(QString title) {
setTitle(title);
}
void SlsQt2DPlot::SetTitle(QString title) { setTitle(title); }
void SlsQt2DPlot::SetXTitle(QString title) {
setAxisTitle(QwtPlot::xBottom, title);
@ -120,40 +73,13 @@ void SlsQt2DPlot::SetZFont(const QFont& f) {
}
void SlsQt2DPlot::SetupColorMap() {
colorMapLinearScale = myColourMap(0);
#if QWT_VERSION < 0x060000
d_spectrogram->setColorMap(*colorMapLinearScale);
#else
d_spectrogram->setColorMap(colorMapLinearScale);
#endif
colorMapLogScale = myColourMap(1);
#if QWT_VERSION < 0x060000
contourLevelsLinear = new QwtValueList();
for (double level = 0.5; level < 10.0; level += 1.0)
(*contourLevelsLinear) += level;
d_spectrogram->setContourLevels(*contourLevelsLinear);
#else
;
d_spectrogram->setColorMap(myColourMap(0));
for (double level = 0.5; level < 10.0; level += 1.0)
(contourLevelsLinear) += level;
d_spectrogram->setContourLevels(contourLevelsLinear);
#endif
//
#if QWT_VERSION < 0x060000
contourLevelsLog = new QwtValueList();
for (double level = 0.5; level < 10.0; level += 1.0)
(*contourLevelsLog) += (pow(10, 2 * level / 10.0) - 1) / 99.0 * 10;
#else
;
for (double level = 0.5; level < 10.0; level += 1.0)
(contourLevelsLog) += (pow(10, 2 * level / 10.0) - 1) / 99.0 * 10;
#endif
// A color bar on the right axis
rightAxis = axisWidget(QwtPlot::yRight);
@ -166,14 +92,15 @@ void SlsQt2DPlot::SetupColorMap() {
void SlsQt2DPlot::FillTestPlot(int mode) {
static int nx = 50;
static int ny = 50;
static double *the_data = 0;
if (the_data == 0)
static double *the_data = nullptr;
if (the_data == nullptr)
the_data = new double[nx * ny];
double dmax = sqrt(pow(nx / 2.0 - 0.5, 2) + pow(ny / 2.0 - 0.5, 2));
for (int i = 0; i < nx; i++) {
for (int j = 0; j < ny; j++) {
double d = sqrt(pow(nx / 2.0 - (i + 0.5), 2) + pow(ny / 2.0 - (j + 0.5), 2));
double d = sqrt(pow(nx / 2.0 - (i + 0.5), 2) +
pow(ny / 2.0 - (j + 0.5), 2));
if (mode % 3)
the_data[i + j * nx] = 10 * d / dmax;
@ -193,14 +120,9 @@ void SlsQt2DPlot::SetupZoom() {
zoomer = new SlsQt2DZoomer(canvas());
zoomer->SetHist(hist);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton,
Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
panner = new QwtPlotPanner(canvas());
panner->setAxisEnabled(QwtPlot::yRight, false);
panner->setMouseButton(Qt::MidButton);
@ -217,31 +139,19 @@ void SlsQt2DPlot::SetupZoom() {
zoomer->setTrackerPen(c);
}
/*void SlsQt2DPlot::CompletelyUnZoom(){
setAxisScale(QwtPlot::xBottom,hist->GetXMin(),hist->GetXMin()+(hist->GetXMax()-hist->GetXMin()));
setAxisScale(QwtPlot::yLeft,hist->GetYMin(),hist->GetYMin()+(hist->GetYMax()-hist->GetYMin()));
zoomer->setZoomBase();
//replot();
}*/
void SlsQt2DPlot::UnZoom(bool replot) {
#if QWT_VERSION < 0x060000
zoomer->setZoomBase(QwtDoubleRect(hist->GetXMin(), hist->GetYMin(), hist->GetXMax() - hist->GetXMin(), hist->GetYMax() - hist->GetYMin()));
#else
zoomer->setZoomBase(QRectF(hist->GetXMin(), hist->GetYMin(), hist->GetXMax() - hist->GetXMin(), hist->GetYMax() - hist->GetYMin()));
#endif
zoomer->setZoomBase(replot); //Call replot for the attached plot before initializing the zoomer with its scales.
zoomer->setZoomBase(QRectF(hist->GetXMin(), hist->GetYMin(),
hist->GetXMax() - hist->GetXMin(),
hist->GetYMax() - hist->GetYMin()));
zoomer->setZoomBase(replot); // Call replot for the attached plot before
// initializing the zoomer with its scales.
// zoomer->zoom(0);
}
void SlsQt2DPlot::SetZoom(double xmin, double ymin, double x_width, double y_width) {
#if QWT_VERSION < 0x060000
zoomer->setZoomBase(QwtDoubleRect(xmin, ymin, x_width, y_width));
#else
void SlsQt2DPlot::SetZoom(double xmin, double ymin, double x_width,
double y_width) {
zoomer->setZoomBase(QRectF(xmin, ymin, x_width, y_width));
#endif
}
void SlsQt2DPlot::DisableZoom(bool disable) {
@ -256,25 +166,23 @@ void SlsQt2DPlot::DisableZoom(bool disable) {
#endif
if (disable) {
if (zoomer) {
zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::NoButton);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::NoButton, Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::NoButton, Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::NoButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect1,
Qt::NoButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::NoButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Qt::NoButton);
}
if (panner)
panner->setMouseButton(Qt::NoButton);
} else {
if (zoomer) {
zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::LeftButton);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect1,
Qt::LeftButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Qt::RightButton);
}
if (panner)
panner->setMouseButton(Qt::MidButton);
@ -282,7 +190,6 @@ void SlsQt2DPlot::DisableZoom(bool disable) {
}
}
void SlsQt2DPlot::SetZMinMax(double zmin, double zmax) {
hist->SetMinMax(zmin, zmax);
}
@ -295,63 +202,40 @@ QwtLinearColorMap *SlsQt2DPlot::myColourMap(QVector<double> colourStops) {
double g[] = {0.00, 0.81, 1.00, 0.20, 0.00};
double b[] = {0.51, 1.00, 0.12, 0.00, 0.00};
QColor c1, c2, c;
c1.setRgbF(r[0], g[0], b[0], 0);
// QColor c1, c2, c;
QColor c2, c;
c2.setRgbF(r[ns - 1], g[ns - 1], b[ns - 1]);
QwtLinearColorMap *copyMap = new QwtLinearColorMap(Qt::lightGray, c2);
for (int is = 0; is < ns - 1; is++) {
c.setRgbF(r[is], g[is], b[is]);
copyMap->addColorStop(colourStops.value(is), c);
copyMap->addColorStop(colourStops[is], c);
}
return copyMap;
}
QwtLinearColorMap *SlsQt2DPlot::myColourMap(int log) {
int ns = 5;
QVector<double> cs1(0);
QVector<double> lcs1(0);
cs1.append(0.);
cs1.append(0.34);
cs1.append(0.61);
cs1.append(0.84);
cs1.append(1.);
QVector<double> cs{0.0, 0.34, 0.61 ,0.84, 1.0};
if (log) {
for (int is = 0; is < ns; is++) {
lcs1.append((pow(10, 2 * cs1.value(is)) - 1) / 99.0);
for (int i = 0; i < cs.size(); ++i)
cs[i] = (pow(10, 2 * cs[i]) - 1) / 99.0;
}
return myColourMap(lcs1);
return myColourMap(cs);
}
return myColourMap(cs1);
}
void SlsQt2DPlot::Update() {
#if QWT_VERSION < 0x060000
rightAxis->setColorMap(d_spectrogram->data().range(), d_spectrogram->colorMap());
#else
if (isLog)
hist->SetMinimumToFirstGreaterThanZero();
const QwtInterval zInterval = d_spectrogram->data()->interval(Qt::ZAxis);
rightAxis->setColorMap(zInterval, myColourMap(isLog));
#endif
if (!zoomer->zoomRectIndex())
UnZoom();
#if QWT_VERSION < 0x060000
setAxisScale(QwtPlot::yRight, d_spectrogram->data().range().minValue(),
d_spectrogram->data().range().maxValue());
#else
//cprintf(MAGENTA, "zmin:%f zmax:%f\n", zInterval.minValue(), zInterval.maxValue());
setAxisScale(QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue());
plotLayout()->setAlignCanvasToScales(true);
#endif
replot();
}
void SlsQt2DPlot::SetInterpolate(bool enable) {
@ -364,7 +248,8 @@ void SlsQt2DPlot::SetContour(bool enable) {
Update();
}
void SlsQt2DPlot::SetLogz(bool enable, bool isMin, bool isMax, double min, double max) {
void SlsQt2DPlot::SetLogz(bool enable, bool isMin, bool isMax, double min,
double max) {
LogZ(enable);
SetZRange(isMin, isMax, min, max);
}
@ -387,63 +272,20 @@ void SlsQt2DPlot::SetZRange(bool isMin, bool isMax, double min, double max){
void SlsQt2DPlot::LogZ(bool on) {
if (on) {
isLog = 1;
//if(hist->GetMinimum()<=0) hist->SetMinimumToFirstGreaterThanZero();
#if QWT_VERSION < 0x060000
d_spectrogram->setColorMap(*colorMapLogScale);
#else
d_spectrogram->setColorMap(myColourMap(isLog));
#endif
setAxisScaleEngine(QwtPlot::yRight, new QwtLog10ScaleEngine);
#if QWT_VERSION < 0x060000
d_spectrogram->setContourLevels(*contourLevelsLog);
#else
setAxisScaleEngine(QwtPlot::yRight, new QwtLogScaleEngine);
d_spectrogram->setContourLevels(contourLevelsLog);
#endif
} else {
isLog = 0;
#if QWT_VERSION < 0x060000
d_spectrogram->setColorMap(*colorMapLinearScale);
#else
d_spectrogram->setColorMap(myColourMap(isLog));
#endif
setAxisScaleEngine(QwtPlot::yRight, new QwtLinearScaleEngine);
#if QWT_VERSION < 0x060000
d_spectrogram->setContourLevels(*contourLevelsLinear);
#else
d_spectrogram->setContourLevels(contourLevelsLinear);
#endif
}
Update();
}
void SlsQt2DPlot::showSpectrogram(bool on) {
// static int io=0;
// FillTestPlot(io++);
d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ImageMode, on);
d_spectrogram->setDefaultContourPen(on ? QPen() : QPen(Qt::NoPen));
Update();
}
/*
void SlsQt2DPlot::printPlot(){
QPrinter printer;
printer.setOrientation(QPrinter::Landscape);
#if QT_VERSION < 0x040000
printer.setColorMode(QPrinter::Color);
printer.setOutputFileName("spectrogram.ps");
if (printer.setup())
#else
printer.setOutputFileName("spectrogram.pdf");
QPrintDialog dialog(&printer);
if ( dialog.exec() )
#endif
{
print(printer);
}
}
*/

72
slsDetectorGui/src/qCloneWidget.cpp Executable file → Normal file
View File

@ -1,7 +1,7 @@
#include "qCloneWidget.h"
#include "qDefs.h"
#include "SlsQt1DPlot.h"
#include "SlsQt2DPlot.h"
#include "qDefs.h"
#include <QCloseEvent>
#include <QFileDialog>
@ -11,10 +11,13 @@
int qCloneWidget::NumClones{0};
qCloneWidget::qCloneWidget(QWidget *parent, SlsQt1DPlot* p1, SlsQt2DPlot* p2, SlsQt1DPlot *gp1, SlsQt2DPlot* gp,
QString title, QString fPath, QString fName, int64_t aIndex,
bool displayStats, QString min, QString max, QString sum):
QMainWindow(parent), plot1d(p1), plot2d(p2), gainplot1d(gp1), gainplot2d(gp), filePath(fPath), fileName(fName), acqIndex(aIndex) {
qCloneWidget::qCloneWidget(QWidget *parent, SlsQt1DPlot *p1, SlsQt2DPlot *p2,
SlsQt1DPlot *gp1, SlsQt2DPlot *gp, QString title,
QString fPath, QString fName, int64_t aIndex,
bool displayStats, QString min, QString max,
QString sum)
: QMainWindow(parent), plot1d(p1), plot2d(p2), gainplot1d(gp1),
gainplot2d(gp), filePath(fPath), fileName(fName), acqIndex(aIndex) {
setupUi(this);
id = qCloneWidget::NumClones++;
SetupWidgetWindow(title);
@ -22,19 +25,17 @@ qCloneWidget::qCloneWidget(QWidget *parent, SlsQt1DPlot* p1, SlsQt2DPlot* p2, Sl
}
qCloneWidget::~qCloneWidget() {
if (plot1d)
delete plot1d;
if (plot2d)
delete plot2d;
if (gainplot1d)
delete gainplot1d;
if (gainplot2d)
delete gainplot2d;
}
void qCloneWidget::SetupWidgetWindow(QString title) {
std::string winTitle = std::string("Snapshot:") + std::to_string(id) + std::string(" - ") + NowTime();
std::string winTitle = std::string("Snapshot:") + std::to_string(id) +
std::string(" - ") + sls::Logger::Timestamp();
setWindowTitle(QString(winTitle.c_str()));
boxPlot->setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
@ -57,7 +58,8 @@ void qCloneWidget::SetupWidgetWindow(QString title) {
} else {
int ratio = qDefs::DATA_GAIN_PLOT_RATIO - 1;
plotLayout->addWidget(plot2d, 0, 0, ratio, ratio);
plotLayout->addWidget(gainplot2d, 0, ratio, 1, 1, Qt::AlignRight | Qt::AlignTop);
plotLayout->addWidget(gainplot2d, 0, ratio, 1, 1,
Qt::AlignRight | Qt::AlignTop);
}
}
connect(actionSaveClone, SIGNAL(triggered()), this, SLOT(SavePlot()));
@ -65,15 +67,19 @@ void qCloneWidget::SetupWidgetWindow(QString title) {
if (gainplot1d != nullptr) {
gainplot1d->setMinimumHeight(qDefs::MIN_HEIGHT_GAIN_PLOT_1D);
gainplot1d->setFixedWidth(plot1d->width());
// gainplot1d->setFixedHeight(plot1d->height() / qDefs::DATA_GAIN_PLOT_RATIO - 1);
// gainplot1d->setFixedHeight(plot1d->height() /
// qDefs::DATA_GAIN_PLOT_RATIO - 1);
}
if (gainplot2d != nullptr) {
gainplot2d->setFixedWidth(plot2d->width() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedWidth(plot2d->width() /
qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() /
qDefs::DATA_GAIN_PLOT_RATIO);
}
}
void qCloneWidget::DisplayStats(bool enable, QString min, QString max, QString sum) {
void qCloneWidget::DisplayStats(bool enable, QString min, QString max,
QString sum) {
if (enable) {
lblMinDisp->setText(QString("%1").arg(min));
lblMaxDisp->setText(QString("%1").arg(max));
@ -88,21 +94,32 @@ void qCloneWidget::SavePlot() {
char cID[10];
sprintf(cID, "%d", id);
// title
QString fName = filePath + QString('/') + fileName + QString("_clone") + QString("%1").arg(id) + QString("_acq") + QString("%1").arg(acqIndex) + QString(".png");
FILE_LOG(logINFO) << "Saving Clone:" << fName.toAscii().constData();
QString fName = filePath + QString('/') + fileName + QString("_clone") +
QString("%1").arg(id) + QString("_acq") +
QString("%1").arg(acqIndex) + QString(".png");
LOG(logINFO) << "Saving Clone:" << fName.toAscii().constData();
// save
QImage img(centralwidget->size().width(), centralwidget->size().height(), QImage::Format_RGB32);
QImage img(centralwidget->size().width(), centralwidget->size().height(),
QImage::Format_RGB32);
QPainter painter(&img);
centralwidget->render(&painter);
fName = QFileDialog::getSaveFileName(this, tr("Save Snapshot "), fName, tr("PNG Files (*.png);;XPM Files(*.xpm);;JPEG Files(*.jpg)"), 0, QFileDialog::ShowDirsOnly);
fName = QFileDialog::getSaveFileName(
this, tr("Save Snapshot "), fName,
tr("PNG Files (*.png);;XPM Files(*.xpm);;JPEG Files(*.jpg)"), nullptr,
QFileDialog::ShowDirsOnly);
if (!fName.isEmpty()) {
if ((img.save(fName))) {
qDefs::Message(qDefs::INFORMATION, "The SnapShot has been successfully saved", "qCloneWidget::SavePlot");
FILE_LOG(logINFO) << "The SnapShot has been successfully saved";
qDefs::Message(qDefs::INFORMATION,
"The SnapShot has been successfully saved",
"qCloneWidget::SavePlot");
LOG(logINFO) << "The SnapShot has been successfully saved";
} else {
qDefs::Message(qDefs::WARNING, "Attempt to save snapshot failed.\n Formats: .png, .jpg, .xpm.", "qCloneWidget::SavePlot");
FILE_LOG(logWARNING) << "Attempt to save snapshot failed";
qDefs::Message(
qDefs::WARNING,
"Attempt to save snapshot failed.\n Formats: .png, .jpg, .xpm.",
"qCloneWidget::SavePlot");
LOG(logWARNING) << "Attempt to save snapshot failed";
}
}
}
@ -110,11 +127,14 @@ void qCloneWidget::SavePlot() {
void qCloneWidget::resizeEvent(QResizeEvent *event) {
if (gainplot1d != nullptr) {
gainplot1d->setFixedWidth(plot1d->width());
gainplot1d->setFixedHeight(plot1d->height() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot1d->setFixedHeight(plot1d->height() /
qDefs::DATA_GAIN_PLOT_RATIO);
}
if (gainplot2d != nullptr) {
gainplot2d->setFixedWidth(plot2d->width() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedWidth(plot2d->width() /
qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() /
qDefs::DATA_GAIN_PLOT_RATIO);
}
event->accept();
}

29
slsDetectorGui/src/qDacWidget.cpp Executable file → Normal file
View File

@ -1,10 +1,10 @@
#include "qDacWidget.h"
#include "qDefs.h"
#include <iostream>
qDacWidget::qDacWidget(QWidget *parent, sls::Detector *detector, bool d, std::string n, slsDetectorDefs::dacIndex i) :
QWidget(parent), det(detector), isDac(d), index(i){
qDacWidget::qDacWidget(QWidget *parent, sls::Detector *detector, bool d,
std::string n, slsDetectorDefs::dacIndex i)
: QWidget(parent), det(detector), isDac(d), index(i) {
setupUi(this);
SetupWidgetWindow(n);
}
@ -25,7 +25,6 @@ void qDacWidget::SetupWidgetWindow(std::string name) {
Refresh();
}
void qDacWidget::Initialization() {
if (isDac) {
connect(spinDac, SIGNAL(editingFinished()), this, SLOT(SetDac()));
@ -38,7 +37,7 @@ void qDacWidget::SetDetectorIndex(int id) {
}
void qDacWidget::GetDac() {
FILE_LOG(logDEBUG) << "Getting Dac " << index;
LOG(logDEBUG) << "Getting Dac " << index;
disconnect(spinDac, SIGNAL(editingFinished()), this, SLOT(SetDac()));
try {
@ -48,26 +47,30 @@ void qDacWidget::GetDac() {
// mv
retval = det->getDAC(index, 1, {detectorIndex}).squash(-1);
lblDacmV->setText(QString("%1mV").arg(retval - 10));
} CATCH_DISPLAY(std::string("Could not get dac ") + std::to_string(index), "qDacWidget::GetDac")
}
CATCH_DISPLAY(std::string("Could not get dac ") + std::to_string(index),
"qDacWidget::GetDac")
connect(spinDac, SIGNAL(editingFinished()), this, SLOT(SetDac()));
}
void qDacWidget::SetDac() {
int val = (int)spinDac->value();
FILE_LOG(logINFO) << "Setting dac:" << lblDac->text().toAscii().data() << " : " << val;
LOG(logINFO) << "Setting dac:" << lblDac->text().toAscii().data()
<< " : " << val;
try {
det->setDAC(index, val, 0, {detectorIndex});
} CATCH_DISPLAY (std::string("Could not set dac ") + std::to_string(index), "qDacWidget::SetDac")
}
CATCH_DISPLAY(std::string("Could not set dac ") + std::to_string(index),
"qDacWidget::SetDac")
// update mV anyway
GetDac();
}
void qDacWidget::GetAdc() {
FILE_LOG(logDEBUG) << "Getting ADC " << index;
LOG(logDEBUG) << "Getting ADC " << index;
try {
auto retval = det->getTemperature(index, {detectorIndex}).squash(-1);
@ -76,8 +79,9 @@ void qDacWidget::GetAdc() {
} else {
spinDac->setValue(retval);
}
} CATCH_DISPLAY (std::string("Could not get adc ") + std::to_string(index), "qDacWidget::GetAdc")
}
CATCH_DISPLAY(std::string("Could not get adc ") + std::to_string(index),
"qDacWidget::GetAdc")
}
void qDacWidget::Refresh() {
@ -87,4 +91,3 @@ void qDacWidget::Refresh() {
GetAdc();
}
}

275
slsDetectorGui/src/qDetectorMain.cpp Executable file → Normal file
View File

@ -1,34 +1,32 @@
#include "qDetectorMain.h"
#include "qDefs.h"
#include "qDrawPlot.h"
#include "qTabMeasurement.h"
#include "qTabDataOutput.h"
#include "qTabPlot.h"
#include "qTabAdvanced.h"
#include "qTabSettings.h"
#include "qTabDataOutput.h"
#include "qTabDebugging.h"
#include "qTabDeveloper.h"
#include "qTabMeasurement.h"
#include "qTabMessages.h"
#include "qTabPlot.h"
#include "qTabSettings.h"
#include "versionAPI.h"
#include "ToString.h"
#include "versionAPI.h"
#include <QResizeEvent>
#include <QScrollArea>
#include <QFileDialog>
#include <QPlastiqueStyle>
#include <QResizeEvent>
#include <QScrollArea>
#include <QSizePolicy>
#include <iostream>
#include <getopt.h>
#include <iostream>
#include <string>
#include <getopt.h>
#include <sys/stat.h>
int main(int argc, char **argv) {
// options
std::string fname = "";
std::string fname;
bool isDeveloper = false;
int64_t tempval = 0;
int multiId = 0;
@ -38,12 +36,12 @@ int main(int argc, char **argv) {
// These options set a flag.
//{"verbose", no_argument, &verbose_flag, 1},
// These options dont set a flag. We distinguish them by their indices.
{"developer", no_argument, 0, 'd'},
{"config", required_argument, 0, 'f'},
{"id", required_argument, 0, 'i'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}};
{"developer", no_argument, nullptr, 'd'},
{"config", required_argument, nullptr, 'f'},
{"id", required_argument, nullptr, 'i'},
{"version", no_argument, nullptr, 'v'},
{"help", no_argument, nullptr, 'h'},
{nullptr, 0, nullptr, 0}};
// getopt_long stores the option index here
optind = 1;
@ -59,7 +57,7 @@ int main(int argc, char **argv) {
case 'f':
fname = optarg;
FILE_LOG(logDEBUG)
LOG(logDEBUG)
<< long_options[option_index].name << " " << optarg;
break;
@ -73,7 +71,7 @@ int main(int argc, char **argv) {
case 'v':
tempval = APIGUI;
FILE_LOG(logINFO) << "SLS Detector GUI " << GITBRANCH << " (0x"
LOG(logINFO) << "SLS Detector GUI " << GITBRANCH << " (0x"
<< std::hex << tempval << ")";
return 0;
@ -89,15 +87,13 @@ int main(int argc, char **argv) {
"i. Default: 0. Required \n" +
"\t only when more than one multi "
"detector object is needed.\n\n";
FILE_LOG(logERROR) << help_message;
LOG(logERROR) << help_message;
return -1;
}
}
QApplication app(argc, argv);
app.setStyle(new QPlastiqueStyle);
//app.setWindowIcon(QIcon(":/icons/images/mountain.png"));
app.setStyle(new QPlastiqueStyle); //style is deleted by QApplication
try {
qDetectorMain det(multiId, fname, isDeveloper);
det.show();
@ -109,8 +105,8 @@ int main(int argc, char **argv) {
return 0;
}
qDetectorMain::qDetectorMain(int multiId, std::string fname, bool isDevel)
: QMainWindow(0), detType(slsDetectorDefs::GENERIC), isDeveloper(isDevel),
qDetectorMain::qDetectorMain(int multiId, const std::string& fname, bool isDevel)
: QMainWindow(nullptr), detType(slsDetectorDefs::GENERIC), isDeveloper(isDevel),
heightPlotWindow(0), heightCentralWidget(0) {
setupUi(this);
@ -118,63 +114,66 @@ qDetectorMain::qDetectorMain(int multiId, std::string fname, bool isDevel)
SetUpWidgetWindow();
}
qDetectorMain::~qDetectorMain() {}
qDetectorMain::~qDetectorMain(){
disconnect(tabs, SIGNAL(currentChanged(int)), this,
SLOT(Refresh(int)));
}
void qDetectorMain::SetUpWidgetWindow() {
setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
// plot setup
plot = sls::make_unique<qDrawPlot>(dockWidgetPlot, det.get());
FILE_LOG(logDEBUG) << "DockPlot ready";
dockWidgetPlot->setWidget(plot.get());
plot = new qDrawPlot(dockWidgetPlot, det.get());
LOG(logDEBUG) << "DockPlot ready";
dockWidgetPlot->setWidget(plot);
// tabs setup
tabs = sls::make_unique<MyTabWidget>(this);
layoutTabs->addWidget(tabs.get());
tabs = new MyTabWidget(this);
layoutTabs->addWidget(tabs);
// creating all the other tab widgets
tabMeasurement = sls::make_unique<qTabMeasurement>(this, det.get(), plot.get());
tabDataOutput = sls::make_unique<qTabDataOutput>(this, det.get());
tabPlot = sls::make_unique<qTabPlot>(this, det.get(), plot.get());
tabSettings = sls::make_unique<qTabSettings>(this, det.get());
tabAdvanced = sls::make_unique<qTabAdvanced>(this, det.get(), plot.get());
tabDebugging = sls::make_unique<qTabDebugging>(this, det.get());
tabDeveloper = sls::make_unique<qTabDeveloper>(this, det.get());
tabMeasurement =
new qTabMeasurement(this, det.get(), plot);
tabDataOutput = new qTabDataOutput(this, det.get());
tabPlot = new qTabPlot(this, det.get(), plot);
tabSettings = new qTabSettings(this, det.get());
tabAdvanced = new qTabAdvanced(this, det.get(), plot);
tabDebugging = new qTabDebugging(this, det.get());
tabDeveloper = new qTabDeveloper(this, det.get());
// creating the scroll area widgets for the tabs
QScrollArea *scroll[NumberOfTabs];
for (int i = 0; i < NumberOfTabs; ++i) {
scroll[i] = new QScrollArea;
scroll[i] = sls::make_unique<QScrollArea>();
scroll[i]->setFrameShape(QFrame::NoFrame);
}
// setting the tab widgets to the scrollareas
scroll[MEASUREMENT]->setWidget(tabMeasurement.get());
scroll[DATAOUTPUT]->setWidget(tabDataOutput.get());
scroll[PLOT]->setWidget(tabPlot.get());
scroll[SETTINGS]->setWidget(tabSettings.get());
scroll[ADVANCED]->setWidget(tabAdvanced.get());
scroll[DEBUGGING]->setWidget(tabDebugging.get());
scroll[DEVELOPER]->setWidget(tabDeveloper.get());
scroll[MEASUREMENT]->setWidget(tabMeasurement);
scroll[DATAOUTPUT]->setWidget(tabDataOutput);
scroll[PLOT]->setWidget(tabPlot);
scroll[SETTINGS]->setWidget(tabSettings);
scroll[ADVANCED]->setWidget(tabAdvanced);
scroll[DEBUGGING]->setWidget(tabDebugging);
scroll[DEVELOPER]->setWidget(tabDeveloper);
// inserting all the tabs
tabs->insertTab(MEASUREMENT, scroll[MEASUREMENT], "Measurement");
tabs->insertTab(DATAOUTPUT, scroll[DATAOUTPUT], "Data Output");
tabs->insertTab(PLOT, scroll[PLOT], "Plot");
tabs->insertTab(SETTINGS, scroll[SETTINGS], "Settings");
tabs->insertTab(ADVANCED, scroll[ADVANCED], "Advanced");
tabs->insertTab(DEBUGGING, scroll[DEBUGGING], "Debugging");
tabs->insertTab(DEVELOPER, scroll[DEVELOPER], "Developer");
tabs->insertTab(MEASUREMENT, scroll[MEASUREMENT].get(), "Measurement");
tabs->insertTab(DATAOUTPUT, scroll[DATAOUTPUT].get(), "Data Output");
tabs->insertTab(PLOT, scroll[PLOT].get(), "Plot");
tabs->insertTab(SETTINGS, scroll[SETTINGS].get(), "Settings");
tabs->insertTab(ADVANCED, scroll[ADVANCED].get(), "Advanced");
tabs->insertTab(DEBUGGING, scroll[DEBUGGING].get(), "Debugging");
tabs->insertTab(DEVELOPER, scroll[DEVELOPER].get(), "Developer");
// no scroll buttons this way
tabs->insertTab(MESSAGES, tabMessages.get(), "Terminal");
tabs->insertTab(MESSAGES, tabMessages, "Terminal");
// swap tabs so that messages is last tab
tabs->tabBar()->moveTab(tabs->indexOf(tabMeasurement.get()), MEASUREMENT);
tabs->tabBar()->moveTab(tabs->indexOf(tabSettings.get()), SETTINGS);
tabs->tabBar()->moveTab(tabs->indexOf(tabDataOutput.get()), DATAOUTPUT);
tabs->tabBar()->moveTab(tabs->indexOf(tabPlot.get()), PLOT);
tabs->tabBar()->moveTab(tabs->indexOf(tabAdvanced.get()), ADVANCED);
tabs->tabBar()->moveTab(tabs->indexOf(tabDebugging.get()), DEBUGGING);
tabs->tabBar()->moveTab(tabs->indexOf(tabDeveloper.get()), DEVELOPER);
tabs->tabBar()->moveTab(tabs->indexOf(tabMessages.get()), MESSAGES);
tabs->tabBar()->moveTab(tabs->indexOf(tabMeasurement), MEASUREMENT);
tabs->tabBar()->moveTab(tabs->indexOf(tabSettings), SETTINGS);
tabs->tabBar()->moveTab(tabs->indexOf(tabDataOutput), DATAOUTPUT);
tabs->tabBar()->moveTab(tabs->indexOf(tabPlot), PLOT);
tabs->tabBar()->moveTab(tabs->indexOf(tabAdvanced), ADVANCED);
tabs->tabBar()->moveTab(tabs->indexOf(tabDebugging), DEBUGGING);
tabs->tabBar()->moveTab(tabs->indexOf(tabDeveloper), DEVELOPER);
tabs->tabBar()->moveTab(tabs->indexOf(tabMessages), MESSAGES);
tabs->setCurrentIndex(MEASUREMENT);
// other tab properties
@ -182,12 +181,11 @@ void qDetectorMain::SetUpWidgetWindow() {
defaultTabColor = tabs->tabBar()->tabTextColor(DATAOUTPUT);
// Set the current tab(measurement) to blue as it is the current one
tabs->tabBar()->setTabTextColor(0, QColor(0, 0, 200, 255));
// increase the width so it uses all the empty space for the tab titles
tabs->tabBar()->setFixedWidth(width() + 61);
tabs->tabBar()->setExpanding(true);
// mode setup - to set up the tabs initially as disabled, not in form so
// done here
FILE_LOG(logINFO)
LOG(logINFO)
<< "Dockable Mode: 0, Debug Mode: 0, Expert Mode: 0, Developer Mode: "
<< isDeveloper;
tabs->setTabEnabled(DEBUGGING, false);
@ -208,20 +206,21 @@ void qDetectorMain::SetUpWidgetWindow() {
Initialization();
}
void qDetectorMain::SetUpDetector(const std::string fName, int multiID) {
void qDetectorMain::SetUpDetector(const std::string& config_file, int multiID) {
// instantiate detector and set window title
det = sls::make_unique<sls::Detector>(multiID);
// create messages tab to capture config file loading logs
tabMessages = sls::make_unique<qTabMessages>(this);
tabMessages = new qTabMessages(this);
// loads the config file at startup
if (!fName.empty())
LoadConfigFile(fName);
if (!config_file.empty())
LoadConfigFile(config_file);
// validate detector type (for GUI) and update menu
detType = det->getDetectorType().tsquash("Different detector type for all modules.");
detType = det->getDetectorType().tsquash(
"Different detector type for all modules.");
actionLoadTrimbits->setEnabled(false);
switch (detType) {
case slsDetectorDefs::EIGER:
@ -235,61 +234,72 @@ void qDetectorMain::SetUpDetector(const std::string fName, int multiID) {
break;
default:
std::ostringstream os;
os << det->getHostname() << " has " <<
sls::ToString(det->getDetectorType().squash()) << " detector type (" <<
std::to_string(detType) << "). Exiting GUI.";
os << det->getHostname() << " has "
<< sls::ToString(det->getDetectorType().squash())
<< " detector type (" << std::to_string(detType)
<< "). Exiting GUI.";
std::string errorMess = os.str();
throw sls::RuntimeError(errorMess.c_str());
}
std::ostringstream os;
os << "SLS Detector GUI : " << sls::ToString(det->getDetectorType().squash())
<< " - " << det->getHostname();
os << "SLS Detector GUI : "
<< sls::ToString(det->getDetectorType().squash()) << " - "
<< det->getHostname();
std::string title = os.str();
FILE_LOG(logINFO) << title;
LOG(logINFO) << title;
setWindowTitle(QString(title.c_str()));
}
void qDetectorMain::Initialization() {
// Dockable Plot
connect(dockWidgetPlot, SIGNAL(topLevelChanged(bool)), this, SLOT(ResizeMainWindow(bool)));
connect(dockWidgetPlot, SIGNAL(topLevelChanged(bool)), this,
SLOT(ResizeMainWindow(bool)));
// tabs
connect(tabs.get(),SIGNAL(currentChanged(int)), this, SLOT(Refresh(int)));//( QWidget*)));
connect(tabs, SIGNAL(currentChanged(int)), this,
SLOT(Refresh(int))); //( QWidget*)));
// Measurement tab
connect(tabMeasurement.get(), SIGNAL(EnableTabsSignal(bool)), this, SLOT(EnableTabs(bool)));
connect(tabMeasurement.get(), SIGNAL(FileNameChangedSignal(QString)), plot.get(), SLOT(SetSaveFileName(QString)));
connect(tabMeasurement, SIGNAL(EnableTabsSignal(bool)), this,
SLOT(EnableTabs(bool)));
connect(tabMeasurement, SIGNAL(FileNameChangedSignal(QString)),
plot, SLOT(SetSaveFileName(QString)));
// Plot tab
connect(tabPlot.get(), SIGNAL(DisableZoomSignal(bool)), this, SLOT(SetZoomToolTip(bool)));
connect(tabPlot, SIGNAL(DisableZoomSignal(bool)), this,
SLOT(SetZoomToolTip(bool)));
// Plotting
connect(plot.get(), SIGNAL(AcquireFinishedSignal()), tabMeasurement.get(), SLOT(AcquireFinished()));
connect(plot.get(), SIGNAL(AbortSignal()), tabMeasurement.get(), SLOT(AbortAcquire()));
connect(plot, SIGNAL(AcquireFinishedSignal()), tabMeasurement,
SLOT(AcquireFinished()));
connect(plot, SIGNAL(AbortSignal()), tabMeasurement,
SLOT(AbortAcquire()));
// menubar
// Modes Menu
connect(menuModes, SIGNAL(triggered(QAction *)), this, SLOT(EnableModes(QAction *)));
connect(menuModes, SIGNAL(triggered(QAction *)), this,
SLOT(EnableModes(QAction *)));
// Utilities Menu
connect(menuUtilities, SIGNAL(triggered(QAction *)), this, SLOT(ExecuteUtilities(QAction *)));
connect(menuUtilities, SIGNAL(triggered(QAction *)), this,
SLOT(ExecuteUtilities(QAction *)));
// Help Menu
connect(menuHelp, SIGNAL(triggered(QAction *)), this, SLOT(ExecuteHelp(QAction *)));
connect(menuHelp, SIGNAL(triggered(QAction *)), this,
SLOT(ExecuteHelp(QAction *)));
}
void qDetectorMain::LoadConfigFile(const std::string fName) {
void qDetectorMain::LoadConfigFile(const std::string& config_file) {
FILE_LOG(logINFO) << "Loading config file at start up:" << fName;
LOG(logINFO) << "Loading config file at start up:" << config_file;
struct stat st_buf;
QString file = QString(fName.c_str());
QString file = QString(config_file.c_str());
// path doesnt exist
if (stat(fName.c_str(), &st_buf)) {
if (stat(config_file.c_str(), &st_buf)) {
qDefs::Message(
qDefs::WARNING,
std::string("<nobr>Start up configuration failed to load. The "
"following file does not exist:</nobr><br><nobr>") +
fName,
config_file,
"qDetectorMain::LoadConfigFile");
FILE_LOG(logWARNING) << "Config file does not exist";
LOG(logWARNING) << "Config file does not exist";
}
// not a file
else if (!S_ISREG(st_buf.st_mode)) {
@ -298,13 +308,15 @@ void qDetectorMain::LoadConfigFile(const std::string fName) {
std::string(
"<nobr>Start up configuration failed to load. The following "
"file is not a recognized file format:</nobr><br><nobr>") +
fName,
config_file,
"qDetectorMain::LoadConfigFile");
FILE_LOG(logWARNING) << "File not recognized";
LOG(logWARNING) << "File not recognized";
} else {
try {
det->loadConfig(fName);
} CATCH_DISPLAY ("Could not load config file.", "qDetectorMain::LoadConfigFile")
det->loadConfig(config_file);
}
CATCH_DISPLAY("Could not load config file.",
"qDetectorMain::LoadConfigFile")
}
}
@ -315,8 +327,7 @@ void qDetectorMain::EnableModes(QAction *action) {
if (action == actionDebug) {
enable = actionDebug->isChecked();
tabs->setTabEnabled(DEBUGGING, enable);
FILE_LOG(logINFO) << "Debug Mode: "
<< qDefs::stringEnable(enable);
LOG(logINFO) << "Debug Mode: " << qDefs::stringEnable(enable);
}
@ -325,9 +336,9 @@ void qDetectorMain::EnableModes(QAction *action) {
enable = actionExpert->isChecked();
tabs->setTabEnabled(ADVANCED, enable);
actionLoadTrimbits->setVisible(enable && detType == slsDetectorDefs::EIGER);
FILE_LOG(logINFO) << "Expert Mode: "
<< qDefs::stringEnable(enable);
actionLoadTrimbits->setVisible(enable &&
detType == slsDetectorDefs::EIGER);
LOG(logINFO) << "Expert Mode: " << qDefs::stringEnable(enable);
}
// Set DockableMode
@ -339,8 +350,7 @@ void qDetectorMain::EnableModes(QAction *action) {
dockWidgetPlot->setFloating(false);
dockWidgetPlot->setFeatures(QDockWidget::NoDockWidgetFeatures);
}
FILE_LOG(logINFO) << "Dockable Mode: "
<< qDefs::stringEnable(enable);
LOG(logINFO) << "Dockable Mode: " << qDefs::stringEnable(enable);
}
}
@ -349,7 +359,7 @@ void qDetectorMain::ExecuteUtilities(QAction *action) {
try {
if (action == actionLoadConfiguration) {
FILE_LOG(logDEBUG) << "Loading Configuration";
LOG(logDEBUG) << "Loading Configuration";
QString fName = QString(det->getFilePath().squash("/tmp/").c_str());
fName = QFileDialog::getOpenFileName(
this, tr("Load Detector Configuration"), fName,
@ -357,19 +367,18 @@ void qDetectorMain::ExecuteUtilities(QAction *action) {
// Gets called when cancelled as well
if (!fName.isEmpty()) {
refreshTabs = true;
det->loadConfig(
std::string(fName.toAscii().constData()));
det->loadConfig(std::string(fName.toAscii().constData()));
qDefs::Message(qDefs::INFORMATION,
"The Configuration Parameters have been "
"configured successfully.",
"qDetectorMain::ExecuteUtilities");
FILE_LOG(logINFO)
LOG(logINFO)
<< "Configuration Parameters loaded successfully";
}
}
else if (action == actionLoadParameters) {
FILE_LOG(logDEBUG) << "Loading Parameters";
LOG(logDEBUG) << "Loading Parameters";
QString fName = QString(det->getFilePath().squash("/tmp/").c_str());
fName = QFileDialog::getOpenFileName(
this, tr("Load Measurement Setup"), fName,
@ -377,20 +386,19 @@ void qDetectorMain::ExecuteUtilities(QAction *action) {
// Gets called when cancelled as well
if (!fName.isEmpty()) {
refreshTabs = true;
det->loadParameters(
std::string(fName.toAscii().constData()));
det->loadParameters(std::string(fName.toAscii().constData()));
qDefs::Message(qDefs::INFORMATION,
"The Detector Parameters have been "
"configured successfully.",
"qDetectorMain::ExecuteUtilities");
FILE_LOG(logINFO)
<< "Parameters loaded successfully";
LOG(logINFO) << "Parameters loaded successfully";
}
}
else if (action == actionLoadTrimbits) {
QString fName = QString((det->getSettingsPath().squash("/tmp/")).c_str());
FILE_LOG(logDEBUG) << "Loading Trimbits";
QString fName =
QString((det->getSettingsPath().squash("/tmp/")).c_str());
LOG(logDEBUG) << "Loading Trimbits";
// so that even nonexisting files can be selected
QFileDialog *fileDialog = new QFileDialog(
this, tr("Load Detector Trimbits"), fName,
@ -401,18 +409,16 @@ void qDetectorMain::ExecuteUtilities(QAction *action) {
// Gets called when cancelled as well
if (!fName.isEmpty()) {
det->loadTrimbits(
std::string(fName.toAscii().constData()));
qDefs::Message(
qDefs::INFORMATION,
det->loadTrimbits(std::string(fName.toAscii().constData()));
qDefs::Message(qDefs::INFORMATION,
"The Trimbits have been loaded successfully.",
"qDetectorMain::ExecuteUtilities");
FILE_LOG(logINFO) << "Trimbits loaded successfully";
LOG(logINFO) << "Trimbits loaded successfully";
}
}
} CATCH_DISPLAY ("Could not execute utilities.", "qDetectorMain::ExecuteUtilities")
}
CATCH_DISPLAY("Could not execute utilities.",
"qDetectorMain::ExecuteUtilities")
Refresh(tabs->currentIndex());
if (refreshTabs) {
@ -431,13 +437,16 @@ void qDetectorMain::ExecuteUtilities(QAction *action) {
void qDetectorMain::ExecuteHelp(QAction *action) {
if (action == actionAbout) {
FILE_LOG(logINFO) << "About Common GUI for Jungfrau, Eiger, Mythen3, Gotthard, Gotthard2 and Moench detectors";
LOG(logINFO) << "About Common GUI for Jungfrau, Eiger, Mythen3, "
"Gotthard, Gotthard2 and Moench detectors";
std::string guiVersion = std::to_string(APIGUI);
std::string clientVersion = "unknown";
try {
clientVersion = std::to_string(det->getClientVersion());
} CATCH_DISPLAY ("Could not get client version.", "qDetectorMain::ExecuteHelp")
}
CATCH_DISPLAY("Could not get client version.",
"qDetectorMain::ExecuteHelp")
qDefs::Message(qDefs::INFORMATION,
"<p style=\"font-family:verdana;\">"
@ -448,7 +457,8 @@ void qDetectorMain::ExecuteHelp(QAction *action) {
clientVersion +
"<br><br>"
"Common GUI to control the SLS Detectors: "
"Jungfrau, Eiger, Mythen3, Gotthard, Gotthard2 and Moench.<br><br>"
"Jungfrau, Eiger, Mythen3, Gotthard, Gotthard2 and "
"Moench.<br><br>"
"It can be operated in parallel with the command "
"line interface:<br>"
"sls_detector_put,<br>sls_detector_get,<br>sls_"
@ -462,7 +472,7 @@ void qDetectorMain::ExecuteHelp(QAction *action) {
}
void qDetectorMain::Refresh(int index) {
FILE_LOG(logDEBUG) << "Refresh Main Tab";
LOG(logDEBUG) << "Refresh Main Tab";
if (!tabs->isTabEnabled(index))
tabs->setCurrentIndex((index++) < (tabs->count() - 1) ? index
@ -501,14 +511,14 @@ void qDetectorMain::Refresh(int index) {
}
void qDetectorMain::ResizeMainWindow(bool b) {
FILE_LOG(logDEBUG1) << "Resizing Main Window: height:" << height();
LOG(logDEBUG1) << "Resizing Main Window: height:" << height();
// undocked from the main window
if (b) {
// sets the main window height to a smaller maximum to get rid of space
setMaximumHeight(height() - heightPlotWindow - 9);
dockWidgetPlot->setMinimumHeight(0);
FILE_LOG(logINFO) << "Undocking from main window";
LOG(logINFO) << "Undocking from main window";
} else {
setMaximumHeight(QWIDGETSIZE_MAX);
// the minimum for plot will be set when the widget gets resized
@ -536,7 +546,7 @@ void qDetectorMain::resizeEvent(QResizeEvent *event) {
}
void qDetectorMain::EnableTabs(bool enable) {
FILE_LOG(logDEBUG) << "qDetectorMain::EnableTabs";
LOG(logDEBUG) << "qDetectorMain::EnableTabs";
// normal tabs
tabs->setTabEnabled(DATAOUTPUT, enable);
@ -555,7 +565,8 @@ void qDetectorMain::EnableTabs(bool enable) {
// expert
bool expertTab = enable && (actionExpert->isChecked());
tabs->setTabEnabled(ADVANCED, expertTab);
actionLoadTrimbits->setVisible(expertTab && detType == slsDetectorDefs::EIGER);
actionLoadTrimbits->setVisible(expertTab &&
detType == slsDetectorDefs::EIGER);
// moved to here, so that its all in order, instead of signals and different
// threads

412
slsDetectorGui/src/qDrawPlot.cpp Executable file → Normal file
View File

@ -1,57 +1,45 @@
#include "qDrawPlot.h"
#include "SlsQt1DPlot.h"
#include "SlsQt2DPlot.h"
#include "detectorData.h"
#include "qCloneWidget.h"
#include "detectorData.h"
#include "ToString.h"
#include "detectorData.h"
#include <QFileDialog>
#include <QPainter>
#include <QtConcurrentRun>
#include <QResizeEvent>
#include <QtConcurrentRun>
qDrawPlot::qDrawPlot(QWidget *parent, sls::Detector *detector) : QWidget(parent), det(detector) {
qDrawPlot::qDrawPlot(QWidget *parent, sls::Detector *detector)
: QWidget(parent), det(detector) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logINFO) << "Plots ready";
LOG(logINFO) << "Plots ready";
}
qDrawPlot::~qDrawPlot() {
DetachHists();
for (QVector<SlsQtH1D *>::iterator h = hists1d.begin();
h != hists1d.end(); ++h)
for (QVector<SlsQtH1D *>::iterator h = hists1d.begin(); h != hists1d.end();
++h) {
delete *h;
hists1d.clear();
}
if (datax1d)
hists1d.clear();
delete[] datax1d;
for (auto &it : datay1d)
delete[] it;
if (gainDatay1d)
delete[] gainDatay1d;
if (data2d)
delete[] data2d;
if (gainData)
delete[] gainData;
if (plot1d)
delete plot1d;
if (gainhist1d)
delete gainhist1d;
if (gainplot1d)
delete gainplot1d;
if (plot2d)
delete plot2d;
if (gainplot2d)
delete gainplot2d;
if (pedestalVals)
delete[] pedestalVals;
if (tempPedestalVals)
delete[] tempPedestalVals;
}
@ -62,15 +50,17 @@ void qDrawPlot::SetupWidgetWindow() {
pixelMask = ((1 << 14) - 1);
gainMask = (3 << 14);
gainOffset = 14;
FILE_LOG(logINFO) << "Pixel Mask: " << std::hex << pixelMask
<< ", Gain Mask:" << gainMask << ", Gain Offset:" << std::dec << gainOffset;
LOG(logINFO) << "Pixel Mask: " << std::hex << pixelMask
<< ", Gain Mask:" << gainMask
<< ", Gain Offset:" << std::dec << gainOffset;
break;
case slsDetectorDefs::GOTTHARD2:
pixelMask = ((1 << 12) - 1);
gainMask = (3 << 12);
gainOffset = 12;
FILE_LOG(logINFO) << "Pixel Mask: " << std::hex << pixelMask
<< ", Gain Mask:" << gainMask << ", Gain Offset:" << std::dec << gainOffset;
LOG(logINFO) << "Pixel Mask: " << std::hex << pixelMask
<< ", Gain Mask:" << gainMask
<< ", Gain Offset:" << std::dec << gainOffset;
break;
default:
break;
@ -82,14 +72,16 @@ void qDrawPlot::SetupWidgetWindow() {
temp = det->getFileNamePrefix().squash("xxx");
fileSaveName = QString(temp.c_str());
} catch (const std::exception &e) {
qDefs::ExceptionMessage("Could not get file path or file name.", e.what(), "qDrawPlot::SetupWidgetWindow");
qDefs::ExceptionMessage("Could not get file path or file name.",
e.what(), "qDrawPlot::SetupWidgetWindow");
fileSavePath = "/tmp";
fileSaveName = "Image";
}
SetupPlots();
SetDataCallBack(true);
det->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack), this);
det->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack),
this);
Initialization();
}
@ -115,19 +107,20 @@ void qDrawPlot::SetupPlots() {
--nPixelsX;
}
}
} CATCH_DISPLAY ("Could not get quad.", "qDrawPlot::SetupPlots")
}
CATCH_DISPLAY("Could not get quad.", "qDrawPlot::SetupPlots")
break;
default:
break;
}
FILE_LOG(logINFO) << "nPixelsX:" << nPixelsX;
FILE_LOG(logINFO) << "nPixelsY:" << nPixelsY;
LOG(logINFO) << "nPixelsX:" << nPixelsX;
LOG(logINFO) << "nPixelsY:" << nPixelsY;
boxPlot->setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
widgetStatistics->hide();
// setup 1d data
if (datax1d)
delete[] datax1d;
datax1d = new double[nPixelsX];
if (datay1d.size()) {
@ -151,7 +144,8 @@ void qDrawPlot::SetupPlots() {
// setup 1d plot
plot1d = new SlsQt1DPlot(boxPlot);
plot1d->setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
plot1d->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
plot1d->SetTitleFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
plot1d->SetXFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
plot1d->SetYFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
plot1d->SetTitle("");
@ -160,7 +154,6 @@ void qDrawPlot::SetupPlots() {
h->Attach(plot1d);
plot1d->hide();
if (gainDatay1d)
delete[] gainDatay1d;
gainDatay1d = new double[nPixelsX];
// default display data
@ -174,22 +167,26 @@ void qDrawPlot::SetupPlots() {
gainhist1d->setSymbolMarkers(isMarkers);
// setup 1d gain plot
gainplot1d = new SlsQt1DPlot(boxPlot);
gainplot1d->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
gainplot1d->SetYFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
gainplot1d->SetTitleFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
gainplot1d->SetYFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
gainplot1d->SetTitle("");
gainplot1d->SetYTitle("Gain");
// set ticks to just 3
QList<double> majorTicks({0, 1, 2, 3});
QwtScaleDiv div(0, 3, QList<double>(), QList<double>(), majorTicks);
gainplot1d->setAxisScaleDiv(QwtPlot::yLeft, div);
//gainplot1d->axisScaleDraw(QwtPlot::xBottom)->enableComponent(QwtScaleDraw::Ticks, false);
//gainplot1d->axisScaleDraw(QwtPlot::yLeft)->enableComponent(QwtScaleDraw::Labels, false);
// gainplot1d->axisScaleDraw(QwtPlot::xBottom)->enableComponent(QwtScaleDraw::Ticks,
// false);
// gainplot1d->axisScaleDraw(QwtPlot::yLeft)->enableComponent(QwtScaleDraw::Labels,
// false);
gainhist1d->setItemAttribute(QwtPlotItem::Legend, false);
gainhist1d->Attach(gainplot1d);
gainplot1d->hide();
// setup 2d data
if (data2d)
delete[] data2d;
data2d = new double[nPixelsY * nPixelsX];
for (unsigned int px = 0; px < nPixelsX; ++px)
@ -199,7 +196,7 @@ void qDrawPlot::SetupPlots() {
pow(nPixelsX / 2, 2) / pow(1 + 1, 2) +
pow(double(py) - nPixelsY / 2, 2) / pow(nPixelsY / 2, 2)) /
sqrt(2);
if (gainData)
delete[] gainData;
gainData = new double[nPixelsY * nPixelsX];
for (unsigned int px = 0; px < nPixelsX; ++px)
@ -211,10 +208,11 @@ void qDrawPlot::SetupPlots() {
sqrt(2);
// setup 2d plot
plot2d = new SlsQt2DPlot(boxPlot);
plot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY,
-0.5, nPixelsY - 0.5, data2d);
plot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5,
nPixelsY - 0.5, data2d);
plot2d->setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
plot2d->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
plot2d->SetTitleFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
plot2d->SetXFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
plot2d->SetYFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
plot2d->SetZFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
@ -224,8 +222,10 @@ void qDrawPlot::SetupPlots() {
plot2d->SetZTitle(zTitle2d);
gainplot2d = new SlsQt2DPlot(boxPlot);
gainplot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5, nPixelsY - 0.5, gainData);
gainplot2d->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
gainplot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5,
nPixelsY - 0.5, gainData);
gainplot2d->SetTitleFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
gainplot2d->setTitle("Gain");
gainplot2d->SetZTitle("");
gainplot2d->enableAxis(QwtPlot::yLeft, false);
@ -240,36 +240,32 @@ void qDrawPlot::SetupPlots() {
plotLayout->addWidget(plot1d, 0, 0, ratio, ratio);
plotLayout->addWidget(plot2d, 0, 0, ratio, ratio);
plotLayout->addWidget(gainplot1d, ratio, 0, 1, ratio, Qt::AlignTop);
plotLayout->addWidget(gainplot2d, 0, ratio, 1, 1, Qt::AlignRight | Qt::AlignTop);
plotLayout->addWidget(gainplot2d, 0, ratio, 1, 1,
Qt::AlignRight | Qt::AlignTop);
}
void qDrawPlot::resizeEvent(QResizeEvent *event) {
if (gainplot2d->isVisible()) {
gainplot2d->setFixedWidth(plot2d->width() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedWidth(plot2d->width() /
qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() /
qDefs::DATA_GAIN_PLOT_RATIO);
}
if (gainplot1d->isVisible()) {
gainplot1d->setFixedWidth(plot1d->width());
gainplot1d->setFixedHeight(plot1d->height() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot1d->setFixedHeight(plot1d->height() /
qDefs::DATA_GAIN_PLOT_RATIO);
}
event->accept();
}
bool qDrawPlot::GetIsRunning() {
return isRunning;
}
bool qDrawPlot::GetIsRunning() { return isRunning; }
void qDrawPlot::SetRunning(bool enable) {
isRunning = enable;
}
void qDrawPlot::SetRunning(bool enable) { isRunning = enable; }
int qDrawPlot::GetProgress() {
return progress;
}
int qDrawPlot::GetProgress() { return progress; }
int64_t qDrawPlot::GetCurrentFrameIndex() {
return currentFrame;
}
int64_t qDrawPlot::GetCurrentFrameIndex() { return currentFrame; }
void qDrawPlot::Select1dPlot(bool enable) {
if (enable) {
@ -291,12 +287,13 @@ void qDrawPlot::Select1dPlot(bool enable) {
}
void qDrawPlot::SetPlotTitlePrefix(QString title) {
FILE_LOG(logINFO) << "Setting Title to " << title.toAscii().constData();
LOG(logINFO) << "Setting Title to " << title.toAscii().constData();
plotTitlePrefix = title;
}
void qDrawPlot::SetXAxisTitle(QString title) {
FILE_LOG(logINFO) << "Setting X Axis Title to " << title.toAscii().constData();
LOG(logINFO) << "Setting X Axis Title to "
<< title.toAscii().constData();
if (is1d) {
xTitle1d = title;
} else {
@ -305,7 +302,8 @@ void qDrawPlot::SetXAxisTitle(QString title) {
}
void qDrawPlot::SetYAxisTitle(QString title) {
FILE_LOG(logINFO) << "Setting Y Axis Title to " << title.toAscii().constData();
LOG(logINFO) << "Setting Y Axis Title to "
<< title.toAscii().constData();
if (is1d) {
yTitle1d = title;
} else {
@ -314,18 +312,20 @@ void qDrawPlot::SetYAxisTitle(QString title) {
}
void qDrawPlot::SetZAxisTitle(QString title) {
FILE_LOG(logINFO) << "Setting Z Axis Title to " << title.toAscii().constData();
LOG(logINFO) << "Setting Z Axis Title to "
<< title.toAscii().constData();
zTitle2d = title;
}
void qDrawPlot::SetXYRangeChanged(bool disable, double *xy, bool *isXY) {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logINFO) << "XY Range has changed";
LOG(logINFO) << "XY Range has changed";
xyRangeChanged = true;
std::copy(xy, xy + 4, xyRange);
std::copy(isXY, isXY + 4, isXYRange);
FILE_LOG(logDEBUG) << "Setting Disable zoom to " << std::boolalpha << disable << std::noboolalpha;
LOG(logDEBUG) << "Setting Disable zoom to " << std::boolalpha
<< disable << std::noboolalpha;
disableZoom = disable;
}
@ -363,7 +363,8 @@ double qDrawPlot::GetYMaximum() {
}
void qDrawPlot::SetDataCallBack(bool enable) {
FILE_LOG(logINFO) << "Setting data call back to " << std::boolalpha << enable << std::noboolalpha;
LOG(logINFO) << "Setting data call back to " << std::boolalpha
<< enable << std::noboolalpha;
if (enable) {
isPlot = true;
det->setRxZmqDataStream(true);
@ -373,24 +374,25 @@ void qDrawPlot::SetDataCallBack(bool enable) {
det->setRxZmqDataStream(false);
det->registerDataCallback(nullptr, this);
}
}
void qDrawPlot::SetBinary(bool enable, int from, int to) {
FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Binary output from " << from << " to " << to;
LOG(logINFO) << (enable ? "Enabling" : "Disabling")
<< " Binary output from " << from << " to " << to;
binaryFrom = from;
binaryTo = to;
isBinary = enable;
}
void qDrawPlot::SetPersistency(int val) {
FILE_LOG(logINFO) << "Setting Persistency to " << val;
LOG(logINFO) << "Setting Persistency to " << val;
persistency = val;
}
void qDrawPlot::SetLines(bool enable) {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logINFO) << "Setting Lines to " << std::boolalpha << enable << std::noboolalpha;
LOG(logINFO) << "Setting Lines to " << std::boolalpha << enable
<< std::noboolalpha;
isLines = enable;
for (int i = 0; i < nHists; ++i) {
SlsQtH1D *h = hists1d.at(i);
@ -400,7 +402,8 @@ void qDrawPlot::SetLines(bool enable) {
void qDrawPlot::SetMarkers(bool enable) {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logINFO) << "Setting Markers to " << std::boolalpha << enable << std::noboolalpha;
LOG(logINFO) << "Setting Markers to " << std::boolalpha << enable
<< std::noboolalpha;
isMarkers = enable;
for (int i = 0; i < nHists; ++i) {
SlsQtH1D *h = hists1d.at(i);
@ -410,71 +413,77 @@ void qDrawPlot::SetMarkers(bool enable) {
void qDrawPlot::Set1dLogY(bool enable) {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logINFO) << "Setting Log Y to " << std::boolalpha << enable << std::noboolalpha;
LOG(logINFO) << "Setting Log Y to " << std::boolalpha << enable
<< std::noboolalpha;
plot1d->SetLogY(enable);
}
void qDrawPlot::SetInterpolate(bool enable) {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logINFO) << "Setting Interpolate to " << std::boolalpha << enable << std::noboolalpha;
LOG(logINFO) << "Setting Interpolate to " << std::boolalpha << enable
<< std::noboolalpha;
plot2d->SetInterpolate(enable);
}
void qDrawPlot::SetContour(bool enable) {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logINFO) << "Setting Countour to " << std::boolalpha << enable << std::noboolalpha;
LOG(logINFO) << "Setting Countour to " << std::boolalpha << enable
<< std::noboolalpha;
plot2d->SetContour(enable);
}
void qDrawPlot::SetLogz(bool enable) {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logINFO) << "Setting Log Z to " << std::boolalpha << enable << std::noboolalpha;
LOG(logINFO) << "Setting Log Z to " << std::boolalpha << enable
<< std::noboolalpha;
plot2d->SetLogz(enable, isZRange[0], isZRange[1], zRange[0], zRange[1]);
}
void qDrawPlot::SetPedestal(bool enable) {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Pedestal";
LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Pedestal";
isPedestal = enable;
resetPedestal = true;
}
void qDrawPlot::RecalculatePedestal() {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logDEBUG) << "Recalculating Pedestal";
LOG(logDEBUG) << "Recalculating Pedestal";
resetPedestal = true;
}
void qDrawPlot::SetAccumulate(bool enable) {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Accumulation";
LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Accumulation";
isAccumulate = enable;
resetAccumulate = true;
}
void qDrawPlot::ResetAccumulate() {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logDEBUG) << "Resetting Accumulation";
LOG(logDEBUG) << "Resetting Accumulation";
resetAccumulate = true;
}
void qDrawPlot::DisplayStatistics(bool enable) {
FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Statistics Display";
LOG(logINFO) << (enable ? "Enabling" : "Disabling")
<< " Statistics Display";
displayStatistics = enable;
}
void qDrawPlot::SetNumDiscardBits(int value) {
FILE_LOG(logINFO) << "Setting number of bits to discard: " << value;
LOG(logINFO) << "Setting number of bits to discard: " << value;
numDiscardBits = value;
}
void qDrawPlot::EnableGainPlot(bool enable) {
FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Gain Plot";
LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Gain Plot";
hasGainData = enable;
}
void qDrawPlot::SetSaveFileName(QString val) {
FILE_LOG(logDEBUG) << "Setting Clone/Save File Name to " << val.toAscii().constData();
LOG(logDEBUG) << "Setting Clone/Save File Name to "
<< val.toAscii().constData();
fileSaveName = val;
}
@ -487,12 +496,16 @@ void qDrawPlot::ClonePlot() {
SlsQt2DPlot *clonegainplot2D = nullptr;
if (is1d) {
FILE_LOG(logDEBUG) << "Cloning 1D Image";
LOG(logDEBUG) << "Cloning 1D Image";
cloneplot1D = new SlsQt1DPlot();
cloneplot1D->setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot1D->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot1D->SetXFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot1D->SetYFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot1D->setFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot1D->SetTitleFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot1D->SetXFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot1D->SetYFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot1D->SetTitle(plot1d->title().text());
cloneplot1D->SetXTitle(xTitle1d);
cloneplot1D->SetYTitle(yTitle1d);
@ -512,8 +525,10 @@ void qDrawPlot::ClonePlot() {
h->setSymbolMarkers(isMarkers);
h->setItemAttribute(QwtPlotItem::Legend, false);
clonegainplot1D = new SlsQt1DPlot();
clonegainplot1D->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
clonegainplot1D->SetYFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
clonegainplot1D->SetTitleFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
clonegainplot1D->SetYFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
clonegainplot1D->SetTitle("");
clonegainplot1D->SetYTitle("Gain");
// set ticks to just 3
@ -521,26 +536,32 @@ void qDrawPlot::ClonePlot() {
QwtScaleDiv div(0, 3, QList<double>(), QList<double>(), majorTicks);
clonegainplot1D->setAxisScaleDiv(QwtPlot::yLeft, div);
h->Attach(clonegainplot1D);
}
} else {
FILE_LOG(logDEBUG) << "Cloning 2D Image";
LOG(logDEBUG) << "Cloning 2D Image";
cloneplot2D = new SlsQt2DPlot();
cloneplot2D->setFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot2D->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot2D->SetXFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot2D->SetYFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot2D->SetZFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot2D->setFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot2D->SetTitleFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot2D->SetXFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot2D->SetYFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot2D->SetZFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
cloneplot2D->setTitle(plot2d->title().text());
cloneplot2D->SetXTitle(xTitle2d);
cloneplot2D->SetYTitle(yTitle2d);
cloneplot2D->SetZTitle(zTitle2d);
cloneplot2D->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5, nPixelsY - 0.5, data2d);
cloneplot2D->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5,
nPixelsY - 0.5, data2d);
cloneplot2D->SetZRange(isZRange[0], isZRange[1], zRange[0], zRange[1]);
if (isGainDataExtracted) {
clonegainplot2D = new SlsQt2DPlot();
clonegainplot2D->SetTitleFont(QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
clonegainplot2D->SetTitleFont(
QFont("Sans Serif", qDefs::Q_FONT_SIZE, QFont::Normal));
clonegainplot2D->SetTitle("Gain");
clonegainplot2D->SetZTitle("");
clonegainplot2D->enableAxis(QwtPlot::yLeft, false);
@ -553,13 +574,16 @@ void qDrawPlot::ClonePlot() {
clonegainplot2D->enableAxis(0, false);
clonegainplot2D->enableAxis(1, false);
clonegainplot2D->enableAxis(2, false);
clonegainplot2D->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5, nPixelsY - 0.5, gainData);
clonegainplot2D->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY,
-0.5, nPixelsY - 0.5, gainData);
}
}
new qCloneWidget(this, cloneplot1D, cloneplot2D, clonegainplot1D,
clonegainplot2D, boxPlot->title(), fileSavePath, fileSaveName, currentAcqIndex,
displayStatistics, lblMinDisp->text(), lblMaxDisp->text(), lblSumDisp->text());
clonegainplot2D, boxPlot->title(), fileSavePath,
fileSaveName, currentAcqIndex, displayStatistics,
lblMinDisp->text(), lblMaxDisp->text(),
lblSumDisp->text());
}
void qDrawPlot::SavePlot() {
@ -568,28 +592,33 @@ void qDrawPlot::SavePlot() {
QPainter painter(&savedImage);
render(&painter);
QString fName = fileSavePath + QString('/') +
fileSaveName +
QString('_') + (is1d ? plot1d->title().text() : plot2d->title().text()) +
QString fName = fileSavePath + QString('/') + fileSaveName + QString('_') +
(is1d ? plot1d->title().text() : plot2d->title().text()) +
QString('_') + QString("%1").arg(currentAcqIndex) +
QString(".png");
fName = QFileDialog::getSaveFileName(0, tr("Save Image"), fName, tr("PNG Files (*.png);;XPM Files(*.xpm);;JPEG Files(*.jpg)"), 0,
fName = QFileDialog::getSaveFileName(
nullptr, tr("Save Image"), fName,
tr("PNG Files (*.png);;XPM Files(*.xpm);;JPEG Files(*.jpg)"), nullptr,
QFileDialog::ShowDirsOnly);
if (!fName.isEmpty()) {
if (savedImage.save(fName)) {
qDefs::Message(qDefs::INFORMATION, "The Image has been successfully saved", "qDrawPlot::SavePlot");
qDefs::Message(qDefs::INFORMATION,
"The Image has been successfully saved",
"qDrawPlot::SavePlot");
fileSavePath = fName.section('/', 0, -2);
} else {
qDefs::Message(qDefs::WARNING, "Attempt to save image failed.\n Formats: .png, .jpg, .xpm.", "qDrawPlot::SavePlot");
qDefs::Message(
qDefs::WARNING,
"Attempt to save image failed.\n Formats: .png, .jpg, .xpm.",
"qDrawPlot::SavePlot");
}
}
}
void qDrawPlot::GetStatistics(double &min, double &max, double &sum) {
FILE_LOG(logDEBUG) << "Calculating Statistics";
LOG(logDEBUG) << "Calculating Statistics";
double *array = data2d;
int size = nPixelsX * nPixelsY;
if (is1d) {
@ -606,7 +635,8 @@ void qDrawPlot::GetStatistics(double &min, double &max, double &sum) {
}
void qDrawPlot::DetachHists() {
for (QVector<SlsQtH1D *>::iterator h = hists1d.begin(); h != hists1d.end(); ++h) {
for (QVector<SlsQtH1D *>::iterator h = hists1d.begin(); h != hists1d.end();
++h) {
(*h)->Detach(plot1d);
}
if (gainhist1d) {
@ -615,7 +645,7 @@ void qDrawPlot::DetachHists() {
}
void qDrawPlot::StartAcquisition() {
FILE_LOG(logDEBUG) << "Starting Acquisition in qDrawPlot";
LOG(logDEBUG) << "Starting Acquisition in qDrawPlot";
progress = 0;
currentFrame = 0;
boxPlot->setTitle("Old Plot");
@ -627,7 +657,9 @@ void qDrawPlot::StartAcquisition() {
if (!det->getRxZmqDataStream().squash(false)) {
det->setRxZmqDataStream(true);
}
} CATCH_DISPLAY("Could not enable data streaming in Receiver.", "qDrawPlot::StartAcquisition");
}
CATCH_DISPLAY("Could not enable data streaming in Receiver.",
"qDrawPlot::StartAcquisition");
}
// refixing all the zooming
@ -637,84 +669,107 @@ void qDrawPlot::StartAcquisition() {
}
emit StartAcquireSignal();
FILE_LOG(logDEBUG) << "End of Starting Acquisition in qDrawPlot";
LOG(logDEBUG) << "End of Starting Acquisition in qDrawPlot";
}
void qDrawPlot::AcquireThread() {
FILE_LOG(logDEBUG) << "Acquire Thread";
LOG(logDEBUG) << "Acquire Thread";
std::string mess;
try {
det->acquire();
} catch (const std::exception &e) {
mess = std::string(e.what());
}
FILE_LOG(logINFO) << "Acquisition Finished";
// exception in acquire will not call acquisition finished call back, so handle it
LOG(logINFO) << "Acquisition Finished";
// exception in acquire will not call acquisition finished call back, so
// handle it
if (!mess.empty()) {
FILE_LOG(logERROR) << "Acquisition Finished with an exception: " << mess;
qDefs::ExceptionMessage("Acquire unsuccessful.", mess, "qDrawPlot::AcquireFinished");
LOG(logERROR) << "Acquisition Finished with an exception: "
<< mess;
qDefs::ExceptionMessage("Acquire unsuccessful.", mess,
"qDrawPlot::AcquireFinished");
try {
det->stopDetector();
} CATCH_DISPLAY("Could not stop detector acquisition.", "qDrawPlot::AcquireFinished");
}
CATCH_DISPLAY("Could not stop detector acquisition.",
"qDrawPlot::AcquireFinished");
try {
det->stopReceiver();
} CATCH_DISPLAY("Could not stop receiver.", "qDrawPlot::AcquireFinished");
}
CATCH_DISPLAY("Could not stop receiver.", "qDrawPlot::AcquireFinished");
emit AbortSignal();
}
FILE_LOG(logDEBUG) << "End of Acquisition Finished";
LOG(logDEBUG) << "End of Acquisition Finished";
}
void qDrawPlot::GetAcquisitionFinishedCallBack(double currentProgress, int detectorStatus, void *this_pointer) {
((qDrawPlot *)this_pointer)->AcquisitionFinished(currentProgress, detectorStatus);
FILE_LOG(logDEBUG) << "Acquisition Finished Call back successful";
void qDrawPlot::GetAcquisitionFinishedCallBack(double currentProgress,
int detectorStatus,
void *this_pointer) {
((qDrawPlot *)this_pointer)
->AcquisitionFinished(currentProgress, detectorStatus);
LOG(logDEBUG) << "Acquisition Finished Call back successful";
}
void qDrawPlot::GetDataCallBack(detectorData *data, uint64_t frameIndex, uint32_t subFrameIndex, void *this_pointer) {
void qDrawPlot::GetDataCallBack(detectorData *data, uint64_t frameIndex,
uint32_t subFrameIndex, void *this_pointer) {
((qDrawPlot *)this_pointer)->GetData(data, frameIndex, subFrameIndex);
FILE_LOG(logDEBUG) << "Get Data Call back successful";
LOG(logDEBUG) << "Get Data Call back successful";
}
void qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus) {
void qDrawPlot::AcquisitionFinished(double currentProgress,
int detectorStatus) {
progress = currentProgress;
std::string status = sls::ToString(static_cast<slsDetectorDefs::runStatus>(detectorStatus));
std::string status =
sls::ToString(static_cast<slsDetectorDefs::runStatus>(detectorStatus));
if (detectorStatus == slsDetectorDefs::ERROR) {
qDefs::Message(qDefs::WARNING, std::string("<nobr>The acquisiton has ended abruptly. Current Detector Status: ") + status + std::string(".</nobr>"), "qDrawPlot::AcquisitionFinished");
FILE_LOG(logERROR) << "Acquisition finished [Status: ERROR]";
qDefs::Message(qDefs::WARNING,
std::string("<nobr>The acquisiton has ended abruptly. "
"Current Detector Status: ") +
status + std::string(".</nobr>"),
"qDrawPlot::AcquisitionFinished");
LOG(logERROR) << "Acquisition finished [Status: ERROR]";
} else {
FILE_LOG(logINFO) << "Acquisition finished [ Status:" << status << ", Progress: " << currentProgress << " ]" ;
LOG(logINFO) << "Acquisition finished [ Status:" << status
<< ", Progress: " << currentProgress << " ]";
}
emit AcquireFinishedSignal();
}
void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, uint32_t subFrameIndex) {
void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex,
uint32_t subFrameIndex) {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logDEBUG)
<< "* GetData Callback *" << std::endl
LOG(logDEBUG) << "* GetData Callback *" << std::endl
<< " frame index: " << frameIndex << std::endl
<< " sub frame index: " << (((int)subFrameIndex == -1) ? (int)-1 : subFrameIndex) << std::endl
<< " sub frame index: "
<< (((int)subFrameIndex == -1) ? (int)-1 : subFrameIndex)
<< std::endl
<< " Data [" << std::endl
<< " \t progress: " << data->progressIndex << std::endl
<< " \t file name: " << data->fileName << std::endl
<< " \t nx: " << data->nx << std::endl
<< " \t ny: " << data->ny << std::endl
<< " \t data bytes: " << data->databytes << std::endl
<< " \t dynamic range: " << data->dynamicRange << std::endl
<< " \t dynamic range: " << data->dynamicRange
<< std::endl
<< " \t file index: " << data->fileIndex << std::endl
<< " ]";
progress = (int)data->progressIndex;
currentAcqIndex = data->fileIndex;
currentFrame = frameIndex;
FILE_LOG(logDEBUG) << "[ Progress:" << progress << ", Frame:" << currentFrame << " ]";
LOG(logDEBUG) << "[ Progress:" << progress
<< ", Frame:" << currentFrame << " ]";
// 2d (only image, not gain data, not pedestalvals),
// check if npixelsX and npixelsY is the same (quad is different)
if (!is1d && (static_cast<int>(nPixelsX) != data->nx || static_cast<int>(nPixelsY) != data->ny)) {
if (!is1d && (static_cast<int>(nPixelsX) != data->nx ||
static_cast<int>(nPixelsY) != data->ny)) {
nPixelsX = data->nx;
nPixelsY = data->ny;
FILE_LOG(logINFO) << "Change in Detector Shape:\n\tnPixelsX:" << nPixelsX << " nPixelsY:" << nPixelsY;
if (data2d)
LOG(logINFO) << "Change in Detector Shape:\n\tnPixelsX:"
<< nPixelsX << " nPixelsY:" << nPixelsY;
delete[] data2d;
data2d = new double[nPixelsY * nPixelsX];
std::fill(data2d, data2d + nPixelsX * nPixelsY, 0);
@ -724,16 +779,18 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, uint32_t subFra
unsigned int nPixels = nPixelsX * (is1d ? 1 : nPixelsY);
double *rawData = new double[nPixels];
if (hasGainData) {
toDoublePixelData(rawData, data->data, nPixels, data->databytes, data->dynamicRange,
is1d ? gainDatay1d : gainData);
toDoublePixelData(rawData, data->data, nPixels, data->databytes,
data->dynamicRange, is1d ? gainDatay1d : gainData);
isGainDataExtracted = true;
} else {
toDoublePixelData(rawData, data->data, nPixels, data->databytes, data->dynamicRange);
toDoublePixelData(rawData, data->data, nPixels, data->databytes,
data->dynamicRange);
isGainDataExtracted = false;
}
// title and frame index titles
plotTitle = plotTitlePrefix + QString(data->fileName.c_str()).section('/', -1);
plotTitle =
plotTitlePrefix + QString(data->fileName.c_str()).section('/', -1);
indexTitle = QString("%1").arg(frameIndex);
if ((int)subFrameIndex != -1) {
indexTitle = QString("%1 %2").arg(frameIndex, subFrameIndex);
@ -742,11 +799,11 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, uint32_t subFra
// reset pedestal
if (resetPedestal) {
pedestalCount = 0;
if (pedestalVals != nullptr)
delete[] pedestalVals;
pedestalVals = new double[nPixels];
std::fill(pedestalVals, pedestalVals + nPixels, 0);
if (tempPedestalVals != nullptr)
delete[] tempPedestalVals;
tempPedestalVals = new double[nPixels];
std::fill(tempPedestalVals, tempPedestalVals + nPixels, 0);
@ -762,9 +819,11 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, uint32_t subFra
}
// calculate the pedestal value
if (pedestalCount == NUM_PEDESTAL_FRAMES) {
FILE_LOG(logINFO) << "Pedestal Calculated after " << NUM_PEDESTAL_FRAMES << " frames";
LOG(logINFO) << "Pedestal Calculated after "
<< NUM_PEDESTAL_FRAMES << " frames";
for (unsigned int px = 0; px < nPixels; ++px)
tempPedestalVals[px] = tempPedestalVals[px] / (double)NUM_PEDESTAL_FRAMES;
tempPedestalVals[px] =
tempPedestalVals[px] / (double)NUM_PEDESTAL_FRAMES;
memcpy(pedestalVals, tempPedestalVals, nPixels * sizeof(double));
pedestalCount++;
}
@ -777,7 +836,7 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, uint32_t subFra
}
delete[] rawData;
FILE_LOG(logDEBUG) << "End of Get Data";
LOG(logDEBUG) << "End of Get Data";
emit UpdateSignal();
}
@ -887,7 +946,8 @@ void qDrawPlot::Update1dPlot() {
gainhist1d->Attach(gainplot1d);
if (!gainplot1d->isVisible()) {
gainplot1d->setFixedWidth(plot1d->width());
gainplot1d->setFixedHeight(plot1d->height() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot1d->setFixedHeight(plot1d->height() /
qDefs::DATA_GAIN_PLOT_RATIO);
gainplot1d->show();
}
} else if (gainplot1d->isVisible()) {
@ -905,12 +965,16 @@ void qDrawPlot::Update2dPlot() {
plot2d->SetXTitle(xTitle2d);
plot2d->SetYTitle(yTitle2d);
plot2d->SetZTitle(zTitle2d);
plot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5, nPixelsY - 0.5, data2d);
plot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5,
nPixelsY - 0.5, data2d);
if (isGainDataExtracted) {
gainplot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5, nPixelsY - 0.5, gainData);
gainplot2d->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, -0.5,
nPixelsY - 0.5, gainData);
if (!gainplot2d->isVisible()) {
gainplot2d->setFixedWidth(plot2d->width() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() / qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedWidth(plot2d->width() /
qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->setFixedHeight(plot2d->height() /
qDefs::DATA_GAIN_PLOT_RATIO);
gainplot2d->show();
}
} else if (gainplot2d->isVisible()) {
@ -928,16 +992,20 @@ void qDrawPlot::Update1dXYRange() {
if (!isXYRange[qDefs::XMIN] && !isXYRange[qDefs::XMAX]) {
plot1d->EnableXAutoScaling();
} else {
double xmin = (isXYRange[qDefs::XMIN] ? xyRange[qDefs::XMIN] : plot1d->GetXMinimum());
double xmax = (isXYRange[qDefs::XMAX] ? xyRange[qDefs::XMAX] : plot1d->GetXMaximum());
double xmin = (isXYRange[qDefs::XMIN] ? xyRange[qDefs::XMIN]
: plot1d->GetXMinimum());
double xmax = (isXYRange[qDefs::XMAX] ? xyRange[qDefs::XMAX]
: plot1d->GetXMaximum());
plot1d->SetXMinMax(xmin, xmax);
}
if (!isXYRange[qDefs::YMIN] && !isXYRange[qDefs::YMAX]) {
plot1d->EnableYAutoScaling();
} else {
double ymin = (isXYRange[qDefs::YMIN] ? xyRange[qDefs::YMIN] : plot1d->GetYMinimum());
double ymax = (isXYRange[qDefs::YMAX] ? xyRange[qDefs::YMAX] : plot1d->GetYMaximum());
double ymin = (isXYRange[qDefs::YMIN] ? xyRange[qDefs::YMIN]
: plot1d->GetYMinimum());
double ymax = (isXYRange[qDefs::YMAX] ? xyRange[qDefs::YMAX]
: plot1d->GetYMaximum());
plot1d->SetYMinMax(ymin, ymax);
}
plot1d->Update();
@ -947,22 +1015,27 @@ void qDrawPlot::Update2dXYRange() {
if (!isXYRange[qDefs::XMIN] && !isXYRange[qDefs::XMAX]) {
plot2d->EnableXAutoScaling();
} else {
double xmin = (isXYRange[qDefs::XMIN] ? xyRange[qDefs::XMIN] : plot2d->GetXMinimum());
double xmax = (isXYRange[qDefs::XMAX] ? xyRange[qDefs::XMAX] : plot2d->GetXMaximum());
double xmin = (isXYRange[qDefs::XMIN] ? xyRange[qDefs::XMIN]
: plot2d->GetXMinimum());
double xmax = (isXYRange[qDefs::XMAX] ? xyRange[qDefs::XMAX]
: plot2d->GetXMaximum());
plot2d->SetXMinMax(xmin, xmax);
}
if (!isXYRange[qDefs::YMIN] && !isXYRange[qDefs::YMAX]) {
plot2d->EnableYAutoScaling();
} else {
double ymin = (isXYRange[qDefs::YMIN] ? xyRange[qDefs::YMIN] : plot2d->GetYMinimum());
double ymax = (isXYRange[qDefs::YMAX] ? xyRange[qDefs::YMAX] : plot2d->GetYMaximum());
double ymin = (isXYRange[qDefs::YMIN] ? xyRange[qDefs::YMIN]
: plot2d->GetYMinimum());
double ymax = (isXYRange[qDefs::YMAX] ? xyRange[qDefs::YMAX]
: plot2d->GetYMaximum());
plot2d->SetYMinMax(ymin, ymax);
}
plot2d->Update();
}
void qDrawPlot::toDoublePixelData(double *dest, char *source, int size, int databytes, int dr, double *gaindest) {
void qDrawPlot::toDoublePixelData(double *dest, char *source, int size,
int databytes, int dr, double *gaindest) {
int ichan = 0;
int ibyte = 0;
int halfbyte = 0;
@ -995,7 +1068,7 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size, int data
detType == slsDetectorDefs::GOTTHARD2) {
// show gain plot
if (gaindest != NULL) {
if (gaindest != nullptr) {
for (ichan = 0; ichan < size; ++ichan) {
uint16_t temp = (*((u_int16_t *)source));
gaindest[ichan] = ((temp & gainMask) >> gainOffset);
@ -1037,10 +1110,9 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size, int data
}
}
void qDrawPlot::UpdatePlot() {
std::lock_guard<std::mutex> lock(mPlots);
FILE_LOG(logDEBUG) << "Update Plot";
LOG(logDEBUG) << "Update Plot";
boxPlot->setTitle(plotTitle);
if (is1d) {
@ -1060,5 +1132,5 @@ void qDrawPlot::UpdatePlot() {
widgetStatistics->hide();
}
FILE_LOG(logDEBUG) << "End of Update Plot";
LOG(logDEBUG) << "End of Update Plot";
}

292
slsDetectorGui/src/qTabAdvanced.cpp Executable file → Normal file
View File

@ -1,15 +1,14 @@
#include "qTabAdvanced.h"
#include "network_utils.h"
#include "qDefs.h"
#include "qDrawPlot.h"
#include "network_utils.h"
#include <iostream>
qTabAdvanced::qTabAdvanced(QWidget *parent, sls::Detector *detector, qDrawPlot *p)
qTabAdvanced::qTabAdvanced(QWidget *parent, sls::Detector *detector,
qDrawPlot *p)
: QWidget(parent), det(detector), plot(p) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Advanced ready";
LOG(logDEBUG) << "Advanced ready";
}
qTabAdvanced::~qTabAdvanced() {}
@ -88,7 +87,8 @@ void qTabAdvanced::Initialization() {
// roi
if (tab_roi->isEnabled()) {
connect(comboReadout, SIGNAL(currentIndexChanged(int)), this, SLOT(GetROI()));
connect(comboReadout, SIGNAL(currentIndexChanged(int)), this,
SLOT(GetROI()));
connect(btnSetRoi, SIGNAL(clicked()), this, SLOT(SetROI()));
connect(btnClearRoi, SIGNAL(clicked()), this, SLOT(ClearROI()));
}
@ -119,10 +119,11 @@ void qTabAdvanced::Initialization() {
}
void qTabAdvanced::PopulateDetectors() {
FILE_LOG(logDEBUG) << "Populating detectors";
LOG(logDEBUG) << "Populating detectors";
disconnect(comboDetector, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetDetector()));
disconnect(comboReadout, SIGNAL(currentIndexChanged(int)), this, SLOT(GetROI()));
disconnect(comboReadout, SIGNAL(currentIndexChanged(int)), this,
SLOT(GetROI()));
comboDetector->clear();
comboReadout->clear();
@ -136,193 +137,219 @@ void qTabAdvanced::PopulateDetectors() {
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetDetector()));
connect(comboReadout, SIGNAL(currentIndexChanged(int)), this, SLOT(GetROI()));
connect(comboReadout, SIGNAL(currentIndexChanged(int)), this,
SLOT(GetROI()));
}
void qTabAdvanced::GetControlPort() {
FILE_LOG(logDEBUG) << "Getting control port ";
LOG(logDEBUG) << "Getting control port ";
disconnect(spinControlPort, SIGNAL(valueChanged(int)), this,
SLOT(SetControlPort(int)));
try {
int retval = det->getControlPort({comboDetector->currentIndex()})[0];
spinControlPort->setValue(retval);
} CATCH_DISPLAY ("Could not get detector control port.", "qTabAdvanced::GetControlPort")
}
CATCH_DISPLAY("Could not get detector control port.",
"qTabAdvanced::GetControlPort")
connect(spinControlPort, SIGNAL(valueChanged(int)), this,
SLOT(SetControlPort(int)));
}
void qTabAdvanced::GetStopPort() {
FILE_LOG(logDEBUG) << "Getting stop port";
LOG(logDEBUG) << "Getting stop port";
disconnect(spinStopPort, SIGNAL(valueChanged(int)), this,
SLOT(SetStopPort(int)));
try {
int retval = det->getStopPort({comboDetector->currentIndex()})[0];
spinStopPort->setValue(retval);
} CATCH_DISPLAY ("Could not get detector stop port.", "qTabAdvanced::GetStopPort")
}
CATCH_DISPLAY("Could not get detector stop port.",
"qTabAdvanced::GetStopPort")
connect(spinStopPort, SIGNAL(valueChanged(int)), this,
SLOT(SetStopPort(int)));
}
void qTabAdvanced::GetDetectorUDPIP() {
FILE_LOG(logDEBUG) << "Getting Detector UDP IP";
LOG(logDEBUG) << "Getting Detector UDP IP";
disconnect(dispDetectorUDPIP, SIGNAL(editingFinished()), this,
SLOT(SetDetectorUDPIP()));
try {
auto retval = det->getSourceUDPIP({comboDetector->currentIndex()})[0].str();
auto retval =
det->getSourceUDPIP({comboDetector->currentIndex()})[0].str();
dispDetectorUDPIP->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get detector UDP IP.", "qTabAdvanced::GetDetectorUDPIP")
}
CATCH_DISPLAY("Could not get detector UDP IP.",
"qTabAdvanced::GetDetectorUDPIP")
connect(dispDetectorUDPIP, SIGNAL(editingFinished()), this,
SLOT(SetDetectorUDPIP()));
}
void qTabAdvanced::GetDetectorUDPMAC() {
FILE_LOG(logDEBUG) << "Getting Detector UDP MAC";
LOG(logDEBUG) << "Getting Detector UDP MAC";
disconnect(dispDetectorUDPMAC, SIGNAL(editingFinished()), this,
SLOT(SetDetectorUDPMAC()));
try {
auto retval = det->getSourceUDPMAC({comboDetector->currentIndex()})[0].str();
auto retval =
det->getSourceUDPMAC({comboDetector->currentIndex()})[0].str();
dispDetectorUDPMAC->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get detector UDP MAC.", "qTabAdvanced::GetDetectorUDPMAC")
}
CATCH_DISPLAY("Could not get detector UDP MAC.",
"qTabAdvanced::GetDetectorUDPMAC")
connect(dispDetectorUDPMAC, SIGNAL(editingFinished()), this,
SLOT(SetDetectorUDPMAC()));
}
void qTabAdvanced::GetCltZMQPort() {
FILE_LOG(logDEBUG) << "Getting Client ZMQ port";
LOG(logDEBUG) << "Getting Client ZMQ port";
disconnect(spinZMQPort, SIGNAL(valueChanged(int)), this,
SLOT(SetCltZMQPort(int)));
try {
int retval =
det->getClientZmqPort({comboDetector->currentIndex()})[0];
int retval = det->getClientZmqPort({comboDetector->currentIndex()})[0];
spinZMQPort->setValue(retval);
} CATCH_DISPLAY ("Could not get client zmq port.", "qTabAdvanced::GetCltZMQPort")
}
CATCH_DISPLAY("Could not get client zmq port.",
"qTabAdvanced::GetCltZMQPort")
connect(spinZMQPort, SIGNAL(valueChanged(int)), this,
SLOT(SetCltZMQPort(int)));
}
void qTabAdvanced::GetCltZMQIP() {
FILE_LOG(logDEBUG) << "Getting Client ZMQ IP";
LOG(logDEBUG) << "Getting Client ZMQ IP";
disconnect(dispZMQIP, SIGNAL(editingFinished()), this, SLOT(SetCltZMQIP()));
try {
auto retval =
det->getClientZmqIp({comboDetector->currentIndex()})[0].str();
dispZMQIP->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get client zmq ip.", "qTabAdvanced::GetCltZMQIP")
}
CATCH_DISPLAY("Could not get client zmq ip.", "qTabAdvanced::GetCltZMQIP")
connect(dispZMQIP, SIGNAL(editingFinished()), this, SLOT(SetCltZMQIP()));
}
void qTabAdvanced::GetRxrHostname() {
FILE_LOG(logDEBUG) << "Getting Receiver Hostname";
LOG(logDEBUG) << "Getting Receiver Hostname";
disconnect(dispRxrHostname, SIGNAL(editingFinished()), this,
SLOT(SetRxrHostname()));
try {
auto retval = det->getRxHostname({comboDetector->currentIndex()})[0];
dispRxrHostname->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get receiver hostname.", "qTabAdvanced::GetRxrHostname")
}
CATCH_DISPLAY("Could not get receiver hostname.",
"qTabAdvanced::GetRxrHostname")
connect(dispRxrHostname, SIGNAL(editingFinished()), this,
SLOT(SetRxrHostname()));
}
void qTabAdvanced::GetRxrTCPPort() {
FILE_LOG(logDEBUG) << "Getting Receiver TCP port";
LOG(logDEBUG) << "Getting Receiver TCP port";
disconnect(spinRxrTCPPort, SIGNAL(valueChanged(int)), this,
SLOT(SetRxrTCPPort(int)));
try {
int retval = det->getRxPort({comboDetector->currentIndex()})[0];
spinRxrTCPPort->setValue(retval);
} CATCH_DISPLAY ("Could not get receiver tcp port.", "qTabAdvanced::GetRxrTCPPort")
}
CATCH_DISPLAY("Could not get receiver tcp port.",
"qTabAdvanced::GetRxrTCPPort")
connect(spinRxrTCPPort, SIGNAL(valueChanged(int)), this,
SLOT(SetRxrTCPPort(int)));
}
void qTabAdvanced::GetRxrUDPPort() {
FILE_LOG(logDEBUG) << "Getting Receiver UDP port";
LOG(logDEBUG) << "Getting Receiver UDP port";
disconnect(spinRxrUDPPort, SIGNAL(valueChanged(int)), this,
SLOT(SetRxrUDPPort(int)));
try {
int retval = det->getDestinationUDPPort({comboDetector->currentIndex()})[0];
int retval =
det->getDestinationUDPPort({comboDetector->currentIndex()})[0];
spinRxrUDPPort->setValue(retval);
} CATCH_DISPLAY ("Could not get receiver udp port.", "qTabAdvanced::GetRxrUDPPort")
}
CATCH_DISPLAY("Could not get receiver udp port.",
"qTabAdvanced::GetRxrUDPPort")
connect(spinRxrUDPPort, SIGNAL(valueChanged(int)), this,
SLOT(SetRxrUDPPort(int)));
}
void qTabAdvanced::GetRxrUDPIP() {
FILE_LOG(logDEBUG) << "Getting Receiver UDP IP";
LOG(logDEBUG) << "Getting Receiver UDP IP";
disconnect(dispRxrUDPIP, SIGNAL(editingFinished()), this,
SLOT(SetRxrUDPIP()));
try {
auto retval = det->getDestinationUDPIP({comboDetector->currentIndex()})[0].str();
auto retval =
det->getDestinationUDPIP({comboDetector->currentIndex()})[0].str();
dispRxrUDPIP->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get receiver udp ip.", "qTabAdvanced::GetRxrUDPIP")
}
CATCH_DISPLAY("Could not get receiver udp ip.", "qTabAdvanced::GetRxrUDPIP")
connect(dispRxrUDPIP, SIGNAL(editingFinished()), this, SLOT(SetRxrUDPIP()));
}
void qTabAdvanced::GetRxrUDPMAC() {
FILE_LOG(logDEBUG) << "Getting Receiver UDP MAC";
LOG(logDEBUG) << "Getting Receiver UDP MAC";
disconnect(dispRxrUDPMAC, SIGNAL(editingFinished()), this,
SLOT(SetRxrUDPMAC()));
try {
auto retval = det->getDestinationUDPMAC({comboDetector->currentIndex()})[0].str();
auto retval =
det->getDestinationUDPMAC({comboDetector->currentIndex()})[0].str();
dispRxrUDPMAC->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get receiver udp mac.", "qTabAdvanced::GetRxrUDPMAC")
}
CATCH_DISPLAY("Could not get receiver udp mac.",
"qTabAdvanced::GetRxrUDPMAC")
connect(dispRxrUDPMAC, SIGNAL(editingFinished()), this,
SLOT(SetRxrUDPMAC()));
}
void qTabAdvanced::GetRxrZMQPort() {
FILE_LOG(logDEBUG) << "Getting Receiver ZMQ port";
LOG(logDEBUG) << "Getting Receiver ZMQ port";
disconnect(spinRxrZMQPort, SIGNAL(valueChanged(int)), this,
SLOT(SetRxrZMQPort(int)));
try {
int retval =
det->getRxZmqPort({comboDetector->currentIndex()})[0];
int retval = det->getRxZmqPort({comboDetector->currentIndex()})[0];
spinRxrZMQPort->setValue(retval);
} CATCH_DISPLAY ("Could not get receiver zmq port.", "qTabAdvanced::GetRxrZMQPort")
}
CATCH_DISPLAY("Could not get receiver zmq port.",
"qTabAdvanced::GetRxrZMQPort")
connect(spinRxrZMQPort, SIGNAL(valueChanged(int)), this,
SLOT(SetRxrZMQPort(int)));
}
void qTabAdvanced::GetRxrZMQIP() {
FILE_LOG(logDEBUG) << "Getting Receiver ZMQ IP";
LOG(logDEBUG) << "Getting Receiver ZMQ IP";
disconnect(dispRxrZMQIP, SIGNAL(editingFinished()), this,
SLOT(SetRxrZMQIP()));
try {
auto retval =
det->getRxZmqIP({comboDetector->currentIndex()})[0].str();
auto retval = det->getRxZmqIP({comboDetector->currentIndex()})[0].str();
dispRxrZMQIP->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get receiver zmq ip.", "qTabAdvanced::GetRxrZMQIP")
}
CATCH_DISPLAY("Could not get receiver zmq ip.", "qTabAdvanced::GetRxrZMQIP")
connect(dispRxrZMQIP, SIGNAL(editingFinished()), this, SLOT(SetRxrZMQIP()));
}
void qTabAdvanced::SetDetector() {
FILE_LOG(logDEBUG) << "Set Detector: "
LOG(logDEBUG) << "Set Detector: "
<< comboDetector->currentText().toAscii().data();
GetControlPort();
@ -339,149 +366,162 @@ void qTabAdvanced::SetDetector() {
GetRxrZMQPort();
GetRxrZMQIP();
FILE_LOG(logDEBUG) << det->printRxConfiguration();
LOG(logDEBUG) << det->printRxConfiguration();
}
void qTabAdvanced::SetControlPort(int port) {
FILE_LOG(logINFO) << "Setting Control Port:" << port;
LOG(logINFO) << "Setting Control Port:" << port;
try {
det->setControlPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE("Could not set control port.", "qTabAdvanced::SetControlPort",
}
CATCH_HANDLE("Could not set control port.", "qTabAdvanced::SetControlPort",
this, &qTabAdvanced::GetControlPort)
}
void qTabAdvanced::SetStopPort(int port) {
FILE_LOG(logINFO) << "Setting Stop Port:" << port;
LOG(logINFO) << "Setting Stop Port:" << port;
try {
det->setStopPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set stop port.", "qTabAdvanced::SetStopPort", this,
}
CATCH_HANDLE("Could not set stop port.", "qTabAdvanced::SetStopPort", this,
&qTabAdvanced::GetStopPort)
}
void qTabAdvanced::SetDetectorUDPIP() {
std::string s = dispDetectorUDPIP->text().toAscii().constData();
FILE_LOG(logINFO) << "Setting Detector UDP IP:" << s;
LOG(logINFO) << "Setting Detector UDP IP:" << s;
try {
det->setSourceUDPIP(sls::IpAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Detector UDP IP.",
}
CATCH_HANDLE("Could not set Detector UDP IP.",
"qTabAdvanced::SetDetectorUDPIP", this,
&qTabAdvanced::GetDetectorUDPIP)
}
void qTabAdvanced::SetDetectorUDPMAC() {
std::string s = dispDetectorUDPMAC->text().toAscii().constData();
FILE_LOG(logINFO) << "Setting Detector UDP MAC:" << s;
LOG(logINFO) << "Setting Detector UDP MAC:" << s;
try {
det->setSourceUDPMAC(sls::MacAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Detector UDP MAC.",
}
CATCH_HANDLE("Could not set Detector UDP MAC.",
"qTabAdvanced::SetDetectorUDPMAC", this,
&qTabAdvanced::GetDetectorUDPMAC)
}
void qTabAdvanced::SetCltZMQPort(int port) {
FILE_LOG(logINFO) << "Setting Client ZMQ Port:" << port;
LOG(logINFO) << "Setting Client ZMQ Port:" << port;
try {
det->setClientZmqPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Client ZMQ port.",
}
CATCH_HANDLE("Could not set Client ZMQ port.",
"qTabAdvanced::SetCltZMQPort", this,
&qTabAdvanced::GetCltZMQPort)
}
void qTabAdvanced::SetCltZMQIP() {
std::string s = dispZMQIP->text().toAscii().constData();
FILE_LOG(logINFO) << "Setting Client ZMQ IP:" << s;
LOG(logINFO) << "Setting Client ZMQ IP:" << s;
try {
det->setClientZmqIp(sls::IpAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Client ZMQ IP.",
"qTabAdvanced::SetCltZMQIP", this,
&qTabAdvanced::GetCltZMQIP)
}
CATCH_HANDLE("Could not set Client ZMQ IP.", "qTabAdvanced::SetCltZMQIP",
this, &qTabAdvanced::GetCltZMQIP)
}
void qTabAdvanced::SetRxrHostname() {
std::string s = dispZMQIP->text().toAscii().constData();
FILE_LOG(logINFO) << "Setting Receiver Hostname:" << s;
LOG(logINFO) << "Setting Receiver Hostname:" << s;
try {
det->setRxHostname(s, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Client ZMQ IP.",
"qTabAdvanced::SetRxrHostname", this,
&qTabAdvanced::GetRxrHostname)
}
CATCH_HANDLE("Could not set Client ZMQ IP.", "qTabAdvanced::SetRxrHostname",
this, &qTabAdvanced::GetRxrHostname)
// update all network widgets (receiver mainly)
SetDetector();
}
void qTabAdvanced::SetRxrTCPPort(int port) {
FILE_LOG(logINFO) << "Setting Receiver TCP Port:" << port;
LOG(logINFO) << "Setting Receiver TCP Port:" << port;
try {
det->setRxPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver TCP port.",
}
CATCH_HANDLE("Could not set Receiver TCP port.",
"qTabAdvanced::SetRxrTCPPort", this,
&qTabAdvanced::GetRxrTCPPort)
}
void qTabAdvanced::SetRxrUDPPort(int port) {
FILE_LOG(logINFO) << "Setting Receiver UDP Port:" << port;
LOG(logINFO) << "Setting Receiver UDP Port:" << port;
try {
det->setRxPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver UDP port.",
}
CATCH_HANDLE("Could not set Receiver UDP port.",
"qTabAdvanced::SetRxrUDPPort", this,
&qTabAdvanced::GetRxrUDPPort)
}
void qTabAdvanced::SetRxrUDPIP() {
std::string s = dispRxrUDPIP->text().toAscii().constData();
FILE_LOG(logINFO) << "Setting Receiver UDP IP:" << s;
LOG(logINFO) << "Setting Receiver UDP IP:" << s;
try {
det->setDestinationUDPIP(sls::IpAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver UDP IP.",
"qTabAdvanced::SetRxrUDPIP", this,
&qTabAdvanced::GetRxrUDPIP)
det->setDestinationUDPIP(sls::IpAddr{s},
{comboDetector->currentIndex()});
}
CATCH_HANDLE("Could not set Receiver UDP IP.", "qTabAdvanced::SetRxrUDPIP",
this, &qTabAdvanced::GetRxrUDPIP)
}
void qTabAdvanced::SetRxrUDPMAC() {
std::string s = dispRxrUDPMAC->text().toAscii().constData();
FILE_LOG(logINFO) << "Setting Receiver UDP MAC:" << s;
LOG(logINFO) << "Setting Receiver UDP MAC:" << s;
try {
det->setDestinationUDPMAC(sls::MacAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver UDP MAC.",
det->setDestinationUDPMAC(sls::MacAddr{s},
{comboDetector->currentIndex()});
}
CATCH_HANDLE("Could not set Receiver UDP MAC.",
"qTabAdvanced::SetRxrUDPMAC", this,
&qTabAdvanced::GetRxrUDPMAC)
}
void qTabAdvanced::SetRxrZMQPort(int port) {
FILE_LOG(logINFO) << "Setting Receiver ZMQ Port:" << port;
LOG(logINFO) << "Setting Receiver ZMQ Port:" << port;
try {
det->setRxZmqPort(port, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver ZMQ port.",
}
CATCH_HANDLE("Could not set Receiver ZMQ port.",
"qTabAdvanced::SetRxrZMQPort", this,
&qTabAdvanced::GetRxrZMQPort)
}
void qTabAdvanced::SetRxrZMQIP() {
std::string s = dispRxrZMQIP->text().toAscii().constData();
FILE_LOG(logINFO) << "Setting Receiver ZMQ IP:" << s;
LOG(logINFO) << "Setting Receiver ZMQ IP:" << s;
try {
det->setRxZmqIP(sls::IpAddr{s}, {comboDetector->currentIndex()});
} CATCH_HANDLE ("Could not set Receiver ZMQ IP.",
"qTabAdvanced::SetRxrZMQIP", this,
&qTabAdvanced::GetRxrZMQIP)
}
CATCH_HANDLE("Could not set Receiver ZMQ IP.", "qTabAdvanced::SetRxrZMQIP",
this, &qTabAdvanced::GetRxrZMQIP)
}
void qTabAdvanced::GetROI() {
FILE_LOG(logDEBUG) << "Getting ROI";
LOG(logDEBUG) << "Getting ROI";
try {
slsDetectorDefs::ROI roi = det->getROI({comboReadout->currentIndex()})[0];
slsDetectorDefs::ROI roi =
det->getROI({comboReadout->currentIndex()})[0];
spinXmin->setValue(roi.xmin);
spinXmax->setValue(roi.xmax);
} CATCH_DISPLAY ("Could not get ROI.", "qTabAdvanced::GetROI")
}
CATCH_DISPLAY("Could not get ROI.", "qTabAdvanced::GetROI")
}
void qTabAdvanced::ClearROI() {
FILE_LOG(logINFO) << "Clearing ROI";
LOG(logINFO) << "Clearing ROI";
spinXmin->setValue(-1);
spinXmax->setValue(-1);
SetROI();
FILE_LOG(logDEBUG) << "ROIs cleared";
LOG(logDEBUG) << "ROIs cleared";
}
void qTabAdvanced::SetROI() {
@ -491,25 +531,27 @@ void qTabAdvanced::SetROI() {
roi.xmax = spinXmax->value();
// set roi
FILE_LOG(logINFO) << "Setting ROI: [" << roi.xmin << ", " << roi.xmax << "]";
LOG(logINFO) << "Setting ROI: [" << roi.xmin << ", " << roi.xmax
<< "]";
try {
det->setROI(roi, {comboReadout->currentIndex()});
} CATCH_DISPLAY ("Could not set these ROIs.",
"qTabAdvanced::SetROI")
}
CATCH_DISPLAY("Could not set these ROIs.", "qTabAdvanced::SetROI")
// update corrected list
GetROI();
}
void qTabAdvanced::GetAllTrimbits() {
FILE_LOG(logDEBUG) << "Getting all trimbits value";
LOG(logDEBUG) << "Getting all trimbits value";
disconnect(spinSetAllTrimbits, SIGNAL(editingFinished()), this,
SLOT(SetAllTrimbits()));
try {
int retval = det->getAllTrimbits().squash(-1);
spinSetAllTrimbits->setValue(retval);
} CATCH_DISPLAY ("Could not get all trimbits.", "qTabAdvanced::GetAllTrimbits")
}
CATCH_DISPLAY("Could not get all trimbits.", "qTabAdvanced::GetAllTrimbits")
connect(spinSetAllTrimbits, SIGNAL(editingFinished()), this,
SLOT(SetAllTrimbits()));
@ -517,24 +559,26 @@ void qTabAdvanced::GetAllTrimbits() {
void qTabAdvanced::SetAllTrimbits() {
int value = spinSetAllTrimbits->value();
FILE_LOG(logINFO) << "Setting all trimbits:" << value;
LOG(logINFO) << "Setting all trimbits:" << value;
try {
det->setAllTrimbits(value);
} CATCH_HANDLE("Could not set all trimbits.", "qTabAdvanced::SetAllTrimbits",
}
CATCH_HANDLE("Could not set all trimbits.", "qTabAdvanced::SetAllTrimbits",
this, &qTabAdvanced::GetAllTrimbits)
}
void qTabAdvanced::GetNumStoragecells() {
FILE_LOG(logDEBUG) << "Getting number of additional storage cells";
LOG(logDEBUG) << "Getting number of additional storage cells";
disconnect(spinNumStoragecells, SIGNAL(valueChanged(int)), this,
SLOT(SetNumStoragecells(int)));
try {
auto retval = det->getNumberOfAdditionalStorageCells().tsquash("Inconsistent values for number of addditional storage cells.");
auto retval = det->getNumberOfAdditionalStorageCells().tsquash(
"Inconsistent values for number of addditional storage cells.");
spinNumStoragecells->setValue(retval);
} CATCH_DISPLAY (
"Could not get number of additional storage cells.",
}
CATCH_DISPLAY("Could not get number of additional storage cells.",
"qTabAdvanced::GetNumStoragecells")
connect(spinNumStoragecells, SIGNAL(valueChanged(int)), this,
@ -542,29 +586,30 @@ void qTabAdvanced::GetNumStoragecells() {
}
void qTabAdvanced::SetNumStoragecells(int value) {
FILE_LOG(logINFO) << "Setting number of additional stoarge cells: "
LOG(logINFO) << "Setting number of additional stoarge cells: "
<< value;
try {
det->setNumberOfAdditionalStorageCells(value);
} CATCH_HANDLE (
"Could not set number of additional storage cells.",
}
CATCH_HANDLE("Could not set number of additional storage cells.",
"qTabAdvanced::SetNumStoragecells", this,
&qTabAdvanced::GetNumStoragecells)
}
void qTabAdvanced::GetSubExposureTime() {
FILE_LOG(logDEBUG) << "Getting sub exposure time";
LOG(logDEBUG) << "Getting sub exposure time";
disconnect(spinSubExpTime, SIGNAL(valueChanged(double)), this,
SLOT(SetSubExposureTime()));
disconnect(comboSubExpTimeUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSubExposureTime()));
try {
auto retval =
det->getSubExptime().tsquash("Subexptime is inconsistent for all detectors.");
auto retval = det->getSubExptime().tsquash(
"Subexptime is inconsistent for all detectors.");
auto time = qDefs::getUserFriendlyTime(retval);
spinSubExpTime->setValue(time.first);
comboSubExpTimeUnit->setCurrentIndex(static_cast<int>(time.second));
} CATCH_DISPLAY ("Could not get sub exposure time.",
}
CATCH_DISPLAY("Could not get sub exposure time.",
"qTabSettings::GetSubExposureTime")
connect(spinSubExpTime, SIGNAL(valueChanged(double)), this,
SLOT(SetSubExposureTime()));
@ -573,33 +618,37 @@ void qTabAdvanced::GetSubExposureTime() {
}
void qTabAdvanced::SetSubExposureTime() {
auto timeNS = qDefs::getNSTime(std::make_pair(spinSubExpTime->value(), static_cast<qDefs::timeUnit>(comboSubExpTimeUnit->currentIndex())));
FILE_LOG(logINFO)
auto timeNS = qDefs::getNSTime(std::make_pair(
spinSubExpTime->value(),
static_cast<qDefs::timeUnit>(comboSubExpTimeUnit->currentIndex())));
LOG(logINFO)
<< "Setting sub frame acquisition time to " << timeNS.count() << " ns"
<< "/" << spinSubExpTime->value()
<< qDefs::getUnitString(
(qDefs::timeUnit)comboSubExpTimeUnit->currentIndex());
try {
det->setSubExptime(timeNS);
} CATCH_DISPLAY ("Could not set sub exposure time.",
}
CATCH_DISPLAY("Could not set sub exposure time.",
"qTabAdvanced::SetSubExposureTime")
GetSubExposureTime();
}
void qTabAdvanced::GetSubDeadTime() {
FILE_LOG(logDEBUG) << "Getting sub dead time";
LOG(logDEBUG) << "Getting sub dead time";
disconnect(spinSubDeadTime, SIGNAL(valueChanged(double)), this,
SLOT(SetSubDeadTime()));
disconnect(comboSubDeadTimeUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSubDeadTime()));
try {
auto retval = det->getSubDeadTime().tsquash("Sub dead time is inconsistent for all detectors.");
auto retval = det->getSubDeadTime().tsquash(
"Sub dead time is inconsistent for all detectors.");
auto time = qDefs::getUserFriendlyTime(retval);
spinSubDeadTime->setValue(time.first);
comboSubDeadTimeUnit->setCurrentIndex(
static_cast<int>(time.second));
} CATCH_DISPLAY ("Could not get sub dead time.",
comboSubDeadTimeUnit->setCurrentIndex(static_cast<int>(time.second));
}
CATCH_DISPLAY("Could not get sub dead time.",
"qTabSettings::GetSubDeadTime")
connect(spinSubDeadTime, SIGNAL(valueChanged(double)), this,
SLOT(SetSubDeadTime()));
@ -608,22 +657,25 @@ void qTabAdvanced::GetSubDeadTime() {
}
void qTabAdvanced::SetSubDeadTime() {
auto timeNS = qDefs::getNSTime(std::make_pair(spinSubDeadTime->value(), static_cast<qDefs::timeUnit>(comboSubDeadTimeUnit->currentIndex())));
auto timeNS = qDefs::getNSTime(std::make_pair(
spinSubDeadTime->value(),
static_cast<qDefs::timeUnit>(comboSubDeadTimeUnit->currentIndex())));
FILE_LOG(logINFO)
LOG(logINFO)
<< "Setting sub frame dead time to " << timeNS.count() << " ns"
<< "/" << spinSubDeadTime->value()
<< qDefs::getUnitString(
(qDefs::timeUnit)comboSubDeadTimeUnit->currentIndex());
try {
det->setSubDeadTime(timeNS);
} CATCH_DISPLAY ("Could not set sub dead time.",
}
CATCH_DISPLAY("Could not set sub dead time.",
"qTabAdvanced::SetSubDeadTime")
GetSubDeadTime();
}
void qTabAdvanced::Refresh() {
FILE_LOG(logDEBUG) << "**Updating Advanced Tab";
LOG(logDEBUG) << "**Updating Advanced Tab";
// trimming
if (tab_trimming->isEnabled()) {
@ -649,5 +701,5 @@ void qTabAdvanced::Refresh() {
GetSubDeadTime();
}
FILE_LOG(logDEBUG) << "**Updated Advanced Tab";
LOG(logDEBUG) << "**Updated Advanced Tab";
}

276
slsDetectorGui/src/qTabDataOutput.cpp Executable file → Normal file
View File

@ -1,25 +1,22 @@
#include "qTabDataOutput.h"
#include "qDefs.h"
#include <QButtonGroup>
#include <QFileDialog>
#include <QStandardItemModel>
#include <QButtonGroup>
#include <QString>
#include <iostream>
#include <string>
#include <unistd.h>
qTabDataOutput::qTabDataOutput(QWidget *parent, sls::Detector *detector) : QWidget(parent), det(detector), btnGroupRate(nullptr) {
qTabDataOutput::qTabDataOutput(QWidget *parent, sls::Detector *detector)
: QWidget(parent), det(detector), btnGroupRate(nullptr) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "DataOutput ready";
LOG(logDEBUG) << "DataOutput ready";
}
qTabDataOutput::~qTabDataOutput() {
if (btnGroupRate)
delete btnGroupRate;
}
qTabDataOutput::~qTabDataOutput() { delete btnGroupRate; }
void qTabDataOutput::SetupWidgetWindow() {
// button group for rate
@ -53,29 +50,39 @@ void qTabDataOutput::SetupWidgetWindow() {
void qTabDataOutput::Initialization() {
// ourdir, fileformat, overwrite enable
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this, SLOT(GetOutputDir()));
connect(dispOutputDir, SIGNAL(editingFinished()), this, SLOT(SetOutputDir()));
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this,
SLOT(GetOutputDir()));
connect(dispOutputDir, SIGNAL(editingFinished()), this,
SLOT(SetOutputDir()));
connect(btnOutputBrowse, SIGNAL(clicked()), this, SLOT(BrowseOutputDir()));
connect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFileFormat(int)));
connect(chkOverwriteEnable, SIGNAL(toggled(bool)), this, SLOT(SetOverwriteEnable(bool)));
connect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFileFormat(int)));
connect(chkOverwriteEnable, SIGNAL(toggled(bool)), this,
SLOT(SetOverwriteEnable(bool)));
if (chkTenGiga->isEnabled()) {
connect(chkTenGiga, SIGNAL(toggled(bool)), this, SLOT(SetTenGigaEnable(bool)));
connect(chkTenGiga, SIGNAL(toggled(bool)), this,
SLOT(SetTenGigaEnable(bool)));
}
// rate
if (chkRate->isEnabled()) {
connect(chkRate, SIGNAL(toggled(bool)), this, SLOT(EnableRateCorrection()));
connect(btnGroupRate, SIGNAL(buttonClicked(int)), this, SLOT(SetRateCorrection()));
connect(spinCustomDeadTime, SIGNAL(editingFinished()), this, SLOT(SetRateCorrection()));
connect(chkRate, SIGNAL(toggled(bool)), this,
SLOT(EnableRateCorrection()));
connect(btnGroupRate, SIGNAL(buttonClicked(int)), this,
SLOT(SetRateCorrection()));
connect(spinCustomDeadTime, SIGNAL(editingFinished()), this,
SLOT(SetRateCorrection()));
}
// flags, speed
if (widgetEiger->isEnabled()) {
connect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSpeed(int)));
connect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFlags()));
connect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSpeed(int)));
connect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFlags()));
}
}
void qTabDataOutput::PopulateDetectors() {
FILE_LOG(logDEBUG) << "Populating detectors";
LOG(logDEBUG) << "Populating detectors";
comboDetector->clear();
comboDetector->addItem("All");
@ -88,10 +95,12 @@ void qTabDataOutput::PopulateDetectors() {
}
void qTabDataOutput::EnableBrowse() {
FILE_LOG(logDEBUG) << "Getting browse enable";
LOG(logDEBUG) << "Getting browse enable";
try {
btnOutputBrowse->setEnabled(false); // exception default
std::string rxHostname = det->getRxHostname({comboDetector->currentIndex() - 1}).squash("none");
std::string rxHostname =
det->getRxHostname({comboDetector->currentIndex() - 1})
.squash("none");
if (rxHostname == "none") {
btnOutputBrowse->setEnabled(false);
} else if (rxHostname == "localhost") {
@ -110,51 +119,67 @@ void qTabDataOutput::EnableBrowse() {
btnOutputBrowse->setEnabled(false);
}
}
} CATCH_DISPLAY ("Could not get receiver hostname.", "qTabDataOutput::EnableBrowse")
}
CATCH_DISPLAY("Could not get receiver hostname.",
"qTabDataOutput::EnableBrowse")
}
void qTabDataOutput::GetFileWrite() {
FILE_LOG(logDEBUG) << "Getting file write enable";
LOG(logDEBUG) << "Getting file write enable";
try {
boxFileWriteEnabled->setEnabled(true); // exception default
auto retval = det->getFileWrite().tsquash("File write is inconsistent for all detectors.");
auto retval = det->getFileWrite().tsquash(
"File write is inconsistent for all detectors.");
boxFileWriteEnabled->setEnabled(retval);
} CATCH_DISPLAY("Could not get file enable.", "qTabDataOutput::GetFileWrite")
}
CATCH_DISPLAY("Could not get file enable.", "qTabDataOutput::GetFileWrite")
}
void qTabDataOutput::GetFileName() {
FILE_LOG(logDEBUG) << "Getting file name";
LOG(logDEBUG) << "Getting file name";
try {
auto retval = det->getFileNamePrefix().tsquash("File name is inconsistent for all detectors.");
auto retval = det->getFileNamePrefix().tsquash(
"File name is inconsistent for all detectors.");
dispFileName->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get file name prefix.", "qTabDataOutput::GetFileName")
}
CATCH_DISPLAY("Could not get file name prefix.",
"qTabDataOutput::GetFileName")
}
void qTabDataOutput::GetOutputDir() {
FILE_LOG(logDEBUG) << "Getting file path";
disconnect(dispOutputDir, SIGNAL(editingFinished()), this, SLOT(SetOutputDir()));
LOG(logDEBUG) << "Getting file path";
disconnect(dispOutputDir, SIGNAL(editingFinished()), this,
SLOT(SetOutputDir()));
try {
std::string path = det->getFilePath({comboDetector->currentIndex() - 1}).tsquash("File path is different for all detectors.");
std::string path =
det->getFilePath({comboDetector->currentIndex() - 1})
.tsquash("File path is different for all detectors.");
dispOutputDir->setText(QString(path.c_str()));
} CATCH_DISPLAY ("Could not get file path.", "qTabDataOutput::GetOutputDir")
connect(dispOutputDir, SIGNAL(editingFinished()), this, SLOT(SetOutputDir()));
}
CATCH_DISPLAY("Could not get file path.", "qTabDataOutput::GetOutputDir")
connect(dispOutputDir, SIGNAL(editingFinished()), this,
SLOT(SetOutputDir()));
}
void qTabDataOutput::BrowseOutputDir() {
FILE_LOG(logDEBUG) << "Browsing output directory";
QString directory = QFileDialog::getExistingDirectory(this, tr("Choose Output Directory "), dispOutputDir->text());
LOG(logDEBUG) << "Browsing output directory";
QString directory = QFileDialog::getExistingDirectory(
this, tr("Choose Output Directory "), dispOutputDir->text());
if (!directory.isEmpty())
dispOutputDir->setText(directory);
}
void qTabDataOutput::SetOutputDir() {
QString path = dispOutputDir->text();
FILE_LOG(logDEBUG) << "Setting output directory to " << path.toAscii().constData();
LOG(logDEBUG) << "Setting output directory to "
<< path.toAscii().constData();
// empty
if (path.isEmpty()) {
qDefs::Message(qDefs::WARNING, "Invalid Output Path. Must not be empty.", "qTabDataOutput::SetOutputDir");
FILE_LOG(logWARNING) << "Invalid Output Path. Must not be empty.";
qDefs::Message(qDefs::WARNING,
"Invalid Output Path. Must not be empty.",
"qTabDataOutput::SetOutputDir");
LOG(logWARNING) << "Invalid Output Path. Must not be empty.";
GetOutputDir();
} else {
// chop off trailing '/'
@ -166,84 +191,122 @@ void qTabDataOutput::SetOutputDir() {
std::string spath = std::string(path.toAscii().constData());
try {
det->setFilePath(spath, {comboDetector->currentIndex() - 1});
} CATCH_HANDLE ("Could not set output file path.", "qTabDataOutput::SetOutputDir", this, &qTabDataOutput::GetOutputDir)
}
CATCH_HANDLE("Could not set output file path.",
"qTabDataOutput::SetOutputDir", this,
&qTabDataOutput::GetOutputDir)
}
}
void qTabDataOutput::GetFileFormat() {
FILE_LOG(logDEBUG) << "Getting File Format";
disconnect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFileFormat(int)));
LOG(logDEBUG) << "Getting File Format";
disconnect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFileFormat(int)));
try {
auto retval = det->getFileFormat().tsquash("File format is inconsistent for all detectors.");
auto retval = det->getFileFormat().tsquash(
"File format is inconsistent for all detectors.");
switch (retval) {
case slsDetectorDefs::BINARY:
case slsDetectorDefs::HDF5:
comboFileFormat->setCurrentIndex(static_cast<int>(retval));
break;
default:
throw sls::RuntimeError(std::string("Unknown file format: ") + std::to_string(static_cast<int>(retval)));
throw sls::RuntimeError(std::string("Unknown file format: ") +
std::to_string(static_cast<int>(retval)));
}
} CATCH_DISPLAY("Could not get file format.", "qTabDataOutput::GetFileFormat")
connect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFileFormat(int)));
}
CATCH_DISPLAY("Could not get file format.", "qTabDataOutput::GetFileFormat")
connect(comboFileFormat, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFileFormat(int)));
}
void qTabDataOutput::SetFileFormat(int format) {
FILE_LOG(logINFO) << "Setting File Format to " << comboFileFormat->currentText().toAscii().data();
LOG(logINFO) << "Setting File Format to "
<< comboFileFormat->currentText().toAscii().data();
try {
det->setFileFormat(static_cast<slsDetectorDefs::fileFormat>(comboFileFormat->currentIndex()));
} CATCH_HANDLE ("Could not set file format.", "qTabDataOutput::SetFileFormat", this, &qTabDataOutput::GetFileFormat)
det->setFileFormat(static_cast<slsDetectorDefs::fileFormat>(
comboFileFormat->currentIndex()));
}
CATCH_HANDLE("Could not set file format.", "qTabDataOutput::SetFileFormat",
this, &qTabDataOutput::GetFileFormat)
}
void qTabDataOutput::GetFileOverwrite() {
FILE_LOG(logDEBUG) << "Getting File Over Write Enable";
disconnect(chkOverwriteEnable, SIGNAL(toggled(bool)), this, SLOT(SetOverwriteEnable(bool)));
LOG(logDEBUG) << "Getting File Over Write Enable";
disconnect(chkOverwriteEnable, SIGNAL(toggled(bool)), this,
SLOT(SetOverwriteEnable(bool)));
try {
auto retval = det->getFileOverWrite().tsquash("File over write is inconsistent for all detectors.");
auto retval = det->getFileOverWrite().tsquash(
"File over write is inconsistent for all detectors.");
chkOverwriteEnable->setChecked(retval);
} CATCH_DISPLAY ("Could not get file over write enable.", "qTabDataOutput::GetFileOverwrite")
}
CATCH_DISPLAY("Could not get file over write enable.",
"qTabDataOutput::GetFileOverwrite")
connect(chkOverwriteEnable, SIGNAL(toggled(bool)), this, SLOT(SetOverwriteEnable(bool)));
connect(chkOverwriteEnable, SIGNAL(toggled(bool)), this,
SLOT(SetOverwriteEnable(bool)));
}
void qTabDataOutput::SetOverwriteEnable(bool enable) {
FILE_LOG(logINFO) << "Setting File Over Write Enable to " << enable;
LOG(logINFO) << "Setting File Over Write Enable to " << enable;
try {
det->setFileOverWrite(enable);
} CATCH_HANDLE ("Could not set file over write enable.", "qTabDataOutput::SetOverwriteEnable", this, &qTabDataOutput::GetFileOverwrite)
}
CATCH_HANDLE("Could not set file over write enable.",
"qTabDataOutput::SetOverwriteEnable", this,
&qTabDataOutput::GetFileOverwrite)
}
void qTabDataOutput::GetTenGigaEnable() {
FILE_LOG(logDEBUG) << "Getting 10GbE enable";
disconnect(chkTenGiga, SIGNAL(toggled(bool)), this, SLOT(SetTenGigaEnable(bool)));
LOG(logDEBUG) << "Getting 10GbE enable";
disconnect(chkTenGiga, SIGNAL(toggled(bool)), this,
SLOT(SetTenGigaEnable(bool)));
try {
auto retval = det->getTenGiga().tsquash("10GbE enable is inconsistent for all detectors.");
auto retval = det->getTenGiga().tsquash(
"10GbE enable is inconsistent for all detectors.");
chkTenGiga->setChecked(retval);
} CATCH_DISPLAY ("Could not get 10GbE enable.", "qTabDataOutput::GetTenGigaEnable")
connect(chkTenGiga, SIGNAL(toggled(bool)), this, SLOT(SetTenGigaEnable(bool)));
}
CATCH_DISPLAY("Could not get 10GbE enable.",
"qTabDataOutput::GetTenGigaEnable")
connect(chkTenGiga, SIGNAL(toggled(bool)), this,
SLOT(SetTenGigaEnable(bool)));
}
void qTabDataOutput::SetTenGigaEnable(bool enable) {
FILE_LOG(logINFO) << "Setting 10GbE to " << enable;
LOG(logINFO) << "Setting 10GbE to " << enable;
try {
det->setTenGiga(enable);
} CATCH_HANDLE ("Could not set 10GbE enable.", "qTabDataOutput::SetTenGigaEnable", this, &qTabDataOutput::GetTenGigaEnable)
}
CATCH_HANDLE("Could not set 10GbE enable.",
"qTabDataOutput::SetTenGigaEnable", this,
&qTabDataOutput::GetTenGigaEnable)
}
void qTabDataOutput::GetRateCorrection() {
FILE_LOG(logDEBUG) << "Getting Rate Correction";
disconnect(chkRate, SIGNAL(toggled(bool)), this, SLOT(EnableRateCorrection()));
disconnect(btnGroupRate, SIGNAL(buttonClicked(int)), this, SLOT(SetRateCorrection()));
disconnect(spinCustomDeadTime, SIGNAL(editingFinished()), this, SLOT(SetRateCorrection()));
LOG(logDEBUG) << "Getting Rate Correction";
disconnect(chkRate, SIGNAL(toggled(bool)), this,
SLOT(EnableRateCorrection()));
disconnect(btnGroupRate, SIGNAL(buttonClicked(int)), this,
SLOT(SetRateCorrection()));
disconnect(spinCustomDeadTime, SIGNAL(editingFinished()), this,
SLOT(SetRateCorrection()));
try {
spinCustomDeadTime->setValue(-1);
int64_t retval = det->getRateCorrection().tsquash("Rate correction (enable/tau) is inconsistent for all detectors.").count();
int64_t retval = det->getRateCorrection()
.tsquash("Rate correction (enable/tau) is "
"inconsistent for all detectors.")
.count();
chkRate->setChecked(retval == 0 ? false : true);
if (retval != 0)
spinCustomDeadTime->setValue(retval);
} CATCH_DISPLAY("Could not get rate correction.", "qTabDataOutput::GetRateCorrection")
}
CATCH_DISPLAY("Could not get rate correction.",
"qTabDataOutput::GetRateCorrection")
connect(chkRate, SIGNAL(toggled(bool)), this, SLOT(EnableRateCorrection()));
connect(btnGroupRate, SIGNAL(buttonClicked(int)), this, SLOT(SetRateCorrection()));
connect(spinCustomDeadTime, SIGNAL(editingFinished()), this, SLOT(SetRateCorrection()));
connect(btnGroupRate, SIGNAL(buttonClicked(int)), this,
SLOT(SetRateCorrection()));
connect(spinCustomDeadTime, SIGNAL(editingFinished()), this,
SLOT(SetRateCorrection()));
}
void qTabDataOutput::EnableRateCorrection() {
@ -252,11 +315,14 @@ void qTabDataOutput::EnableRateCorrection() {
SetRateCorrection();
return;
}
FILE_LOG(logINFO) << "Disabling Rate correction";
LOG(logINFO) << "Disabling Rate correction";
// disable
try {
det->setRateCorrection(sls::ns(0));
} CATCH_HANDLE ("Could not switch off rate correction.", "qTabDataOutput::EnableRateCorrection", this, &qTabDataOutput::GetRateCorrection)
}
CATCH_HANDLE("Could not switch off rate correction.",
"qTabDataOutput::EnableRateCorrection", this,
&qTabDataOutput::GetRateCorrection)
}
void qTabDataOutput::SetRateCorrection() {
@ -268,59 +334,81 @@ void qTabDataOutput::SetRateCorrection() {
// custom dead time
if (radioCustomDeadtime->isChecked()) {
int64_t deadtime = spinCustomDeadTime->value();
FILE_LOG(logINFO) << "Setting Rate Correction with custom dead time: " << deadtime;
LOG(logINFO)
<< "Setting Rate Correction with custom dead time: "
<< deadtime;
det->setRateCorrection(sls::ns(deadtime));
}
// default dead time
else {
FILE_LOG(logINFO) << "Setting Rate Correction with default dead time";
LOG(logINFO)
<< "Setting Rate Correction with default dead time";
det->setDefaultRateCorrection();
}
} CATCH_HANDLE ("Could not set rate correction.", "qTabDataOutput::SetRateCorrection", this, &qTabDataOutput::GetRateCorrection)
}
CATCH_HANDLE("Could not set rate correction.",
"qTabDataOutput::SetRateCorrection", this,
&qTabDataOutput::GetRateCorrection)
}
void qTabDataOutput::GetSpeed() {
FILE_LOG(logDEBUG) << "Getting Speed";
disconnect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSpeed(int)));
LOG(logDEBUG) << "Getting Speed";
disconnect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSpeed(int)));
try {
auto retval = det->getSpeed().tsquash("Speed is inconsistent for all detectors.");
auto retval =
det->getSpeed().tsquash("Speed is inconsistent for all detectors.");
comboEigerClkDivider->setCurrentIndex(static_cast<int>(retval));
} CATCH_DISPLAY ("Could not get speed.", "qTabDataOutput::GetSpeed")
connect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSpeed(int)));
}
CATCH_DISPLAY("Could not get speed.", "qTabDataOutput::GetSpeed")
connect(comboEigerClkDivider, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSpeed(int)));
}
void qTabDataOutput::SetSpeed(int speed) {
FILE_LOG(logINFO) << "Setting Speed to " << comboEigerClkDivider->currentText().toAscii().data();;
LOG(logINFO) << "Setting Speed to "
<< comboEigerClkDivider->currentText().toAscii().data();
;
try {
det->setSpeed(static_cast<slsDetectorDefs::speedLevel>(speed));
} CATCH_HANDLE ("Could not set speed.", "qTabDataOutput::SetSpeed", this, &qTabDataOutput::GetSpeed)
}
CATCH_HANDLE("Could not set speed.", "qTabDataOutput::SetSpeed", this,
&qTabDataOutput::GetSpeed)
}
void qTabDataOutput::GetFlags() {
FILE_LOG(logDEBUG) << "Getting readout flags";
disconnect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFlags()));
LOG(logDEBUG) << "Getting readout flags";
disconnect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFlags()));
try {
auto retval = det->getParallelMode().tsquash("Parallel Flag is inconsistent for all detectors.");
auto retval = det->getParallelMode().tsquash(
"Parallel Flag is inconsistent for all detectors.");
// parallel or non parallel
if (retval)
comboEigerParallelFlag->setCurrentIndex(PARALLEL);
else
comboEigerParallelFlag->setCurrentIndex(NONPARALLEL);
} CATCH_DISPLAY ("Could not get flags.", "qTabDataOutput::GetFlags")
connect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFlags()));
}
CATCH_DISPLAY("Could not get flags.", "qTabDataOutput::GetFlags")
connect(comboEigerParallelFlag, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetFlags()));
}
void qTabDataOutput::SetFlags() {
auto mode = comboEigerParallelFlag->currentIndex() == PARALLEL ? true : false;
auto mode =
comboEigerParallelFlag->currentIndex() == PARALLEL ? true : false;
try {
FILE_LOG(logINFO) << "Setting Readout Flags to " << comboEigerParallelFlag->currentText().toAscii().data();
LOG(logINFO)
<< "Setting Readout Flags to "
<< comboEigerParallelFlag->currentText().toAscii().data();
det->setParallelMode(mode);
} CATCH_HANDLE ("Could not set readout flags.", "qTabDataOutput::SetFlags", this, &qTabDataOutput::GetFlags)
}
CATCH_HANDLE("Could not set readout flags.", "qTabDataOutput::SetFlags",
this, &qTabDataOutput::GetFlags)
}
void qTabDataOutput::Refresh() {
FILE_LOG(logDEBUG) << "**Updating DataOutput Tab";
LOG(logDEBUG) << "**Updating DataOutput Tab";
EnableBrowse();
GetFileWrite();
@ -339,5 +427,5 @@ void qTabDataOutput::Refresh() {
GetFlags();
}
FILE_LOG(logDEBUG) << "**Updated DataOutput Tab";
LOG(logDEBUG) << "**Updated DataOutput Tab";
}

122
slsDetectorGui/src/qTabDebugging.cpp Executable file → Normal file
View File

@ -1,33 +1,26 @@
#include "qTabDebugging.h"
#include "qDefs.h"
#include "ToString.h"
#include <QDesktopWidget>
#include <QGridLayout>
#include <QTreeWidget>
#include <iostream>
qTabDebugging::qTabDebugging(QWidget *parent, sls::Detector *detector) :
QWidget(parent), det(detector), treeDet(nullptr), lblDetectorHostname(nullptr), lblDetectorFirmware(nullptr), lblDetectorSoftware(nullptr) {
qTabDebugging::qTabDebugging(QWidget *parent, sls::Detector *detector)
: QWidget(parent), det(detector), treeDet(nullptr),
lblDetectorHostname(nullptr), lblDetectorFirmware(nullptr),
lblDetectorSoftware(nullptr) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Debugging ready";
LOG(logDEBUG) << "Debugging ready";
}
qTabDebugging::~qTabDebugging() {
if (treeDet)
delete treeDet;
if (lblDetectorHostname)
delete lblDetectorHostname;
if (lblDetectorFirmware)
delete lblDetectorFirmware;
if (lblDetectorSoftware)
delete lblDetectorSoftware;
}
void qTabDebugging::SetupWidgetWindow() {
// enabling according to det type
if (det->getDetectorType().squash() == slsDetectorDefs::EIGER) {
@ -44,9 +37,9 @@ void qTabDebugging::SetupWidgetWindow() {
Refresh();
}
void qTabDebugging::Initialization() {
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this, SLOT(GetDetectorStatus()));
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this,
SLOT(GetDetectorStatus()));
connect(btnGetInfo, SIGNAL(clicked()), this, SLOT(GetInfo()));
if (btnTest->isEnabled()) {
connect(btnTest, SIGNAL(clicked()), this, SLOT(TestDetector()));
@ -54,7 +47,7 @@ void qTabDebugging::Initialization() {
}
void qTabDebugging::PopulateDetectors() {
FILE_LOG(logDEBUG) << "Populating detectors";
LOG(logDEBUG) << "Populating detectors";
comboDetector->clear();
auto res = det->getHostname();
@ -64,17 +57,19 @@ void qTabDebugging::PopulateDetectors() {
}
void qTabDebugging::GetDetectorStatus() {
FILE_LOG(logDEBUG) << "Getting Status";
LOG(logDEBUG) << "Getting Status";
try {
std::string status = sls::ToString(det->getDetectorStatus({comboDetector->currentIndex()})[0]);
std::string status = sls::ToString(
det->getDetectorStatus({comboDetector->currentIndex()})[0]);
lblStatus->setText(QString(status.c_str()).toUpper());
} CATCH_DISPLAY ("Could not get detector status.", "qTabDebugging::GetDetectorStatus")
}
CATCH_DISPLAY("Could not get detector status.",
"qTabDebugging::GetDetectorStatus")
}
void qTabDebugging::GetInfo() {
FILE_LOG(logDEBUG) << "Getting Readout Info";
LOG(logDEBUG) << "Getting Readout Info";
// open info in a new popup
QFrame *popup1 = new QFrame(this, Qt::Popup | Qt::SubWindow);
@ -90,34 +85,45 @@ void qTabDebugging::GetInfo() {
// to make sure the size is constant
lblDetectorFirmware->setFixedWidth(100);
layout->addWidget(dispFrame, 0, 1);
QString detName = QString(sls::ToString(det->getDetectorType().squash()).c_str());
QString detName =
QString(sls::ToString(det->getDetectorType().squash()).c_str());
switch (det->getDetectorType().squash()) {
case slsDetectorDefs::EIGER:
formLayout->addWidget(new QLabel("Half Module:"), 0, 0);
formLayout->addItem(new QSpacerItem(15, 20, QSizePolicy::Fixed, QSizePolicy::Fixed), 0, 1);
formLayout->addItem(
new QSpacerItem(15, 20, QSizePolicy::Fixed, QSizePolicy::Fixed), 0,
1);
formLayout->addWidget(lblDetectorHostname, 0, 2);
formLayout->addWidget(new QLabel("Half Module Firmware Version:"), 1, 0);
formLayout->addWidget(new QLabel("Half Module Firmware Version:"), 1,
0);
formLayout->addWidget(lblDetectorFirmware, 1, 2);
formLayout->addWidget(new QLabel("Half Module Software Version:"), 2, 0);
formLayout->addWidget(new QLabel("Half Module Software Version:"), 2,
0);
formLayout->addWidget(lblDetectorSoftware, 2, 2);
treeDet->setHeaderLabel("Eiger Detector");
// get num modules
for (int i = 0; i < comboDetector->count() / 2; ++i)
items.append(new QTreeWidgetItem((QTreeWidget *)0, QStringList(QString("Module %1").arg(i))));
items.append(new QTreeWidgetItem(
(QTreeWidget *)nullptr, QStringList(QString("Module %1").arg(i))));
treeDet->insertTopLevelItems(0, items);
// gets det names
for (int i = 0; i < comboDetector->count(); ++i) {
QList<QTreeWidgetItem *> childItems;
childItems.append(new QTreeWidgetItem((QTreeWidget *)0, QStringList(QString("Half Module (%1)").arg(comboDetector->itemText(i)))));
childItems.append(new QTreeWidgetItem(
(QTreeWidget *)nullptr,
QStringList(QString("Half Module (%1)")
.arg(comboDetector->itemText(i)))));
treeDet->topLevelItem(i * 2)->insertChildren(0, childItems);
}
break;
default:
formLayout->addWidget(new QLabel("Module:"), 0, 0);
formLayout->addItem(new QSpacerItem(15, 20, QSizePolicy::Fixed, QSizePolicy::Fixed), 0, 1);
formLayout->addItem(
new QSpacerItem(15, 20, QSizePolicy::Fixed, QSizePolicy::Fixed), 0,
1);
formLayout->addWidget(lblDetectorHostname, 0, 2);
formLayout->addWidget(new QLabel("Module Firmware Version:"), 1, 0);
formLayout->addWidget(lblDetectorFirmware, 1, 2);
@ -126,28 +132,33 @@ void qTabDebugging::GetInfo() {
treeDet->setHeaderLabel(QString(detName + " Detector"));
// gets det names
for (int i = 0; i < comboDetector->count(); ++i)
items.append(new QTreeWidgetItem((QTreeWidget *)0, QStringList(QString("Module (%1)").arg(comboDetector->itemText(i)))));
items.append(new QTreeWidgetItem(
(QTreeWidget *)nullptr,
QStringList(
QString("Module (%1)").arg(comboDetector->itemText(i)))));
treeDet->insertTopLevelItems(0, items);
break;
}
// show and center widget
int x = ((parentWidget()->width()) - (popup1->frameGeometry().width())) / 2;
int y = ((parentWidget()->height()) - (popup1->frameGeometry().height())) / 2;
int y =
((parentWidget()->height()) - (popup1->frameGeometry().height())) / 2;
QDesktopWidget *desktop = QApplication::desktop();
int screen = desktop->screenNumber(this);
popup1->setWindowModality(Qt::WindowModal);
popup1->move((desktop->screenGeometry(screen).x()) + x, (desktop->screenGeometry(screen).y()) + y);
popup1->move((desktop->screenGeometry(screen).x()) + x,
(desktop->screenGeometry(screen).y()) + y);
popup1->show();
// put the first parameters
SetParameters(treeDet->topLevelItem(0));
// connect to slots
connect(treeDet, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(SetParameters(QTreeWidgetItem *)));
connect(treeDet, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
SLOT(SetParameters(QTreeWidgetItem *)));
}
void qTabDebugging::SetParameters(QTreeWidgetItem *item) {
// eiger: if half module clicked, others: true always
bool ignoreOrHalfModuleClicked = true;
@ -164,16 +175,22 @@ void qTabDebugging::SetParameters(QTreeWidgetItem *item) {
break;
}
try {
auto retval = std::string("0x") + std::to_string((unsigned long)det->getFirmwareVersion({comboDetector->currentIndex()})[0]);
auto retval = std::string("0x") +
std::to_string((unsigned long)det->getFirmwareVersion(
{comboDetector->currentIndex()})[0]);
lblDetectorFirmware->setText(QString(retval.c_str()));
retval = std::string("0x") + std::to_string((unsigned long)det->getDetectorServerVersion({comboDetector->currentIndex()})[0]);
retval =
std::string("0x") +
std::to_string((unsigned long)det->getDetectorServerVersion(
{comboDetector->currentIndex()})[0]);
lblDetectorSoftware->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get versions.", "qTabDebugging::SetParameters")
}
CATCH_DISPLAY("Could not get versions.", "qTabDebugging::SetParameters")
}
}
void qTabDebugging::TestDetector() {
FILE_LOG(logINFO) << "Testing Readout";
LOG(logINFO) << "Testing Readout";
try {
QString moduleName = "Module";
@ -182,35 +199,42 @@ void qTabDebugging::TestDetector() {
}
// construct message
QString message = QString("<nobr>Test Results for %1:</nobr><br><br>").arg(comboDetector->currentText());
QString message = QString("<nobr>Test Results for %1:</nobr><br><br>")
.arg(comboDetector->currentText());
// detector firmware
if (chkDetectorFirmware->isChecked()) {
try {
det->executeFirmwareTest({comboDetector->currentIndex()});
message.append(QString("<nobr>%1 Firmware: PASS</nobr><br>").arg(moduleName));
FILE_LOG(logINFO) << "Detector Firmware Test: Pass";
} CATCH_DISPLAY ("Firmware test failed.", "qTabDebugging::TestDetector")
message.append(QString("<nobr>%1 Firmware: PASS</nobr><br>")
.arg(moduleName));
LOG(logINFO) << "Detector Firmware Test: Pass";
}
CATCH_DISPLAY("Firmware test failed.",
"qTabDebugging::TestDetector")
}
// detector CPU-FPGA bus
if (chkDetectorBus->isChecked()) {
try {
det->executeBusTest({comboDetector->currentIndex()});
message.append(QString("<nobr>%1 Bus: PASS</nobr><br>").arg(moduleName));
FILE_LOG(logINFO) << "Detector Bus Test: Pass";
} CATCH_DISPLAY ("Bus test failed.", "qTabDebugging::TestDetector")
message.append(
QString("<nobr>%1 Bus: PASS</nobr><br>").arg(moduleName));
LOG(logINFO) << "Detector Bus Test: Pass";
}
CATCH_DISPLAY("Bus test failed.", "qTabDebugging::TestDetector")
}
// display message
qDefs::Message(qDefs::INFORMATION, message.toAscii().constData(), "qTabDebugging::TestDetector");
} CATCH_DISPLAY ("Could not execute digital test.", "qTabDebugging::TestDetector")
qDefs::Message(qDefs::INFORMATION, message.toAscii().constData(),
"qTabDebugging::TestDetector");
}
CATCH_DISPLAY("Could not execute digital test.",
"qTabDebugging::TestDetector")
}
void qTabDebugging::Refresh() {
FILE_LOG(logDEBUG) << "**Updating Debugging Tab";
LOG(logDEBUG) << "**Updating Debugging Tab";
GetDetectorStatus();
FILE_LOG(logDEBUG) << "**Updated Debugging Tab";
LOG(logDEBUG) << "**Updated Debugging Tab";
}

372
slsDetectorGui/src/qTabDeveloper.cpp Executable file → Normal file
View File

@ -1,13 +1,12 @@
#include "qTabDeveloper.h"
#include "qDefs.h"
#include "qDacWidget.h"
#include "qDefs.h"
#include <iostream>
qTabDeveloper::qTabDeveloper(QWidget *parent, sls::Detector *detector) : QWidget(parent), det(detector) {
qTabDeveloper::qTabDeveloper(QWidget *parent, sls::Detector *detector)
: QWidget(parent), det(detector) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Developer ready";
LOG(logDEBUG) << "Developer ready";
}
qTabDeveloper::~qTabDeveloper() {}
@ -25,127 +24,260 @@ void qTabDeveloper::SetupWidgetWindow() {
slsDetectorDefs::detectorType detType = det->getDetectorType().squash();
switch (detType) {
case slsDetectorDefs::EIGER:
dacWidgets.push_back(new qDacWidget(this, det, true, "v SvP: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v SvN ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vrf: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vrs: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vtr: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vtgstv: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v cal: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vcp ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vcn: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vis: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v rxb_lb: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v rxb_rb: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vcmp_ll: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vcmp_lr: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vcmp_rl: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Vcmp_rr: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v threshold: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(this, det, false, "Temperature FPGA Ext: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(this, det, false, "Temperature 10GE: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(this, det, false, "Temperature DCDC: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(this, det, false, "Temperature SODL: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(this, det, false, "Temperature SODR: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(this, det, false, "Temperature FPGA: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v SvP: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v SvN ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v Vrf: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v Vrs: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v Vtr: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v Vtgstv: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v cal: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v Vcp ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v Vcn: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v Vis: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v rxb_lb: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v rxb_rb: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"v Vcmp_ll: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"v Vcmp_lr: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"v Vcmp_rl: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"v Vcmp_rr: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"v threshold: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(
this, det, false,
"Temperature FPGA Ext: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(
this, det, false,
"Temperature 10GE: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(
this, det, false,
"Temperature DCDC: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(
this, det, false,
"Temperature SODL: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(
this, det, false,
"Temperature SODR: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(
this, det, false,
"Temperature FPGA: ", getSLSIndex(detType, tempid++)));
break;
case slsDetectorDefs::GOTTHARD:
comboHV->show();
lblComboHV->show();
dacWidgets.push_back(new qDacWidget(this, det, true, "v Reference: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Cascode n: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Cascode p: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Comp. Output: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Cascode out ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Comp. Input: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v Comp. Ref: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "i Base Test: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(this, det, false, "Temperature ADC: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(this, det, false, "Temperature FPGA: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"v Reference: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"v Cascode n: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"v Cascode p: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"v Comp. Output: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true, "v Cascode out ",
getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"v Comp. Input: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"v Comp. Ref: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"i Base Test: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(
this, det, false,
"Temperature ADC: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(
this, det, false,
"Temperature FPGA: ", getSLSIndex(detType, tempid++)));
break;
case slsDetectorDefs::JUNGFRAU:
lblSpinHV->show();
spinHV->show();
dacWidgets.push_back(new qDacWidget(this, det, true, "v vb comp: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v vdd prot: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v vin com: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v vref prech: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v vb pixbuf: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v vb ds: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "v vref ds: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "i vref comp: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(this, det, false, "Temperature ADC: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"v vb comp: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"v vdd prot: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"v vin com: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"v vref prech: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"v vb pixbuf: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "v vb ds: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"v vref ds: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"i vref comp: ", getSLSIndex(detType, tempid++)));
adcWidgets.push_back(new qDacWidget(
this, det, false,
"Temperature ADC: ", getSLSIndex(detType, tempid++)));
break;
case slsDetectorDefs::MOENCH:
lblSpinHV->show();
spinHV->show();
dacWidgets.push_back(new qDacWidget(this, det, true, "vbp_colbuf: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vipre: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vin_cm: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vb_sda: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vcasc_sfp: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vout_cm: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vipre_cds: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "ibias_sfp: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vbp_colbuf: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vipre: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vin_cm: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vb_sda: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vcasc_sfp: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vout_cm: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vipre_cds: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"ibias_sfp: ", getSLSIndex(detType, tempid++)));
break;
case slsDetectorDefs::MYTHEN3:
lblSpinHV->show();
spinHV->show();
hvmin = 0;
dacWidgets.push_back(new qDacWidget(this, det, true, "vcassh: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vth2: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vshaper: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vshaperneg: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vipre_out: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vth3: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vth1: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vicin: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vcas: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vpreamp: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vph: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vipre: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "viinsh: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vpl: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vtrim: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vdcsh: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vcassh: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vth2: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vshaper: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vshaperneg: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vipre_out: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vth3: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vth1: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vicin: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vcas: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vpreamp: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vph: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vipre: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "viinsh: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vpl: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vtrim: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vdcsh: ", getSLSIndex(detType, tempid++)));
break;
case slsDetectorDefs::GOTTHARD2:
lblSpinHV->show();
spinHV->show();
hvmin = 0;
dacWidgets.push_back(new qDacWidget(this, det, true, "vref_h_adc: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vb_comp_fe: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vb_comp_adc: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vcom_cds: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vref_rstore: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vb_opa_1st: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vref_comp_fe: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vcom_adc1: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vref_prech: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vref_l_adc: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vref_cds: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vb_cs: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vb_opa_fd: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(this, det, true, "vcom_adc2: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vref_h_adc: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vb_comp_fe: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"vb_comp_adc: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vcom_cds: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"vref_rstore: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vb_opa_1st: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true,
"vref_comp_fe: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vcom_adc1: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vref_prech: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vref_l_adc: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vref_cds: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(new qDacWidget(
this, det, true, "vb_cs: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vb_opa_fd: ", getSLSIndex(detType, tempid++)));
dacWidgets.push_back(
new qDacWidget(this, det, true,
"vcom_adc2: ", getSLSIndex(detType, tempid++)));
break;
default:
break;
}
} CATCH_DISPLAY (std::string("Could not get dac/ adc index ") + std::to_string(tempid), "qTabDeveloper::SetupWidgetWindow")
}
CATCH_DISPLAY(std::string("Could not get dac/ adc index ") +
std::to_string(tempid),
"qTabDeveloper::SetupWidgetWindow")
for (size_t i = 0; i < dacWidgets.size(); ++i) {
gridlayoutDac->addWidget(dacWidgets[i], i / 2, i % 2);
}
gridlayoutDac->addItem(new QSpacerItem(20,20,QSizePolicy::Fixed,QSizePolicy::Expanding),dacWidgets.size(), 0);
gridlayoutDac->addItem(
new QSpacerItem(20, 20, QSizePolicy::Fixed, QSizePolicy::Expanding),
dacWidgets.size(), 0);
for (size_t i = 0; i < adcWidgets.size(); ++i) {
gridlayoutAdc->addWidget(adcWidgets[i], i / 2, i % 2);
}
gridlayoutAdc->addItem(new QSpacerItem(20,20,QSizePolicy::Fixed,QSizePolicy::Expanding),adcWidgets.size(), 0);
gridlayoutAdc->addItem(
new QSpacerItem(20, 20, QSizePolicy::Fixed, QSizePolicy::Expanding),
adcWidgets.size(), 0);
tabWidget->setCurrentIndex(0);
@ -154,15 +286,16 @@ void qTabDeveloper::SetupWidgetWindow() {
Refresh();
}
void qTabDeveloper::Initialization() {
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this, SLOT(Refresh()));
connect(comboHV, SIGNAL(currentIndexChanged(int)), this, SLOT(SetHighVoltage()));
connect(comboDetector, SIGNAL(currentIndexChanged(int)), this,
SLOT(Refresh()));
connect(comboHV, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetHighVoltage()));
connect(spinHV, SIGNAL(editingFinished()), this, SLOT(SetHighVoltage()));
}
void qTabDeveloper::PopulateDetectors() {
FILE_LOG(logDEBUG) << "Populating detectors";
LOG(logDEBUG) << "Populating detectors";
comboDetector->clear();
comboDetector->addItem("All");
@ -179,16 +312,19 @@ void qTabDeveloper::GetHighVoltage() {
// not enabled for eiger
if (!comboHV->isVisible() && !spinHV->isVisible())
return;
FILE_LOG(logDEBUG) << "Getting High Voltage";
LOG(logDEBUG) << "Getting High Voltage";
disconnect(spinHV, SIGNAL(editingFinished()), this, SLOT(SetHighVoltage()));
disconnect(comboHV, SIGNAL(currentIndexChanged(int)), this, SLOT(SetHighVoltage()));
disconnect(comboHV, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetHighVoltage()));
try {
// dac units
auto retval = det->getHighVoltage({comboDetector->currentIndex() - 1}).tsquash("Inconsistent values for high voltage.");
auto retval = det->getHighVoltage({comboDetector->currentIndex() - 1})
.tsquash("Inconsistent values for high voltage.");
// spinHV
if (spinHV->isVisible()) {
if (retval != 0 && retval < hvmin && retval > HV_MAX) {
throw sls::RuntimeError(std::string("Unknown High Voltage: ") + std::to_string(retval));
throw sls::RuntimeError(std::string("Unknown High Voltage: ") +
std::to_string(retval));
}
spinHV->setValue(retval);
}
@ -217,25 +353,32 @@ void qTabDeveloper::GetHighVoltage() {
comboHV->setCurrentIndex(HV_200);
break;
default:
throw sls::RuntimeError(std::string("Unknown High Voltage: ") + std::to_string(retval));
throw sls::RuntimeError(std::string("Unknown High Voltage: ") +
std::to_string(retval));
}
}
} CATCH_DISPLAY ("Could not get high voltage.", "qTabDeveloper::GetHighVoltage")
}
CATCH_DISPLAY("Could not get high voltage.",
"qTabDeveloper::GetHighVoltage")
connect(spinHV, SIGNAL(editingFinished()), this, SLOT(SetHighVoltage()));
connect(comboHV, SIGNAL(currentIndexChanged(int)), this, SLOT(SetHighVoltage()));
connect(comboHV, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetHighVoltage()));
}
void qTabDeveloper::SetHighVoltage() {
int val = (comboHV->isVisible() ? comboHV->currentText().toInt() : spinHV->value());
FILE_LOG(logINFO) << "Setting high voltage:" << val;
int val = (comboHV->isVisible() ? comboHV->currentText().toInt()
: spinHV->value());
LOG(logINFO) << "Setting high voltage:" << val;
try {
det->setHighVoltage({comboDetector->currentIndex() - 1});
} CATCH_HANDLE ("Could not set high voltage.", "qTabDeveloper::SetHighVoltage",
}
CATCH_HANDLE("Could not set high voltage.", "qTabDeveloper::SetHighVoltage",
this, &qTabDeveloper::GetHighVoltage)
}
slsDetectorDefs::dacIndex qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorType detType, int index) {
slsDetectorDefs::dacIndex
qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorType detType, int index) {
switch (detType) {
case slsDetectorDefs::EIGER:
@ -287,7 +430,8 @@ slsDetectorDefs::dacIndex qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorTy
case 22:
return slsDetectorDefs::TEMPERATURE_FPGA;
default:
throw sls::RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index));
throw sls::RuntimeError(std::string("Unknown dac/adc index") +
std::to_string(index));
}
break;
case slsDetectorDefs::GOTTHARD:
@ -313,7 +457,8 @@ slsDetectorDefs::dacIndex qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorTy
case 9:
return slsDetectorDefs::TEMPERATURE_FPGA;
default:
throw sls::RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index));
throw sls::RuntimeError(std::string("Unknown dac/adc index") +
std::to_string(index));
}
break;
@ -338,7 +483,8 @@ slsDetectorDefs::dacIndex qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorTy
case 8:
return slsDetectorDefs::TEMPERATURE_ADC;
default:
throw sls::RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index));
throw sls::RuntimeError(std::string("Unknown dac/adc index") +
std::to_string(index));
}
break;
@ -361,7 +507,8 @@ slsDetectorDefs::dacIndex qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorTy
case 7:
return slsDetectorDefs::IBIAS_SFP;
default:
throw sls::RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index));
throw sls::RuntimeError(std::string("Unknown dac/adc index") +
std::to_string(index));
}
break;
@ -400,7 +547,8 @@ slsDetectorDefs::dacIndex qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorTy
case 15:
return slsDetectorDefs::VDCSH;
default:
throw sls::RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index));
throw sls::RuntimeError(std::string("Unknown dac/adc index") +
std::to_string(index));
}
break;
@ -435,7 +583,8 @@ slsDetectorDefs::dacIndex qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorTy
case 13:
return slsDetectorDefs::VCOM_ADC2;
default:
throw sls::RuntimeError(std::string("Unknown dac/adc index") + std::to_string(index));
throw sls::RuntimeError(std::string("Unknown dac/adc index") +
std::to_string(index));
}
break;
@ -445,7 +594,7 @@ slsDetectorDefs::dacIndex qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorTy
}
void qTabDeveloper::Refresh() {
FILE_LOG(logDEBUG) << "**Updating Developer Tab\n";
LOG(logDEBUG) << "**Updating Developer Tab\n";
for (const auto &it : dacWidgets) {
it->SetDetectorIndex(comboDetector->currentIndex() - 1);
}
@ -453,6 +602,5 @@ void qTabDeveloper::Refresh() {
it->SetDetectorIndex(comboDetector->currentIndex() - 1);
}
GetHighVoltage();
FILE_LOG(logDEBUG) << "**Updated Developer Tab";
LOG(logDEBUG) << "**Updated Developer Tab";
}

455
slsDetectorGui/src/qTabMeasurement.cpp Executable file → Normal file
View File

@ -1,35 +1,30 @@
#include "qTabMeasurement.h"
#include "qDefs.h"
#include "qDrawPlot.h"
#include "string_utils.h"
#include <QStandardItemModel>
#include <QTimer>
#include <cmath>
#include <iostream>
qTabMeasurement::qTabMeasurement(QWidget *parent, sls::Detector *detector, qDrawPlot *p) : QWidget(parent), det(detector), plot(p),
progressTimer(nullptr) {
qTabMeasurement::qTabMeasurement(QWidget *parent, sls::Detector *detector,
qDrawPlot *p)
: QWidget(parent), det(detector), plot(p), progressTimer(nullptr) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Measurement ready";
LOG(logDEBUG) << "Measurement ready";
}
qTabMeasurement::~qTabMeasurement() {
if (progressTimer)
delete progressTimer;
}
qTabMeasurement::~qTabMeasurement() { delete progressTimer; }
void qTabMeasurement::SetupWidgetWindow() {
// palette
red = QPalette();
red.setColor(QPalette::Active, QPalette::WindowText, Qt::red);
acqPeriodTip = spinPeriod->toolTip();
errPeriodTip = QString("<nobr>Frame period between exposures.</nobr><br>"
errPeriodTip =
QString("<nobr>Frame period between exposures.</nobr><br>"
"<nobr> #period#</nobr><br><br>") +
QString("<nobr><font color=\"red\"><b>Acquisition Period</b> should be"
QString(
"<nobr><font color=\"red\"><b>Acquisition Period</b> should be"
" greater than or equal to <b>Exposure Time</b>.</font></nobr>");
// timer to update the progress bar
@ -43,7 +38,8 @@ void qTabMeasurement::SetupWidgetWindow() {
spinDelay->setEnabled(true);
comboDelayUnit->setEnabled(true);
// default is triggers and delay (not #bursts and burst period for gotthard2 in auto mode)
// default is triggers and delay (not #bursts and burst period for gotthard2
// in auto mode)
ShowTriggerDelay();
// enabling according to det type
@ -85,51 +81,69 @@ void qTabMeasurement::SetupWidgetWindow() {
}
void qTabMeasurement::Initialization() {
connect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTimingMode(int)));
connect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(SetNumMeasurements(int)));
connect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(SetNumFrames(int)));
connect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(SetNumTriggers(int)));
connect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetTimingMode(int)));
connect(spinNumMeasurements, SIGNAL(valueChanged(int)), this,
SLOT(SetNumMeasurements(int)));
connect(spinNumFrames, SIGNAL(valueChanged(int)), this,
SLOT(SetNumFrames(int)));
connect(spinNumTriggers, SIGNAL(valueChanged(int)), this,
SLOT(SetNumTriggers(int)));
if (spinNumBursts->isEnabled()) {
connect(spinNumBursts, SIGNAL(valueChanged(int)), this, SLOT(SetNumBursts(int)));
connect(spinNumBursts, SIGNAL(valueChanged(int)), this,
SLOT(SetNumBursts(int)));
}
if (spinNumSamples->isEnabled()) {
connect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(SetNumSamples(int)));
connect(spinNumSamples, SIGNAL(valueChanged(int)), this,
SLOT(SetNumSamples(int)));
}
connect(spinExpTime, SIGNAL(valueChanged(double)), this, SLOT(SetExposureTime()));
connect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetExposureTime()));
connect(spinPeriod, SIGNAL(valueChanged(double)), this, SLOT(SetAcquisitionPeriod()));
connect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetAcquisitionPeriod()));
connect(spinExpTime, SIGNAL(valueChanged(double)), this,
SLOT(SetExposureTime()));
connect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetExposureTime()));
connect(spinPeriod, SIGNAL(valueChanged(double)), this,
SLOT(SetAcquisitionPeriod()));
connect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetAcquisitionPeriod()));
if (spinDelay->isEnabled()) {
connect(spinDelay, SIGNAL(valueChanged(double)), this, SLOT(SetDelay()));
connect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetDelay()));
connect(spinDelay, SIGNAL(valueChanged(double)), this,
SLOT(SetDelay()));
connect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetDelay()));
}
if (spinBurstPeriod->isEnabled()) {
connect(spinBurstPeriod, SIGNAL(valueChanged(double)), this, SLOT(SetBurstPeriod()));
connect(comboBurstPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetBurstPeriod()));
connect(spinBurstPeriod, SIGNAL(valueChanged(double)), this,
SLOT(SetBurstPeriod()));
connect(comboBurstPeriodUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetBurstPeriod()));
}
connect(chkFile, SIGNAL(toggled(bool)), this, SLOT(SetFileWrite(bool)));
connect(dispFileName, SIGNAL(editingFinished()), this, SLOT(SetFileName()));
connect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(SetRunIndex(int)));
if (startingFnumImplemented) {
connect(spinStartingFrameNumber, SIGNAL(valueChanged(int)), this, SLOT(SetStartingFrameNumber(int)));
connect(spinStartingFrameNumber, SIGNAL(valueChanged(int)), this,
SLOT(SetStartingFrameNumber(int)));
}
connect(progressTimer, SIGNAL(timeout()), this, SLOT(UpdateProgress()));
connect(btnStart, SIGNAL(clicked()), this, SLOT(StartAcquisition()));
connect(btnStop, SIGNAL(clicked()), this, SLOT(StopAcquisition()));
}
void qTabMeasurement::ShowTriggerDelay() {
bool showTrigger = true;
if (det->getDetectorType().squash() == slsDetectorDefs::GOTTHARD2) {
try {
FILE_LOG(logDEBUG) << "Getting burst mode";
auto retval = det->getBurstMode().tsquash("Inconsistent burst mode for all detectors.");
LOG(logDEBUG) << "Getting burst mode";
auto retval = det->getBurstMode().tsquash(
"Inconsistent burst mode for all detectors.");
// burst mode and auto timing mode
if (retval != slsDetectorDefs::BURST_OFF && comboTimingMode->currentIndex() == AUTO) {
if (retval != slsDetectorDefs::BURST_OFF &&
comboTimingMode->currentIndex() == AUTO) {
showTrigger = false;
}
} CATCH_DISPLAY ("Could not get burst mode.", "qTabMeasurement::ShowTriggerDelay")
}
CATCH_DISPLAY("Could not get burst mode.",
"qTabMeasurement::ShowTriggerDelay")
}
if (showTrigger) {
@ -147,14 +161,15 @@ void qTabMeasurement::ShowTriggerDelay() {
}
}
void qTabMeasurement::SetupTimingMode() {
QStandardItemModel* model = qobject_cast<QStandardItemModel *>(comboTimingMode->model());
QStandardItemModel *model =
qobject_cast<QStandardItemModel *>(comboTimingMode->model());
QModelIndex index[NUMTIMINGMODES];
QStandardItem *item[NUMTIMINGMODES];
if (model) {
for (int i = 0; i < NUMTIMINGMODES; i++) {
index[i] = model->index(i, comboTimingMode->modelColumn(), comboTimingMode->rootModelIndex());
index[i] = model->index(i, comboTimingMode->modelColumn(),
comboTimingMode->rootModelIndex());
item[i] = model->itemFromIndex(index[i]);
}
@ -166,7 +181,7 @@ void qTabMeasurement::SetupTimingMode() {
}
void qTabMeasurement::EnableWidgetsforTimingMode() {
FILE_LOG(logDEBUG) << "Enabling Widgets for Timing Mode";
LOG(logDEBUG) << "Enabling Widgets for Timing Mode";
// default
lblNumFrames->setEnabled(false);
@ -251,11 +266,13 @@ void qTabMeasurement::EnableWidgetsforTimingMode() {
}
void qTabMeasurement::GetTimingMode() {
FILE_LOG(logDEBUG) << "Getting timing mode";
disconnect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTimingMode(int)));
LOG(logDEBUG) << "Getting timing mode";
disconnect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetTimingMode(int)));
try {
auto oldMode = comboTimingMode->currentIndex();
auto retval = det->getTimingMode().tsquash("Inconsistent timing mode for all detectors.");
auto retval = det->getTimingMode().tsquash(
"Inconsistent timing mode for all detectors.");
switch (retval) {
case slsDetectorDefs::AUTO_TIMING:
case slsDetectorDefs::TRIGGER_EXPOSURE:
@ -268,153 +285,218 @@ void qTabMeasurement::GetTimingMode() {
}
break;
default:
throw sls::RuntimeError(std::string("Unknown timing mode: ")+ std::to_string(retval));
throw sls::RuntimeError(std::string("Unknown timing mode: ") +
std::to_string(retval));
}
} CATCH_DISPLAY("Could not get timing mode.", "qTabMeasurement::GetTimingMode")
connect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTimingMode(int)));
}
CATCH_DISPLAY("Could not get timing mode.",
"qTabMeasurement::GetTimingMode")
connect(comboTimingMode, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetTimingMode(int)));
}
void qTabMeasurement::SetTimingMode(int val) {
FILE_LOG(logINFO) << "Setting timing mode:" << comboTimingMode->currentText().toAscii().data();
LOG(logINFO) << "Setting timing mode:"
<< comboTimingMode->currentText().toAscii().data();
try {
det->setTimingMode(static_cast<slsDetectorDefs::timingMode>(val));
EnableWidgetsforTimingMode();
} CATCH_HANDLE("Could not set timing mode.", "qTabMeasurement::SetTimingMode", this, &qTabMeasurement::GetTimingMode)
}
CATCH_HANDLE("Could not set timing mode.", "qTabMeasurement::SetTimingMode",
this, &qTabMeasurement::GetTimingMode)
}
void qTabMeasurement::SetNumMeasurements(int val) {
FILE_LOG(logINFO) << "Setting Number of Measurements to " << val;
LOG(logINFO) << "Setting Number of Measurements to " << val;
numMeasurements = val;
}
void qTabMeasurement::GetNumFrames() {
FILE_LOG(logDEBUG) << "Getting number of frames";
disconnect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(SetNumFrames(int)));
LOG(logDEBUG) << "Getting number of frames";
disconnect(spinNumFrames, SIGNAL(valueChanged(int)), this,
SLOT(SetNumFrames(int)));
try {
auto retval = det->getNumberOfFrames().tsquash("Inconsistent number of frames for all detectors.");
auto retval = det->getNumberOfFrames().tsquash(
"Inconsistent number of frames for all detectors.");
spinNumFrames->setValue(retval);
} CATCH_DISPLAY ("Could not get number of frames.", "qTabMeasurement::GetNumFrames")
connect(spinNumFrames, SIGNAL(valueChanged(int)), this, SLOT(SetNumFrames(int)));
}
CATCH_DISPLAY("Could not get number of frames.",
"qTabMeasurement::GetNumFrames")
connect(spinNumFrames, SIGNAL(valueChanged(int)), this,
SLOT(SetNumFrames(int)));
}
void qTabMeasurement::SetNumFrames(int val) {
FILE_LOG(logINFO) << "Setting number of frames to " << val;
LOG(logINFO) << "Setting number of frames to " << val;
try {
det->setNumberOfFrames(val);
} CATCH_HANDLE("Could not set number of frames.", "qTabMeasurement::SetNumFrames", this, &qTabMeasurement::GetNumFrames)
}
CATCH_HANDLE("Could not set number of frames.",
"qTabMeasurement::SetNumFrames", this,
&qTabMeasurement::GetNumFrames)
}
void qTabMeasurement::GetNumTriggers() {
FILE_LOG(logDEBUG) << "Getting number of triggers";
disconnect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(SetNumTriggers(int)));
LOG(logDEBUG) << "Getting number of triggers";
disconnect(spinNumTriggers, SIGNAL(valueChanged(int)), this,
SLOT(SetNumTriggers(int)));
try {
auto retval = det->getNumberOfTriggers().tsquash("Inconsistent number of triggers for all detectors.");
auto retval = det->getNumberOfTriggers().tsquash(
"Inconsistent number of triggers for all detectors.");
spinNumTriggers->setValue(retval);
} CATCH_DISPLAY ("Could not get number of frames.", "qTabMeasurement::GetNumTriggers")
connect(spinNumTriggers, SIGNAL(valueChanged(int)), this, SLOT(SetNumTriggers(int)));
}
CATCH_DISPLAY("Could not get number of frames.",
"qTabMeasurement::GetNumTriggers")
connect(spinNumTriggers, SIGNAL(valueChanged(int)), this,
SLOT(SetNumTriggers(int)));
}
void qTabMeasurement::SetNumTriggers(int val) {
FILE_LOG(logINFO) << "Setting number of triggers to " << val;
LOG(logINFO) << "Setting number of triggers to " << val;
try {
det->setNumberOfTriggers(val);
} CATCH_HANDLE("Could not set number of triggers.", "qTabMeasurement::SetNumTriggers", this, &qTabMeasurement::GetNumTriggers)
}
CATCH_HANDLE("Could not set number of triggers.",
"qTabMeasurement::SetNumTriggers", this,
&qTabMeasurement::GetNumTriggers)
}
void qTabMeasurement::GetNumBursts() {
FILE_LOG(logDEBUG) << "Getting number of bursts";
disconnect(spinNumBursts, SIGNAL(valueChanged(int)), this, SLOT(SetNumBursts(int)));
LOG(logDEBUG) << "Getting number of bursts";
disconnect(spinNumBursts, SIGNAL(valueChanged(int)), this,
SLOT(SetNumBursts(int)));
try {
auto retval = det->getNumberOfBursts().tsquash("Inconsistent number of bursts for all detectors.");
auto retval = det->getNumberOfBursts().tsquash(
"Inconsistent number of bursts for all detectors.");
spinNumBursts->setValue(retval);
} CATCH_DISPLAY ("Could not get number of frames.", "qTabMeasurement::GetNumBursts")
connect(spinNumBursts, SIGNAL(valueChanged(int)), this, SLOT(SetNumBursts(int)));
}
CATCH_DISPLAY("Could not get number of frames.",
"qTabMeasurement::GetNumBursts")
connect(spinNumBursts, SIGNAL(valueChanged(int)), this,
SLOT(SetNumBursts(int)));
}
void qTabMeasurement::SetNumBursts(int val) {
FILE_LOG(logINFO) << "Setting number of bursts to " << val;
LOG(logINFO) << "Setting number of bursts to " << val;
try {
det->setNumberOfBursts(val);
} CATCH_HANDLE("Could not set number of bursts.", "qTabMeasurement::SetNumBursts", this, &qTabMeasurement::GetNumBursts)
}
CATCH_HANDLE("Could not set number of bursts.",
"qTabMeasurement::SetNumBursts", this,
&qTabMeasurement::GetNumBursts)
}
void qTabMeasurement::GetNumSamples() {
FILE_LOG(logDEBUG) << "Getting number of samples";
disconnect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(SetNumSamples(int)));
LOG(logDEBUG) << "Getting number of samples";
disconnect(spinNumSamples, SIGNAL(valueChanged(int)), this,
SLOT(SetNumSamples(int)));
try {
auto retval = det->getNumberOfAnalogSamples().tsquash("Inconsistent number of analog samples for all detectors.");
auto retval = det->getNumberOfAnalogSamples().tsquash(
"Inconsistent number of analog samples for all detectors.");
spinNumSamples->setValue(retval);
} CATCH_DISPLAY ("Could not get number of samples.", "qTabMeasurement::GetNumSamples")
connect(spinNumSamples, SIGNAL(valueChanged(int)), this, SLOT(SetNumSamples(int)));
}
CATCH_DISPLAY("Could not get number of samples.",
"qTabMeasurement::GetNumSamples")
connect(spinNumSamples, SIGNAL(valueChanged(int)), this,
SLOT(SetNumSamples(int)));
}
void qTabMeasurement::SetNumSamples(int val) {
FILE_LOG(logINFO) << "Setting number of samples to " << val;
LOG(logINFO) << "Setting number of samples to " << val;
try {
det->setNumberOfAnalogSamples(val);
} CATCH_HANDLE("Could not set number of samples.", "qTabMeasurement::SetNumSamples", this, &qTabMeasurement::GetNumSamples)
}
CATCH_HANDLE("Could not set number of samples.",
"qTabMeasurement::SetNumSamples", this,
&qTabMeasurement::GetNumSamples)
}
void qTabMeasurement::GetExposureTime() {
FILE_LOG(logDEBUG) << "Getting exposure time";
disconnect(spinExpTime, SIGNAL(valueChanged(double)), this, SLOT(SetExposureTime()));
disconnect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetExposureTime()));
LOG(logDEBUG) << "Getting exposure time";
disconnect(spinExpTime, SIGNAL(valueChanged(double)), this,
SLOT(SetExposureTime()));
disconnect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetExposureTime()));
try {
spinExpTime->setValue(-1);
auto retval = det->getExptime().tsquash("Inconsistent exposure time for all detectors.");
auto retval = det->getExptime().tsquash(
"Inconsistent exposure time for all detectors.");
auto time = qDefs::getUserFriendlyTime(retval);
spinExpTime->setValue(time.first);
comboExpUnit->setCurrentIndex(static_cast<int>(time.second));
CheckAcqPeriodGreaterThanExp();
} CATCH_DISPLAY ("Could not get exposure time.", "qTabMeasurement::GetExposureTime")
connect(spinExpTime, SIGNAL(valueChanged(double)), this, SLOT(SetExposureTime()));
connect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetExposureTime()));
}
CATCH_DISPLAY("Could not get exposure time.",
"qTabMeasurement::GetExposureTime")
connect(spinExpTime, SIGNAL(valueChanged(double)), this,
SLOT(SetExposureTime()));
connect(comboExpUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetExposureTime()));
}
void qTabMeasurement::SetExposureTime() {
auto val = spinExpTime->value();
auto unit = static_cast<qDefs::timeUnit>(comboExpUnit->currentIndex());
FILE_LOG(logINFO) << "Setting exposure time to " << val << " " << qDefs::getUnitString(unit);
LOG(logINFO) << "Setting exposure time to " << val << " "
<< qDefs::getUnitString(unit);
try {
auto timeNS = qDefs::getNSTime(std::make_pair(val, unit));
det->setExptime(timeNS);
CheckAcqPeriodGreaterThanExp();
} CATCH_HANDLE("Could not set exposure time.", "qTabMeasurement::SetExposureTime", this, &qTabMeasurement::GetExposureTime)
}
CATCH_HANDLE("Could not set exposure time.",
"qTabMeasurement::SetExposureTime", this,
&qTabMeasurement::GetExposureTime)
}
void qTabMeasurement::GetAcquisitionPeriod() {
FILE_LOG(logDEBUG) << "Getting acquisition period";
disconnect(spinPeriod, SIGNAL(valueChanged(double)), this, SLOT(SetAcquisitionPeriod()));
disconnect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetAcquisitionPeriod()));
LOG(logDEBUG) << "Getting acquisition period";
disconnect(spinPeriod, SIGNAL(valueChanged(double)), this,
SLOT(SetAcquisitionPeriod()));
disconnect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetAcquisitionPeriod()));
try {
spinPeriod->setValue(-1);
auto retval = det->getPeriod().tsquash("Inconsistent acquisition period for all detectors.");
auto retval = det->getPeriod().tsquash(
"Inconsistent acquisition period for all detectors.");
auto time = qDefs::getUserFriendlyTime(retval);
spinPeriod->setValue(time.first);
comboPeriodUnit->setCurrentIndex(static_cast<int>(time.second));
CheckAcqPeriodGreaterThanExp();
} CATCH_DISPLAY ("Could not get acquisition period.", "qTabMeasurement::GetAcquisitionPeriod")
connect(spinPeriod, SIGNAL(valueChanged(double)), this, SLOT(SetAcquisitionPeriod()));
connect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetAcquisitionPeriod()));
}
CATCH_DISPLAY("Could not get acquisition period.",
"qTabMeasurement::GetAcquisitionPeriod")
connect(spinPeriod, SIGNAL(valueChanged(double)), this,
SLOT(SetAcquisitionPeriod()));
connect(comboPeriodUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetAcquisitionPeriod()));
}
void qTabMeasurement::SetAcquisitionPeriod() {
auto val = spinPeriod->value();
auto unit = static_cast<qDefs::timeUnit>(comboPeriodUnit->currentIndex());
FILE_LOG(logINFO) << "Setting acquisition period to " << val << " " << qDefs::getUnitString(unit);
LOG(logINFO) << "Setting acquisition period to " << val << " "
<< qDefs::getUnitString(unit);
try {
auto timeNS = qDefs::getNSTime(std::make_pair(val, unit));
det->setPeriod(timeNS);
CheckAcqPeriodGreaterThanExp();
} CATCH_HANDLE("Could not set acquisition period.", "qTabMeasurement::SetAcquisitionPeriod", this, &qTabMeasurement::GetAcquisitionPeriod)
}
CATCH_HANDLE("Could not set acquisition period.",
"qTabMeasurement::SetAcquisitionPeriod", this,
&qTabMeasurement::GetAcquisitionPeriod)
}
void qTabMeasurement::CheckAcqPeriodGreaterThanExp() {
FILE_LOG(logDEBUG) << "Checking period >= exptime";
LOG(logDEBUG) << "Checking period >= exptime";
bool error = false;
if (lblPeriod->isEnabled()) {
auto exptimeNS = qDefs::getNSTime(std::make_pair(spinExpTime->value(), static_cast<qDefs::timeUnit>(comboExpUnit->currentIndex())));
auto acqtimeNS = qDefs::getNSTime(std::make_pair(spinPeriod->value(), static_cast<qDefs::timeUnit>(comboPeriodUnit->currentIndex())));
auto exptimeNS = qDefs::getNSTime(std::make_pair(
spinExpTime->value(),
static_cast<qDefs::timeUnit>(comboExpUnit->currentIndex())));
auto acqtimeNS = qDefs::getNSTime(std::make_pair(
spinPeriod->value(),
static_cast<qDefs::timeUnit>(comboPeriodUnit->currentIndex())));
if (exptimeNS > acqtimeNS) {
error = true;
spinPeriod->setToolTip(errPeriodTip);
@ -433,145 +515,191 @@ void qTabMeasurement::CheckAcqPeriodGreaterThanExp() {
}
void qTabMeasurement::GetDelay() {
FILE_LOG(logDEBUG) << "Getting delay";
LOG(logDEBUG) << "Getting delay";
disconnect(spinDelay, SIGNAL(valueChanged(double)), this, SLOT(SetDelay()));
disconnect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetDelay()));
disconnect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetDelay()));
try {
spinDelay->setValue(-1);
auto retval = det->getDelayAfterTrigger().tsquash("Inconsistent delay for all detectors.");
auto retval = det->getDelayAfterTrigger().tsquash(
"Inconsistent delay for all detectors.");
auto time = qDefs::getUserFriendlyTime(retval);
spinDelay->setValue(time.first);
comboDelayUnit->setCurrentIndex(static_cast<int>(time.second));
} CATCH_DISPLAY ("Could not get delay.", "qTabMeasurement::GetDelay")
}
CATCH_DISPLAY("Could not get delay.", "qTabMeasurement::GetDelay")
connect(spinDelay, SIGNAL(valueChanged(double)), this, SLOT(SetDelay()));
connect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetDelay()));
connect(comboDelayUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetDelay()));
}
void qTabMeasurement::SetDelay() {
auto val = spinDelay->value();
auto unit = static_cast<qDefs::timeUnit>(comboDelayUnit->currentIndex());
FILE_LOG(logINFO) << "Setting delay to " << val << " " << qDefs::getUnitString(unit);
LOG(logINFO) << "Setting delay to " << val << " "
<< qDefs::getUnitString(unit);
try {
auto timeNS = qDefs::getNSTime(std::make_pair(val, unit));
det->setDelayAfterTrigger(timeNS);
} CATCH_HANDLE("Could not set delay.", "qTabMeasurement::SetDelay", this, &qTabMeasurement::GetDelay)
}
CATCH_HANDLE("Could not set delay.", "qTabMeasurement::SetDelay", this,
&qTabMeasurement::GetDelay)
}
void qTabMeasurement::GetBurstPeriod() {
FILE_LOG(logDEBUG) << "Getting Burst Period";
disconnect(spinBurstPeriod, SIGNAL(valueChanged(double)), this, SLOT(SetBurstPeriod()));
disconnect(comboBurstPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetBurstPeriod()));
LOG(logDEBUG) << "Getting Burst Period";
disconnect(spinBurstPeriod, SIGNAL(valueChanged(double)), this,
SLOT(SetBurstPeriod()));
disconnect(comboBurstPeriodUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetBurstPeriod()));
try {
spinBurstPeriod->setValue(-1);
auto retval = det->getBurstPeriod().tsquash("Inconsistent burst period for all detectors.");
auto retval = det->getBurstPeriod().tsquash(
"Inconsistent burst period for all detectors.");
auto time = qDefs::getUserFriendlyTime(retval);
spinBurstPeriod->setValue(time.first);
comboBurstPeriodUnit->setCurrentIndex(static_cast<int>(time.second));
} CATCH_DISPLAY ("Could not get burst period.", "qTabMeasurement::GetBurstPeriod")
connect(spinBurstPeriod, SIGNAL(valueChanged(double)), this, SLOT(SetBurstPeriod()));
connect(comboBurstPeriodUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetBurstPeriod()));
}
CATCH_DISPLAY("Could not get burst period.",
"qTabMeasurement::GetBurstPeriod")
connect(spinBurstPeriod, SIGNAL(valueChanged(double)), this,
SLOT(SetBurstPeriod()));
connect(comboBurstPeriodUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetBurstPeriod()));
}
void qTabMeasurement::SetBurstPeriod() {
auto val = spinBurstPeriod->value();
auto unit = static_cast<qDefs::timeUnit>(comboBurstPeriodUnit->currentIndex());
FILE_LOG(logINFO) << "Setting burst period to " << val << " " << qDefs::getUnitString(unit);
auto unit =
static_cast<qDefs::timeUnit>(comboBurstPeriodUnit->currentIndex());
LOG(logINFO) << "Setting burst period to " << val << " "
<< qDefs::getUnitString(unit);
try {
auto timeNS = qDefs::getNSTime(std::make_pair(val, unit));
det->setBurstPeriod(timeNS);
} CATCH_HANDLE("Could not set burst period.", "qTabMeasurement::SetBurstPeriod", this, &qTabMeasurement::GetBurstPeriod)
}
CATCH_HANDLE("Could not set burst period.",
"qTabMeasurement::SetBurstPeriod", this,
&qTabMeasurement::GetBurstPeriod)
}
void qTabMeasurement::GetFileWrite() {
FILE_LOG(logDEBUG) << "Getting File Write Enable";
LOG(logDEBUG) << "Getting File Write Enable";
disconnect(chkFile, SIGNAL(toggled(bool)), this, SLOT(SetFileWrite(bool)));
try {
dispFileName->setEnabled(true); // default, even when exception
lblIndex->setEnabled(true);
spinIndex->setEnabled(true);
auto retval = det->getFileWrite().tsquash("Inconsistent file write for all detectors.");
auto retval = det->getFileWrite().tsquash(
"Inconsistent file write for all detectors.");
chkFile->setChecked(retval);
dispFileName->setEnabled(retval);
lblIndex->setEnabled(retval);
spinIndex->setEnabled(retval);
} CATCH_DISPLAY ("Could not get file over write enable.", "qTabMeasurement::GetFileWrite")
}
CATCH_DISPLAY("Could not get file over write enable.",
"qTabMeasurement::GetFileWrite")
connect(chkFile, SIGNAL(toggled(bool)), this, SLOT(SetFileWrite(bool)));
}
void qTabMeasurement::SetFileWrite(bool val) {
FILE_LOG(logINFO) << "Set File Write to " << val;
LOG(logINFO) << "Set File Write to " << val;
try {
det->setFileWrite(val);
dispFileName->setEnabled(val);
lblIndex->setEnabled(val);
spinIndex->setEnabled(val);
} CATCH_HANDLE("Could not set file write enable.", "qTabMeasurement::SetFileWrite", this, &qTabMeasurement::GetFileWrite)
}
CATCH_HANDLE("Could not set file write enable.",
"qTabMeasurement::SetFileWrite", this,
&qTabMeasurement::GetFileWrite)
}
void qTabMeasurement::GetFileName() {
FILE_LOG(logDEBUG) << "Getting file name prefix";
disconnect(dispFileName, SIGNAL(editingFinished()), this, SLOT(SetFileName()));
LOG(logDEBUG) << "Getting file name prefix";
disconnect(dispFileName, SIGNAL(editingFinished()), this,
SLOT(SetFileName()));
try {
auto retval = det->getFileNamePrefix().tsquash("Inconsistent file name prefix for all detectors.");
auto retval = det->getFileNamePrefix().tsquash(
"Inconsistent file name prefix for all detectors.");
dispFileName->setText(QString(retval.c_str()));
} CATCH_DISPLAY ("Could not get file name prefix.", "qTabMeasurement::GetFileName")
}
CATCH_DISPLAY("Could not get file name prefix.",
"qTabMeasurement::GetFileName")
connect(dispFileName, SIGNAL(editingFinished()), this, SLOT(SetFileName()));
}
void qTabMeasurement::SetFileName() {
std::string val = std::string(dispFileName->text().toAscii().constData());
FILE_LOG(logINFO) << "Setting File Name Prefix:" << val;
LOG(logINFO) << "Setting File Name Prefix:" << val;
try {
det->setFileNamePrefix(val);
} CATCH_HANDLE("Could not set file name prefix.", "qTabMeasurement::SetFileName", this, &qTabMeasurement::GetFileName)
}
CATCH_HANDLE("Could not set file name prefix.",
"qTabMeasurement::SetFileName", this,
&qTabMeasurement::GetFileName)
emit FileNameChangedSignal(dispFileName->text());
}
void qTabMeasurement::GetRunIndex() {
FILE_LOG(logDEBUG) << "Getting Acquisition File index";
disconnect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(SetRunIndex(int)));
LOG(logDEBUG) << "Getting Acquisition File index";
disconnect(spinIndex, SIGNAL(valueChanged(int)), this,
SLOT(SetRunIndex(int)));
try {
auto retval = det->getAcquisitionIndex().tsquash("Inconsistent file index for all detectors.");
auto retval = det->getAcquisitionIndex().tsquash(
"Inconsistent file index for all detectors.");
spinIndex->setValue(retval);
} CATCH_DISPLAY ("Could not get acquisition file index.", "qTabMeasurement::GetRunIndex")
}
CATCH_DISPLAY("Could not get acquisition file index.",
"qTabMeasurement::GetRunIndex")
connect(spinIndex, SIGNAL(valueChanged(int)), this, SLOT(SetRunIndex(int)));
}
void qTabMeasurement::SetRunIndex(int val) {
FILE_LOG(logINFO) << "Setting Acquisition File Index to " << val;
LOG(logINFO) << "Setting Acquisition File Index to " << val;
try {
det->setAcquisitionIndex(val);
} CATCH_HANDLE("Could not set acquisition file index.", "qTabMeasurement::SetRunIndex", this, &qTabMeasurement::GetRunIndex)
}
CATCH_HANDLE("Could not set acquisition file index.",
"qTabMeasurement::SetRunIndex", this,
&qTabMeasurement::GetRunIndex)
}
void qTabMeasurement::GetStartingFrameNumber() {
FILE_LOG(logDEBUG) << "Getting Starting Frame Number";
disconnect(spinStartingFrameNumber, SIGNAL(valueChanged(int)), this, SLOT(SetStartingFrameNumber(int)));
LOG(logDEBUG) << "Getting Starting Frame Number";
disconnect(spinStartingFrameNumber, SIGNAL(valueChanged(int)), this,
SLOT(SetStartingFrameNumber(int)));
try {
auto retval = det->getStartingFrameNumber().tsquash("Inconsistent starting frame number for all detectors.");
auto retval = det->getStartingFrameNumber().tsquash(
"Inconsistent starting frame number for all detectors.");
spinStartingFrameNumber->setValue(retval);
} CATCH_DISPLAY ("Could not get starting frame number.", "qTabMeasurement::GetStartingFrameNumber")
connect(spinStartingFrameNumber, SIGNAL(valueChanged(int)), this, SLOT(SetStartingFrameNumber(int)));
}
CATCH_DISPLAY("Could not get starting frame number.",
"qTabMeasurement::GetStartingFrameNumber")
connect(spinStartingFrameNumber, SIGNAL(valueChanged(int)), this,
SLOT(SetStartingFrameNumber(int)));
}
void qTabMeasurement::SetStartingFrameNumber(int val) {
FILE_LOG(logINFO) << "Setting Starting frame number to " << val;
LOG(logINFO) << "Setting Starting frame number to " << val;
try {
det->setStartingFrameNumber(val);
} CATCH_HANDLE("Could not set starting frame number.", "qTabMeasurement::SetStartingFrameNumber", this, &qTabMeasurement::GetStartingFrameNumber)
}
CATCH_HANDLE("Could not set starting frame number.",
"qTabMeasurement::SetStartingFrameNumber", this,
&qTabMeasurement::GetStartingFrameNumber)
}
void qTabMeasurement::ResetProgress() {
FILE_LOG(logDEBUG) << "Resetting progress";
LOG(logDEBUG) << "Resetting progress";
lblCurrentFrame->setText("0");
lblCurrentMeasurement->setText("0");
progressBar->setValue(0);
}
void qTabMeasurement::UpdateProgress() {
FILE_LOG(logDEBUG) << "Updating progress";
LOG(logDEBUG) << "Updating progress";
progressBar->setValue(plot->GetProgress());
lblCurrentFrame->setText(QString::number(plot->GetCurrentFrameIndex()));
lblCurrentMeasurement->setText(QString::number(currentMeasurement));
@ -584,29 +712,36 @@ int qTabMeasurement::VerifyOutputDirectoryError() {
det->setFilePath(it);
}
return slsDetectorDefs::OK;
} CATCH_DISPLAY ("Could not set path.", "qTabMeasurement::VerifyOutputDirectoryError")
}
CATCH_DISPLAY("Could not set path.",
"qTabMeasurement::VerifyOutputDirectoryError")
return slsDetectorDefs::FAIL; // for exception
}
void qTabMeasurement::StartAcquisition() {
btnStart->setEnabled(false);
// if file write enabled and output dir doesnt exist
if ((chkFile->isChecked()) && (VerifyOutputDirectoryError() == slsDetectorDefs::FAIL)) {
if (qDefs::Message(qDefs::QUESTION,
"<nobr>Your data will not be saved.</nobr><br><nobr>Disable File write and Proceed with acquisition anyway?</nobr>",
if ((chkFile->isChecked()) &&
(VerifyOutputDirectoryError() == slsDetectorDefs::FAIL)) {
if (qDefs::Message(
qDefs::QUESTION,
"<nobr>Your data will not be saved.</nobr><br><nobr>Disable "
"File write and Proceed with acquisition anyway?</nobr>",
"qTabMeasurement::StartAcquisition") == slsDetectorDefs::FAIL) {
btnStart->setEnabled(true);
return;
} else {
disconnect(chkFile, SIGNAL(toggled(bool)), this, SLOT(SetFileWrite(bool)));
disconnect(chkFile, SIGNAL(toggled(bool)), this,
SLOT(SetFileWrite(bool)));
chkFile->setChecked(false);
// cannot wait for signals from chkFile
SetFileWrite(false);
connect(chkFile, SIGNAL(toggled(bool)), this, SLOT(SetFileWrite(bool)));
connect(chkFile, SIGNAL(toggled(bool)), this,
SLOT(SetFileWrite(bool)));
}
}
FILE_LOG(logINFOBLUE) << "Starting Acquisition";
LOG(logINFOBLUE) << "Starting Acquisition";
plot->SetRunning(true);
isAcquisitionStopped = false;
currentMeasurement = 0;
@ -617,27 +752,30 @@ void qTabMeasurement::StartAcquisition() {
emit EnableTabsSignal(false);
}
void qTabMeasurement::StopAcquisition() {
FILE_LOG(logINFORED) << "Stopping Acquisition";
LOG(logINFORED) << "Stopping Acquisition";
try {
isAcquisitionStopped = true;
det->stopDetector();
} CATCH_DISPLAY("Could not stop acquisition.", "qTabMeasurement::StopAcquisition")
}
CATCH_DISPLAY("Could not stop acquisition.",
"qTabMeasurement::StopAcquisition")
}
void qTabMeasurement::AcquireFinished() {
// to catch only once (if abort acquire also calls acq finished call back)
if (!btnStart->isEnabled()) {
FILE_LOG(logDEBUG) << "Acquire Finished";
LOG(logDEBUG) << "Acquire Finished";
UpdateProgress();
GetRunIndex();
if (startingFnumImplemented) {
GetStartingFrameNumber();
}
FILE_LOG(logDEBUG) << "Measurement " << currentMeasurement << " finished";
LOG(logDEBUG) << "Measurement " << currentMeasurement
<< " finished";
// next measurement if acq is not stopped
if (!isAcquisitionStopped && ((currentMeasurement + 1) < numMeasurements)) {
if (!isAcquisitionStopped &&
((currentMeasurement + 1) < numMeasurements)) {
++currentMeasurement;
plot->StartAcquisition();
}
@ -653,7 +791,7 @@ void qTabMeasurement::AcquireFinished() {
}
void qTabMeasurement::AbortAcquire() {
FILE_LOG(logINFORED) << "Abort Acquire";
LOG(logINFORED) << "Abort Acquire";
isAcquisitionStopped = true;
AcquireFinished();
}
@ -663,11 +801,12 @@ void qTabMeasurement::Enable(bool enable) {
frameNotTimeResolved->setEnabled(enable);
// shortcut each time, else it doesnt work a second time
btnStart->setShortcut(QApplication::translate("TabMeasurementObject", "Shift+Space", 0, QApplication::UnicodeUTF8));
btnStart->setShortcut(QApplication::translate(
"TabMeasurementObject", "Shift+Space", nullptr, QApplication::UnicodeUTF8));
}
void qTabMeasurement::Refresh() {
FILE_LOG(logDEBUG) << "**Updating Measurement Tab";
LOG(logDEBUG) << "**Updating Measurement Tab";
if (!plot->GetIsRunning()) {
GetTimingMode();
@ -696,5 +835,5 @@ void qTabMeasurement::Refresh() {
ResetProgress();
}
FILE_LOG(logDEBUG) << "**Updated Measurement Tab";
LOG(logDEBUG) << "**Updated Measurement Tab";
}

67
slsDetectorGui/src/qTabMessages.cpp Executable file → Normal file
View File

@ -1,25 +1,22 @@
#include "qTabMessages.h"
#include "qDefs.h"
#include <QDir>
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QDir>
#include <QProcess>
#include <QKeyEvent>
#include <iostream>
#include <QProcess>
#include <QTextStream>
#include <string>
qTabMessages::qTabMessages(QWidget *parent) : QWidget(parent) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Messages ready";
LOG(logDEBUG) << "Messages ready";
}
qTabMessages::~qTabMessages() {
process->close();
if (process)
delete process;
}
@ -42,28 +39,28 @@ void qTabMessages::keyPressEvent(QKeyEvent* event) {
// cout<<"inside KeyPressEvent()\n";
if (event->key() == Qt::Key_Up) {
GetLastCommand();
}
else if (event->key() == Qt::Key_Down) {
} else if (event->key() == Qt::Key_Down) {
ClearCommand();
}
/* else if((event->key() == Qt::Key_Return) ||(event->key() == Qt::Key_Enter)) {
ExecuteCommand();
}*/ else {
/* else if((event->key() == Qt::Key_Return) ||(event->key() ==
Qt::Key_Enter)) { ExecuteCommand();
}*/
else {
event->ignore();
}
}
void qTabMessages::PrintNextLine() {
dispLog->append(QString("<font color = \"DarkGrey\">") + QDir::current().dirName() + QString("$ ") + QString("</font>"));
dispLog->append(QString("<font color = \"DarkGrey\">") +
QDir::current().dirName() + QString("$ ") +
QString("</font>"));
}
void qTabMessages::GetLastCommand() {
dispCommand->setText(lastCommand.join(" "));
}
void qTabMessages::ClearCommand() {
dispCommand->setText("");
}
void qTabMessages::ClearCommand() { dispCommand->setText(""); }
void qTabMessages::ExecuteCommand() {
QStringList param = dispCommand->text().split(" ");
@ -72,11 +69,14 @@ void qTabMessages::ExecuteCommand() {
dispCommand->clear();
// appending command to log without newline
dispLog->moveCursor(QTextCursor::End);
dispLog->insertHtml(QString("<font color = \"DarkBlue\">") + param.join(" ") + QString("</font>"));
dispLog->insertHtml(QString("<font color = \"DarkBlue\">") +
param.join(" ") + QString("</font>"));
QString command = param.at(0);
param.removeFirst();
FILE_LOG(logINFO) << "Executing Command:[" << command.toAscii().constData() << "] with Arguments:[" << param.join(" ").toAscii().constData() << "]";
LOG(logINFO) << "Executing Command:[" << command.toAscii().constData()
<< "] with Arguments:["
<< param.join(" ").toAscii().constData() << "]";
process->setProcessChannelMode(QProcess::MergedChannels);
process->start(command, param);
@ -90,34 +90,40 @@ void qTabMessages::ExecuteCommand() {
void qTabMessages::AppendOutput() {
QByteArray result = process->readAll();
result.replace("\n", "<br>");
dispLog->append(QString("<font color = \"DarkBlue\">") + result + QString("</font>"));
FILE_LOG(logDEBUG) << "Command executed successfully";
dispLog->append(QString("<font color = \"DarkBlue\">") + result +
QString("</font>"));
LOG(logDEBUG) << "Command executed successfully";
PrintNextLine();
}
void qTabMessages::AppendError() {
dispLog->append(QString("<font color = \"Red\">") + process->errorString() + QString("</font>"));
FILE_LOG(logERROR) << "Error executing command";
dispLog->append(QString("<font color = \"Red\">") + process->errorString() +
QString("</font>"));
LOG(logERROR) << "Error executing command";
PrintNextLine();
}
void qTabMessages::SaveLog() {
QString fName = QDir::cleanPath(QDir::currentPath()) + "/LogFile.txt";
fName = QFileDialog::getSaveFileName(this, tr("Save Snapshot "),
fName, tr("Text files (*.txt);;All Files(*)"));
fName =
QFileDialog::getSaveFileName(this, tr("Save Snapshot "), fName,
tr("Text files (*.txt);;All Files(*)"));
if (!fName.isEmpty()) {
QFile outfile;
outfile.setFileName(fName);
if (outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&outfile);
out << dispLog->toPlainText() << endl;
std::string mess = std::string("The Log has been successfully saved to ") + fName.toAscii().constData();
std::string mess =
std::string("The Log has been successfully saved to ") +
fName.toAscii().constData();
qDefs::Message(qDefs::INFORMATION, mess, "TabMessages::SaveLog");
FILE_LOG(logINFO) << mess;
LOG(logINFO) << mess;
} else {
FILE_LOG(logWARNING) << "Attempt to save log file failed: " << fName.toAscii().constData();
qDefs::Message(qDefs::WARNING, "Attempt to save log file failed.", "qTabMessages::SaveLog");
LOG(logWARNING) << "Attempt to save log file failed: "
<< fName.toAscii().constData();
qDefs::Message(qDefs::WARNING, "Attempt to save log file failed.",
"qTabMessages::SaveLog");
}
}
dispCommand->setFocus();
@ -125,7 +131,7 @@ void qTabMessages::SaveLog() {
void qTabMessages::ClearLog() {
dispLog->clear();
FILE_LOG(logINFO) << "Log Cleared";
LOG(logINFO) << "Log Cleared";
PrintNextLine();
dispCommand->setFocus();
}
@ -134,4 +140,3 @@ void qTabMessages::Refresh() {
dispCommand->clear();
dispCommand->setFocus();
}

325
slsDetectorGui/src/qTabPlot.cpp Executable file → Normal file
View File

@ -1,15 +1,11 @@
#include "qTabPlot.h"
#include "qDefs.h"
#include "qDrawPlot.h"
#include <QStandardItemModel>
#include <QStackedLayout>
#include <QButtonGroup>
#include <QAbstractButton>
#include <QButtonGroup>
#include <QStackedLayout>
#include <QStandardItemModel>
#include <iostream>
#include <math.h>
#include <string>
QString qTabPlot::defaultPlotTitle("");
QString qTabPlot::defaultHistXAxisTitle("Channel Number");
@ -18,18 +14,14 @@ QString qTabPlot::defaultImageXAxisTitle("Pixel");
QString qTabPlot::defaultImageYAxisTitle("Pixel");
QString qTabPlot::defaultImageZAxisTitle("Intensity");
qTabPlot::qTabPlot(QWidget *parent, sls::Detector *detector, qDrawPlot *p) :
QWidget(parent), det(detector), plot(p), is1d(false) {
qTabPlot::qTabPlot(QWidget *parent, sls::Detector *detector, qDrawPlot *p)
: QWidget(parent), det(detector), plot(p), is1d(false) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Plot ready";
LOG(logDEBUG) << "Plot ready";
}
qTabPlot::~qTabPlot() {
if (btnGroupPlotType)
delete btnGroupPlotType;
}
qTabPlot::~qTabPlot() { delete btnGroupPlotType; }
void qTabPlot::SetupWidgetWindow() {
// button group for plot type
@ -87,13 +79,18 @@ void qTabPlot::SetupWidgetWindow() {
void qTabPlot::Initialization() {
// Plot arguments box
connect(btnGroupPlotType, SIGNAL(buttonClicked(int)), this, SLOT(SetPlot()));
connect(btnGroupPlotType, SIGNAL(buttonClicked(int)), this,
SLOT(SetPlot()));
// Plotting frequency box
connect(comboFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
connect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
connect(spinTimeGap, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
connect(spinNthFrame, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
connect(comboFrequency, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
connect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
connect(spinTimeGap, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
connect(spinNthFrame, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
// navigation buttons for options
connect(btnRight1D, SIGNAL(clicked()), this, SLOT(Set1DPlotOptionsRight()));
@ -102,28 +99,40 @@ void qTabPlot::Initialization() {
connect(btnLeft2D, SIGNAL(clicked()), this, SLOT(Set2DPlotOptionsLeft()));
// 1D options
connect(chkSuperimpose, SIGNAL(toggled(bool)), this, SLOT(EnablePersistency(bool)));
connect(spinPersistency, SIGNAL(valueChanged(int)), plot, SLOT(SetPersistency(int)));
connect(chkSuperimpose, SIGNAL(toggled(bool)), this,
SLOT(EnablePersistency(bool)));
connect(spinPersistency, SIGNAL(valueChanged(int)), plot,
SLOT(SetPersistency(int)));
connect(chkPoints, SIGNAL(toggled(bool)), plot, SLOT(SetMarkers(bool)));
connect(chkLines, SIGNAL(toggled(bool)), plot, SLOT(SetLines(bool)));
connect(chk1DLog, SIGNAL(toggled(bool)), plot, SLOT(Set1dLogY(bool)));
connect(chkStatistics, SIGNAL(toggled(bool)), plot, SLOT(DisplayStatistics(bool)));
connect(chkStatistics, SIGNAL(toggled(bool)), plot,
SLOT(DisplayStatistics(bool)));
// 2D Plot box
connect(chkInterpolate, SIGNAL(toggled(bool)), plot, SLOT(SetInterpolate(bool)));
connect(chkInterpolate, SIGNAL(toggled(bool)), plot,
SLOT(SetInterpolate(bool)));
connect(chkContour, SIGNAL(toggled(bool)), plot, SLOT(SetContour(bool)));
connect(chkLogz, SIGNAL(toggled(bool)), plot, SLOT(SetLogz(bool)));
connect(chkStatistics_2, SIGNAL(toggled(bool)), plot, SLOT(DisplayStatistics(bool)));
connect(chkStatistics_2, SIGNAL(toggled(bool)), plot,
SLOT(DisplayStatistics(bool)));
// pedstal
connect(chkPedestal, SIGNAL(toggled(bool)), plot, SLOT(SetPedestal(bool)));
connect(btnRecalPedestal, SIGNAL(clicked()), plot, SLOT(RecalculatePedestal()));
connect(chkPedestal_2, SIGNAL(toggled(bool)), plot, SLOT(SetPedestal(bool)));
connect(btnRecalPedestal_2, SIGNAL(clicked()), plot, SLOT(RecalculatePedestal()));
connect(btnRecalPedestal, SIGNAL(clicked()), plot,
SLOT(RecalculatePedestal()));
connect(chkPedestal_2, SIGNAL(toggled(bool)), plot,
SLOT(SetPedestal(bool)));
connect(btnRecalPedestal_2, SIGNAL(clicked()), plot,
SLOT(RecalculatePedestal()));
// accumulate
connect(chkAccumulate, SIGNAL(toggled(bool)), plot, SLOT(SetAccumulate(bool)));
connect(btnResetAccumulate, SIGNAL(clicked()), plot, SLOT(ResetAccumulate()));
connect(chkAccumulate_2, SIGNAL(toggled(bool)), plot, SLOT(SetAccumulate(bool)));
connect(btnResetAccumulate_2, SIGNAL(clicked()), plot, SLOT(ResetAccumulate()));
connect(chkAccumulate, SIGNAL(toggled(bool)), plot,
SLOT(SetAccumulate(bool)));
connect(btnResetAccumulate, SIGNAL(clicked()), plot,
SLOT(ResetAccumulate()));
connect(chkAccumulate_2, SIGNAL(toggled(bool)), plot,
SLOT(SetAccumulate(bool)));
connect(btnResetAccumulate_2, SIGNAL(clicked()), plot,
SLOT(ResetAccumulate()));
// binary
connect(chkBinary, SIGNAL(toggled(bool)), this, SLOT(SetBinary()));
connect(chkBinary_2, SIGNAL(toggled(bool)), this, SLOT(SetBinary()));
@ -133,12 +142,15 @@ void qTabPlot::Initialization() {
connect(spinTo_2, SIGNAL(valueChanged(int)), this, SLOT(SetBinary()));
// gainplot
if (chkGainPlot->isEnabled())
connect(chkGainPlot, SIGNAL(toggled(bool)), plot, SLOT(EnableGainPlot(bool)));
connect(chkGainPlot, SIGNAL(toggled(bool)), plot,
SLOT(EnableGainPlot(bool)));
if (chkGainPlot1D->isEnabled())
connect(chkGainPlot1D, SIGNAL(toggled(bool)), plot, SLOT(EnableGainPlot(bool)));
connect(chkGainPlot1D, SIGNAL(toggled(bool)), plot,
SLOT(EnableGainPlot(bool)));
// gap pixels
if (chkGapPixels->isEnabled())
connect(chkGapPixels, SIGNAL(toggled(bool)), this, SLOT(SetGapPixels(bool)));
connect(chkGapPixels, SIGNAL(toggled(bool)), this,
SLOT(SetGapPixels(bool)));
// Save, clone
connect(btnSave, SIGNAL(clicked()), plot, SLOT(SavePlot()));
@ -149,10 +161,14 @@ void qTabPlot::Initialization() {
connect(chkXAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(chkYAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(chkZAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(dispTitle, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispXAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispYAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispZAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispTitle, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispXAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispYAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispZAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(chkXMin, SIGNAL(toggled(bool)), this, SLOT(SetXRange()));
connect(chkXMax, SIGNAL(toggled(bool)), this, SLOT(SetXRange()));
@ -162,7 +178,8 @@ void qTabPlot::Initialization() {
connect(dispXMax, SIGNAL(editingFinished()), this, SLOT(SetXRange()));
connect(dispYMin, SIGNAL(editingFinished()), this, SLOT(SetYRange()));
connect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetYRange()));
connect(chkAspectRatio, SIGNAL(toggled(bool)), this, SLOT(CheckAspectRatio()));
connect(chkAspectRatio, SIGNAL(toggled(bool)), this,
SLOT(CheckAspectRatio()));
connect(chkZMin, SIGNAL(toggled(bool)), this, SLOT(SetZRange()));
connect(chkZMax, SIGNAL(toggled(bool)), this, SLOT(SetZRange()));
@ -171,7 +188,7 @@ void qTabPlot::Initialization() {
}
void qTabPlot::Select1DPlot(bool enable) {
FILE_LOG(logDEBUG) << "Selecting " << (enable ? "1" : "2") << "D Plot";
LOG(logDEBUG) << "Selecting " << (enable ? "1" : "2") << "D Plot";
is1d = enable;
box1D->setEnabled(enable);
box2D->setEnabled(!enable);
@ -192,9 +209,9 @@ void qTabPlot::Select1DPlot(bool enable) {
void qTabPlot::SetPlot() {
bool plotEnable = false;
if (radioNoPlot->isChecked()) {
FILE_LOG(logINFO) << "Setting Plot Type: No Plot";
LOG(logINFO) << "Setting Plot Type: No Plot";
} else if (radioDataGraph->isChecked()) {
FILE_LOG(logINFO) << "Setting Plot Type: Datagraph";
LOG(logINFO) << "Setting Plot Type: Datagraph";
plotEnable = true;
}
boxFrequency->setEnabled(plotEnable);
@ -215,47 +232,51 @@ void qTabPlot::SetPlot() {
}
void qTabPlot::Set1DPlotOptionsRight() {
FILE_LOG(logDEBUG) << "1D Options Right";
LOG(logDEBUG) << "1D Options Right";
int i = stackedWidget1D->currentIndex();
if (i == (stackedWidget1D->count() - 1))
stackedWidget1D->setCurrentIndex(0);
else
stackedWidget1D->setCurrentIndex(i + 1);
box1D->setTitle(QString("1D Plot Options %1").arg(stackedWidget1D->currentIndex() + 1));
box1D->setTitle(
QString("1D Plot Options %1").arg(stackedWidget1D->currentIndex() + 1));
}
void qTabPlot::Set1DPlotOptionsLeft() {
FILE_LOG(logDEBUG) << "1D Options Left";
LOG(logDEBUG) << "1D Options Left";
int i = stackedWidget1D->currentIndex();
if (i == 0)
stackedWidget1D->setCurrentIndex(stackedWidget1D->count() - 1);
else
stackedWidget1D->setCurrentIndex(i - 1);
box1D->setTitle(QString("1D Plot Options %1").arg(stackedWidget1D->currentIndex() + 1));
box1D->setTitle(
QString("1D Plot Options %1").arg(stackedWidget1D->currentIndex() + 1));
}
void qTabPlot::Set2DPlotOptionsRight() {
FILE_LOG(logDEBUG) << "2D Options Right";
LOG(logDEBUG) << "2D Options Right";
int i = stackedWidget2D->currentIndex();
if (i == (stackedWidget2D->count() - 1))
stackedWidget2D->setCurrentIndex(0);
else
stackedWidget2D->setCurrentIndex(i + 1);
box2D->setTitle(QString("2D Plot Options %1").arg(stackedWidget2D->currentIndex() + 1));
box2D->setTitle(
QString("2D Plot Options %1").arg(stackedWidget2D->currentIndex() + 1));
}
void qTabPlot::Set2DPlotOptionsLeft() {
FILE_LOG(logDEBUG) << "2D Options Left";
LOG(logDEBUG) << "2D Options Left";
int i = stackedWidget2D->currentIndex();
if (i == 0)
stackedWidget2D->setCurrentIndex(stackedWidget2D->count() - 1);
else
stackedWidget2D->setCurrentIndex(i - 1);
box2D->setTitle(QString("2D Plot Options %1").arg(stackedWidget2D->currentIndex() + 1));
box2D->setTitle(
QString("2D Plot Options %1").arg(stackedWidget2D->currentIndex() + 1));
}
void qTabPlot::EnablePersistency(bool enable) {
FILE_LOG(logINFO) << "Superimpose " << (enable ? "enabled" : "disabled");
LOG(logINFO) << "Superimpose " << (enable ? "enabled" : "disabled");
lblPersistency->setEnabled(enable);
spinPersistency->setEnabled(enable);
if (enable)
@ -268,14 +289,16 @@ void qTabPlot::SetBinary() {
bool binary1D = chkBinary->isChecked();
bool binary2D = chkBinary_2->isChecked();
if (is1d) {
FILE_LOG(logINFO) << "Binary Plot " << (binary1D ? "enabled" : "disabled");
LOG(logINFO) << "Binary Plot "
<< (binary1D ? "enabled" : "disabled");
lblFrom->setEnabled(binary1D);
lblTo->setEnabled(binary1D);
spinFrom->setEnabled(binary1D);
spinTo->setEnabled(binary1D);
plot->SetBinary(binary1D, spinFrom->value(), spinTo->value());
} else {
FILE_LOG(logINFO) << "Binary Plot " << (binary2D ? "enabled" : "disabled");
LOG(logINFO) << "Binary Plot "
<< (binary2D ? "enabled" : "disabled");
lblFrom_2->setEnabled(binary2D);
lblTo_2->setEnabled(binary2D);
spinFrom_2->setEnabled(binary2D);
@ -285,32 +308,42 @@ void qTabPlot::SetBinary() {
}
void qTabPlot::GetGapPixels() {
FILE_LOG(logDEBUG) << "Getting gap pixels";
disconnect(chkGapPixels, SIGNAL(toggled(bool)), this, SLOT(SetGapPixels(bool)));
LOG(logDEBUG) << "Getting gap pixels";
disconnect(chkGapPixels, SIGNAL(toggled(bool)), this,
SLOT(SetGapPixels(bool)));
try {
auto retval = det->getRxAddGapPixels().tsquash("Inconsistent gap pixels enabled for all detectors.");
auto retval = det->getRxAddGapPixels().tsquash(
"Inconsistent gap pixels enabled for all detectors.");
chkGapPixels->setChecked(retval);
} CATCH_DISPLAY ("Could not get gap pixels enable.", "qTabPlot::GetGapPixels")
connect(chkGapPixels, SIGNAL(toggled(bool)), this, SLOT(SetGapPixels(bool)));
}
CATCH_DISPLAY("Could not get gap pixels enable.", "qTabPlot::GetGapPixels")
connect(chkGapPixels, SIGNAL(toggled(bool)), this,
SLOT(SetGapPixels(bool)));
}
void qTabPlot::SetGapPixels(bool enable) {
FILE_LOG(logINFO) << "Setting Gap Pixels Enable to " << enable;
LOG(logINFO) << "Setting Gap Pixels Enable to " << enable;
try {
det->setRxAddGapPixels(enable);
} CATCH_HANDLE("Could not set gap pixels enable.", "qTabPlot::SetGapPixels", this, &qTabPlot::GetGapPixels)
}
CATCH_HANDLE("Could not set gap pixels enable.", "qTabPlot::SetGapPixels",
this, &qTabPlot::GetGapPixels)
}
void qTabPlot::SetTitles() {
FILE_LOG(logDEBUG) << "Setting Plot Titles";
LOG(logDEBUG) << "Setting Plot Titles";
disconnect(chkTitle, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
disconnect(chkXAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
disconnect(chkYAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
disconnect(chkZAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
disconnect(dispTitle, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
disconnect(dispXAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
disconnect(dispYAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
disconnect(dispZAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
disconnect(dispTitle, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
disconnect(dispXAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
disconnect(dispYAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
disconnect(dispZAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
// title
if (!chkTitle->isChecked() || dispTitle->text().isEmpty()) {
@ -321,15 +354,19 @@ void qTabPlot::SetTitles() {
}
// x
if (!chkXAxis->isChecked() || dispXAxis->text().isEmpty()) {
dispXAxis->setText(is1d ? defaultHistXAxisTitle : defaultImageXAxisTitle);
plot->SetXAxisTitle(is1d ? defaultHistXAxisTitle : defaultImageXAxisTitle);
dispXAxis->setText(is1d ? defaultHistXAxisTitle
: defaultImageXAxisTitle);
plot->SetXAxisTitle(is1d ? defaultHistXAxisTitle
: defaultImageXAxisTitle);
} else {
plot->SetXAxisTitle(dispXAxis->text());
}
// y
if (!chkYAxis->isChecked() || dispYAxis->text().isEmpty()) {
dispYAxis->setText(is1d ? defaultHistYAxisTitle : defaultImageYAxisTitle);
plot->SetYAxisTitle(is1d ? defaultHistYAxisTitle : defaultImageYAxisTitle);
dispYAxis->setText(is1d ? defaultHistYAxisTitle
: defaultImageYAxisTitle);
plot->SetYAxisTitle(is1d ? defaultHistYAxisTitle
: defaultImageYAxisTitle);
} else {
plot->SetYAxisTitle(dispYAxis->text());
}
@ -345,14 +382,18 @@ void qTabPlot::SetTitles() {
connect(chkXAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(chkYAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(chkZAxis, SIGNAL(toggled(bool)), this, SLOT(SetTitles()));
connect(dispTitle, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispXAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispYAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispZAxis, SIGNAL(textChanged(const QString &)), this, SLOT(SetTitles()));
connect(dispTitle, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispXAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispYAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
connect(dispZAxis, SIGNAL(textChanged(const QString &)), this,
SLOT(SetTitles()));
}
void qTabPlot::SetXRange() {
FILE_LOG(logDEBUG) << "Enable X axis range";
LOG(logDEBUG) << "Enable X axis range";
if (chkAspectRatio->isChecked()) {
MaintainAspectRatio(static_cast<int>(slsDetectorDefs::Y));
@ -362,7 +403,7 @@ void qTabPlot::SetXRange() {
}
void qTabPlot::SetYRange() {
FILE_LOG(logDEBUG) << "Enable Y axis range";
LOG(logDEBUG) << "Enable Y axis range";
if (chkAspectRatio->isChecked()) {
MaintainAspectRatio(static_cast<int>(slsDetectorDefs::X));
@ -380,18 +421,23 @@ void qTabPlot::CheckAspectRatio() {
}
void qTabPlot::SetXYRange() {
FILE_LOG(logDEBUG) << "Set XY Range";
LOG(logDEBUG) << "Set XY Range";
bool disablezoom = false;
bool isRange[4]{false, false, false, false};
double xyRange[4]{0, 0, 0, 0};
QString dispVal[4] {dispXMin->text(), dispXMax->text(), dispYMin->text(), dispYMax->text()};
bool chkVal[4] {chkXMin->isChecked(), chkXMax->isChecked(), chkYMin->isChecked(), chkYMax->isChecked()};
QString dispVal[4]{dispXMin->text(), dispXMax->text(), dispYMin->text(),
dispYMax->text()};
bool chkVal[4]{chkXMin->isChecked(), chkXMax->isChecked(),
chkYMin->isChecked(), chkYMax->isChecked()};
for (int i = 0; i < 4; ++i) {
if (chkVal[i] && !dispVal[i].isEmpty()) {
double val = dispVal[i].toDouble();
FILE_LOG(logDEBUG) << "Setting " << qDefs::getRangeAsString(static_cast<qDefs::range>(i)) << " to " << val;
LOG(logDEBUG)
<< "Setting "
<< qDefs::getRangeAsString(static_cast<qDefs::range>(i))
<< " to " << val;
xyRange[i] = val;
isRange[i] = true;
disablezoom = true;
@ -403,7 +449,7 @@ void qTabPlot::SetXYRange() {
}
void qTabPlot::MaintainAspectRatio(int dimension) {
FILE_LOG(logDEBUG) << "Maintaining Aspect Ratio";
LOG(logDEBUG) << "Maintaining Aspect Ratio";
disconnect(chkXMin, SIGNAL(toggled(bool)), this, SLOT(SetXRange()));
disconnect(chkXMax, SIGNAL(toggled(bool)), this, SLOT(SetXRange()));
@ -434,52 +480,71 @@ void qTabPlot::MaintainAspectRatio(int dimension) {
ranges[qDefs::XMAX] = plot->GetXMaximum();
ranges[qDefs::YMIN] = plot->GetYMinimum();
ranges[qDefs::YMAX] = plot->GetYMaximum();
double idealAspectratio = (ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]);
FILE_LOG(logDEBUG) << "Ideal Aspect ratio: " << idealAspectratio << " for x(" << ranges[qDefs::XMIN] << " - " << ranges[qDefs::XMAX] << "), y(" << ranges[qDefs::YMIN] << " - " << ranges[qDefs::YMAX] << ")";
double idealAspectratio = (ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) /
(ranges[qDefs::YMAX] - ranges[qDefs::YMIN]);
LOG(logDEBUG) << "Ideal Aspect ratio: " << idealAspectratio
<< " for x(" << ranges[qDefs::XMIN] << " - "
<< ranges[qDefs::XMAX] << "), y(" << ranges[qDefs::YMIN]
<< " - " << ranges[qDefs::YMAX] << ")";
// calculate current aspect ratio
ranges[qDefs::XMIN] = dispXMin->text().toDouble();
ranges[qDefs::XMAX] = dispXMax->text().toDouble();
ranges[qDefs::YMIN] = dispYMin->text().toDouble();
ranges[qDefs::YMAX] = dispYMax->text().toDouble();
double currentAspectRatio = (ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]);
FILE_LOG(logDEBUG) << "Current Aspect ratio: " << currentAspectRatio << " for x(" << ranges[qDefs::XMIN] << " - " << ranges[qDefs::XMAX] << "), y(" << ranges[qDefs::YMIN] << " - " << ranges[qDefs::YMAX] << ")";
double currentAspectRatio = (ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) /
(ranges[qDefs::YMAX] - ranges[qDefs::YMIN]);
LOG(logDEBUG) << "Current Aspect ratio: " << currentAspectRatio
<< " for x(" << ranges[qDefs::XMIN] << " - "
<< ranges[qDefs::XMAX] << "), y(" << ranges[qDefs::YMIN]
<< " - " << ranges[qDefs::YMAX] << ")";
if (currentAspectRatio != idealAspectratio) {
// dimension: 1(x changed: y adjusted), 0(y changed: x adjusted), -1(aspect ratio clicked: larger one adjusted)
// dimension: 1(x changed: y adjusted), 0(y changed: x adjusted),
// -1(aspect ratio clicked: larger one adjusted)
if (dimension == -1) {
dimension = ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) > (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]))
? static_cast<int>(slsDetectorDefs::X) : static_cast<int>(slsDetectorDefs::Y);
dimension = ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) >
(ranges[qDefs::YMAX] - ranges[qDefs::YMIN]))
? static_cast<int>(slsDetectorDefs::X)
: static_cast<int>(slsDetectorDefs::Y);
}
// calculate new value to maintain aspect ratio
// adjust x
double newval = 0;
if (dimension == static_cast<int>(slsDetectorDefs::X)) {
newval = idealAspectratio * (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]) + ranges[qDefs::XMIN];
newval =
idealAspectratio * (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]) +
ranges[qDefs::XMIN];
if (newval <= plot->GetXMaximum()) {
ranges[qDefs::XMAX] = newval;
dispXMax->setText(QString::number(newval));
FILE_LOG(logDEBUG) << "New XMax: " << newval;
LOG(logDEBUG) << "New XMax: " << newval;
} else {
newval = ranges[qDefs::XMAX] - (idealAspectratio * (ranges[qDefs::YMAX] - ranges[qDefs::YMIN]));
newval = ranges[qDefs::XMAX] -
(idealAspectratio *
(ranges[qDefs::YMAX] - ranges[qDefs::YMIN]));
ranges[qDefs::XMIN] = newval;
dispXMin->setText(QString::number(newval));
FILE_LOG(logDEBUG) << "New XMin: " << newval;
LOG(logDEBUG) << "New XMin: " << newval;
}
}
// adjust y
else {
newval = ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / idealAspectratio) + ranges[qDefs::YMIN];
newval = ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) /
idealAspectratio) +
ranges[qDefs::YMIN];
if (newval <= plot->GetYMaximum()) {
ranges[qDefs::YMAX] = newval;
dispYMax->setText(QString::number(newval));
FILE_LOG(logDEBUG) << "New YMax: " << newval;
LOG(logDEBUG) << "New YMax: " << newval;
} else {
newval = ranges[qDefs::YMAX] - ((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) / idealAspectratio);
newval = ranges[qDefs::YMAX] -
((ranges[qDefs::XMAX] - ranges[qDefs::XMIN]) /
idealAspectratio);
ranges[qDefs::YMIN] = newval;
dispYMin->setText(QString::number(newval));
FILE_LOG(logDEBUG) << "New YMax: " << newval;
LOG(logDEBUG) << "New YMax: " << newval;
}
}
}
@ -504,36 +569,47 @@ void qTabPlot::SetZRange() {
if (isZRange[0] && !dispZMin->text().isEmpty()) {
double val = dispZMin->text().toDouble();
FILE_LOG(logDEBUG) << "Setting zmin to " << val;
LOG(logDEBUG) << "Setting zmin to " << val;
zRange[0] = val;
}
if (isZRange[1] && !dispZMax->text().isEmpty()) {
double val = dispZMax->text().toDouble();
FILE_LOG(logDEBUG) << "Setting zmax to " << val;
LOG(logDEBUG) << "Setting zmax to " << val;
zRange[1] = val;
}
plot->SetZRange(zRange, isZRange);
}
void qTabPlot::GetStreamingFrequency() {
FILE_LOG(logDEBUG) << "Getting Streaming Frequency";
disconnect(comboFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
disconnect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
disconnect(spinTimeGap, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
disconnect(spinNthFrame, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
LOG(logDEBUG) << "Getting Streaming Frequency";
disconnect(comboFrequency, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
disconnect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
disconnect(spinTimeGap, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
disconnect(spinNthFrame, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
try {
int freq = det->getRxZmqFrequency().tsquash("Inconsistent receiver zmq streaming frequency for all detectors.");
int freq = det->getRxZmqFrequency().tsquash(
"Inconsistent receiver zmq streaming frequency for all detectors.");
// time interval
if (freq == 0) {
comboFrequency->setCurrentIndex(0);
stackedTimeInterval->setCurrentIndex(0);
try {
int timeMs = det->getRxZmqTimer().tsquash("Inconsistent receiver zmq streaming timer for all detectors.");
auto timeNS = qDefs::getNSTime(std::make_pair(static_cast<double>(timeMs), qDefs::MILLISECONDS));
int timeMs = det->getRxZmqTimer().tsquash(
"Inconsistent receiver zmq streaming timer for all "
"detectors.");
auto timeNS = qDefs::getNSTime(std::make_pair(
static_cast<double>(timeMs), qDefs::MILLISECONDS));
auto time = qDefs::getUserFriendlyTime(timeNS);
spinTimeGap->setValue(time.first);
comboTimeGapUnit->setCurrentIndex(static_cast<int>(time.second));
} CATCH_DISPLAY ("Could not get streaming timer.", "qTabPlot::GetStreamingFrequency")
comboTimeGapUnit->setCurrentIndex(
static_cast<int>(time.second));
}
CATCH_DISPLAY("Could not get streaming timer.",
"qTabPlot::GetStreamingFrequency")
}
// every nth frame
else {
@ -541,33 +617,44 @@ void qTabPlot::GetStreamingFrequency() {
stackedTimeInterval->setCurrentIndex(1);
spinNthFrame->setValue(freq);
}
} CATCH_DISPLAY ("Could not get streaming frequency.", "qTabPlot::GetStreamingFrequency")
connect(comboFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
connect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(SetStreamingFrequency()));
connect(spinTimeGap, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
connect(spinNthFrame, SIGNAL(editingFinished()), this, SLOT(SetStreamingFrequency()));
}
CATCH_DISPLAY("Could not get streaming frequency.",
"qTabPlot::GetStreamingFrequency")
connect(comboFrequency, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
connect(comboTimeGapUnit, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetStreamingFrequency()));
connect(spinTimeGap, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
connect(spinNthFrame, SIGNAL(editingFinished()), this,
SLOT(SetStreamingFrequency()));
}
void qTabPlot::SetStreamingFrequency() {
bool frequency = (comboFrequency->currentIndex() == 0) ? 0 : 1;
auto freqVal = spinNthFrame->value();
auto timeVal = spinTimeGap->value();
auto timeUnit = static_cast<qDefs::timeUnit>(comboTimeGapUnit->currentIndex());
auto timeUnit =
static_cast<qDefs::timeUnit>(comboTimeGapUnit->currentIndex());
stackedTimeInterval->setCurrentIndex(comboFrequency->currentIndex());
try {
if (frequency) {
FILE_LOG(logINFO) << "Setting Streaming Frequency to " << freqVal;
LOG(logINFO) << "Setting Streaming Frequency to " << freqVal;
det->setRxZmqFrequency(freqVal);
} else {
FILE_LOG(logINFO) << "Setting Streaming Timer to " << timeVal << " " << qDefs::getUnitString(timeUnit);
LOG(logINFO) << "Setting Streaming Timer to " << timeVal << " "
<< qDefs::getUnitString(timeUnit);
auto timeMS = qDefs::getMSTime(std::make_pair(timeVal, timeUnit));
det->setRxZmqTimer(timeMS.count());
}
} CATCH_HANDLE("Could not set streaming frequency/ timer.", "qTabPlot::SetStreamingFrequency", this, &qTabPlot::GetStreamingFrequency)
}
CATCH_HANDLE("Could not set streaming frequency/ timer.",
"qTabPlot::SetStreamingFrequency", this,
&qTabPlot::GetStreamingFrequency)
}
void qTabPlot::Refresh() {
FILE_LOG(logDEBUG) << "**Updating Plot Tab";
LOG(logDEBUG) << "**Updating Plot Tab";
if (!plot->GetIsRunning()) {
boxPlotType->setEnabled(true);
@ -600,5 +687,5 @@ void qTabPlot::Refresh() {
chkGapPixels->setEnabled(false);
}
FILE_LOG(logDEBUG) << "**Updated Plot Tab";
LOG(logDEBUG) << "**Updated Plot Tab";
}

110
slsDetectorGui/src/qTabSettings.cpp Executable file → Normal file
View File

@ -1,17 +1,13 @@
#include "qTabSettings.h"
#include "qDefs.h"
#include "ToString.h"
#include <QStandardItemModel>
#include <cmath>
#include <iostream>
qTabSettings::qTabSettings(QWidget *parent, sls::Detector *detector): QWidget(parent), det(detector) {
qTabSettings::qTabSettings(QWidget *parent, sls::Detector *detector)
: QWidget(parent), det(detector) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Settings ready";
LOG(logDEBUG) << "Settings ready";
}
qTabSettings::~qTabSettings() {}
@ -40,22 +36,21 @@ void qTabSettings::SetupWidgetWindow() {
SetupDetectorSettings();
}
spinThreshold->setValue(-1);
Initialization();
// default for the disabled
GetDynamicRange();
Refresh();
}
void qTabSettings::SetupDetectorSettings() {
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(comboSettings->model());
QStandardItemModel *model =
qobject_cast<QStandardItemModel *>(comboSettings->model());
if (model) {
QModelIndex index[NUMSETTINGS];
QStandardItem *item[NUMSETTINGS];
for (int i = 0; i < NUMSETTINGS; ++i) {
index[i] = model->index(i, comboSettings->modelColumn(), comboSettings->rootModelIndex());
index[i] = model->index(i, comboSettings->modelColumn(),
comboSettings->rootModelIndex());
item[i] = model->itemFromIndex(index[i]);
item[i]->setEnabled(false);
}
@ -98,9 +93,10 @@ void qTabSettings::SetupDetectorSettings() {
item[(int)G4_LOWGAIN]->setEnabled(true);
break;
default:
FILE_LOG(logDEBUG) << "Unknown detector type. Exiting GUI.";
LOG(logDEBUG) << "Unknown detector type. Exiting GUI.";
qDefs::Message(qDefs::CRITICAL,
"Unknown detector type. Exiting GUI.", "qTabSettings::SetupDetectorSettings");
"Unknown detector type. Exiting GUI.",
"qTabSettings::SetupDetectorSettings");
exit(-1);
}
}
@ -109,22 +105,27 @@ void qTabSettings::SetupDetectorSettings() {
void qTabSettings::Initialization() {
// Settings
if (comboSettings->isEnabled())
connect(comboSettings, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSettings(int)));
connect(comboSettings, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSettings(int)));
// Dynamic Range
if (comboDynamicRange->isEnabled())
connect(comboDynamicRange, SIGNAL(activated(int)), this, SLOT(SetDynamicRange(int)));
connect(comboDynamicRange, SIGNAL(activated(int)), this,
SLOT(SetDynamicRange(int)));
// Threshold
if (spinThreshold->isEnabled())
connect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy(int)));
connect(spinThreshold, SIGNAL(valueChanged(int)), this,
SLOT(SetThresholdEnergy(int)));
}
void qTabSettings::GetSettings() {
FILE_LOG(logDEBUG) << "Getting settings";
disconnect(comboSettings, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSettings(int)));
LOG(logDEBUG) << "Getting settings";
disconnect(comboSettings, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSettings(int)));
try {
auto retval = det->getSettings().tsquash("Inconsistent settings for all detectors.");
auto retval = det->getSettings().tsquash(
"Inconsistent settings for all detectors.");
switch (retval) {
case slsDetectorDefs::UNDEFINED:
comboSettings->setCurrentIndex(UNDEFINED);
@ -134,22 +135,27 @@ void qTabSettings::GetSettings() {
break;
default:
if ((int)retval < -1 || (int)retval >= NUMSETTINGS) {
throw sls::RuntimeError(std::string("Unknown settings: ") + std::to_string(retval));
throw sls::RuntimeError(std::string("Unknown settings: ") +
std::to_string(retval));
}
comboSettings->setCurrentIndex(retval);
break;
}
} CATCH_DISPLAY ("Could not get settings.", "qTabSettings::GetSettings")
connect(comboSettings, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSettings(int)));
}
CATCH_DISPLAY("Could not get settings.", "qTabSettings::GetSettings")
connect(comboSettings, SIGNAL(currentIndexChanged(int)), this,
SLOT(SetSettings(int)));
}
void qTabSettings::SetSettings(int index) {
// settings
auto val = static_cast<slsDetectorDefs::detectorSettings>(index);
try {
FILE_LOG(logINFO) << "Setting Settings to " << sls::ToString(val);
LOG(logINFO) << "Setting Settings to " << sls::ToString(val);
det->setSettings(val);
} CATCH_HANDLE ("Could not set settings.", "qTabSettings::SetSettings", this, &qTabSettings::GetSettings)
}
CATCH_HANDLE("Could not set settings.", "qTabSettings::SetSettings", this,
&qTabSettings::GetSettings)
// threshold
if (spinThreshold->isEnabled()) {
SetThresholdEnergy(spinThreshold->value());
@ -157,10 +163,12 @@ void qTabSettings::SetSettings(int index) {
}
void qTabSettings::GetDynamicRange() {
FILE_LOG(logDEBUG) << "Getting dynamic range";
disconnect(comboDynamicRange, SIGNAL(activated(int)), this, SLOT(SetDynamicRange(int)));
LOG(logDEBUG) << "Getting dynamic range";
disconnect(comboDynamicRange, SIGNAL(activated(int)), this,
SLOT(SetDynamicRange(int)));
try {
auto retval = det->getDynamicRange().tsquash("Inconsistent dynamic range for all detectors.");
auto retval = det->getDynamicRange().tsquash(
"Inconsistent dynamic range for all detectors.");
// set the final value on gui
switch (retval) {
case 32:
@ -176,14 +184,19 @@ void qTabSettings::GetDynamicRange() {
comboDynamicRange->setCurrentIndex(DYNAMICRANGE_4);
break;
default:
throw sls::RuntimeError(std::string("Unknown dynamic range: ") + std::to_string(retval));
throw sls::RuntimeError(std::string("Unknown dynamic range: ") +
std::to_string(retval));
}
} CATCH_DISPLAY ("Could not get dynamic range.", "qTabSettings::GetDynamicRange")
connect(comboDynamicRange, SIGNAL(activated(int)), this,SLOT(SetDynamicRange(int)));
}
CATCH_DISPLAY("Could not get dynamic range.",
"qTabSettings::GetDynamicRange")
connect(comboDynamicRange, SIGNAL(activated(int)), this,
SLOT(SetDynamicRange(int)));
}
void qTabSettings::SetDynamicRange(int index) {
FILE_LOG(logINFO) << "Setting dynamic range to " << comboDynamicRange->currentText().toAscii().data();
LOG(logINFO) << "Setting dynamic range to "
<< comboDynamicRange->currentText().toAscii().data();
try {
switch (index) {
case DYNAMICRANGE_32:
@ -199,32 +212,43 @@ void qTabSettings::SetDynamicRange(int index) {
det->setDynamicRange(4);
break;
default:
throw sls::RuntimeError(std::string("Unknown dynamic range: ") + std::to_string(index));
throw sls::RuntimeError(std::string("Unknown dynamic range: ") +
std::to_string(index));
}
} CATCH_HANDLE ("Could not set dynamic range.", "qTabSettings::SetDynamicRange", this, &qTabSettings::GetDynamicRange)
}
CATCH_HANDLE("Could not set dynamic range.",
"qTabSettings::SetDynamicRange", this,
&qTabSettings::GetDynamicRange)
}
void qTabSettings::GetThresholdEnergy() {
FILE_LOG(logDEBUG) << "Getting theshold energy";
disconnect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy(int)));
LOG(logDEBUG) << "Getting theshold energy";
disconnect(spinThreshold, SIGNAL(valueChanged(int)), this,
SLOT(SetThresholdEnergy(int)));
try {
auto retval = det->getThresholdEnergy().tsquash("Inconsistent threhsold energy for all detectors.");
auto retval = det->getThresholdEnergy().tsquash(
"Inconsistent threhsold energy for all detectors.");
spinThreshold->setValue(retval);
} CATCH_DISPLAY ("Could not get threshold energy.", "qTabDataOutput::GetThresholdEnergy")
connect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy(int)));
}
CATCH_DISPLAY("Could not get threshold energy.",
"qTabDataOutput::GetThresholdEnergy")
connect(spinThreshold, SIGNAL(valueChanged(int)), this,
SLOT(SetThresholdEnergy(int)));
}
void qTabSettings::SetThresholdEnergy(int index) {
FILE_LOG(logINFO) << "Setting Threshold Energy to " << index << " eV";
LOG(logINFO) << "Setting Threshold Energy to " << index << " eV";
try {
det->setThresholdEnergy(index);
} CATCH_DISPLAY ("Could not get threshold energy.", "qTabSettings::SetThresholdEnergy")
}
CATCH_DISPLAY("Could not get threshold energy.",
"qTabSettings::SetThresholdEnergy")
// set the right value anyway (due to tolerance)
GetThresholdEnergy();
}
void qTabSettings::Refresh() {
FILE_LOG(logDEBUG) << "**Updating Settings Tab";
LOG(logDEBUG) << "**Updating Settings Tab";
if (comboSettings->isEnabled()) {
GetSettings();
@ -237,5 +261,5 @@ void qTabSettings::Refresh() {
if (spinThreshold->isEnabled())
GetThresholdEnergy();
FILE_LOG(logDEBUG) << "**Updated Settings Tab";
LOG(logDEBUG) << "**Updated Settings Tab";
}

View File

@ -1,7 +1,28 @@
add_library(slsProjectCWarnings INTERFACE)
target_compile_options(slsProjectCWarnings INTERFACE
-Wall
-Wextra
-Wno-unused-parameter #Needs to be slowly mitigated
-Wdouble-promotion
-Wformat=2
-Wredundant-decls
# -Wconversion
-Wdouble-promotion
-Werror=return-type
)
# Install fake the library
install(TARGETS slsProjectCWarnings
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
add_subdirectory(ctbDetectorServer)
add_subdirectory(eigerDetectorServer)
add_subdirectory(gotthardDetectorServer)
add_subdirectory(jungfrauDetectorServer)
#add_subdirectory(moenchDetectorServer)
add_subdirectory(mythen3DetectorServer)
add_subdirectory(gotthard2DetectorServer)
add_subdirectory(moenchDetectorServer)

View File

@ -32,7 +32,7 @@ target_compile_definitions(ctbDetectorServer_virtual
)
target_link_libraries(ctbDetectorServer_virtual
PUBLIC pthread rt
PUBLIC pthread rt slsProjectCWarnings
)
set_target_properties(ctbDetectorServer_virtual PROPERTIES

View File

@ -36,7 +36,7 @@ typedef struct udp_header_struct {
#define UDP_IP_HEADER_LENGTH_BYTES (28)
/* Enums */
enum ADCINDEX {V_PWR_IO, V_PWR_A, V_PWR_B, V_PWR_C, V_PWR_D, I_PWR_IO, I_PWR_A, I_PWR_B, I_PWR_C, I_PWR_D};
enum ADCINDEX {V_PWR_IO, V_PWR_A, V_PWR_B, V_PWR_C, V_PWR_D, I_PWR_IO, I_PWR_A, I_PWR_B, I_PWR_C, I_PWR_D, S_ADC0, S_ADC1, S_ADC2, S_ADC3, S_ADC4, S_ADC5, S_ADC6, S_ADC7, S_TMP};
enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
D10, D11, D12, D13, D14, D15, D16, D17,
D_PWR_D, D_PWR_CHIP, D_PWR_C, D_PWR_B, D_PWR_A, D_PWR_IO};

View File

@ -25,13 +25,13 @@ int i2c_open(const char* file,unsigned int addr){
//device file
int fd = open( file, O_RDWR );
if (fd < 0) {
FILE_LOG(logERROR, ("Warning: Unable to open file %s\n",file));
LOG(logERROR, ("Warning: Unable to open file %s\n",file));
return -1;
}
//device address
if( ioctl( fd, I2C_SLAVE, addr&0x7F ) < 0 ) {
FILE_LOG(logERROR, ("Warning: Unable to set slave address:0x%x \n",addr));
LOG(logERROR, ("Warning: Unable to set slave address:0x%x \n",addr));
return -2;
}
return fd;
@ -45,17 +45,17 @@ int i2c_read(){
unsigned char buf = reg;
if (write(fd, &buf, 1)!= 1){
FILE_LOG(logERROR, ("Warning: Unable to write read request to register %d\n", reg));
LOG(logERROR, ("Warning: Unable to write read request to register %d\n", reg));
return -1;
}
//read and update value (but old value read out)
if(read(fd, &buf, 1) != 1){
FILE_LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
return -2;
}
//read again to read the updated value
if(read(fd, &buf, 1) != 1){
FILE_LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
LOG(logERROR, ("Warning: Unable to read register %d\n", reg));
return -2;
}
close(fd);
@ -76,7 +76,7 @@ int i2c_write(unsigned int value){
buf[0] = reg;
buf[1] = val;
if (write(fd, buf, 2) != 2) {
FILE_LOG(logERROR, ("Warning: Unable to write %d to register %d\n",val, reg));
LOG(logERROR, ("Warning: Unable to write %d to register %d\n",val, reg));
return -1;
}
@ -92,10 +92,10 @@ int main(int argc, char* argv[]) {
int fd = open(PORTNAME, O_RDWR | O_NOCTTY | O_SYNC);
if(fd < 0){
FILE_LOG(logERROR, ("Warning: Unable to open port %s\n", PORTNAME));
LOG(logERROR, ("Warning: Unable to open port %s\n", PORTNAME));
return -1;
}
FILE_LOG(logINFO, ("opened port at %s\n",PORTNAME));
LOG(logINFO, ("opened port at %s\n",PORTNAME));
struct termios serial_conf;
// reset structure
@ -110,17 +110,17 @@ int main(int argc, char* argv[]) {
serial_conf.c_lflag = ICANON;
// flush input
if(tcflush(fd, TCIOFLUSH) < 0){
FILE_LOG(logERROR, ("Warning: error form tcflush %d\n", errno));
LOG(logERROR, ("Warning: error form tcflush %d\n", errno));
return 0;
}
// set new options for the port, TCSANOW:changes occur immediately without waiting for data to complete
if(tcsetattr(fd, TCSANOW, &serial_conf) < 0){
FILE_LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
return 0;
}
if(tcsetattr(fd, TCSAFLUSH, &serial_conf) < 0){
FILE_LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
LOG(logERROR, ("Warning: error form tcsetattr %d\n", errno));
return 0;
}
@ -130,25 +130,25 @@ int main(int argc, char* argv[]) {
char buffer[BUFFERSIZE];
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-1] = '\n';
FILE_LOG(logINFO, ("Ready...\n"));
LOG(logINFO, ("Ready...\n"));
while(ret != GOODBYE){
memset(buffer,0,BUFFERSIZE);
n = read(fd,buffer,BUFFERSIZE);
FILE_LOG(logDEBUG1, ("Received %d Bytes\n", n));
FILE_LOG(logINFO, ("Got message: '%s'\n",buffer));
LOG(logDEBUG1, ("Received %d Bytes\n", n));
LOG(logINFO, ("Got message: '%s'\n",buffer));
switch(buffer[0]){
case '\0':
FILE_LOG(logINFO, ("Got Start (Detector restart)\n"));
LOG(logINFO, ("Got Start (Detector restart)\n"));
break;
case 's':
FILE_LOG(logINFO, ("Got Start \n"));
LOG(logINFO, ("Got Start \n"));
break;
case 'p':
if (!sscanf(&buffer[1],"%d",&ival)){
FILE_LOG(logERROR, ("Warning: cannot scan voltage value\n"));
LOG(logERROR, ("Warning: cannot scan voltage value\n"));
break;
}
// ok/ fail
@ -158,9 +158,9 @@ int main(int argc, char* argv[]) {
strcpy(buffer,"fail ");
else
strcpy(buffer,"success ");
FILE_LOG(logINFO, ("Sending: '%s'\n",buffer));
LOG(logINFO, ("Sending: '%s'\n",buffer));
n = write(fd, buffer, BUFFERSIZE);
FILE_LOG(logDEBUG1, ("Sent %d Bytes\n", n));
LOG(logDEBUG1, ("Sent %d Bytes\n", n));
break;
case 'g':
@ -173,17 +173,17 @@ int main(int argc, char* argv[]) {
else
strcpy(buffer,"success ");
n = write(fd, buffer, BUFFERSIZE);
FILE_LOG(logINFO, ("Sending: '%s'\n",buffer));
FILE_LOG(logDEBUG1, ("Sent %d Bytes\n", n));
LOG(logINFO, ("Sending: '%s'\n",buffer));
LOG(logDEBUG1, ("Sent %d Bytes\n", n));
//value
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-1] = '\n';
if(ival >= 0){
FILE_LOG(logINFO, ("Sending: '%d'\n",ival));
LOG(logINFO, ("Sending: '%d'\n",ival));
sprintf(buffer,"%d ",ival);
n = write(fd, buffer, BUFFERSIZE);
FILE_LOG(logINFO, ("Sent %d Bytes\n", n));
}else FILE_LOG(logERROR, ("%s\n",buffer));
LOG(logINFO, ("Sent %d Bytes\n", n));
}else LOG(logERROR, ("%s\n",buffer));
break;
case 'e':
@ -191,7 +191,7 @@ int main(int argc, char* argv[]) {
ret = GOODBYE;
break;
default:
FILE_LOG(logERROR, ("Unknown Command. buffer:'%s'\n",buffer));
LOG(logERROR, ("Unknown Command. buffer:'%s'\n",buffer));
break;
}
}

View File

@ -77,7 +77,7 @@ unsigned int BebInfo_GetSrcPort(struct BebInfo* bebInfo, int ten_gig) {return te
void BebInfo_Print(struct BebInfo* bebInfo) {
FILE_LOG(logINFO, (
LOG(logINFO, (
"%d) Beb Info:\n"
"\tSerial Add: 0x%x\n"
"\tMAC 1GbE: %s\n"
@ -133,7 +133,7 @@ void Beb_Beb(int id) {
if (!Beb_InitBebInfos()) exit(1);
FILE_LOG(logDEBUG1, ("Printing Beb infos:\n"));
LOG(logDEBUG1, ("Printing Beb infos:\n"));
unsigned int i;
for(i=1;i<bebInfoSize;i++) BebInfo_Print(&beb_infos[i]);
@ -157,12 +157,12 @@ void Beb_GetModuleConfiguration(int* master, int* top, int* normal) {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Module Configuration FAIL\n"));
LOG(logERROR, ("Module Configuration FAIL\n"));
} else {
//read data
ret = Beb_Read32(csp0base, MODULE_CONFIGURATION_MASK);
FILE_LOG(logDEBUG1, ("Module Configuration OK\n"));
FILE_LOG(logDEBUG1, ("Beb: value =0x%x\n",ret));
LOG(logDEBUG1, ("Module Configuration OK\n"));
LOG(logDEBUG1, ("Beb: value =0x%x\n",ret));
if (ret&TOP_BIT_MASK) {
*top = 1;
Beb_top = 1;
@ -215,7 +215,7 @@ void Beb_EndofDataSend(int tengiga) {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_COUNTER_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Delay read counter fail\n"));
LOG(logERROR, ("Delay read counter fail\n"));
return;
} else {
//read data first time
@ -227,7 +227,7 @@ void Beb_EndofDataSend(int tengiga) {
r_framepktMsbcounter = Beb_Read32(csp0base, addr_r_framepktMsbcounter);
r_txndelaycounter = Beb_Read32(csp0base, addr_r_txndelaycounter);
r_framedelaycounter = Beb_Read32(csp0base, addr_r_framedelaycounter);
FILE_LOG(logDEBUG1, ("\nLeft\n"
LOG(logDEBUG1, ("\nLeft\n"
"FramepacketLsbcounter: %d\n"
"FramepacketMsbcounter: %d\n"
"Txndelaycounter:%d\n"
@ -245,7 +245,7 @@ void Beb_EndofDataSend(int tengiga) {
while(1) {
maxtimer = MAX(MAX(l_txndelaycounter,l_framedelaycounter),MAX(r_txndelaycounter,r_framedelaycounter));
maxtimer /= 100;
FILE_LOG(logDEBUG1, ("Will wait for %d us\n",maxtimer));
LOG(logDEBUG1, ("Will wait for %d us\n",maxtimer));
usleep(maxtimer);
//read new values
@ -257,7 +257,7 @@ void Beb_EndofDataSend(int tengiga) {
r_framepktMsbcounter_new = Beb_Read32(csp0base, addr_r_framepktMsbcounter);
r_txndelaycounter_new = Beb_Read32(csp0base, addr_r_txndelaycounter);
r_framedelaycounter_new = Beb_Read32(csp0base, addr_r_framedelaycounter);
FILE_LOG(logDEBUG1, ("\nLeft\n"
LOG(logDEBUG1, ("\nLeft\n"
"FramepacketLsbcounter: %d\n"
"FramepacketMsbcounter: %d\n"
"Txndelaycounter:%d\n"
@ -288,7 +288,7 @@ void Beb_EndofDataSend(int tengiga) {
}
FILE_LOG(logINFO, ("Detector has sent all data\n"));
LOG(logINFO, ("Detector has sent all data\n"));
//close file pointer
Beb_close(fd,csp0base);
}
@ -310,14 +310,14 @@ int Beb_SetMasterViaSoftware() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Set Master FAIL\n"));
LOG(logERROR, ("Set Master FAIL\n"));
} else {
value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET);
value|=MASTER_BIT;
value|=OVERWRITE_HARDWARE_BIT;
int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET,value);
if (newval!=value) {
FILE_LOG(logERROR, ("Could not set Master via Software\n"));
LOG(logERROR, ("Could not set Master via Software\n"));
} else {
ret = 0;
}
@ -343,14 +343,14 @@ int Beb_SetSlaveViaSoftware() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Set Slave FAIL\n"));
LOG(logERROR, ("Set Slave FAIL\n"));
} else {
value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET);
value&=~MASTER_BIT;
value|=OVERWRITE_HARDWARE_BIT;
int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET,value);
if (newval!=value) {
FILE_LOG(logERROR, ("Could not set Slave via Software\n"));
LOG(logERROR, ("Could not set Slave via Software\n"));
} else {
ret = 0;
}
@ -371,11 +371,11 @@ int Beb_Activate(int enable) {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Deactivate FAIL\n"));
LOG(logERROR, ("Deactivate FAIL\n"));
} else {
if (enable > -1) {
value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET);
FILE_LOG(logINFO, ("Deactivate register value before:%d\n",value));
LOG(logINFO, ("Deactivate register value before:%d\n",value));
if (enable)
value&=~DEACTIVATE_BIT;
else
@ -384,9 +384,9 @@ int Beb_Activate(int enable) {
int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET,value);
if (newval!=value) {
if (enable) {
FILE_LOG(logERROR, ("Could not activate via Software\n"));
LOG(logERROR, ("Could not activate via Software\n"));
} else {
FILE_LOG(logERROR, ("Could not deactivate via Software\n"));
LOG(logERROR, ("Could not deactivate via Software\n"));
}
}
}
@ -396,9 +396,9 @@ int Beb_Activate(int enable) {
else ret = 1;
if (enable == -1) {
if (ret) {
FILE_LOG(logINFOBLUE, ("Detector is active. Register value:%d\n", value));
LOG(logINFOBLUE, ("Detector is active. Register value:%d\n", value));
} else {
FILE_LOG(logERROR, ("Detector is deactivated! Register value:%d\n", value));
LOG(logERROR, ("Detector is deactivated! Register value:%d\n", value));
}
}
@ -430,7 +430,7 @@ int Beb_Set32bitOverflow(int val) {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Could not read register to set overflow flag in 32 bit mode. FAIL\n"));
LOG(logERROR, ("Could not read register to set overflow flag in 32 bit mode. FAIL\n"));
return -1;
}
else {
@ -459,7 +459,7 @@ int Beb_GetTenGigaFlowControl() {
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to get ten giga flow control. FAIL\n"));
LOG(logERROR, ("Could not read register to get ten giga flow control. FAIL\n"));
return -1;
} else {
u_int32_t retval = Beb_Read32(csp0base, offset);
@ -471,13 +471,13 @@ int Beb_GetTenGigaFlowControl() {
}
int Beb_SetTenGigaFlowControl(int value) {
FILE_LOG(logINFO, ("Setting ten giga flow control to %d\n", value));
LOG(logINFO, ("Setting ten giga flow control to %d\n", value));
value = value == 0 ? 0 : 1;
u_int32_t offset = FLOW_REG_OFFSET;
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to set ten giga flow control. FAIL\n"));
LOG(logERROR, ("Could not read register to set ten giga flow control. FAIL\n"));
return 0;
} else {
// reset bit
@ -499,7 +499,7 @@ int Beb_GetTransmissionDelayFrame() {
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to get transmission delay frame. FAIL\n"));
LOG(logERROR, ("Could not read register to get transmission delay frame. FAIL\n"));
return -1;
} else {
u_int32_t retval = Beb_Read32(csp0base, offset);
@ -509,16 +509,16 @@ int Beb_GetTransmissionDelayFrame() {
}
int Beb_SetTransmissionDelayFrame(int value) {
FILE_LOG(logINFO, ("Setting transmission delay frame to %d\n", value));
LOG(logINFO, ("Setting transmission delay frame to %d\n", value));
if (value < 0) {
FILE_LOG(logERROR, ("Invalid transmission delay frame value %d\n", value));
LOG(logERROR, ("Invalid transmission delay frame value %d\n", value));
return 0;
}
u_int32_t offset = TXM_DELAY_FRAME_OFFSET;
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to set transmission delay frame. FAIL\n"));
LOG(logERROR, ("Could not read register to set transmission delay frame. FAIL\n"));
return 0;
} else {
Beb_Write32(csp0base, offset, value);
@ -532,7 +532,7 @@ int Beb_GetTransmissionDelayLeft() {
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to get transmission delay left. FAIL\n"));
LOG(logERROR, ("Could not read register to get transmission delay left. FAIL\n"));
return -1;
} else {
u_int32_t retval = Beb_Read32(csp0base, offset);
@ -542,16 +542,16 @@ int Beb_GetTransmissionDelayLeft() {
}
int Beb_SetTransmissionDelayLeft(int value) {
FILE_LOG(logINFO, ("Setting transmission delay left to %d\n", value));
LOG(logINFO, ("Setting transmission delay left to %d\n", value));
if (value < 0) {
FILE_LOG(logERROR, ("Invalid transmission delay left value %d\n", value));
LOG(logERROR, ("Invalid transmission delay left value %d\n", value));
return 0;
}
u_int32_t offset = TXM_DELAY_LEFT_OFFSET;
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to set transmission delay left. FAIL\n"));
LOG(logERROR, ("Could not read register to set transmission delay left. FAIL\n"));
return 0;
} else {
Beb_Write32(csp0base, offset, value);
@ -565,7 +565,7 @@ int Beb_GetTransmissionDelayRight() {
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to get transmission delay right. FAIL\n"));
LOG(logERROR, ("Could not read register to get transmission delay right. FAIL\n"));
return -1;
} else {
u_int32_t retval = Beb_Read32(csp0base, offset);
@ -575,16 +575,16 @@ int Beb_GetTransmissionDelayRight() {
}
int Beb_SetTransmissionDelayRight(int value) {
FILE_LOG(logINFO, ("Setting transmission delay right to %d\n", value));
LOG(logINFO, ("Setting transmission delay right to %d\n", value));
if (value < 0) {
FILE_LOG(logERROR, ("Invalid transmission delay right value %d\n", value));
LOG(logERROR, ("Invalid transmission delay right value %d\n", value));
return 0;
}
u_int32_t offset = TXM_DELAY_RIGHT_OFFSET;
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) {
FILE_LOG(logERROR, ("Could not read register to set transmission delay right. FAIL\n"));
LOG(logERROR, ("Could not read register to set transmission delay right. FAIL\n"));
return 0;
} else {
Beb_Write32(csp0base, offset, value);
@ -617,12 +617,12 @@ int Beb_SetNetworkParameter(enum NETWORKINDEX mode, int val) {
break;
default: FILE_LOG(logERROR, ("Unrecognized mode in network parameter: %d\n",mode)); return -1;
default: LOG(logERROR, ("Unrecognized mode in network parameter: %d\n",mode)); return -1;
}
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Could not read register to set network parameter. FAIL\n"));
LOG(logERROR, ("Could not read register to set network parameter. FAIL\n"));
return -1;
} else {
if (val > -1) {
@ -655,11 +655,11 @@ int Beb_ResetToHardwareSettings() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Reset to Hardware Settings FAIL\n"));
LOG(logERROR, ("Reset to Hardware Settings FAIL\n"));
} else {
value = Beb_Write32(csp0base, MASTERCONFIG_OFFSET,0);
if (value) {
FILE_LOG(logERROR, ("Could not reset to hardware settings\n"));
LOG(logERROR, ("Could not reset to hardware settings\n"));
} else {
ret = 0;
}
@ -682,11 +682,11 @@ u_int32_t Beb_GetFirmwareRevision() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_VERSION);
if (fd < 0) {
FILE_LOG(logERROR, ("Firmware Revision Read FAIL\n"));
LOG(logERROR, ("Firmware Revision Read FAIL\n"));
} else {
value = Beb_Read32(csp0base, FIRMWARE_VERSION_OFFSET);
if (!value) {
FILE_LOG(logERROR, ("Firmware Revision Number does not exist in this version\n"));
LOG(logERROR, ("Firmware Revision Number does not exist in this version\n"));
}
}
@ -706,11 +706,11 @@ u_int32_t Beb_GetFirmwareSoftwareAPIVersion() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_VERSION);
if (fd < 0) {
FILE_LOG(logERROR, ("Firmware Software API Version Read FAIL\n"));
LOG(logERROR, ("Firmware Software API Version Read FAIL\n"));
} else {
value = Beb_Read32(csp0base, FIRMWARESOFTWARE_API_OFFSET);
if (!value) {
FILE_LOG(logERROR, ("Firmware Software API Version does not exist in this version\n"));
LOG(logERROR, ("Firmware Software API Version does not exist in this version\n"));
}
}
@ -731,14 +731,14 @@ void Beb_ResetFrameNumber() {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Reset Frame Number FAIL\n"));
LOG(logERROR, ("Reset Frame Number FAIL\n"));
} else {
//write a 1
Beb_Write32(csp0base, FRAME_NUM_RESET_OFFSET, 1);
usleep(100000); //100ms
//write a 0
Beb_Write32(csp0base, FRAME_NUM_RESET_OFFSET, 0);
FILE_LOG(logINFO, ("Frame Number Reset OK\n"));
LOG(logINFO, ("Frame Number Reset OK\n"));
//close file pointer
Beb_close(fd,csp0base);
}
@ -764,7 +764,7 @@ int Beb_InitBebInfos() {//file name at some point
int i0=Beb_detid,i1=0;
if (Beb_GetBebInfoIndex(i0)) {
FILE_LOG(logERROR, ("cant add beb. adding beb %d, beb number %d already added.\n",Beb_detid, i0));
LOG(logERROR, ("cant add beb. adding beb %d, beb number %d already added.\n",Beb_detid, i0));
exit(0);
}
struct BebInfo b1;
@ -798,7 +798,7 @@ int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, char* src_mac
/******* if (!i) return 0;****************************/ //i must be greater than 0, zero is the global send
BebInfo_SetHeaderInfo(&beb_infos[i],ten_gig,src_mac,src_ip,src_port);
FILE_LOG(logINFO, ("Printing Beb info number (%d) :\n",i));
LOG(logINFO, ("Printing Beb info number (%d) :\n",i));
BebInfo_Print(&beb_infos[i]);
return 1;
@ -813,7 +813,7 @@ int Beb_CheckSourceStuffBebInfo() {
if (!Beb_SetHeaderData(
BebInfo_GetBebNumber(&beb_infos[i]),0,"00:00:00:00:00:00","10.0.0.1",20000)||
!Beb_SetHeaderData(BebInfo_GetBebNumber(&beb_infos[i]),1,"00:00:00:00:00:00","10.0.0.1",20000)) {
FILE_LOG(logINFO, ("Error in BebInfo for module number %d.\n",BebInfo_GetBebNumber(&beb_infos[i])));
LOG(logINFO, ("Error in BebInfo for module number %d.\n",BebInfo_GetBebNumber(&beb_infos[i])));
BebInfo_Print(&beb_infos[i]);
return 0;
}
@ -826,10 +826,10 @@ unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb) {
unsigned int i;
for(i=1;i<bebInfoSize;i++)
if (beb_numb==BebInfo_GetBebNumber(&beb_infos[i])) {
FILE_LOG(logDEBUG1, ("*****found beb index:%d, for beb number:%d\n",i,beb_numb));
LOG(logDEBUG1, ("*****found beb index:%d, for beb number:%d\n",i,beb_numb));
return i;
}
FILE_LOG(logDEBUG1, ("*****Returning 0\n"));
LOG(logDEBUG1, ("*****Returning 0\n"));
return 0;
}
@ -841,7 +841,7 @@ int Beb_WriteTo(unsigned int index) {
return 1;
if (index>=bebInfoSize) {
FILE_LOG(logERROR, ("WriteTo index error.\n"));
LOG(logERROR, ("WriteTo index error.\n"));
return 0;
}
@ -886,7 +886,7 @@ int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header
int fd = Beb_open(&csp0base,bram_phy_addr);
if (fd < 0) {
FILE_LOG(logERROR, ("Set up UDP Header FAIL\n"));
LOG(logERROR, ("Set up UDP Header FAIL\n"));
} else {
//read data
memcpy(csp0base+header_number*16, &udp_header, sizeof(udp_header));
@ -932,18 +932,18 @@ int Beb_SetHeaderData1(char* src_mac, char* src_ip, unsigned int src_port, char*
*/
if (!Beb_SetMAC(src_mac,&(udp_header.src_mac[0]))) return 0;
FILE_LOG(logINFO, ("Setting Source MAC to %s\n",src_mac));
LOG(logINFO, ("Setting Source MAC to %s\n",src_mac));
if (!Beb_SetIP(src_ip,&(udp_header.src_ip[0]))) return 0;
FILE_LOG(logINFO, ("Setting Source IP to %s\n",src_ip));
LOG(logINFO, ("Setting Source IP to %s\n",src_ip));
if (!Beb_SetPortNumber(src_port,&(udp_header.src_port[0]))) return 0;
FILE_LOG(logINFO, ("Setting Source port to %d\n",src_port));
LOG(logINFO, ("Setting Source port to %d\n",src_port));
if (!Beb_SetMAC(dst_mac,&(udp_header.dst_mac[0]))) return 0;
FILE_LOG(logINFO, ("Setting Destination MAC to %s\n",dst_mac));
LOG(logINFO, ("Setting Destination MAC to %s\n",dst_mac));
if (!Beb_SetIP(dst_ip,&(udp_header.dst_ip[0]))) return 0;
FILE_LOG(logINFO, ("Setting Destination IP to %s\n",dst_ip));
LOG(logINFO, ("Setting Destination IP to %s\n",dst_ip));
if (!Beb_SetPortNumber(dst_port,&(udp_header.dst_port[0]))) return 0;
FILE_LOG(logINFO, ("Setting Destination port to %d\n",dst_port));
LOG(logINFO, ("Setting Destination port to %d\n",dst_port));
Beb_AdjustIPChecksum(&udp_header);
@ -968,7 +968,7 @@ int Beb_SetMAC(char* mac, uint8_t* dst_ptr) {
char *pch = strtok (macVal,":");
while (pch != NULL) {
if (strlen(pch)!=2) {
FILE_LOG(logERROR, ("Error: in mac address -> %s\n",macVal));
LOG(logERROR, ("Error: in mac address -> %s\n",macVal));
return 0;
}
@ -987,7 +987,7 @@ int Beb_SetIP(char* ip, uint8_t* dst_ptr) {
char *pch = strtok (ipVal,".");
while (pch != NULL) {
if (((i!=3) && ((strlen(pch)>3) || (strlen(pch)<1))) || ((i==3)&&((strlen(pch)<1) || (strlen(pch) > 3)))) {
FILE_LOG(logERROR, ("Error: in ip address -> %s\n",ipVal));
LOG(logERROR, ("Error: in ip address -> %s\n",ipVal));
return 0;
}
@ -1050,11 +1050,11 @@ int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, i
Beb_send_data[1] = 0x62000000 | (!stop_read_when_fifo_empty) << 27 | (ten_gig==1) << 24 | packet_size << 14 | dst_number << 8 | npackets;
FILE_LOG(logDEBUG1, ("Beb_send_data[1]:%X\n",Beb_send_data[1]));
LOG(logDEBUG1, ("Beb_send_data[1]:%X\n",Beb_send_data[1]));
Beb_send_data[2] = 0;
Beb_SwapDataFun(0,2,&(Beb_send_data[1]));
FILE_LOG(logDEBUG1, ("Beb_send_data[1] Swapped:%X\n",Beb_send_data[1]));
LOG(logDEBUG1, ("Beb_send_data[1] Swapped:%X\n",Beb_send_data[1]));
if (Beb_activated) {
if (!Beb_WriteTo(i)) return 0;
@ -1085,7 +1085,7 @@ int Beb_StopAcquisition()
//open file pointer
int fd = Beb_open(&csp0base,XPAR_CMD_GENERATOR);
if (fd < 0) {
FILE_LOG(logERROR, ("Beb Stop Acquisition FAIL\n"));
LOG(logERROR, ("Beb Stop Acquisition FAIL\n"));
return 0;
} else {
//find value
@ -1098,7 +1098,7 @@ int Beb_StopAcquisition()
Beb_Write32(csp0base, (LEFT_OFFSET + STOP_ACQ_OFFSET),(valuel&(~STOP_ACQ_BIT)));
Beb_Write32(csp0base, (RIGHT_OFFSET + STOP_ACQ_OFFSET),(valuer&(~STOP_ACQ_BIT)));
FILE_LOG(logINFO, ("Beb Stop Acquisition OK\n"));
LOG(logINFO, ("Beb Stop Acquisition OK\n"));
//close file pointer
Beb_close(fd,csp0base);
}
@ -1116,7 +1116,7 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
unsigned int nl = Beb_readNLines;
unsigned int npackets = (nl * maxnp) / maxnl;
if ((nl * maxnp) % maxnl) {
FILE_LOG(logERROR, ("Read N Lines is incorrect. Switching to Full Image Readout\n"));
LOG(logERROR, ("Read N Lines is incorrect. Switching to Full Image Readout\n"));
npackets = maxnp;
}
int in_two_requests = (npackets > MAX_PACKETS_PER_REQUEST) ? 1 : 0;
@ -1126,8 +1126,8 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
unsigned int header_size = 4; //4*64 bits
unsigned int packet_size = ten_gig ? 0x200 : 0x80; // 4k or 1k packets
FILE_LOG(logDEBUG1, ("----Beb_RequestNImages Start----\n"));
FILE_LOG(logINFO, ("beb_number:%d, ten_gig:%d,dst_number:%d, npackets:%d, "
LOG(logDEBUG1, ("----Beb_RequestNImages Start----\n"));
LOG(logINFO, ("beb_number:%d, ten_gig:%d,dst_number:%d, npackets:%d, "
"Beb_bit_mode:%d, header_size:%d, nimages:%d, test_just_send_out_packets_no_wait:%d\n",
beb_number, ten_gig, dst_number, npackets, Beb_bit_mode, header_size,
nimages, test_just_send_out_packets_no_wait));
@ -1138,13 +1138,13 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
//open file pointer
int fd = Beb_open(&csp0base,XPAR_CMD_GENERATOR);
if (fd < 0) {
FILE_LOG(logERROR, ("Beb Request N Images FAIL\n"));
LOG(logERROR, ("Beb Request N Images FAIL\n"));
return 0;
} else {
{
int i;
for (i=0; i < 10; i++)
FILE_LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4))));
LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4))));
}
// Generating commands
u_int32_t send_header_command = 0x62000000 | (!test_just_send_out_packets_no_wait) << 27 | (ten_gig==1) << 24 | header_size << 14 | 0;
@ -1152,8 +1152,8 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
{
int i;
for (i=0; i < 10; i++)
FILE_LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4))));
FILE_LOG(logDEBUG1, ("%d\n",in_two_requests));
LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4))));
LOG(logDEBUG1, ("%d\n",in_two_requests));
}
//"0x20 << 8" is dst_number (0x00 for left, 0x20 for right)
//Left
@ -1181,12 +1181,12 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
{
int i;
for (i=0; i < 10; i++)
FILE_LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4)))); //*(ptrl+i));
FILE_LOG(logDEBUG1, ("%d\n",in_two_requests));
LOG(logDEBUG1, ("%X\n",Beb_Read32(csp0base, (LEFT_OFFSET + i*4)))); //*(ptrl+i));
LOG(logDEBUG1, ("%d\n",in_two_requests));
}
Beb_close(fd,csp0base);
FILE_LOG(logDEBUG1, ("----Beb_RequestNImages----\n"));
LOG(logDEBUG1, ("----Beb_RequestNImages----\n"));
}
return 1;
@ -1194,7 +1194,7 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_nu
int Beb_Test(unsigned int beb_number) {
FILE_LOG(logINFO, ("Testing module number: %d\n",beb_number));
LOG(logINFO, ("Testing module number: %d\n",beb_number));
//int SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, string dst_mac, string dst_ip, unsigned int dst_port) {
@ -1202,14 +1202,14 @@ int Beb_Test(unsigned int beb_number) {
unsigned int index = Beb_GetBebInfoIndex(beb_number);
if (!index) {
FILE_LOG(logERROR, ("Error beb number (%d)not in list????\n",beb_number));
LOG(logERROR, ("Error beb number (%d)not in list????\n",beb_number));
return 0;
}
unsigned int i;
for(i=0;i<64;i++) {
if (!Beb_SetUpUDPHeader(beb_number,0,i,"60:fb:42:f4:e3:d2","129.129.205.186",22000+i)) {
FILE_LOG(logERROR, ("Error setting up header table....\n"));
LOG(logERROR, ("Error setting up header table....\n"));
return 0;
}
}
@ -1217,7 +1217,7 @@ int Beb_Test(unsigned int beb_number) {
// SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, int stop_read_when_fifo_empty=1);
for(i=0;i<64;i++) {
if (!Beb_SendMultiReadRequest(beb_number,i%3+1,0,i,1,0,1)) {
FILE_LOG(logERROR, ("Error requesting data....\n"));
LOG(logERROR, ("Error requesting data....\n"));
return 0;
}
}
@ -1237,7 +1237,7 @@ int Beb_GetBebFPGATemp()
//open file pointer
int fd = Beb_open(&csp0base,XPAR_SYSMON_0_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Module Configuration FAIL\n"));
LOG(logERROR, ("Module Configuration FAIL\n"));
} else {
//read data
ret = Beb_Read32(csp0base, FPGA_TEMP_OFFSET);
@ -1255,11 +1255,11 @@ void Beb_SetDetectorNumber(uint32_t detid) {
return;
uint32_t swapid = Beb_swap_uint16(detid);
//FILE_LOG(logINFO, "detector id %d swapped %d\n", detid, swapid));
//LOG(logINFO, "detector id %d swapped %d\n", detid, swapid));
u_int32_t* csp0base=0;
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_TEST_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Set Detector ID FAIL\n"));
LOG(logERROR, ("Set Detector ID FAIL\n"));
return;
} else {
uint32_t value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
@ -1267,24 +1267,24 @@ void Beb_SetDetectorNumber(uint32_t detid) {
Beb_Write32(csp0base, UDP_HEADER_A_LEFT_OFST, value | ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
if ((value & UDP_HEADER_ID_MSK) != ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)) {
FILE_LOG(logERROR, ("Set Detector ID FAIL\n"));
LOG(logERROR, ("Set Detector ID FAIL\n"));
}
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
value &= UDP_HEADER_X_MSK; // to keep previous x value
Beb_Write32(csp0base, UDP_HEADER_A_RIGHT_OFST, value | ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
if ((value & UDP_HEADER_ID_MSK) != ((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)) {
FILE_LOG(logERROR, ("Set Detector ID FAIL\n"));
LOG(logERROR, ("Set Detector ID FAIL\n"));
}
Beb_close(fd,csp0base);
}
FILE_LOG(logINFO, ("Detector id %d set in UDP Header\n\n", detid));
LOG(logINFO, ("Detector id %d set in UDP Header\n\n", detid));
}
int Beb_SetQuad(int value) {
if (value < 0)
return OK;
FILE_LOG(logINFO, ("Setting Quad to %d in Beb\n", value));
LOG(logINFO, ("Setting Quad to %d in Beb\n", value));
Beb_quadEnable = (value == 0 ? 0 : 1);
return Beb_SetDetectorPosition(Beb_positions);
}
@ -1300,7 +1300,7 @@ int* Beb_GetDetectorPosition() {
int Beb_SetDetectorPosition(int pos[]) {
if (!Beb_activated)
return OK;
FILE_LOG(logINFO, ("Got Position values %d %d...\n", pos[0],pos[1]));
LOG(logINFO, ("Got Position values %d %d...\n", pos[0],pos[1]));
// save positions
Beb_positions[0] = pos[0];
@ -1321,7 +1321,7 @@ int Beb_SetDetectorPosition(int pos[]) {
//open file pointer
int fd = Beb_open(&csp0base,XPAR_PLB_GPIO_TEST_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Set Detector Position FAIL\n"));
LOG(logERROR, ("Set Detector Position FAIL\n"));
return FAIL;
} else {
uint32_t value = 0;
@ -1333,7 +1333,7 @@ int Beb_SetDetectorPosition(int pos[]) {
Beb_Write32(csp0base, UDP_HEADER_A_LEFT_OFST, value | ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
if ((value & UDP_HEADER_X_MSK) != ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) {
FILE_LOG(logERROR, ("Could not set row position for left port\n"));
LOG(logERROR, ("Could not set row position for left port\n"));
ret = FAIL;
}
// x right
@ -1343,7 +1343,7 @@ int Beb_SetDetectorPosition(int pos[]) {
Beb_Write32(csp0base, UDP_HEADER_A_RIGHT_OFST, value | ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
if ((value & UDP_HEADER_X_MSK) != ((posval << UDP_HEADER_X_OFST) & UDP_HEADER_X_MSK)) {
FILE_LOG(logERROR, ("Could not set row position for right port\n"));
LOG(logERROR, ("Could not set row position for right port\n"));
ret = FAIL;
}
@ -1356,7 +1356,7 @@ int Beb_SetDetectorPosition(int pos[]) {
Beb_Write32(csp0base, UDP_HEADER_B_LEFT_OFST, value | ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_B_LEFT_OFST);
if ((value & UDP_HEADER_Y_MSK) != ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) {
FILE_LOG(logERROR, ("Could not set column position for left port\n"));
LOG(logERROR, ("Could not set column position for left port\n"));
ret = FAIL;
}
@ -1367,7 +1367,7 @@ int Beb_SetDetectorPosition(int pos[]) {
Beb_Write32(csp0base, UDP_HEADER_B_RIGHT_OFST, value | ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK));
value = Beb_Read32(csp0base, UDP_HEADER_B_RIGHT_OFST);
if ((value & UDP_HEADER_Y_MSK) != ((posval << UDP_HEADER_Y_OFST) & UDP_HEADER_Y_MSK)) {
FILE_LOG(logERROR, ("Could not set column position for right port\n"));
LOG(logERROR, ("Could not set column position for right port\n"));
ret = FAIL;
}
@ -1376,7 +1376,7 @@ int Beb_SetDetectorPosition(int pos[]) {
Beb_close(fd,csp0base);
}
if (ret == OK) {
FILE_LOG(logINFO, ("Position set to...\n"
LOG(logINFO, ("Position set to...\n"
"\tLeft: [%d, %d]\n"
"\tRight:[%d, %d]\n",
posLeft[0], posLeft[1], posRight[0], posRight[1]));
@ -1390,12 +1390,12 @@ int Beb_SetStartingFrameNumber(uint64_t value) {
Beb_deactivatedStartFrameNumber = value;
return OK;
}
FILE_LOG(logINFO, ("Setting start frame number: %llu\n", (long long unsigned int)value));
LOG(logINFO, ("Setting start frame number: %llu\n", (long long unsigned int)value));
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_TEST_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Set Start Frame Number FAIL\n"));
LOG(logERROR, ("Set Start Frame Number FAIL\n"));
return FAIL;
}
// since the read is not implemented in firmware yet
@ -1407,7 +1407,7 @@ int Beb_SetStartingFrameNumber(uint64_t value) {
Beb_Write32(csp0base, UDP_HEADER_FRAME_NUMBER_MSB_OFST, (valueInFirmware >> 32) & (0xffffffff));
Beb_close(fd,csp0base);
FILE_LOG(logINFO, ("Going to reset Frame Number\n"));
LOG(logINFO, ("Going to reset Frame Number\n"));
Beb_ResetFrameNumber();
return OK;
}
@ -1418,11 +1418,11 @@ int Beb_GetStartingFrameNumber(uint64_t* retval, int tengigaEnable) {
return OK;
}
FILE_LOG(logDEBUG1, ("Getting start frame number\n"));
LOG(logDEBUG1, ("Getting start frame number\n"));
u_int32_t* csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_COUNTER_BASEADDR);
if (fd < 0) {
FILE_LOG(logERROR, ("Get Start Frame Number FAIL\n"));
LOG(logERROR, ("Get Start Frame Number FAIL\n"));
return FAIL;
}
@ -1440,7 +1440,7 @@ int Beb_GetStartingFrameNumber(uint64_t* retval, int tengigaEnable) {
Beb_close(fd,csp0base);
if (left1g != right1g) {
FILE_LOG(logERROR, ("Retrieved inconsistent frame numbers from 1g left %llu and right %llu\n",
LOG(logERROR, ("Retrieved inconsistent frame numbers from 1g left %llu and right %llu\n",
(long long int)left1g, (long long int)right1g));
*retval = (left1g > right1g) ? left1g : right1g; // give max to set it to when stopping acq & different value
return -2; // to differentiate between failed address mapping
@ -1461,7 +1461,7 @@ int Beb_GetStartingFrameNumber(uint64_t* retval, int tengigaEnable) {
++right10g; // increment for firmware
if (left10g != right10g) {
FILE_LOG(logERROR, ("Retrieved inconsistent frame numbers from `0g left %llu and right %llu\n",
LOG(logERROR, ("Retrieved inconsistent frame numbers from `0g left %llu and right %llu\n",
(long long int)left10g, (long long int)right10g));
*retval = (left10g > right10g) ? left10g : right10g; // give max to set it to when stopping acq & different value
return -2; // to differentiate between failed address mapping
@ -1484,15 +1484,15 @@ int Beb_open(u_int32_t** csp0base, u_int32_t offset) {
int fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (fd == -1) {
FILE_LOG(logERROR, ("\nCan't find /dev/mem!\n"));
LOG(logERROR, ("\nCan't find /dev/mem!\n"));
} else {
FILE_LOG(logDEBUG1, ("/dev/mem opened\n"));
LOG(logDEBUG1, ("/dev/mem opened\n"));
*csp0base = (u_int32_t*)mmap(0, BEB_MMAP_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, offset);
if (*csp0base == MAP_FAILED) {
FILE_LOG(logERROR, ("\nCan't map memmory area!!\n"));
LOG(logERROR, ("\nCan't map memmory area!!\n"));
fd = -1;
}
else FILE_LOG(logDEBUG1, ("CSP0 mapped %p\n",(void*)*csp0base));
else LOG(logDEBUG1, ("CSP0 mapped %p\n",(void*)*csp0base));
}
return fd;
}

View File

@ -27,7 +27,7 @@ target_compile_definitions(eigerDetectorServerMaster_virtual
)
target_link_libraries(eigerDetectorServerMaster_virtual
PUBLIC pthread rt
PUBLIC pthread rt slsProjectCWarnings
)
set_target_properties(eigerDetectorServerMaster_virtual PROPERTIES

File diff suppressed because it is too large Load Diff

View File

@ -55,7 +55,7 @@ void Feb_Interface_SendCompleteList(unsigned int n,unsigned int* list) {
int Feb_Interface_WriteTo(unsigned int ch) {
if (ch>0xfff) return 0;
FILE_LOG(logDEBUG1, ("FIW ch %d\n", ch));
LOG(logDEBUG1, ("FIW ch %d\n", ch));
Feb_Interface_send_data_raw[0] = 0x8fff0000;
if (Local_Write(ll,4,Feb_Interface_send_data_raw)!=4) return 0;
@ -176,7 +176,7 @@ int Feb_Interface_WriteMemory(unsigned int sub_num, unsigned int mem_num, unsign
start_address &= 0x3fff;
nwrites &= 0x3ff;
if (!nwrites||nwrites>Feb_Interface_send_buffer_size-2) {
FILE_LOG(logERROR, ("invalid nwrites:%d\n",nwrites));
LOG(logERROR, ("invalid nwrites:%d\n",nwrites));
return 0;
}//*d-1026

View File

@ -8,18 +8,18 @@
void Local_LocalLinkInterface1(struct LocalLinkInterface* ll,unsigned int ll_fifo_badr) {
FILE_LOG(logDEBUG1, ("Initialize PLB LL FIFOs\n"));
LOG(logDEBUG1, ("Initialize PLB LL FIFOs\n"));
ll->ll_fifo_base=0;
ll->ll_fifo_ctrl_reg=0;
if (Local_Init(ll,ll_fifo_badr)) {
Local_Reset(ll);
FILE_LOG(logDEBUG1, ("\tFIFO Status : 0x%08x\n\n\n", Local_StatusVector(ll)));
} else FILE_LOG(logERROR, ("\tCould not map LocalLink : 0x%08x\n\n\n", ll_fifo_badr));
LOG(logDEBUG1, ("\tFIFO Status : 0x%08x\n\n\n", Local_StatusVector(ll)));
} else LOG(logERROR, ("\tCould not map LocalLink : 0x%08x\n\n\n", ll_fifo_badr));
}
void Local_LocalLinkInterface(struct LocalLinkInterface* ll) {
FILE_LOG(logDEBUG1, ("Initializing new memory\n"));
LOG(logDEBUG1, ("Initializing new memory\n"));
}
@ -55,7 +55,7 @@ int Local_Reset(struct LocalLinkInterface* ll) {
int Local_Reset1(struct LocalLinkInterface* ll,unsigned int rst_mask) {
ll->ll_fifo_ctrl_reg |= rst_mask;
FILE_LOG(logDEBUG1, ("\tCTRL Register bits: 0x%08x\n",ll->ll_fifo_ctrl_reg));
LOG(logDEBUG1, ("\tCTRL Register bits: 0x%08x\n",ll->ll_fifo_ctrl_reg));
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
HWIO_xfs_out32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_CTRL,ll->ll_fifo_ctrl_reg);
@ -90,9 +90,9 @@ int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buf
last_word = (buffer_len-1)/4;
word_ptr = (unsigned int *)buffer;
FILE_LOG(logDEBUG1, ("LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base));
LOG(logDEBUG1, ("LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base));
for (i=0; i < buffer_len/4; i++)
FILE_LOG(logDEBUG1, ("%.8X ",*(((unsigned *) buffer)+i)));
LOG(logDEBUG1, ("%.8X ",*(((unsigned *) buffer)+i)));
while (words_send <= last_word)
{
@ -101,7 +101,7 @@ int Local_Write(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buf
status = HWIO_xfs_in32(ll->ll_fifo_base+4*PLB_LL_FIFO_REG_STATUS);
if ((status & PLB_LL_FIFO_STATUS_ALMOSTFULL) == 0) vacancy = 1;
if (vacancy == 0) {
FILE_LOG(logERROR, ("Fifo full!\n"));
LOG(logERROR, ("Fifo full!\n"));
}
}
@ -136,7 +136,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
volatile unsigned int fifo_val;
int sof = 0;
FILE_LOG(logDEBUG1, ("LL Read - If: %X - Data: ",ll->ll_fifo_base));
LOG(logDEBUG1, ("LL Read - If: %X - Data: ",ll->ll_fifo_base));
word_ptr = (unsigned int *)buffer;
do
@ -162,7 +162,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
{
if ( (buffer_len >> 2) > buffer_ptr)
{
FILE_LOG(logDEBUG1, ("%.8X ", fifo_val));
LOG(logDEBUG1, ("%.8X ", fifo_val));
word_ptr[buffer_ptr++] = fifo_val; //write to buffer
}
else
@ -174,7 +174,7 @@ int Local_Read(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
if (status & PLB_LL_FIFO_STATUS_LL_EOF)
{
len = (buffer_ptr << 2) -3 + ( (status & PLB_LL_FIFO_STATUS_LL_REM)>>PLB_LL_FIFO_STATUS_LL_REM_SHIFT );
FILE_LOG(logDEBUG1, ("Len: %d\n",len));
LOG(logDEBUG1, ("Len: %d\n",len));
buffer_ptr = 0;
return len;
}
@ -207,11 +207,11 @@ int Local_Test(struct LocalLinkInterface* ll,unsigned int buffer_len, void *buff
do{
len = Local_Read(ll,rec_buff_len,rec_buffer);
FILE_LOG(logDEBUG1, ("receive length: %i\n",len));
LOG(logDEBUG1, ("receive length: %i\n",len));
if (len > 0) {
rec_buffer[len]=0;
FILE_LOG(logINFO, ("%s\n", (char*) rec_buffer));
LOG(logINFO, ("%s\n", (char*) rec_buffer));
}
} while(len > 0);

View File

@ -11,6 +11,7 @@
#include <unistd.h> //to gethostname
#include <string.h>
#ifdef VIRTUAL
#include <netinet/in.h>
#include "communication_funcs_UDP.h"
#include <pthread.h>
#include <time.h>
@ -106,7 +107,7 @@ void basictests() {
initCheckDone = 0;
memset(initErrorMessage, 0, MAX_STR_LENGTH);
#ifdef VIRTUAL
FILE_LOG(logINFOBLUE, ("************ EIGER Virtual Server *****************\n\n"));
LOG(logINFOBLUE, ("************ EIGER Virtual Server *****************\n\n"));
#endif
uint32_t ipadd = getDetectorIP();
uint64_t macadd = getDetectorMAC();
@ -115,7 +116,7 @@ void basictests() {
int64_t sw_fw_apiversion = getFirmwareAPIVersion();
int64_t client_sw_apiversion = getClientServerAPIVersion();
FILE_LOG(logINFOBLUE, ("**************** EIGER Server *********************\n\n"
LOG(logINFOBLUE, ("**************** EIGER Server *********************\n\n"
"Detector IP Addr:\t\t 0x%x\n"
"Detector MAC Addr:\t\t 0x%llx\n"
@ -149,7 +150,7 @@ void basictests() {
//cant read versions
if (!fwversion || !sw_fw_apiversion) {
strcpy(initErrorMessage, "Cant read versions from FPGA. Please update firmware.\n");
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
@ -160,7 +161,7 @@ void basictests() {
"Please update detector software (min. %lld) to be compatible with this firmware.\n",
(long long int)sw_fw_apiversion,
(long long int)REQUIRED_FIRMWARE_VERSION);
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
@ -171,11 +172,11 @@ void basictests() {
"Please update firmware (min. %lld) to be compatible with this server.\n",
(long long int)fwversion,
(long long int)REQUIRED_FIRMWARE_VERSION);
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
FILE_LOG(logINFO, ("Compatibility - success\n"));
LOG(logINFO, ("Compatibility - success\n"));
}
@ -241,11 +242,15 @@ u_int64_t getDetectorMAC() {
strcat(mac,pch);
pch = strtok (NULL, ":");
}
#ifdef VIRTUAL
sscanf(mac,"%lx",&res);
#else
sscanf(mac, "%llx", &res);
#endif
//increment by 1 for 10g
if (send_to_ten_gig)
res++;
//FILE_LOG(logINFO, ("mac:%llx\n",res));
//LOG(logINFO, ("mac:%llx\n",res));
return res;
}
@ -263,6 +268,9 @@ u_int32_t getDetectorIP() {
#endif
fgets(output, sizeof(output), sysFile);
pclose(sysFile);
if (strlen(output) <= 1) {
return 0;
}
//converting IPaddress to hex.
char* pcword = strtok (output,".");
@ -273,7 +281,7 @@ u_int32_t getDetectorIP() {
}
strcpy(output,temp);
sscanf(output, "%x", &res);
//FILE_LOG(logINFO, ("ip:%x\n",res));
//LOG(logINFO, ("ip:%x\n",res));
return res;
}
@ -304,12 +312,20 @@ void initControlServer() {
if (Feb_Control_OpenSerialCommunication())
;// Feb_Control_CloseSerialCommunication();
}
FILE_LOG(logDEBUG1, ("Control server: FEB Initialization done\n"));
LOG(logDEBUG1, ("Control server: FEB Initialization done\n"));
Beb_Beb(detid);
Beb_SetDetectorNumber(getDetectorNumber());
FILE_LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
setupDetector();
// activate (if it gets ip) (later FW will deactivate at startup)
if (getDetectorIP() != 0) {
Beb_Activate(1);
Feb_Control_activate(1);
} else {
Beb_Activate(0);
Feb_Control_activate(0);
}
}
initCheckDone = 1;
#endif
@ -324,7 +340,16 @@ void initStopServer() {
Feb_Interface_FebInterface();
Feb_Control_FebControl();
Feb_Control_Init(master,top,normal,getDetectorNumber());
FILE_LOG(logDEBUG1, ("Stop server: FEB Initialization done\n"));
LOG(logDEBUG1, ("Stop server: FEB Initialization done\n"));
// activate (if it gets ip) (later FW will deactivate at startup)
// also needed for stop server for status
if (getDetectorIP() != 0) {
Beb_Activate(1);
Feb_Control_activate(1);
} else {
Beb_Activate(0);
Feb_Control_activate(0);
}
#endif
}
@ -343,7 +368,7 @@ void getModuleConfiguration() {
#else
normal = 1;
#endif
FILE_LOG(logINFOBLUE, ("Module: %s %s %s\n",
LOG(logINFOBLUE, ("Module: %s %s %s\n",
(top ? "TOP" : "BOTTOM"),
(master ? "MASTER" : "SLAVE"),
(normal ? "NORMAL" : "SPECIAL")));
@ -354,7 +379,7 @@ void getModuleConfiguration() {
int *n=&normal;
Beb_GetModuleConfiguration(m,t,n);
if (isControlServer) {
FILE_LOG(logINFOBLUE, ("Module: %s %s %s\n",
LOG(logINFOBLUE, ("Module: %s %s %s\n",
(top ? "TOP" : "BOTTOM"),
(master ? "MASTER" : "SLAVE"),
(normal ? "NORMAL" : "SPECIAL")));
@ -367,7 +392,7 @@ void getModuleConfiguration() {
pclose(sysFile);
sscanf(output,"%u",&detid);
if (isControlServer) {
FILE_LOG(logINFOBLUE, ("Detector ID: %u\n\n", detid));
LOG(logINFOBLUE, ("Detector ID: %u\n\n", detid));
}
#endif
}
@ -377,15 +402,15 @@ void getModuleConfiguration() {
/* set up detector */
void allocateDetectorStructureMemory() {
FILE_LOG(logINFO, ("This Server is for 1 Eiger half module (250k)\n\n"));
LOG(logINFO, ("This Server is for 1 Eiger half module (250k)\n\n"));
//Allocation of memory
detectorModules = malloc(sizeof(sls_detector_module));
detectorChans = malloc(NCHIP*NCHAN*sizeof(int));
detectorDacs = malloc(NDAC*sizeof(int));
FILE_LOG(logDEBUG1, ("modules from 0x%x to 0x%x\n",detectorModules, detectorModules));
FILE_LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n",detectorChans, detectorChans));
FILE_LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs));
LOG(logDEBUG1, ("modules from 0x%x to 0x%x\n",detectorModules, detectorModules));
LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n",detectorChans, detectorChans));
LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs));
(detectorModules)->dacs = detectorDacs;
(detectorModules)->chanregs = detectorChans;
(detectorModules)->ndac = NDAC;
@ -410,19 +435,19 @@ void setupDetector() {
allocateDetectorStructureMemory();
//set dacs
FILE_LOG(logINFOBLUE, ("Setting Default Dac values\n"));
LOG(logINFOBLUE, ("Setting Default Dac values\n"));
{
int i = 0;
const int defaultvals[NDAC] = DEFAULT_DAC_VALS;
for(i = 0; i < NDAC; ++i) {
setDAC((enum DACINDEX)i,defaultvals[i],0);
if ((detectorModules)->dacs[i] != defaultvals[i]) {
FILE_LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n",i ,defaultvals[i], (detectorModules)->dacs[i]));
LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n",i ,defaultvals[i], (detectorModules)->dacs[i]));
}
}
}
FILE_LOG(logINFOBLUE, ("Setting Default Parameters\n"));
LOG(logINFOBLUE, ("Setting Default Parameters\n"));
//setting default measurement parameters
setNumFrames(DEFAULT_NUM_FRAMES);
setExpTime(DEFAULT_EXPTIME);
@ -451,7 +476,7 @@ void setupDetector() {
#ifndef VIRTUAL
Feb_Control_CheckSetup();
#endif
FILE_LOG(logDEBUG1, ("Setup detector done\n\n"));
LOG(logDEBUG1, ("Setup detector done\n\n"));
}
@ -487,13 +512,13 @@ int readRegister(uint32_t offset, uint32_t* retval) {
int setDynamicRange(int dr) {
#ifdef VIRTUAL
if (dr > 0) {
FILE_LOG(logINFO, ("Setting dynamic range: %d\n", dr));
LOG(logINFO, ("Setting dynamic range: %d\n", dr));
eiger_dynamicrange = dr;
}
return eiger_dynamicrange;
#else
if (dr > 0) {
FILE_LOG(logDEBUG1, ("Setting dynamic range: %d\n", dr));
LOG(logDEBUG1, ("Setting dynamic range: %d\n", dr));
if (Feb_Control_SetDynamicRange(dr)) {
//EigerSetBitMode(dr);
@ -502,7 +527,7 @@ int setDynamicRange(int dr) {
for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested
if (Beb_SetUpTransferParameters(dr))
eiger_dynamicrange = dr;
else FILE_LOG(logERROR, ("Could not set bit mode in the back end\n"));
else LOG(logERROR, ("Could not set bit mode in the back end\n"));
}
}
//make sure back end and front end have the same bit mode
@ -549,7 +574,7 @@ int getOverFlowMode() {
void setStoreInRamMode(int mode) {
mode = (mode == 0 ? 0 : 1);
FILE_LOG(logINFO, ("Setting Store in Ram mode to %d\n", mode));
LOG(logINFO, ("Setting Store in Ram mode to %d\n", mode));
eiger_storeinmem = mode;
}
@ -583,7 +608,7 @@ int getStartingFrameNumber(uint64_t* retval) {
void setNumFrames(int64_t val) {
if (val > 0) {
FILE_LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
#ifndef VIRTUAL
if (Feb_Control_SetNExposures((unsigned int)val * eiger_ntriggers)) {
eiger_nexposures = val;
@ -606,7 +631,7 @@ int64_t getNumFrames() {
void setNumTriggers(int64_t val) {
if (val > 0) {
FILE_LOG(logINFO, ("Setting number of triggers %lld\n", (long long int)val));
LOG(logINFO, ("Setting number of triggers %lld\n", (long long int)val));
#ifndef VIRTUAL
if (Feb_Control_SetNExposures((unsigned int)val * eiger_nexposures)) {
eiger_ntriggers = val;
@ -627,7 +652,7 @@ int64_t getNumTriggers() {
}
int setExpTime(int64_t val) {
FILE_LOG(logINFO, ("Setting exptime %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting exptime %lld ns\n", (long long int)val));
#ifndef VIRTUAL
Feb_Control_SetExposureTime(val/(1E9));
#else
@ -645,7 +670,7 @@ int64_t getExpTime() {
}
int setPeriod(int64_t val) {
FILE_LOG(logINFO, ("Setting period %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting period %lld ns\n", (long long int)val));
#ifndef VIRTUAL
Feb_Control_SetExposurePeriod(val/(1E9));
#else
@ -663,7 +688,7 @@ int64_t getPeriod() {
}
int setSubExpTime(int64_t val) {
FILE_LOG(logINFO, ("Setting subexptime %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting subexptime %lld ns\n", (long long int)val));
#ifndef VIRTUAL
// calculate subdeadtime before settings subexptime
int64_t subdeadtime = Feb_Control_GetSubFramePeriod() - Feb_Control_GetSubFrameExposureTime();
@ -688,14 +713,14 @@ int64_t getSubExpTime() {
}
int setDeadTime(int64_t val) {
FILE_LOG(logINFO, ("Setting subdeadtime %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting subdeadtime %lld ns\n", (long long int)val));
#ifndef VIRTUAL
// get subexptime
int64_t subexptime = Feb_Control_GetSubFrameExposureTime();
#else
int64_t subexptime = eiger_virtual_subexptime * 10;
#endif
FILE_LOG(logINFO, ("Setting sub period (subdeadtime(%lld)): %lldns\n",
LOG(logINFO, ("Setting sub period (subdeadtime(%lld)): %lldns\n",
(long long int)subexptime,
(long long int)val),
(long long int)(val + subexptime));
@ -746,7 +771,7 @@ int64_t getMeasuredSubPeriod() {
int setModule(sls_detector_module myMod, char* mess) {
FILE_LOG(logINFO, ("Setting module with settings %d\n",myMod.reg));
LOG(logINFO, ("Setting module with settings %d\n",myMod.reg));
// settings
setSettings( (enum detectorSettings)myMod.reg);
@ -756,9 +781,9 @@ int setModule(sls_detector_module myMod, char* mess) {
if (detectorModules) {
if (copyModule(detectorModules,&myMod) == FAIL) {
sprintf(mess, "Could not copy module\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined\n"));
LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
}
@ -766,9 +791,9 @@ int setModule(sls_detector_module myMod, char* mess) {
// iodelay
if (setIODelay(myMod.iodelay)!= myMod.iodelay) {
sprintf(mess, "Could not set module. Could not set iodelay %d\n", myMod.iodelay);
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined\n"));
LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
@ -778,7 +803,7 @@ int setModule(sls_detector_module myMod, char* mess) {
else {
// (loading a random trim file) (dont return fail)
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
}
// dacs
@ -788,9 +813,9 @@ int setModule(sls_detector_module myMod, char* mess) {
setDAC((enum DACINDEX)i, myMod.dacs[i] , 0);
if (myMod.dacs[i] != (detectorModules)->dacs[i]) {
sprintf(mess, "Could not set module. Could not set dac %d\n", i);
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined\n"));
LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
}
@ -798,9 +823,9 @@ int setModule(sls_detector_module myMod, char* mess) {
// trimbits
#ifndef VIRTUAL
if (myMod.nchan == 0) {
FILE_LOG(logINFO, ("Setting module without trimbits\n"));
LOG(logINFO, ("Setting module without trimbits\n"));
} else {
FILE_LOG(logINFO, ("Setting module with trimbits\n"));
LOG(logINFO, ("Setting module with trimbits\n"));
//includ gap pixels
unsigned int tt[263680];
int iy, ichip, ix, ip = 0, ich = 0;
@ -819,9 +844,9 @@ int setModule(sls_detector_module myMod, char* mess) {
//set trimbits
if (!Feb_Control_SetTrimbits(Feb_Control_GetModuleNumber(), tt)) {
sprintf(mess, "Could not set module. Could not set trimbits\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
return FAIL;
}
}
@ -834,9 +859,9 @@ int setModule(sls_detector_module myMod, char* mess) {
setRateCorrection(0);
sprintf(mess,"Cannot set module. Cannot set Rate correction. "
"No default tau provided. Deactivating Rate Correction\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
return FAIL;
}
}
@ -847,9 +872,9 @@ int setModule(sls_detector_module myMod, char* mess) {
int64_t retvalTau = setRateCorrection(myMod.tau);
if (myMod.tau != retvalTau) {
sprintf(mess, "Cannot set module. Could not set rate correction\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
return FAIL;
}
}
@ -898,7 +923,7 @@ enum detectorSettings setSettings(enum detectorSettings sett) {
return thisSettings;
}if (sett != GET_SETTINGS)
thisSettings = sett;
FILE_LOG(logINFO, ("Settings: %d\n", thisSettings));
LOG(logINFO, ("Settings: %d\n", thisSettings));
return thisSettings;
}
@ -914,13 +939,13 @@ enum detectorSettings getSettings() {
/* parameters - threshold */
int getThresholdEnergy() {
FILE_LOG(logDEBUG1, ("Getting Threshold energy\n"));
LOG(logDEBUG1, ("Getting Threshold energy\n"));
return eiger_photonenergy;
}
int setThresholdEnergy(int ev) {
FILE_LOG(logINFO, ("Setting threshold energy:%d\n",ev));
LOG(logINFO, ("Setting threshold energy:%d\n",ev));
if (ev >= 0)
eiger_photonenergy = ev;
return getThresholdEnergy();
@ -937,7 +962,7 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
if (val < 0)
return;
FILE_LOG(logDEBUG1, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
LOG(logDEBUG1, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
if (ind == E_VTHRESHOLD) {
setDAC(E_VCMP_LL, val, mV);
@ -950,7 +975,7 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
// validate index
if (ind < 0 || ind >= NDAC) {
FILE_LOG(logERROR, ("\tDac index %d is out of bounds (0 to %d)\n", ind, NDAC - 1));
LOG(logERROR, ("\tDac index %d is out of bounds (0 to %d)\n", ind, NDAC - 1));
return;
}
@ -988,24 +1013,24 @@ int getDAC(enum DACINDEX ind, int mV) {
(ret[1]==ret[2])&&
(ret[2]==ret[3]) &&
(ret[3]==ret[4])) {
FILE_LOG(logINFO, ("\tvthreshold match\n"));
LOG(logINFO, ("\tvthreshold match\n"));
return ret[0];
} else {
FILE_LOG(logERROR, ("\tvthreshold mismatch vcmp_ll:%d vcmp_lr:%d vcmp_rl:%d vcmp_rr:%d vcp:%d\n",
LOG(logERROR, ("\tvthreshold mismatch vcmp_ll:%d vcmp_lr:%d vcmp_rl:%d vcmp_rr:%d vcp:%d\n",
ret[0],ret[1],ret[2],ret[3], ret[4]));
return -1;
}
}
if (!mV) {
FILE_LOG(logDEBUG1, ("Getting DAC %d : %d dac\n",ind, (detectorModules)->dacs[ind]));
LOG(logDEBUG1, ("Getting DAC %d : %d dac\n",ind, (detectorModules)->dacs[ind]));
return (detectorModules)->dacs[ind];
}
int voltage = -1;
// dac units to voltage
ConvertToDifferentRange(LTC2620_MIN_VAL, LTC2620_MAX_VAL, DAC_MIN_MV, DAC_MAX_MV,
(detectorModules)->dacs[ind], &voltage);
FILE_LOG(logDEBUG1, ("Getting DAC %d : %d dac (%d mV)\n",ind, (detectorModules)->dacs[ind], voltage));
LOG(logDEBUG1, ("Getting DAC %d : %d dac (%d mV)\n",ind, (detectorModules)->dacs[ind], voltage));
return voltage;
}
@ -1047,7 +1072,7 @@ int getADC(enum ADCINDEX ind) {
return -1;
}
FILE_LOG(logINFO, ("Temperature %s: %f°C\n", tempnames[ind], (double)retval/1000.00));
LOG(logINFO, ("Temperature %s: %f°C\n", tempnames[ind], (double)retval/1000.00));
return retval;
#endif
@ -1081,13 +1106,13 @@ int setHighVoltage(int val) {
// get
if (!Feb_Control_GetHighVoltage(&eiger_highvoltage)) {
FILE_LOG(logERROR, ("Could not read high voltage\n"));
LOG(logERROR, ("Could not read high voltage\n"));
return -3;
}
// tolerance of 5
if (abs(eiger_theo_highvoltage-eiger_highvoltage) > HIGH_VOLTAGE_TOLERANCE) {
FILE_LOG(logINFO, ("High voltage still ramping: %d\n", eiger_highvoltage));
LOG(logINFO, ("High voltage still ramping: %d\n", eiger_highvoltage));
return eiger_highvoltage;
}
return eiger_theo_highvoltage;
@ -1121,10 +1146,10 @@ void setTiming( enum timingMode arg) {
ret = 3;
break;
default:
FILE_LOG(logERROR, ("Unknown timing mode %d\n", arg));
LOG(logERROR, ("Unknown timing mode %d\n", arg));
return;
}
FILE_LOG(logDEBUG1, ("Setting Triggering Mode: %d\n", (int)ret));
LOG(logDEBUG1, ("Setting Triggering Mode: %d\n", (int)ret));
#ifndef VIRTUAL
if (Feb_Control_SetTriggerMode(ret,1))
#endif
@ -1143,7 +1168,7 @@ enum timingMode getTiming() {
case 3:
return GATED;
default:
FILE_LOG(logERROR, ("Unknown trigger mode found %d\n", eiger_triggermode));
LOG(logERROR, ("Unknown trigger mode found %d\n", eiger_triggermode));
return GET_TIMING_MODE;
}
}
@ -1161,22 +1186,7 @@ int configureMAC() {
int destport = udpDetails.dstport;
int destport2 = udpDetails.dstport2;
#ifdef VIRTUAL
char cDestIp[MAX_STR_LENGTH];
memset(cDestIp, 0, MAX_STR_LENGTH);
sprintf(cDestIp, "%d.%d.%d.%d", (destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff);
FILE_LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d, port2:%d)\n", cDestIp, destport, destport2));
if (setUDPDestinationDetails(0, cDestIp, destport) == FAIL) {
FILE_LOG(logERROR, ("could not set udp destination IP and port\n"));
return FAIL;
}
if (setUDPDestinationDetails(1, cDestIp, destport2) == FAIL) {
FILE_LOG(logERROR, ("could not set udp destination IP and port2\n"));
return FAIL;
}
return OK;
#else
FILE_LOG(logINFO, ("Configuring MAC\n"));
LOG(logINFO, ("Configuring MAC\n"));
char src_mac[50], src_ip[INET_ADDRSTRLEN],dst_mac[50], dst_ip[INET_ADDRSTRLEN];
getMacAddressinString(src_mac, 50, sourcemac);
@ -1184,15 +1194,32 @@ int configureMAC() {
getIpAddressinString(src_ip, sourceip);
getIpAddressinString(dst_ip, destip);
FILE_LOG(logINFO, (
LOG(logINFO, (
"\tSource IP : %s\n"
"\tSource MAC : %s\n"
"\tSource Port : %d\n"
"\tDest IP : %s\n"
"\tDest MAC : %s\n",
"\tDest MAC : %s\n"
"\tDest Port : %d\n"
"\tDest Port2 : %d\n",
src_ip, src_mac, src_port,
dst_ip, dst_mac));
dst_ip, dst_mac, destport, destport2));
#ifdef VIRTUAL
char cDestIp[MAX_STR_LENGTH];
memset(cDestIp, 0, MAX_STR_LENGTH);
sprintf(cDestIp, "%d.%d.%d.%d", (destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff);
LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d, port2:%d)\n", cDestIp, destport, destport2));
if (setUDPDestinationDetails(0, cDestIp, destport) == FAIL) {
LOG(logERROR, ("could not set udp destination IP and port\n"));
return FAIL;
}
if (setUDPDestinationDetails(1, cDestIp, destport2) == FAIL) {
LOG(logERROR, ("could not set udp destination IP and port2\n"));
return FAIL;
}
return OK;
#else
int beb_num = detid;
int header_number = 0;
@ -1200,13 +1227,13 @@ int configureMAC() {
if (!top)
dst_port = destport2;
FILE_LOG(logINFO, ("\tDest Port : %d\n", dst_port));
LOG(logINFO, ("\tDest Port : %d\n", dst_port));
int i=0;
/* for(i=0;i<32;i++) { modified for Aldo*/
if (Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) &&
Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port)) {
FILE_LOG(logDEBUG1, ("\tset up left ok\n"));
LOG(logDEBUG1, ("\tset up left ok\n"));
} else {
return FAIL;
}
@ -1216,12 +1243,12 @@ int configureMAC() {
dst_port = destport2;
if (!top)
dst_port = destport;
FILE_LOG(logINFO, ("\tDest Port : %d\n",dst_port));
LOG(logINFO, ("\tDest Port : %d\n",dst_port));
/*for(i=0;i<32;i++) {*//** modified for Aldo*/
if (Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) &&
Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port)) {
FILE_LOG(logDEBUG1, (" set up right ok\n"));
LOG(logDEBUG1, (" set up right ok\n"));
} else {
return FAIL;
}
@ -1283,8 +1310,8 @@ int setInterruptSubframe(int value) {
if(!Feb_Control_SetInterruptSubframe(value)) {
return FAIL;
}
return OK;
#endif
return OK;
}
int getInterruptSubframe() {
@ -1303,8 +1330,8 @@ int setReadNLines(int value) {
return FAIL;
}
Beb_SetReadNLines(value);
return OK;
#endif
return OK;
}
int getReadNLines() {
@ -1317,7 +1344,7 @@ int getReadNLines() {
int enableTenGigabitEthernet(int val) {
if (val!=-1) {
FILE_LOG(logINFO, ("Setting 10Gbe: %d\n", (val > 0) ? 1 : 0));
LOG(logINFO, ("Setting 10Gbe: %d\n", (val > 0) ? 1 : 0));
if (val>0)
send_to_ten_gig = 1;
else
@ -1332,11 +1359,11 @@ int enableTenGigabitEthernet(int val) {
/* eiger specific - iodelay, pulse, rate, temp, activate, delay nw parameter */
int setClockDivider(enum CLKINDEX ind, int val) {
if (ind != RUN_CLK) {
FILE_LOG(logERROR, ("Unknown clock index: %d\n", ind));
LOG(logERROR, ("Unknown clock index: %d\n", ind));
return FAIL;
}
if (val >= 0) {
FILE_LOG(logINFO, ("Setting Read out Speed: %d\n", val));
LOG(logINFO, ("Setting Read out Speed: %d\n", val));
#ifndef VIRTUAL
if (Feb_Control_SetReadoutSpeed(val))
#endif
@ -1347,7 +1374,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
int getClockDivider(enum CLKINDEX ind) {
if (ind != RUN_CLK) {
FILE_LOG(logERROR, ("Unknown clock index: %d\n", ind));
LOG(logERROR, ("Unknown clock index: %d\n", ind));
return FAIL;
}
return eiger_readoutspeed;
@ -1355,7 +1382,7 @@ int getClockDivider(enum CLKINDEX ind) {
int setIODelay(int val) {
if (val!=-1) {
FILE_LOG(logDEBUG1, ("Setting IO Delay: %d\n",val));
LOG(logDEBUG1, ("Setting IO Delay: %d\n",val));
#ifndef VIRTUAL
if (Feb_Control_SetIDelays(Feb_Control_GetModuleNumber(),val))
#endif
@ -1367,7 +1394,7 @@ int setIODelay(int val) {
int setCounterBit(int val) {
if (val!=-1) {
FILE_LOG(logINFO, ("Setting Counter Bit: %d\n",val));
LOG(logINFO, ("Setting Counter Bit: %d\n",val));
#ifdef VIRTUAL
eiger_virtual_counter_bit = val;
#else
@ -1431,10 +1458,10 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
//same setting
if ((tau_in_nsec == custom_tau_in_nsec) && (ratetable_period_in_nsec == actual_period)) {
if (eiger_dynamicrange == 32) {
FILE_LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
(long long int)tau_in_nsec,(long long int)ratetable_period_in_nsec));
} else {
FILE_LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same exptime %lldns\n",
LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same exptime %lldns\n",
(long long int)tau_in_nsec,(long long int)ratetable_period_in_nsec));
}
}
@ -1448,7 +1475,7 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
}
//activating rate correction
eiger_virtual_ratecorrection_variable = 1;
FILE_LOG(logINFO, ("Rate Correction Value set to %lld ns\n",(long long int)eiger_virtual_ratetable_tau_in_ns));
LOG(logINFO, ("Rate Correction Value set to %lld ns\n",(long long int)eiger_virtual_ratetable_tau_in_ns));
return eiger_virtual_ratetable_tau_in_ns;
#else
@ -1477,10 +1504,10 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
//same setting
if ((tau_in_nsec == custom_tau_in_nsec) && (ratetable_period_in_nsec == actual_period)) {
if (dr == 32) {
FILE_LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
tau_in_nsec,ratetable_period_in_nsec));
} else {
FILE_LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same exptime %lldns\n",
LOG(logINFO, ("Rate Table already created before: Same Tau %lldns, Same exptime %lldns\n",
tau_in_nsec,ratetable_period_in_nsec));
}
}
@ -1488,14 +1515,14 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
else {
int ret = Feb_Control_SetRateCorrectionTau(custom_tau_in_nsec);
if (ret<=0) {
FILE_LOG(logERROR, ("Rate correction failed. Deactivating rate correction\n"));
LOG(logERROR, ("Rate correction failed. Deactivating rate correction\n"));
Feb_Control_SetRateCorrectionVariable(0);
return ret;
}
}
//activating rate correction
Feb_Control_SetRateCorrectionVariable(1);
FILE_LOG(logINFO, ("Rate Correction Value set to %lld ns\n", (long long int)Feb_Control_Get_RateTable_Tau_in_nsec()));
LOG(logINFO, ("Rate Correction Value set to %lld ns\n", (long long int)Feb_Control_Get_RateTable_Tau_in_nsec()));
Feb_Control_PrintCorrectedValues();
return Feb_Control_Get_RateTable_Tau_in_nsec();
@ -1516,7 +1543,7 @@ int getDefaultSettingsTau_in_nsec() {
void setDefaultSettingsTau_in_nsec(int t) {
default_tau_from_file = t;
FILE_LOG(logINFO, ("Default tau set to %d\n", default_tau_from_file));
LOG(logINFO, ("Default tau set to %d\n", default_tau_from_file));
}
int64_t getCurrentTau() {
@ -1531,7 +1558,7 @@ int64_t getCurrentTau() {
}
void setExternalGating(int enable[]) {
if (enable>=0) {
if (enable[0]>=0 && enable[1]>=0) {
#ifndef VIRTUAL
Feb_Control_SetExternalEnableMode(enable[0], enable[1]);//enable = 0 or 1, polarity = 0 or 1 , where 1 is positive
#endif
@ -1545,7 +1572,7 @@ void setExternalGating(int enable[]) {
int setAllTrimbits(int val) {
#ifndef VIRTUAL
if (!Feb_Control_SaveAllTrimbitsTo(val)) {
FILE_LOG(logERROR, ("Could not set all trimbits\n"));
LOG(logERROR, ("Could not set all trimbits\n"));
return FAIL;
}
#endif
@ -1556,7 +1583,7 @@ int setAllTrimbits(int val) {
}
}
FILE_LOG(logINFO, ("All trimbits have been set to %d\n", val));
LOG(logINFO, ("All trimbits have been set to %d\n", val));
return OK;
}
@ -1572,7 +1599,7 @@ int getAllTrimbits() {
}
}
FILE_LOG(logINFO, ("Value of all Trimbits: %d\n", value));
LOG(logINFO, ("Value of all Trimbits: %d\n", value));
return value;
}
@ -1684,7 +1711,7 @@ int setTransmissionDelayRight(int value) {
int prepareAcquisition() {
#ifndef VIRTUAL
FILE_LOG(logINFO, ("Going to prepare for acquisition with counter_bit:%d\n",Feb_Control_Get_Counter_Bit()));
LOG(logINFO, ("Going to prepare for acquisition with counter_bit:%d\n",Feb_Control_Get_Counter_Bit()));
Feb_Control_PrepareForAcquisition();
#endif
return OK;
@ -1701,15 +1728,15 @@ int startStateMachine() {
if(createUDPSocket(1) != OK) {
return FAIL;
}
FILE_LOG(logINFOBLUE, ("starting state machine\n"));
LOG(logINFOBLUE, ("starting state machine\n"));
eiger_virtual_status = 1;
eiger_virtual_stop = 0;
if (pthread_create(&eiger_virtual_tid, NULL, &start_timer, NULL)) {
FILE_LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
eiger_virtual_status = 0;
return FAIL;
}
FILE_LOG(logINFO ,("Virtual Acquisition started\n"));
LOG(logINFO ,("Virtual Acquisition started\n"));
return OK;
#else
@ -1717,21 +1744,21 @@ int startStateMachine() {
//get the DAQ toggle bit
prev_flag = Feb_Control_AcquisitionStartedBit();
FILE_LOG(logINFO, ("Going to start acquisition\n"));
LOG(logINFO, ("Going to start acquisition\n"));
Feb_Control_StartAcquisition();
if (!eiger_storeinmem) {
FILE_LOG(logINFO, ("requesting images right after start\n"));
LOG(logINFO, ("requesting images right after start\n"));
ret = startReadOut();
}
//wait for acquisition start
if (ret == OK) {
if (!Feb_Control_WaitForStartedFlag(5000, prev_flag)) {
FILE_LOG(logERROR, ("Acquisition did not FILE_LOG(logERROR ouble reading register\n"));
LOG(logERROR, ("Acquisition did not LOG(logERROR ouble reading register\n"));
return FAIL;
}
FILE_LOG(logINFOGREEN, ("Acquisition started\n"));
LOG(logINFOGREEN, ("Acquisition started\n"));
}
return ret;
@ -1752,7 +1779,7 @@ void* start_timer(void* arg) {
int numPacketsPerFrame = (tgEnable ? 4 : 16) * dr;
int npixelsx = 256 * 2 * bytesPerPixel;
int databytes = 256 * 256 * 2 * bytesPerPixel;
FILE_LOG(logINFO, (" dr:%f\n bytesperpixel:%d\n tgenable:%d\n datasize:%d\n packetsize:%d\n numpackes:%d\n npixelsx:%d\n databytes:%d\n",
LOG(logINFO, (" dr:%f\n bytesperpixel:%d\n tgenable:%d\n datasize:%d\n packetsize:%d\n numpackes:%d\n npixelsx:%d\n databytes:%d\n",
dr, bytesPerPixel, tgEnable, datasize, packetsize, numPacketsPerFrame, npixelsx, databytes));
@ -1828,7 +1855,7 @@ void* start_timer(void* arg) {
sendUDPPacket(1, packetData2, packetsize);
}
}
FILE_LOG(logINFO, ("Sent frame: %d\n", frameNr));
LOG(logINFO, ("Sent frame: %d\n", frameNr));
clock_gettime(CLOCK_REALTIME, &end);
int64_t time_ns = ((end.tv_sec - begin.tv_sec) * 1E9 +
(end.tv_nsec - begin.tv_nsec));
@ -1846,7 +1873,7 @@ void* start_timer(void* arg) {
closeUDPSocket(1);
eiger_virtual_status = 0;
FILE_LOG(logINFOBLUE, ("Finished Acquiring\n"));
LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL;
}
#endif
@ -1855,13 +1882,13 @@ void* start_timer(void* arg) {
int stopStateMachine() {
FILE_LOG(logINFORED, ("Going to stop acquisition\n"));
LOG(logINFORED, ("Going to stop acquisition\n"));
#ifdef VIRTUAL
eiger_virtual_stop = 0;
return OK;
#else
if ((Feb_Control_StopAcquisition() != STATUS_IDLE) || (!Beb_StopAcquisition()) ) {
FILE_LOG(logERROR, ("failed to stop acquisition\n"));
LOG(logERROR, ("failed to stop acquisition\n"));
return FAIL;
}
@ -1887,7 +1914,7 @@ int softwareTrigger() {
int startReadOut() {
FILE_LOG(logINFO, ("Requesting images...\n"));
LOG(logINFO, ("Requesting images...\n"));
#ifdef VIRTUAL
return OK;
#else
@ -1918,10 +1945,10 @@ int startReadOut() {
enum runStatus getRunStatus() {
#ifdef VIRTUAL
if (eiger_virtual_status == 0) {
FILE_LOG(logINFO, ("Status: IDLE\n"));
LOG(logINFO, ("Status: IDLE\n"));
return IDLE;
} else {
FILE_LOG(logINFO, ("Status: RUNNING...\n"));
LOG(logINFO, ("Status: RUNNING...\n"));
return RUNNING;
}
#else
@ -1929,13 +1956,13 @@ enum runStatus getRunStatus() {
int i = Feb_Control_AcquisitionInProgress();
switch (i) {
case STATUS_ERROR:
FILE_LOG(logERROR, ("Status: ERROR reading status register\n"));
LOG(logERROR, ("Status: ERROR reading status register\n"));
return ERROR;
case STATUS_IDLE:
FILE_LOG(logINFOBLUE, ("Status: IDLE\n"));
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
default:
FILE_LOG(logINFOBLUE, ("Status: RUNNING...\n"));
LOG(logINFOBLUE, ("Status: RUNNING...\n"));
return RUNNING;
}
@ -1951,22 +1978,22 @@ void readFrame(int *ret, char *mess) {
while(eiger_virtual_status == 1){
usleep(500);
}
FILE_LOG(logINFOGREEN, ("acquisition successfully finished\n"));
LOG(logINFOGREEN, ("acquisition successfully finished\n"));
return;
#else
if (Feb_Control_WaitForFinishedFlag(5000) == STATUS_ERROR) {
FILE_LOG(logERROR, ("Waiting for finished flag\n"));
LOG(logERROR, ("Waiting for finished flag\n"));
*ret = FAIL;
return;
}
FILE_LOG(logINFOGREEN, ("Acquisition finished\n"));
LOG(logINFOGREEN, ("Acquisition finished\n"));
if (eiger_storeinmem) {
FILE_LOG(logINFO, ("requesting images after storing in memory\n"));
LOG(logINFO, ("requesting images after storing in memory\n"));
if (startReadOut() == FAIL) {
strcpy(mess,"Could not execute read image requests\n");
FILE_LOG(logERROR, (mess));
LOG(logERROR, (mess));
*ret = (int)FAIL;
return;
}
@ -1974,7 +2001,7 @@ void readFrame(int *ret, char *mess) {
//wait for detector to send
Beb_EndofDataSend(send_to_ten_gig);
FILE_LOG(logINFOGREEN, ("Acquisition successfully finished\n"));
LOG(logINFOGREEN, ("Acquisition successfully finished\n"));
#endif
}
@ -1993,7 +2020,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
int idac, ichan;
int ret=OK;
FILE_LOG(logDEBUG1, ("Copying module\n"));
LOG(logDEBUG1, ("Copying module\n"));
if (srcMod->serialnumber>=0) {
@ -2001,16 +2028,16 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
}
//no trimbit feature
if (destMod->nchan && ((srcMod->nchan)>(destMod->nchan))) {
FILE_LOG(logINFO, ("Number of channels of source is larger than number of channels of destination\n"));
LOG(logINFO, ("Number of channels of source is larger than number of channels of destination\n"));
return FAIL;
}
if ((srcMod->ndac)>(destMod->ndac)) {
FILE_LOG(logINFO, ("Number of dacs of source is larger than number of dacs of destination\n"));
LOG(logINFO, ("Number of dacs of source is larger than number of dacs of destination\n"));
return FAIL;
}
FILE_LOG(logDEBUG1, ("DACs: src %d, dest %d\n",srcMod->ndac,destMod->ndac));
FILE_LOG(logDEBUG1, ("Chans: src %d, dest %d\n",srcMod->nchan,destMod->nchan));
LOG(logDEBUG1, ("DACs: src %d, dest %d\n",srcMod->ndac,destMod->ndac));
LOG(logDEBUG1, ("Chans: src %d, dest %d\n",srcMod->nchan,destMod->nchan));
destMod->ndac=srcMod->ndac;
destMod->nchip=srcMod->nchip;
destMod->nchan=srcMod->nchan;
@ -2022,7 +2049,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
destMod->tau=srcMod->tau;
if (srcMod->eV>=0)
destMod->eV=srcMod->eV;
FILE_LOG(logDEBUG1, ("Copying register %x (%x)\n",destMod->reg,srcMod->reg ));
LOG(logDEBUG1, ("Copying register %x (%x)\n",destMod->reg,srcMod->reg ));
if (destMod->nchan!=0) {
for (ichan=0; ichan<(srcMod->nchan); ichan++) {
@ -2030,7 +2057,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
*((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan);
}
}
else FILE_LOG(logINFO, ("Not Copying trimbits\n"));
else LOG(logINFO, ("Not Copying trimbits\n"));
for (idac=0; idac<(srcMod->ndac); idac++) {
if (*((srcMod->dacs)+idac)>=0) {

View File

@ -76,6 +76,8 @@ enum CLKINDEX {RUN_CLK, NUM_CLOCKS};
#define DEFAULT_TEST_MODE (0)
#define DEFAULT_HIGH_VOLTAGE (0)
#define MAX_TRIMBITS_VALUE (63)
#define MAX_ROWS_PER_READOUT (256)
#define MAX_PACKETS_PER_REQUEST (256)

View File

@ -27,7 +27,7 @@ target_compile_definitions(gotthard2DetectorServer_virtual
)
target_link_libraries(gotthard2DetectorServer_virtual
PUBLIC pthread rt
PUBLIC pthread rt slsProjectCWarnings
)
set_target_properties(gotthard2DetectorServer_virtual PROPERTIES

View File

@ -25,7 +25,7 @@ target_compile_definitions(gotthardDetectorServer_virtual
)
target_link_libraries(gotthardDetectorServer_virtual
PUBLIC pthread rt
PUBLIC pthread rt slsProjectCWarnings
)
set_target_properties(gotthardDetectorServer_virtual PROPERTIES

View File

@ -14,21 +14,18 @@ add_executable(jungfrauDetectorServer_virtual
../slsDetectorServer/src/communication_funcs_UDP.c
)
include_directories(
target_include_directories(jungfrauDetectorServer_virtual
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
../slsDetectorServer/include
../../slsSupportLib/include
)
target_include_directories(jungfrauDetectorServer_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(jungfrauDetectorServer_virtual
PUBLIC JUNGFRAUD VIRTUAL STOP_SERVER
)
target_link_libraries(jungfrauDetectorServer_virtual
PUBLIC pthread rt slsProjectOptions slsProjectWarnings
PUBLIC pthread rt slsProjectCWarnings
)
set_target_properties(jungfrauDetectorServer_virtual PROPERTIES
@ -36,5 +33,6 @@ set_target_properties(jungfrauDetectorServer_virtual PROPERTIES
)
install(TARGETS jungfrauDetectorServer_virtual
EXPORT "${TARGETS_EXPORT_NAME}"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@ -30,7 +30,7 @@ target_compile_definitions(moenchDetectorServer_virtual
)
target_link_libraries(moenchDetectorServer_virtual
PUBLIC pthread rt
PUBLIC pthread rt slsProjectCWarnings
)
set_target_properties(moenchDetectorServer_virtual PROPERTIES

View File

@ -59,6 +59,7 @@ enum CLKINDEX {RUN_CLK, ADC_CLK, SYNC_CLK, DBIT_CLK, NUM_CLOCKS};
#define NUM_BYTES_PER_PIXEL (DYNAMIC_RANGE / 8)
#define CLK_FREQ (156.25) /* MHz */
#define NSAMPLES_PER_ROW (25)
#define NCHANS_PER_ADC (25)
/** Default Parameters */
#define DEFAULT_PATTERN_FILE ("DefaultPattern.txt")

View File

@ -26,7 +26,7 @@ target_compile_definitions(mythen3DetectorServer_virtual
)
target_link_libraries(mythen3DetectorServer_virtual
PUBLIC pthread rt
PUBLIC pthread rt slsProjectCWarnings
)
set_target_properties(mythen3DetectorServer_virtual PROPERTIES

View File

@ -1,7 +1,6 @@
#include "slsDetectorFunctionList.h"
#include "versionAPI.h"
#include "clogger.h"
#include "nios.h"
#include "DAC6571.h"
#include "LTC2620_Driver.h"
#include "common.h"
@ -37,7 +36,7 @@ int32_t clkPhase[NUM_CLOCKS] = {};
uint32_t clkFrequency[NUM_CLOCKS] = {};
int highvoltage = 0;
int dacValues[NDAC] = {0};
int dacValues[NDAC] = {};
int detPos[2] = {};
uint32_t countermask = 0; // will be removed later when in firmware converted to mask
@ -55,28 +54,28 @@ void basictests() {
initCheckDone = 0;
memset(initErrorMessage, 0, MAX_STR_LENGTH);
#ifdef VIRTUAL
FILE_LOG(logINFOBLUE, ("******** Mythen3 Virtual Server *****************\n"));
LOG(logINFOBLUE, ("******** Mythen3 Virtual Server *****************\n"));
if (mapCSP0() == FAIL) {
strcpy(initErrorMessage,
"Could not map to memory. Dangerous to continue.\n");
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
}
return;
#else
FILE_LOG(logINFOBLUE, ("************ Mythen3 Server *********************\n"));
LOG(logINFOBLUE, ("************ Mythen3 Server *********************\n"));
if (mapCSP0() == FAIL) {
strcpy(initErrorMessage,
"Could not map to memory. Dangerous to continue.\n");
FILE_LOG(logERROR, ("%s\n\n", initErrorMessage));
LOG(logERROR, ("%s\n\n", initErrorMessage));
initError = FAIL;
return;
}
// does check only if flag is 0 (by default), set by command line
if ((!debugflag) && ((testFpga() == FAIL)|| (testBus() == FAIL))) {
if ((!debugflag) && ((checkType() == FAIL) || (testFpga() == FAIL)|| (testBus() == FAIL))) {
strcpy(initErrorMessage,
"Could not pass basic tests of FPGA and bus. Dangerous to continue.\n");
FILE_LOG(logERROR, ("%s\n\n", initErrorMessage));
LOG(logERROR, ("%s\n\n", initErrorMessage));
initError = FAIL;
return;
}
@ -89,7 +88,7 @@ void basictests() {
int64_t client_sw_apiversion = getClientServerAPIVersion();
uint32_t requiredFirmwareVersion = REQRD_FRMWRE_VRSN;
FILE_LOG(logINFOBLUE, ("*************************************************\n"
LOG(logINFOBLUE, ("*************************************************\n"
"Hardware Version:\t\t 0x%x\n"
"Detector IP Addr:\t\t 0x%x\n"
@ -118,11 +117,11 @@ void basictests() {
//cant read versions
FILE_LOG(logINFO, ("Testing Firmware-software compatibility:\n"));
LOG(logINFO, ("Testing Firmware-software compatibility:\n"));
if(!fwversion || !sw_fw_apiversion){
strcpy(initErrorMessage,
"Cant read versions from FPGA. Please update firmware.\n");
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
@ -134,7 +133,7 @@ void basictests() {
"Please update detector software (min. 0x%llx) to be compatible with this firmware.\n",
(long long int)sw_fw_apiversion,
(long long int)requiredFirmwareVersion);
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
@ -146,11 +145,11 @@ void basictests() {
"Please update firmware (min. 0x%llx) to be compatible with this server.\n",
(long long int)fwversion,
(long long int)requiredFirmwareVersion);
FILE_LOG(logERROR, (initErrorMessage));
LOG(logERROR, (initErrorMessage));
initError = FAIL;
return;
}
FILE_LOG(logINFO, ("Compatibility - success\n"));
LOG(logINFO, ("Compatibility - success\n"));
#endif
}
@ -161,7 +160,7 @@ int checkType() {
#endif
u_int32_t type = ((bus_r(FPGA_VERSION_REG) & DETECTOR_TYPE_MSK) >> DETECTOR_TYPE_OFST);
if (type != MYTHEN3){
FILE_LOG(logERROR, ("This is not a Mythen3 Server (read %d, expected %d)\n", type, MYTHEN3));
LOG(logERROR, ("This is not a Mythen3 firmware (read %d, expected %d)\n", type, MYTHEN3));
return FAIL;
}
@ -172,15 +171,15 @@ int testFpga() {
#ifdef VIRTUAL
return OK;
#endif
FILE_LOG(logINFO, ("Testing FPGA:\n"));
LOG(logINFO, ("Testing FPGA:\n"));
//fixed pattern
int ret = OK;
volatile u_int32_t val = bus_r(FIX_PATT_REG);
if (val == FIX_PATT_VAL) {
FILE_LOG(logINFO, ("Fixed pattern: successful match 0x%08x\n",val));
LOG(logINFO, ("Fixed pattern: successful match 0x%08x\n",val));
} else {
FILE_LOG(logERROR, ("Fixed pattern does not match! Read 0x%08x, expected 0x%08x\n", val, FIX_PATT_VAL));
LOG(logERROR, ("Fixed pattern does not match! Read 0x%08x, expected 0x%08x\n", val, FIX_PATT_VAL));
ret = FAIL;
}
return ret;
@ -190,17 +189,17 @@ int testBus() {
#ifdef VIRTUAL
return OK;
#endif
FILE_LOG(logINFO, ("Testing Bus:\n"));
LOG(logINFO, ("Testing Bus:\n"));
int ret = OK;
u_int32_t addr = DTA_OFFSET_REG;
int times = 1000 * 1000;
int i = 0;
u_int32_t times = 1000 * 1000;
u_int32_t i = 0;
for (i = 0; i < times; ++i) {
bus_w(addr, i * 100);
if (i * 100 != bus_r(addr)) {
FILE_LOG(logERROR, ("Mismatch! Wrote 0x%x, read 0x%x\n",
LOG(logERROR, ("Mismatch! Wrote 0x%x, read 0x%x\n",
i * 100, bus_r(addr)));
ret = FAIL;
}
@ -209,7 +208,7 @@ int testBus() {
bus_w(addr, 0);
if (ret == OK) {
FILE_LOG(logINFO, ("Successfully tested bus %d times\n", times));
LOG(logINFO, ("Successfully tested bus %d times\n", times));
}
return ret;
}
@ -295,7 +294,7 @@ u_int32_t getDetectorIP(){
}
strcpy(output,temp);
sscanf(output, "%x", &res);
//FILE_LOG(logINFO, ("ip:%x\n",res);
//LOG(logINFO, ("ip:%x\n",res);
return res;
}
@ -317,7 +316,7 @@ void initStopServer() {
usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) {
FILE_LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE);
}
}
@ -326,7 +325,7 @@ void initStopServer() {
/* set up detector */
void setupDetector() {
FILE_LOG(logINFO, ("This Server is for 1 Mythen3 module \n"));
LOG(logINFO, ("This Server is for 1 Mythen3 module \n"));
clkFrequency[READOUT_C0] = DEFAULT_READOUT_C0;
clkFrequency[READOUT_C1] = DEFAULT_READOUT_C1;
@ -381,7 +380,7 @@ void setupDetector() {
int setDefaultDacs() {
int ret = OK;
FILE_LOG(logINFOBLUE, ("Setting Default Dac values\n"));
LOG(logINFOBLUE, ("Setting Default Dac values\n"));
{
int i = 0;
const int defaultvals[NDAC] = DEFAULT_DAC_VALS;
@ -398,7 +397,7 @@ void cleanFifos() {
#ifdef VIRTUAL
return;
#endif
FILE_LOG(logINFO, ("Clearing Acquisition Fifos\n"));
LOG(logINFO, ("Clearing Acquisition Fifos\n"));
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_CLR_ACQSTN_FIFO_MSK);
}
@ -406,7 +405,7 @@ void resetCore() {
#ifdef VIRTUAL
return;
#endif
FILE_LOG(logINFO, ("Resetting Core\n"));
LOG(logINFO, ("Resetting Core\n"));
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_CRE_RST_MSK);
}
@ -414,7 +413,7 @@ void resetPeripheral() {
#ifdef VIRTUAL
return;
#endif
FILE_LOG(logINFO, ("Resetting Peripheral\n"));
LOG(logINFO, ("Resetting Peripheral\n"));
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_PRPHRL_RST_MSK);
}
@ -438,7 +437,7 @@ int setDynamicRange(int dr){
regval = CONFIG_DYNAMIC_RANGE_24_VAL;
break;
default:
FILE_LOG(logERROR, ("Invalid dynamic range %d\n", dr));
LOG(logERROR, ("Invalid dynamic range %d\n", dr));
return -1;
}
// set it
@ -457,7 +456,7 @@ int setDynamicRange(int dr){
case CONFIG_DYNAMIC_RANGE_24_VAL:
return 32;
default:
FILE_LOG(logERROR, ("Invalid dynamic range %d read back\n", regval >> CONFIG_DYNAMIC_RANGE_OFST));
LOG(logERROR, ("Invalid dynamic range %d read back\n", regval >> CONFIG_DYNAMIC_RANGE_OFST));
return -1;
}
}
@ -467,7 +466,7 @@ int setDynamicRange(int dr){
void setNumFrames(int64_t val) {
if (val > 0) {
FILE_LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
set64BitReg(val, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG);
}
}
@ -478,7 +477,7 @@ int64_t getNumFrames() {
void setNumTriggers(int64_t val) {
if (val > 0) {
FILE_LOG(logINFO, ("Setting number of triggers %lld\n", (long long int)val));
LOG(logINFO, ("Setting number of triggers %lld\n", (long long int)val));
set64BitReg(val, SET_CYCLES_LSB_REG, SET_CYCLES_MSB_REG);
}
}
@ -489,10 +488,10 @@ int64_t getNumTriggers() {
int setExpTime(int64_t val) {
if (val < 0) {
FILE_LOG(logERROR, ("Invalid exptime: %lld ns\n", (long long int)val));
LOG(logERROR, ("Invalid exptime: %lld ns\n", (long long int)val));
return FAIL;
}
FILE_LOG(logINFO, ("Setting exptime %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting exptime %lld ns\n", (long long int)val));
val *= (1E-9 * clkFrequency[SYSTEM_C0]);
setPatternWaitTime(0, val);
@ -511,10 +510,10 @@ int64_t getExpTime() {
int setPeriod(int64_t val) {
if (val < 0) {
FILE_LOG(logERROR, ("Invalid period: %lld ns\n", (long long int)val));
LOG(logERROR, ("Invalid period: %lld ns\n", (long long int)val));
return FAIL;
}
FILE_LOG(logINFO, ("Setting period %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting period %lld ns\n", (long long int)val));
val *= (1E-9 * FIXED_PLL_FREQUENCY);
set64BitReg(val, SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG);
@ -538,7 +537,7 @@ void setCounterMask(uint32_t arg) {
countermask = arg;
// convert mask into number of counters (until firmware converts to mask)
int ncounters = __builtin_popcount(countermask);
FILE_LOG(logINFO, ("Setting number of counters to %d\n", ncounters));
LOG(logINFO, ("Setting number of counters to %d\n", ncounters));
uint32_t val = 0;
switch (ncounters) {
case 1:
@ -554,7 +553,7 @@ void setCounterMask(uint32_t arg) {
uint32_t addr = CONFIG_REG;
bus_w(addr, bus_r(addr) &~ CONFIG_COUNTER_ENA_MSK);
bus_w(addr, bus_r(addr) | val);
FILE_LOG(logDEBUG, ("Config Reg: 0x%x\n", bus_r(addr)));
LOG(logDEBUG, ("Config Reg: 0x%x\n", bus_r(addr)));
}
uint32_t getCounterMask() {
@ -593,10 +592,10 @@ uint32_t getCounterMask() {
int setDelayAfterTrigger(int64_t val) {
if (val < 0) {
FILE_LOG(logERROR, ("Invalid delay after trigger: %lld ns\n", (long long int)val));
LOG(logERROR, ("Invalid delay after trigger: %lld ns\n", (long long int)val));
return FAIL;
}
FILE_LOG(logINFO, ("Setting delay after trigger %lld ns\n", (long long int)val));
LOG(logINFO, ("Setting delay after trigger %lld ns\n", (long long int)val));
val *= (1E-9 * FIXED_PLL_FREQUENCY);
set64BitReg(val, SET_TRIGGER_DELAY_LSB_REG, SET_TRIGGER_DELAY_MSB_REG);
@ -650,11 +649,11 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
}
char* dac_names[] = {DAC_NAMES};
FILE_LOG(logDEBUG1, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], val, (mV ? "mV" : "dac units")));
LOG(logDEBUG1, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], val, (mV ? "mV" : "dac units")));
int dacval = val;
#ifdef VIRTUAL
FILE_LOG(logINFO, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], val, (mV ? "mV" : "dac units")));
LOG(logINFO, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], val, (mV ? "mV" : "dac units")));
if (!mV) {
dacValues[ind] = val;
}
@ -671,12 +670,12 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
int getDAC(enum DACINDEX ind, int mV) {
if (!mV) {
FILE_LOG(logDEBUG1, ("Getting DAC %d : %d dac\n",ind, dacValues[ind]));
LOG(logDEBUG1, ("Getting DAC %d : %d dac\n",ind, dacValues[ind]));
return dacValues[ind];
}
int voltage = -1;
LTC2620_D_DacToVoltage(dacValues[ind], &voltage);
FILE_LOG(logDEBUG1, ("Getting DAC %d : %d dac (%d mV)\n",ind, dacValues[ind], voltage));
LOG(logDEBUG1, ("Getting DAC %d : %d dac (%d mV)\n",ind, dacValues[ind], voltage));
return voltage;
}
@ -697,7 +696,7 @@ int setHighVoltage(int val){
// setting hv
if (val >= 0) {
FILE_LOG(logINFO, ("Setting High voltage: %d V\n", val));
LOG(logINFO, ("Setting High voltage: %d V\n", val));
DAC6571_Set(val);
highvoltage = val;
}
@ -710,15 +709,15 @@ void setTiming( enum timingMode arg){
if(arg != GET_TIMING_MODE){
switch (arg) {
case AUTO_TIMING:
FILE_LOG(logINFO, ("Set Timing: Auto\n"));
LOG(logINFO, ("Set Timing: Auto\n"));
bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) & ~EXT_SIGNAL_MSK);
break;
case TRIGGER_EXPOSURE:
FILE_LOG(logINFO, ("Set Timing: Trigger\n"));
LOG(logINFO, ("Set Timing: Trigger\n"));
bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) | EXT_SIGNAL_MSK);
break;
default:
FILE_LOG(logERROR, ("Unknown timing mode %d\n", arg));
LOG(logERROR, ("Unknown timing mode %d\n", arg));
}
}
}
@ -743,17 +742,17 @@ int configureMAC() {
char cDestIp[MAX_STR_LENGTH];
memset(cDestIp, 0, MAX_STR_LENGTH);
sprintf(cDestIp, "%d.%d.%d.%d", (dstip>>24)&0xff,(dstip>>16)&0xff,(dstip>>8)&0xff,(dstip)&0xff);
FILE_LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d)\n", cDestIp, dstport));
LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d)\n", cDestIp, dstport));
if (setUDPDestinationDetails(0, cDestIp, dstport) == FAIL) {
FILE_LOG(logERROR, ("could not set udp destination IP and port\n"));
LOG(logERROR, ("could not set udp destination IP and port\n"));
return FAIL;
}
#endif
FILE_LOG(logINFOBLUE, ("Configuring MAC\n"));
LOG(logINFOBLUE, ("Configuring MAC\n"));
FILE_LOG(logINFO, ("\tSource IP : %d.%d.%d.%d \t\t(0x%08x)\n",
LOG(logINFO, ("\tSource IP : %d.%d.%d.%d \t\t(0x%08x)\n",
(srcip>>24)&0xff,(srcip>>16)&0xff,(srcip>>8)&0xff,(srcip)&0xff, srcip));
FILE_LOG(logINFO, ("\tSource MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n",
LOG(logINFO, ("\tSource MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n",
(unsigned int)((srcmac>>40)&0xFF),
(unsigned int)((srcmac>>32)&0xFF),
(unsigned int)((srcmac>>24)&0xFF),
@ -761,11 +760,11 @@ int configureMAC() {
(unsigned int)((srcmac>>8)&0xFF),
(unsigned int)((srcmac>>0)&0xFF),
(long long unsigned int)srcmac));
FILE_LOG(logINFO, ("\tSource Port : %d \t\t\t(0x%08x)\n", srcport, srcport));
LOG(logINFO, ("\tSource Port : %d \t\t\t(0x%08x)\n", srcport, srcport));
FILE_LOG(logINFO, ("\tDest. IP : %d.%d.%d.%d \t\t(0x%08x)\n",
LOG(logINFO, ("\tDest. IP : %d.%d.%d.%d \t\t(0x%08x)\n",
(dstip>>24)&0xff,(dstip>>16)&0xff,(dstip>>8)&0xff,(dstip)&0xff, dstip));
FILE_LOG(logINFO, ("\tDest. MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n",
LOG(logINFO, ("\tDest. MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n",
(unsigned int)((dstmac>>40)&0xFF),
(unsigned int)((dstmac>>32)&0xFF),
(unsigned int)((dstmac>>24)&0xFF),
@ -773,7 +772,7 @@ int configureMAC() {
(unsigned int)((dstmac>>8)&0xFF),
(unsigned int)((dstmac>>0)&0xFF),
(long long unsigned int)dstmac));
FILE_LOG(logINFO, ("\tDest. Port : %d \t\t\t(0x%08x)\n\n",dstport, dstport));
LOG(logINFO, ("\tDest. Port : %d \t\t\t(0x%08x)\n\n",dstport, dstport));
// start addr
uint32_t addr = BASE_UDP_RAM;
@ -847,7 +846,7 @@ void calcChecksum(udp_header* udp) {
sum = (sum & 0xffff) + (sum >> 16);// Fold 32-bit sum to 16 bits
long int checksum = sum & 0xffff;
checksum += UDP_IP_HEADER_LENGTH_BYTES;
FILE_LOG(logINFO, ("\tIP checksum is 0x%lx\n",checksum));
LOG(logINFO, ("\tIP checksum is 0x%lx\n",checksum));
udp->ip_checksum = checksum;
}
@ -864,7 +863,7 @@ int setDetectorPosition(int pos[]) {
bus_w(addr, (bus_r(addr) &~COORD_ROW_MSK) | ((value << COORD_ROW_OFST) & COORD_ROW_MSK));
valueRead = ((bus_r(addr) & COORD_ROW_MSK) >> COORD_ROW_OFST);
if (valueRead != value) {
FILE_LOG(logERROR, ("Could not set row. Set %d, read %d\n", value, valueRead));
LOG(logERROR, ("Could not set row. Set %d, read %d\n", value, valueRead));
ret = FAIL;
}
@ -873,12 +872,12 @@ int setDetectorPosition(int pos[]) {
bus_w(addr, (bus_r(addr) &~COORD_COL_MSK) | ((value << COORD_COL_OFST) & COORD_COL_MSK));
valueRead = ((bus_r(addr) & COORD_COL_MSK) >> COORD_COL_OFST);
if (valueRead != value) {
FILE_LOG(logERROR, ("Could not set column. Set %d, read %d\n", value, valueRead));
LOG(logERROR, ("Could not set column. Set %d, read %d\n", value, valueRead));
ret = FAIL;
}
if (ret == OK) {
FILE_LOG(logINFO, ("\tPosition set to [%d, %d]\n", detPos[X], detPos[Y]));
LOG(logINFO, ("\tPosition set to [%d, %d]\n", detPos[X], detPos[Y]));
}
return ret;
@ -893,41 +892,41 @@ int* getDetectorPosition() {
uint64_t readPatternWord(int addr) {
// error (handled in tcp)
if (addr < 0 || addr >= MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot get Pattern - Word. Invalid addr 0x%x. "
LOG(logERROR, ("Cannot get Pattern - Word. Invalid addr 0x%x. "
"Should be between 0 and 0x%x\n", addr, MAX_PATTERN_LENGTH));
return -1;
}
FILE_LOG(logINFO, (" Reading Pattern Word (addr:0x%x)\n", addr));
LOG(logINFO, (" Reading Pattern Word (addr:0x%x)\n", addr));
uint32_t reg_lsb = PATTERN_STEP0_LSB_REG + addr * REG_OFFSET * 2; // the first word in RAM as base plus the offset of the word to write (addr)
uint32_t reg_msb = PATTERN_STEP0_MSB_REG + addr * REG_OFFSET * 2;
// read value
uint64_t retval = get64BitReg(reg_lsb, reg_msb);
FILE_LOG(logDEBUG1, (" Word(addr:0x%x) retval: 0x%llx\n", addr, (long long int) retval));
LOG(logDEBUG1, (" Word(addr:0x%x) retval: 0x%llx\n", addr, (long long int) retval));
return retval;
}
uint64_t writePatternWord(int addr, uint64_t word) {
// get
if (word == -1)
if ((int64_t)word == -1)
return readPatternWord(addr);
// error (handled in tcp)
if (addr < 0 || addr >= MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot set Pattern - Word. Invalid addr 0x%x. "
LOG(logERROR, ("Cannot set Pattern - Word. Invalid addr 0x%x. "
"Should be between 0 and 0x%x\n", addr, MAX_PATTERN_LENGTH));
return -1;
}
FILE_LOG(logINFO, ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", addr, (long long int) word));
LOG(logINFO, ("Setting Pattern Word (addr:0x%x, word:0x%llx)\n", addr, (long long int) word));
uint32_t reg_lsb = PATTERN_STEP0_LSB_REG + addr * REG_OFFSET * 2; // the first word in RAM as base plus the offset of the word to write (addr)
uint32_t reg_msb = PATTERN_STEP0_MSB_REG + addr * REG_OFFSET * 2;
// write word
set64BitReg(word, reg_lsb, reg_msb);
FILE_LOG(logDEBUG1, (" Wrote word. PatternIn Reg: 0x%llx\n", get64BitReg(reg_lsb, reg_msb)));
LOG(logDEBUG1, (" Wrote word. PatternIn Reg: 0x%llx\n", get64BitReg(reg_lsb, reg_msb)));
return readPatternWord(addr);
}
@ -936,7 +935,7 @@ int setPatternWaitAddress(int level, int addr) {
// error (handled in tcp)
if (addr >= MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot set Pattern Wait Address. Invalid addr 0x%x. "
LOG(logERROR, ("Cannot set Pattern Wait Address. Invalid addr 0x%x. "
"Should be between 0 and 0x%x\n", addr, MAX_PATTERN_LENGTH));
return -1;
}
@ -962,20 +961,20 @@ int setPatternWaitAddress(int level, int addr) {
mask = PATTERN_WAIT_2_ADDR_MSK;
break;
default:
FILE_LOG(logERROR, ("Cannot set Pattern Wait Address. Invalid level 0x%x. "
LOG(logERROR, ("Cannot set Pattern Wait Address. Invalid level 0x%x. "
"Should be between 0 and 2.\n", level));
return -1;
}
// set
if (addr >= 0) {
FILE_LOG(logINFO, ("Setting Pattern Wait Address (level:%d, addr:0x%x)\n", level, addr));
LOG(logINFO, ("Setting Pattern Wait Address (level:%d, addr:0x%x)\n", level, addr));
bus_w(reg, ((addr << offset) & mask));
}
// get
uint32_t regval = ((bus_r(reg) & mask) >> offset);
FILE_LOG(logDEBUG1, (" Wait Address retval (level:%d, addr:0x%x)\n", level, regval));
LOG(logDEBUG1, (" Wait Address retval (level:%d, addr:0x%x)\n", level, regval));
return regval;
}
@ -997,20 +996,20 @@ uint64_t setPatternWaitTime(int level, uint64_t t) {
regm = PATTERN_WAIT_TIMER_2_MSB_REG;
break;
default:
FILE_LOG(logERROR, ("Cannot set Pattern Wait Time. Invalid level %d. "
LOG(logERROR, ("Cannot set Pattern Wait Time. Invalid level %d. "
"Should be between 0 and 2.\n", level));
return -1;
}
// set
if (t >= 0) {
FILE_LOG(logINFO, ("Setting Pattern Wait Time (level:%d, t:%lld)\n", level, (long long int)t));
if ((int64_t)t >= 0) {
LOG(logINFO, ("Setting Pattern Wait Time (level:%d, t:%lld)\n", level, (long long int)t));
set64BitReg(t, regl, regm);
}
// get
uint64_t regval = get64BitReg(regl, regm);
FILE_LOG(logDEBUG1, (" Wait Time retval (level:%d, t:%lld)\n", level, (long long int)regval));
LOG(logDEBUG1, (" Wait Time retval (level:%d, t:%lld)\n", level, (long long int)regval));
return regval;
}
@ -1018,7 +1017,7 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
// (checked at tcp)
if (*startAddr >= MAX_PATTERN_LENGTH || *stopAddr >= MAX_PATTERN_LENGTH) {
FILE_LOG(logERROR, ("Cannot set Pattern Loop, Address (startaddr:0x%x, stopaddr:0x%x) must be "
LOG(logERROR, ("Cannot set Pattern Loop, Address (startaddr:0x%x, stopaddr:0x%x) must be "
"less than 0x%x\n",
*startAddr, *stopAddr, MAX_PATTERN_LENGTH));
}
@ -1066,7 +1065,7 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
break;
default:
// already checked at tcp interface
FILE_LOG(logERROR, ("Cannot set Pattern loop. Invalid level %d. "
LOG(logERROR, ("Cannot set Pattern loop. Invalid level %d. "
"Should be between -1 and 2.\n", level));
*startAddr = 0;
*stopAddr = 0;
@ -1077,7 +1076,7 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
if (level >= 0) {
// set iteration
if (*nLoop >= 0) {
FILE_LOG(logINFO, ("Setting Pattern Loop (level:%d, nLoop:%d)\n",
LOG(logINFO, ("Setting Pattern Loop (level:%d, nLoop:%d)\n",
level, *nLoop));
bus_w(nLoopReg, *nLoop);
}
@ -1087,20 +1086,20 @@ void setPatternLoop(int level, int *startAddr, int *stopAddr, int *nLoop) {
// set
if (*startAddr >= 0 && *stopAddr >= 0) {
// writing start and stop addr
FILE_LOG(logINFO, ("Setting Pattern Loop (level:%d, startaddr:0x%x, stopaddr:0x%x)\n",
LOG(logINFO, ("Setting Pattern Loop (level:%d, startaddr:0x%x, stopaddr:0x%x)\n",
level, *startAddr, *stopAddr));
bus_w(addr, ((*startAddr << startOffset) & startMask) | ((*stopAddr << stopOffset) & stopMask));
FILE_LOG(logDEBUG1, ("Addr:0x%x, val:0x%x\n", addr, bus_r(addr)));
LOG(logDEBUG1, ("Addr:0x%x, val:0x%x\n", addr, bus_r(addr)));
}
// get
else {
*startAddr = ((bus_r(addr) & startMask) >> startOffset);
FILE_LOG(logDEBUG1, ("Getting Pattern Loop Start Address (level:%d, Read startAddr:0x%x)\n",
LOG(logDEBUG1, ("Getting Pattern Loop Start Address (level:%d, Read startAddr:0x%x)\n",
level, *startAddr));
*stopAddr = ((bus_r(addr) & stopMask) >> stopOffset);
FILE_LOG(logDEBUG1, ("Getting Pattern Loop Stop Address (level:%d, Read stopAddr:0x%x)\n",
LOG(logDEBUG1, ("Getting Pattern Loop Stop Address (level:%d, Read stopAddr:0x%x)\n",
level, *stopAddr));
}
}
@ -1122,27 +1121,27 @@ uint64_t getPatternBitMask() {
}
int checkDetectorType() {
FILE_LOG(logINFO, ("Checking type of module\n"));
LOG(logINFO, ("Checking type of module\n"));
FILE* fd = fopen(TYPE_FILE_NAME, "r");
if (fd == NULL) {
FILE_LOG(logERROR, ("Could not open file %s to get type of the module attached\n", TYPE_FILE_NAME));
LOG(logERROR, ("Could not open file %s to get type of the module attached\n", TYPE_FILE_NAME));
return -1;
}
char buffer[MAX_STR_LENGTH];
memset(buffer, 0, sizeof(buffer));
fread (buffer, MAX_STR_LENGTH, sizeof(char), fd);
if (strlen(buffer) == 0) {
FILE_LOG(logERROR, ("Could not read file %s to get type of the module attached\n", TYPE_FILE_NAME));
LOG(logERROR, ("Could not read file %s to get type of the module attached\n", TYPE_FILE_NAME));
return -1;
}
int type = atoi(buffer);
if (type > TYPE_NO_MODULE_STARTING_VAL) {
FILE_LOG(logERROR, ("No Module attached! Expected %d for Mythen, got %d\n", TYPE_MYTHEN3_MODULE_VAL, type));
LOG(logERROR, ("No Module attached! Expected %d for Mythen, got %d\n", TYPE_MYTHEN3_MODULE_VAL, type));
return -2;
}
if (abs(type - TYPE_MYTHEN3_MODULE_VAL) > TYPE_TOLERANCE) {
FILE_LOG(logERROR, ("Wrong Module attached! Expected %d for Mythen3, got %d\n", TYPE_MYTHEN3_MODULE_VAL, type));
LOG(logERROR, ("Wrong Module attached! Expected %d for Mythen3, got %d\n", TYPE_MYTHEN3_MODULE_VAL, type));
return FAIL;
}
return OK;
@ -1151,11 +1150,11 @@ int checkDetectorType() {
int powerChip (int on){
if(on != -1){
if(on){
FILE_LOG(logINFO, ("Powering chip: on\n"));
LOG(logINFO, ("Powering chip: on\n"));
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_PWR_CHIP_MSK);
}
else{
FILE_LOG(logINFO, ("Powering chip: off\n"));
LOG(logINFO, ("Powering chip: off\n"));
bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_PWR_CHIP_MSK);
}
}
@ -1166,19 +1165,19 @@ int powerChip (int on){
int setPhase(enum CLKINDEX ind, int val, int degrees) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to set phase\n", ind));
LOG(logERROR, ("Unknown clock index %d to set phase\n", ind));
return FAIL;
}
char* clock_names[] = {CLK_NAMES};
FILE_LOG(logINFOBLUE, ("Setting %s clock (%d) phase to %d %s\n", clock_names[ind], ind, val, degrees == 0 ? "" : "degrees"));
LOG(logINFOBLUE, ("Setting %s clock (%d) phase to %d %s\n", clock_names[ind], ind, val, degrees == 0 ? "" : "degrees"));
int maxShift = getMaxPhase(ind);
// validation
if (degrees && (val < 0 || val > 359)) {
FILE_LOG(logERROR, ("\tPhase outside limits (0 - 359°C)\n"));
LOG(logERROR, ("\tPhase outside limits (0 - 359°C)\n"));
return FAIL;
}
if (!degrees && (val < 0 || val > maxShift - 1)) {
FILE_LOG(logERROR, ("\tPhase outside limits (0 - %d phase shifts)\n", maxShift - 1));
LOG(logERROR, ("\tPhase outside limits (0 - %d phase shifts)\n", maxShift - 1));
return FAIL;
}
@ -1187,14 +1186,14 @@ int setPhase(enum CLKINDEX ind, int val, int degrees) {
if (degrees) {
ConvertToDifferentRange(0, 359, 0, maxShift - 1, val, &valShift);
}
FILE_LOG(logDEBUG1, ("\tphase shift: %d (degrees/shift: %d)\n", valShift, val));
LOG(logDEBUG1, ("\tphase shift: %d (degrees/shift: %d)\n", valShift, val));
int relativePhase = valShift - clkPhase[ind];
FILE_LOG(logDEBUG1, ("\trelative phase shift: %d (Current phase: %d)\n", relativePhase, clkPhase[ind]));
LOG(logDEBUG1, ("\trelative phase shift: %d (Current phase: %d)\n", relativePhase, clkPhase[ind]));
// same phase
if (!relativePhase) {
FILE_LOG(logINFO, ("\tNothing to do in Phase Shift\n"));
LOG(logINFO, ("\tNothing to do in Phase Shift\n"));
return OK;
}
@ -1213,7 +1212,7 @@ int setPhase(enum CLKINDEX ind, int val, int degrees) {
int getPhase(enum CLKINDEX ind, int degrees) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to get phase\n", ind));
LOG(logERROR, ("Unknown clock index %d to get phase\n", ind));
return -1;
}
if (!degrees)
@ -1226,7 +1225,7 @@ int getPhase(enum CLKINDEX ind, int degrees) {
int getMaxPhase(enum CLKINDEX ind) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to get max phase\n", ind));
LOG(logERROR, ("Unknown clock index %d to get max phase\n", ind));
return -1;
}
int vcofreq = getVCOFrequency(ind);
@ -1234,7 +1233,7 @@ int getMaxPhase(enum CLKINDEX ind) {
int ret = ((double)vcofreq / (double)clkFrequency[ind]) * maxshiftstep;
char* clock_names[] = {CLK_NAMES};
FILE_LOG(logDEBUG1, ("\tMax Phase Shift (%s): %d (Clock: %d Hz, VCO:%d Hz)\n",
LOG(logDEBUG1, ("\tMax Phase Shift (%s): %d (Clock: %d Hz, VCO:%d Hz)\n",
clock_names[ind], ret, clkFrequency[ind], vcofreq));
return ret;
@ -1242,13 +1241,13 @@ int getMaxPhase(enum CLKINDEX ind) {
int validatePhaseinDegrees(enum CLKINDEX ind, int val, int retval) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to validate phase in degrees\n", ind));
LOG(logERROR, ("Unknown clock index %d to validate phase in degrees\n", ind));
return FAIL;
}
if (val == -1) {
return OK;
}
FILE_LOG(logDEBUG1, ("validating phase in degrees for clk %d\n", (int)ind));
LOG(logDEBUG1, ("validating phase in degrees for clk %d\n", (int)ind));
int maxShift = getMaxPhase(ind);
// convert degrees to shift
int valShift = 0;
@ -1265,7 +1264,7 @@ int validatePhaseinDegrees(enum CLKINDEX ind, int val, int retval) {
int getFrequency(enum CLKINDEX ind) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to get frequency\n", ind));
LOG(logERROR, ("Unknown clock index %d to get frequency\n", ind));
return -1;
}
return clkFrequency[ind];
@ -1273,7 +1272,7 @@ int getFrequency(enum CLKINDEX ind) {
int getVCOFrequency(enum CLKINDEX ind) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to get vco frequency\n", ind));
LOG(logERROR, ("Unknown clock index %d to get vco frequency\n", ind));
return -1;
}
int pllIndex = (int)(ind >= SYSTEM_C0 ? SYSTEM_PLL : READOUT_PLL);
@ -1286,7 +1285,7 @@ int getMaxClockDivider() {
int setClockDivider(enum CLKINDEX ind, int val) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to set clock divider\n", ind));
LOG(logERROR, ("Unknown clock index %d to set clock divider\n", ind));
return FAIL;
}
if (val < 2 || val > getMaxClockDivider()) {
@ -1297,7 +1296,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
int currentdiv = vcofreq / (int)clkFrequency[ind];
int newfreq = vcofreq / val;
FILE_LOG(logINFO, ("\tSetting %s clock (%d) divider from %d (%d Hz) to %d (%d Hz). \n\t(Vcofreq: %d Hz)\n", clock_names[ind], ind, currentdiv, clkFrequency[ind], val, newfreq, vcofreq));
LOG(logINFO, ("\tSetting %s clock (%d) divider from %d (%d Hz) to %d (%d Hz). \n\t(Vcofreq: %d Hz)\n", clock_names[ind], ind, currentdiv, clkFrequency[ind], val, newfreq, vcofreq));
// Remembering old phases in degrees
int oldPhases[NUM_CLOCKS];
@ -1313,7 +1312,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
int clkIndex = (int)(ind >= SYSTEM_C0 ? ind - SYSTEM_C0 : ind);
ALTERA_PLL_C10_SetOuputFrequency (pllIndex, clkIndex, newfreq);
clkFrequency[ind] = newfreq;
FILE_LOG(logINFO, ("\t%s clock (%d) divider set to %d (%d Hz)\n", clock_names[ind], ind, val, clkFrequency[ind]));
LOG(logINFO, ("\t%s clock (%d) divider set to %d (%d Hz)\n", clock_names[ind], ind, val, clkFrequency[ind]));
// phase is reset by pll (when setting output frequency)
if (ind >= READOUT_C0) {
@ -1331,7 +1330,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
for (i = 0; i < NUM_CLOCKS; ++i) {
int currPhaseDeg = getPhase(i, 1);
if (oldPhases[i] != currPhaseDeg) {
FILE_LOG(logINFO, ("\tCorrecting %s clock (%d) phase from %d to %d degrees\n", clock_names[i], i, currPhaseDeg, oldPhases[i]));
LOG(logINFO, ("\tCorrecting %s clock (%d) phase from %d to %d degrees\n", clock_names[i], i, currPhaseDeg, oldPhases[i]));
setPhase(i, oldPhases[i], 1);
}
}
@ -1341,7 +1340,7 @@ int setClockDivider(enum CLKINDEX ind, int val) {
int getClockDivider(enum CLKINDEX ind) {
if (ind < 0 || ind >= NUM_CLOCKS) {
FILE_LOG(logERROR, ("Unknown clock index %d to get clock divider\n", ind));
LOG(logERROR, ("Unknown clock index %d to get clock divider\n", ind));
return -1;
}
return (getVCOFrequency(ind) / (int)clkFrequency[ind]);
@ -1355,25 +1354,25 @@ int startStateMachine(){
if(createUDPSocket(0) != OK) {
return FAIL;
}
FILE_LOG(logINFOBLUE, ("starting state machine\n"));
LOG(logINFOBLUE, ("starting state machine\n"));
// set status to running
virtual_status = 1;
virtual_stop = 0;
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
FILE_LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0;
return FAIL;
}
FILE_LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
return OK;
#endif
FILE_LOG(logINFOBLUE, ("Starting State Machine\n"));
LOG(logINFOBLUE, ("Starting State Machine\n"));
cleanFifos();
//start state machine
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STRT_ACQSTN_MSK);
FILE_LOG(logINFO, ("Status Register: %08x\n",bus_r(STATUS_REG)));
LOG(logINFO, ("Status Register: %08x\n",bus_r(STATUS_REG)));
return OK;
}
@ -1441,7 +1440,7 @@ void* start_timer(void* arg) {
sendUDPPacket(0, packetData, packetsize);
}
}
FILE_LOG(logINFO, ("Sent frame: %d\n", frameNr));
LOG(logINFO, ("Sent frame: %d\n", frameNr));
// calculate time left in period
clock_gettime(CLOCK_REALTIME, &end);
@ -1461,52 +1460,52 @@ void* start_timer(void* arg) {
closeUDPSocket(0);
// set status to idle
virtual_status = 0;
FILE_LOG(logINFOBLUE, ("Finished Acquiring\n"));
LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL;
}
#endif
int stopStateMachine(){
FILE_LOG(logINFORED, ("Stopping State Machine\n"));
LOG(logINFORED, ("Stopping State Machine\n"));
#ifdef VIRTUAL
virtual_stop = 0;
return OK;
#endif
//stop state machine
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STP_ACQSTN_MSK);
FILE_LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
return OK;
}
enum runStatus getRunStatus(){
#ifdef VIRTUAL
if(virtual_status == 0){
FILE_LOG(logINFOBLUE, ("Status: IDLE\n"));
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
}else{
FILE_LOG(logINFOBLUE, ("Status: RUNNING\n"));
LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING;
}
#endif
FILE_LOG(logDEBUG1, ("Getting status\n"));
LOG(logDEBUG1, ("Getting status\n"));
uint32_t retval = bus_r(PAT_STATUS_REG);
FILE_LOG(logINFO, ("Status Register: %08x\n",retval));
LOG(logINFO, ("Status Register: %08x\n",retval));
enum runStatus s;
//running
if (retval & PAT_STATUS_RUN_BUSY_MSK) {
if (retval & PAT_STATUS_WAIT_FOR_TRGGR_MSK) {
FILE_LOG(logINFOBLUE, ("Status: WAITING\n"));
LOG(logINFOBLUE, ("Status: WAITING\n"));
s = WAITING;
} else {
if (retval & PAT_STATUS_DLY_BFRE_TRGGR_MSK) {
FILE_LOG(logINFO, ("Status: Delay before Trigger\n"));
LOG(logINFO, ("Status: Delay before Trigger\n"));
} else if (retval & PAT_STATUS_DLY_AFTR_TRGGR_MSK) {
FILE_LOG(logINFO, ("Status: Delay after Trigger\n"));
LOG(logINFO, ("Status: Delay after Trigger\n"));
}
FILE_LOG(logINFOBLUE, ("Status: RUNNING\n"));
LOG(logINFOBLUE, ("Status: RUNNING\n"));
s = RUNNING;
}
}
@ -1515,16 +1514,16 @@ enum runStatus getRunStatus(){
else {
// stopped or error
if (retval & PAT_STATUS_FIFO_FULL_MSK) {
FILE_LOG(logINFOBLUE, ("Status: STOPPED\n")); //FIFO FULL??
LOG(logINFOBLUE, ("Status: STOPPED\n")); //FIFO FULL??
s = STOPPED;
} else if (retval & PAT_STATUS_CSM_BUSY_MSK) {
FILE_LOG(logINFOBLUE, ("Status: READ MACHINE BUSY\n"));
LOG(logINFOBLUE, ("Status: READ MACHINE BUSY\n"));
s = TRANSMITTING;
} else if (!retval) {
FILE_LOG(logINFOBLUE, ("Status: IDLE\n"));
LOG(logINFOBLUE, ("Status: IDLE\n"));
s = IDLE;
} else {
FILE_LOG(logERROR, ("Status: Unknown status %08x\n", retval));
LOG(logERROR, ("Status: Unknown status %08x\n", retval));
s = ERROR;
}
}
@ -1539,7 +1538,7 @@ void readFrame(int *ret, char *mess) {
}
#ifdef VIRTUAL
FILE_LOG(logINFOGREEN, ("acquisition successfully finished\n"));
LOG(logINFOGREEN, ("acquisition successfully finished\n"));
return;
#endif
@ -1548,9 +1547,9 @@ void readFrame(int *ret, char *mess) {
int64_t retval = getNumFramesLeft() + 1;
if ( retval > 0) {
FILE_LOG(logERROR, ("No data and run stopped: %lld frames left\n",(long long int)retval));
LOG(logERROR, ("No data and run stopped: %lld frames left\n",(long long int)retval));
} else {
FILE_LOG(logINFOGREEN, ("Acquisition successfully finished\n"));
LOG(logINFOGREEN, ("Acquisition successfully finished\n"));
}
}
@ -1559,7 +1558,7 @@ u_int32_t runBusy() {
return virtual_status;
#endif
u_int32_t s = (bus_r(PAT_STATUS_REG) & PAT_STATUS_RUN_BUSY_MSK);
//FILE_LOG(logDEBUG1, ("Status Register: %08x\n", s));
//LOG(logDEBUG1, ("Status Register: %08x\n", s));
return s;
}

View File

@ -28,7 +28,7 @@ logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5
#define ERROR_MSG_LENGTH 1000
#define FILE_LOG(lvl, fmt, ...) \
#define LOG(lvl, fmt, ...) \
if (lvl > FILELOG_MAX_LEVEL); \
else {char* temp = FILELOG_BuildLog fmt; FILELOG_PrintLog(lvl, temp);free(temp);}

View File

@ -2,15 +2,28 @@
#include "slsDetectorServer_defs.h" // DAC_INDEX, ADC_INDEX, also include RegisterDefs.h
#ifdef GOTTHARDD
#include "clogger.h" // runState(enum TLogLevel)
#include "AD9252.h" // old board compatibility
#endif
#ifndef VIRTUAL
#if defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD)
#include "AD9257.h" // commonServerFunctions.h, blackfin.h, ansi.h
#endif
#ifdef MOENCHD
#include "readDefaultPattern.h"
#endif
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
#include "programFpgaNios.h"
#elif defined(CHIPTESTBOARDD) || defined(JUNGFRAUD) || defined(MOENCHD)
#include "programFpgaBlackfin.h"
#endif
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
#include "nios.h"
#elif defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD)
#include "blackfin.h"
#endif
#include <stdlib.h>
#include <stdio.h> // FILE
#include <sys/types.h>
@ -107,9 +120,6 @@ int readRegister(uint32_t offset, uint32_t* retval);
#elif GOTTHARDD
uint32_t writeRegister16And32(uint32_t offset, uint32_t data); //FIXME its not there in ctb or moench?
uint32_t readRegister16And32(uint32_t offset);
#else
extern u_int32_t writeRegister(u_int32_t offset, u_int32_t data); // blackfin.h or nios.h
extern u_int32_t readRegister(u_int32_t offset); // blackfin.h or nios.h
#endif
@ -192,19 +202,6 @@ void setNumBursts(int64_t val);
int64_t getNumBursts();
int setBurstPeriod(int64_t val);
int64_t getBurstPeriod();
void setNumFramesBurst(int64_t val);
int64_t getNumFramesBurst();
void setNumFramesCont(int64_t val);
int64_t getNumFramesCont();
int setExptimeBurst(int64_t val);
int setExptimeCont(int64_t val);
int setExptimeBoth(int64_t val);
int64_t getExptimeBoth();
int setPeriodBurst(int64_t val);
int64_t getPeriodBurst();
int setPeriodCont(int64_t val);
int64_t getPeriodCont();
#endif
#ifdef EIGERD
int setSubExpTime(int64_t val);
@ -271,16 +268,6 @@ int setThresholdEnergy(int ev);
#endif
// parameters - dac, adc, hv
#ifdef GOTTHARDD
extern void AD9252_Set(int addr, int val); // AD9252.h (old board)
#endif
#if defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD)
extern void AD9257_Set(int addr, int val); // AD9257.h
#endif
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
extern int AD9257_GetVrefVoltage(int mV); // AD9257.h
extern int AD9257_SetVrefVoltage(int val, int mV); // AD9257.h
#endif
#ifdef GOTTHARD2D
int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val);
@ -382,10 +369,6 @@ int getFrequency(enum CLKINDEX ind);
void configureSyncFrequency(enum CLKINDEX ind);
void setPipeline(enum CLKINDEX ind, int val);
int getPipeline(enum CLKINDEX ind);
extern void eraseFlash(); // programFpgaBlackfin.h
extern int startWritingFPGAprogram(FILE** filefp); // programFpgaBlackfin.h
extern void stopWritingFPGAprogram(FILE* filefp); // programFpgaBlackfin.h
extern int writeFPGAProgram(char* fpgasrc, uint64_t fsize, FILE* filefp); // programFpgaBlackfin.h
// patterns
uint64_t writePatternIOControl(uint64_t word);
uint64_t writePatternClkControl(uint64_t word);
@ -403,9 +386,6 @@ uint64_t getPatternMask();
void setPatternBitMask(uint64_t mask);
uint64_t getPatternBitMask();
#endif
#ifdef MOENCHD
extern int loadDefaultPattern(char* fname); // readDefaultPattern.h
#endif
// jungfrau specific - powerchip, autocompdisable, clockdiv, asictimer, clock, pll, flashing firmware
#ifdef JUNGFRAUD
@ -422,10 +402,6 @@ int validatePhaseinDegrees(enum CLKINDEX ind, int val, int retval);
int setThresholdTemperature(int val);
int setTemperatureControl(int val);
int setTemperatureEvent(int val);
extern void eraseFlash(); // programFpgaBlackfin.h
extern int startWritingFPGAprogram(FILE** filefp); // programFpgaBlackfin.h
extern void stopWritingFPGAprogram(FILE* filefp); // programFpgaBlackfin.h
extern int writeFPGAProgram(char* fpgasrc, uint64_t fsize, FILE* filefp); // programFpgaBlackfin.h
void alignDeserializer();
// eiger specific - iodelay, pulse, rate, temp, activate, delay nw parameter
@ -504,18 +480,6 @@ void setTimingSource(enum timingSourceType value);
enum timingSourceType getTimingSource();
#endif
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
extern void NotifyServerStartSuccess();
extern void CreateNotificationForCriticalTasks();
extern void rebootControllerAndFPGA(); // programFpgaNios.h
extern int findFlash(char* mess); // programFpgaNios.h
extern void eraseFlash(); // programFpgaNios.h
extern int eraseAndWriteToFlash(char* mess, char* fpgasrc, uint64_t fsize); // programFpgaNios.h
extern int writeFPGAProgram(char* mess, char* fpgasrc, uint64_t fsize, FILE* filefp); // programFpgaNios.h
#endif
#if defined(JUNGFRAUD) || defined(EIGERD)
int getTenGigaFlowControl();
int setTenGigaFlowControl(int value);
@ -574,8 +538,12 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod);
#endif
int calculateDataBytes();
int getTotalNumberOfChannels();
#if defined(MOENCHD) || defined(CHIPTESTBOARDD)
void getNumberOfChannels(int* nchanx, int* nchany);
#endif
int getNumberOfChips();
int getNumberOfDACs();
int getNumberOfChannelsPerChip();

View File

@ -20,7 +20,7 @@ void validate64(int64_t arg, int64_t retval, char* modename, enum numberMode num
int executeCommand(char* command, char* result, enum TLogLevel level);
int M_nofunc(int);
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
extern void rebootControllerAndFPGA();
void rebootNiosControllerAndFPGA();
#endif
// functions called by client
@ -216,3 +216,4 @@ int get_current_source(int);
int set_current_source(int);
int get_timing_source(int);
int set_timing_source(int);
int get_num_channels(int);

View File

@ -82,7 +82,7 @@ uint32_t AD7689_DigMask = 0x0;
int AD7689_DigOffset = 0x0;
void AD7689_SetDefines(uint32_t reg, uint32_t roreg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst) {
FILE_LOG(logDEBUG, ("AD7689: reg:0x%x roreg:0x%x cmsk:0x%x clkmsk:0x%x dmsk:0x%x dofst:%d\n",
LOG(logDEBUG, ("AD7689: reg:0x%x roreg:0x%x cmsk:0x%x clkmsk:0x%x dmsk:0x%x dofst:%d\n",
reg, roreg, cmsk, clkmsk, dmsk, dofst));
AD7689_Reg = reg;
AD7689_ROReg = roreg;
@ -100,13 +100,13 @@ void AD7689_Disable() {
}
void AD7689_Set(uint32_t codata) {
FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Writing 0x%08x to Config Reg\n", codata));
LOG(logINFO, ("\tSetting ADC SPI Register. Writing 0x%08x to Config Reg\n", codata));
serializeToSPI(AD7689_Reg, codata, AD7689_CnvMask, AD7689_ADC_CFG_NUMBITS,
AD7689_ClkMask, AD7689_DigMask, AD7689_DigOffset, 1);
}
uint16_t AD7689_Get() {
FILE_LOG(logINFO, ("\tGetting ADC SPI Register.\n"));
LOG(logINFO, ("\tGetting ADC SPI Register.\n"));
return (uint16_t)serializeFromSPI(AD7689_Reg, AD7689_CnvMask, AD7689_ADC_DATA_NUMBITS,
AD7689_ClkMask, AD7689_DigMask, AD7689_ROReg, 1);
}
@ -135,11 +135,11 @@ int AD7689_GetTemperature() {
ConvertToDifferentRange(0, AD7689_INT_MAX_STEPS,
AD7689_INT_REF_MIN_MV, AD7689_INT_REF_MAX_MV,
regval, &retval);
FILE_LOG(logDEBUG1, ("voltage read for temp: %d mV\n", retval));
LOG(logDEBUG1, ("voltage read for temp: %d mV\n", retval));
// value in °C
double tempValue = AD7689_TMP_C_FOR_1_MV * (double)retval;
FILE_LOG(logINFO, ("\ttemp read : %f °C (%d unit)\n", tempValue, regval));
LOG(logINFO, ("\ttemp read : %f °C (%d unit)\n", tempValue, regval));
return tempValue;
@ -148,7 +148,7 @@ int AD7689_GetTemperature() {
int AD7689_GetChannel(int ichan) {
// filter channels val
if (ichan < 0 || ichan >= AD7689_NUM_CHANNELS) {
FILE_LOG(logERROR, ("Cannot get slow adc channel. "
LOG(logERROR, ("Cannot get slow adc channel. "
"%d out of bounds (0 to %d)\n", ichan, AD7689_NUM_CHANNELS - 1));
return -1;
}
@ -179,15 +179,15 @@ int AD7689_GetChannel(int ichan) {
AD7689_INT_REF_MIN_MV, AD7689_INT_REF_MAX_MV,
regval, &retval);*/
FILE_LOG(logINFO, ("\tvoltage read for chan %d: %d uV (regVal: %d)\n", ichan, retval, regval));
LOG(logINFO, ("\tvoltage read for chan %d: %d uV (regVal: %d)\n", ichan, retval, regval));
return retval;
}
void AD7689_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring AD7689 (Slow ADCs): \n"));
LOG(logINFOBLUE, ("Configuring AD7689 (Slow ADCs): \n"));
// from power up, 3 invalid conversions
FILE_LOG(logINFO, ("\tConfiguring %d x due to invalid conversions from power up\n", AD7689_NUM_INVALID_CONVERSIONS));
LOG(logINFO, ("\tConfiguring %d x due to invalid conversions from power up\n", AD7689_NUM_INVALID_CONVERSIONS));
int i = 0;
for (i = 0; i < AD7689_NUM_INVALID_CONVERSIONS; ++i) {
AD7689_Set(

View File

@ -124,40 +124,40 @@ void AD9252_Set(int addr, int val) {
u_int32_t codata;
codata = val + (addr << 8);
FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr));
LOG(logINFO, ("\tSetting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr));
serializeToSPI(AD9252_Reg, codata, AD9252_CsMask, AD9252_ADC_NUMBITS,
AD9252_ClkMask, AD9252_DigMask, AD9252_DigOffset, 0);
}
void AD9252_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring ADC9252:\n"));
LOG(logINFOBLUE, ("Configuring ADC9252:\n"));
//power mode reset
FILE_LOG(logINFO, ("\tPower mode reset\n"));
LOG(logINFO, ("\tPower mode reset\n"));
AD9252_Set(AD9252_POWER_MODE_REG, AD9252_INT_RESET_VAL);
//power mode chip run
FILE_LOG(logINFO, ("\tPower mode chip run\n"));
LOG(logINFO, ("\tPower mode chip run\n"));
AD9252_Set(AD9252_POWER_MODE_REG, AD9252_INT_CHIP_RUN_VAL);
// binary offset
FILE_LOG(logINFO, ("\tBinary offset\n"));
LOG(logINFO, ("\tBinary offset\n"));
AD9252_Set(AD9252_OUT_MODE_REG, AD9252_OUT_BINARY_OFST_VAL);
//output clock phase
#ifdef GOTTHARDD
FILE_LOG(logINFO, ("\tOutput clock phase is at default: 180\n"));
LOG(logINFO, ("\tOutput clock phase is at default: 180\n"));
#else
FILE_LOG(logINFO, ("\tOutput clock phase: 60\n"));
LOG(logINFO, ("\tOutput clock phase: 60\n"));
AD9257_Set(AD9257_OUT_PHASE_REG, AD9257_OUT_CLK_60_VAL);
#endif
// lvds-iee reduced , binary offset
FILE_LOG(logINFO, ("\tLvds-iee reduced, binary offset\n"));
LOG(logINFO, ("\tLvds-iee reduced, binary offset\n"));
AD9252_Set(AD9252_OUT_MODE_REG, AD9252_OUT_LVDS_IEEE_VAL);
// all devices on chip to receive next command
FILE_LOG(logINFO, ("\tAll devices on chip to receive next command\n"));
LOG(logINFO, ("\tAll devices on chip to receive next command\n"));
AD9252_Set(AD9252_DEV_IND_2_REG,
AD9252_CHAN_H_MSK | AD9252_CHAN_G_MSK | AD9252_CHAN_F_MSK | AD9252_CHAN_E_MSK);
AD9252_Set(AD9252_DEV_IND_1_REG,
@ -165,13 +165,13 @@ void AD9252_Configure(){
AD9252_CLK_CH_DCO_MSK | AD9252_CLK_CH_IFCO_MSK);
// no test mode
FILE_LOG(logINFO, ("\tNo test mode\n"));
LOG(logINFO, ("\tNo test mode\n"));
AD9252_Set(AD9252_TEST_MODE_REG, AD9252_TST_OFF_VAL);
#ifdef TESTADC
FILE_LOG(logINFOBLUE, ("Putting ADC in Test Mode!\n");
LOG(logINFOBLUE, ("Putting ADC in Test Mode!\n");
// mixed bit frequency test mode
FILE_LOG(logINFO, ("\tMixed bit frequency test mode\n"));
LOG(logINFO, ("\tMixed bit frequency test mode\n"));
AD9252_Set(AD9252_TEST_MODE_REG, AD9252_TST_MXD_BT_FRQ_VAL);
#endif
}

View File

@ -163,7 +163,7 @@ int AD9257_GetVrefVoltage(int mV) {
case 4:
return 2000;
default:
FILE_LOG(logERROR, ("Could not convert Adc Vpp from mode to mV\n"));
LOG(logERROR, ("Could not convert Adc Vpp from mode to mV\n"));
return -1;
}
}
@ -190,7 +190,7 @@ int AD9257_SetVrefVoltage(int val, int mV) {
break;
// validation for mV
default:
FILE_LOG(logERROR, ("mv:%d doesnt exist\n", val));
LOG(logERROR, ("mv:%d doesnt exist\n", val));
return FAIL;
}
}
@ -198,19 +198,19 @@ int AD9257_SetVrefVoltage(int val, int mV) {
// validation for mode
switch(mode) {
case 0:
FILE_LOG(logINFO, ("Setting ADC Vref to 1.0 V (Mode:%d)\n", mode));
LOG(logINFO, ("Setting ADC Vref to 1.0 V (Mode:%d)\n", mode));
break;
case 1:
FILE_LOG(logINFO, ("Setting ADC Vref to 1.14 V (Mode:%d)\n", mode));
LOG(logINFO, ("Setting ADC Vref to 1.14 V (Mode:%d)\n", mode));
break;
case 2:
FILE_LOG(logINFO, ("Setting ADC Vref to 1.33 V (Mode:%d)\n", mode));
LOG(logINFO, ("Setting ADC Vref to 1.33 V (Mode:%d)\n", mode));
break;
case 3:
FILE_LOG(logINFO, ("Setting ADC Vref to 1.6 V (Mode:%d)\n", mode));
LOG(logINFO, ("Setting ADC Vref to 1.6 V (Mode:%d)\n", mode));
break;
case 4:
FILE_LOG(logINFO, ("Setting ADC Vref to 2.0 V (Mode:%d)\n", mode));
LOG(logINFO, ("Setting ADC Vref to 2.0 V (Mode:%d)\n", mode));
break;
default:
return FAIL;
@ -225,32 +225,32 @@ void AD9257_Set(int addr, int val) {
u_int32_t codata;
codata = val + (addr << 8);
FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr));
LOG(logINFO, ("\tSetting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr));
serializeToSPI(AD9257_Reg, codata, AD9257_CsMask, AD9257_ADC_NUMBITS,
AD9257_ClkMask, AD9257_DigMask, AD9257_DigOffset, 0);
}
void AD9257_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring ADC9257:\n"));
LOG(logINFOBLUE, ("Configuring ADC9257:\n"));
//power mode reset
FILE_LOG(logINFO, ("\tPower mode reset\n"));
LOG(logINFO, ("\tPower mode reset\n"));
AD9257_Set(AD9257_POWER_MODE_REG, AD9257_INT_RESET_VAL);
//power mode chip run
FILE_LOG(logINFO, ("\tPower mode chip run\n"));
LOG(logINFO, ("\tPower mode chip run\n"));
AD9257_Set(AD9257_POWER_MODE_REG, AD9257_INT_CHIP_RUN_VAL);
// binary offset, lvds-iee reduced
FILE_LOG(logINFO, ("\tBinary offset, Lvds-ieee reduced\n"));
LOG(logINFO, ("\tBinary offset, Lvds-ieee reduced\n"));
AD9257_Set(AD9257_OUT_MODE_REG, AD9257_OUT_BINARY_OFST_VAL | AD9257_OUT_LVDS_IEEE_VAL);
//output clock phase
FILE_LOG(logINFO, ("\tOutput clock phase: 180\n"));
LOG(logINFO, ("\tOutput clock phase: 180\n"));
AD9257_Set(AD9257_OUT_PHASE_REG, AD9257_OUT_CLK_180_VAL);
// all devices on chip to receive next command
FILE_LOG(logINFO, ("\tAll devices on chip to receive next command\n"));
LOG(logINFO, ("\tAll devices on chip to receive next command\n"));
AD9257_Set(AD9257_DEV_IND_2_REG,
AD9257_CHAN_H_MSK | AD9257_CHAN_G_MSK | AD9257_CHAN_F_MSK | AD9257_CHAN_E_MSK);
@ -260,21 +260,21 @@ void AD9257_Configure(){
// vref
#ifdef GOTTHARDD
FILE_LOG(logINFO, ("\tVref default at 2.0\n"));
LOG(logINFO, ("\tVref default at 2.0\n"));
AD9257_SetVrefVoltage(AD9257_VREF_DEFAULT_VAL, 0);
#else
FILE_LOG(logINFO, ("\tVref 1.33\n"));
LOG(logINFO, ("\tVref 1.33\n"));
AD9257_SetVrefVoltage(AD9257_VREF_1_33_VAL, 0);
#endif
// no test mode
FILE_LOG(logINFO, ("\tNo test mode\n"));
LOG(logINFO, ("\tNo test mode\n"));
AD9257_Set(AD9257_TEST_MODE_REG, AD9257_TST_OFF_VAL);
#ifdef TESTADC
FILE_LOG(logINFOBLUE, ("Putting ADC in Test Mode!\n");
LOG(logINFOBLUE, ("Putting ADC in Test Mode!\n");
// mixed bit frequency test mode
FILE_LOG(logINFO, ("\tMixed bit frequency test mode\n"));
LOG(logINFO, ("\tMixed bit frequency test mode\n"));
AD9257_Set(AD9257_TEST_MODE_REG, AD9257_TST_MXD_BT_FRQ_VAL);
#endif
}

View File

@ -113,22 +113,22 @@ void ALTERA_PLL_SetDefines(uint32_t creg, uint32_t preg, uint32_t rprmsk, uint32
#endif
void ALTERA_PLL_ResetPLL () {
FILE_LOG(logINFO, ("Resetting only PLL\n"));
LOG(logINFO, ("Resetting only PLL\n"));
FILE_LOG(logDEBUG2, ("pllrstmsk:0x%x\n", ALTERA_PLL_Cntrl_PLLRstMask));
LOG(logDEBUG2, ("pllrstmsk:0x%x\n", ALTERA_PLL_Cntrl_PLLRstMask));
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) | ALTERA_PLL_Cntrl_PLLRstMask);
FILE_LOG(logDEBUG2, ("Set PLL Reset mSk: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
LOG(logDEBUG2, ("Set PLL Reset mSk: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
usleep(ALTERA_PLL_WAIT_TIME_US);
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) & ~ALTERA_PLL_Cntrl_PLLRstMask);
FILE_LOG(logDEBUG2, ("UnSet PLL Reset mSk: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
LOG(logDEBUG2, ("UnSet PLL Reset mSk: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
}
void ALTERA_PLL_ResetPLLAndReconfiguration () {
FILE_LOG(logINFO, ("Resetting PLL and Reconfiguration\n"));
LOG(logINFO, ("Resetting PLL and Reconfiguration\n"));
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) | ALTERA_PLL_Cntrl_RcnfgPrmtrRstMask | ALTERA_PLL_Cntrl_PLLRstMask);
usleep(ALTERA_PLL_WAIT_TIME_US);
@ -136,7 +136,7 @@ void ALTERA_PLL_ResetPLLAndReconfiguration () {
}
void ALTERA_PLL_SetPllReconfigReg(uint32_t reg, uint32_t val, int useSecondWRMask) {
FILE_LOG(logDEBUG1, ("Setting PLL Reconfig Reg, reg:0x%x, val:0x%x, useSecondWRMask:%d)\n", reg, val, useSecondWRMask));
LOG(logDEBUG1, ("Setting PLL Reconfig Reg, reg:0x%x, val:0x%x, useSecondWRMask:%d)\n", reg, val, useSecondWRMask));
uint32_t wrmask = ALTERA_PLL_Cntrl_WrPrmtrMask;
#ifdef JUNGFRAUD
@ -145,38 +145,38 @@ void ALTERA_PLL_SetPllReconfigReg(uint32_t reg, uint32_t val, int useSecondWRMas
}
#endif
FILE_LOG(logDEBUG2, ("pllparamreg:0x%x pllcontrolreg:0x%x addrofst:%d addrmsk:0x%x wrmask:0x%x\n",
LOG(logDEBUG2, ("pllparamreg:0x%x pllcontrolreg:0x%x addrofst:%d addrmsk:0x%x wrmask:0x%x\n",
ALTERA_PLL_Param_Reg, ALTERA_PLL_Cntrl_Reg, ALTERA_PLL_Cntrl_AddrOfst, ALTERA_PLL_Cntrl_AddrMask, wrmask));
// set parameter
bus_w(ALTERA_PLL_Param_Reg, val);
FILE_LOG(logDEBUG2, ("Set Parameter: ALTERA_PLL_Param_Reg:0x%x\n", bus_r(ALTERA_PLL_Param_Reg)));
LOG(logDEBUG2, ("Set Parameter: ALTERA_PLL_Param_Reg:0x%x\n", bus_r(ALTERA_PLL_Param_Reg)));
usleep(ALTERA_PLL_WAIT_TIME_US);
// set address
bus_w(ALTERA_PLL_Cntrl_Reg, (reg << ALTERA_PLL_Cntrl_AddrOfst) & ALTERA_PLL_Cntrl_AddrMask);
FILE_LOG(logDEBUG2, ("Set Address: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
LOG(logDEBUG2, ("Set Address: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
usleep(ALTERA_PLL_WAIT_TIME_US);
//write parameter
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) | wrmask);
FILE_LOG(logDEBUG2, ("Set WR bit: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
LOG(logDEBUG2, ("Set WR bit: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
usleep(ALTERA_PLL_WAIT_TIME_US);
bus_w(ALTERA_PLL_Cntrl_Reg, bus_r(ALTERA_PLL_Cntrl_Reg) & ~wrmask);
FILE_LOG(logDEBUG2, ("Unset WR bit: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
LOG(logDEBUG2, ("Unset WR bit: ALTERA_PLL_Cntrl_Reg:0x%x\n", bus_r(ALTERA_PLL_Cntrl_Reg)));
usleep(ALTERA_PLL_WAIT_TIME_US);
}
void ALTERA_PLL_SetPhaseShift(int32_t phase, int clkIndex, int pos) {
FILE_LOG(logINFO, ("\tWriting PLL Phase Shift\n"));
LOG(logINFO, ("\tWriting PLL Phase Shift\n"));
uint32_t value = (((phase << ALTERA_PLL_SHIFT_NUM_SHIFTS_OFST) & ALTERA_PLL_SHIFT_NUM_SHIFTS_MSK) |
((clkIndex << ALTERA_PLL_SHIFT_CNT_SELECT_OFST) & ALTERA_PLL_SHIFT_CNT_SELECT_MSK) |
(pos ? ALTERA_PLL_SHIFT_UP_DOWN_POS_VAL : ALTERA_PLL_SHIFT_UP_DOWN_NEG_VAL));
FILE_LOG(logDEBUG1, ("C%d phase word:0x%08x\n", clkIndex, value));
LOG(logDEBUG1, ("C%d phase word:0x%08x\n", clkIndex, value));
int useSecondWR = 0;
#ifdef JUNGFRAUD
@ -190,12 +190,12 @@ void ALTERA_PLL_SetPhaseShift(int32_t phase, int clkIndex, int pos) {
}
void ALTERA_PLL_SetModePolling() {
FILE_LOG(logINFO, ("\tSetting Polling Mode\n"));
LOG(logINFO, ("\tSetting Polling Mode\n"));
ALTERA_PLL_SetPllReconfigReg(ALTERA_PLL_MODE_REG, ALTERA_PLL_MODE_PLLNG_MD_VAL, 0);
}
int ALTERA_PLL_SetOuputFrequency (int clkIndex, int pllVCOFreqMhz, int value) {
FILE_LOG(logDEBUG1, ("C%d: Setting output frequency to %d (pllvcofreq: %dMhz)\n", clkIndex, value, pllVCOFreqMhz));
LOG(logDEBUG1, ("C%d: Setting output frequency to %d (pllvcofreq: %dMhz)\n", clkIndex, value, pllVCOFreqMhz));
// calculate output frequency
float total_div = (float)pllVCOFreqMhz / (float)value;
@ -210,14 +210,14 @@ int ALTERA_PLL_SetOuputFrequency (int clkIndex, int pllVCOFreqMhz, int value) {
++high_count;
odd_division = 1;
}
FILE_LOG(logINFO, ("\tC%d: Low:%d, High:%d, Odd:%d\n", clkIndex, low_count, high_count, odd_division));
LOG(logINFO, ("\tC%d: Low:%d, High:%d, Odd:%d\n", clkIndex, low_count, high_count, odd_division));
// command to set output frequency
uint32_t val = (((low_count << ALTERA_PLL_C_COUNTER_LW_CNT_OFST) & ALTERA_PLL_C_COUNTER_LW_CNT_MSK) |
((high_count << ALTERA_PLL_C_COUNTER_HGH_CNT_OFST) & ALTERA_PLL_C_COUNTER_HGH_CNT_MSK) |
((odd_division << ALTERA_PLL_C_COUNTER_ODD_DVSN_OFST) & ALTERA_PLL_C_COUNTER_ODD_DVSN_MSK) |
((clkIndex << ALTERA_PLL_C_COUNTER_SLCT_OFST) & ALTERA_PLL_C_COUNTER_SLCT_MSK));
FILE_LOG(logDEBUG1, ("C%d word:0x%08x\n", clkIndex, val));
LOG(logDEBUG1, ("C%d word:0x%08x\n", clkIndex, val));
// write frequency (post-scale output counter C)
ALTERA_PLL_SetPllReconfigReg(ALTERA_PLL_C_COUNTER_REG, val, 0);

View File

@ -76,10 +76,10 @@ int ALTERA_PLL_C10_GetMaxPhaseShiftStepsofVCO() {
}
void ALTERA_PLL_C10_Reconfigure(int pllIndex) {
FILE_LOG(logINFO, ("\tReconfiguring PLL %d\n", pllIndex));
LOG(logINFO, ("\tReconfiguring PLL %d\n", pllIndex));
// write anything to base address to start reconfiguring
FILE_LOG(logDEBUG1, ("\tWriting 1 to base address 0x%x to start reconfiguring\n", ALTERA_PLL_C10_BaseAddress[pllIndex]));
LOG(logDEBUG1, ("\tWriting 1 to base address 0x%x to start reconfiguring\n", ALTERA_PLL_C10_BaseAddress[pllIndex]));
bus_w_csp1(ALTERA_PLL_C10_BaseAddress[pllIndex], 0x1);
usleep(ALTERA_PLL_C10_WAIT_TIME_US);
}
@ -87,7 +87,7 @@ void ALTERA_PLL_C10_Reconfigure(int pllIndex) {
void ALTERA_PLL_C10_ResetPLL (int pllIndex) {
uint32_t resetreg = ALTERA_PLL_C10_Reset_Reg[pllIndex];
uint32_t resetmsk = ALTERA_PLL_C10_Reset_Msk[pllIndex];
FILE_LOG(logINFO, ("Resetting PLL %d\n", pllIndex));
LOG(logINFO, ("Resetting PLL %d\n", pllIndex));
bus_w_csp1(resetreg, bus_r_csp1(resetreg) | resetmsk);
usleep(ALTERA_PLL_C10_WAIT_TIME_US);
@ -95,7 +95,7 @@ void ALTERA_PLL_C10_ResetPLL (int pllIndex) {
void ALTERA_PLL_C10_SetPhaseShift(int pllIndex, int clkIndex, int phase, int pos) {
FILE_LOG(logINFO, ("\tC%d: Writing PLL %d Phase Shift [phase:%d, pos dir:%d]\n", clkIndex, pllIndex, phase, pos));
LOG(logINFO, ("\tC%d: Writing PLL %d Phase Shift [phase:%d, pos dir:%d]\n", clkIndex, pllIndex, phase, pos));
uint32_t addr = ALTERA_PLL_C10_BaseAddress[pllIndex] + (ALTERA_PLL_C10_PHASE_SHIFT_BASE_REG + (int)clkIndex) * ALTERA_PLL_C10_Reg_offset;
int maxshifts = ALTERA_PLL_C10_MAX_SHIFTS_PER_OPERATION;
@ -105,7 +105,7 @@ void ALTERA_PLL_C10_SetPhaseShift(int pllIndex, int clkIndex, int phase, int pos
int phaseToDo = (phase > maxshifts) ? maxshifts : phase;
uint32_t value = (((phaseToDo << ALTERA_PLL_C10_SHIFT_NUM_SHIFTS_OFST) & ALTERA_PLL_C10_SHIFT_NUM_SHIFTS_MSK) |
(pos ? ALTERA_PLL_C10_SHIFT_UP_DOWN_POS_VAL : ALTERA_PLL_C10_SHIFT_UP_DOWN_NEG_VAL));
FILE_LOG(logDEBUG1, ("\t[addr:0x%x, phaseTodo:%d phaseleft:%d phase word:0x%08x]\n", addr, phaseToDo, phase, value));
LOG(logDEBUG1, ("\t[addr:0x%x, phaseTodo:%d phaseleft:%d phase word:0x%08x]\n", addr, phaseToDo, phase, value));
bus_w_csp1(addr, value);
ALTERA_PLL_C10_Reconfigure(pllIndex);
@ -116,7 +116,7 @@ void ALTERA_PLL_C10_SetPhaseShift(int pllIndex, int clkIndex, int phase, int pos
void ALTERA_PLL_C10_SetOuputFrequency (int pllIndex, int clkIndex, int value) {
int pllVCOFreqHz = ALTERA_PLL_C10_VCO_FREQ[pllIndex];
FILE_LOG(logDEBUG1, ("\tC%d: Setting output frequency for pll %d to %d (pllvcofreq: %dHz)\n", clkIndex, pllIndex, value, pllVCOFreqHz));
LOG(logDEBUG1, ("\tC%d: Setting output frequency for pll %d to %d (pllvcofreq: %dHz)\n", clkIndex, pllIndex, value, pllVCOFreqHz));
// calculate output frequency
float total_div = (float)pllVCOFreqHz / (float)value;
@ -131,14 +131,14 @@ void ALTERA_PLL_C10_SetOuputFrequency (int pllIndex, int clkIndex, int value) {
++high_count;
odd_division = 1;
}
FILE_LOG(logINFO, ("\tC%d: Low:%d, High:%d, Odd:%d\n", clkIndex, low_count, high_count, odd_division));
LOG(logINFO, ("\tC%d: Low:%d, High:%d, Odd:%d\n", clkIndex, low_count, high_count, odd_division));
// command to set output frequency
uint32_t addr = ALTERA_PLL_C10_BaseAddress[pllIndex] + (ALTERA_PLL_C10_C_COUNTER_BASE_REG + (int)clkIndex) * ALTERA_PLL_C10_Reg_offset;
uint32_t val = (((low_count << ALTERA_PLL_C10_C_COUNTER_LW_CNT_OFST) & ALTERA_PLL_C10_C_COUNTER_LW_CNT_MSK) |
((high_count << ALTERA_PLL_C10_C_COUNTER_HGH_CNT_OFST) & ALTERA_PLL_C10_C_COUNTER_HGH_CNT_MSK) |
((odd_division << ALTERA_PLL_C10_C_COUNTER_ODD_DVSN_OFST) & ALTERA_PLL_C10_C_COUNTER_ODD_DVSN_MSK));
FILE_LOG(logDEBUG1, ("\t[addr:0x%x, word:0x%08x]\n", addr, val));
LOG(logDEBUG1, ("\t[addr:0x%x, word:0x%08x]\n", addr, val));
// write frequency
bus_w_csp1(addr, val);

View File

@ -20,7 +20,7 @@ char ASIC_Driver_DriverFileName[MAX_STR_LENGTH];
void ASIC_Driver_SetDefines(char* driverfname) {
FILE_LOG(logINFOBLUE, ("Configuring ASIC Driver to %s\n", driverfname));
LOG(logINFOBLUE, ("Configuring ASIC Driver to %s\n", driverfname));
memset(ASIC_Driver_DriverFileName, 0, MAX_STR_LENGTH);
strcpy(ASIC_Driver_DriverFileName, driverfname);
}
@ -28,14 +28,14 @@ void ASIC_Driver_SetDefines(char* driverfname) {
int ASIC_Driver_Set (int index, int length, char* buffer) {
char fname[MAX_STR_LENGTH];
sprintf(fname, "%s%d", ASIC_Driver_DriverFileName, index + 1);
FILE_LOG(logDEBUG2, ("\t[chip index: %d, length: %d, fname: %s]\n", index, length, fname));
LOG(logDEBUG2, ("\t[chip index: %d, length: %d, fname: %s]\n", index, length, fname));
{
FILE_LOG(logDEBUG2, ("\t[values: \n"));
LOG(logDEBUG2, ("\t[values: \n"));
int i;
for (i = 0; i < length; ++i) {
FILE_LOG(logDEBUG2, ("\t%d: 0x%02hhx\n", i, buffer[i]));
LOG(logDEBUG2, ("\t%d: 0x%02hhx\n", i, buffer[i]));
}
FILE_LOG(logDEBUG2, ("\t]\n"));
LOG(logDEBUG2, ("\t]\n"));
}
#ifdef VIRTUAL
@ -43,7 +43,7 @@ int ASIC_Driver_Set (int index, int length, char* buffer) {
#endif
int fd=open(fname, O_RDWR);
if (fd == -1) {
FILE_LOG(logERROR, ("Could not open file %s for writing to control ASIC (%d)\n", fname, index));
LOG(logERROR, ("Could not open file %s for writing to control ASIC (%d)\n", fname, index));
return FAIL;
}
@ -56,7 +56,7 @@ int ASIC_Driver_Set (int index, int length, char* buffer) {
// transfer command
int status = ioctl(fd, SPI_IOC_MESSAGE(1), &transfer);
if (status < 0) {
FILE_LOG(logERROR, ("Could not send command to ASIC\n"));
LOG(logERROR, ("Could not send command to ASIC\n"));
perror("SPI_IOC_MESSAGE");
close(fd);
return FAIL;

View File

@ -15,14 +15,14 @@ int DAC6571_HardMaxVoltage = 0;
char DAC6571_DriverFileName[MAX_STR_LENGTH];
void DAC6571_SetDefines(int hardMaxV, char* driverfname) {
FILE_LOG(logINFOBLUE, ("Configuring High Voltage to %s (hard max: %dV)\n", driverfname, hardMaxV));
LOG(logINFOBLUE, ("Configuring High Voltage to %s (hard max: %dV)\n", driverfname, hardMaxV));
DAC6571_HardMaxVoltage = hardMaxV;
memset(DAC6571_DriverFileName, 0, MAX_STR_LENGTH);
strcpy(DAC6571_DriverFileName, driverfname);
}
int DAC6571_Set (int val) {
FILE_LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
if (val < 0)
return FAIL;
@ -34,12 +34,12 @@ int DAC6571_Set (int val) {
DAC6571_MIN_DAC_VAL, DAC6571_MAX_DAC_VAL,
val, &dacvalue);
FILE_LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
//open file
FILE* fd=fopen(DAC6571_DriverFileName,"w");
if (fd==NULL) {
FILE_LOG(logERROR, ("Could not open file %s for writing to set high voltage\n", DAC6571_DriverFileName));
LOG(logERROR, ("Could not open file %s for writing to set high voltage\n", DAC6571_DriverFileName));
return FAIL;
}
//convert to string, add 0 and write to file

View File

@ -101,8 +101,8 @@ uint32_t I2C_Transfer_Command_Fifo_Reg = 0x0;
void I2C_ConfigureI2CCore(uint32_t creg, uint32_t sreg,
uint32_t rreg, uint32_t rlvlreg,
uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg) {
FILE_LOG(logINFO, ("\tConfiguring I2C Core for %d kbps:\n", I2C_DATA_RATE_KBPS));
FILE_LOG(logDEBUG1,("controlreg,:0x%x, statusreg,:0x%x, "
LOG(logINFO, ("\tConfiguring I2C Core for %d kbps:\n", I2C_DATA_RATE_KBPS));
LOG(logDEBUG1,("controlreg,:0x%x, statusreg,:0x%x, "
"rxrdatafiforeg: 0x%x, rxdatafifocountreg,:0x%x, "
"scllow,:0x%x, sclhighreg,:0x%x, sdaholdreg,:0x%x, transfercmdreg,:0x%x\n",
creg, sreg, rreg, rlvlreg, slreg, shreg, sdreg, treg));
@ -128,54 +128,54 @@ void I2C_ConfigureI2CCore(uint32_t creg, uint32_t sreg,
// convert to us, then to clock (defined in blackfin.h)
uint32_t sdaDataHoldCount = ((sdaDataHoldTimeNs / 1000.00) * I2C_CLOCK_MHZ);
FILE_LOG(logINFO, ("\tSetting SCL Low Period: %d ns (%d clocks)\n", sclLowPeriodNs, sclLowPeriodCount));
LOG(logINFO, ("\tSetting SCL Low Period: %d ns (%d clocks)\n", sclLowPeriodNs, sclLowPeriodCount));
bus_w(I2C_Scl_Low_Count_Reg, bus_r(I2C_Scl_Low_Count_Reg) |
((sclLowPeriodCount << I2C_SCL_LOW_COUNT_PERIOD_OFST) & I2C_SCL_LOW_COUNT_PERIOD_MSK));
FILE_LOG(logDEBUG1, ("SCL Low reg:0x%x\n", bus_r(I2C_Scl_Low_Count_Reg)));
LOG(logDEBUG1, ("SCL Low reg:0x%x\n", bus_r(I2C_Scl_Low_Count_Reg)));
FILE_LOG(logINFO, ("\tSetting SCL High Period: %d ns (%d clocks)\n", sclLowPeriodNs, sclLowPeriodCount));
LOG(logINFO, ("\tSetting SCL High Period: %d ns (%d clocks)\n", sclLowPeriodNs, sclLowPeriodCount));
bus_w(I2C_Scl_High_Count_Reg, bus_r(I2C_Scl_High_Count_Reg) |
((sclLowPeriodCount << I2C_SCL_HIGH_COUNT_PERIOD_OFST) & I2C_SCL_HIGH_COUNT_PERIOD_MSK));
FILE_LOG(logDEBUG1, ("SCL High reg:0x%x\n", bus_r(I2C_Scl_High_Count_Reg)));
LOG(logDEBUG1, ("SCL High reg:0x%x\n", bus_r(I2C_Scl_High_Count_Reg)));
FILE_LOG(logINFO, ("\tSetting SDA Hold Time: %d ns (%d clocks)\n", sdaDataHoldTimeNs, sdaDataHoldCount));
LOG(logINFO, ("\tSetting SDA Hold Time: %d ns (%d clocks)\n", sdaDataHoldTimeNs, sdaDataHoldCount));
bus_w(I2C_Sda_Hold_Reg, bus_r(I2C_Sda_Hold_Reg) |
((sdaDataHoldCount << I2C_SDA_HOLD_COUNT_PERIOD_OFST) & I2C_SDA_HOLD_COUNT_PERIOD_MSK));
FILE_LOG(logDEBUG1, ("SDA Hold reg:0x%x\n", bus_r(I2C_Sda_Hold_Reg)));
LOG(logDEBUG1, ("SDA Hold reg:0x%x\n", bus_r(I2C_Sda_Hold_Reg)));
FILE_LOG(logINFO, ("\tEnabling core and bus speed to fast (up to 400 kbps)\n"));
LOG(logINFO, ("\tEnabling core and bus speed to fast (up to 400 kbps)\n"));
bus_w(I2C_Control_Reg, bus_r(I2C_Control_Reg) |
I2C_CTRL_ENBLE_CORE_MSK | I2C_CTRL_BUS_SPEED_FAST_400_VAL);// fixme: (works?)
FILE_LOG(logDEBUG1, ("Control reg:0x%x\n", bus_r(I2C_Control_Reg)));
LOG(logDEBUG1, ("Control reg:0x%x\n", bus_r(I2C_Control_Reg)));
//The INA226 supports the transmission protocol for fast mode (1 kHz to 400 kHz) and high-speed mode (1 kHz to 2.94 MHz).
}
uint32_t I2C_Read(uint32_t devId, uint32_t addr) {
FILE_LOG(logDEBUG2, (" ================================================\n"));
FILE_LOG(logDEBUG2, (" Reading from I2C device 0x%x and reg 0x%x\n", devId, addr));
LOG(logDEBUG2, (" ================================================\n"));
LOG(logDEBUG2, (" Reading from I2C device 0x%x and reg 0x%x\n", devId, addr));
// device Id mask
uint32_t devIdMask = ((devId << I2C_TFR_CMD_ADDR_OFST) & I2C_TFR_CMD_ADDR_MSK);
FILE_LOG(logDEBUG2, (" devId:0x%x\n", devIdMask));
LOG(logDEBUG2, (" devId:0x%x\n", devIdMask));
// write I2C ID
bus_w(I2C_Transfer_Command_Fifo_Reg, (devIdMask & ~(I2C_TFR_CMD_RW_MSK)));
FILE_LOG(logDEBUG2, (" write devID and R/-W:0x%x\n", (devIdMask & ~(I2C_TFR_CMD_RW_MSK))));
LOG(logDEBUG2, (" write devID and R/-W:0x%x\n", (devIdMask & ~(I2C_TFR_CMD_RW_MSK))));
// write register addr
bus_w(I2C_Transfer_Command_Fifo_Reg, addr);
FILE_LOG(logDEBUG2, (" write addr:0x%x\n", addr));
LOG(logDEBUG2, (" write addr:0x%x\n", addr));
// repeated start with read (repeated start needed here because it was in write operation mode earlier, for the device ID)
bus_w(I2C_Transfer_Command_Fifo_Reg, (devIdMask | I2C_TFR_CMD_RPTD_STRT_MSK | I2C_TFR_CMD_RW_READ_VAL));
FILE_LOG(logDEBUG2, (" repeated start:0x%x\n", (devIdMask | I2C_TFR_CMD_RPTD_STRT_MSK | I2C_TFR_CMD_RW_READ_VAL)));
LOG(logDEBUG2, (" repeated start:0x%x\n", (devIdMask | I2C_TFR_CMD_RPTD_STRT_MSK | I2C_TFR_CMD_RW_READ_VAL)));
// continue reading
bus_w(I2C_Transfer_Command_Fifo_Reg, 0x0);
FILE_LOG(logDEBUG2, (" continue reading:0x%x\n", 0x0));
LOG(logDEBUG2, (" continue reading:0x%x\n", 0x0));
// stop reading
bus_w(I2C_Transfer_Command_Fifo_Reg, I2C_TFR_CMD_STOP_MSK);
FILE_LOG(logDEBUG2, (" stop reading:0x%x\n", I2C_TFR_CMD_STOP_MSK));
LOG(logDEBUG2, (" stop reading:0x%x\n", I2C_TFR_CMD_STOP_MSK));
// read value
uint32_t retval = 0;
@ -185,56 +185,56 @@ uint32_t I2C_Read(uint32_t devId, uint32_t addr) {
int status = 1;
while(status) {
status = bus_r(I2C_Status_Reg) & I2C_STATUS_BUSY_MSK;
FILE_LOG(logDEBUG2, (" status:%d\n", status));
LOG(logDEBUG2, (" status:%d\n", status));
usleep(0);
}
// get rx fifo level (get number of bytes to be received)
int level = bus_r(I2C_Rx_Data_Fifo_Level_Reg);
FILE_LOG(logDEBUG2, (" level:%d\n", level));
LOG(logDEBUG2, (" level:%d\n", level));
int iloop = level - 1;
// level bytes to read, read 1 byte at a time
for (iloop = level - 1; iloop >= 0; --iloop) {
u_int16_t byte = bus_r(I2C_Rx_Data_Fifo_Reg) & I2C_RX_DATA_FIFO_RXDATA_MSK;
FILE_LOG(logDEBUG2, (" byte nr %d:0x%x\n", iloop, byte));
LOG(logDEBUG2, (" byte nr %d:0x%x\n", iloop, byte));
// push by 1 byte at a time
retval |= (byte << (8 * iloop));
}
FILE_LOG(logDEBUG2, (" retval:0x%x\n", retval));
FILE_LOG(logDEBUG2, (" ================================================\n"));
LOG(logDEBUG2, (" retval:0x%x\n", retval));
LOG(logDEBUG2, (" ================================================\n"));
return retval;
}
void I2C_Write(uint32_t devId, uint32_t addr, uint16_t data) {
FILE_LOG(logDEBUG2, (" ================================================\n"));
FILE_LOG(logDEBUG2, (" Writing to I2C (Device:0x%x, reg:0x%x, data:%d)\n", devId, addr, data));
LOG(logDEBUG2, (" ================================================\n"));
LOG(logDEBUG2, (" Writing to I2C (Device:0x%x, reg:0x%x, data:%d)\n", devId, addr, data));
// device Id mask
uint32_t devIdMask = ((devId << I2C_TFR_CMD_ADDR_OFST) & I2C_TFR_CMD_ADDR_MSK);
FILE_LOG(logDEBUG2, (" devId:0x%x\n", devId));
LOG(logDEBUG2, (" devId:0x%x\n", devId));
// write I2C ID
bus_w(I2C_Transfer_Command_Fifo_Reg, (devIdMask & ~(I2C_TFR_CMD_RW_MSK)));
FILE_LOG(logDEBUG2, (" write devID and R/-W:0x%x\n", (devIdMask & ~(I2C_TFR_CMD_RW_MSK))));
LOG(logDEBUG2, (" write devID and R/-W:0x%x\n", (devIdMask & ~(I2C_TFR_CMD_RW_MSK))));
// write register addr
bus_w(I2C_Transfer_Command_Fifo_Reg, addr);
FILE_LOG(logDEBUG2, (" write addr:0x%x\n", addr));
LOG(logDEBUG2, (" write addr:0x%x\n", addr));
// do not do the repeated start as it is already in write operation mode (else it wont work)
uint8_t msb = (uint8_t)((data & 0xFF00) >> 8);
uint8_t lsb = (uint8_t)(data & 0x00FF);
FILE_LOG(logDEBUG2, (" msb:0x%02x, lsb:0x%02x\n", msb, lsb));
LOG(logDEBUG2, (" msb:0x%02x, lsb:0x%02x\n", msb, lsb));
// writing data MSB
bus_w(I2C_Transfer_Command_Fifo_Reg, ((msb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK));
FILE_LOG(logDEBUG2, (" write msb:0x%02x\n", ((msb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK)));
LOG(logDEBUG2, (" write msb:0x%02x\n", ((msb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK)));
// writing data LSB and stop writing bit
bus_w(I2C_Transfer_Command_Fifo_Reg, ((lsb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK) | I2C_TFR_CMD_STOP_MSK);
FILE_LOG(logDEBUG2, (" write lsb and stop writing:0x%x\n", ((lsb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK) | I2C_TFR_CMD_STOP_MSK));
FILE_LOG(logDEBUG2, (" ================================================\n"));
LOG(logDEBUG2, (" write lsb and stop writing:0x%x\n", ((lsb << I2C_TFR_CMD_DATA_FR_WR_OFST) & I2C_TFR_CMD_DATA_FR_WR_MSK) | I2C_TFR_CMD_STOP_MSK));
LOG(logDEBUG2, (" ================================================\n"));
}

View File

@ -63,21 +63,21 @@ int INA226_Calibration_Register_Value = 0;
void INA226_ConfigureI2CCore(double rOhm, uint32_t creg, uint32_t sreg,
uint32_t rreg, uint32_t rlvlreg,
uint32_t slreg, uint32_t shreg, uint32_t sdreg, uint32_t treg) {
FILE_LOG(logINFOBLUE, ("Configuring INA226\n"));
FILE_LOG(logDEBUG1, ("Shunt ohm resistor: %f\n", rOhm));
LOG(logINFOBLUE, ("Configuring INA226\n"));
LOG(logDEBUG1, ("Shunt ohm resistor: %f\n", rOhm));
INA226_Shunt_Resistor_Ohm = rOhm;
I2C_ConfigureI2CCore(creg, sreg, rreg, rlvlreg, slreg, shreg, sdreg, treg);
}
void INA226_CalibrateCurrentRegister(uint32_t deviceId) {
FILE_LOG(logINFO, ("Calibrating Current Register for Device ID: 0x%x\n", deviceId));
LOG(logINFO, ("Calibrating Current Register for Device ID: 0x%x\n", deviceId));
// get calibration value based on shunt resistor
uint16_t calVal = ((uint16_t)INA226_getCalibrationValue(INA226_Shunt_Resistor_Ohm)) & INA226_CALIBRATION_MSK;
FILE_LOG(logINFO, ("\tCalculated calibration reg value: 0x%0x (%d)\n", calVal, calVal));
LOG(logINFO, ("\tCalculated calibration reg value: 0x%0x (%d)\n", calVal, calVal));
calVal = ((double)calVal / INA226_CALIBRATION_CURRENT_TOLERANCE) + 0.5;
FILE_LOG(logINFO, ("\tRealculated (for tolerance) calibration reg value: 0x%0x (%d)\n", calVal, calVal));
LOG(logINFO, ("\tRealculated (for tolerance) calibration reg value: 0x%0x (%d)\n", calVal, calVal));
INA226_Calibration_Register_Value = calVal;
// calibrate current register
@ -86,71 +86,71 @@ void INA226_CalibrateCurrentRegister(uint32_t deviceId) {
// read back calibration register
int retval = I2C_Read(deviceId, INA226_CALIBRATION_REG);
if (retval != calVal) {
FILE_LOG(logERROR, ("Cannot set calibration register for I2C. Set 0x%x, read 0x%x\n", calVal, retval));
LOG(logERROR, ("Cannot set calibration register for I2C. Set 0x%x, read 0x%x\n", calVal, retval));
}
}
int INA226_ReadVoltage(uint32_t deviceId) {
FILE_LOG(logDEBUG1, (" Reading voltage\n"));
LOG(logDEBUG1, (" Reading voltage\n"));
uint32_t regval = I2C_Read(deviceId, INA226_BUS_VOLTAGE_REG);
FILE_LOG(logDEBUG1, (" bus voltage reg: 0x%08x\n", regval));
LOG(logDEBUG1, (" bus voltage reg: 0x%08x\n", regval));
// value in uV
int voltageuV = 0;
ConvertToDifferentRange(0, INA226_BUS_VOLTAGE_MX_STPS,
INA226_BUS_VOLTAGE_VMIN_UV, INA226_BUS_VOLTAGE_VMAX_UV,
regval, &voltageuV);
FILE_LOG(logDEBUG1, (" voltage: 0x%d uV\n", voltageuV));
LOG(logDEBUG1, (" voltage: 0x%d uV\n", voltageuV));
// value in mV
int voltagemV = voltageuV / 1000;
FILE_LOG(logDEBUG1, (" voltage: %d mV\n", voltagemV));
FILE_LOG(logINFO, ("Voltage via I2C (Device: 0x%x): %d mV\n", deviceId, voltagemV));
LOG(logDEBUG1, (" voltage: %d mV\n", voltagemV));
LOG(logINFO, ("Voltage via I2C (Device: 0x%x): %d mV\n", deviceId, voltagemV));
return voltagemV;
}
int INA226_ReadCurrent(uint32_t deviceId) {
FILE_LOG(logDEBUG1, (" Reading current\n"));
LOG(logDEBUG1, (" Reading current\n"));
// read shunt voltage register
FILE_LOG(logDEBUG1, (" Reading shunt voltage reg\n"));
LOG(logDEBUG1, (" Reading shunt voltage reg\n"));
uint32_t shuntVoltageRegVal = I2C_Read(deviceId, INA226_SHUNT_VOLTAGE_REG);
FILE_LOG(logDEBUG1, (" shunt voltage reg: %d\n", shuntVoltageRegVal));
LOG(logDEBUG1, (" shunt voltage reg: %d\n", shuntVoltageRegVal));
// read it once more as this error has occured once
if (shuntVoltageRegVal == 0xFFFF) {
FILE_LOG(logDEBUG1, (" Reading shunt voltage reg again\n"));
LOG(logDEBUG1, (" Reading shunt voltage reg again\n"));
shuntVoltageRegVal = I2C_Read(deviceId, INA226_SHUNT_VOLTAGE_REG);
FILE_LOG(logDEBUG1, (" shunt voltage reg: %d\n", shuntVoltageRegVal));
LOG(logDEBUG1, (" shunt voltage reg: %d\n", shuntVoltageRegVal));
}
// value for current
int retval = INA226_getConvertedCurrentUnits(shuntVoltageRegVal, INA226_Calibration_Register_Value);
FILE_LOG(logDEBUG1, (" current unit value: %d\n", retval));
LOG(logDEBUG1, (" current unit value: %d\n", retval));
// reading directly the current reg
FILE_LOG(logDEBUG1, (" Reading current reg\n"));
LOG(logDEBUG1, (" Reading current reg\n"));
int cuurentRegVal = I2C_Read(deviceId, INA226_CURRENT_REG);
FILE_LOG(logDEBUG1, (" current reg: %d\n", cuurentRegVal));
LOG(logDEBUG1, (" current reg: %d\n", cuurentRegVal));
// read it once more as this error has occured once
if (cuurentRegVal >= 0xFFF0) {
FILE_LOG(logDEBUG1, (" Reading current reg again\n"));
LOG(logDEBUG1, (" Reading current reg again\n"));
cuurentRegVal = I2C_Read(deviceId, INA226_CURRENT_REG);
FILE_LOG(logDEBUG1, (" current reg: %d\n", cuurentRegVal));
LOG(logDEBUG1, (" current reg: %d\n", cuurentRegVal));
}
// should be the same
FILE_LOG(logDEBUG1, (" ===============current reg: %d, current unit cal:%d=================================\n", cuurentRegVal, retval));
LOG(logDEBUG1, (" ===============current reg: %d, current unit cal:%d=================================\n", cuurentRegVal, retval));
// current in uA
int currentuA = cuurentRegVal * INA226_CURRENT_IMIN_UA;
FILE_LOG(logDEBUG1, (" current: %d uA\n", currentuA));
LOG(logDEBUG1, (" current: %d uA\n", currentuA));
// current in mA
int currentmA = (currentuA / 1000.00) + 0.5;
FILE_LOG(logDEBUG1, (" current: %d mA\n", currentmA));
LOG(logDEBUG1, (" current: %d mA\n", currentmA));
FILE_LOG(logINFO, ("Current via I2C (Device: 0x%x): %d mA\n", deviceId, currentmA));
LOG(logINFO, ("Current via I2C (Device: 0x%x): %d mA\n", deviceId, currentmA));
return currentmA;
}

View File

@ -92,12 +92,12 @@ int LTC2620_DacToVoltage(int dacval, int* voltage) {
}
void LTC2620_SetSingle(int cmd, int data, int dacaddr) {
FILE_LOG(logDEBUG2, ("(Single) dac addr:%d, dac value:%d, cmd:%d\n", dacaddr, data, cmd));
LOG(logDEBUG2, ("(Single) dac addr:%d, dac value:%d, cmd:%d\n", dacaddr, data, cmd));
uint32_t codata = (((data << LTC2620_DAC_DATA_OFST) & LTC2620_DAC_DATA_MSK) |
((dacaddr << LTC2620_DAC_ADDR_OFST) & LTC2620_DAC_ADDR_MSK) |
cmd);
FILE_LOG(logDEBUG2, ("codata: 0x%x\n", codata));
LOG(logDEBUG2, ("codata: 0x%x\n", codata));
serializeToSPI (LTC2620_Reg, codata, LTC2620_CsMask, LTC2620_NUMBITS,
LTC2620_ClkMask, LTC2620_DigMask, LTC2620_DigOffset, 0);
@ -114,24 +114,24 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
uint32_t valw = 0;
int ichip = 0;
FILE_LOG(logDEBUG2, ("(Daisy) desired chip index:%d, nchip:%d, dac ch:%d, val:%d, cmd:0x%x \n",
LOG(logDEBUG2, ("(Daisy) desired chip index:%d, nchip:%d, dac ch:%d, val:%d, cmd:0x%x \n",
chipIndex, nchip, dacaddr, data, cmd));
// data to be bit banged
uint32_t codata = (((data << LTC2620_DAC_DATA_OFST) & LTC2620_DAC_DATA_MSK) |
((dacaddr << LTC2620_DAC_ADDR_OFST) & LTC2620_DAC_ADDR_MSK) |
cmd);
FILE_LOG(logDEBUG2, ("codata: 0x%x\n", codata));
LOG(logDEBUG2, ("codata: 0x%x\n", codata));
// select all chips (ctb daisy chain; others 1 chip)
FILE_LOG(logDEBUG2, ("Selecting LTC2620\n"));
LOG(logDEBUG2, ("Selecting LTC2620\n"));
SPIChipSelect (&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask, 0);
// send same data to all
if (chipIndex < 0) {
FILE_LOG(logDEBUG2, ("Send same data to all\n"));
LOG(logDEBUG2, ("Send same data to all\n"));
for (ichip = 0; ichip < nchip; ++ichip) {
FILE_LOG(logDEBUG2, ("Send data (0x%x) to ichip %d\n", codata, ichip));
LOG(logDEBUG2, ("Send data (0x%x) to ichip %d\n", codata, ichip));
LTC2620_SendDaisyData(&valw, codata);
}
}
@ -140,40 +140,40 @@ void LTC2620_SetDaisy(int cmd, int data, int dacaddr, int chipIndex) {
else {
// send nothing to subsequent ichips (daisy chain) (if any chips after desired chip)
for (ichip = chipIndex + 1; ichip < nchip; ++ichip) {
FILE_LOG(logDEBUG2, ("Send nothing to ichip %d\n", ichip));
LOG(logDEBUG2, ("Send nothing to ichip %d\n", ichip));
LTC2620_SendDaisyData(&valw, LTC2620_DAC_CMD_NO_OPRTN_VAL);
}
// send data to desired chip
FILE_LOG(logDEBUG2, ("Send data (0x%x) to ichip %d\n", codata, chipIndex));
LOG(logDEBUG2, ("Send data (0x%x) to ichip %d\n", codata, chipIndex));
LTC2620_SendDaisyData(&valw, codata);
// send nothing to preceding ichips (daisy chain) (if any chips in front of desired chip)
for (ichip = 0; ichip < chipIndex; ++ichip) {
FILE_LOG(logDEBUG2, ("Send nothing to ichip %d\n", ichip));
LOG(logDEBUG2, ("Send nothing to ichip %d\n", ichip));
LTC2620_SendDaisyData(&valw, LTC2620_DAC_CMD_NO_OPRTN_VAL);
}
}
// deselect all chips (ctb daisy chain; others 1 chip)
FILE_LOG(logDEBUG2, ("Deselecting LTC2620\n"));
LOG(logDEBUG2, ("Deselecting LTC2620\n"));
SPIChipDeselect(&valw, LTC2620_Reg, LTC2620_CsMask, LTC2620_ClkMask, LTC2620_DigMask, 0);
}
void LTC2620_Set(int cmd, int data, int dacaddr, int chipIndex) {
FILE_LOG(logDEBUG1, ("cmd:0x%x, data:%d, dacaddr:%d, chipIndex:%d\n", cmd, data, dacaddr, chipIndex));
FILE_LOG(logDEBUG2, (" ================================================\n"));
LOG(logDEBUG1, ("cmd:0x%x, data:%d, dacaddr:%d, chipIndex:%d\n", cmd, data, dacaddr, chipIndex));
LOG(logDEBUG2, (" ================================================\n"));
// ctb
if (LTC2620_Ndac > LTC2620_NUMCHANNELS)
LTC2620_SetDaisy(cmd, data, dacaddr, chipIndex);
// others
else
LTC2620_SetSingle(cmd, data, dacaddr);
FILE_LOG(logDEBUG2, (" ================================================\n"));
LOG(logDEBUG2, (" ================================================\n"));
}
void LTC2620_Configure(){
FILE_LOG(logINFOBLUE, ("Configuring LTC2620\n"));
LOG(logINFOBLUE, ("Configuring LTC2620\n"));
// dac channel - all channels
int addr = (LTC2620_DAC_ADDR_MSK >> LTC2620_DAC_ADDR_OFST);
@ -189,7 +189,7 @@ void LTC2620_Configure(){
}
void LTC2620_SetDAC (int dacnum, int data) {
FILE_LOG(logDEBUG1, ("Setting dac %d to %d\n", dacnum, data));
LOG(logDEBUG1, ("Setting dac %d to %d\n", dacnum, data));
// LTC2620 index
int ichip = dacnum / LTC2620_NUMCHANNELS;
@ -202,19 +202,19 @@ void LTC2620_SetDAC (int dacnum, int data) {
// power down mode, value is ignored
if (data == LTC2620_PWR_DOWN_VAL) {
cmd = LTC2620_DAC_CMD_PWR_DWN_VAL;
FILE_LOG(logDEBUG1, ("POWER DOWN\n"));
LOG(logDEBUG1, ("POWER DOWN\n"));
} else {
FILE_LOG(logDEBUG1,("Write to Input Register and Update\n"));
LOG(logDEBUG1,("Write to Input Register and Update\n"));
}
LTC2620_Set(cmd, data, addr, ichip);
}
int LTC2620_SetDACValue (int dacnum, int val, int mV, int* dacval) {
FILE_LOG(logDEBUG1, ("dacnum:%d, val:%d, ismV:%d\n", dacnum, val, mV));
LOG(logDEBUG1, ("dacnum:%d, val:%d, ismV:%d\n", dacnum, val, mV));
// validate index
if (dacnum < 0 || dacnum >= LTC2620_Ndac) {
FILE_LOG(logERROR, ("Dac index %d is out of bounds (0 to %d)\n", dacnum, LTC2620_Ndac - 1));
LOG(logERROR, ("Dac index %d is out of bounds (0 to %d)\n", dacnum, LTC2620_Ndac - 1));
return FAIL;
}
@ -240,13 +240,13 @@ int LTC2620_SetDACValue (int dacnum, int val, int mV, int* dacval) {
// conversion out of bounds
if (ret == FAIL) {
FILE_LOG(logERROR, ("Setting Dac %d %s is out of bounds\n", dacnum, (mV ? "mV" : "dac units")));
LOG(logERROR, ("Setting Dac %d %s is out of bounds\n", dacnum, (mV ? "mV" : "dac units")));
return FAIL;
}
// set
if ( (*dacval >= 0) || (*dacval == LTC2620_PWR_DOWN_VAL)) {
FILE_LOG(logINFO, ("Setting DAC %d: %d dac (%d mV)\n",dacnum, *dacval, dacmV));
LOG(logINFO, ("Setting DAC %d: %d dac (%d mV)\n",dacnum, *dacval, dacmV));
LTC2620_SetDAC(dacnum, *dacval);
}
return OK;

View File

@ -17,7 +17,7 @@ char LTC2620_D_DriverFileName[MAX_STR_LENGTH];
int LTC2620_D_NumDacs = 0;
void LTC2620_D_SetDefines(int hardMaxV, char* driverfname, int numdacs) {
FILE_LOG(logINFOBLUE, ("Configuring DACs (LTC2620) to %s (numdacs:%d, hard max: %dmV)\n", driverfname, numdacs, hardMaxV));
LOG(logINFOBLUE, ("Configuring DACs (LTC2620) to %s (numdacs:%d, hard max: %dmV)\n", driverfname, numdacs, hardMaxV));
LTC2620_D_HardMaxVoltage = hardMaxV;
memset(LTC2620_D_DriverFileName, 0, MAX_STR_LENGTH);
strcpy(LTC2620_D_DriverFileName, driverfname);
@ -40,10 +40,10 @@ int LTC2620_D_DacToVoltage(int dacval, int* voltage) {
int LTC2620_D_SetDACValue (int dacnum, int val, int mV, char* dacname, int* dacval) {
FILE_LOG(logDEBUG1, ("dacnum:%d, val:%d, ismV:%d\n", dacnum, val, mV));
LOG(logDEBUG1, ("dacnum:%d, val:%d, ismV:%d\n", dacnum, val, mV));
// validate index
if (dacnum < 0 || dacnum >= LTC2620_D_NumDacs) {
FILE_LOG(logERROR, ("Dac index %d is out of bounds (0 to %d)\n", dacnum, LTC2620_D_NumDacs - 1));
LOG(logERROR, ("Dac index %d is out of bounds (0 to %d)\n", dacnum, LTC2620_D_NumDacs - 1));
return FAIL;
}
@ -64,22 +64,22 @@ int LTC2620_D_SetDACValue (int dacnum, int val, int mV, char* dacname, int* dacv
// conversion out of bounds
if (ret == FAIL) {
FILE_LOG(logERROR, ("Setting Dac %d %s is out of bounds\n", dacnum, (mV ? "mV" : "dac units")));
LOG(logERROR, ("Setting Dac %d %s is out of bounds\n", dacnum, (mV ? "mV" : "dac units")));
return FAIL;
}
// set
if ( (*dacval >= 0) || (*dacval == LTC2620_D_PWR_DOWN_VAL)) {
FILE_LOG(logINFO, ("Setting DAC %2d [%-12s] : %d dac (%d mV)\n",dacnum, dacname, *dacval, dacmV));
LOG(logINFO, ("Setting DAC %2d [%-12s] : %d dac (%d mV)\n",dacnum, dacname, *dacval, dacmV));
char fname[MAX_STR_LENGTH];
sprintf(fname, "%s%d", LTC2620_D_DriverFileName, dacnum);
FILE_LOG(logDEBUG1, ("fname %s\n",fname));
LOG(logDEBUG1, ("fname %s\n",fname));
//open file
FILE* fd=fopen(fname,"w");
if (fd==NULL) {
FILE_LOG(logERROR, ("Could not open file %s for writing to set dac %d\n", fname, dacnum));
LOG(logERROR, ("Could not open file %s for writing to set dac %d\n", fname, dacnum));
return FAIL;
}
//convert to string, add 0 and write to file

View File

@ -26,7 +26,7 @@ int MAX1932_MaxVoltage = 0;
void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst,
int minMV, int maxMV) {
FILE_LOG(logINFOBLUE, ("Configuring High Voltage\n"));
LOG(logINFOBLUE, ("Configuring High Voltage\n"));
MAX1932_Reg = reg;
MAX1932_CsMask = cmsk;
MAX1932_ClkMask = clkmsk;
@ -44,7 +44,7 @@ void MAX1932_Disable() {
}
int MAX1932_Set (int val) {
FILE_LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
if (val < 0)
return FAIL;
@ -69,7 +69,7 @@ int MAX1932_Set (int val) {
dacvalue &= MAX1932_HV_DATA_MSK;
}
FILE_LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
serializeToSPI(MAX1932_Reg, dacvalue, MAX1932_CsMask, MAX1932_HV_NUMBITS,
MAX1932_ClkMask, MAX1932_DigMask, MAX1932_DigOffset, 0);
return OK;

View File

@ -54,7 +54,7 @@ void createUDPPacketHeader(char* buffer, uint16_t id) {
}
int fillUDPPacket(char* buffer) {
FILE_LOG(logDEBUG2, ("Analog (databytes:%d, offset:%d)\n Digital (databytes:%d offset:%d)\n",
LOG(logDEBUG2, ("Analog (databytes:%d, offset:%d)\n Digital (databytes:%d offset:%d)\n",
analogDataBytes, analogOffset, digitalDataBytes, digitalOffset));
// reached end of data for one frame
if (analogOffset >= analogDataBytes && digitalOffset >= digitalDataBytes) {
@ -76,7 +76,7 @@ int fillUDPPacket(char* buffer) {
// increment and copy udp packet number (starts at 0)
++udpPacketNumber;
header->packetNumber = udpPacketNumber;
FILE_LOG(logDEBUG2, ("Creating packet number %d (fnum:%lld)\n", udpPacketNumber, (long long int) udpFrameNumber));
LOG(logDEBUG2, ("Creating packet number %d (fnum:%lld)\n", udpPacketNumber, (long long int) udpFrameNumber));
int freeBytes = UDP_PACKET_DATA_BYTES;
@ -111,7 +111,7 @@ int fillUDPPacket(char* buffer) {
// pad data
if (freeBytes) {
memset(buffer + sizeof(sls_detector_header) + analogBytes + digitalBytes, 0, freeBytes);
FILE_LOG(logDEBUG1, ("Padding %d bytes for fnum:%lld pnum:%d\n", freeBytes, (long long int)udpFrameNumber, udpPacketNumber));
LOG(logDEBUG1, ("Padding %d bytes for fnum:%lld pnum:%d\n", freeBytes, (long long int)udpFrameNumber, udpPacketNumber));
}
return UDP_PACKET_DATA_BYTES + sizeof(sls_detector_header);

View File

@ -44,7 +44,7 @@ int64_t get64BitReg(int aLSB, int aMSB){
vMSB=bus_r(aMSB);
v64=vMSB;
v64=(v64<<32) | vLSB;
FILE_LOG(logDEBUG5, (" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64));
LOG(logDEBUG5, (" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64));
return v64;
}
@ -94,33 +94,33 @@ u_int32_t writeRegister16(u_int32_t offset, u_int32_t data) {
int mapCSP0(void) {
// if not mapped
if (csp0base == 0) {
FILE_LOG(logINFO, ("Mapping memory\n"));
LOG(logINFO, ("Mapping memory\n"));
#ifdef VIRTUAL
csp0base = malloc(MEM_SIZE);
if (csp0base == NULL) {
FILE_LOG(logERROR, ("Could not allocate virtual memory.\n"));
LOG(logERROR, ("Could not allocate virtual memory.\n"));
return FAIL;
}
FILE_LOG(logINFO, ("memory allocated\n"));
LOG(logINFO, ("memory allocated\n"));
#else
int fd;
fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
if (fd == -1) {
FILE_LOG(logERROR, ("Can't find /dev/mem\n"));
LOG(logERROR, ("Can't find /dev/mem\n"));
return FAIL;
}
FILE_LOG(logDEBUG1, ("/dev/mem opened\n"));
LOG(logDEBUG1, ("/dev/mem opened\n"));
csp0base = mmap(0, MEM_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, CSP0);
if (csp0base == MAP_FAILED) {
FILE_LOG(logERROR, ("Can't map memmory area\n"));
LOG(logERROR, ("Can't map memmory area\n"));
return FAIL;
}
#endif
FILE_LOG(logINFO, ("csp0base mapped from %p to %p\n",
LOG(logINFO, ("csp0base mapped from %p to %p\n",
csp0base, (csp0base + MEM_SIZE)));
FILE_LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
}else
FILE_LOG(logINFO, ("Memory already mapped before\n"));
LOG(logINFO, ("Memory already mapped before\n"));
return OK;
}

Some files were not shown because too many files have changed in this diff Show More