ChimeraTK-DeviceAccess  03.18.00
testGetSetAsCoocked.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 
4 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_MODULE GetSetAsCookedTest
6 #include <boost/test/unit_test.hpp>
7 using namespace boost::unit_test_framework;
8 
9 #include <Device.h>
10 using namespace ChimeraTK;
11 
12 BOOST_AUTO_TEST_CASE(testRawAccessor) {
13  setDMapFilePath("dummies.dmap");
14 
15  Device d;
16  d.open("DUMMYD3");
17 
18  auto scalarRawAccessor = d.getScalarRegisterAccessor<int32_t>("BOARD/WORD_USER", 0, {AccessMode::raw});
19  scalarRawAccessor = 25;
20  // the register has 3 fractional bits
21  BOOST_CHECK(std::fabs(scalarRawAccessor.getAsCooked<double>() - 25. / 8) < 0.0001);
22 
23  scalarRawAccessor.setAsCooked(31. / 8);
24  BOOST_CHECK_EQUAL(int32_t(scalarRawAccessor), 31);
25 
26  auto oneDRawAccessor = d.getOneDRegisterAccessor<int32_t>("ADC/AREA_DMAABLE_FIXEDPOINT16_3", 0, 0, {AccessMode::raw});
27 
28  oneDRawAccessor[0] = 12;
29  oneDRawAccessor[1] = 13;
30 
31  // the register has 3 fractional bits
32  BOOST_CHECK(std::fabs(oneDRawAccessor.getAsCooked<double>(0) - 12. / 8) < 0.0001);
33  BOOST_CHECK(std::fabs(oneDRawAccessor.getAsCooked<double>(1) - 13. / 8) < 0.0001);
34 
35  oneDRawAccessor.setAsCooked(0, 42. / 8);
36  oneDRawAccessor.setAsCooked(1, 43. / 8);
37 
38  BOOST_CHECK_EQUAL(oneDRawAccessor[0], 42);
39  BOOST_CHECK_EQUAL(oneDRawAccessor[1], 43);
40 }
ChimeraTK::Device::getOneDRegisterAccessor
OneDRegisterAccessor< UserType > getOneDRegisterAccessor(const RegisterPath &registerPathName, size_t numberOfWords=0, size_t wordOffsetInRegister=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a OneDRegisterAccessor object for the given register.
Definition: Device.h:273
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(testRawAccessor)
Definition: testGetSetAsCoocked.cpp:12
Device.h
ChimeraTK::Device
Class allows to read/write registers from device.
Definition: Device.h:39
ChimeraTK::Device::open
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition: Device.cc:58
ChimeraTK::Device::getScalarRegisterAccessor
ScalarRegisterAccessor< UserType > getScalarRegisterAccessor(const RegisterPath &registerPathName, size_t wordOffsetInRegister=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a ScalarRegisterObject object for the given register.
Definition: Device.h:263
ChimeraTK::setDMapFilePath
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.
Definition: Utilities.cpp:327
ChimeraTK
Definition: DummyBackend.h:16