Skip to content
Snippets Groups Projects
Commit 344afeb0 authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

removed all uses of the ProcessScalar class and replaced it with the...

removed all uses of the ProcessScalar class and replaced it with the ProcessArray (ProcessScalar will be removed from the CSA soon)
parent 1d188c22
No related branches found
No related tags found
No related merge requests found
......@@ -26,11 +26,9 @@ namespace ChimeraTK {
EqFct * _eqFct; //< The EqFct which is holding the factory. Needed in the constructor of the doocs properties.
boost::shared_ptr<ControlSystemSynchronizationUtility> _syncUtility; //< The syncUtility is needed to register listeners
// create the DOOCS property. Note: DOOCS_T and DOOCS_VALUE_T are only used for scalar properties, not for arrays!
template<class T, class DOOCS_T, class DOOCS_VALUE_T>
typename boost::shared_ptr<D_fct> createDoocsScalar(typename ProcessVariable::SharedPtr & processVariable);
template<class T>
typename boost::shared_ptr<D_fct> createDoocsArray(typename ProcessVariable::SharedPtr & processVariable);
typename boost::shared_ptr<D_fct> createDoocsProperty(typename ProcessVariable::SharedPtr & processVariable);
};
......
......@@ -41,19 +41,19 @@ protected:
*/
void notify(boost::shared_ptr< ProcessVariable > processVariable){
// It is safe to static cast because the DoocsScalarListener is inside a
// DoocsProcessScalar, which always holds a ProcessScalar, never a ProcessArray
_doocsVariable->set_value( static_cast< ProcessScalar<T> & >(*processVariable) );
// DoocsProcessScalar, which always holds the right type
_doocsVariable->set_value( (static_cast< ProcessArray<T> & >(*processVariable)).accessData(0) );
}
private:
DOOCS_T * _doocsVariable;
};
boost::shared_ptr< ProcessScalar<T> > _processScalar;
boost::shared_ptr< ProcessArray<T> > _processScalar;
public:
DoocsProcessScalar( EqFct * const eqFct,
boost::shared_ptr< typename ChimeraTK::ProcessScalar<T> > const & processScalar,
boost::shared_ptr< typename ChimeraTK::ProcessArray<T> > const & processScalar,
ControlSystemSynchronizationUtility & syncUtility)
: DOOCS_T( splitStringAtFirstSlash(processScalar->getName()).second.c_str(), eqFct),
_processScalar(processScalar) {
......@@ -79,7 +79,7 @@ public:
*/
void set_value(DOOCS_VALUE_T t){
DOOCS_T::set_value(t);
*_processScalar = t;
_processScalar->accessData(0) = t;
if (_processScalar->isWriteable()){
_processScalar->write();
}
......
......@@ -5,6 +5,10 @@ namespace ChimeraTK{
inline std::pair< std::string, std::string > splitStringAtFirstSlash(std::string input){
auto slashPosition = input.find_first_of("/");
if(slashPosition == 0) { // ignore leading slash
input = input.substr(1);
slashPosition = input.find_first_of("/");
}
if (slashPosition == std::string::npos){
return std::make_pair( std::string(), input);
}
......
......@@ -14,25 +14,8 @@ namespace ChimeraTK {
}
template<class T, class DOOCS_T, class DOOCS_VALUE_T>
typename boost::shared_ptr<D_fct> DoocsPVFactory::createDoocsScalar(
typename ProcessVariable::SharedPtr & processVariable){
// the DoocsProcessScalar needs the real ProcessScalar type,
// not just ProcessVariable
typename ProcessScalar<T>::SharedPtr processScalar
= boost::dynamic_pointer_cast< ProcessScalar<T> >(processVariable);
if (!processScalar){
throw std::invalid_argument(std::string("DoocsPVFactory::createDoocsScalar : processScalar is of the wrong type ")
+ processVariable->getValueType().name());
}
return boost::shared_ptr<D_fct>( new DoocsProcessScalar<T, DOOCS_T, DOOCS_VALUE_T>(_eqFct, processScalar, *_syncUtility) );
}
template<class T>
typename boost::shared_ptr<D_fct> DoocsPVFactory::createDoocsArray(
typename ProcessVariable::SharedPtr & processVariable){
// the DoocsProcessArray needs the real ProcessScalar type,
// not just ProcessVariable
typename boost::shared_ptr<D_fct> DoocsPVFactory::createDoocsProperty(typename ProcessVariable::SharedPtr & processVariable) {
// the DoocsProcessArray needs the real ProcessScalar type, not just ProcessVariable
typename ProcessArray<T>::SharedPtr processArray
= boost::dynamic_pointer_cast< ProcessArray<T> >(processVariable);
if (!processArray){
......@@ -40,60 +23,43 @@ namespace ChimeraTK {
+ processVariable->getValueType().name());
}
return boost::shared_ptr<D_fct>(
new DoocsProcessArray<T>(_eqFct, processArray, *_syncUtility) );
assert(processArray->getNumberOfChannels() == 1);
if(processArray->getNumberOfSamples() > 1 ) {
return boost::shared_ptr<D_fct>( new DoocsProcessArray<T>(_eqFct, processArray, *_syncUtility) );
}
else {
return boost::shared_ptr<D_fct>( new DoocsProcessScalar<T, DOOCS_T, DOOCS_VALUE_T>(_eqFct, processArray, *_syncUtility) );
}
}
boost::shared_ptr<D_fct> DoocsPVFactory::create( ProcessVariable::SharedPtr & processVariable ){
std::type_info const & valueType = processVariable->getValueType();
if( processVariable->isArray() ){
// it's an array, call the createDoocsArray method
// Unfortunately we need a big if/else block to hard-code the template
// parameter. The value type in only known at run time,
// but the template parameter has to be known at compile time.
if (valueType == typeid(int8_t)) {
return createDoocsArray<int8_t>(processVariable);
} else if (valueType == typeid(uint8_t)) {
return createDoocsArray<uint8_t>(processVariable);
} else if (valueType == typeid(int16_t)) {
return createDoocsArray<int16_t>(processVariable);
} else if (valueType == typeid(uint16_t)) {
return createDoocsArray<uint16_t>(processVariable);
} else if (valueType == typeid(int32_t)) {
return createDoocsArray<int32_t>(processVariable);
} else if (valueType == typeid(uint32_t)) {
return createDoocsArray<uint32_t>(processVariable);
} else if (valueType == typeid(float)) {
return createDoocsArray<float>(processVariable);
} else if (valueType == typeid(double)) {
return createDoocsArray<double>(processVariable);
} else {
throw std::invalid_argument("unsupported value type");
}
// Unfortunately we need a big if/else block to hard-code the template
// parameter. The value type in only known at run time,
// but the template parameter has to be known at compile time.
if (valueType == typeid(int8_t)) {
return createDoocsProperty<int8_t, D_int, int>(processVariable);
} else if (valueType == typeid(uint8_t)) {
return createDoocsProperty<uint8_t, D_int, int>(processVariable);
} else if (valueType == typeid(int16_t)) {
return createDoocsProperty<int16_t, D_int, int>(processVariable);
} else if (valueType == typeid(uint16_t)) {
return createDoocsProperty<uint16_t, D_int, int>(processVariable);
} else if (valueType == typeid(int32_t)) {
return createDoocsProperty<int32_t, D_int, int>(processVariable);
} else if (valueType == typeid(uint32_t)) {
return createDoocsProperty<uint32_t, D_int, int>(processVariable);
} else if (valueType == typeid(float)) {
return createDoocsProperty<float, D_float, float>(processVariable);
} else if (valueType == typeid(double)) {
return createDoocsProperty<double, D_double, double>(processVariable);
} else {
throw std::invalid_argument("unsupported value type");
}
else{ // it's a scalar, call the createScalar method
if (valueType == typeid(int8_t)) {
return createDoocsScalar<int8_t, D_int, int>(processVariable);
} else if (valueType == typeid(uint8_t)) {
return createDoocsScalar<uint8_t, D_int, int>(processVariable);
} else if (valueType == typeid(int16_t)) {
return createDoocsScalar<int16_t, D_int, int>(processVariable);
} else if (valueType == typeid(uint16_t)) {
return createDoocsScalar<uint16_t, D_int, int>(processVariable);
} else if (valueType == typeid(int32_t)) {
return createDoocsScalar<int32_t, D_int, int>(processVariable);
} else if (valueType == typeid(uint32_t)) {
return createDoocsScalar<uint32_t, D_int, int>(processVariable);
} else if (valueType == typeid(float)) {
return createDoocsScalar<float, D_float, float>(processVariable);
} else if (valueType == typeid(double)) {
return createDoocsScalar<double, D_double, double>(processVariable);
} else {
throw std::invalid_argument("unsupported value type");
}
}// else isArray
}
}
}// namespace
......@@ -8,7 +8,7 @@
#include "DoocsAdapter.h"
#include <ChimeraTK/ControlSystemAdapter/DevicePVManager.h>
#include <ChimeraTK/ControlSystemAdapter/ProcessScalar.h>
#include <ChimeraTK/ControlSystemAdapter/ProcessArray.h>
#include <ChimeraTK/ControlSystemAdapter/SynchronizationDirection.h>
using namespace boost::unit_test_framework;
......@@ -28,14 +28,14 @@ public:
};
struct BusinessLogic{
ProcessScalar<int>::SharedPtr toDeviceInt;
ProcessScalar<int>::SharedPtr fromDeviceInt;
ProcessArray<int>::SharedPtr toDeviceInt;
ProcessArray<int>::SharedPtr fromDeviceInt;
BusinessLogic(boost::shared_ptr<ChimeraTK::DevicePVManager> const & pvManager)
: toDeviceInt(pvManager->createProcessScalar<int>(
controlSystemToDevice, "TO_DEVICE_INT") ),
fromDeviceInt(pvManager->createProcessScalar<int>(
deviceToControlSystem, "FROM_DEVICE_INT") ){
: toDeviceInt(pvManager->createProcessArray<int>(
controlSystemToDevice, "TO_DEVICE_INT",1) ),
fromDeviceInt(pvManager->createProcessArray<int>(
deviceToControlSystem, "FROM_DEVICE_INT",1) ){
}
};
......@@ -74,19 +74,19 @@ BOOST_AUTO_TEST_CASE( testCSAdapterEqFct ) {
// write once and check
doocsProperties["TO_DEVICE_INT "]->set_value(13);
businessLogic.toDeviceInt->readNonBlocking();
BOOST_CHECK( *(businessLogic.toDeviceInt) == 13 );
BOOST_CHECK( businessLogic.toDeviceInt->accessData(0) == 13 );
// change and observe the change in the device
doocsProperties["TO_DEVICE_INT "]->set_value(14);
businessLogic.toDeviceInt->readNonBlocking();
BOOST_CHECK( *(businessLogic.toDeviceInt) == 14 );
BOOST_CHECK( businessLogic.toDeviceInt->accessData(0) == 14 );
// and the other direction
*(businessLogic.fromDeviceInt) = 12;
businessLogic.fromDeviceInt->accessData(0) = 12;
businessLogic.fromDeviceInt->write();
eqFct.update();
BOOST_CHECK( doocsProperties["FROM_DEVICE_INT "]->value() == 12);
*(businessLogic.fromDeviceInt) = 15;
businessLogic.fromDeviceInt->accessData(0) = 15;
businessLogic.fromDeviceInt->write();
eqFct.update();
BOOST_CHECK( doocsProperties["FROM_DEVICE_INT "]->value() == 15);
......
......@@ -38,12 +38,12 @@ public:
template<class T, class DOOCS_T, class DOOCS_VALUE_T>
typename boost::shared_ptr<D_fct> createDoocsScalar(typename ProcessVariable::SharedPtr & processVariable){
return DoocsPVFactory::createDoocsScalar<T, DOOCS_T, DOOCS_VALUE_T>(processVariable);
return DoocsPVFactory::createDoocsProperty<T, DOOCS_T, DOOCS_VALUE_T>(processVariable);
}
template<class T>
template<class T, class DOOCS_T, class DOOCS_VALUE_T>
typename boost::shared_ptr<D_fct> createDoocsArray(typename ProcessVariable::SharedPtr & processVariable){
return DoocsPVFactory::createDoocsArray<T>(processVariable);
return DoocsPVFactory::createDoocsProperty<T, DOOCS_T, DOOCS_VALUE_T>(processVariable);
}
};
......@@ -70,14 +70,14 @@ BOOST_AUTO_TEST_CASE( testCreateScalars ) {
shared_ptr<DevicePVManager> devManager = pvManagers.second;
// create all process variables before creating the sync util
devManager->createProcessScalar<int32_t>(controlSystemToDevice,"int32");
devManager->createProcessScalar<uint32_t>(controlSystemToDevice,"uint32");
devManager->createProcessScalar<int16_t>(controlSystemToDevice,"int16");
devManager->createProcessScalar<uint16_t>(controlSystemToDevice,"uint16");
devManager->createProcessScalar<int8_t>(controlSystemToDevice,"int8");
devManager->createProcessScalar<uint8_t>(controlSystemToDevice,"uint8");
devManager->createProcessScalar<float>(controlSystemToDevice,"float");
devManager->createProcessScalar<double>(controlSystemToDevice,"double");
devManager->createProcessArray<int32_t>(controlSystemToDevice,"int32",1);
devManager->createProcessArray<uint32_t>(controlSystemToDevice,"uint32",1);
devManager->createProcessArray<int16_t>(controlSystemToDevice,"int16",1);
devManager->createProcessArray<uint16_t>(controlSystemToDevice,"uint16",1);
devManager->createProcessArray<int8_t>(controlSystemToDevice,"int8",1);
devManager->createProcessArray<uint8_t>(controlSystemToDevice,"uint8",1);
devManager->createProcessArray<float>(controlSystemToDevice,"float",1);
devManager->createProcessArray<double>(controlSystemToDevice,"double",1);
shared_ptr<ControlSystemSynchronizationUtility> syncUtil(
new ControlSystemSynchronizationUtility(csManager));
......@@ -87,35 +87,35 @@ BOOST_AUTO_TEST_CASE( testCreateScalars ) {
// We insert check points with integers so we know where the algorithm kicks out in case of an error.
// These checkpoints are always true.
testCreateProcessScalar<int32_t, D_int, int>(
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessScalar<int32_t>("int32")),
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessArray<int32_t>("int32")),
factory);
BOOST_CHECK(-32);
testCreateProcessScalar<uint32_t, D_int, int>(
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessScalar<uint32_t>("uint32")),
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessArray<uint32_t>("uint32")),
factory);
BOOST_CHECK(32);
testCreateProcessScalar<int16_t, D_int, int>(
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessScalar<int16_t>("int16")),
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessArray<int16_t>("int16")),
factory);
BOOST_CHECK(-16);
testCreateProcessScalar<uint16_t, D_int, int>(
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessScalar<uint16_t>("uint16")),
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessArray<uint16_t>("uint16")),
factory);
BOOST_CHECK(16);
testCreateProcessScalar<int8_t, D_int, int>(
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessScalar<int8_t>("int8")),
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessArray<int8_t>("int8")),
factory);
BOOST_CHECK(-8);
testCreateProcessScalar<uint8_t, D_int, int>(
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessScalar<uint8_t>("uint8")),
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessArray<uint8_t>("uint8")),
factory);
BOOST_CHECK(8);
testCreateProcessScalar<float, D_float, float>(
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessScalar<float>("float")),
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessArray<float>("float")),
factory);
BOOST_CHECK(0.5);
testCreateProcessScalar<double, D_double, double>(
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessScalar<double>("double")),
boost::dynamic_pointer_cast<ProcessVariable>(csManager->getProcessArray<double>("double")),
factory);
}
......@@ -156,14 +156,14 @@ BOOST_AUTO_TEST_CASE( testErrorHandling ){
static const size_t arraySize = 10;
// int64 is not supported yet
devManager->createProcessArray<int64_t>(controlSystemToDevice,"toDeviceArray",arraySize);
devManager->createProcessScalar<int64_t>(controlSystemToDevice,"toDeviceInt");
devManager->createProcessArray<int64_t>(controlSystemToDevice,"toDeviceInt",1);
shared_ptr<ControlSystemSynchronizationUtility> syncUtil(
new ControlSystemSynchronizationUtility(csManager));
TestableDoocsPVFactory testableFactory(NULL /*eqFct*/, syncUtil);
ProcessVariable::SharedPtr processScalar =
csManager->getProcessScalar<int64_t>("toDeviceInt");
csManager->getProcessArray<int64_t>("toDeviceInt");
// Intentionally put the int64 scalar to the int32 create function.
// Unfortunately BOOST_CHECK cannot deal with multiple template parameters,
// so we have to trick it
......@@ -176,8 +176,8 @@ BOOST_AUTO_TEST_CASE( testErrorHandling ){
}
// now the same with arrays
ProcessVariable::SharedPtr processArray = csManager->getProcessArray<int64_t>("toDeviceArray");
BOOST_CHECK_THROW( testableFactory.createDoocsArray<int32_t>(processArray),
ProcessVariable::SharedPtr processArray = csManager->getProcessArray<int64_t>("toDeviceArray");
BOOST_CHECK_THROW( ( testableFactory.createDoocsArray<int32_t, D_int, int>(processArray) ),
std::invalid_argument );
// finally we check that the create method catches the not-supported type.
......
......@@ -30,34 +30,34 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( toDeviceIntegerTypeTest, T, integer_test_types ){
ControlSystemSynchronizationUtility syncUtil(csManager);
boost::shared_ptr< ProcessScalar< T> > deviceVariable =
devManager->createProcessScalar<T>(controlSystemToDevice,"toDeviceVariable");
boost::shared_ptr< ProcessScalar<T> > controlSystemVariable =
csManager->getProcessScalar<T>("toDeviceVariable");
boost::shared_ptr< ProcessArray<T> > deviceVariable =
devManager->createProcessArray<T>(controlSystemToDevice,"toDeviceVariable", 1);
boost::shared_ptr< ProcessArray<T> > controlSystemVariable =
csManager->getProcessArray<T>("toDeviceVariable");
// set the variables to 0
*deviceVariable=0;
*controlSystemVariable=0;
deviceVariable->accessData(0)=0;
controlSystemVariable->accessData(0)=0;
// just write to the doocs scalar, it is automatically sending
DoocsProcessScalar<T, D_int, int> doocsScalar( NULL, controlSystemVariable, syncUtil );
doocsScalar=42;
BOOST_CHECK( *controlSystemVariable == 42 );
BOOST_CHECK( controlSystemVariable->accessData(0) == 42 );
// receive on the device side and check that the value has arrived
deviceVariable->readNonBlocking();
BOOST_CHECK( *deviceVariable == 42 );
BOOST_CHECK( deviceVariable->accessData(0) == 42 );
// check with negative values, and cast so unsigned gets correct results
// check that the set_value overloading is working by calling the function of the base class
// (note: cast to a reference, otherwise inheritance/ virtual functions calls do not work)
static_cast<D_int&>(doocsScalar).set_value(-13);
BOOST_CHECK( *controlSystemVariable == static_cast<T>(-13) );
BOOST_CHECK( controlSystemVariable->accessData(0) == static_cast<T>(-13) );
// receive on the device side and check that the value has arrived
deviceVariable->readNonBlocking();
BOOST_CHECK( *deviceVariable == static_cast<T>(-13) );
BOOST_CHECK( deviceVariable->accessData(0) == static_cast<T>(-13) );
}
// as boost testing does not allow multiple template parameters we use code
......@@ -71,32 +71,32 @@ BOOST_AUTO_TEST_CASE(toDeviceFloatTest){
ControlSystemSynchronizationUtility syncUtil(csManager);
boost::shared_ptr< ProcessScalar<float> > deviceFloat =
devManager->createProcessScalar<float>(controlSystemToDevice,"toDeviceFloat");
boost::shared_ptr< ProcessScalar<float> > controlSystemFloat =
csManager->getProcessScalar<float>("toDeviceFloat");
boost::shared_ptr< ProcessArray<float> > deviceFloat =
devManager->createProcessArray<float>(controlSystemToDevice,"toDeviceFloat",1);
boost::shared_ptr< ProcessArray<float> > controlSystemFloat =
csManager->getProcessArray<float>("toDeviceFloat");
// set the variables to 0
*deviceFloat=0;
*controlSystemFloat=0;
deviceFloat->accessData(0)=0;
controlSystemFloat->accessData(0)=0;
// just write to the doocs scalar, it is automatically sending
DoocsProcessScalar<float, D_float, float> doocsScalar( NULL, controlSystemFloat, syncUtil );
doocsScalar=12.125;
BOOST_CHECK( *controlSystemFloat == 12.125 );
BOOST_CHECK( controlSystemFloat->accessData(0) == 12.125 );
// receive on the device side and check that the value has arrived
deviceFloat->readNonBlocking();
BOOST_CHECK( *deviceFloat == 12.125 );
BOOST_CHECK( deviceFloat->accessData(0) == 12.125 );
// check that the set_value overloading is working by calling the function of the base class
// (note: cast to a reference, otherwise inheritance/ virtual functions calls do not work)
static_cast<D_float&>(doocsScalar).set_value(-13.);
BOOST_CHECK( *controlSystemFloat == -13. );
BOOST_CHECK( controlSystemFloat->accessData(0) == -13. );
// receive on the device side and check that the value has arrived
deviceFloat->readNonBlocking();
BOOST_CHECK( *deviceFloat == -13. );
BOOST_CHECK( deviceFloat->accessData(0) == -13. );
}
BOOST_AUTO_TEST_CASE(toDeviceDoubleTest){
......@@ -107,32 +107,32 @@ BOOST_AUTO_TEST_CASE(toDeviceDoubleTest){
ControlSystemSynchronizationUtility syncUtil(csManager);
boost::shared_ptr< ProcessScalar<double> > deviceDouble =
devManager->createProcessScalar<double>(controlSystemToDevice,"toDeviceDouble");
boost::shared_ptr< ProcessScalar<double> > controlSystemDouble =
csManager->getProcessScalar<double>("toDeviceDouble");
boost::shared_ptr< ProcessArray<double> > deviceDouble =
devManager->createProcessArray<double>(controlSystemToDevice,"toDeviceDouble",1);
boost::shared_ptr< ProcessArray<double> > controlSystemDouble =
csManager->getProcessArray<double>("toDeviceDouble");
// set the variables to 0
*deviceDouble=0;
*controlSystemDouble=0;
deviceDouble->accessData(0)=0;
controlSystemDouble->accessData(0)=0;
// just write to the doocs scalar, it is automatically sending
DoocsProcessScalar<double, D_double, double> doocsScalar( NULL, controlSystemDouble, syncUtil );
doocsScalar=12.125;
BOOST_CHECK( *controlSystemDouble == 12.125 );
BOOST_CHECK( controlSystemDouble->accessData(0) == 12.125 );
// receive on the device side and check that the value has arrived
deviceDouble->readNonBlocking();
BOOST_CHECK( *deviceDouble == 12.125 );
BOOST_CHECK( deviceDouble->accessData(0) == 12.125 );
// check that the set_value overloading is working by calling the function of the base class
// (note: cast to a reference, otherwise inheritance/ virtual functions calls do not work)
static_cast<D_double&>(doocsScalar).set_value(-13.);
BOOST_CHECK( *controlSystemDouble == -13. );
BOOST_CHECK( controlSystemDouble->accessData(0) == -13. );
// receive on the device side and check that the value has arrived
deviceDouble->readNonBlocking();
BOOST_CHECK( *deviceDouble == -13. );
BOOST_CHECK( deviceDouble->accessData(0) == -13. );
}
BOOST_AUTO_TEST_CASE_TEMPLATE( fromDeviceIntegerTypeTest, T, integer_test_types ){
......@@ -143,30 +143,30 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fromDeviceIntegerTypeTest, T, integer_test_types
ControlSystemSynchronizationUtility syncUtil(csManager);
typename ProcessScalar<T>::SharedPtr deviceVariable =
devManager->createProcessScalar<T>(deviceToControlSystem,"fromDeviceVariable");
typename ProcessScalar<T>::SharedPtr controlSystemVariable =
csManager->getProcessScalar<T>("fromDeviceVariable");
typename ProcessArray<T>::SharedPtr deviceVariable =
devManager->createProcessArray<T>(deviceToControlSystem,"fromDeviceVariable",1);
typename ProcessArray<T>::SharedPtr controlSystemVariable =
csManager->getProcessArray<T>("fromDeviceVariable");
// set the variables to 0
*deviceVariable=0;
*controlSystemVariable=0;
deviceVariable->accessData(0)=0;
controlSystemVariable->accessData(0)=0;
// initialise the doocs scalar
DoocsProcessScalar<T, D_int, int> doocsScalar( NULL, controlSystemVariable, syncUtil );
doocsScalar=0;
*deviceVariable=42;
deviceVariable->accessData(0)=42;
deviceVariable->write();
BOOST_CHECK( *controlSystemVariable == 0 );
BOOST_CHECK( controlSystemVariable->accessData(0) == 0 );
BOOST_CHECK( doocsScalar.value() == 0 );
syncUtil.receiveAll();
BOOST_CHECK( *controlSystemVariable == 42 );
BOOST_CHECK( controlSystemVariable->accessData(0) == 42 );
BOOST_CHECK( doocsScalar.value() == 42 );
// negative test for signed int, with cast for uints
*deviceVariable=-13;
deviceVariable->accessData(0)=-13;
deviceVariable->write();
syncUtil.receiveAll();
BOOST_CHECK( doocsScalar.value() == static_cast<int>(static_cast<T>(-13)) );
......@@ -180,26 +180,26 @@ BOOST_AUTO_TEST_CASE( fromDeviceFloatTest ){
ControlSystemSynchronizationUtility syncUtil(csManager);
ProcessScalar<float>::SharedPtr deviceVariable =
devManager->createProcessScalar<float>(deviceToControlSystem,"fromDeviceVariable");
ProcessScalar<float>::SharedPtr controlSystemVariable =
csManager->getProcessScalar<float>("fromDeviceVariable");
ProcessArray<float>::SharedPtr deviceVariable =
devManager->createProcessArray<float>(deviceToControlSystem,"fromDeviceVariable",1);
ProcessArray<float>::SharedPtr controlSystemVariable =
csManager->getProcessArray<float>("fromDeviceVariable");
// set the variables to 0
*deviceVariable=0;
*controlSystemVariable=0;
deviceVariable->accessData(0)=0;
controlSystemVariable->accessData(0)=0;
// initialise the doocs scalar
DoocsProcessScalar<float, D_float, float> doocsScalar( NULL, controlSystemVariable, syncUtil );
doocsScalar=0;
*deviceVariable=12.125;
deviceVariable->accessData(0)=12.125;
deviceVariable->write();
BOOST_CHECK( *controlSystemVariable == 0 );
BOOST_CHECK( controlSystemVariable->accessData(0) == 0 );
BOOST_CHECK( doocsScalar.value() == 0 );
syncUtil.receiveAll();
BOOST_CHECK( *controlSystemVariable == 12.125 );
BOOST_CHECK( controlSystemVariable->accessData(0) == 12.125 );
BOOST_CHECK( doocsScalar.value() == 12.125 );
}
......@@ -211,26 +211,26 @@ BOOST_AUTO_TEST_CASE( fromDeviceDoubleTest ){
ControlSystemSynchronizationUtility syncUtil(csManager);
ProcessScalar<double>::SharedPtr deviceVariable =
devManager->createProcessScalar<double>(deviceToControlSystem,"fromDeviceVariable");
ProcessScalar<double>::SharedPtr controlSystemVariable =
csManager->getProcessScalar<double>("fromDeviceVariable");
ProcessArray<double>::SharedPtr deviceVariable =
devManager->createProcessArray<double>(deviceToControlSystem,"fromDeviceVariable",1);
ProcessArray<double>::SharedPtr controlSystemVariable =
csManager->getProcessArray<double>("fromDeviceVariable");
// set the variables to 0
*deviceVariable=0;
*controlSystemVariable=0;
deviceVariable->accessData(0)=0;
controlSystemVariable->accessData(0)=0;
// initialise the doocs scalar
DoocsProcessScalar<double, D_double, double> doocsScalar( NULL, controlSystemVariable, syncUtil );
doocsScalar=0;
*deviceVariable=12.125;
deviceVariable->accessData(0)=12.125;
deviceVariable->write();
BOOST_CHECK( *controlSystemVariable == 0 );
BOOST_CHECK( controlSystemVariable->accessData(0) == 0 );
BOOST_CHECK( doocsScalar.value() == 0 );
syncUtil.receiveAll();
BOOST_CHECK( *controlSystemVariable == 12.125 );
BOOST_CHECK( controlSystemVariable->accessData(0) == 12.125 );
BOOST_CHECK( doocsScalar.value() == 12.125 );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment