diff --git a/.gitattributes b/.gitattributes index d7cbe7c00641d232fb14d520dde3fbc2077c20b4..358f518e6cad91139dae55bde90dc16e6a9107f7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1691,19 +1691,6 @@ LCS/Tools/src/countpurecodecomm -text LCS/Tools/src/fillreview -text LCS/Tools/src/makecov -text LCS/Tools/src/processgcov -text -LCS/WinCCWrapper/CMakeLists.txt -text -LCS/WinCCWrapper/doc/winccwrapper.md -text -LCS/WinCCWrapper/src/CMakeLists.txt -text -LCS/WinCCWrapper/src/ConnectWaitForAnswer.cc -text -LCS/WinCCWrapper/src/ConnectWaitForAnswer.h -text -LCS/WinCCWrapper/src/WinCCManager.cc -text -LCS/WinCCWrapper/src/WinCCResources.cc -text -LCS/WinCCWrapper/src/WinCCWrapper.cc -text -LCS/WinCCWrapper/src/WinCCWrapper_boost_python.cc -text -LCS/WinCCWrapper/src/__init__.py -text -LCS/WinCCWrapper/test/CMakeLists.txt -text -LCS/WinCCWrapper/test/WinCCGet.cc -text -LCS/WinCCWrapper/test/WinCCSet.cc -text LCS/doc/package.dox -text LCU/Firmware/images/ap3b_v6_2.hex -text LCU/Firmware/images/ap3b_v7_13.bit -text diff --git a/LCS/WinCCWrapper/CMakeLists.txt b/LCS/WinCCWrapper/CMakeLists.txt deleted file mode 100644 index 9c27cda941686b32cf500187319529c7cb17ac08..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Wrapper around WinCC API to read/write to datapoints from/to WinCC database, includes boost python bindings -lofar_package(WinCCWrapper 1.0 ) - -include(LofarFindPackage) - -#hard-coded path where wincc api can be found on build systems -set(WINCC_ROOT_DIR /opt/WinCC_OA/3.15 CACHE PATH "root dir where the WinCC_OA api can be found") -lofar_find_package(WINCC) - -IF(WINCC_FOUND) - add_subdirectory(include) - add_subdirectory(src) - add_subdirectory(test) -ENDIF(WINCC_FOUND) diff --git a/LCS/WinCCWrapper/doc/winccwrapper.md b/LCS/WinCCWrapper/doc/winccwrapper.md deleted file mode 100644 index 63ac9fbe26e5409dd390e48af0f8053b7c028c94..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/doc/winccwrapper.md +++ /dev/null @@ -1,124 +0,0 @@ - -# WinCCWrapper Overview {#winccwrapper_overview} - -## General - -### Description/Summary - -The WinCCWrapper library is a simple C++ wrapper around the difficult to use WinCC_OA API. Of course one could always still choose use the WinCC_OA API which provides more features than this simple wrapper. This WinCCWrapper is aimed at providing a simple API to set and get datapoints into a wincc database. All calls are blocking/synchronous (where the underlying WinCC_OA API is asynchronous). - -This WinCCWrapper library has the following features: -- set/get datapoints for the most common datatypes (int, long, float, bool, string, time_t) -- mark datapoints as valid/invalid. -- "connect" to changes in datapoints: whenever a 'connected' datapoint is changed (by whoever from whereever) then a supplied callback function is called. - -Boost-python bindings are provided as well, exposing the same API in python. - - -### Authors/Owners - -- Auke Klazema <mailto:klazema@astron.nl> -- Jorrit Schaap <mailto:schaap@astron.nl> - -### Overview - -This package builds a c++ library, and python bindings. For further details, see Description above. - -- - - - -## DEVELOPMENT - -### Analyses -This library originated from the Responsive Telescope project which needed a means to use the station monitoring information available in the wincc database. It was later extended in the APERTIF project to provide a means to set/get the validness of datapoints. - -The folling feaures were required, and implemented: -- set/get datapoints for the most common datatypes (int, long, float, bool, string, time_t) -- mark datapoints as valid/invalid. -- "connect" to changes in datapoints: whenever a 'connected' datapoint is changed (by whoever from whereever) then a supplied callback function is called. - -Because the WinCC_OA API is hard to use, we decided to implement this simple wrapper. -Because the WinCC_OA API is in C++, this wrapper needed to be written in C++ as well. -Because we needed to have the same API available in python as well, we decided to create boost-python bindings. - - -### Design -No fancy design needed. This is just a library with a few classes wrapping the complicated WinCC_OA API into a simple API. - -### Source Code -- [WinCCWrapper in SVN](https://svn.astron.nl/LOFAR/branches/SW-26_WinCC/LCS/WinCCWrapper) -- [WinCCWrapper Code Documentation](@ref winccwrapper_overview) - -### Testing - -#### Unit Testing - -We decided not to provide unit tests, because that would require to write a quite large mocked version of the WinCC_OA API, which would be bigger and more complex than the wrapper classes themselves. - -#### Integration Testing - -When BUILD_TESTING is ON, then little test programs are built: WinCCSet and WinCCGet. They can be run from the cmdline (on a host where WinCC is running) and be used to test whether you can successfully set and/or get a datapoint. This is a manual test. - -#### Build & Deploy - -This library needs a c++11 compiler. -Dependencies on other libraries are automatically found by cmake, and otherwise reported which are missing. - -##### Build locally - - svn co https://svn.astron.nl/LOFAR/<some_branch_or_trunk> <my_source_dir> - cd <my_source_dir> - mkdir -p build/gnu_cxx11debug - cd build/gnu_cxx11debug - cmake -DBUILD_PACKAGES=WinCCWrapper -DUSE_LOG4CPLUS=OFF -DCMAKE_INSTALL_PREFIX=/opt/lofar/ ../.. - cd ../.. - make - make install - -##### Build using Jenkins - -There are no special Jenkins jobs for this package specifically. Such a job is also not needed. CMake will automatically take care of building this package whenever a package which is build by Jenkins is dependent on WinCCWrapper. - -##### Deploy - -There is no special Jenkins job to deploy this package specifically. Such a job is also not needed. The library from this package is deployed automatically thanks to cmake/jenkins whenever another package is deployed which depends on this package. - -- - - - -## OPERATIONS - -### Configuration -- There are no configuration files. - -### Log Files -- This library does not produce log files. A program using this library could produce logfiles, and these log files will contain the log lines issued by this library. - -### Runtime -- This library just loads whenever a using program is started. - -### Interfaces (API) -- It's a library. See the source code documentation for the api. - -### Files/Databases -- It depends on a running WINCC_OA instance (which run on the mcu's) -- No other files and/or databases are needed. - -### Dependencies -- WINCC_OA 3.15 (API, and runtime, which are installed on mcu's and the buildhostcentos7) - -### Security -- No login credentials are needed. - -- - - - -## ADDITIONAL INFORMATION - -### User Documentation - -N.A. - -### Operations Documentation - -N.A. - - - diff --git a/LCS/WinCCWrapper/src/CMakeLists.txt b/LCS/WinCCWrapper/src/CMakeLists.txt deleted file mode 100644 index e6a9ecd6de8da16ea347bb97f5f544f5b3fc9368..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/src/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -include(LofarPackageVersion) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include) - -lofar_add_library(wincc_wrapper - WinCCManager.cc - WinCCResources.cc - WinCCWrapper.cc - ConnectWaitForAnswer.cc) - -# Try to find Boost-Python. -# If found, build the bindings, otherwise give a warning. -FIND_PATH(BOOST_PYTHON_FOUND "boost/python.hpp") - -if(BOOST_PYTHON_FOUND) - # create python modules and boost python bindings - - include(LofarFindPackage) - lofar_find_package(Python 2.6 REQUIRED) - lofar_find_package(Boost REQUIRED COMPONENTS python) - include(PythonInstall) - - set(_py_files __init__.py) - SET(WINCC_PACKAGE_PATH "lofar/common/wincc") - python_install(${_py_files} DESTINATION ${WINCC_PACKAGE_PATH}) - - lofar_add_library(pywincc MODULE WinCCWrapper_boost_python.cc) - set_target_properties(pywincc PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY ${PYTHON_BUILD_DIR}/${WINCC_PACKAGE_PATH}) - target_link_libraries(pywincc ${BOOST_LIBRARIES}) - target_link_libraries(pywincc wincc_wrapper) - - # This is a quick-and-dirty fix to install the Python binding module in the - # right place. It will now be installed twice, because lofar_add_library() - # will install it in $prefix/$libdir - install(TARGETS pywincc DESTINATION ${PYTHON_INSTALL_DIR}/${WINCC_PACKAGE_PATH}) -else() - message (WARNING, "Boost-Python not found; not building python bindings for wincc.") -endif() - diff --git a/LCS/WinCCWrapper/src/ConnectWaitForAnswer.cc b/LCS/WinCCWrapper/src/ConnectWaitForAnswer.cc deleted file mode 100644 index 767ea576d761ca1ee4e99202ba2f07af82c3ba11..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/src/ConnectWaitForAnswer.cc +++ /dev/null @@ -1,87 +0,0 @@ -//# Copyright (C) 2017 -//# ASTRON (Netherlands Institute for Radio Astronomy) -//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands -//# -//# This file is part of the LOFAR Software Suite. -//# -//# The LOFAR Software Suite is free software: you can redistribute it and/or -//# modify it under the terms of the GNU General Public License as published by -//# the Free Software Foundation, either version 3 of the License, or (at your -//# option) any later version. -//# -//# The LOFAR Software Suite is distributed in the hope that it will be -//# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -//# Public License for more details. -//# -//# You should have received a copy of the GNU General Public License along with -//# The LOFAR Software Suite. If not, see <http://www.gnu.org/licenses/>. - -#include "ConnectWaitForAnswer.h" -#include "WinCCManager.h" - -namespace LOFAR { - namespace WINCCWRAPPER { - -using namespace std; - -void ConnectWaitForAnswer::hotLinkCallBack(DpMsgAnswer &answer) -{ - for (AnswerGroup *grpPtr = answer.getFirstGroup(); grpPtr; grpPtr = answer.getNextGroup()) - { - if (grpPtr->getError()) - { - cout << "Error!" << endl; - } - else - { - for (DpVCItem * item = grpPtr->getFirstItem(); item; item = grpPtr->getNextItem()) - { - Variable *varPtr = item->getValuePtr(); - - if(varPtr) - { - string name = get_datapoint_name(item); - Variable *value = varPtr->clone(); //WinCCManager should delete cloned pointer - - ((WinCCManager *) Manager::getManPtr())->handle_get(name, value); - } - } - } - } -} - -void ConnectWaitForAnswer::hotLinkCallBack(DpHLGroup &group) -{ - for (DpVCItem *item = group.getFirstItem(); item; item = group.getNextItem()) - { - handle_group_item(item); - } -} - -void ConnectWaitForAnswer::handle_group_item(const DpVCItem* const item) -{ - Variable *varPtr = item->getValuePtr(); - - if (varPtr) - { - string name = get_datapoint_name(item); - string value = varPtr->formatValue().c_str(); - - ((WinCCManager *) Manager::getManPtr())->handle_hotlink(name, value); - } -} - -std::string ConnectWaitForAnswer::get_datapoint_name(const DpVCItem* const item) -{ - DpIdentifier dpIdentifier = item->getDpIdentifier(); - - CharString name = ""; - - Manager::getName(dpIdentifier, name); - - return name.c_str(); -} - - } // namespace WINCCWRAPPER -} // namespace LOFAR diff --git a/LCS/WinCCWrapper/src/ConnectWaitForAnswer.h b/LCS/WinCCWrapper/src/ConnectWaitForAnswer.h deleted file mode 100644 index 28dd3f0138a5c84e25374ade4ee2bea51ad9745a..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/src/ConnectWaitForAnswer.h +++ /dev/null @@ -1,46 +0,0 @@ -//# Copyright (C) 2017 -//# ASTRON (Netherlands Institute for Radio Astronomy) -//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands -//# -//# This file is part of the LOFAR Software Suite. -//# -//# The LOFAR Software Suite is free software: you can redistribute it and/or -//# modify it under the terms of the GNU General Public License as published by -//# the Free Software Foundation, either version 3 of the License, or (at your -//# option) any later version. -//# -//# The LOFAR Software Suite is distributed in the hope that it will be -//# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -//# Public License for more details. -//# -//# You should have received a copy of the GNU General Public License along with -//# The LOFAR Software Suite. If not, see <http://www.gnu.org/licenses/>. - -#ifndef CONNECT_WAIT_FOR_ANSWER_H -#define CONNECT_WAIT_FOR_ANSWER_H - -#include <string> - -#include <HotLinkWaitForAnswer.hxx> -#include <DpMsgAnswer.hxx> -#include <DpHLGroup.hxx> - -namespace LOFAR { - namespace WINCCWRAPPER { - -class ConnectWaitForAnswer : public HotLinkWaitForAnswer -{ -public: - using HotLinkWaitForAnswer::hotLinkCallBack; - virtual void hotLinkCallBack(DpMsgAnswer &answer); - virtual void hotLinkCallBack(DpHLGroup &group); -private: - void handle_group_item(const DpVCItem* const item); - std::string get_datapoint_name(const DpVCItem* const item); -}; - - } // namespace WINCCWRAPPER -} // namespace LOFAR - -#endif diff --git a/LCS/WinCCWrapper/src/WinCCManager.cc b/LCS/WinCCWrapper/src/WinCCManager.cc deleted file mode 100644 index 217023ca010283a83cc3c5208ed036722857efbe..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/src/WinCCManager.cc +++ /dev/null @@ -1,445 +0,0 @@ -//# Copyright (C) 2017 -//# ASTRON (Netherlands Institute for Radio Astronomy) -//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands -//# -//# This file is part of the LOFAR Software Suite. -//# -//# The LOFAR Software Suite is free software: you can redistribute it and/or -//# modify it under the terms of the GNU General Public License as published by -//# the Free Software Foundation, either version 3 of the License, or (at your -//# option) any later version. -//# -//# The LOFAR Software Suite is distributed in the hope that it will be -//# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -//# Public License for more details. -//# -//# You should have received a copy of the GNU General Public License along with -//# The LOFAR Software Suite. If not, see <http://www.gnu.org/licenses/>. - -#include <sstream> - -#include <StartDpInitSysMsg.hxx> - -#include "WinCCManager.h" -#include "ConnectWaitForAnswer.h" -#include <DrvManager.hxx> -#include <PeriphAddr.hxx> -#include <AbstractHWMapper.hxx> -#include <BitVar.hxx> -#include <TimeVar.hxx> -#include <Variable.hxx> -#include <IntegerVar.hxx> -#include <LongVar.hxx> -#include <TextVar.hxx> -#include <cassert> - -namespace LOFAR { - namespace WINCCWRAPPER { - -using namespace std; - -volatile bool WinCCManager::doExit = false; - -WinCCManager::WinCCManager() : - Manager(ManagerIdentifier(API_MAN, Resources::getManNum())) -{ - init(); -} - -void WinCCManager::init() -{ - // First connect to Data manager. - // We want Typecontainer and Identification so we can resolve names - // This call succeeds or the manager will exit - connectToData(StartDpInitSysMsg::TYPE_CONTAINER | StartDpInitSysMsg::DP_IDENTIFICATION); - - // While we are in STATE_INIT we are initialized by the Data manager - while (getManagerState() == STATE_INIT) - { - // Wait max. 1 second in select to receive next message from data. - // It won't take that long... - long sec=1, usec=0; - dispatch(sec, usec); - } - - // We are now in STATE_ADJUST and can connect to Event manager - // This call will succeed or the manager will exit - connectToEvent(); -} - -void WinCCManager::connect_datapoints(const std::vector<std::string> &dataPoints) -{ - for(vector<string>::const_iterator it = dataPoints.begin(); it != dataPoints.end(); it++) - { - DpIdentList dpList; - DpIdentifier dpIdConnect; - - if (Manager::getId(it->c_str(), dpIdConnect) == PVSS_FALSE) - { - // This name was unknown - ErrHdl::error(ErrClass::PRIO_SEVERE, - ErrClass::ERR_PARAM, - ErrClass::UNEXPECTEDSTATE, - "PublishManager", - "connect_datapoints", - CharString("Datapoint ") + CharString(it->c_str()) + - CharString(" missing")); - } - else - { - dpList.append(dpIdConnect); - // We give the dpConnect a nice naked pointer because it will delete it when the manager stops. - HotLinkWaitForAnswer* wait = new ConnectWaitForAnswer(); - Manager::dpConnect(dpList, wait); - } - } -} - -bool WinCCManager::set_datapoint(const std::string &name, const Variable &value, bool valid) -{ - //reuse the set_datapoint_validity, and explicitly set the value to the given value - return set_datapoint_validity(name, valid, &value); -} - -// request the datapoint (async). is called by _get_datapoint which makes it blocking (synchronous) by waiting for the answer. -bool WinCCManager::request_datapoint(const std::string &name) -{ - DpIdentifier dpId; - - if (Manager::getId(name.c_str(), dpId) == PVSS_FALSE) - { - // This name was unknown. - ErrHdl::error(ErrClass::PRIO_SEVERE, - ErrClass::ERR_PARAM, - ErrClass::UNEXPECTEDSTATE, - "WinCCManager", - "get_datapoint", - CharString("Datapoint ") + CharString(name.c_str()) + - CharString(" missing")); - return false; - } - - HotLinkWaitForAnswer* wait = new ConnectWaitForAnswer(); - return (PVSS_TRUE == Manager::dpGet(dpId, wait)); -} - -void WinCCManager::handle_get(const std::string &name, Variable *&value) -{ - values[name] = value; -} - -bool WinCCManager::has_received_variable(const std::string &name) -{ - std::map<string, Variable*>::iterator it; - - it = values.find(name); - - return (it != values.end()); -} - -bool WinCCManager::get_received_variable(const std::string &name, Variable *&value) -{ - assert(value == nullptr); - - std::map<string, Variable*>::iterator it; - - it = values.find(name); - - if(it != values.end()) - { - value = it->second; - values.erase(it); - return true; - } - - return false; -} - -bool WinCCManager::wait_for_received_variable(const std::string &name, unsigned long msec_timeout) -{ - clock_t start_time = clock(); - - long sec=0, usec=10000; - - while(!has_received_variable(name)) { - dispatch(sec, usec); - - clock_t now = clock(); - unsigned long elapsed = (1000*(now-start_time))/(CLOCKS_PER_SEC); - if(elapsed >= msec_timeout) { - ErrHdl::error(ErrClass::PRIO_SEVERE, - ErrClass::ERR_PARAM, - ErrClass::UNEXPECTEDSTATE, - "WinCCManager", - "wait_for_received_variable", - CharString("timeout while waiting for requested datapoint ") + CharString(name.c_str())); - - return false; - } - } - return true; -} - - -bool WinCCManager::get_datapoint_variable(const std::string &name, Variable *&variable_value) -{ - assert(variable_value == nullptr); - - //sometimes the Manager prepends text to the name in its answers - //so make sure we use the correct name from the manager by looking up the dpId... - DpIdentifier dpId; - if (Manager::getId(name.c_str(), dpId) == PVSS_FALSE) - { - // This name was unknown. - ErrHdl::error(ErrClass::PRIO_SEVERE, - ErrClass::ERR_PARAM, - ErrClass::UNEXPECTEDSTATE, - "WinCCManager", - "get_datapoint", - CharString("Datapoint ") + CharString(name.c_str()) + - CharString(" missing")); - return false; - } - - //...and then reverse lookup the manager's verion of the name - CharString man_dp_name = ""; - Manager::getName(dpId, man_dp_name); //should always succeed as we just received the dpId from the manager - - std::string the_name(man_dp_name.c_str()); - if(request_datapoint(the_name)) - { - if(wait_for_received_variable(the_name, 1000)) { - if(get_received_variable(the_name, variable_value)) { - return true; - } - } - } - - return false; -} - -//use template specialization to have a compile time switch -//to convert a Variable of unknown internal type to a typed value -//return the internally created converted_var, so it can be deleted in _get_datapoint -template <typename Tval> -Variable::ConvertResult convert(Variable *var, Tval &value, Variable *&converted_var); - -template <> -Variable::ConvertResult convert(Variable *var, int &value, Variable *&converted_var) -{ - Variable::ConvertResult cr = var->convert(VariableType::INTEGER_VAR, converted_var); - if(Variable::ConvertResult::OK == cr) - value = ((IntegerVar*)converted_var)->getValue(); - return cr; -} - -template <> -Variable::ConvertResult convert(Variable *var, long &value, Variable *&converted_var) -{ - Variable::ConvertResult cr = var->convert(VariableType::LONG_VAR, converted_var); - if(Variable::ConvertResult::OK == cr) - value = ((LongVar*)converted_var)->getValue(); - return cr; -} - -template <> -Variable::ConvertResult convert(Variable *var, float &value, Variable *&converted_var) -{ - Variable::ConvertResult cr = var->convert(VariableType::FLOAT_VAR, converted_var); - if(Variable::ConvertResult::OK == cr) - value = ((FloatVar*)converted_var)->getValue(); - return cr; -} - -template <> -Variable::ConvertResult convert(Variable *var, bool &value, Variable *&converted_var) -{ - Variable::ConvertResult cr = var->convert(VariableType::BIT_VAR, converted_var); - if(Variable::ConvertResult::OK == cr) - value = ((BitVar*)converted_var)->getValue(); - - return cr; -} - -template <> -Variable::ConvertResult convert(Variable *var, std::string &value, Variable *&converted_var) -{ - Variable::ConvertResult cr = var->convert(VariableType::TEXT_VAR, converted_var); - if(Variable::ConvertResult::OK == cr) - value = ((TextVar*)converted_var)->getString().c_str(); - return cr; -} - -template <> -Variable::ConvertResult convert(Variable *var, struct tm &value, Variable *&converted_var) -{ - Variable::ConvertResult cr = var->convert(VariableType::TIME_VAR, converted_var); - if(Variable::ConvertResult::OK == cr) { - time_t time_val = ((TimeVar*)converted_var)->getSeconds(); - struct tm *tmp_tm; - tmp_tm = gmtime(&time_val); - value = *tmp_tm; - } - - return cr; -} - -//internal generic method to get the typed (Tval) value of a datapoint -//used by the public strictly typed methods -template <typename Tval> -bool WinCCManager::_get_datapoint(const std::string &name, Tval &value) -{ - Variable *var = NULL; - if(get_datapoint_variable(name, var)) - { - VariablePtr converted_var = NULL; - Variable::ConvertResult cr = convert(var, value, converted_var); - if(Variable::ConvertResult::OK == cr || Variable::ConvertResult::OUT_OF_RANGE == cr) - { - delete converted_var; //delete it, since it was a newly created variable in var->convert - delete var; //delete it, since it was a cloned variable created in get_datapoint_variable - return (Variable::ConvertResult::OK == cr); - } - delete var; //delete it, since it was a cloned variable created in get_datapoint_variable - } - - return false; -} - -//below, a few strictly type methods for get_datapoint are defined -//they just call the templated _get_datapoint, so why not just use the one and only templated method? -//because with these strictly type methods, we force the compiler to define the methods for these types -//so they can be found when called from a dynamicaly type language like python. -//see the WinCCWrapper_boost_python file. -bool WinCCManager::get_datapoint(const std::string &name, int &value) -{ - return _get_datapoint(name, value); -} - -bool WinCCManager::get_datapoint(const std::string &name, long &value) -{ - return _get_datapoint(name, value); -} - -bool WinCCManager::get_datapoint(const std::string &name, float &value) -{ - return _get_datapoint(name, value); -} - -bool WinCCManager::get_datapoint(const std::string &name, bool &value) -{ - return _get_datapoint(name, value); -} - -bool WinCCManager::get_datapoint(const std::string &name, std::string &value) -{ - return _get_datapoint(name, value); -} - -bool WinCCManager::get_datapoint(const std::string &name, struct tm &value) -{ - return _get_datapoint(name, value); -} - -bool WinCCManager::set_datapoint_validity(const std::string &name, bool validity, const Variable *value) -{ - DpIdentifier dpId; - - if (Manager::getId(name.c_str(), dpId) == PVSS_FALSE) - { - // This name was unknown. - ErrHdl::error(ErrClass::PRIO_SEVERE, - ErrClass::ERR_PARAM, - ErrClass::UNEXPECTEDSTATE, - "WinCCManager", - "set_datapoint_validity", - CharString("Datapoint ") + CharString(name.c_str()) + - CharString(" missing")); - return false; - } - - //determine if we need to use the given value, or get the last known value - Variable *last_known_value = NULL; - if(value == NULL) { - //obtain last known value, needs to be deleted later - get_datapoint_variable(name, last_known_value); - } - - if(value != NULL || last_known_value != NULL) - { - TimeVar now; - BitVec infoBits; - if(!validity) { - infoBits.set(DriverBits::DRV_INVALID); - infoBits.set(DriverBits::DRV_VALID_INVALID); - } - - DrvManager *drvman = DrvManager::getSelfPtr(); - drvman ->sendVCMsg(dpId, value!=NULL ? *value : *last_known_value, now, infoBits); - - //process, wait max 10 ms - long sec=0, usec=10000; - dispatch(sec, usec); - - if(last_known_value != NULL) { - //we obtained the last known value... - //delete it, since it was a cloned variable created in get_datapoint_variable - delete last_known_value; - } - - return true; - } - - return false; -} - - -void WinCCManager::run() -{ - // Let Manager handle SIGINT and SIGTERM (Ctrl+C, kill) - // Manager::sigHdl will call virtual function Manager::signalHandler - signal(SIGINT, Manager::sigHdl); - signal(SIGTERM, Manager::sigHdl); - - // Now loop until we are finished - while ( true ) - { - // Exit flag set ? - if (doExit) - return; - - //process, wait max 100 ms - long sec=0, usec=100000; - dispatch(sec, usec); - } -} - -void WinCCManager::exit() -{ - Manager::exit(0); -} - -void WinCCManager::handle_hotlink(const std::string &name, const std::string &value) -{ - if(callback) - { - callback(name, value); - } -} - -void WinCCManager::signalHandler(int sig) -{ - if ((sig == SIGINT) || (sig == SIGTERM)) - { - WinCCManager::doExit = true; - } - else - { - Manager::signalHandler(sig); - } -} - - } // namespace WINCCWRAPPER -} // namespace LOFAR - diff --git a/LCS/WinCCWrapper/src/WinCCResources.cc b/LCS/WinCCWrapper/src/WinCCResources.cc deleted file mode 100644 index 5eb7dbf8d1e3935abb068f6aa843514ba7b1c84a..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/src/WinCCResources.cc +++ /dev/null @@ -1,44 +0,0 @@ -//# Copyright (C) 2017 -//# ASTRON (Netherlands Institute for Radio Astronomy) -//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands -//# -//# This file is part of the LOFAR Software Suite. -//# -//# The LOFAR Software Suite is free software: you can redistribute it and/or -//# modify it under the terms of the GNU General Public License as published by -//# the Free Software Foundation, either version 3 of the License, or (at your -//# option) any later version. -//# -//# The LOFAR Software Suite is distributed in the hope that it will be -//# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -//# Public License for more details. -//# -//# You should have received a copy of the GNU General Public License along with -//# The LOFAR Software Suite. If not, see <http://www.gnu.org/licenses/>. - -#include <Resources.hxx> - -#include "WinCCResources.h" - -namespace LOFAR { - namespace WINCCWRAPPER { - -using namespace std; - -WinCCResources::WinCCResources(const std::string &project_name) -{ - init(project_name); -} - -void WinCCResources::init(const std::string & /*project_name*/) -{ - // TODO set specific project instead of current project. - char* ownArgv[] = {(char *)"WinCCWrapper", (char *)"-currentproj", (char *)"-log", (char *)"+stderr"}; - int ownArgc = sizeof ownArgv / sizeof ownArgv[0]; - - Resources::init(ownArgc, ownArgv); -} - - } // namespace WINCCWRAPPER -} // namespace LOFAR diff --git a/LCS/WinCCWrapper/src/WinCCWrapper.cc b/LCS/WinCCWrapper/src/WinCCWrapper.cc deleted file mode 100644 index 19883c0a99a3d44c0a95091f67c1f4ff34ece726..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/src/WinCCWrapper.cc +++ /dev/null @@ -1,178 +0,0 @@ -//# Copyright (C) 2017 -//# ASTRON (Netherlands Institute for Radio Astronomy) -//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands -//# -//# This file is part of the LOFAR Software Suite. -//# -//# The LOFAR Software Suite is free software: you can redistribute it and/or -//# modify it under the terms of the GNU General Public License as published by -//# the Free Software Foundation, either version 3 of the License, or (at your -//# option) any later version. -//# -//# The LOFAR Software Suite is distributed in the hope that it will be -//# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -//# Public License for more details. -//# -//# You should have received a copy of the GNU General Public License along with -//# The LOFAR Software Suite. If not, see <http://www.gnu.org/licenses/>. - -#include <StartDpInitSysMsg.hxx> -#include <IntegerVar.hxx> -#include <FloatVar.hxx> -#include <LongVar.hxx> -#include <TimeVar.hxx> - -#include <condition_variable> -#include <mutex> -#include <queue> -#include <thread> - -#include "WinCCWrapper.h" -#include "ConnectWaitForAnswer.h" - -namespace LOFAR { - namespace WINCCWRAPPER { - -using namespace std; - -//! Each datapoint has a human readable name in the wincc database, but the actual value is stored in a sub-item. Append that to each set/get datapoint name. -static const string DP_SUFFIX = ":_original.._value"; - -WinCCWrapper::WinCCWrapper(const std::string &project_name) : - resources(project_name) -{ - manager = new WinCCManager(); -} - -void WinCCWrapper::run() -{ - manager->run(); -} - -void WinCCWrapper::exit() -{ - manager->exit(); -} - -void WinCCWrapper::connect_datapoints(const std::vector<std::string> &data_points) -{ - manager->connect_datapoints(data_points); -} - -void WinCCWrapper::set_connect_datapoints_callback(std::function<void(std::string name, std::string value)> callback) -{ - manager->set_connect_datapoints_callback(callback); -} - -// set_datapoint -bool WinCCWrapper::set_datapoint(const std::string &name, int value, bool valid) -{ - IntegerVar variable{value}; - - return manager->set_datapoint(name + DP_SUFFIX, variable, valid); -} - -bool WinCCWrapper::set_datapoint(const std::string &name, long value, bool valid) -{ - LongVar variable{value}; - - return manager->set_datapoint(name + DP_SUFFIX, variable, valid); -} - -bool WinCCWrapper::set_datapoint(const std::string &name, float value, bool valid) -{ - FloatVar variable{value}; - - return manager->set_datapoint(name + DP_SUFFIX, variable, valid); -} - -bool WinCCWrapper::set_datapoint(const std::string &name, bool value, bool valid) -{ - BitVar variable{value}; - - return manager->set_datapoint(name + DP_SUFFIX, variable, valid); -} - -bool WinCCWrapper::set_datapoint(const std::string &name, std::string value, bool valid) -{ - TextVar variable{CharString(value.c_str())}; - - return manager->set_datapoint(name + DP_SUFFIX, variable, valid); -} - -bool WinCCWrapper::set_datapoint_time(const std::string &name, time_t value, bool valid) -{ - TimeVar variable(0,0); - variable.setSeconds(value); - - return manager->set_datapoint(name + DP_SUFFIX, variable, valid); -} - -// get_datapoint -template <typename T> -bool WinCCWrapper::get_datapoint(const std::string &name, T &value) -{ - return manager->get_datapoint(name + DP_SUFFIX, value); -} - -int WinCCWrapper::get_datapoint_int(const std::string &name) -{ - int value; - if(get_datapoint(name, value)) - return value; - throw std::runtime_error("Could not get datapoint"); -} - -long WinCCWrapper::get_datapoint_long(const std::string &name) -{ - long value; - if(get_datapoint(name, value)) - return value; - throw std::runtime_error("Could not get datapoint"); -} - -float WinCCWrapper::get_datapoint_float(const std::string &name) -{ - float value; - if(get_datapoint(name, value)) - return value; - throw std::runtime_error("Could not get datapoint"); -} - -bool WinCCWrapper::get_datapoint_bool(const std::string &name) -{ - bool value; - if(get_datapoint(name, value)) - return value; - throw std::runtime_error("Could not get datapoint"); -} - -std::string WinCCWrapper::get_datapoint_string(const std::string &name) -{ - std::string value; - if(get_datapoint(name, value)) - return value; - throw std::runtime_error("Could not get datapoint"); -} - -time_t WinCCWrapper::get_datapoint_time(const std::string &name) -{ - struct tm value; - if(get_datapoint(name, value)) - return mktime(&value); - throw std::runtime_error("Could not get datapoint"); -} - -bool WinCCWrapper::set_datapoint_valid(const std::string &name) -{ - return manager->set_datapoint_valid(name + DP_SUFFIX); -} - -bool WinCCWrapper::set_datapoint_invalid(const std::string &name) -{ - return manager->set_datapoint_invalid(name + DP_SUFFIX); -} - - } // namespace WINCCWRAPPER -} // namespace LOFAR diff --git a/LCS/WinCCWrapper/src/WinCCWrapper_boost_python.cc b/LCS/WinCCWrapper/src/WinCCWrapper_boost_python.cc deleted file mode 100644 index 50f32eb0f950ebdfb7890b1d3964b39ce05caaa1..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/src/WinCCWrapper_boost_python.cc +++ /dev/null @@ -1,56 +0,0 @@ -//# Copyright (C) 2017 -//# ASTRON (Netherlands Institute for Radio Astronomy) -//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands -//# -//# This file is part of the LOFAR Software Suite. -//# -//# The LOFAR Software Suite is free software: you can redistribute it and/or -//# modify it under the terms of the GNU General Public License as published by -//# the Free Software Foundation, either version 3 of the License, or (at your -//# option) any later version. -//# -//# The LOFAR Software Suite is distributed in the hope that it will be -//# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -//# Public License for more details. -//# -//# You should have received a copy of the GNU General Public License along with -//# The LOFAR Software Suite. If not, see <http://www.gnu.org/licenses/>. - -#include <boost/python.hpp> -#include "WinCCWrapper.h" - -BOOST_PYTHON_MODULE(pywincc) -{ - using namespace boost::python; - using namespace LOFAR::WINCCWRAPPER; - - bool (WinCCWrapper::*set_datapoint_int)(const std::string&, int, bool) = &WinCCWrapper::set_datapoint; - bool (WinCCWrapper::*set_datapoint_long)(const std::string&, long, bool) = &WinCCWrapper::set_datapoint; - bool (WinCCWrapper::*set_datapoint_float)(const std::string&, float, bool) = &WinCCWrapper::set_datapoint; - bool (WinCCWrapper::*set_datapoint_bool)(const std::string&, bool, bool) = &WinCCWrapper::set_datapoint; - bool (WinCCWrapper::*set_datapoint_string)(const std::string&, std::string, bool) = &WinCCWrapper::set_datapoint; - bool (WinCCWrapper::*set_datapoint_time)(const std::string&, time_t, bool) = &WinCCWrapper::set_datapoint_time; - bool (WinCCWrapper::*set_datapoint_valid)(const std::string&) = &WinCCWrapper::set_datapoint_valid; - bool (WinCCWrapper::*set_datapoint_invalid)(const std::string&) = &WinCCWrapper::set_datapoint_invalid; - - class_<WinCCWrapper>("WinCCWrapper", init<const std::string&>()) - .def("set_datapoint_int", set_datapoint_int) - .def("set_datapoint_long", set_datapoint_long) - .def("set_datapoint_float", set_datapoint_float) - .def("set_datapoint_bool", set_datapoint_bool) - .def("set_datapoint_string", set_datapoint_string) - .def("set_datapoint_time", set_datapoint_time) - .def("set_datapoint", set_datapoint_float) // 'common'/'generic' set_datapoint python method just calls set_datapoint_float - .def("set_datapoint_valid", set_datapoint_valid) - .def("set_datapoint_invalid", set_datapoint_invalid) - .def("get_datapoint_int", &WinCCWrapper::get_datapoint_int) - .def("get_datapoint_long", &WinCCWrapper::get_datapoint_long) - .def("get_datapoint_float", &WinCCWrapper::get_datapoint_float) - .def("get_datapoint_bool", &WinCCWrapper::get_datapoint_bool) - .def("get_datapoint_string", &WinCCWrapper::get_datapoint_string) - .def("get_datapoint_time", &WinCCWrapper::get_datapoint_time) - .def("get_datapoint", &WinCCWrapper::get_datapoint_float) // 'common'/'generic' get_datapoint python method just calls get_datapoint_float - ; -} - diff --git a/LCS/WinCCWrapper/src/__init__.py b/LCS/WinCCWrapper/src/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/LCS/WinCCWrapper/test/CMakeLists.txt b/LCS/WinCCWrapper/test/CMakeLists.txt deleted file mode 100644 index c0e25c5a523711a37a3deb95c9ddd43d87d35077..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/test/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -include(LofarCTest) - -IF(BUILD_TESTING) - lofar_add_bin_program(WinCCSet WinCCSet.cc) - lofar_add_bin_program(WinCCGet WinCCGet.cc) - - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include) -ENDIF(BUILD_TESTING) diff --git a/LCS/WinCCWrapper/test/WinCCGet.cc b/LCS/WinCCWrapper/test/WinCCGet.cc deleted file mode 100644 index c050990c75186f4a1d938cb59b63d72945383641..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/test/WinCCGet.cc +++ /dev/null @@ -1,18 +0,0 @@ -#include <cstdlib> -#include <string> -#include <WinCCWrapper.h> - -using namespace LOFAR::WINCCWRAPPER; - -int main(int, char * argv[]) -{ - WinCCWrapper wrapper{""}; - - std::string dpname{argv[1]}; - int value = 22; - - value = wrapper.get_datapoint_int(dpname); - std::cout << dpname << ": " << value << std::endl; - - return 0; -} diff --git a/LCS/WinCCWrapper/test/WinCCSet.cc b/LCS/WinCCWrapper/test/WinCCSet.cc deleted file mode 100644 index c7d05fd428fdb792d6e4660e6ffd6698cc6cf313..0000000000000000000000000000000000000000 --- a/LCS/WinCCWrapper/test/WinCCSet.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include <cstdlib> -#include <string> -#include <WinCCWrapper.h> - -using namespace LOFAR::WINCCWRAPPER; - -int main(int, char * argv[]) -{ - WinCCWrapper wrapper{""}; - - std::string dpname{argv[1]}; - int value = atoi(argv[2]); - - wrapper.set_datapoint(dpname, value); - - return 0; -}