diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0d4c71819862b7cc2ae7bfe9f0d3cb4cc01cb606 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.nse_depinfo +bin +obj + +# Eclipse +.cproject +.project +.settings diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..135ddcf3c8bbfca8d7af272ed891474c8dfc1b1a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "deps/socket2"] + path = deps/socket2 + url = git@gitlab.elettra.eu:cs/ds/socket2.git +[submodule "deps/socket2client"] + path = deps/socket2client + url = git@gitlab.elettra.eu:cs/cls/socket2client.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5b384bc19e5a792daa864c6f3f663ceb73c20e61 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +NAME_SRV = plcrack3-srv + +CXXFLAGS = -I ../socket2/src +SRC_FILES = $(wildcard deps/socket2*/src/Socket2*.cpp) +CXXFLAGS = -Ideps/socket2client/src -Ideps/socket2/src + + +include ../makefiles/Make-9.3.6.in diff --git a/deps/socket2 b/deps/socket2 new file mode 160000 index 0000000000000000000000000000000000000000..36fd91bbeb50e33556cd5dfd73888552dd0a69d6 --- /dev/null +++ b/deps/socket2 @@ -0,0 +1 @@ +Subproject commit 36fd91bbeb50e33556cd5dfd73888552dd0a69d6 diff --git a/deps/socket2client b/deps/socket2client new file mode 160000 index 0000000000000000000000000000000000000000..0f51d74c0c1f1e3aae5bf5a3ce4e9cbbea80face --- /dev/null +++ b/deps/socket2client @@ -0,0 +1 @@ +Subproject commit 0f51d74c0c1f1e3aae5bf5a3ce4e9cbbea80face diff --git a/docs/Blocco_dati_SCAMBIO.pdf b/docs/Blocco_dati_SCAMBIO.pdf new file mode 100644 index 0000000000000000000000000000000000000000..574dc6e7bd1b3842ea2a9f908dae8ceaebc5fa24 Binary files /dev/null and b/docs/Blocco_dati_SCAMBIO.pdf differ diff --git a/src/ClassFactory.cpp b/src/ClassFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18658ec8e9407de326242397cecb44e770f45c0d --- /dev/null +++ b/src/ClassFactory.cpp @@ -0,0 +1,52 @@ +/*----- PROTECTED REGION ID(PLCRack3::ClassFactory.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : ClassFactory.cpp +// +// description : C++ source for the class_factory method of the DServer +// device class. This method is responsible for the creation of +// all class singleton for a device server. It is called +// at device server startup. +// +// project : PLCRack3 +// +// This file is part of Tango device class. +// +// Tango 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. +// +// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + +#include <tango.h> +#include "PLCRack3Class.h" + +// Add class header files if needed + + +/** + * Create PLCRack3 Class singleton and store it in DServer object. + */ + +void Tango::DServer::class_factory() +{ + // Add method class init if needed + add_class(PLCRack3_ns::PLCRack3Class::init("PLCRack3")); +} +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3::ClassFactory.cpp diff --git a/src/PLCRack3.cpp b/src/PLCRack3.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eaa572d1cc9fa6236a1578c531fe9bd7d9b3004e --- /dev/null +++ b/src/PLCRack3.cpp @@ -0,0 +1,742 @@ +/*----- PROTECTED REGION ID(PLCRack3.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : PLCRack3.cpp +// +// description : C++ source for the PLCRack3 class and its commands. +// The class is derived from Device. It represents the +// CORBA servant object which will be accessed from the +// network. All commands which can be executed on the +// PLCRack3 are implemented in this file. +// +// project : PLCRack3 +// +// This file is part of Tango device class. +// +// Tango 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. +// +// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include "PLCRack3.h" +#include "PLCRack3Class.h" +#include "plcsrvthread.h" +#include <iomanip> //used for debug dump of db +#include <netdb.h> +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3.cpp + +/** + * PLCRack3 class description: + * PLC Rack Triplo + */ + +//================================================================ +// The following table gives the correspondence +// between command and method names. +// +// Command name | Method name +//================================================================ +// State | Inherited (no method) +// Status | Inherited (no method) +//================================================================ + +//================================================================ +// Attributes managed are: +//================================================================ +// sezione2Temp | Tango::DevDouble Scalar +// sezione1Temp | Tango::DevDouble Scalar +// buncherTemp | Tango::DevDouble Scalar +// sezione2State | Tango::DevBoolean Scalar +// sezione1State | Tango::DevBoolean Scalar +// buncherState | Tango::DevBoolean Scalar +// sezione2FSHighState | Tango::DevBoolean Scalar +// sezione2TSState | Tango::DevBoolean Scalar +// sezione1FSHighState | Tango::DevBoolean Scalar +// sezione1TSState | Tango::DevBoolean Scalar +// buncherFSHighState | Tango::DevBoolean Scalar +// buncherTSState | Tango::DevBoolean Scalar +// sezione2FSLowState | Tango::DevBoolean Scalar +// sezione1FSLowState | Tango::DevBoolean Scalar +// buncherFSLowState | Tango::DevBoolean Scalar +//================================================================ + +namespace PLCRack3_ns +{ +/*----- PROTECTED REGION ID(PLCRack3::namespace_starting) ENABLED START -----*/ +/* clang-format on */ +// static initializations +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3::namespace_starting + +//-------------------------------------------------------- +/** + * Method : PLCRack3::PLCRack3() + * Description: Constructors for a Tango device + * implementing the classPLCRack3 + */ +//-------------------------------------------------------- +PLCRack3::PLCRack3(Tango::DeviceClass *cl, std::string &s) + : Socket2Client(cl, s.c_str()) +{ + /*----- PROTECTED REGION ID(PLCRack3::constructor_1) ENABLED START -----*/ + /* clang-format on */ + init_device(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::constructor_1 +} +//-------------------------------------------------------- +PLCRack3::PLCRack3(Tango::DeviceClass *cl, const char *s) + : Socket2Client(cl, s) +{ + /*----- PROTECTED REGION ID(PLCRack3::constructor_2) ENABLED START -----*/ + /* clang-format on */ + init_device(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::constructor_2 +} +//-------------------------------------------------------- +PLCRack3::PLCRack3(Tango::DeviceClass *cl, const char *s, const char *d) + : Socket2Client(cl, s, d) +{ + /*----- PROTECTED REGION ID(PLCRack3::constructor_3) ENABLED START -----*/ + /* clang-format on */ + init_device(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::constructor_3 +} +//-------------------------------------------------------- +PLCRack3::~PLCRack3() +{ + delete_device(); +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::delete_device() + * Description: will be called at device destruction or at init command + */ +//-------------------------------------------------------- +void PLCRack3::delete_device() +{ + DEBUG_STREAM << "PLCRack3::delete_device() " << device_name << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::delete_device) ENABLED START -----*/ + /* clang-format on */ + // Delete device allocated objects + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::delete_device + delete[] attr_sezione2Temp_read; + delete[] attr_sezione1Temp_read; + delete[] attr_buncherTemp_read; + delete[] attr_sezione2State_read; + delete[] attr_sezione1State_read; + delete[] attr_buncherState_read; + delete[] attr_sezione2FSHighState_read; + delete[] attr_sezione2TSState_read; + delete[] attr_sezione1FSHighState_read; + delete[] attr_sezione1TSState_read; + delete[] attr_buncherFSHighState_read; + delete[] attr_buncherTSState_read; + delete[] attr_sezione2FSLowState_read; + delete[] attr_sezione1FSLowState_read; + delete[] attr_buncherFSLowState_read; + + if (Tango::Util::instance()->is_svr_shutting_down()==false && + Tango::Util::instance()->is_device_restarting(device_name)==false && + Tango::Util::instance()->is_svr_starting()==false) + { + // If not shutting down call delete device for inherited object + Socket2Client_ns::Socket2Client::delete_device(); + } +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::init_device() + * Description: will be called at device initialization. + */ +//-------------------------------------------------------- +void PLCRack3::init_device() +{ + DEBUG_STREAM << "PLCRack3::init_device() create device " << device_name << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::init_device_before) ENABLED START -----*/ + /* clang-format on */ + // Initialization before get_device_property() call + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::init_device_before + + if (Tango::Util::instance()->is_svr_starting() == false && + Tango::Util::instance()->is_device_restarting(device_name)==false) + { + // If not starting up call init device for inherited object + Socket2Client_ns::Socket2Client::init_device(); + } + // No device property to be read from database + + attr_sezione2Temp_read = new Tango::DevDouble[1]; + attr_sezione1Temp_read = new Tango::DevDouble[1]; + attr_buncherTemp_read = new Tango::DevDouble[1]; + attr_sezione2State_read = new Tango::DevBoolean[1]; + attr_sezione1State_read = new Tango::DevBoolean[1]; + attr_buncherState_read = new Tango::DevBoolean[1]; + attr_sezione2FSHighState_read = new Tango::DevBoolean[1]; + attr_sezione2TSState_read = new Tango::DevBoolean[1]; + attr_sezione1FSHighState_read = new Tango::DevBoolean[1]; + attr_sezione1TSState_read = new Tango::DevBoolean[1]; + attr_buncherFSHighState_read = new Tango::DevBoolean[1]; + attr_buncherTSState_read = new Tango::DevBoolean[1]; + attr_sezione2FSLowState_read = new Tango::DevBoolean[1]; + attr_sezione1FSLowState_read = new Tango::DevBoolean[1]; + attr_buncherFSLowState_read = new Tango::DevBoolean[1]; + // No longer if mandatory property not set. + if (mandatoryNotDefined) + return; + + /*----- PROTECTED REGION ID(PLCRack3::init_device) ENABLED START -----*/ + /* clang-format on */ + // Initialize device + loop = new plcsrvthread(this); + loop->start(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::init_device +} + + +//-------------------------------------------------------- +/** + * Method : PLCRack3::always_executed_hook() + * Description: method always executed before any command is executed + */ +//-------------------------------------------------------- +void PLCRack3::always_executed_hook() +{ + DEBUG_STREAM << "PLCRack3::always_executed_hook() " << device_name << std::endl; + if (mandatoryNotDefined) + { + Tango::Except::throw_exception( + (const char *)"PROPERTY_NOT_SET", + get_status().c_str(), + (const char *)"PLCRack3::always_executed_hook()"); + } + /*----- PROTECTED REGION ID(PLCRack3::always_executed_hook) ENABLED START -----*/ + /* clang-format on */ + // code always executed before all requests + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::always_executed_hook +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::read_attr_hardware() + * Description: Hardware acquisition for attributes + */ +//-------------------------------------------------------- +void PLCRack3::read_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list)) +{ + DEBUG_STREAM << "PLCRack3::read_attr_hardware(std::vector<long> &attr_list) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_attr_hardware) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_attr_hardware +} +//-------------------------------------------------------- +/** + * Method : PLCRack3::write_attr_hardware() + * Description: Hardware writing for attributes + */ +//-------------------------------------------------------- +void PLCRack3::write_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list)) +{ + DEBUG_STREAM << "PLCRack3::write_attr_hardware(std::vector<long> &attr_list) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::write_attr_hardware) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::write_attr_hardware +} + +//-------------------------------------------------------- +/** + * Read attribute sezione2Temp related method + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_sezione2Temp(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_sezione2Temp(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_sezione2Temp) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_sezione2Temp_read = (double)(ntohs(db500.temp_sez2))/100.0; + attr.set_value(attr_sezione2Temp_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_sezione2Temp +} +//-------------------------------------------------------- +/** + * Read attribute sezione1Temp related method + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_sezione1Temp(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_sezione1Temp(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_sezione1Temp) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_sezione1Temp_read = (double)(ntohs(db500.temp_sez1))/100.0; + attr.set_value(attr_sezione1Temp_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_sezione1Temp +} +//-------------------------------------------------------- +/** + * Read attribute buncherTemp related method + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_buncherTemp(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_buncherTemp(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_buncherTemp) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_buncherTemp_read = (double)(ntohs(db500.temp_buncher))/100.0; + attr.set_value(attr_buncherTemp_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_buncherTemp +} +//-------------------------------------------------------- +/** + * Read attribute sezione2State related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_sezione2State(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_sezione2State(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_sezione2State) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_sezione2State_read = (Tango::DevBoolean)(db500.stato_sez2 != 0); + attr.set_value(attr_sezione2State_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_sezione2State +} +//-------------------------------------------------------- +/** + * Write attribute sezione2State related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::write_sezione2State(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "PLCRack3::write_sezione2State(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(PLCRack3::write_sezione2State) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + if(w_val) + send_cmd(StartSez2Cmd); + else + send_cmd(StopSez2Cmd); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::write_sezione2State +} +//-------------------------------------------------------- +/** + * Read attribute sezione1State related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_sezione1State(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_sezione1State(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_sezione1State) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_sezione1State_read = (Tango::DevBoolean)(db500.stato_sez1 != 0); + attr.set_value(attr_sezione1State_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_sezione1State +} +//-------------------------------------------------------- +/** + * Write attribute sezione1State related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::write_sezione1State(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "PLCRack3::write_sezione1State(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(PLCRack3::write_sezione1State) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + if(w_val) + send_cmd(StartSez1Cmd); + else + send_cmd(StopSez1Cmd); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::write_sezione1State +} +//-------------------------------------------------------- +/** + * Read attribute buncherState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_buncherState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_buncherState(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_buncherState) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_buncherState_read = (Tango::DevBoolean)(db500.stato_buncher != 0); + attr.set_value(attr_buncherState_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_buncherState +} +//-------------------------------------------------------- +/** + * Write attribute buncherState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::write_buncherState(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "PLCRack3::write_buncherState(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(PLCRack3::write_buncherState) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + if(w_val) + send_cmd(StartBuncherCmd); + else + send_cmd(StopBuncherCmd); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::write_buncherState +} +//-------------------------------------------------------- +/** + * Read attribute sezione2FSHighState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_sezione2FSHighState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_sezione2FSHighState(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_sezione2FSHighState) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_sezione2FSHighState_read = (Tango::DevBoolean)(db500.limite_superiore_portata2 != 0); + attr.set_value(attr_sezione2FSHighState_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_sezione2FSHighState +} +//-------------------------------------------------------- +/** + * Read attribute sezione2TSState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_sezione2TSState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_sezione2TSState(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_sezione2TSState) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_sezione2TSState_read = (Tango::DevBoolean)(db500.termostato_resistenza2 != 0); + attr.set_value(attr_sezione2TSState_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_sezione2TSState +} +//-------------------------------------------------------- +/** + * Read attribute sezione1FSHighState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_sezione1FSHighState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_sezione1FSHighState(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_sezione1FSHighState) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_sezione1FSHighState_read = (Tango::DevBoolean)(db500.limite_superiore_portata1 != 0); + attr.set_value(attr_sezione1FSHighState_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_sezione1FSHighState +} +//-------------------------------------------------------- +/** + * Read attribute sezione1TSState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_sezione1TSState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_sezione1TSState(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_sezione1TSState) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_sezione1TSState_read = (Tango::DevBoolean)(db500.termostato_resistenza1 != 0); + attr.set_value(attr_sezione1TSState_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_sezione1TSState +} +//-------------------------------------------------------- +/** + * Read attribute buncherFSHighState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_buncherFSHighState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_buncherFSHighState(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_buncherFSHighState) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_buncherFSHighState_read = (Tango::DevBoolean)(db500.limite_superiore_portata3 != 0); + attr.set_value(attr_buncherFSHighState_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_buncherFSHighState +} +//-------------------------------------------------------- +/** + * Read attribute buncherTSState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_buncherTSState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_buncherTSState(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_buncherTSState) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_buncherTSState_read = (Tango::DevBoolean)(db500.termostato_resistenza3 != 0); + attr.set_value(attr_buncherTSState_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_buncherTSState +} +//-------------------------------------------------------- +/** + * Read attribute sezione2FSLowState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_sezione2FSLowState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_sezione2FSLowState(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_sezione2FSLowState) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_sezione2FSLowState_read = (Tango::DevBoolean)(db500.limite_inferiore_portata2 != 0); + attr.set_value(attr_sezione2FSLowState_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_sezione2FSLowState +} +//-------------------------------------------------------- +/** + * Read attribute sezione1FSLowState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_sezione1FSLowState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_sezione1FSLowState(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_sezione1FSLowState) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_sezione1FSLowState_read = (Tango::DevBoolean)(db500.limite_inferiore_portata1 != 0); + attr.set_value(attr_sezione1FSLowState_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_sezione1FSLowState +} +//-------------------------------------------------------- +/** + * Read attribute buncherFSLowState related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCRack3::read_buncherFSLowState(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCRack3::read_buncherFSLowState(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(PLCRack3::read_buncherFSLowState) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + *attr_buncherFSLowState_read = (Tango::DevBoolean)(db500.limite_inferiore_buncher != 0); + attr.set_value(attr_buncherFSLowState_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::read_buncherFSLowState +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::add_dynamic_attributes() + * Description: Create the dynamic attributes if any + * for specified device. + */ +//-------------------------------------------------------- +void PLCRack3::add_dynamic_attributes() +{ + /*----- PROTECTED REGION ID(PLCRack3::add_dynamic_attributes) ENABLED START -----*/ + /* clang-format on */ + // Add your own code to create and add dynamic attributes if any + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::add_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::add_dynamic_commands() + * Description: Create the dynamic commands if any + * for specified device. + */ +//-------------------------------------------------------- +void PLCRack3::add_dynamic_commands() +{ + /*----- PROTECTED REGION ID(PLCRack3::add_dynamic_commands) ENABLED START -----*/ + /* clang-format on */ + // Add your own code to create and add dynamic commands if any + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::add_dynamic_commands +} + +/*----- PROTECTED REGION ID(PLCRack3::namespace_ending) ENABLED START -----*/ +/* clang-format on */ +// Additional Methods +void PLCRack3::send_cmd (uint16_t cmd) +{ + cmd_t prepared_cmd; + memset(&prepared_cmd, 0, sizeof(cmd_t)); + prepared_cmd.db_number=htons(cmd); + try { + send_frame((unsigned char *)&prepared_cmd, sizeof(cmd_t)); + } + catch(Tango::DevFailed e) { + set_state(Tango::FAULT); + set_status("Write command failed"); + Tango::Except::re_throw_exception(e, + (const char *) "write error", + (const char *) "write cmd error", + (const char *) "PLCRack3::send_cmd", Tango::ERR); + } +} +void PLCRack3::send_frame (unsigned char *query, size_t query_length) +{ + + for(size_t k=0;k<query_length;) + { + stringstream tmp; + size_t g; + tmp << "dbTX: "<<setw(3)<<setfill(' ')<<k<<" -> "; + for(g=0; g<10; g++) + { + if(k+g>=query_length) + break; + tmp << " " <<hex<<setw(2)<<setfill(' ')<< (int)(unsigned char)query[k+g]; + } + k+=g; + if(k<query_length) + { + tmp << " | "<<dec<<setw(3)<<setfill(' ')<<k<<hex<<" -> "; + for(g=0; g<10; g++) + { + if(k+g>=query_length) + break; + tmp << " " <<hex<<setw(2)<<setfill(' ')<< (int)(unsigned char)query[k+g]; + } + k+=g; + } + DEBUG_STREAM<<tmp.str()<<dec<<endl; + } + + vector<unsigned char> dtw; + dtw.reserve(query_length); + for (unsigned int i=0; i<query_length; ++i) + dtw.push_back(query[i]); + + write(dtw); +} +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3::namespace_ending +} // namespace diff --git a/src/PLCRack3.h b/src/PLCRack3.h new file mode 100644 index 0000000000000000000000000000000000000000..1bfaa2c6b3468e8e9ec46dddce9768c7bcf0a2fd --- /dev/null +++ b/src/PLCRack3.h @@ -0,0 +1,441 @@ +/*----- PROTECTED REGION ID(PLCRack3.h) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : PLCRack3.h +// +// description : Include file for the PLCRack3 class +// +// project : PLCRack3 +// +// This file is part of Tango device class. +// +// Tango 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. +// +// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#ifndef PLCRack3_H +#define PLCRack3_H + +#include <tango.h> +#include <Socket2Client.h> + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3.h + +#ifdef TANGO_LOG + // cppTango after c934adea (Merge branch 'remove-cout-definition' into 'main', 2022-05-23) + // nothing to do +#else + // cppTango 9.3-backports and older + #define TANGO_LOG cout + #define TANGO_LOG_INFO cout2 + #define TANGO_LOG_DEBUG cout3 +#endif // TANGO_LOG + +constexpr uint16_t StartSez1Cmd=200; +constexpr uint16_t StartSez2Cmd=201; +constexpr uint16_t StartBuncherCmd=202; +constexpr uint16_t StopSez1Cmd=210; +constexpr uint16_t StopSez2Cmd=211; +constexpr uint16_t StopBuncherCmd=212; + +/** + * PLCRack3 class description: + * PLC Rack Triplo + */ + + +namespace PLCRack3_ns +{ +/*----- PROTECTED REGION ID(PLCRack3::Additional Class Declarations) ENABLED START -----*/ +/* clang-format on */ +class plcsrvthread; +// Additional Class Declarations +#pragma pack(push,1) // exact fit - no padding + +typedef struct +{ + uint8_t timestamp[8]; +} date_and_time_t; + +typedef struct +{ + int16_t db_number; + date_and_time_t db_time; +} header_t; + +//DB XX +//typedef struct +//{ +// int16_t db_number; +// date_and_time_t db_time; +// uint16_t code; +//} cmd_t; + +//DB XX +typedef struct +{ + int16_t db_number; + date_and_time_t db_time; + uint16_t temp_sez1; + uint16_t temp_sez2; + uint16_t temp_buncher; +#if __BYTE_ORDER == __BIG_ENDIAN + uint8_t stato_sez2:1, //8.7 + stato_sez1:1, + stop_buncher:1, + stop_sez2:1, + stop_sez1:1, + start_buncher:1, + start_sez2:1, + start_sez1:1; //8.0 +#else + uint8_t start_sez1:1, //8.0 + start_sez2:1, + start_buncher:1, + stop_sez1:1, + stop_sez2:1, + stop_buncher:1, + stato_sez1:1, + stato_sez2:1; //8.7 +#endif +#if __BYTE_ORDER == __BIG_ENDIAN + uint8_t termostato_resistenza1:1, //9.7 + limite_superiore_portata3:1, + limite_superiore_portata2:1, + limite_superiore_portata1:1, + limite_inferiore_buncher:1, + limite_inferiore_portata2:1, + limite_inferiore_portata1:1, + stato_buncher:1; //9.0 +#else + uint8_t stato_buncher:1, //9.0 + limite_inferiore_portata1:1, + limite_inferiore_portata2:1, + limite_inferiore_buncher:1, + limite_superiore_portata1:1, + limite_superiore_portata2:1, + limite_superiore_portata3:1, + termostato_resistenza1:1; //9.7 +#endif +#if __BYTE_ORDER == __BIG_ENDIAN + uint8_t spare:6, //10.2-10.7 + termostato_resistenza3:1, //10.1 + termostato_resistenza2:1; //10.0 +#else + uint8_t termostato_resistenza2:1, //10.0 + termostato_resistenza3:1, //10.1 + spare:6; //10.2-10.7 +#endif + uint8_t spare_; +} data_t; + +typedef data_t cmd_t; +#pragma pack(pop) //back to whatever the previous packing mode was +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3::Additional Class Declarations + +class PLCRack3 : public Socket2Client_ns::Socket2Client +{ + +/*----- PROTECTED REGION ID(PLCRack3::Data Members) ENABLED START -----*/ +/* clang-format on */ +// Add your own data members +public: +bool abortflag; +friend class plcsrvthread; +plcsrvthread *loop; +data_t db500; +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3::Data Members + +// Device property data members +public: + + bool mandatoryNotDefined; + +// Attribute data members +public: + Tango::DevDouble *attr_sezione2Temp_read; + Tango::DevDouble *attr_sezione1Temp_read; + Tango::DevDouble *attr_buncherTemp_read; + Tango::DevBoolean *attr_sezione2State_read; + Tango::DevBoolean *attr_sezione1State_read; + Tango::DevBoolean *attr_buncherState_read; + Tango::DevBoolean *attr_sezione2FSHighState_read; + Tango::DevBoolean *attr_sezione2TSState_read; + Tango::DevBoolean *attr_sezione1FSHighState_read; + Tango::DevBoolean *attr_sezione1TSState_read; + Tango::DevBoolean *attr_buncherFSHighState_read; + Tango::DevBoolean *attr_buncherTSState_read; + Tango::DevBoolean *attr_sezione2FSLowState_read; + Tango::DevBoolean *attr_sezione1FSLowState_read; + Tango::DevBoolean *attr_buncherFSLowState_read; + +// Constructors and destructors +public: + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + PLCRack3(Tango::DeviceClass *cl,std::string &s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + PLCRack3(Tango::DeviceClass *cl,const char *s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + PLCRack3(Tango::DeviceClass *cl,const char *s,const char *d); + /** + * The device object destructor. + */ + ~PLCRack3(); + + +// Miscellaneous methods +public: + /* + * will be called at device destruction or at init command. + */ + void delete_device(); + /* + * Initialize the device + */ + virtual void init_device(); + /* + * Always executed method before execution command method. + */ + virtual void always_executed_hook(); + + /* + * Check if mandatory property has been set + */ + void check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop); + +// Attribute methods +public: + //-------------------------------------------------------- + /* + * Method : PLCRack3::read_attr_hardware() + * Description: Hardware acquisition for attributes. + */ + //-------------------------------------------------------- + virtual void read_attr_hardware(std::vector<long> &attr_list); + //-------------------------------------------------------- + /* + * Method : PLCRack3::write_attr_hardware() + * Description: Hardware writing for attributes. + */ + //-------------------------------------------------------- + virtual void write_attr_hardware(std::vector<long> &attr_list); + +/** + * Attribute sezione2Temp related methods + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_sezione2Temp(Tango::Attribute &attr); + virtual bool is_sezione2Temp_allowed(Tango::AttReqType type); +/** + * Attribute sezione1Temp related methods + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_sezione1Temp(Tango::Attribute &attr); + virtual bool is_sezione1Temp_allowed(Tango::AttReqType type); +/** + * Attribute buncherTemp related methods + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_buncherTemp(Tango::Attribute &attr); + virtual bool is_buncherTemp_allowed(Tango::AttReqType type); +/** + * Attribute sezione2State related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_sezione2State(Tango::Attribute &attr); + virtual void write_sezione2State(Tango::WAttribute &attr); + virtual bool is_sezione2State_allowed(Tango::AttReqType type); +/** + * Attribute sezione1State related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_sezione1State(Tango::Attribute &attr); + virtual void write_sezione1State(Tango::WAttribute &attr); + virtual bool is_sezione1State_allowed(Tango::AttReqType type); +/** + * Attribute buncherState related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_buncherState(Tango::Attribute &attr); + virtual void write_buncherState(Tango::WAttribute &attr); + virtual bool is_buncherState_allowed(Tango::AttReqType type); +/** + * Attribute sezione2FSHighState related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_sezione2FSHighState(Tango::Attribute &attr); + virtual bool is_sezione2FSHighState_allowed(Tango::AttReqType type); +/** + * Attribute sezione2TSState related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_sezione2TSState(Tango::Attribute &attr); + virtual bool is_sezione2TSState_allowed(Tango::AttReqType type); +/** + * Attribute sezione1FSHighState related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_sezione1FSHighState(Tango::Attribute &attr); + virtual bool is_sezione1FSHighState_allowed(Tango::AttReqType type); +/** + * Attribute sezione1TSState related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_sezione1TSState(Tango::Attribute &attr); + virtual bool is_sezione1TSState_allowed(Tango::AttReqType type); +/** + * Attribute buncherFSHighState related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_buncherFSHighState(Tango::Attribute &attr); + virtual bool is_buncherFSHighState_allowed(Tango::AttReqType type); +/** + * Attribute buncherTSState related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_buncherTSState(Tango::Attribute &attr); + virtual bool is_buncherTSState_allowed(Tango::AttReqType type); +/** + * Attribute sezione2FSLowState related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_sezione2FSLowState(Tango::Attribute &attr); + virtual bool is_sezione2FSLowState_allowed(Tango::AttReqType type); +/** + * Attribute sezione1FSLowState related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_sezione1FSLowState(Tango::Attribute &attr); + virtual bool is_sezione1FSLowState_allowed(Tango::AttReqType type); +/** + * Attribute buncherFSLowState related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_buncherFSLowState(Tango::Attribute &attr); + virtual bool is_buncherFSLowState_allowed(Tango::AttReqType type); + + + //-------------------------------------------------------- + /** + * Method : PLCRack3::add_dynamic_attributes() + * Description: Add dynamic attributes if any. + */ + //-------------------------------------------------------- + void add_dynamic_attributes(); + + + + +// Command related methods +public: + + + //-------------------------------------------------------- + /** + * Method : PLCRack3::add_dynamic_commands() + * Description: Add dynamic commands if any. + */ + //-------------------------------------------------------- + void add_dynamic_commands(); + +/*----- PROTECTED REGION ID(PLCRack3::Additional Method prototypes) ENABLED START -----*/ +/* clang-format on */ +// Additional Method prototypes +Tango::DevState socket_get_state(){/*return get_state2();*/return Tango::ON;} +void send_cmd (uint16_t cmd); +void send_frame (unsigned char *query, size_t query_length); +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3::Additional Method prototypes +}; + +/*----- PROTECTED REGION ID(PLCRack3::Additional Classes Definitions) ENABLED START -----*/ +/* clang-format on */ +// Additional Classes Definitions +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3::Additional Classes Definitions + +} // End of namespace + +#endif // PLCRack3_H diff --git a/src/PLCRack3.xmi b/src/PLCRack3.xmi new file mode 100644 index 0000000000000000000000000000000000000000..32df4c51d87d1c607cb806513fd3b4e6d4b099af --- /dev/null +++ b/src/PLCRack3.xmi @@ -0,0 +1,153 @@ +<?xml version="1.0" encoding="ASCII"?> +<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl"> + <classes name="PLCRack3" pogoRevision="9.7"> + <description description="PLC Rack Triplo" title="PLCRack3" sourcePath="/home/graziano/ws/ds/plcrack3/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="true" hasConcreteProperty="false" hasAbstractCommand="false" hasAbstractAttribute="false"> + <inheritances classname="Device_Impl" sourcePath=""/> + <inheritances classname="Socket2Client" sourcePath="../deps/socket2client/src"/> + <identification contact="at elettra.eu - graziano.scalamera" author="graziano.scalamera" emailDomain="elettra.eu" classFamily="SoftwareSystem" siteSpecific="" platform="Unix Like" bus="Ethernet" manufacturer="none" reference=""/> + </description> + <deviceProperties name="DeviceName" mandatory="true" description=""> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="true" concrete="true"/> + </deviceProperties> + <commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="none"> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Device state"> + <type xsi:type="pogoDsl:StateType"/> + </argout> + <status abstract="true" inherited="true" concrete="true"/> + </commands> + <commands name="Status" description="This command gets the device status (stored in its device_status data member) and returns it to the caller." execMethod="dev_status" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="none"> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Device status"> + <type xsi:type="pogoDsl:ConstStringType"/> + </argout> + <status abstract="true" inherited="true" concrete="true"/> + </commands> + <attributes name="sezione2Temp" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="sezione1Temp" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="buncherTemp" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="sezione2State" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="sezione1State" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="buncherState" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="sezione2FSHighState" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="sezione2TSState" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="sezione1FSHighState" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="sezione1TSState" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="buncherFSHighState" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="buncherTSState" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="sezione2FSLowState" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="sezione1FSLowState" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="buncherFSLowState" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <preferences docHome="./doc_html" makefileHome="$(TANGO_HOME)"/> + </classes> +</pogoDsl:PogoSystem> diff --git a/src/PLCRack3Class.cpp b/src/PLCRack3Class.cpp new file mode 100644 index 0000000000000000000000000000000000000000..97561d6954337a881ce3313abb7af45969707f0f --- /dev/null +++ b/src/PLCRack3Class.cpp @@ -0,0 +1,826 @@ +/*----- PROTECTED REGION ID(PLCRack3Class.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : PLCRack3Class.cpp +// +// description : C++ source for the PLCRack3Class. +// A singleton class derived from DeviceClass. +// It implements the command and attribute list +// and all properties and methods required +// by the PLCRack3 once per process. +// +// project : PLCRack3 +// +// This file is part of Tango device class. +// +// Tango 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. +// +// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include "PLCRack3Class.h" +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3Class.cpp + +//------------------------------------------------------------------- +/** + * Create PLCRack3Class singleton and + * return it in a C function for Python usage + */ +//------------------------------------------------------------------- +extern "C" { +#ifdef _TG_WINDOWS_ + +__declspec(dllexport) + +#endif + + Tango::DeviceClass *_create_PLCRack3_class(const char *name) { + return PLCRack3_ns::PLCRack3Class::init(name); + } +} + +namespace PLCRack3_ns +{ +//=================================================================== +// Initialize pointer for singleton pattern +//=================================================================== +PLCRack3Class *PLCRack3Class::_instance = NULL; + +//=================================================================== +// Class constants +//=================================================================== +//-------------------------------------------------------- +/** + * method : PLCRack3Class::PLCRack3Class(std::string &s) + * description : constructor for the PLCRack3Class + * + * @param s The class name + */ +//-------------------------------------------------------- +PLCRack3Class::PLCRack3Class(std::string &s):Socket2Client_ns::Socket2ClientClass(s) +{ + TANGO_LOG_INFO << "Entering PLCRack3Class constructor" << std::endl; + set_default_property(); + write_class_property(); + + /*----- PROTECTED REGION ID(PLCRack3Class::constructor) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::constructor + + TANGO_LOG_INFO << "Leaving PLCRack3Class constructor" << std::endl; +} + +//-------------------------------------------------------- +/** + * method : PLCRack3Class::~PLCRack3Class() + * description : destructor for the PLCRack3Class + */ +//-------------------------------------------------------- +PLCRack3Class::~PLCRack3Class() +{ + /*----- PROTECTED REGION ID(PLCRack3Class::destructor) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::destructor + + _instance = NULL; +} + + +//-------------------------------------------------------- +/** + * method : PLCRack3Class::init + * description : Create the object if not already done. + * Otherwise, just return a pointer to the object + * + * @param name The class name + */ +//-------------------------------------------------------- +PLCRack3Class *PLCRack3Class::init(const char *name) +{ + if (_instance == NULL) + { + try + { + std::string s(name); + _instance = new PLCRack3Class(s); + } + catch (std::bad_alloc &) + { + throw; + } + } + return _instance; +} + +//-------------------------------------------------------- +/** + * method : PLCRack3Class::instance + * description : Check if object already created, + * and return a pointer to the object + */ +//-------------------------------------------------------- +PLCRack3Class *PLCRack3Class::instance() +{ + if (_instance == NULL) + { + std::cerr << "Class is not initialized !!" << std::endl; + exit(-1); + } + return _instance; +} + + + +//=================================================================== +// Command execution method calls +//=================================================================== + +//=================================================================== +// Properties management +//=================================================================== +//-------------------------------------------------------- +/** + * Method : PLCRack3Class::get_class_property() + * Description: Get the class property for specified name. + */ +//-------------------------------------------------------- +Tango::DbDatum PLCRack3Class::get_class_property(std::string &prop_name) +{ + for (unsigned int i=0 ; i<cl_prop.size() ; i++) + if (cl_prop[i].name == prop_name) + return cl_prop[i]; + // if not found, returns an empty DbDatum + return Tango::DbDatum(prop_name); +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3Class::get_default_device_property() + * Description: Return the default value for device property. + */ +//-------------------------------------------------------- +Tango::DbDatum PLCRack3Class::get_default_device_property(std::string &prop_name) +{ + for (unsigned int i=0 ; i<dev_def_prop.size() ; i++) + if (dev_def_prop[i].name == prop_name) + return dev_def_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3Class::get_default_class_property() + * Description: Return the default value for class property. + */ +//-------------------------------------------------------- +Tango::DbDatum PLCRack3Class::get_default_class_property(std::string &prop_name) +{ + for (unsigned int i=0 ; i<cl_def_prop.size() ; i++) + if (cl_def_prop[i].name == prop_name) + return cl_def_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} + + +//-------------------------------------------------------- +/** + * Method : PLCRack3Class::set_default_property() + * Description: Set default property (class and device) for wizard. + * For each property, add to wizard property name and description. + * If default value has been set, add it to wizard property and + * store it in a DbDatum. + */ +//-------------------------------------------------------- +void PLCRack3Class::set_default_property() +{ + std::string prop_name; + std::string prop_desc; + std::string prop_def; + std::vector<std::string> vect_data; + + // Set Default Class Properties + + // Set Default device Properties +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3Class::write_class_property() + * Description: Set class description fields as property in database + */ +//-------------------------------------------------------- +void PLCRack3Class::write_class_property() +{ + // First time, check if database used + if (Tango::Util::_UseDb == false) + return; + + Tango::DbData data; + std::string classname = get_name(); + std::string header; + + // Put title + Tango::DbDatum title("ProjectTitle"); + std::string str_title("PLCRack3"); + title << str_title; + data.push_back(title); + + // Put Description + Tango::DbDatum description("Description"); + std::vector<std::string> str_desc; + str_desc.push_back("PLC Rack Triplo"); + description << str_desc; + data.push_back(description); + + // Put inheritance + Tango::DbDatum inher_datum("InheritedFrom"); + std::vector<std::string> inheritance; + inheritance.push_back("TANGO_BASE_CLASS"); + inher_datum << inheritance; + data.push_back(inher_datum); + + // Call database and and values + get_db_class()->put_property(data); +} + +//=================================================================== +// Factory methods +//=================================================================== + +//-------------------------------------------------------- +/** + * Method : PLCRack3Class::device_factory() + * Description: Create the device object(s) + * and store them in the device list + */ +//-------------------------------------------------------- +void PLCRack3Class::device_factory(const Tango::DevVarStringArray *devlist_ptr) +{ + /*----- PROTECTED REGION ID(PLCRack3Class::device_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::device_factory_before + + // Create devices and add it into the device list + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + TANGO_LOG_DEBUG << "Device name : " << (*devlist_ptr)[i].in() << std::endl; + device_list.push_back(new PLCRack3(this, (*devlist_ptr)[i])); + } + + // Manage dynamic attributes if any + erase_dynamic_attributes(devlist_ptr, get_class_attr()->get_attr_list()); + + // Export devices to the outside world + for (unsigned long i=1 ; i<=devlist_ptr->length() ; i++) + { + // Add dynamic attributes if any + PLCRack3 *dev = static_cast<PLCRack3 *>(device_list[device_list.size()-i]); + dev->add_dynamic_attributes(); + + // Check before if database used. + if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false)) + export_device(dev); + else + export_device(dev, dev->get_name().c_str()); + } + + /*----- PROTECTED REGION ID(PLCRack3Class::device_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::device_factory_after +} +//-------------------------------------------------------- +/** + * Method : PLCRack3Class::attribute_factory() + * Description: Create the attribute object(s) + * and store them in the attribute list + */ +//-------------------------------------------------------- +void PLCRack3Class::attribute_factory(std::vector<Tango::Attr *> &att_list) +{ + /*----- PROTECTED REGION ID(PLCRack3Class::attribute_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::attribute_factory_before + // Call atribute_factory for inherited class + Socket2Client_ns::Socket2ClientClass::attribute_factory(att_list); + + // Attribute : sezione2Temp + sezione2TempAttrib *sezione2temp = new sezione2TempAttrib(); + Tango::UserDefaultAttrProp sezione2temp_prop; + // description not set for sezione2Temp + // label not set for sezione2Temp + // unit not set for sezione2Temp + // standard_unit not set for sezione2Temp + // display_unit not set for sezione2Temp + // format not set for sezione2Temp + // max_value not set for sezione2Temp + // min_value not set for sezione2Temp + // max_alarm not set for sezione2Temp + // min_alarm not set for sezione2Temp + // max_warning not set for sezione2Temp + // min_warning not set for sezione2Temp + // delta_t not set for sezione2Temp + // delta_val not set for sezione2Temp + sezione2temp->set_default_properties(sezione2temp_prop); + // Not Polled + sezione2temp->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(sezione2temp); + + // Attribute : sezione1Temp + sezione1TempAttrib *sezione1temp = new sezione1TempAttrib(); + Tango::UserDefaultAttrProp sezione1temp_prop; + // description not set for sezione1Temp + // label not set for sezione1Temp + // unit not set for sezione1Temp + // standard_unit not set for sezione1Temp + // display_unit not set for sezione1Temp + // format not set for sezione1Temp + // max_value not set for sezione1Temp + // min_value not set for sezione1Temp + // max_alarm not set for sezione1Temp + // min_alarm not set for sezione1Temp + // max_warning not set for sezione1Temp + // min_warning not set for sezione1Temp + // delta_t not set for sezione1Temp + // delta_val not set for sezione1Temp + sezione1temp->set_default_properties(sezione1temp_prop); + // Not Polled + sezione1temp->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(sezione1temp); + + // Attribute : buncherTemp + buncherTempAttrib *bunchertemp = new buncherTempAttrib(); + Tango::UserDefaultAttrProp bunchertemp_prop; + // description not set for buncherTemp + // label not set for buncherTemp + // unit not set for buncherTemp + // standard_unit not set for buncherTemp + // display_unit not set for buncherTemp + // format not set for buncherTemp + // max_value not set for buncherTemp + // min_value not set for buncherTemp + // max_alarm not set for buncherTemp + // min_alarm not set for buncherTemp + // max_warning not set for buncherTemp + // min_warning not set for buncherTemp + // delta_t not set for buncherTemp + // delta_val not set for buncherTemp + bunchertemp->set_default_properties(bunchertemp_prop); + // Not Polled + bunchertemp->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(bunchertemp); + + // Attribute : sezione2State + sezione2StateAttrib *sezione2state = new sezione2StateAttrib(); + Tango::UserDefaultAttrProp sezione2state_prop; + // description not set for sezione2State + // label not set for sezione2State + // unit not set for sezione2State + // standard_unit not set for sezione2State + // display_unit not set for sezione2State + // format not set for sezione2State + // max_value not set for sezione2State + // min_value not set for sezione2State + // max_alarm not set for sezione2State + // min_alarm not set for sezione2State + // max_warning not set for sezione2State + // min_warning not set for sezione2State + // delta_t not set for sezione2State + // delta_val not set for sezione2State + sezione2state->set_default_properties(sezione2state_prop); + // Not Polled + sezione2state->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(sezione2state); + + // Attribute : sezione1State + sezione1StateAttrib *sezione1state = new sezione1StateAttrib(); + Tango::UserDefaultAttrProp sezione1state_prop; + // description not set for sezione1State + // label not set for sezione1State + // unit not set for sezione1State + // standard_unit not set for sezione1State + // display_unit not set for sezione1State + // format not set for sezione1State + // max_value not set for sezione1State + // min_value not set for sezione1State + // max_alarm not set for sezione1State + // min_alarm not set for sezione1State + // max_warning not set for sezione1State + // min_warning not set for sezione1State + // delta_t not set for sezione1State + // delta_val not set for sezione1State + sezione1state->set_default_properties(sezione1state_prop); + // Not Polled + sezione1state->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(sezione1state); + + // Attribute : buncherState + buncherStateAttrib *buncherstate = new buncherStateAttrib(); + Tango::UserDefaultAttrProp buncherstate_prop; + // description not set for buncherState + // label not set for buncherState + // unit not set for buncherState + // standard_unit not set for buncherState + // display_unit not set for buncherState + // format not set for buncherState + // max_value not set for buncherState + // min_value not set for buncherState + // max_alarm not set for buncherState + // min_alarm not set for buncherState + // max_warning not set for buncherState + // min_warning not set for buncherState + // delta_t not set for buncherState + // delta_val not set for buncherState + buncherstate->set_default_properties(buncherstate_prop); + // Not Polled + buncherstate->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(buncherstate); + + // Attribute : sezione2FSHighState + sezione2FSHighStateAttrib *sezione2fshighstate = new sezione2FSHighStateAttrib(); + Tango::UserDefaultAttrProp sezione2fshighstate_prop; + // description not set for sezione2FSHighState + // label not set for sezione2FSHighState + // unit not set for sezione2FSHighState + // standard_unit not set for sezione2FSHighState + // display_unit not set for sezione2FSHighState + // format not set for sezione2FSHighState + // max_value not set for sezione2FSHighState + // min_value not set for sezione2FSHighState + // max_alarm not set for sezione2FSHighState + // min_alarm not set for sezione2FSHighState + // max_warning not set for sezione2FSHighState + // min_warning not set for sezione2FSHighState + // delta_t not set for sezione2FSHighState + // delta_val not set for sezione2FSHighState + sezione2fshighstate->set_default_properties(sezione2fshighstate_prop); + // Not Polled + sezione2fshighstate->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(sezione2fshighstate); + + // Attribute : sezione2TSState + sezione2TSStateAttrib *sezione2tsstate = new sezione2TSStateAttrib(); + Tango::UserDefaultAttrProp sezione2tsstate_prop; + // description not set for sezione2TSState + // label not set for sezione2TSState + // unit not set for sezione2TSState + // standard_unit not set for sezione2TSState + // display_unit not set for sezione2TSState + // format not set for sezione2TSState + // max_value not set for sezione2TSState + // min_value not set for sezione2TSState + // max_alarm not set for sezione2TSState + // min_alarm not set for sezione2TSState + // max_warning not set for sezione2TSState + // min_warning not set for sezione2TSState + // delta_t not set for sezione2TSState + // delta_val not set for sezione2TSState + sezione2tsstate->set_default_properties(sezione2tsstate_prop); + // Not Polled + sezione2tsstate->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(sezione2tsstate); + + // Attribute : sezione1FSHighState + sezione1FSHighStateAttrib *sezione1fshighstate = new sezione1FSHighStateAttrib(); + Tango::UserDefaultAttrProp sezione1fshighstate_prop; + // description not set for sezione1FSHighState + // label not set for sezione1FSHighState + // unit not set for sezione1FSHighState + // standard_unit not set for sezione1FSHighState + // display_unit not set for sezione1FSHighState + // format not set for sezione1FSHighState + // max_value not set for sezione1FSHighState + // min_value not set for sezione1FSHighState + // max_alarm not set for sezione1FSHighState + // min_alarm not set for sezione1FSHighState + // max_warning not set for sezione1FSHighState + // min_warning not set for sezione1FSHighState + // delta_t not set for sezione1FSHighState + // delta_val not set for sezione1FSHighState + sezione1fshighstate->set_default_properties(sezione1fshighstate_prop); + // Not Polled + sezione1fshighstate->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(sezione1fshighstate); + + // Attribute : sezione1TSState + sezione1TSStateAttrib *sezione1tsstate = new sezione1TSStateAttrib(); + Tango::UserDefaultAttrProp sezione1tsstate_prop; + // description not set for sezione1TSState + // label not set for sezione1TSState + // unit not set for sezione1TSState + // standard_unit not set for sezione1TSState + // display_unit not set for sezione1TSState + // format not set for sezione1TSState + // max_value not set for sezione1TSState + // min_value not set for sezione1TSState + // max_alarm not set for sezione1TSState + // min_alarm not set for sezione1TSState + // max_warning not set for sezione1TSState + // min_warning not set for sezione1TSState + // delta_t not set for sezione1TSState + // delta_val not set for sezione1TSState + sezione1tsstate->set_default_properties(sezione1tsstate_prop); + // Not Polled + sezione1tsstate->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(sezione1tsstate); + + // Attribute : buncherFSHighState + buncherFSHighStateAttrib *buncherfshighstate = new buncherFSHighStateAttrib(); + Tango::UserDefaultAttrProp buncherfshighstate_prop; + // description not set for buncherFSHighState + // label not set for buncherFSHighState + // unit not set for buncherFSHighState + // standard_unit not set for buncherFSHighState + // display_unit not set for buncherFSHighState + // format not set for buncherFSHighState + // max_value not set for buncherFSHighState + // min_value not set for buncherFSHighState + // max_alarm not set for buncherFSHighState + // min_alarm not set for buncherFSHighState + // max_warning not set for buncherFSHighState + // min_warning not set for buncherFSHighState + // delta_t not set for buncherFSHighState + // delta_val not set for buncherFSHighState + buncherfshighstate->set_default_properties(buncherfshighstate_prop); + // Not Polled + buncherfshighstate->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(buncherfshighstate); + + // Attribute : buncherTSState + buncherTSStateAttrib *bunchertsstate = new buncherTSStateAttrib(); + Tango::UserDefaultAttrProp bunchertsstate_prop; + // description not set for buncherTSState + // label not set for buncherTSState + // unit not set for buncherTSState + // standard_unit not set for buncherTSState + // display_unit not set for buncherTSState + // format not set for buncherTSState + // max_value not set for buncherTSState + // min_value not set for buncherTSState + // max_alarm not set for buncherTSState + // min_alarm not set for buncherTSState + // max_warning not set for buncherTSState + // min_warning not set for buncherTSState + // delta_t not set for buncherTSState + // delta_val not set for buncherTSState + bunchertsstate->set_default_properties(bunchertsstate_prop); + // Not Polled + bunchertsstate->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(bunchertsstate); + + // Attribute : sezione2FSLowState + sezione2FSLowStateAttrib *sezione2fslowstate = new sezione2FSLowStateAttrib(); + Tango::UserDefaultAttrProp sezione2fslowstate_prop; + // description not set for sezione2FSLowState + // label not set for sezione2FSLowState + // unit not set for sezione2FSLowState + // standard_unit not set for sezione2FSLowState + // display_unit not set for sezione2FSLowState + // format not set for sezione2FSLowState + // max_value not set for sezione2FSLowState + // min_value not set for sezione2FSLowState + // max_alarm not set for sezione2FSLowState + // min_alarm not set for sezione2FSLowState + // max_warning not set for sezione2FSLowState + // min_warning not set for sezione2FSLowState + // delta_t not set for sezione2FSLowState + // delta_val not set for sezione2FSLowState + sezione2fslowstate->set_default_properties(sezione2fslowstate_prop); + // Not Polled + sezione2fslowstate->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(sezione2fslowstate); + + // Attribute : sezione1FSLowState + sezione1FSLowStateAttrib *sezione1fslowstate = new sezione1FSLowStateAttrib(); + Tango::UserDefaultAttrProp sezione1fslowstate_prop; + // description not set for sezione1FSLowState + // label not set for sezione1FSLowState + // unit not set for sezione1FSLowState + // standard_unit not set for sezione1FSLowState + // display_unit not set for sezione1FSLowState + // format not set for sezione1FSLowState + // max_value not set for sezione1FSLowState + // min_value not set for sezione1FSLowState + // max_alarm not set for sezione1FSLowState + // min_alarm not set for sezione1FSLowState + // max_warning not set for sezione1FSLowState + // min_warning not set for sezione1FSLowState + // delta_t not set for sezione1FSLowState + // delta_val not set for sezione1FSLowState + sezione1fslowstate->set_default_properties(sezione1fslowstate_prop); + // Not Polled + sezione1fslowstate->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(sezione1fslowstate); + + // Attribute : buncherFSLowState + buncherFSLowStateAttrib *buncherfslowstate = new buncherFSLowStateAttrib(); + Tango::UserDefaultAttrProp buncherfslowstate_prop; + // description not set for buncherFSLowState + // label not set for buncherFSLowState + // unit not set for buncherFSLowState + // standard_unit not set for buncherFSLowState + // display_unit not set for buncherFSLowState + // format not set for buncherFSLowState + // max_value not set for buncherFSLowState + // min_value not set for buncherFSLowState + // max_alarm not set for buncherFSLowState + // min_alarm not set for buncherFSLowState + // max_warning not set for buncherFSLowState + // min_warning not set for buncherFSLowState + // delta_t not set for buncherFSLowState + // delta_val not set for buncherFSLowState + buncherfslowstate->set_default_properties(buncherfslowstate_prop); + // Not Polled + buncherfslowstate->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(buncherfslowstate); + + + // Create a list of static attributes + create_static_attribute_list(get_class_attr()->get_attr_list()); + /*----- PROTECTED REGION ID(PLCRack3Class::attribute_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::attribute_factory_after +} +//-------------------------------------------------------- +/** + * Method : PLCRack3Class::pipe_factory() + * Description: Create the pipe object(s) + * and store them in the pipe list + */ +//-------------------------------------------------------- +void PLCRack3Class::pipe_factory() +{ + /*----- PROTECTED REGION ID(PLCRack3Class::pipe_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::pipe_factory_before + /*----- PROTECTED REGION ID(PLCRack3Class::pipe_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::pipe_factory_after +} +//-------------------------------------------------------- +/** + * Method : PLCRack3Class::command_factory() + * Description: Create the command object(s) + * and store them in the command list + */ +//-------------------------------------------------------- +void PLCRack3Class::command_factory() +{ + /*----- PROTECTED REGION ID(PLCRack3Class::command_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::command_factory_before + // Call command_factory for inherited class + Socket2Client_ns::Socket2ClientClass::command_factory(); + + + + /*----- PROTECTED REGION ID(PLCRack3Class::command_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::command_factory_after +} + +//=================================================================== +// Dynamic attributes related methods +//=================================================================== + +//-------------------------------------------------------- +/** + * method : PLCRack3Class::create_static_attribute_list + * description : Create the a list of static attributes + * + * @param att_list the created attribute list + */ +//-------------------------------------------------------- +void PLCRack3Class::create_static_attribute_list(std::vector<Tango::Attr *> &att_list) +{ + for (unsigned long i=0 ; i<att_list.size() ; i++) + { + std::string att_name(att_list[i]->get_name()); + transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower); + defaultAttList.push_back(att_name); + } + + TANGO_LOG_INFO << defaultAttList.size() << " attributes in default list" << std::endl; + + /*----- PROTECTED REGION ID(PLCRack3Class::create_static_att_list) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::create_static_att_list +} + + +//-------------------------------------------------------- +/** + * method : PLCRack3Class::erase_dynamic_attributes + * description : delete the dynamic attributes if any. + * + * @param devlist_ptr the device list pointer + * @param list of all attributes + */ +//-------------------------------------------------------- +void PLCRack3Class::erase_dynamic_attributes(const Tango::DevVarStringArray *devlist_ptr, std::vector<Tango::Attr *> &att_list) +{ + Tango::Util *tg = Tango::Util::instance(); + + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + Tango::DeviceImpl *dev_impl = tg->get_device_by_name(((std::string)(*devlist_ptr)[i]).c_str()); + PLCRack3 *dev = static_cast<PLCRack3 *> (dev_impl); + + std::vector<Tango::Attribute *> &dev_att_list = dev->get_device_attr()->get_attribute_list(); + std::vector<Tango::Attribute *>::iterator ite_att; + for (ite_att=dev_att_list.begin() ; ite_att != dev_att_list.end() ; ++ite_att) + { + std::string att_name((*ite_att)->get_name_lower()); + if ((att_name == "state") || (att_name == "status")) + continue; + std::vector<std::string>::iterator ite_str = find(defaultAttList.begin(), defaultAttList.end(), att_name); + if (ite_str == defaultAttList.end()) + { + TANGO_LOG_INFO << att_name << " is a UNWANTED dynamic attribute for device " << (*devlist_ptr)[i] << std::endl; + Tango::Attribute &att = dev->get_device_attr()->get_attr_by_name(att_name.c_str()); + dev->remove_attribute(att_list[att.get_attr_idx()], true, false); + --ite_att; + } + } + } + /*----- PROTECTED REGION ID(PLCRack3Class::erase_dynamic_attributes) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::erase_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3Class::get_attr_object_by_name() + * Description: returns Tango::Attr * object found by name + */ +//-------------------------------------------------------- +Tango::Attr *PLCRack3Class::get_attr_object_by_name(std::vector<Tango::Attr *> &att_list, std::string attname) +{ + std::vector<Tango::Attr *>::iterator it; + for (it=att_list.begin() ; it<att_list.end() ; ++it) + if ((*it)->get_name()==attname) + return (*it); + // Attr does not exist + return NULL; +} + + +/*----- PROTECTED REGION ID(PLCRack3Class::Additional Methods) ENABLED START -----*/ +/* clang-format on */ +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3Class::Additional Methods +} // namespace diff --git a/src/PLCRack3Class.h b/src/PLCRack3Class.h new file mode 100644 index 0000000000000000000000000000000000000000..aad7a80780da06afb9c008434586716b3885dc26 --- /dev/null +++ b/src/PLCRack3Class.h @@ -0,0 +1,313 @@ +/*----- PROTECTED REGION ID(PLCRack3Class.h) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : PLCRack3Class.h +// +// description : Include for the PLCRack3 root class. +// This class is the singleton class for +// the PLCRack3 device class. +// It contains all properties and methods which the +// PLCRack3 requires only once e.g. the commands. +// +// project : PLCRack3 +// +// This file is part of Tango device class. +// +// Tango 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. +// +// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#ifndef PLCRack3Class_H +#define PLCRack3Class_H + +#include <tango.h> +#include <Socket2ClientClass.h> +#include "PLCRack3.h" + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3Class.h + + +namespace PLCRack3_ns +{ +/*----- PROTECTED REGION ID(PLCRack3Class::classes for dynamic creation) ENABLED START -----*/ +/* clang-format on */ + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3Class::classes for dynamic creation + +//========================================= +// Define classes for attributes +//========================================= +// Attribute sezione2Temp class definition +class sezione2TempAttrib: public Tango::Attr +{ +public: + sezione2TempAttrib():Attr("sezione2Temp", + Tango::DEV_DOUBLE, Tango::READ) {} + ~sezione2TempAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_sezione2Temp(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_sezione2Temp_allowed(ty);} +}; + +// Attribute sezione1Temp class definition +class sezione1TempAttrib: public Tango::Attr +{ +public: + sezione1TempAttrib():Attr("sezione1Temp", + Tango::DEV_DOUBLE, Tango::READ) {} + ~sezione1TempAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_sezione1Temp(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_sezione1Temp_allowed(ty);} +}; + +// Attribute buncherTemp class definition +class buncherTempAttrib: public Tango::Attr +{ +public: + buncherTempAttrib():Attr("buncherTemp", + Tango::DEV_DOUBLE, Tango::READ) {} + ~buncherTempAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_buncherTemp(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_buncherTemp_allowed(ty);} +}; + +// Attribute sezione2State class definition +class sezione2StateAttrib: public Tango::Attr +{ +public: + sezione2StateAttrib():Attr("sezione2State", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {} + ~sezione2StateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_sezione2State(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<PLCRack3 *>(dev))->write_sezione2State(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_sezione2State_allowed(ty);} +}; + +// Attribute sezione1State class definition +class sezione1StateAttrib: public Tango::Attr +{ +public: + sezione1StateAttrib():Attr("sezione1State", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {} + ~sezione1StateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_sezione1State(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<PLCRack3 *>(dev))->write_sezione1State(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_sezione1State_allowed(ty);} +}; + +// Attribute buncherState class definition +class buncherStateAttrib: public Tango::Attr +{ +public: + buncherStateAttrib():Attr("buncherState", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {} + ~buncherStateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_buncherState(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<PLCRack3 *>(dev))->write_buncherState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_buncherState_allowed(ty);} +}; + +// Attribute sezione2FSHighState class definition +class sezione2FSHighStateAttrib: public Tango::Attr +{ +public: + sezione2FSHighStateAttrib():Attr("sezione2FSHighState", + Tango::DEV_BOOLEAN, Tango::READ) {} + ~sezione2FSHighStateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_sezione2FSHighState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_sezione2FSHighState_allowed(ty);} +}; + +// Attribute sezione2TSState class definition +class sezione2TSStateAttrib: public Tango::Attr +{ +public: + sezione2TSStateAttrib():Attr("sezione2TSState", + Tango::DEV_BOOLEAN, Tango::READ) {} + ~sezione2TSStateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_sezione2TSState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_sezione2TSState_allowed(ty);} +}; + +// Attribute sezione1FSHighState class definition +class sezione1FSHighStateAttrib: public Tango::Attr +{ +public: + sezione1FSHighStateAttrib():Attr("sezione1FSHighState", + Tango::DEV_BOOLEAN, Tango::READ) {} + ~sezione1FSHighStateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_sezione1FSHighState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_sezione1FSHighState_allowed(ty);} +}; + +// Attribute sezione1TSState class definition +class sezione1TSStateAttrib: public Tango::Attr +{ +public: + sezione1TSStateAttrib():Attr("sezione1TSState", + Tango::DEV_BOOLEAN, Tango::READ) {} + ~sezione1TSStateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_sezione1TSState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_sezione1TSState_allowed(ty);} +}; + +// Attribute buncherFSHighState class definition +class buncherFSHighStateAttrib: public Tango::Attr +{ +public: + buncherFSHighStateAttrib():Attr("buncherFSHighState", + Tango::DEV_BOOLEAN, Tango::READ) {} + ~buncherFSHighStateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_buncherFSHighState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_buncherFSHighState_allowed(ty);} +}; + +// Attribute buncherTSState class definition +class buncherTSStateAttrib: public Tango::Attr +{ +public: + buncherTSStateAttrib():Attr("buncherTSState", + Tango::DEV_BOOLEAN, Tango::READ) {} + ~buncherTSStateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_buncherTSState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_buncherTSState_allowed(ty);} +}; + +// Attribute sezione2FSLowState class definition +class sezione2FSLowStateAttrib: public Tango::Attr +{ +public: + sezione2FSLowStateAttrib():Attr("sezione2FSLowState", + Tango::DEV_BOOLEAN, Tango::READ) {} + ~sezione2FSLowStateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_sezione2FSLowState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_sezione2FSLowState_allowed(ty);} +}; + +// Attribute sezione1FSLowState class definition +class sezione1FSLowStateAttrib: public Tango::Attr +{ +public: + sezione1FSLowStateAttrib():Attr("sezione1FSLowState", + Tango::DEV_BOOLEAN, Tango::READ) {} + ~sezione1FSLowStateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_sezione1FSLowState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_sezione1FSLowState_allowed(ty);} +}; + +// Attribute buncherFSLowState class definition +class buncherFSLowStateAttrib: public Tango::Attr +{ +public: + buncherFSLowStateAttrib():Attr("buncherFSLowState", + Tango::DEV_BOOLEAN, Tango::READ) {} + ~buncherFSLowStateAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCRack3 *>(dev))->read_buncherFSLowState(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCRack3 *>(dev))->is_buncherFSLowState_allowed(ty);} +}; + + +/** + * The PLCRack3Class singleton definition + */ + +#ifdef _TG_WINDOWS_ +class __declspec(dllexport) PLCRack3Class : public Socket2Client_ns::Socket2ClientClass +#else +class PLCRack3Class : public Socket2Client_ns::Socket2ClientClass +#endif +{ + /*----- PROTECTED REGION ID(PLCRack3Class::Additional DServer data members) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3Class::Additional DServer data members + + public: + // write class properties data members + Tango::DbData cl_prop; + Tango::DbData cl_def_prop; + Tango::DbData dev_def_prop; + // Method prototypes + static PLCRack3Class *init(const char *); + static PLCRack3Class *instance(); + ~PLCRack3Class(); + Tango::DbDatum get_class_property(std::string &); + Tango::DbDatum get_default_device_property(std::string &); + Tango::DbDatum get_default_class_property(std::string &); + + protected: + PLCRack3Class(std::string &); + static PLCRack3Class *_instance; + void command_factory(); + void attribute_factory(std::vector<Tango::Attr *> &); + void pipe_factory(); + void write_class_property(); + void set_default_property(); + void get_class_property(); + std::string get_cvstag(); + std::string get_cvsroot(); + + private: + void device_factory(TANGO_UNUSED(const Tango::DevVarStringArray *)); + void create_static_attribute_list(std::vector<Tango::Attr *> &); + void erase_dynamic_attributes(const Tango::DevVarStringArray *,std::vector<Tango::Attr *> &); + std::vector<std::string> defaultAttList; + Tango::Attr *get_attr_object_by_name(std::vector<Tango::Attr *> &att_list, std::string attname); +}; + +} // End of namespace + +#endif // PLCRack3_H diff --git a/src/PLCRack3StateMachine.cpp b/src/PLCRack3StateMachine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..64504393b382928e53449be9faa6b6b1fbf597e2 --- /dev/null +++ b/src/PLCRack3StateMachine.cpp @@ -0,0 +1,331 @@ +/*----- PROTECTED REGION ID(PLCRack3StateMachine.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : PLCRack3StateMachine.cpp +// +// description : State machine file for the PLCRack3 class +// +// project : PLCRack3 +// +// This file is part of Tango device class. +// +// Tango 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. +// +// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + +#include "PLCRack3.h" + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3::PLCRack3StateMachine.cpp + +//================================================================ +// States | Description +//================================================================ + + +namespace PLCRack3_ns +{ +//================================================= +// Attributes Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_sezione2Temp_allowed() + * Description: Execution allowed for sezione2Temp attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_sezione2Temp_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for sezione2Temp attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::sezione2TempStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione2TempStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_sezione1Temp_allowed() + * Description: Execution allowed for sezione1Temp attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_sezione1Temp_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for sezione1Temp attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::sezione1TempStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione1TempStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_buncherTemp_allowed() + * Description: Execution allowed for buncherTemp attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_buncherTemp_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for buncherTemp attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::buncherTempStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::buncherTempStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_sezione2State_allowed() + * Description: Execution allowed for sezione2State attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_sezione2State_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for sezione2State attribute in Write access. + /*----- PROTECTED REGION ID(PLCRack3::sezione2StateStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione2StateStateAllowed_WRITE + + // Not any excluded states for sezione2State attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::sezione2StateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione2StateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_sezione1State_allowed() + * Description: Execution allowed for sezione1State attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_sezione1State_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for sezione1State attribute in Write access. + /*----- PROTECTED REGION ID(PLCRack3::sezione1StateStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione1StateStateAllowed_WRITE + + // Not any excluded states for sezione1State attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::sezione1StateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione1StateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_buncherState_allowed() + * Description: Execution allowed for buncherState attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_buncherState_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for buncherState attribute in Write access. + /*----- PROTECTED REGION ID(PLCRack3::buncherStateStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::buncherStateStateAllowed_WRITE + + // Not any excluded states for buncherState attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::buncherStateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::buncherStateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_sezione2FSHighState_allowed() + * Description: Execution allowed for sezione2FSHighState attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_sezione2FSHighState_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for sezione2FSHighState attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::sezione2FSHighStateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione2FSHighStateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_sezione2TSState_allowed() + * Description: Execution allowed for sezione2TSState attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_sezione2TSState_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for sezione2TSState attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::sezione2TSStateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione2TSStateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_sezione1FSHighState_allowed() + * Description: Execution allowed for sezione1FSHighState attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_sezione1FSHighState_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for sezione1FSHighState attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::sezione1FSHighStateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione1FSHighStateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_sezione1TSState_allowed() + * Description: Execution allowed for sezione1TSState attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_sezione1TSState_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for sezione1TSState attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::sezione1TSStateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione1TSStateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_buncherFSHighState_allowed() + * Description: Execution allowed for buncherFSHighState attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_buncherFSHighState_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for buncherFSHighState attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::buncherFSHighStateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::buncherFSHighStateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_buncherTSState_allowed() + * Description: Execution allowed for buncherTSState attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_buncherTSState_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for buncherTSState attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::buncherTSStateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::buncherTSStateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_sezione2FSLowState_allowed() + * Description: Execution allowed for sezione2FSLowState attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_sezione2FSLowState_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for sezione2FSLowState attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::sezione2FSLowStateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione2FSLowStateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_sezione1FSLowState_allowed() + * Description: Execution allowed for sezione1FSLowState attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_sezione1FSLowState_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for sezione1FSLowState attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::sezione1FSLowStateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::sezione1FSLowStateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCRack3::is_buncherFSLowState_allowed() + * Description: Execution allowed for buncherFSLowState attribute + */ +//-------------------------------------------------------- +bool PLCRack3::is_buncherFSLowState_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for buncherFSLowState attribute in read access. + /*----- PROTECTED REGION ID(PLCRack3::buncherFSLowStateStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // PLCRack3::buncherFSLowStateStateAllowed_READ + return true; +} + + +//================================================= +// Commands Allowed Methods +//================================================= + + +/*----- PROTECTED REGION ID(PLCRack3::PLCRack3StateAllowed.AdditionalMethods) ENABLED START -----*/ +/* clang-format on */ +// Additional Methods +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3::PLCRack3StateAllowed.AdditionalMethods + +} // End of namespace diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..271851cb2bd9bcd6b13294c47528dcb0a8712c2c --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,88 @@ +/*----- PROTECTED REGION ID(PLCRack3::main.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : main.cpp +// +// description : C++ source for the PLCRack3 device server main. +// The main rule is to initialize (and create) the Tango +// system and to create the DServerClass singleton. +// The main should be the same for every Tango device server. +// +// project : PLCRack3 +// +// This file is part of Tango device class. +// +// Tango 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. +// +// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= +#include <tango.h> + +// Check if crash reporting is used. +#if defined(ENABLE_CRASH_REPORT) +# include <crashreporting/crash_report.h> +#else +# define DECLARE_CRASH_HANDLER +# define INSTALL_CRASH_HANDLER +#endif + +DECLARE_CRASH_HANDLER + +int main(int argc,char *argv[]) +{ + INSTALL_CRASH_HANDLER + Tango::Util *tg = nullptr; + try + { + // Initialize the device server + //---------------------------------------- + tg = Tango::Util::init(argc,argv); + + // Create the device server singleton + // which will create everything + //---------------------------------------- + tg->server_init(false); + + // Run the endless loop + //---------------------------------------- + std::cout << "Ready to accept request" << std::endl; + tg->server_run(); + } + catch (std::bad_alloc &) + { + std::cout << "Can't allocate memory to store device object !!!" << std::endl; + std::cout << "Exiting" << std::endl; + } + catch (CORBA::Exception &e) + { + Tango::Except::print_exception(e); + + std::cout << "Received a CORBA_Exception" << std::endl; + std::cout << "Exiting" << std::endl; + } + + if(tg) + { + tg->server_cleanup(); + } + return(0); +} + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // PLCRack3::main.cpp diff --git a/src/plcsrvthread.cpp b/src/plcsrvthread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a0953a2b94acbc984ed9118b8ede9f8b3759902d --- /dev/null +++ b/src/plcsrvthread.cpp @@ -0,0 +1,406 @@ +/* + * plcsrvthread.cpp + * + * 2009/07/16 - SF: first release + * + * + */ + +#include "plcsrvthread.h" +#include <iomanip> //used for debug dump of db +#include <netdb.h> + +namespace PLCRack3_ns{ + + +/* + * plcsrvthread::run() + * Run + */ +void plcsrvthread::run(void *) +{ + DEBUG_STREAM << "plcsrvthread::run() entering..." << endl; + int pausemicro = 3000000; + server_started=0; + push_counter = 0; + allow_push = true; + + + buf = new char[2*BUF_LEN]; + while (!t_PLCRack3->abortflag) { + if(server_started==0) + { + Srv_Prepare(); + } + else + { + t_PLCRack3->set_state(Tango::FAULT); + t_PLCRack3->set_status("srv not connected"); + } + + usleep(pausemicro); + DEBUG_STREAM << "plcsrvthread::run() trying to reconnect" << endl; + } + delete [] buf; +} + + + + +void plcsrvthread::Srv_Prepare(void) +{ + DEBUG_STREAM << "plcsrvthread::"<<__func__<<": entering..." << endl; + char *save_buf_ptr = &buf[0];; + timeval t_now; + gettimeofday(&last_read, NULL); + while (!t_PLCRack3->abortflag) + { + bool connection_ok = false; + + server_started=1; //fake + Tango::DevState dp_state=Tango::FAULT; + try + { + dp_state = t_PLCRack3->socket_get_state(); + if(dp_state == Tango::ON) + connection_ok = true; + } + catch(Tango::DevFailed &e) + { + INFO_STREAM << __func__ << ": error reading socket state="<<e.errors[0].desc; + sleep(1); + } + + if(connection_ok) + {//connection established + DEBUG_STREAM<<"plcsrvthread::Srv_Prepare() connection ok"<<endl; + errcount =0; + first_mesg = true; + cnt = 0; + buf = save_buf_ptr; + memset (buf,0,2*BUF_LEN); + + do + { + gettimeofday(&t_now, NULL); + double diff_s = t_now.tv_sec - last_read.tv_sec; + if(diff_s > 30) + { + t_PLCRack3->set_state(Tango::ALARM); + t_PLCRack3->set_status("Timeout waiting PLC data"); + } + + while(cnt > 0) + { + header_t *head; + head = reinterpret_cast<header_t *>(&buf[0]); + uint16_t btype = head->db_number; + btype = ntohs(btype); + if(btype == 0) + { + cnt--; + buf++; + DEBUG_STREAM << "plcsrvthread::run() looking for header, now " << cnt << " in buffer"<<endl; + if(cnt == 0) + { + buf = save_buf_ptr; + memset (buf,0,2*BUF_LEN); + INFO_STREAM << __func__ << ": " << cnt << " unknown bytes in buffer, type="<<btype<<", emptying"; + } + } + else + { + break; + } + } + + //DEBUG_STREAM << "plcsrvthread::Srv_Prepare()going to read from sock" << endl; + try + { + Tango::DevLong count=t_PLCRack3->input_length(); + if(count > 0) + { + if(count+cnt > BUF_LEN) + count = BUF_LEN-cnt; + vector<unsigned char> dtr; + t_PLCRack3->read(count, dtr); + for (unsigned int i=0; i<dtr.size(); ++i) + { + buf[i] = dtr[i]; + } + gettimeofday(&last_read, NULL); + INFO_STREAM << __func__ << ": read " << count << " now " << cnt+count << " in buffer" << endl; + } + else + { + timespec time_to_sleep; + time_to_sleep.tv_sec=0; + //time_to_sleep.tv_nsec= 0.5 * 1000000L;//0.5ms + //time_to_sleep.tv_nsec= 10 * 1000000L;//100ms + time_to_sleep.tv_nsec= 100 * 1000000L;//100ms + //time_to_sleep.tv_nsec= 500 * 1000000L;//500ms + nanosleep(&time_to_sleep, NULL); + } + cnt += count; + if(t_PLCRack3->get_state() != Tango::RUNNING) + { + t_PLCRack3->set_status("PLC OK"); + t_PLCRack3->set_state(Tango::RUNNING); + } + } + catch(Tango::DevFailed &e) + { + stringstream tmp; + tmp << "Error reading " << e.errors[0].desc; + INFO_STREAM << __func__ << ": " << tmp.str(); + cnt = -1; + t_PLCRack3->set_state(Tango::FAULT); + t_PLCRack3->set_status(tmp.str()); + } + + if (cnt < 0 ) + { + break; + } + else if (cnt == 0) + { + //DEBUG_STREAM<<"plcsrvthread::Srv_Prepare() read 0 char"<<endl; + continue; + } + else + { //reading ok + //INFO_STREAM << "plcsrvthread::run() in else cnt=" << cnt <<endl; + header_t *head; + head = reinterpret_cast<header_t *>(&buf[0]); + uint16_t btype = head->db_number; + btype = ntohs(btype); + size_t ui_size = sizeof(data_t);//TODO + INFO_STREAM << "plcsrvthread::run() before while cnt=" << cnt << " ui_size="<<ui_size <<endl; + while(cnt < ui_size && cnt >= 0) + { + if(cnt > 0) + DEBUG_STREAM << "plcsrvthread::run() after while cnt=" << cnt << " ui_size="<<ui_size <<endl; + if(cnt < ui_size) + { + try + { + Tango::DevLong count=t_PLCRack3->input_length(); + //INFO_STREAM << "plcsrvthread::run() in while count=" << count <<endl; + if(count > 0) + { + if(BUF_LEN-cnt < ui_size-cnt) + { + INFO_STREAM << "plcsrvthread::run() bytes missing=" << ui_size-cnt << " cannot fit in buffer, " << BUF_LEN-cnt << " bytes left!" <<endl; + //empty buffer and restart reading + buf = save_buf_ptr; + memset (buf,0,2*BUF_LEN); + cnt = 0; + } + //read just what's missing + if(count > ui_size-cnt) + count = ui_size-cnt; + if(count > BUF_LEN-cnt) + count = BUF_LEN-cnt; + vector<unsigned char> dtr; + t_PLCRack3->read(count, dtr); + for (unsigned int i=0; i<dtr.size(); ++i) + { + buf[cnt+i] = dtr[i]; + } + gettimeofday(&last_read, NULL); + head = reinterpret_cast<header_t *>(&buf[0]); + btype = head->db_number; + btype = ntohs(btype); + } + else + { + timespec time_to_sleep; + time_to_sleep.tv_sec=0; + //time_to_sleep.tv_nsec= 0.5 * 1000000L;//0.5ms + //time_to_sleep.tv_nsec= 10 * 1000000L;//100ms + time_to_sleep.tv_nsec= 100 * 1000000L;//100ms//TODO + nanosleep(&time_to_sleep, NULL); + } + cnt += count; + if(count > 0) + INFO_STREAM << "plcsrvthread::run() receiving for type:" << btype <<" "<< count << " more bytes, total received="<<cnt<< " expected="<<ui_size <<endl; + } + catch(Tango::DevFailed &e) + { + INFO_STREAM << __func__ << ": error reading " << e.errors[0].desc; + cnt = -1; + sleep(1); + } + } + + if(cnt < ui_size) + { + if(cnt > 0) + INFO_STREAM << "plcsrvthread::run() still missing bytes total received=" << cnt <<" < expected="<< ui_size << endl; + continue; + } + + INFO_STREAM << "plcsrvthread::run() finally received complete type:" << btype <<" length:"<< ui_size<<endl; + + }//end while(cnt < ui_size) + while(cnt > 0) + { + head = reinterpret_cast<header_t *>(&buf[0]); + btype = head->db_number; + btype = ntohs(btype); + size_t ui_size = sizeof(data_t);//TODO + DEBUG_STREAM << "plcsrvthread::run() read " << cnt << " in buffer, type:" << btype <<endl; + if(cnt >= ui_size && ui_size > 0) + { + parse_message(btype, ui_size); + cnt -= ui_size; + if(cnt > 0) + { + buf += ui_size; + INFO_STREAM << "plcsrvthread::run() after parsing " << ui_size << " there are " << cnt <<" remaining in buffer. buf moved ahead of "<< ui_size << " -> " << hex<<setw(2)<<setfill(' ')<< (int)(unsigned char) buf[0]<<","<<(int)(unsigned char) buf[1]<<","<< (int)(unsigned char) buf[2]<<","<<(int)(unsigned char) buf[3]<<","<< (int)(unsigned char) buf[4]<<","<<(int)(unsigned char) buf[5]<<","<<(int)(unsigned char) buf[6]<<","<< (int)(unsigned char) buf[7]<<endl; + } + else + { + buf = save_buf_ptr; + memset (buf,0,2*BUF_LEN); + INFO_STREAM << "plcsrvthread::run() buf empty after parsing cnt=" << cnt; + break; + } + } + else if(cnt > 0 && ui_size == 0 && btype == 0) + { + buf = save_buf_ptr; + memset (buf,0,2*BUF_LEN); + INFO_STREAM << "plcsrvthread::run() emptying buffer cnt=" << cnt << " type==0 && ui_size==0"; + cnt = 0; + break; + } + else if(cnt < ui_size) + { + INFO_STREAM << __func__ << " exiting parsing loop with " << cnt << " remaining, type=" << btype << " size="<<ui_size; + char tmp[BUF_LEN]; + memcpy(tmp,buf,cnt); + buf = save_buf_ptr; + memset (buf,0,2*BUF_LEN); + memcpy(buf,tmp,cnt); + break; + } + } + DEBUG_STREAM << "plcsrvthread::run() end of loop while (cnt > 0)"<<endl; + + } // end of message-print else + // end of do loop statement + }while ((cnt >= 0)&&(!t_PLCRack3->abortflag)); // do loop condition + }//end of accept else + } // end of while (1) +// close(t_PLCRack3->sock); + server_started=0; + return; + +} + + +void plcsrvthread::parse_message(uint16_t type, uint16_t size) +{ + INFO_STREAM << __func__ << ": entering parsing, type="<<type<< " size=" <<size << endl; + for(int k=0;k<size;) + { + stringstream tmp; + int g; + tmp << "DB"<<type<<": "<<setw(3)<<setfill(' ')<<k<<" -> "; + for(g=0; g<10; g++) + { + if(k+g>=size) + break; + tmp << " " <<hex<<setw(2)<<setfill(' ')<< (int)(unsigned char)buf[k+g]; + } + k+=g; + if(k<size) + { + tmp << " | "<<dec<<setw(3)<<setfill(' ')<<k<<hex<<" -> "; + for(g=0; g<10; g++) + { + if(k+g>=size) + break; + tmp << " " <<hex<<setw(2)<<setfill(' ')<< (int)(unsigned char)buf[k+g]; + } + k+=g; + } + DEBUG_STREAM<<tmp.str()<<dec<<endl; + } + switch(type) + { + case 500: + case 0: + case 200: + case 201: + case 202: + case 210: + case 211: + case 212: + INFO_STREAM << __func__ << ": received DB500 size=" <<size << endl; + memcpy(&t_PLCRack3->db500, buf, size); + break; + default: + INFO_STREAM << __func__ << ": message NOT recognized, type "<<type<< " size=" <<size << endl; + break; + } +} + +uint16_t plcsrvthread::plc_swap(uint16_t in) +{ + return ((in>>8)|((in&0x00ff)<<8)); +} + + + +uint32_t plcsrvthread::plc_swaplong(uint32_t in) +{ + return ((in>>16)|((in&0x0000ffff)<<16)); +} + +float plcsrvthread::htonf(float val_f) +{ + float *ret_val; + uint32_t *val_l; + uint32_t ret_val_l; + + val_l = (uint32_t *)&val_f; +#if 1 + ret_val_l = htonl(*val_l); +#else +# if __BYTE_ORDER == __LITTLE_ENDIAN + ret_val_l = __bswap_32(*val_l); +#else + ret_val_l = *val_l; +#endif +#endif + ret_val=(float *)&ret_val_l; + + return *ret_val; +} + +float plcsrvthread::ntohf(float val_f) +{ + float *ret_val; + uint32_t *val_l; + uint32_t ret_val_l; + + val_l = (uint32_t *)&val_f; +#if 1 + ret_val_l = ntohl(*val_l); +#else +# if __BYTE_ORDER == __LITTLE_ENDIAN + ret_val_l = __bswap_32(*val_l); +#else + ret_val_l = *val_l; +#endif +#endif + ret_val=(float *)&ret_val_l; + + return *ret_val; +} + +}//namespace + + diff --git a/src/plcsrvthread.h b/src/plcsrvthread.h new file mode 100644 index 0000000000000000000000000000000000000000..8f36b9f506fa79c0655ecc2f8b3cdfb53233009d --- /dev/null +++ b/src/plcsrvthread.h @@ -0,0 +1,92 @@ +/* + * plcsrvthread.h + * + */ + +#ifndef PLCSRVTHREAD_H +#define PLCSRVTHREAD_H + +#include <omnithread.h> +#include <tango.h> +#include <stdio.h> +#include <errno.h> + +#include <PLCRack3.h> + + +//size of the message buffer +#define BUF_LEN 200000 + +namespace PLCRack3_ns{ + +class plcsrvthread : public omni_thread, public Tango::LogAdapter{ + + private: + PLCRack3 *t_PLCRack3; + bool db20_received; + bool db24_received; + + public: + + plcsrvthread(PLCRack3 *s):Tango::LogAdapter(s){ + t_PLCRack3 = s; + + first_mesg = true; + db20_received = false; + db24_received = false; + }; + + ~plcsrvthread() { + }; +// void *StartUndetached(){ +// start_undetached(); +// } +// void *run_undetached(void *); + + protected: + void run(void *); + + int errcount; + struct timeval last_read; + char frame2[BUF_LEN]; + u_short olddata; + // tstamp_t time_before; + // intlck_db53 lastmsg; + + Tango::DeviceProxy *mydevice; + Tango::DeviceAttribute arl; + + // logalarm_t local_mesg; + + int cnt, cnt2, server_started; + bool first_mesg; + + // struct sembuf operations[1]; + int retval; + int id; + + //char buf[BUF_LEN]; + char *buf; + unsigned long push_counter; + bool allow_push; + + void Srv_Prepare(void); + uint16_t plc_swap(uint16_t in); + uint32_t plc_swaplong(uint32_t in); + void parse_message(uint16_t type, uint16_t size); + +// long ll, mm; + u_short v; + int brk; + + int idx; + + float ntohf(float val_f); + float htonf(float val_f); +}; /* end class plcsrvthread() */ + +}// namespace + +#endif + +/* EOF */