diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..79907543670791b802525873551c7af56fd81035 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +NAME_SRV = plcfastint-srv +MYSQL_INC= `mysql_config --include` +MYSQL_LIB= `mysql_config --libs_r` +CXXFLAGS += $(MYSQL_INC) +LDFLAGS += $(MYSQL_LIB) + +include ../makefiles/Make-9.2.2.in diff --git a/src/ClassFactory.cpp b/src/ClassFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7eec961db868299e6e22e6629a3b1112aa5b354b --- /dev/null +++ b/src/ClassFactory.cpp @@ -0,0 +1,58 @@ +/*----- PROTECTED REGION ID(PLCsocket::ClassFactory.cpp) ENABLED START -----*/ +static const char *RcsId = "$Header: /home/cvsadm/cvsroot/fermi/servers/plcsocket/src/ClassFactory.cpp,v 1.4 2017-02-23 08:42:46 graziano Exp $"; +//+============================================================================= +// +// file : ClassFactory.cpp +// +// description : C++ source for the class_factory method of the DServer +// device class. This method is responsible to create +// all class singletin for a device server. It is called +// at device server startup +// +// project : TANGO Device Server +// +// $Author: graziano $ +// +// $Revision: 1.4 $ +// +// $Log: ClassFactory.cpp,v $ +// Revision 1.4 2017-02-23 08:42:46 graziano +// Aggiunta comando disable_interlock_id5 +// +// Revision 1.3 2014-04-22 13:02:39 graziano +// new pogo +// added command EnableBPM_11_2 +// +// Revision 1.2 2008-04-23 08:26:19 sara +// added queue for logging on db +// +// Revision 1.1.1.1 2007/01/22 11:01:52 sara +// First release of PLC socket server +// +// copyleft : European Synchrotron Radiation Facility +// BP 220, Grenoble 38043 +// FRANCE +// +//-============================================================================= +// +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +// +// (c) - Software Engineering Group - ESRF +//============================================================================= + + +#include <tango.h> +#include <PLCsocketClass.h> + +/** + * Create PLCsocketClass singleton and store it in DServer object. + */ + +void Tango::DServer::class_factory() +{ + + add_class(PLCsocket_ns::PLCsocketClass::init("PLCsocket")); + +} +/*----- PROTECTED REGION END -----*/ // PLCsocket::ClassFactory.cpp diff --git a/src/PLCsocket.cpp b/src/PLCsocket.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9463ea7d6f64d2b7321c02300ca22ba0c54ca72b --- /dev/null +++ b/src/PLCsocket.cpp @@ -0,0 +1,2064 @@ +/*----- PROTECTED REGION ID(PLCsocket.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: PLCsocket.cpp,v 1.8 2017-02-23 08:42:46 graziano Exp $"; +//============================================================================= +// +// file : PLCsocket.cpp +// +// description : C++ source for the PLCsocket 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 +// PLCsocket are implemented in this file. +// +// project : PLC interlock server +// +// 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/>. +// +// $Author: graziano $ +// +// $Revision: 1.8 $ +// $Date: 2017-02-23 08:42:46 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include <tango.h> +#include <PLCsocketClass.h> +#include <iostream> +#include "plclgthread.h" +#include "plctimingthread.h" +#include "plcsrvthread.h" +#include <iomanip> //used for debug dump of db + +/*----- PROTECTED REGION END -----*/ // PLCsocket.cpp + +/** + * PLCsocket class description: + * + */ + +//================================================================ +// The following table gives the correspondence +// between command and method names. +// +// Command name | Method name +//================================================================ +// State | Inherited (no method) +// Status | Inherited (no method) +// Beam_dump | beam_dump +// Send_ack | send_ack +// Seq_state_rst | seq_state_rst +// Test_debug | test_debug +// EnableBPM11_2 | enable_bpm11_2 +// DisableInterlockSCW | disable_interlock_scw +// DisableInterlockID5 | disable_interlock_id5 +//================================================================ + +//================================================================ +// Attributes managed are: +//================================================================ +// IThreshold | Tango::DevBoolean Scalar +// Libera3hc | Tango::DevBoolean Scalar +// BeamDumpPLCA10 | Tango::DevBoolean Scalar +// BeamAbi | Tango::DevBoolean Scalar +// CallPm | Tango::DevBoolean Scalar +// AlIThreshold | Tango::DevBoolean Scalar +// AlLibera3hc | Tango::DevBoolean Scalar +// Seq_state | Tango::DevString Scalar +// EnableBPM11_2 | Tango::DevBoolean Scalar +// OpenId | Tango::DevBoolean Spectrum ( max = 16) +// DiodeDet | Tango::DevBoolean Spectrum ( max = 16) +// LiberaSt | Tango::DevBoolean Spectrum ( max = 16) +// LiberaNd | Tango::DevBoolean Spectrum ( max = 16) +// IlkEnable | Tango::DevBoolean Spectrum ( max = 16) +// AlOpenId | Tango::DevBoolean Spectrum ( max = 16) +// AlDiodeDet | Tango::DevBoolean Spectrum ( max = 16) +// AlLiberaSt | Tango::DevBoolean Spectrum ( max = 16) +// AlLiberaNd | Tango::DevBoolean Spectrum ( max = 16) +// Seq_num | Tango::DevDouble Spectrum ( max = 3) +//================================================================ + +namespace PLCsocket_ns +{ +/*----- PROTECTED REGION ID(PLCsocket::namespace_starting) ENABLED START -----*/ + +// static initializations + +/*----- PROTECTED REGION END -----*/ // PLCsocket::namespace_starting + +//-------------------------------------------------------- +/** + * Method : PLCsocket::PLCsocket() + * Description : Constructors for a Tango device + * implementing the classPLCsocket + */ +//-------------------------------------------------------- +PLCsocket::PLCsocket(Tango::DeviceClass *cl, string &s) + : TANGO_BASE_CLASS(cl, s.c_str()) +{ + /*----- PROTECTED REGION ID(PLCsocket::constructor_1) ENABLED START -----*/ + init_device(); + + /*----- PROTECTED REGION END -----*/ // PLCsocket::constructor_1 +} +//-------------------------------------------------------- +PLCsocket::PLCsocket(Tango::DeviceClass *cl, const char *s) + : TANGO_BASE_CLASS(cl, s) +{ + /*----- PROTECTED REGION ID(PLCsocket::constructor_2) ENABLED START -----*/ + init_device(); + + /*----- PROTECTED REGION END -----*/ // PLCsocket::constructor_2 +} +//-------------------------------------------------------- +PLCsocket::PLCsocket(Tango::DeviceClass *cl, const char *s, const char *d) + : TANGO_BASE_CLASS(cl, s, d) +{ + /*----- PROTECTED REGION ID(PLCsocket::constructor_3) ENABLED START -----*/ + init_device(); + + /*----- PROTECTED REGION END -----*/ // PLCsocket::constructor_3 +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::delete_device() + * Description : will be called at device destruction or at init command + */ +//-------------------------------------------------------- +void PLCsocket::delete_device() +{ + DEBUG_STREAM << "PLCsocket::delete_device() " << device_name << endl; + /*----- PROTECTED REGION ID(PLCsocket::delete_device) ENABLED START -----*/ + + // Delete device allocated objects + // Delete device's allocated object + int t_finish = hbeat;// time in msec to wait for the thread to complete + abortflag = 1; //stops thread + + int secs = (int)t_finish/1000; + int nanos = (t_finish*1000-secs)*1000000000; + omni_thread::sleep(secs,nanos);// for the last thread to finish + usleep(11000000); + if(attr_Seq_num_read) { + delete attr_Seq_num_read; + attr_Seq_num_read = 0; + } + if(sock) + close(sock); + if(new_sd) + close(new_sd); + + if(fdlog) + close(fdlog); + delete mutex; + mysql_close(&dbp); + + /*----- PROTECTED REGION END -----*/ // PLCsocket::delete_device + delete[] attr_EnableBPM11_2_read; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::init_device() + * Description : will be called at device initialization. + */ +//-------------------------------------------------------- +void PLCsocket::init_device() +{ + DEBUG_STREAM << "PLCsocket::init_device() create device " << device_name << endl; + /*----- PROTECTED REGION ID(PLCsocket::init_device_before) ENABLED START -----*/ + + // Initialization before get_device_property() call + + logloop = 0; + tmloop = 0; + srvloop = 0; + fdlog = 0; + logfile2 = "/ELETTRA_log/logs/plcsocket-srv.log"; + sock = 0; + logging_msg = 0; + + abortflag = 0; + is_beamdumpcmd = 0; + + attr_OpenId_read = 0; + attr_DiodeDet_read = 0; + attr_LiberaSt_read = 0; + attr_LiberaNd_read = 0; + attr_IThreshold_read = 0; + attr_Libera3hc_read = 0; + attr_BeamDumpPLCA10_read = 0; + attr_IlkEnable_read = 0; + attr_BeamAbi_read = 0; + attr_CallPm_read = 0; + attr_Seq_num_read = 0; + seq[0] = 0;//seq num + seq[1] = 0;//seq change + seq[2] = 0;//seq sent + s_state = NORMAL_ST; + + message.campo_ingressi_1 = 0xffff; + message.campo_ingressi_2 = 0xffff; + message.campo_ingressi_3 = 0xffff; + message.campo_ingressi_4 = 0xffff; + message.campo_ingressi_5 = 0xffff; + message.memo_allarmi_1 = 0xffff; + message.memo_allarmi_2 = 0xffff; + message.memo_allarmi_3 = 0xffff; + message.memo_allarmi_4 = 0xffff; + message.memo_allarmi_5 = 0xffff; + message.campo_uscite_1 = 0x0000; + message.campo_uscite_2 = 0xffff; + + + + /*----- PROTECTED REGION END -----*/ // PLCsocket::init_device_before + + + // Get the device properties from database + get_device_property(); + + attr_EnableBPM11_2_read = new Tango::DevBoolean[1]; + /*----- PROTECTED REGION ID(PLCsocket::init_device) ENABLED START -----*/ + + // Initialize device + + memset (old_timestamp,0,TSTAMP_SIZE); + memset (new_timestamp,0,TSTAMP_SIZE); + memset (last_ck_read,0,TSTAMP_SIZE); + if(logfile.empty()) + logfile.append(logfile2); + if(ack_policy.empty()) + ack_policy.append(AUTO_ACK); + + Tango::Database *db = new Tango::Database(); + Tango::DbData db_data; + + + db_data.push_back(Tango::DbDatum("openId")); + db_data.push_back(Tango::DbDatum("diodeDet")); + db_data.push_back(Tango::DbDatum("liberaSt")); + db_data.push_back(Tango::DbDatum("liberaNd")); + db_data.push_back(Tango::DbDatum("IThreshold")); + db_data.push_back(Tango::DbDatum("libera3hc")); + db_data.push_back(Tango::DbDatum("beamDumpPLCA10")); + db_data.push_back(Tango::DbDatum("beamAbi")); + + db->get_device_attribute_property(get_name(), db_data); //read from db attribute properties + + memset(&dbmessages, 0, (sizeof(dbm))); + + static att_db all_dbm[] = { + {"openId", &(openid_m[0][0]), &(dbmessages.mesg_openid[0][0]), 16}, + {"diodeDet", &(diodedet_m[0][0]), &(dbmessages.mesg_diodedet[0][0]), 16}, + {"liberaSt", &(liberast_m[0][0]), &(dbmessages.mesg_liberast[0][0]), 16}, + {"liberaNd", &(liberand_m[0][0]), &(dbmessages.mesg_liberand[0][0]), 16}, + {"IThreshold", &(ithreshold_m[0]), &(dbmessages.mesg_ithreshold[0]), 1}, + {"libera3hc", &(libera3hc_m[0]), &(dbmessages.mesg_libera3hc[0]), 1}, + {"beamDumpPLCA10", &(plca10_m[0]), &(dbmessages.mesg_plca10[0]), 1}, + {"beamAbi", &(beam_dump_m[0]), &(dbmessages.mesg_beamabi[0]), 1} + }; + + for(int l=0;l<16;l++){ + memset(mesg_openid[l][0],0,35); + memset(mesg_diodedet[l][0],0,35); + memset(mesg_liberast[l][0],0,35); + memset(mesg_liberand[l][0],0,35); + memset(mesg_openid[l][1],0,35); + memset(mesg_diodedet[l][1],0,35); + memset(mesg_liberast[l][1],0,35); + memset(mesg_liberand[l][1],0,35); + } + for(int l=0;l<2;l++){ + memset(mesg_ithreshold[l],0,35); + memset(mesg_libera3hc[l],0,35); + memset(mesg_plca10[l],0,35); + memset(mesg_beamabi[l],0,35); + } + for (int i=0; i< db_data.size(); i++){ + long nb_prop; + string &att_name = db_data[i].name; + db_data[i] >> nb_prop; + for(int z=0;z<8;z++){ + if (att_name == all_dbm[z].att_name){ //select attributes to be monitored + int found1 = 0; + int found2 = 0; + for (int k=0;k < nb_prop;k++){ //get single property + i++; + string &prop_name = db_data[i].name; + string p_val; + db_data[i] >> p_val; + int pos = 0; + int cnt = 0; + //p_val.resize(1+p_val.length()); + //p_val.append("\n"); + if(prop_name == "db_labels_al"){ //found alarm message for db + vector<string> stvalues; + db_data[i] >> stvalues; + for (int h=0; h<stvalues.size();h++){ + strcpy(&((all_dbm[z].res_m)[cnt][0]),stvalues.at(h).c_str()); + + } +// for(int k=0;k<p_val.length();k++){ +// if(p_val.c_str()[k]=='\n'){ +// strcpy(&((all_dbm[z].res_m)[cnt][0]), ((p_val.substr(pos, k-pos)).substr(0,34)).c_str()); +// pos = k+1; +// cnt+=2; +// } +// } + found1 = 1; + } + cnt = 1; + if(prop_name == "db_labels_ok"){ //found ok message for db + vector<string> stvalues; + db_data[i] >> stvalues; + for (int h=0; h<stvalues.size();h++){ + strcpy(&((all_dbm[z].res_m)[cnt][0]),stvalues.at(h).c_str()); + + } +// for(int k=0;k<p_val.length();k++){ +// if(p_val.c_str()[k]=='\n'){ +// strcpy(&((all_dbm[z].res_m)[cnt][0]), ((p_val.substr(pos, k-pos)).substr(0,34)).c_str()); +// pos = k+1; +// cnt+=2; +// } +// } + found2 = 1; + } + } + if(found1 == 0){ //no alarm message for db, add default message + for(int j=0;j<2*all_dbm[z].dim;j+=2){ + strcpy(&((all_dbm[z].res_m)[j][0]), &((all_dbm[z].fixed_m)[j][0])); + } + } + if(found2 == 0){ //no ok message for db, add default message + for(int j=1;j<2*all_dbm[z].dim;j+=2){ + strcpy(&((all_dbm[z].res_m)[j][0]), &((all_dbm[z].fixed_m)[j][0])); + } + } + } + } + } + + for(int j=0, i=0;j<2*NUM_ID;j++, i++){ + strcpy(mesg_openid[i][0], &((all_dbm[0].res_m)[j][0])); + j++; + strcpy(mesg_openid[i][1], &((all_dbm[0].res_m)[j][0])); + } + for(int j=0, i=0;j<2*NUM_DIODE;j++, i++){ + strcpy(mesg_diodedet[i][0], &((all_dbm[1].res_m)[j][0])); + j++; + strcpy(mesg_diodedet[i][1], &((all_dbm[1].res_m)[j][0])); + } + for(int j=0, i=0;j<2*NUM_LIBERA1;j++, i++){ + strcpy(mesg_liberast[i][0], &((all_dbm[2].res_m)[j][0])); + j++; + strcpy(mesg_liberast[i][1], &((all_dbm[2].res_m)[j][0])); + } + for(int j=0, i=0;j<2*NUM_LIBERA2;j++, i++){ + strcpy(mesg_liberand[i][0], &((all_dbm[3].res_m)[j][0])); + j++; + strcpy(mesg_liberand[i][1], &((all_dbm[3].res_m)[j][0])); + } + strcpy(mesg_ithreshold[0], &((all_dbm[4].res_m)[0][0])); + strcpy(mesg_ithreshold[1], &((all_dbm[4].res_m)[1][0])); + strcpy(mesg_libera3hc[0], &((all_dbm[5].res_m)[0][0])); + strcpy(mesg_libera3hc[1], &((all_dbm[5].res_m)[1][0])); + strcpy(mesg_plca10[0], &((all_dbm[6].res_m)[0][0])); + strcpy(mesg_plca10[1], &((all_dbm[6].res_m)[1][0])); + strcpy(mesg_beamabi[0], &((all_dbm[7].res_m)[0][0])); + strcpy(mesg_beamabi[1], &((all_dbm[7].res_m)[1][0])); + + + + logging_msg = logging; + int fail_flag = 0; + ip_host = ipaddr; + char buf3[BUF_LAB_SIZE]; + memset (buf3,0,sizeof(buf3)); + memset (&message,0,sizeof(intlck_libera_t)); + memset (&old_message,0,sizeof(intlck_libera_t)); + memset (&i_answer,0,sizeof(ilk_answer_t)); + + //mutual exclusion + mutex = new omni_mutex::omni_mutex(); + + + //semaphore for message list + argument.val = 0; + semid = semget(1000, 1, 0666 | IPC_CREAT); + if(semid < 0){ + DEBUG_STREAM << "PLCsocket::cannot create semaphore" << endl; + } + if(semctl(semid, 0, SETVAL, argument) < 0){ + DEBUG_STREAM << "PLCsocket::Cannot init semaphore value to 0" << endl; + } + else{ + DEBUG_STREAM << "PLCsocket::Semaphore initialized" << endl; + } + + logloop = new plclgthread::plclgthread(this); + logloop->StartUndetached(); + + tmloop = new plctimingthread::plctimingthread(this); + tmloop->StartUndetached(); + + if(sock > 0) + close(sock); + srvloop = new plcsrvthread::plcsrvthread(this); + srvloop->StartUndetached(); + DEBUG_STREAM << "PLCsocket::init_device() started thread" << endl; + + + //get mysql connection + if(!mysql_init(&dbp)){ + if(get_state()!=Tango::FAULT) + set_state(Tango::DISABLE); + set_status("init db log error"); + DEBUG_STREAM << "PLCsocket::init_device() init db log error" << endl; + } + my_bool my_auto_reconnect=1; + if(mysql_options(&dbp,MYSQL_OPT_RECONNECT,&my_auto_reconnect) !=0){ + if(get_state()!=Tango::FAULT) + set_state(Tango::DISABLE); + set_status("mysql auto reconnection error"); + DEBUG_STREAM << "PLCsocket::init_device() mysql auto reconnection error" << mysql_error(&dbp) << endl; + } + string dbhost; + string dbuser; + string dbpw; + string dbname; + string dbport; + int dbportint; + vector<string>::iterator iter = db_param.begin(); + dbhost = ((string)*iter); + iter++; + dbuser = ((string)*iter); + iter++; + dbpw = ((string)*iter); + iter++; + dbname = ((string)*iter); + iter++; + dbport = ((string)*iter); + dbportint = atoi(dbport.c_str()); + if(dbportint!=0){ + if(!mysql_real_connect(&dbp, dbhost.c_str(), dbuser.c_str(), dbpw.c_str(), dbname.c_str(), dbportint, NULL, 0)){ +// if(!mysql_real_connect(&dbp, "log.ecs.elettra.trieste.it", "ilk", "InterLock", "FastInterlock", 3306, NULL, 0)){ + if(get_state()!=Tango::FAULT) + set_state(Tango::DISABLE); + set_status("db log connection error"); + DEBUG_STREAM << "PLCsocket::init_device() db log connection error" << endl; + } + else{ + if(get_state()==Tango::DISABLE) + set_state(Tango::ON); + set_status("db log connected"); + } + } + else{ + if(get_state()!=Tango::FAULT) + set_state(Tango::DISABLE); + set_status("db log connection error"); + DEBUG_STREAM << "PLCsocket::init_device() db log connection error" << endl; + } + + //open the logging file + if(logging_msg == 1){ + + if((fdlog = open(logfile.c_str(), O_RDWR | O_APPEND , S_IRWXU | S_IRWXG | S_IRWXO)) < 0){ + DEBUG_STREAM << "PLCsocket::init_device() cannot open log file:" << strerror(errno) << endl; + if(get_state()!=Tango::FAULT) + set_state(Tango::DISABLE); + set_status("logging file opening error"); + } + else{ + int writefile = 0; + int ln = 0; + string pie; + pie.append("seq_num\t\t"); + pie.append("seq_chng\t"); + pie.append("seq_sent\t"); + pie.append("Timestamp\t\t"); + pie.append("OpenId\t"); + pie.append("DiodeD\t"); + pie.append("LiberaS\t"); + pie.append("LiberaN\t"); + pie.append("Lib_3hc\t"); + pie.append("I<20mA\t"); + pie.append("BD_A10\t"); + pie.append("IlkEnbl\t"); + pie.append("BeamAbi\t"); + pie.append("CallPm"); + for(int j=0;j<strlen(pie.c_str());j++){ + buf3[ln+j] = pie.c_str()[j]; + } + ln+=strlen(pie.c_str()); + buf3[ln] = '\n'; + if((writefile = write (fdlog, buf3, ln+1)<0)){ + DEBUG_STREAM << "PLCsocket::init_device() write head file failure:" << strerror(errno) << endl; + } + + } + } + DEBUG_STREAM << "PLCsocket::init_device() finished" << endl; + /*----- PROTECTED REGION END -----*/ // PLCsocket::init_device +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::get_device_property() + * Description : Read database to initialize property data members. + */ +//-------------------------------------------------------- +void PLCsocket::get_device_property() +{ + /*----- PROTECTED REGION ID(PLCsocket::get_device_property_before) ENABLED START -----*/ + + // Initialize property data members + + /*----- PROTECTED REGION END -----*/ // PLCsocket::get_device_property_before + + + // Read device properties from database. + Tango::DbData dev_prop; + dev_prop.push_back(Tango::DbDatum("Ipaddr")); + dev_prop.push_back(Tango::DbDatum("Wport")); + dev_prop.push_back(Tango::DbDatum("Rport")); + dev_prop.push_back(Tango::DbDatum("Srv_host")); + dev_prop.push_back(Tango::DbDatum("Hbeat")); + dev_prop.push_back(Tango::DbDatum("Labels")); + dev_prop.push_back(Tango::DbDatum("Logfile")); + dev_prop.push_back(Tango::DbDatum("Db_param")); + dev_prop.push_back(Tango::DbDatum("Logging")); + dev_prop.push_back(Tango::DbDatum("Timeadjust")); + dev_prop.push_back(Tango::DbDatum("Ack_policy")); + + // is there at least one property to be read ? + if (dev_prop.size()>0) + { + // Call database and extract values + if (Tango::Util::instance()->_UseDb==true) + get_db_device()->get_property(dev_prop); + + // get instance on PLCsocketClass to get class property + Tango::DbDatum def_prop, cl_prop; + PLCsocketClass *ds_class = + (static_cast<PLCsocketClass *>(get_device_class())); + int i = -1; + + // Try to initialize Ipaddr from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> ipaddr; + else { + // Try to initialize Ipaddr from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> ipaddr; + } + // And try to extract Ipaddr value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> ipaddr; + + // Try to initialize Wport from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> wport; + else { + // Try to initialize Wport from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> wport; + } + // And try to extract Wport value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> wport; + + // Try to initialize Rport from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> rport; + else { + // Try to initialize Rport from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> rport; + } + // And try to extract Rport value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> rport; + + // Try to initialize Srv_host from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> srv_host; + else { + // Try to initialize Srv_host from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> srv_host; + } + // And try to extract Srv_host value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> srv_host; + + // Try to initialize Hbeat from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> hbeat; + else { + // Try to initialize Hbeat from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> hbeat; + } + // And try to extract Hbeat value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> hbeat; + + // Try to initialize Labels from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> labels; + else { + // Try to initialize Labels from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> labels; + } + // And try to extract Labels value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> labels; + + // Try to initialize Logfile from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> logfile; + else { + // Try to initialize Logfile from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> logfile; + } + // And try to extract Logfile value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> logfile; + + // Try to initialize Db_param from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> db_param; + else { + // Try to initialize Db_param from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> db_param; + } + // And try to extract Db_param value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> db_param; + + // Try to initialize Logging from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> logging; + else { + // Try to initialize Logging from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> logging; + } + // And try to extract Logging value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> logging; + + // Try to initialize Timeadjust from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> timeadjust; + else { + // Try to initialize Timeadjust from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> timeadjust; + } + // And try to extract Timeadjust value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> timeadjust; + + // Try to initialize Ack_policy from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> ack_policy; + else { + // Try to initialize Ack_policy from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> ack_policy; + } + // And try to extract Ack_policy value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> ack_policy; + + } + + /*----- PROTECTED REGION ID(PLCsocket::get_device_property_after) ENABLED START -----*/ + + // Check device property data members init + + /*----- PROTECTED REGION END -----*/ // PLCsocket::get_device_property_after +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::always_executed_hook() + * Description : method always executed before any command is executed + */ +//-------------------------------------------------------- +void PLCsocket::always_executed_hook() +{ + DEBUG_STREAM << "PLCsocket::always_executed_hook() " << device_name << endl; + /*----- PROTECTED REGION ID(PLCsocket::always_executed_hook) ENABLED START -----*/ + + // code always executed before all requests + + /*----- PROTECTED REGION END -----*/ // PLCsocket::always_executed_hook +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::read_attr_hardware() + * Description : Hardware acquisition for attributes + */ +//-------------------------------------------------------- +void PLCsocket::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list)) +{ + DEBUG_STREAM << "PLCsocket::read_attr_hardware(vector<long> &attr_list) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_attr_hardware) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_attr_hardware +} + +//-------------------------------------------------------- +/** + * Read attribute IThreshold related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCsocket::read_IThreshold(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_IThreshold(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_IThreshold) ENABLED START -----*/ + ithreshold = (message.campo_ingressi_5 & maskbits[0])==ACTIVE?false:true; + al_ithreshold = (message.memo_allarmi_5 & maskbits[0])==ACTIVE?false:true; + attr_IThreshold_read = &ithreshold; + attr.set_value(attr_IThreshold_read, 1, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_IThreshold +} +//-------------------------------------------------------- +/** + * Read attribute Libera3hc related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCsocket::read_Libera3hc(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_Libera3hc(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_Libera3hc) ENABLED START -----*/ + libera3hc = ((message.campo_ingressi_5 & maskbits[1])>>1)==ACTIVE?false:true; + al_libera3hc = ((message.memo_allarmi_5 & maskbits[1])>>1)==ACTIVE?false:true; + attr_Libera3hc_read = &libera3hc; + attr.set_value(attr_Libera3hc_read, 1, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_Libera3hc +} +//-------------------------------------------------------- +/** + * Read attribute BeamDumpPLCA10 related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCsocket::read_BeamDumpPLCA10(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_BeamDumpPLCA10(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_BeamDumpPLCA10) ENABLED START -----*/ + beamdumpplca10 = ((message.campo_ingressi_5 & maskbits[2])>>2)==ACTIVE?false:true; + attr_BeamDumpPLCA10_read = &beamdumpplca10; + attr.set_value(attr_BeamDumpPLCA10_read, 1, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_BeamDumpPLCA10 +} +//-------------------------------------------------------- +/** + * Read attribute BeamAbi related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCsocket::read_BeamAbi(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_BeamAbi(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_BeamAbi) ENABLED START -----*/ + beamabi = (message.campo_uscite_2 & maskbits[0])==ACTIVE?false:true; + attr_BeamAbi_read = &beamabi; + attr.set_value(attr_BeamAbi_read, 1, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_BeamAbi +} +//-------------------------------------------------------- +/** + * Read attribute CallPm related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCsocket::read_CallPm(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_CallPm(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_CallPm) ENABLED START -----*/ + callpm = ((message.campo_uscite_2 & maskbits[1])>>1)==ACTIVE?false:true; + attr_CallPm_read = &callpm; + attr.set_value(attr_CallPm_read, 1, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_CallPm +} +//-------------------------------------------------------- +/** + * Read attribute AlIThreshold related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCsocket::read_AlIThreshold(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_AlIThreshold(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_AlIThreshold) ENABLED START -----*/ + al_ithreshold = (message.memo_allarmi_5 & maskbits[0])==ACTIVE?false:true; + attr_AlIThreshold_read = &al_ithreshold; + attr.set_value(attr_AlIThreshold_read, 1, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_AlIThreshold +} +//-------------------------------------------------------- +/** + * Read attribute AlLibera3hc related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCsocket::read_AlLibera3hc(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_AlLibera3hc(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_AlLibera3hc) ENABLED START -----*/ + al_libera3hc = ((message.memo_allarmi_5 & maskbits[1])>>1)==ACTIVE?false:true; + attr_AlLibera3hc_read = &al_libera3hc; + attr.set_value(attr_AlLibera3hc_read, 1, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_AlLibera3hc +} +//-------------------------------------------------------- +/** + * Read attribute Seq_state related method + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCsocket::read_Seq_state(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_Seq_state(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_Seq_state) ENABLED START -----*/ + attr_Seq_state_read = &(s_state); + attr.set_value(attr_Seq_state_read, 1, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_Seq_state +} +//-------------------------------------------------------- +/** + * Read attribute EnableBPM11_2 related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void PLCsocket::read_EnableBPM11_2(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_EnableBPM11_2(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_EnableBPM11_2) ENABLED START -----*/ + DEBUG_STREAM << "PLCsocket::read_EnableBPM11_2: message.mesg_type= "<<hex<<message.mesg_type<<" DISABLED_BPM11_2_MESG=" <<DISABLED_BPM11_2_MESG<<dec << endl; + if(message.mesg_type & DISABLED_BPM11_2_MESG) + *attr_EnableBPM11_2_read = false; + else + *attr_EnableBPM11_2_read = true; + // Set the attribute value + attr.set_value(attr_EnableBPM11_2_read); + + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_EnableBPM11_2 +} +//-------------------------------------------------------- +/** + * Read attribute OpenId related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ +//-------------------------------------------------------- +void PLCsocket::read_OpenId(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_OpenId(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_OpenId) ENABLED START -----*/ + for(int j=0;j<NUM_ID;j++){ + openid[j] = ((message.campo_ingressi_1 & maskbits[j])>>j)==ACTIVE?false:true; + al_openid[j] = ((message.memo_allarmi_1 & maskbits[j])>>j)==ACTIVE?false:true; + } + attr_OpenId_read = &openid[0]; + attr.set_value(attr_OpenId_read, NUM_ID, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_OpenId +} +//-------------------------------------------------------- +/** + * Read attribute DiodeDet related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ +//-------------------------------------------------------- +void PLCsocket::read_DiodeDet(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_DiodeDet(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_DiodeDet) ENABLED START -----*/ + for(int j=0;j<NUM_DIODE;j++){ + diodedet[j] = ((message.campo_ingressi_2 & maskbits[j])>>j)==ACTIVE?false:true; + al_diodedet[j] = ((message.memo_allarmi_2 & maskbits[j])>>j)==ACTIVE?false:true; + } + attr_DiodeDet_read = &diodedet[0]; + attr.set_value(attr_DiodeDet_read, NUM_DIODE, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_DiodeDet +} +//-------------------------------------------------------- +/** + * Read attribute LiberaSt related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ +//-------------------------------------------------------- +void PLCsocket::read_LiberaSt(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_LiberaSt(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_LiberaSt) ENABLED START -----*/ + for(int j=0;j<NUM_LIBERA1;j++){ + liberast[j] = ((message.campo_ingressi_3 & maskbits[j])>>j)==ACTIVE?false:true; + al_liberast[j] = ((message.memo_allarmi_3 & maskbits[j])>>j)==ACTIVE?false:true; + } + attr_LiberaSt_read = &liberast[0]; + attr.set_value(attr_LiberaSt_read, NUM_LIBERA1, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_LiberaSt +} +//-------------------------------------------------------- +/** + * Read attribute LiberaNd related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ +//-------------------------------------------------------- +void PLCsocket::read_LiberaNd(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_LiberaNd(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_LiberaNd) ENABLED START -----*/ + for(int j=0;j<NUM_LIBERA2;j++){ + liberand[j] = ((message.campo_ingressi_4 & maskbits[j])>>j)==ACTIVE?false:true; + al_liberand[j] = ((message.memo_allarmi_4 & maskbits[j])>>j)==ACTIVE?false:true; + } + attr_LiberaNd_read = &liberand[0]; + attr.set_value(attr_LiberaNd_read, NUM_LIBERA2, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_LiberaNd +} +//-------------------------------------------------------- +/** + * Read attribute IlkEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ +//-------------------------------------------------------- +void PLCsocket::read_IlkEnable(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_IlkEnable(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_IlkEnable) ENABLED START -----*/ + for(int j=0;j<NUM_INTLOCK;j++){ + IlkEnable[j] = ((message.campo_uscite_1 & maskbits[j])>>j)==ACTIVE?false:true; + } + attr_IlkEnable_read = &IlkEnable[0]; + attr.set_value(attr_IlkEnable_read, NUM_INTLOCK, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_IlkEnable +} +//-------------------------------------------------------- +/** + * Read attribute AlOpenId related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ +//-------------------------------------------------------- +void PLCsocket::read_AlOpenId(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_AlOpenId(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_AlOpenId) ENABLED START -----*/ + for(int j=0;j<NUM_ID;j++){ + al_openid[j] = ((message.memo_allarmi_1 & maskbits[j])>>j)==ACTIVE?false:true; + } + attr_AlOpenId_read = &al_openid[0]; + attr.set_value(attr_AlOpenId_read, NUM_ID, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_AlOpenId +} +//-------------------------------------------------------- +/** + * Read attribute AlDiodeDet related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ +//-------------------------------------------------------- +void PLCsocket::read_AlDiodeDet(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_AlDiodeDet(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_AlDiodeDet) ENABLED START -----*/ + for(int j=0;j<NUM_DIODE;j++){ + al_diodedet[j] = ((message.memo_allarmi_2 & maskbits[j])>>j)==ACTIVE?false:true; + } + attr_AlDiodeDet_read = &al_diodedet[0]; + attr.set_value(attr_AlDiodeDet_read, NUM_DIODE, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_AlDiodeDet +} +//-------------------------------------------------------- +/** + * Read attribute AlLiberaSt related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ +//-------------------------------------------------------- +void PLCsocket::read_AlLiberaSt(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_AlLiberaSt(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_AlLiberaSt) ENABLED START -----*/ + for(int j=0;j<NUM_LIBERA1;j++){ + al_liberast[j] = ((message.memo_allarmi_3 & maskbits[j])>>j)==ACTIVE?false:true; + } + attr_AlLiberaSt_read = &al_liberast[0]; + attr.set_value(attr_AlLiberaSt_read, NUM_LIBERA1, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_AlLiberaSt +} +//-------------------------------------------------------- +/** + * Read attribute AlLiberaNd related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ +//-------------------------------------------------------- +void PLCsocket::read_AlLiberaNd(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_AlLiberaNd(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_AlLiberaNd) ENABLED START -----*/ + for(int j=0;j<NUM_LIBERA2;j++){ + al_liberand[j] = ((message.memo_allarmi_4 & maskbits[j])>>j)==ACTIVE?false:true; + } + attr_AlLiberaNd_read = &al_liberand[0]; + attr.set_value(attr_AlLiberaNd_read, NUM_LIBERA2, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_AlLiberaNd +} +//-------------------------------------------------------- +/** + * Read attribute Seq_num related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 3 + */ +//-------------------------------------------------------- +void PLCsocket::read_Seq_num(Tango::Attribute &attr) +{ + DEBUG_STREAM << "PLCsocket::read_Seq_num(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(PLCsocket::read_Seq_num) ENABLED START -----*/ + seq[0] = message.seq_num; + seq[1] = message.seq_async; + seq[2] = message.seq_sent; + attr_Seq_num_read = &seq[0]; + attr.set_value(attr_Seq_num_read, 3, 0, false); + /*----- PROTECTED REGION END -----*/ // PLCsocket::read_Seq_num +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::add_dynamic_attributes() + * Description : Create the dynamic attributes if any + * for specified device. + */ +//-------------------------------------------------------- +void PLCsocket::add_dynamic_attributes() +{ + /*----- PROTECTED REGION ID(PLCsocket::add_dynamic_attributes) ENABLED START -----*/ + + // Add your own code to create and add dynamic attributes if any + + /*----- PROTECTED REGION END -----*/ // PLCsocket::add_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Command Beam_dump related method + * Description: + * + * @returns + */ +//-------------------------------------------------------- +Tango::DevString PLCsocket::beam_dump() +{ + Tango::DevString argout; + DEBUG_STREAM << "PLCsocket::Beam_dump() - " << device_name << endl; + /*----- PROTECTED REGION ID(PLCsocket::beam_dump) ENABLED START -----*/ + + // Add your own code + argout = new char[15]; + unsigned char query[BUF_LEN]; + memset (query,0,BUF_LEN); + + + try{ + i_answer.code = BEAM_DUMP_CODE; + i_answer.ack_1 = 0x0; + i_answer.ack_2 = 0x0; + i_answer.ack_3 = 0x0; + i_answer.ack_4 = 0x0; + i_answer.ack_5 = 0x0; + for(int i=0;i<8;i++){ + (i_answer.tstamp_srv)[i] = 0x00; + } + bcopy(&i_answer, &query[0], (sizeof(ilk_answer_t))); + send_frame(query, (sizeof(ilk_answer_t))); + + } + catch(Tango::DevFailed e) { + set_state(Tango::FAULT); + set_status("beam_dump cmd failed"); + Tango::Except::re_throw_exception(e, + (const char *) "write error", + (const char *) "write beam_dump error", + (const char *) "PLCsocket::beam_dump", Tango::ERR); + } + + is_beamdumpcmd = 1; + + set_state(Tango::ON); + set_status("Connection opened"); + + strcpy(argout, "beam_dump sent"); + DEBUG_STREAM << "PLCsocket::beam_dump(): finished... !" << endl; + + /*----- PROTECTED REGION END -----*/ // PLCsocket::beam_dump + return argout; +} +//-------------------------------------------------------- +/** + * Command Send_ack related method + * Description: + * + * @returns + */ +//-------------------------------------------------------- +Tango::DevString PLCsocket::send_ack() +{ + Tango::DevString argout; + DEBUG_STREAM << "PLCsocket::Send_ack() - " << device_name << endl; + /*----- PROTECTED REGION ID(PLCsocket::send_ack) ENABLED START -----*/ + + // Add your own code + argout = new char[15]; + unsigned char query[BUF_LEN]; + memset (query,0,BUF_LEN); + + send_auto_ack(); + + set_state(Tango::ON); + set_status("Connection opened"); + + strcpy(argout, "acknowledge sent"); + DEBUG_STREAM << "PLCsocket::send_ack(): finished... !" << endl; + /*----- PROTECTED REGION END -----*/ // PLCsocket::send_ack + return argout; +} +//-------------------------------------------------------- +/** + * Command Seq_state_rst related method + * Description: + * + */ +//-------------------------------------------------------- +void PLCsocket::seq_state_rst() +{ + DEBUG_STREAM << "PLCsocket::Seq_state_rst() - " << device_name << endl; + /*----- PROTECTED REGION ID(PLCsocket::seq_state_rst) ENABLED START -----*/ + + // Add your own code + s_state = NORMAL_ST; + + DEBUG_STREAM << "PLCsocket::seq_state_rst(): set state to normal" << endl; + /*----- PROTECTED REGION END -----*/ // PLCsocket::seq_state_rst +} +//-------------------------------------------------------- +/** + * Command Test_debug related method + * Description: + * + */ +//-------------------------------------------------------- +void PLCsocket::test_debug() +{ + DEBUG_STREAM << "PLCsocket::Test_debug() - " << device_name << endl; + /*----- PROTECTED REGION ID(PLCsocket::test_debug) ENABLED START -----*/ + + // Add your own code + char* bad_pointer; + delete bad_pointer; + /*----- PROTECTED REGION END -----*/ // PLCsocket::test_debug +} +//-------------------------------------------------------- +/** + * Command EnableBPM11_2 related method + * Description: + * + * @param argin + */ +//-------------------------------------------------------- +void PLCsocket::enable_bpm11_2(Tango::DevBoolean argin) +{ + DEBUG_STREAM << "PLCsocket::EnableBPM11_2() - " << device_name << endl; + /*----- PROTECTED REGION ID(PLCsocket::enable_bpm11_2) ENABLED START -----*/ + + // Add your own code + unsigned char query[BUF_LEN]; + memset (query,0,BUF_LEN); + + + try{ + if(argin) + i_answer.code = ENABLE_BPM_11_2_CODE; + else + i_answer.code = DISABLE_BPM_11_2_CODE; + i_answer.ack_1 = 0x0; + i_answer.ack_2 = 0x0; + i_answer.ack_3 = 0x0; + i_answer.ack_4 = 0x0; + i_answer.ack_5 = 0x0; + for(int i=0;i<8;i++){ + (i_answer.tstamp_srv)[i] = 0x00; + } + bcopy(&i_answer, &query[0], (sizeof(ilk_answer_t))); + send_frame(query, (sizeof(ilk_answer_t))); + + } + catch(Tango::DevFailed e) { + set_state(Tango::FAULT); + set_status("EnableBPM11_2 cmd failed"); + Tango::Except::re_throw_exception(e, + (const char *) "write error", + (const char *) "write EnableBPM11_2 error", + (const char *) "PLCsocket::EnableBPM11_2", Tango::ERR); + } + + is_beamdumpcmd = 1; + + set_state(Tango::ON); + set_status("Connection opened"); + + DEBUG_STREAM << "PLCsocket::EnableBPM11_2(): finished... !" << endl; + /*----- PROTECTED REGION END -----*/ // PLCsocket::enable_bpm11_2 +} +//-------------------------------------------------------- +/** + * Command DisableInterlockSCW related method + * Description: + * + */ +//-------------------------------------------------------- +void PLCsocket::disable_interlock_scw() +{ + DEBUG_STREAM << "PLCsocket::DisableInterlockSCW() - " << device_name << endl; + /*----- PROTECTED REGION ID(PLCsocket::disable_interlock_scw) ENABLED START -----*/ + + // Add your own code + unsigned char query[BUF_LEN]; + memset (query,0,BUF_LEN); + + + try{ + i_answer.code = DISABLE_INTLK_SCW_CODE; + i_answer.ack_1 = 0x0; + i_answer.ack_2 = 0x0; + i_answer.ack_3 = 0x0; + i_answer.ack_4 = 0x0; + i_answer.ack_5 = 0x0; + for(int i=0;i<8;i++){ + (i_answer.tstamp_srv)[i] = 0x00; + } + bcopy(&i_answer, &query[0], (sizeof(ilk_answer_t))); + send_frame(query, (sizeof(ilk_answer_t))); + + } + catch(Tango::DevFailed e) { + set_state(Tango::FAULT); + set_status("Disable Interlock SCW cmd failed"); + Tango::Except::re_throw_exception(e, + (const char *) "write error", + (const char *) "write disable_interlock_scw error", + (const char *) "PLCsocket::disable_interlock_scw", Tango::ERR); + } + + /*----- PROTECTED REGION END -----*/ // PLCsocket::disable_interlock_scw +} +//-------------------------------------------------------- +/** + * Command DisableInterlockID5 related method + * Description: + * + */ +//-------------------------------------------------------- +void PLCsocket::disable_interlock_id5() +{ + DEBUG_STREAM << "PLCsocket::DisableInterlockID5() - " << device_name << endl; + /*----- PROTECTED REGION ID(PLCsocket::disable_interlock_id5) ENABLED START -----*/ + + // Add your own code + unsigned char query[BUF_LEN]; + memset (query,0,BUF_LEN); + + + try{ + i_answer.code = DISABLE_INTLK_ID5_CODE; + i_answer.ack_1 = 0x0; + i_answer.ack_2 = 0x0; + i_answer.ack_3 = 0x0; + i_answer.ack_4 = 0x0; + i_answer.ack_5 = 0x0; + for(int i=0;i<8;i++){ + (i_answer.tstamp_srv)[i] = 0x00; + } + bcopy(&i_answer, &query[0], (sizeof(ilk_answer_t))); + send_frame(query, (sizeof(ilk_answer_t))); + + } + catch(Tango::DevFailed e) { + set_state(Tango::FAULT); + set_status("Disable Interlock ID5 cmd failed"); + Tango::Except::re_throw_exception(e, + (const char *) "write error", + (const char *) "write disable_interlock_id5 error", + (const char *) "PLCsocket::disable_interlock_id5", Tango::ERR); + } + + /*----- PROTECTED REGION END -----*/ // PLCsocket::disable_interlock_id5 +} +//-------------------------------------------------------- +/** + * Method : PLCsocket::add_dynamic_commands() + * Description : Create the dynamic commands if any + * for specified device. + */ +//-------------------------------------------------------- +void PLCsocket::add_dynamic_commands() +{ + /*----- PROTECTED REGION ID(PLCsocket::add_dynamic_commands) ENABLED START -----*/ + + // Add your own code to create and add dynamic commands if any + + /*----- PROTECTED REGION END -----*/ // PLCsocket::add_dynamic_commands +} + +/*----- PROTECTED REGION ID(PLCsocket::namespace_ending) ENABLED START -----*/ + +// Additional Methods + +//+------------------------------------------------------------------ +/** + * method: PLCsocket::push_it + * + * description: method to push user events + * + * @return + * + */ +//+------------------------------------------------------------------ +void PLCsocket::push_it() +{ + gettimeofday(&_pre2,NULL);//takes first timestamp + DEBUG_STREAM << "PLCsocket::push_it(): entering... !" << endl; + vector<string> filt_names; + vector<double> filt_values; + filt_names.push_back("campo"); + filt_values.push_back(message.campo_ingressi_1); + + + memset (buffer,0,BUF_LEN); + bcopy(&old_message, &buffer, sizeof(PLCsocket_ns::intlck_libera)); + + for(int j=0;j<NUM_ID;j++){ + openid[j] = ((message.campo_ingressi_1 & maskbits[j])>>j)==ACTIVE?false:true; + al_openid[j] = ((message.memo_allarmi_1 & maskbits[j])>>j)==ACTIVE?false:true; + old_openid[j] = ((old_message.campo_ingressi_1 & maskbits[j])>>j)==ACTIVE?false:true; + } + for(int j=0;j<NUM_DIODE;j++){ + diodedet[j] = ((message.campo_ingressi_2 & maskbits[j])>>j)==ACTIVE?false:true; + al_diodedet[j] = ((message.memo_allarmi_2 & maskbits[j])>>j)==ACTIVE?false:true; + old_diodedet[j] = ((old_message.campo_ingressi_2 & maskbits[j])>>j)==ACTIVE?false:true; + } + for(int j=0;j<NUM_LIBERA1;j++){ + liberast[j] = ((message.campo_ingressi_3 & maskbits[j])>>j)==ACTIVE?false:true; + al_liberast[j] = ((message.memo_allarmi_3 & maskbits[j])>>j)==ACTIVE?false:true; + old_liberast[j] = ((old_message.campo_ingressi_3 & maskbits[j])>>j)==ACTIVE?false:true; + } + for(int j=0;j<NUM_LIBERA2;j++){ + liberand[j] = ((message.campo_ingressi_4 & maskbits[j])>>j)==ACTIVE?false:true; + al_liberand[j] = ((message.memo_allarmi_4 & maskbits[j])>>j)==ACTIVE?false:true; + old_liberand[j] = ((old_message.campo_ingressi_4 & maskbits[j])>>j)==ACTIVE?false:true; + } + ithreshold = (message.campo_ingressi_5 & maskbits[0])==ACTIVE?false:true; + old_ithreshold = (old_message.campo_ingressi_5 & maskbits[0])==ACTIVE?false:true; + al_ithreshold = (message.memo_allarmi_5 & maskbits[0])==ACTIVE?false:true; + libera3hc = ((message.campo_ingressi_5 & maskbits[1])>>1)==ACTIVE?false:true; + beamdumpplca10 = ((message.campo_ingressi_5 & maskbits[2])>>2)==ACTIVE?false:true; + old_libera3hc = ((old_message.campo_ingressi_5 & maskbits[1])>>1)==ACTIVE?false:true; + old_beamdumpplca10 = ((old_message.campo_ingressi_5 & maskbits[2])>>2)==ACTIVE?false:true; + al_libera3hc = ((message.memo_allarmi_5 & maskbits[1])>>1)==ACTIVE?false:true; + for(int j=0;j<NUM_INTLOCK;j++){ + IlkEnable[j] = ((message.campo_uscite_1 & maskbits[j])>>j)==ACTIVE?false:true; + old_IlkEnable[j] = ((old_message.campo_uscite_1 & maskbits[j])>>j)==ACTIVE?false:true; + } + beamabi = (message.campo_uscite_2 & maskbits[0])==ACTIVE?false:true; + old_beamabi = (old_message.campo_uscite_2 & maskbits[0])==ACTIVE?false:true; + callpm = ((message.campo_uscite_2 & maskbits[1])>>1)==ACTIVE?false:true; + + + //push_event makes a set_value of the attribute with the specified data, then send event + try{ + string nm = "openId"; + + push_event(nm, filt_names, filt_values, openid, NUM_ID); + + nm = "diodeDet"; + push_event(nm, filt_names, filt_values, diodedet, NUM_DIODE); + + nm = "liberaSt"; + push_event(nm, filt_names, filt_values, liberast, NUM_LIBERA1); + + nm = "liberaNd"; + push_event(nm, filt_names, filt_values, liberand, NUM_LIBERA2); + + nm = "IlkEnable"; + push_event(nm, filt_names, filt_values, IlkEnable, NUM_INTLOCK); + + nm = "ithreshold"; + push_event(nm, filt_names, filt_values, &ithreshold, 1); + + nm = "libera3hc"; + push_event(nm, filt_names, filt_values, &libera3hc, 1); + + nm = "beamDumpPLCA10"; + push_event(nm, filt_names, filt_values, &beamdumpplca10, 1); + + nm = "beamAbi"; + push_event(nm, filt_names, filt_values, &beamabi, 1); + + nm = "callPm"; + push_event(nm, filt_names, filt_values, &callpm, 1); + + nm = "AlOpenId"; + push_event(nm, filt_names, filt_values, al_openid, NUM_ID); + + nm = "AlDiodeDet"; + push_event(nm, filt_names, filt_values, al_diodedet, NUM_DIODE); + + nm = "AlLiberaSt"; + push_event(nm, filt_names, filt_values, al_liberast, NUM_LIBERA1); + + nm = "AlLiberaNd"; + push_event(nm, filt_names, filt_values, al_liberand, NUM_LIBERA2); + + nm = "AlIThreshold"; + push_event(nm, filt_names, filt_values, &al_ithreshold, 1); + + nm = "AlLibera3hc"; + push_event(nm, filt_names, filt_values, &al_libera3hc, 1); + + } + catch(Tango::DevFailed e) { + DEBUG_STREAM << "PLCsocket::push_it(): error pushing user events" << endl; + set_state(Tango::FAULT); + set_status("Events not pushed"); + Tango::Except::re_throw_exception(e, + (const char *) "pushing events error", + (const char *) "pushing events error", + (const char *) "PLCsocket::push_it()", Tango::ERR); + } + // corrected libera signal + for(int j=0;j<NUM_LIBERA1;j++){ + corr_liberast[j] = (liberast[j] || IlkEnable[j]); + old_corr_liberast[j] = (old_liberast[j] || old_IlkEnable[j]); + } + for(int j=0;j<NUM_LIBERA2;j++){ + corr_liberand[j] = (liberand[j] || IlkEnable[j]); + old_corr_liberand[j] = (old_liberand[j] || old_IlkEnable[j]); + } + corr_libera3hc = (libera3hc || ithreshold); + old_corr_libera3hc = (old_libera3hc || old_ithreshold); + + filt_names.clear(); + filt_values.clear(); + if(get_state()!=Tango::FAULT) + set_state(Tango::ON); + set_status("Events pushed"); + INFO_STREAM << "PLCsocket::push_it(): Events pushed" << endl; + gettimeofday(&_post2,NULL);//takes second timestamp + + int tempo = (_post2.tv_sec - _pre2.tv_sec)*1000000 + + (int)((float)(_post2.tv_usec - _pre2.tv_usec)) ; + gettimeofday(&_pre2,NULL);//takes first timestamp + + if(message.mesg_type & CHANGE_MESG){ + + int condition[9]; + condition[0] = message.campo_ingressi_1^old_message.campo_ingressi_1; + condition[1] = message.campo_ingressi_2^old_message.campo_ingressi_2; + condition[2] = message.campo_ingressi_3^old_message.campo_ingressi_3; + condition[3] = message.campo_ingressi_4^old_message.campo_ingressi_4; + condition[4] = message.campo_ingressi_5^old_message.campo_ingressi_5; + condition[5]=((message.campo_uscite_2&maskbits[0])^(old_message.campo_uscite_2&maskbits[0])); + condition[6] = message.campo_uscite_1; + + + if(condition[0]!=0x0000){ + for(int j=0;j<NUM_ID;j++){ + if(openid[j]!=old_openid[j]){ + log_to_db(openid[j]<old_openid[j]?mesg_openid[j][0]:mesg_openid[j][1], message.tstamp_campo); + } + } + } + if(condition[1]!=0x0000){ + for(int j=0;j<NUM_DIODE;j++){ + if(diodedet[j]!=old_diodedet[j]){ + log_to_db(diodedet[j]<old_diodedet[j]?mesg_diodedet[j][0]:mesg_diodedet[j][1], message.tstamp_campo); + } + } + } + if((condition[2]!=0x0000) || (condition[6]!=0x0000)) { + for(int j=0;j<NUM_LIBERA1;j++){ + if((corr_liberast[j]!=old_corr_liberast[j])){ + log_to_db(corr_liberast[j]<old_corr_liberast[j]?mesg_liberast[j][0]:mesg_liberast[j][1], message.tstamp_campo); + } + } + } + if((condition[3]!=0x0000)||(condition[6]!=0x0000)){ + for(int j=0;j<NUM_LIBERA2;j++){ + if(corr_liberand[j]!=old_corr_liberand[j]){ + log_to_db(corr_liberand[j]<old_corr_liberand[j]?mesg_liberand[j][0]:mesg_liberand[j][1], message.tstamp_campo); + } + } + } + if(condition[4]!=0x0000){ + if(ithreshold!=old_ithreshold){ + log_to_db(ithreshold<old_ithreshold?mesg_ithreshold[0]:mesg_ithreshold[1], message.tstamp_campo); + } + if(corr_libera3hc!=old_corr_libera3hc){ + log_to_db(corr_libera3hc<old_corr_libera3hc?mesg_libera3hc[0]:mesg_libera3hc[1], message.tstamp_campo); + } + if(beamdumpplca10!=old_beamdumpplca10){ + log_to_db(beamdumpplca10<old_beamdumpplca10?mesg_plca10[0]:mesg_plca10[1], message.tstamp_campo); + } + } + if(condition[5]!=0x0000){ + if(beamabi!=old_beamabi){ + log_to_db(beamabi<old_beamabi?mesg_beamabi[0]:mesg_beamabi[1], message.tstamp_campo); + } + } + + + DEBUG_STREAM << "PLCsocket::push_it() change message logged" << endl; + + } + if(message.mesg_type & BDCA_MESG){ + if(beamabi<old_beamabi){ + if(is_beamdumpcmd!=0){ + log_to_db(beam_dump_cmd, message.tstamp_campo); + is_beamdumpcmd=0; + DEBUG_STREAM << "PLCsocket::push_it() beam dump cmd message logged" << endl; + } + else{ + DEBUG_STREAM << "PLCsocket::push_it() error: beam_dump_cmd_answer without the command" << endl; + } + } + else{ + DEBUG_STREAM << "PLCsocket::push_it() beam dump cmd answer without beam dump" << endl; + } + } + if(message.mesg_type & PERIODIC_MESG){ + //dont log + DEBUG_STREAM << "PLCsocket::push_it() periodic message" << endl; + } + //if(logging_msg == 1){ +// log_it(); + //} + DEBUG_STREAM << "PLCsocket::push_it(): finished" << endl; + gettimeofday(&_post2,NULL);//takes second timestamp + tempo = (_post2.tv_sec - _pre2.tv_sec)*1000000 + + (int)((float)(_post2.tv_usec - _pre2.tv_usec)) ; + +} + +//+------------------------------------------------------------------ +/** + * method: PLCsocket::log_it + * + * description: method to execute the logging to a textfile + * + * @return + * + */ +//+------------------------------------------------------------------ +void PLCsocket::log_it() +{ + DEBUG_STREAM << "PLCsocket::log_it(): entering... !" << endl; + char buf[10];//buffer for single digit conversion + char buf2[BUF_LEN]; + + int col[10]; + col[0] = message.campo_ingressi_1;//OpenID + col[1] = message.campo_ingressi_2;//DiodeDet + col[2] = message.campo_ingressi_3;//LiberaSt + col[3] = message.campo_ingressi_4;//LiberaNd + col[4] = ((message.campo_ingressi_5 & maskbits[1])>>1);//Libera3hc + col[5] = (message.campo_ingressi_5 & maskbits[0]);//IThreshold + col[6] = ((message.campo_ingressi_5 & maskbits[2])>>2);//BeamDumpPLCA10 + col[7] = message.campo_uscite_1;//IlkEnable + col[8] = (message.campo_uscite_2 & maskbits[0]);//BeamAbi + col[9] = ((message.campo_uscite_2 & maskbits[1])>>1);//CallPm + + int writefile = 0; + string x; + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%08ld\t", message.seq_num); + x.append(buf); + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%08ld\t", message.seq_async); + x.append(buf); + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%08ld\t", message.seq_sent); + x.append(buf); + memset (buf2, 0, BUF_LEN ); + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%02x/%02x/%02x ", message.tstamp_campo[3], message.tstamp_campo[0], message.tstamp_campo[1]); + x.append(buf); + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%02x:%02x:%02x", message.tstamp_campo[2], message.tstamp_campo[5], message.tstamp_campo[4]); + x.append(buf); + memset (buf, 0, sizeof(buf) ); +// sprintf(buf, ".%02x%02x", message.tstamp_campo[7], message.tstamp_campo[6]); + sprintf(buf, ".%02x%01x-%01x", message.tstamp_campo[7], message.tstamp_campo[6]>>4, message.tstamp_campo[6]&0x000f); + x.append(buf); +/* for(int k=0; k<TSTAMP_SIZE/2;k++){ + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%02x-%02x-", message.tstamp_campo[1+2*k], message.tstamp_campo[2*k]); + x.append(buf); +}*/ + sprintf(buf2, "\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d",col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7],col[8],col[9]); + x.append(buf2); + x.append("\n"); + + if((writefile = write (fdlog, x.c_str(), x.length()))<0){ + if(get_state()!=Tango::FAULT) + set_state(Tango::DISABLE); + set_status("File logging failure"); + DEBUG_STREAM << "PLCsocket::log_it(): File logging failure" << endl; + } + else{ + if(get_state()!=Tango::FAULT) + set_state(Tango::ON); + set_status("Log written"); + } + DEBUG_STREAM << "PLCsocket::log_it(): finished" << endl; + +} + +//+------------------------------------------------------------------ +/** + * method: PLCsocket::log_msg + * + * description: method to execute the logging to a textfile + * + * @return + * + */ +//+------------------------------------------------------------------ +void PLCsocket::log_msg(intlck_libera_t me) +{ + DEBUG_STREAM << "PLCsocket::log_msg(): entering... !" << endl; + char buf[10];//buffer for single digit conversion + char buf2[BUF_LEN]; + + int col[10]; + col[0] = me.campo_ingressi_1;//OpenID + col[1] = me.campo_ingressi_2;//DiodeDet + col[2] = me.campo_ingressi_3;//LiberaSt + col[3] = me.campo_ingressi_4;//LiberaNd + col[4] = ((me.campo_ingressi_5 & maskbits[1])>>1);//Libera3hc + col[5] = (me.campo_ingressi_5 & maskbits[0]);//IThreshold + col[6] = ((me.campo_ingressi_5 & maskbits[2])>>2);//BeamDumpPLCA10 + col[7] = me.campo_uscite_1;//IlkEnable + col[8] = (me.campo_uscite_2 & maskbits[0]);//BeamAbi + col[9] = ((me.campo_uscite_2 & maskbits[1])>>1);//CallPm + + int writefile = 0; + string x; + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%08ld\t", me.seq_num); + x.append(buf); + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%08ld\t", me.seq_async); + x.append(buf); + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%08ld\t", me.seq_sent); + x.append(buf); + memset (buf2, 0, BUF_LEN ); + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%02x/%02x/%02x ", me.tstamp_campo[3], me.tstamp_campo[0], me.tstamp_campo[1]); + x.append(buf); + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%02x:%02x:%02x", me.tstamp_campo[2], me.tstamp_campo[5], me.tstamp_campo[4]); + x.append(buf); + memset (buf, 0, sizeof(buf) ); +// sprintf(buf, ".%02x%02x", me.tstamp_campo[7], me.tstamp_campo[6]); + sprintf(buf, ".%02x%01x-%01x", me.tstamp_campo[7], me.tstamp_campo[6]>>4, me.tstamp_campo[6]&0x000f); + x.append(buf); +/* for(int k=0; k<TSTAMP_SIZE/2;k++){ + memset (buf, 0, sizeof(buf) ); + sprintf(buf, "%02x-%02x-", me.tstamp_campo[1+2*k], me.tstamp_campo[2*k]); + x.append(buf); +}*/ + sprintf(buf2, "\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d",col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7],col[8],col[9]); + x.append(buf2); + x.append("\n"); + + if((writefile = write (fdlog, x.c_str(), x.length()))<0){ + if(get_state()!=Tango::FAULT) + set_state(Tango::DISABLE); + set_status("File logging failure"); + DEBUG_STREAM << "PLCsocket::log_msg(): File logging failure" << endl; + } + if(writefile==-1){ + set_state(Tango::DISABLE); + set_status("File logging failure"); + } + else if(get_state()!=Tango::FAULT){ + set_state(Tango::ON); + set_status("Log written"); + } + DEBUG_STREAM << "PLCsocket::log_msg(): finished" << endl; + +} + +//+------------------------------------------------------------------ +/** + * method: PLCsocket::log_to_db + * + * description: method to execute the logging to a textfile + * + * @return + * + */ +//+------------------------------------------------------------------ +void PLCsocket::log_to_db(db_mesg ms, tstamp_t t) +{ + DEBUG_STREAM << "PLCsocket::log_to_db(): entering... !" << endl; + + char query[DB_QUERY_LEN]; + int col[10]; + col[0] = message.campo_ingressi_1;//OpenID + col[1] = message.campo_ingressi_2;//DiodeDet + col[2] = message.campo_ingressi_3;//LiberaSt + col[3] = message.campo_ingressi_4;//LiberaNd + col[4] = ((message.campo_ingressi_5 & maskbits[1])>>1);//Libera3hc + col[5] = (message.campo_ingressi_5 & maskbits[0]);//IThreshold + col[6] = ((message.campo_ingressi_5 & maskbits[2])>>2);//BeamDumpPLCA10 + col[7] = message.campo_uscite_1;//IlkEnable + col[8] = (message.campo_uscite_2 & maskbits[0]);//BeamAbi + col[9] = ((message.campo_uscite_2 & maskbits[1])>>1);//CallPm + + + + long lll = calc_timeval(t); + long mmm = calc_time_ms(t); + double dob = ((double)mmm)/1000; + dob += lll; + + char log_m[35]; + for(int s=0;s<35;s++){ + log_m[s] = ms[s]; + } + + int y = snprintf(query, DB_QUERY_LEN, "INSERT INTO FastInterlock.Log (Timestamp,Message,OpenID,DiodeDet,LiberaSt,LiberaNd,Libera3hc,IThreshold,BDplcA10,IlkEnable,BeamAbi,CallPm)\ + VALUES (%f,\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",dob,log_m,col[0],col[1],col[2],col[3],col[4],col[5],col[6],col[7],col[8],col[9]); + if(y>=DB_QUERY_LEN){ + DEBUG_STREAM << "PLCsocket::log_to_db(): db query too long" << endl; + } + else{ + if ((mysql_query(&dbp,query))){ + if(get_state()!=Tango::FAULT) + set_state(Tango::DISABLE); + set_status("db log insert error"); + DEBUG_STREAM << "PLCsocket::log_to_db(): " << mysql_error(&dbp) << endl; + } + else{ + if(get_state()!=Tango::FAULT) + set_state(Tango::ON); + set_status("db log insert ok"); + } + + } + INFO_STREAM << "PLCsocket::log_to_db(): Events logged" << endl; + +} + + +//+------------------------------------------------------------------ +/** + * method: PLCsocket::sync_plc + * + * description: method to refresh plc timestamp + * + * @return + * + */ +//+------------------------------------------------------------------ +void PLCsocket::sync_plc(tstamp_t t) +{ + DEBUG_STREAM << "PLCsocket::sync_plc(): entering... !" << endl; + + unsigned char query[BUF_LEN]; + memset (query,0,BUF_LEN); + + try{ + i_answer.code = SYNC_CODE; + i_answer.ack_1 = 0x0; + i_answer.ack_2 = 0x0; + i_answer.ack_3 = 0x0; + i_answer.ack_4 = 0x0; + i_answer.ack_5 = 0x0; + for(int i=0;i<8;i++){ + (i_answer.tstamp_srv)[i] = t[i]; + } + + bcopy(&i_answer, &query[0], (sizeof(ilk_answer_t))); + send_frame(query, (sizeof(ilk_answer_t))); + + } + catch(Tango::DevFailed e) { + set_state(Tango::FAULT); + set_status("Write failed"); + Tango::Except::re_throw_exception(e, + (const char *) "write error", + (const char *) "write sync_plc error", + (const char *) "PLCsocket::sync_plc", Tango::ERR); + } + + set_state(Tango::ON); + set_status("plc clock syncronized"); + + + INFO_STREAM << "PLCsocket::sync_plc(): Events logged" << endl; + +} + + +//+------------------------------------------------------------------ +/** + * method: PLCsocket::send_frame() + * + * Description: Send a frame to a node via TCP/IP + * + * Arg(s) In: unsigned char *query - data to send + * short query_length - number of data words to send + * + * + */ +//+------------------------------------------------------------------ + +void PLCsocket::send_frame (unsigned char *query, short query_length) +{ + unsigned char frame[BUF_LEN]; + memset ( frame, 0, sizeof(frame) ); + unsigned short int sbuf[BUF_LEN]; + memset (sbuf,0,1+(2*query_length)); + bcopy(&query[0], &sbuf, 2*query_length); + for (int i=0; i<query_length; i++){ + sbuf[i] = ntohs(sbuf[i]); + } + bcopy(&sbuf, &frame[0], 2*query_length); + + char *buf=(char *)&sbuf; + for(int k=0;k<query_length;) + { + stringstream tmp; + int g; + tmp << "db52: "<<setw(3)<<setfill(' ')<<k<<" -> "; + for(g=0; g<10; g++) + { + if(k+g>=query_length) + break; + tmp << " " <<hex<<setw(2)<<setfill(' ')<< (int)(unsigned char)buf[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)buf[k+g]; + } + k+=g; + } + DEBUG_STREAM<<tmp.str()<<dec<<endl; + } + + int writecnt = write (new_sd, frame,query_length); + if(writecnt ==-1){ + if(get_state()!=Tango::FAULT) + set_state(Tango::UNKNOWN); + set_status("error writing socket"); + } + +} + +//+------------------------------------------------------------------ +/** + * method: PLCsocket::send_auto_ack + * + * description: method to execute "Send_ack" + * + * @param argin hex string representing single acknowledges + * @return command result + * + */ +//+------------------------------------------------------------------ +void PLCsocket::send_auto_ack(void) +{ + DEBUG_STREAM << "PLCsocket::send_auto_ack(): entering... !" << endl; + + // Add your own code to control device here + + unsigned char query[BUF_LEN]; + memset (query,0,BUF_LEN); + + try{ + i_answer.code = ACK_CODE; + for(int i=0;i<8;i++){ + (i_answer.tstamp_srv)[i] = 0x00; + } + bcopy(&i_answer, &query[0], (sizeof(ilk_answer_t))); + send_frame(query, (sizeof(ilk_answer_t))); + + } + catch(Tango::DevFailed e) { + set_state(Tango::FAULT); + set_status("Write failed"); + Tango::Except::re_throw_exception(e, + (const char *) "write error", + (const char *) "write ack error", + (const char *) "PLCsocket::send_ack", Tango::ERR); + } + + set_state(Tango::ON); + set_status("acknowledge sent"); + + return; +} + + + +long int PLCsocket::calc_timeval(PLCsocket_ns::tstamp_t t_new) +{ + char buffer [10]; + tm t2; + time_t tn; + + + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[4]); + t2.tm_sec = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[5]); + t2.tm_min = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[2]); + t2.tm_hour = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[3]); + t2.tm_mday = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[0]); + t2.tm_mon = atoi(buffer)-1; + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[1]); + t2.tm_year = atoi(buffer)+100; + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[6]); + t2.tm_wday = atoi(buffer)-1; +#if 0 + t2.tm_isdst = 0/*-1*/; //TODO: -1: let mktime decide if DST and adjust, 0: leave as it is + + DEBUG_STREAM << __func__<<": hour=0x"<<hex<<(int)hour<<" min=0x"<<(int)min<<" sec=0x"<<(int)sec<<dec<<endl; +#endif + tn = mktime(&t2)/*-timezone*/;//with -timezone as if GMT +#if 0 + DEBUG_STREAM << __func__<<": --> tn="<<tn<<" timezone="<<timezone<<" t2.tm_isdst="<<(int)t2.tm_isdst<<endl; + if(t2.tm_isdst == 1) + { + DEBUG_STREAM << __func__<<": --> ORA SOLARE! corrected to hour="<<(int)t2.tm_hour<<" min="<<(int)t2.tm_min<<" sec="<<(int)t2.tm_sec<<endl; + } +#endif + return (long int)tn; +} /* end calc_timeval() */ + + +long int PLCsocket::calc_time_ms(PLCsocket_ns::tstamp_t t_new) +{ + long d = 0; + long ms_new; + int c1, c2; + ms_new = 0; + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[7]); + c1 = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[6]); + c2 = atoi(buffer); + ms_new = c1*10+(c2>>4); + d = ms_new; + + return d; + +} /* end calc_time_ms() */ + +/*----- PROTECTED REGION END -----*/ // PLCsocket::namespace_ending +} // namespace diff --git a/src/PLCsocket.h b/src/PLCsocket.h new file mode 100644 index 0000000000000000000000000000000000000000..697244c0e647e591235a24d39e70218bf717a32b --- /dev/null +++ b/src/PLCsocket.h @@ -0,0 +1,807 @@ +/*----- PROTECTED REGION ID(PLCsocket.h) ENABLED START -----*/ +//============================================================================= +// +// file : PLCsocket.h +// +// description : Include file for the PLCsocket class +// +// project : PLC interlock server +// +// 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/>. +// +// $Author: graziano $ +// +// $Revision: 1.7 $ +// $Date: 2017-02-23 08:42:46 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#ifndef PLCsocket_H +#define PLCsocket_H + +#include <tango.h> +#include <sys/time.h> +#include <time.h> +#include <sys/sem.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <deque> +#include <mysql.h> + + + +//size of the message buffer +#define BUF_LEN 250 +//timestamp size in bytes +#define TSTAMP_SIZE 8 +//size of the label buffer +#define BUF_LAB_SIZE 1024 +//max size of the db query +#define DB_QUERY_LEN 1024 + +//beam dump and ack codes for plc +#define BEAM_DUMP_MESG "UU" +#define ACK_MESG "aa" +#define SYNC_MESG "ww" +//beam dump and ack codes for plc +#define BEAM_DUMP_CODE 0x5555 +#define ACK_CODE 0x6161 +#define SYNC_CODE 0x7777 +#define ENABLE_BPM_11_2_CODE 0x5544 +#define DISABLE_BPM_11_2_CODE 0x4455 +#define DISABLE_INTLK_SCW_CODE 0x1111 //4369 +#define DISABLE_INTLK_ID5_CODE 0x2222 //8738 +//ack policy, auto_ack by default +#define AUTO_ACK "auto" +#define MANUAL_ACK "manual" +//seq number state +#define NORMAL_ST "normal state" +#define LOSTPK_ST "lost packet" +//length of the ack message +#define ACK_MASK_LEN 10 +//types of message from plc +#define PERIODIC_MESG 0x01 +#define CHANGE_MESG 0x02 +#define BDCA_MESG 0x04 //answer message to beam dump command +#define DISABLED_BPM11_2_MESG 0x8 //answer message to beam dump command +//number of bit of input +#define NUM_ID 16 +#define NUM_DIODE 16 +#define NUM_LIBERA1 16 +#define NUM_LIBERA2 16 +#define NUM_INTLOCK 16 + +//mask for operation on single bits +#define MASK_BIT0 0x0001 +#define MASK_BIT1 0x0002 +#define MASK_BIT2 0x0004 +#define MASK_BIT3 0x0008 +#define MASK_BIT4 0x0010 +#define MASK_BIT5 0x0020 +#define MASK_BIT6 0x0040 +#define MASK_BIT7 0x0080 +#define MASK_BIT8 0x0100 +#define MASK_BIT9 0x0200 +#define MASK_BIT10 0x0400 +#define MASK_BIT11 0x0800 +#define MASK_BIT12 0x1000 +#define MASK_BIT13 0x2000 +#define MASK_BIT14 0x4000 +#define MASK_BIT15 0x8000 + +#define ACTIVE 0 //ACTIVE level causes boolean attributes set to false +#define UNACTIVE 1 //ACTIVE level causes boolean attributes set to true + +class PLCsocketClass; +class plclgthread; +class plctimingthread; +class plcsrvthread; + + +/*----- PROTECTED REGION END -----*/ // PLCsocket.h + +/** + * PLCsocket class description: + * + */ + +namespace PLCsocket_ns +{ +/*----- PROTECTED REGION ID(PLCsocket::Additional Class Declarations) ENABLED START -----*/ + +// Additional Class Declarations +// timestamp +typedef unsigned char tstamp_t[TSTAMP_SIZE]; + +typedef char db_mesg[35]; + +typedef struct intlck_libera { + u_short campo_ingressi_1, + campo_ingressi_2, + campo_ingressi_3, + campo_ingressi_4, + campo_ingressi_5; //valori degli ingressi, bit per bit + u_short campo_uscite_1, + campo_uscite_2; //valori delle uscite, bit per bit + tstamp_t tstamp_campo; //timestamp lettura ingressi + u_short memo_allarmi_1, + memo_allarmi_2, + memo_allarmi_3, + memo_allarmi_4, + memo_allarmi_5; //stato degli allarmi, bit per bit + tstamp_t tstamp_ack; //timestamp utimo ack + u_short memo_ack_1, + memo_ack_2, + memo_ack_3, + memo_ack_4, + memo_ack_5; //stato degli acknowledge, bit per bit + u_short mesg_type; //type of the message: hearthbeat or change + u_long seq_num, //sequence number + seq_async, //sequence number change mesg + seq_sent; //sequence number sent packets + u_short db_number, //number of db(check) + spare; +} intlck_libera_t; + +typedef struct ilk_answer { + u_short code; + u_short ack_1, + ack_2, + ack_3, + ack_4, + ack_5; + tstamp_t tstamp_srv; +} ilk_answer_t; + +static int maskbits[] = { + MASK_BIT0, + MASK_BIT1, + MASK_BIT2, + MASK_BIT3, + MASK_BIT4, + MASK_BIT5, + MASK_BIT6, + MASK_BIT7, + MASK_BIT8, + MASK_BIT9, + MASK_BIT10, + MASK_BIT11, + MASK_BIT12, + MASK_BIT13, + MASK_BIT14, + MASK_BIT15 +}; + +static db_mesg openid_m[][2] = { + {"ID S1.1 CLOSED","ID S1.1 OPENED"}, + {"ID S1.2 CLOSED","ID S1.2 OPENED"}, + {"ID S2.2 CLOSED","ID S2.2 OPENED"}, + {"ID S3.2 CLOSED","ID S3.2 OPENED"}, + {"ID S4.2 CLOSED","ID S4.2 OPENED"}, + {"ID S5.2 CLOSED","ID S5.2 OPENED"}, + {"ID S6.2 CLOSED","ID S6.2 OPENED"}, + {"ID S7.2 CLOSED","ID S7.2 OPENED"}, + {"ID S8.2 CLOSED","ID S8.2 OPENED"}, + {"ID S9.2 CLOSED","ID S9.2 OPENED"}, + {"ID S10.2 CLOSED","ID S10.2 OPENED"}, + {"ID S11.2 CLOSED","ID S11.2 OPENED"}, + {" "," "}, + {" "," "}, + {" "," "}, + {" "," "} +}; + +static db_mesg diodedet_m[][2] = { + {"DIODE BPM S1.1 ALARM","DIODE BPM S1.1 NORMAL"}, + {"DIODE BPM S1.2 ALARM","DIODE BPM S1.2 NORMAL"}, + {"DIODE BPM S2.2 ALARM","DIODE BPM S2.2 NORMAL"}, + {"DIODE BPM S3.2 ALARM","DIODE BPM S3.2 NORMAL"}, + {"DIODE BPM S4.2 ALARM","DIODE BPM S4.2 NORMAL"}, + {"DIODE BPM S5.2 ALARM","DIODE BPM S5.2 NORMAL"}, + {"DIODE BPM S6.2 ALARM","DIODE BPM S6.2 NORMAL"}, + {"DIODE BPM S7.2 ALARM","DIODE BPM S7.2 NORMAL"}, + {"DIODE BPM S8.2 ALARM","DIODE BPM S8.2 NORMAL"}, + {"DIODE BPM S9.2 ALARM","DIODE BPM S9.2 NORMAL"}, + {"DIODE BPM S10.2 ALARM","DIODE BPM S10.2 NORMAL"}, + {"DIODE BPM S11.2 ALARM","DIODE BPM S11.2 NORMAL"}, + {" "," "}, + {" "," "}, + {" "," "}, + {" "," "} +}; + +static db_mesg liberast_m[][2] = { + {"Libera BPM S12.8 ALARM","Libera BPM S12.8 NORMAL"}, + {"Libera BPM S1.3 ALARM","Libera BPM S1.3 NORMAL"}, + {"Libera BPM S2.3 ALARM","Libera BPM S2.3 NORMAL"}, + {"Libera BPM S3.3 ALARM","Libera BPM S3.3 NORMAL"}, + {"Libera BPM S4.3 ALARM","Libera BPM S4.3 NORMAL"}, + {"Libera BPM S5.3 ALARM","Libera BPM S5.3 NORMAL"}, + {"Libera BPM S6.3 ALARM","Libera BPM S6.3 NORMAL"}, + {"Libera BPM S7.3 ALARM","Libera BPM S7.3 NORMAL"}, + {"Libera BPM S8.3 ALARM","Libera BPM S8.3 NORMAL"}, + {"Libera BPM S9.3 ALARM","Libera BPM S9.3 NORMAL"}, + {"Libera BPM S10.3 ALARM","Libera BPM S10.3 NORMAL"}, + {"Libera BPM S11.3 ALARM","Libera BPM S11.3 NORMAL"}, + {" "," "}, + {" "," "}, + {" "," "}, + {" "," "} +}; + +static db_mesg liberand_m[][2] = { + {"Libera BPM S1.1 ALARM","Libera BPM S1.1 NORMAL"}, + {"Libera BPM S1.4 ALARM","Libera BPM S1.4 NORMAL"}, + {"Libera BPM S2.4 ALARM","Libera BPM S2.4 NORMAL"}, + {"Libera BPM S3.4 ALARM","Libera BPM S3.4 NORMAL"}, + {"Libera BPM S4.4 ALARM","Libera BPM S4.4 NORMAL"}, + {"Libera BPM S5.4 ALARM","Libera BPM S5.4 NORMAL"}, + {"Libera BPM S6.4 ALARM","Libera BPM S6.4 NORMAL"}, + {"Libera BPM S7.4 ALARM","Libera BPM S7.4 NORMAL"}, + {"Libera BPM S8.4 ALARM","Libera BPM S8.4 NORMAL"}, + {"Libera BPM S9.4 ALARM","Libera BPM S9.4 NORMAL"}, + {"Libera BPM S10.4 ALARM","Libera BPM S10.4 NORMAL"}, + {"Libera BPM S11.4 ALARM","Libera BPM S11.4 NORMAL"}, + {" "," "}, + {" "," "}, + {" "," "}, + {" "," "} +}; + +static db_mesg ithreshold_m[] = { + "I > 20 mA", + "I < 20 mA" +}; +static db_mesg libera3hc_m[] = { + "Libera BPM S11.2 (3HC) ALARM", + "Libera BPM S11.2 (3HC) NORMAL" +}; +static db_mesg plca10_m[] = { + "beam dump from A10 PLC", + "beam enabled from A10 PLC" +}; +static db_mesg beam_dump_cmd = "beam dump command"; +static db_mesg beam_dump_m[] = { + "beam dump", + "beam enabled" +}; + +typedef struct dbm{ + db_mesg mesg_openid[NUM_ID][2], + mesg_diodedet[NUM_DIODE][2], + mesg_liberast[NUM_LIBERA1][2], + mesg_liberand[NUM_LIBERA2][2], + mesg_ithreshold[2], + mesg_libera3hc[2], + mesg_plca10[2], + mesg_beamabi[2]; +} dbm_; + +typedef struct att_db { + char *att_name;//name of the attribute + db_mesg *fixed_m;//fixed messages for the specific attribute + db_mesg *res_m;//resulting messages + int dim; +} att_db_; + +/*----- PROTECTED REGION END -----*/ // PLCsocket::Additional Class Declarations + +class PLCsocket : public TANGO_BASE_CLASS +{ + +/*----- PROTECTED REGION ID(PLCsocket::Data Members) ENABLED START -----*/ + +// Add your own data members +public: + + + +/*----- PROTECTED REGION END -----*/ // PLCsocket::Data Members + +// Device property data members +public: + // Ipaddr: ip address of PLC + string ipaddr; + // Wport: + Tango::DevShort wport; + // Rport: + Tango::DevShort rport; + // Srv_host: ip addr of the server + string srv_host; + // Hbeat: max time in ms between two read from plc + Tango::DevShort hbeat; + // Labels: list of labels to be written in the panel + vector<string> labels; + // Logfile: + string logfile; + // Db_param: contains the parameter string to access logging db:<BR> + // hostname-user-passwd-db_name-port + vector<string> db_param; + // Logging: + Tango::DevShort logging; + // Timeadjust: + string timeadjust; + // Ack_policy: + string ack_policy; + +// Attribute data members +public: + Tango::DevBoolean *attr_IThreshold_read; + Tango::DevBoolean *attr_Libera3hc_read; + Tango::DevBoolean *attr_BeamDumpPLCA10_read; + Tango::DevBoolean *attr_BeamAbi_read; + Tango::DevBoolean *attr_CallPm_read; + Tango::DevBoolean *attr_AlIThreshold_read; + Tango::DevBoolean *attr_AlLibera3hc_read; + Tango::DevString *attr_Seq_state_read; + Tango::DevBoolean *attr_EnableBPM11_2_read; + Tango::DevBoolean *attr_OpenId_read; + Tango::DevBoolean *attr_DiodeDet_read; + Tango::DevBoolean *attr_LiberaSt_read; + Tango::DevBoolean *attr_LiberaNd_read; + Tango::DevBoolean *attr_IlkEnable_read; + Tango::DevBoolean *attr_AlOpenId_read; + Tango::DevBoolean *attr_AlDiodeDet_read; + Tango::DevBoolean *attr_AlLiberaSt_read; + Tango::DevBoolean *attr_AlLiberaNd_read; + Tango::DevDouble *attr_Seq_num_read; + +// Constructors and destructors +public: + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + PLCsocket(Tango::DeviceClass *cl,string &s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + PLCsocket(Tango::DeviceClass *cl,const char *s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + PLCsocket(Tango::DeviceClass *cl,const char *s,const char *d); + /** + * The device object destructor. + */ + ~PLCsocket() {delete_device();}; + + +// Miscellaneous methods +public: + /* + * will be called at device destruction or at init command. + */ + void delete_device(); + /* + * Initialize the device + */ + virtual void init_device(); + /* + * Read the device properties from database + */ + void get_device_property(); + /* + * Always executed method before execution command method. + */ + virtual void always_executed_hook(); + + +// Attribute methods +public: + //-------------------------------------------------------- + /* + * Method : PLCsocket::read_attr_hardware() + * Description : Hardware acquisition for attributes. + */ + //-------------------------------------------------------- + virtual void read_attr_hardware(vector<long> &attr_list); + +/** + * Attribute IThreshold related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_IThreshold(Tango::Attribute &attr); + virtual bool is_IThreshold_allowed(Tango::AttReqType type); +/** + * Attribute Libera3hc related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_Libera3hc(Tango::Attribute &attr); + virtual bool is_Libera3hc_allowed(Tango::AttReqType type); +/** + * Attribute BeamDumpPLCA10 related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_BeamDumpPLCA10(Tango::Attribute &attr); + virtual bool is_BeamDumpPLCA10_allowed(Tango::AttReqType type); +/** + * Attribute BeamAbi related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_BeamAbi(Tango::Attribute &attr); + virtual bool is_BeamAbi_allowed(Tango::AttReqType type); +/** + * Attribute CallPm related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_CallPm(Tango::Attribute &attr); + virtual bool is_CallPm_allowed(Tango::AttReqType type); +/** + * Attribute AlIThreshold related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_AlIThreshold(Tango::Attribute &attr); + virtual bool is_AlIThreshold_allowed(Tango::AttReqType type); +/** + * Attribute AlLibera3hc related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_AlLibera3hc(Tango::Attribute &attr); + virtual bool is_AlLibera3hc_allowed(Tango::AttReqType type); +/** + * Attribute Seq_state related methods + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_Seq_state(Tango::Attribute &attr); + virtual bool is_Seq_state_allowed(Tango::AttReqType type); +/** + * Attribute EnableBPM11_2 related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_EnableBPM11_2(Tango::Attribute &attr); + virtual bool is_EnableBPM11_2_allowed(Tango::AttReqType type); +/** + * Attribute OpenId related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ + virtual void read_OpenId(Tango::Attribute &attr); + virtual bool is_OpenId_allowed(Tango::AttReqType type); +/** + * Attribute DiodeDet related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ + virtual void read_DiodeDet(Tango::Attribute &attr); + virtual bool is_DiodeDet_allowed(Tango::AttReqType type); +/** + * Attribute LiberaSt related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ + virtual void read_LiberaSt(Tango::Attribute &attr); + virtual bool is_LiberaSt_allowed(Tango::AttReqType type); +/** + * Attribute LiberaNd related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ + virtual void read_LiberaNd(Tango::Attribute &attr); + virtual bool is_LiberaNd_allowed(Tango::AttReqType type); +/** + * Attribute IlkEnable related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ + virtual void read_IlkEnable(Tango::Attribute &attr); + virtual bool is_IlkEnable_allowed(Tango::AttReqType type); +/** + * Attribute AlOpenId related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ + virtual void read_AlOpenId(Tango::Attribute &attr); + virtual bool is_AlOpenId_allowed(Tango::AttReqType type); +/** + * Attribute AlDiodeDet related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ + virtual void read_AlDiodeDet(Tango::Attribute &attr); + virtual bool is_AlDiodeDet_allowed(Tango::AttReqType type); +/** + * Attribute AlLiberaSt related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ + virtual void read_AlLiberaSt(Tango::Attribute &attr); + virtual bool is_AlLiberaSt_allowed(Tango::AttReqType type); +/** + * Attribute AlLiberaNd related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Spectrum max = 16 + */ + virtual void read_AlLiberaNd(Tango::Attribute &attr); + virtual bool is_AlLiberaNd_allowed(Tango::AttReqType type); +/** + * Attribute Seq_num related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 3 + */ + virtual void read_Seq_num(Tango::Attribute &attr); + virtual bool is_Seq_num_allowed(Tango::AttReqType type); + + + //-------------------------------------------------------- + /** + * Method : PLCsocket::add_dynamic_attributes() + * Description : Add dynamic attributes if any. + */ + //-------------------------------------------------------- + void add_dynamic_attributes(); + + + + +// Command related methods +public: + /** + * Command Beam_dump related method + * Description: + * + * @returns + */ + virtual Tango::DevString beam_dump(); + virtual bool is_Beam_dump_allowed(const CORBA::Any &any); + /** + * Command Send_ack related method + * Description: + * + * @returns + */ + virtual Tango::DevString send_ack(); + virtual bool is_Send_ack_allowed(const CORBA::Any &any); + /** + * Command Seq_state_rst related method + * Description: + * + */ + virtual void seq_state_rst(); + virtual bool is_Seq_state_rst_allowed(const CORBA::Any &any); + /** + * Command Test_debug related method + * Description: + * + */ + virtual void test_debug(); + virtual bool is_Test_debug_allowed(const CORBA::Any &any); + /** + * Command EnableBPM11_2 related method + * Description: + * + * @param argin + */ + virtual void enable_bpm11_2(Tango::DevBoolean argin); + virtual bool is_EnableBPM11_2_allowed(const CORBA::Any &any); + /** + * Command DisableInterlockSCW related method + * Description: + * + */ + virtual void disable_interlock_scw(); + virtual bool is_DisableInterlockSCW_allowed(const CORBA::Any &any); + /** + * Command DisableInterlockID5 related method + * Description: + * + */ + virtual void disable_interlock_id5(); + virtual bool is_DisableInterlockID5_allowed(const CORBA::Any &any); + + + //-------------------------------------------------------- + /** + * Method : PLCsocket::add_dynamic_commands() + * Description : Add dynamic commands if any. + */ + //-------------------------------------------------------- + void add_dynamic_commands(); + +/*----- PROTECTED REGION ID(PLCsocket::Additional Method prototypes) ENABLED START -----*/ + +// Additional Method prototypes +int abortflag; // flag used to abort thread loops + + plclgthread *logloop; //logging thread + plctimingthread *tmloop; //timing thread + plcsrvthread *srvloop; //read from socket thread + omni_mutex::omni_mutex *mutex; + deque<intlck_libera_t> mesg_list; + + union semun { + int val; + struct semid_ds *buf; + ushort * array; + } argument; + int semid; + + + string ip_host; // ip host name for tcp/ip + int new_sd, sock; // socket for data exchange + int fdlog; //logfile + const char* logfile2; //name of the logfile + + MYSQL dbp; + + void log_it();//logging of the raw message + void log_msg(intlck_libera_t m);//logging of the raw message + void log_to_db(db_mesg ms, tstamp_t t); + void push_it();//push of the events to subscribed clients + void sync_plc(tstamp_t t); + + int is_beamdumpcmd; + int logging_msg; + intlck_libera_t message; + intlck_libera_t old_message; + tstamp_t old_timestamp; + tstamp_t new_timestamp; + tstamp_t last_ck_read; + ilk_answer_t i_answer; + + //data from field + Tango::DevBoolean openid[NUM_ID]; + Tango::DevBoolean diodedet[NUM_DIODE]; + Tango::DevBoolean liberast[NUM_LIBERA1]; + Tango::DevBoolean liberand[NUM_LIBERA2]; + Tango::DevBoolean IlkEnable[NUM_INTLOCK]; + Tango::DevBoolean ithreshold; + Tango::DevBoolean libera3hc; + Tango::DevBoolean beamdumpplca10; + Tango::DevBoolean beamabi; + Tango::DevBoolean callpm; + Tango::DevBoolean corr_liberast[NUM_LIBERA1]; + Tango::DevBoolean corr_liberand[NUM_LIBERA2]; + Tango::DevBoolean corr_libera3hc; + Tango::DevDouble seq[3]; + Tango::DevString s_state; + + //alarms + Tango::DevBoolean al_openid[NUM_ID]; + Tango::DevBoolean al_diodedet[NUM_DIODE]; + Tango::DevBoolean al_liberast[NUM_LIBERA1]; + Tango::DevBoolean al_liberand[NUM_LIBERA2]; + Tango::DevBoolean al_ithreshold; + Tango::DevBoolean al_libera3hc; + + //acknowledges registered from plc + Tango::DevBoolean ack_openid[NUM_ID]; + Tango::DevBoolean ack_diodedet[NUM_DIODE]; + Tango::DevBoolean ack_liberast[NUM_LIBERA1]; + Tango::DevBoolean ack_liberand[NUM_LIBERA2]; + Tango::DevBoolean ack_ithreshold; + Tango::DevBoolean ack_libera3hc; + Tango::DevBoolean ack_beamdumpplca10; + + //old message for compare + Tango::DevBoolean old_openid[NUM_ID]; + Tango::DevBoolean old_diodedet[NUM_DIODE]; + Tango::DevBoolean old_liberast[NUM_LIBERA1]; + Tango::DevBoolean old_liberand[NUM_LIBERA2]; + Tango::DevBoolean old_IlkEnable[NUM_INTLOCK]; + Tango::DevBoolean old_ithreshold; + Tango::DevBoolean old_libera3hc; + Tango::DevBoolean old_beamdumpplca10; + Tango::DevBoolean old_beamabi; + Tango::DevBoolean old_corr_liberast[NUM_LIBERA1]; + Tango::DevBoolean old_corr_liberand[NUM_LIBERA2]; + Tango::DevBoolean old_corr_libera3hc; + + //log messages from db + db_mesg mesg_openid[NUM_ID][2]; + db_mesg mesg_diodedet[NUM_DIODE][2]; + db_mesg mesg_liberast[NUM_LIBERA1][2]; + db_mesg mesg_liberand[NUM_LIBERA2][2]; + db_mesg mesg_ithreshold[2]; + db_mesg mesg_libera3hc[2]; + db_mesg mesg_plca10[2]; + db_mesg mesg_beamabi[2]; + dbm dbmessages; + + struct timeval _pre2, _post2; + char buffer[BUF_LEN]; + uint16_t ack_mask[5]; + void send_auto_ack(void); + string calc_timest(); + long int calc_timeval(tstamp_t); + long int calc_time_ms(tstamp_t); + + +protected : + void send_frame (unsigned char *frame, short frame_length); + +/*----- PROTECTED REGION END -----*/ // PLCsocket::Additional Method prototypes +}; + +/*----- PROTECTED REGION ID(PLCsocket::Additional Classes Definitions) ENABLED START -----*/ + +// Additional Classes Definitions + +/*----- PROTECTED REGION END -----*/ // PLCsocket::Additional Classes Definitions + +} // End of namespace + +#endif // PLCsocket_H diff --git a/src/PLCsocket.xmi b/src/PLCsocket.xmi new file mode 100644 index 0000000000000000000000000000000000000000..5cf9c3813d0ab9b8061afd932ed20574174ceed9 --- /dev/null +++ b/src/PLCsocket.xmi @@ -0,0 +1,284 @@ +<?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="PLCsocket" pogoRevision="9.1"> + <description description="" title="PLC interlock server" sourcePath="/home/graziano/fermi/servers/plcsocket/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false"> + <inheritances classname="Device_4Impl" sourcePath=""/> + <identification contact="at elettra.trieste.it - claudio.scafuri" author="claudio.scafuri" emailDomain="elettra.trieste.it" classFamily="Misc" siteSpecific="" platform="Unix Like" bus="tcp/ip" manufacturer="none" reference=""/> + </description> + <deviceProperties name="Ipaddr" description="ip address of PLC"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Wport" description=""> + <type xsi:type="pogoDsl:ShortType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Rport" description=""> + <type xsi:type="pogoDsl:ShortType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Srv_host" description="ip addr of the server"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Hbeat" description="max time in ms between two read from plc"> + <type xsi:type="pogoDsl:ShortType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Labels" description="list of labels to be written in the panel"> + <type xsi:type="pogoDsl:StringVectorType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Logfile" description=""> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Db_param" description="contains the parameter string to access logging db:<BR>
hostname-user-passwd-db_name-port"> + <type xsi:type="pogoDsl:StringVectorType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Logging" description=""> + <type xsi:type="pogoDsl:ShortType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Timeadjust" description=""> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Ack_policy" description=""> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <commands name="State" description="This command gets the device state (stored in its <i>device_state</i> 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="State Code"> + <type xsi:type="pogoDsl:StateType"/> + </argout> + <status abstract="true" inherited="true" concrete="true" concreteHere="false"/> + </commands> + <commands name="Status" description="This command gets the device status (stored in its <i>device_status</i> 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="Status description"> + <type xsi:type="pogoDsl:ConstStringType"/> + </argout> + <status abstract="true" inherited="true" concrete="true" concreteHere="false"/> + </commands> + <commands name="Beam_dump" description="" execMethod="beam_dump" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:StringType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="Send_ack" description="" execMethod="send_ack" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:StringType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="Seq_state_rst" description="" execMethod="seq_state_rst" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="Test_debug" description="" execMethod="test_debug" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="EnableBPM11_2" description="" execMethod="enable_bpm11_2" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:BooleanType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="DisableInterlockSCW" description="" execMethod="disable_interlock_scw" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="DisableInterlockID5" description="" execMethod="disable_interlock_id5" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <attributes name="IThreshold" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="Libera3hc" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="BeamDumpPLCA10" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="BeamAbi" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="CallPm" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="AlIThreshold" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="AlLibera3hc" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="Seq_state" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="EnableBPM11_2" 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="OpenId" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="16" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="DiodeDet" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="16" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="LiberaSt" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="16" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="LiberaNd" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="16" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="IlkEnable" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="16" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="AlOpenId" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="16" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="AlDiodeDet" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="16" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="AlLiberaSt" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="16" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="AlLiberaNd" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="16" maxY="0"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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="Seq_num" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="3" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <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> + <states name="ON" description="*"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="FAULT" description="Severe error occurred"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="UNKNOWN" description="Data timestamp is not coherent"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="ALARM" description="*"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="DISABLE" description="Logging DB connection is not available, the server is not logging"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <preferences docHome="./doc_html" makefileHome="/usr/local/tango-9.2.2/share/pogo/preferences"/> + </classes> +</pogoDsl:PogoSystem> diff --git a/src/PLCsocketClass.cpp b/src/PLCsocketClass.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a9e274ce5f138b03c82556007f2a8869a421a488 --- /dev/null +++ b/src/PLCsocketClass.cpp @@ -0,0 +1,1365 @@ +/*----- PROTECTED REGION ID(PLCsocketClass.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: PLCsocketClass.cpp,v 1.7 2017-02-23 08:42:46 graziano Exp $"; +static const char *TagName = "$Name: $"; +static const char *CvsPath = "$Source: /home/cvsadm/cvsroot/fermi/servers/plcsocket/src/PLCsocketClass.cpp,v $"; +static const char *SvnPath = "$HeadURL: $"; +static const char *HttpServer = "http://www.esrf.eu/computing/cs/tango/tango_doc/ds_doc/"; +//============================================================================= +// +// file : PLCsocketClass.cpp +// +// description : C++ source for the PLCsocketClass. +// A singleton class derived from DeviceClass. +// It implements the command and attribute list +// and all properties and methods required +// by the PLCsocket once per process. +// +// project : PLC interlock server +// +// 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/>. +// +// $Author: graziano $ +// +// $Revision: 1.7 $ +// $Date: 2017-02-23 08:42:46 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include <tango.h> +#include <PLCsocket.h> +#include <PLCsocketClass.h> + +/*----- PROTECTED REGION END -----*/ // PLCsocketClass.cpp + +//------------------------------------------------------------------- +/** + * Create PLCsocketClass singleton and + * return it in a C function for Python usage + */ +//------------------------------------------------------------------- +extern "C" { +#ifdef _TG_WINDOWS_ + +__declspec(dllexport) + +#endif + + Tango::DeviceClass *_create_PLCsocket_class(const char *name) { + return PLCsocket_ns::PLCsocketClass::init(name); + } +} + +namespace PLCsocket_ns +{ +//=================================================================== +// Initialize pointer for singleton pattern +//=================================================================== +PLCsocketClass *PLCsocketClass::_instance = NULL; + +//-------------------------------------------------------- +/** + * method : PLCsocketClass::PLCsocketClass(string &s) + * description : constructor for the PLCsocketClass + * + * @param s The class name + */ +//-------------------------------------------------------- +PLCsocketClass::PLCsocketClass(string &s):Tango::DeviceClass(s) +{ + cout2 << "Entering PLCsocketClass constructor" << endl; + set_default_property(); + write_class_property(); + + /*----- PROTECTED REGION ID(PLCsocketClass::constructor) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::constructor + + cout2 << "Leaving PLCsocketClass constructor" << endl; +} + +//-------------------------------------------------------- +/** + * method : PLCsocketClass::~PLCsocketClass() + * description : destructor for the PLCsocketClass + */ +//-------------------------------------------------------- +PLCsocketClass::~PLCsocketClass() +{ + /*----- PROTECTED REGION ID(PLCsocketClass::destructor) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::destructor + + _instance = NULL; +} + + +//-------------------------------------------------------- +/** + * method : PLCsocketClass::init + * description : Create the object if not already done. + * Otherwise, just return a pointer to the object + * + * @param name The class name + */ +//-------------------------------------------------------- +PLCsocketClass *PLCsocketClass::init(const char *name) +{ + if (_instance == NULL) + { + try + { + string s(name); + _instance = new PLCsocketClass(s); + } + catch (bad_alloc &) + { + throw; + } + } + return _instance; +} + +//-------------------------------------------------------- +/** + * method : PLCsocketClass::instance + * description : Check if object already created, + * and return a pointer to the object + */ +//-------------------------------------------------------- +PLCsocketClass *PLCsocketClass::instance() +{ + if (_instance == NULL) + { + cerr << "Class is not initialised !!" << endl; + exit(-1); + } + return _instance; +} + + + +//=================================================================== +// Command execution method calls +//=================================================================== +//-------------------------------------------------------- +/** + * method : Beam_dumpClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *Beam_dumpClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "Beam_dumpClass::execute(): arrived" << endl; + return insert((static_cast<PLCsocket *>(device))->beam_dump()); +} + +//-------------------------------------------------------- +/** + * method : Send_ackClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *Send_ackClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "Send_ackClass::execute(): arrived" << endl; + return insert((static_cast<PLCsocket *>(device))->send_ack()); +} + +//-------------------------------------------------------- +/** + * method : Seq_state_rstClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *Seq_state_rstClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "Seq_state_rstClass::execute(): arrived" << endl; + ((static_cast<PLCsocket *>(device))->seq_state_rst()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : Test_debugClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *Test_debugClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "Test_debugClass::execute(): arrived" << endl; + ((static_cast<PLCsocket *>(device))->test_debug()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : EnableBPM11_2Class::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *EnableBPM11_2Class::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "EnableBPM11_2Class::execute(): arrived" << endl; + Tango::DevBoolean argin; + extract(in_any, argin); + ((static_cast<PLCsocket *>(device))->enable_bpm11_2(argin)); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : DisableInterlockSCWClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *DisableInterlockSCWClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "DisableInterlockSCWClass::execute(): arrived" << endl; + ((static_cast<PLCsocket *>(device))->disable_interlock_scw()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : DisableInterlockID5Class::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *DisableInterlockID5Class::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "DisableInterlockID5Class::execute(): arrived" << endl; + ((static_cast<PLCsocket *>(device))->disable_interlock_id5()); + return new CORBA::Any(); +} + + +//=================================================================== +// Properties management +//=================================================================== +//-------------------------------------------------------- +/** + * Method : PLCsocketClass::get_class_property() + * Description : Get the class property for specified name. + */ +//-------------------------------------------------------- +Tango::DbDatum PLCsocketClass::get_class_property(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 : PLCsocketClass::get_default_device_property() + * Description : Return the default value for device property. + */ +//-------------------------------------------------------- +Tango::DbDatum PLCsocketClass::get_default_device_property(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 : PLCsocketClass::get_default_class_property() + * Description : Return the default value for class property. + */ +//-------------------------------------------------------- +Tango::DbDatum PLCsocketClass::get_default_class_property(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 : PLCsocketClass::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 PLCsocketClass::set_default_property() +{ + string prop_name; + string prop_desc; + string prop_def; + vector<string> vect_data; + + // Set Default Class Properties + + // Set Default device Properties + prop_name = "Ipaddr"; + prop_desc = "ip address of PLC"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Wport"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Rport"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Srv_host"; + prop_desc = "ip addr of the server"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Hbeat"; + prop_desc = "max time in ms between two read from plc"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Labels"; + prop_desc = "list of labels to be written in the panel"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Logfile"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Db_param"; + prop_desc = "contains the parameter string to access logging db:<BR>\nhostname-user-passwd-db_name-port"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Logging"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Timeadjust"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Ack_policy"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); +} + +//-------------------------------------------------------- +/** + * Method : PLCsocketClass::write_class_property() + * Description : Set class description fields as property in database + */ +//-------------------------------------------------------- +void PLCsocketClass::write_class_property() +{ + // First time, check if database used + if (Tango::Util::_UseDb == false) + return; + + Tango::DbData data; + string classname = get_name(); + string header; + string::size_type start, end; + + // Put title + Tango::DbDatum title("ProjectTitle"); + string str_title("PLC interlock server"); + title << str_title; + data.push_back(title); + + // Put Description + Tango::DbDatum description("Description"); + vector<string> str_desc; + str_desc.push_back(""); + description << str_desc; + data.push_back(description); + + // put cvs or svn location + string filename("PLCsocket"); + filename += "Class.cpp"; + + // check for cvs information + string src_path(CvsPath); + start = src_path.find("/"); + if (start!=string::npos) + { + end = src_path.find(filename); + if (end>start) + { + string strloc = src_path.substr(start, end-start); + // Check if specific repository + start = strloc.find("/cvsroot/"); + if (start!=string::npos && start>0) + { + string repository = strloc.substr(0, start); + if (repository.find("/segfs/")!=string::npos) + strloc = "ESRF:" + strloc.substr(start, strloc.length()-start); + } + Tango::DbDatum cvs_loc("cvs_location"); + cvs_loc << strloc; + data.push_back(cvs_loc); + } + } + + // check for svn information + else + { + string src_path(SvnPath); + start = src_path.find("://"); + if (start!=string::npos) + { + end = src_path.find(filename); + if (end>start) + { + header = "$HeadURL: "; + start = header.length(); + string strloc = src_path.substr(start, (end-start)); + + Tango::DbDatum svn_loc("svn_location"); + svn_loc << strloc; + data.push_back(svn_loc); + } + } + } + + // Get CVS or SVN revision tag + + // CVS tag + string tagname(TagName); + header = "$Name: "; + start = header.length(); + string endstr(" $"); + + end = tagname.find(endstr); + if (end!=string::npos && end>start) + { + string strtag = tagname.substr(start, end-start); + Tango::DbDatum cvs_tag("cvs_tag"); + cvs_tag << strtag; + data.push_back(cvs_tag); + } + + // SVN tag + string svnpath(SvnPath); + header = "$HeadURL: "; + start = header.length(); + + end = svnpath.find(endstr); + if (end!=string::npos && end>start) + { + string strloc = svnpath.substr(start, end-start); + + string tagstr ("/tags/"); + start = strloc.find(tagstr); + if ( start!=string::npos ) + { + start = start + tagstr.length(); + end = strloc.find(filename); + string strtag = strloc.substr(start, end-start-1); + + Tango::DbDatum svn_tag("svn_tag"); + svn_tag << strtag; + data.push_back(svn_tag); + } + } + + // Get URL location + string httpServ(HttpServer); + if (httpServ.length()>0) + { + Tango::DbDatum db_doc_url("doc_url"); + db_doc_url << httpServ; + data.push_back(db_doc_url); + } + + // Put inheritance + Tango::DbDatum inher_datum("InheritedFrom"); + vector<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 : PLCsocketClass::device_factory() + * Description : Create the device object(s) + * and store them in the device list + */ +//-------------------------------------------------------- +void PLCsocketClass::device_factory(const Tango::DevVarStringArray *devlist_ptr) +{ + /*----- PROTECTED REGION ID(PLCsocketClass::device_factory_before) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::device_factory_before + + // Create devices and add it into the device list + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + cout4 << "Device name : " << (*devlist_ptr)[i].in() << endl; + device_list.push_back(new PLCsocket(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 + PLCsocket *dev = static_cast<PLCsocket *>(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(PLCsocketClass::device_factory_after) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::device_factory_after +} +//-------------------------------------------------------- +/** + * Method : PLCsocketClass::attribute_factory() + * Description : Create the attribute object(s) + * and store them in the attribute list + */ +//-------------------------------------------------------- +void PLCsocketClass::attribute_factory(vector<Tango::Attr *> &att_list) +{ + /*----- PROTECTED REGION ID(PLCsocketClass::attribute_factory_before) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::attribute_factory_before + // Attribute : IThreshold + IThresholdAttrib *ithreshold = new IThresholdAttrib(); + Tango::UserDefaultAttrProp ithreshold_prop; + // description not set for IThreshold + // label not set for IThreshold + // unit not set for IThreshold + // standard_unit not set for IThreshold + // display_unit not set for IThreshold + // format not set for IThreshold + // max_value not set for IThreshold + // min_value not set for IThreshold + // max_alarm not set for IThreshold + // min_alarm not set for IThreshold + // max_warning not set for IThreshold + // min_warning not set for IThreshold + // delta_t not set for IThreshold + // delta_val not set for IThreshold + + ithreshold->set_default_properties(ithreshold_prop); + // Not Polled + ithreshold->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(ithreshold); + + // Attribute : Libera3hc + Libera3hcAttrib *libera3hc = new Libera3hcAttrib(); + Tango::UserDefaultAttrProp libera3hc_prop; + // description not set for Libera3hc + // label not set for Libera3hc + // unit not set for Libera3hc + // standard_unit not set for Libera3hc + // display_unit not set for Libera3hc + // format not set for Libera3hc + // max_value not set for Libera3hc + // min_value not set for Libera3hc + // max_alarm not set for Libera3hc + // min_alarm not set for Libera3hc + // max_warning not set for Libera3hc + // min_warning not set for Libera3hc + // delta_t not set for Libera3hc + // delta_val not set for Libera3hc + + libera3hc->set_default_properties(libera3hc_prop); + // Not Polled + libera3hc->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(libera3hc); + + // Attribute : BeamDumpPLCA10 + BeamDumpPLCA10Attrib *beamdumpplca10 = new BeamDumpPLCA10Attrib(); + Tango::UserDefaultAttrProp beamdumpplca10_prop; + // description not set for BeamDumpPLCA10 + // label not set for BeamDumpPLCA10 + // unit not set for BeamDumpPLCA10 + // standard_unit not set for BeamDumpPLCA10 + // display_unit not set for BeamDumpPLCA10 + // format not set for BeamDumpPLCA10 + // max_value not set for BeamDumpPLCA10 + // min_value not set for BeamDumpPLCA10 + // max_alarm not set for BeamDumpPLCA10 + // min_alarm not set for BeamDumpPLCA10 + // max_warning not set for BeamDumpPLCA10 + // min_warning not set for BeamDumpPLCA10 + // delta_t not set for BeamDumpPLCA10 + // delta_val not set for BeamDumpPLCA10 + + beamdumpplca10->set_default_properties(beamdumpplca10_prop); + // Not Polled + beamdumpplca10->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(beamdumpplca10); + + // Attribute : BeamAbi + BeamAbiAttrib *beamabi = new BeamAbiAttrib(); + Tango::UserDefaultAttrProp beamabi_prop; + // description not set for BeamAbi + // label not set for BeamAbi + // unit not set for BeamAbi + // standard_unit not set for BeamAbi + // display_unit not set for BeamAbi + // format not set for BeamAbi + // max_value not set for BeamAbi + // min_value not set for BeamAbi + // max_alarm not set for BeamAbi + // min_alarm not set for BeamAbi + // max_warning not set for BeamAbi + // min_warning not set for BeamAbi + // delta_t not set for BeamAbi + // delta_val not set for BeamAbi + + beamabi->set_default_properties(beamabi_prop); + // Not Polled + beamabi->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(beamabi); + + // Attribute : CallPm + CallPmAttrib *callpm = new CallPmAttrib(); + Tango::UserDefaultAttrProp callpm_prop; + // description not set for CallPm + // label not set for CallPm + // unit not set for CallPm + // standard_unit not set for CallPm + // display_unit not set for CallPm + // format not set for CallPm + // max_value not set for CallPm + // min_value not set for CallPm + // max_alarm not set for CallPm + // min_alarm not set for CallPm + // max_warning not set for CallPm + // min_warning not set for CallPm + // delta_t not set for CallPm + // delta_val not set for CallPm + + callpm->set_default_properties(callpm_prop); + // Not Polled + callpm->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(callpm); + + // Attribute : AlIThreshold + AlIThresholdAttrib *alithreshold = new AlIThresholdAttrib(); + Tango::UserDefaultAttrProp alithreshold_prop; + // description not set for AlIThreshold + // label not set for AlIThreshold + // unit not set for AlIThreshold + // standard_unit not set for AlIThreshold + // display_unit not set for AlIThreshold + // format not set for AlIThreshold + // max_value not set for AlIThreshold + // min_value not set for AlIThreshold + // max_alarm not set for AlIThreshold + // min_alarm not set for AlIThreshold + // max_warning not set for AlIThreshold + // min_warning not set for AlIThreshold + // delta_t not set for AlIThreshold + // delta_val not set for AlIThreshold + + alithreshold->set_default_properties(alithreshold_prop); + // Not Polled + alithreshold->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(alithreshold); + + // Attribute : AlLibera3hc + AlLibera3hcAttrib *allibera3hc = new AlLibera3hcAttrib(); + Tango::UserDefaultAttrProp allibera3hc_prop; + // description not set for AlLibera3hc + // label not set for AlLibera3hc + // unit not set for AlLibera3hc + // standard_unit not set for AlLibera3hc + // display_unit not set for AlLibera3hc + // format not set for AlLibera3hc + // max_value not set for AlLibera3hc + // min_value not set for AlLibera3hc + // max_alarm not set for AlLibera3hc + // min_alarm not set for AlLibera3hc + // max_warning not set for AlLibera3hc + // min_warning not set for AlLibera3hc + // delta_t not set for AlLibera3hc + // delta_val not set for AlLibera3hc + + allibera3hc->set_default_properties(allibera3hc_prop); + // Not Polled + allibera3hc->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(allibera3hc); + + // Attribute : Seq_state + Seq_stateAttrib *seq_state = new Seq_stateAttrib(); + Tango::UserDefaultAttrProp seq_state_prop; + // description not set for Seq_state + // label not set for Seq_state + // unit not set for Seq_state + // standard_unit not set for Seq_state + // display_unit not set for Seq_state + // format not set for Seq_state + // max_value not set for Seq_state + // min_value not set for Seq_state + // max_alarm not set for Seq_state + // min_alarm not set for Seq_state + // max_warning not set for Seq_state + // min_warning not set for Seq_state + // delta_t not set for Seq_state + // delta_val not set for Seq_state + + seq_state->set_default_properties(seq_state_prop); + // Not Polled + seq_state->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(seq_state); + + // Attribute : EnableBPM11_2 + EnableBPM11_2Attrib *enablebpm11_2 = new EnableBPM11_2Attrib(); + Tango::UserDefaultAttrProp enablebpm11_2_prop; + // description not set for EnableBPM11_2 + // label not set for EnableBPM11_2 + // unit not set for EnableBPM11_2 + // standard_unit not set for EnableBPM11_2 + // display_unit not set for EnableBPM11_2 + // format not set for EnableBPM11_2 + // max_value not set for EnableBPM11_2 + // min_value not set for EnableBPM11_2 + // max_alarm not set for EnableBPM11_2 + // min_alarm not set for EnableBPM11_2 + // max_warning not set for EnableBPM11_2 + // min_warning not set for EnableBPM11_2 + // delta_t not set for EnableBPM11_2 + // delta_val not set for EnableBPM11_2 + + enablebpm11_2->set_default_properties(enablebpm11_2_prop); + // Not Polled + enablebpm11_2->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(enablebpm11_2); + + // Attribute : OpenId + OpenIdAttrib *openid = new OpenIdAttrib(); + Tango::UserDefaultAttrProp openid_prop; + // description not set for OpenId + // label not set for OpenId + // unit not set for OpenId + // standard_unit not set for OpenId + // display_unit not set for OpenId + // format not set for OpenId + // max_value not set for OpenId + // min_value not set for OpenId + // max_alarm not set for OpenId + // min_alarm not set for OpenId + // max_warning not set for OpenId + // min_warning not set for OpenId + // delta_t not set for OpenId + // delta_val not set for OpenId + + openid->set_default_properties(openid_prop); + // Not Polled + openid->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(openid); + + // Attribute : DiodeDet + DiodeDetAttrib *diodedet = new DiodeDetAttrib(); + Tango::UserDefaultAttrProp diodedet_prop; + // description not set for DiodeDet + // label not set for DiodeDet + // unit not set for DiodeDet + // standard_unit not set for DiodeDet + // display_unit not set for DiodeDet + // format not set for DiodeDet + // max_value not set for DiodeDet + // min_value not set for DiodeDet + // max_alarm not set for DiodeDet + // min_alarm not set for DiodeDet + // max_warning not set for DiodeDet + // min_warning not set for DiodeDet + // delta_t not set for DiodeDet + // delta_val not set for DiodeDet + + diodedet->set_default_properties(diodedet_prop); + // Not Polled + diodedet->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(diodedet); + + // Attribute : LiberaSt + LiberaStAttrib *liberast = new LiberaStAttrib(); + Tango::UserDefaultAttrProp liberast_prop; + // description not set for LiberaSt + // label not set for LiberaSt + // unit not set for LiberaSt + // standard_unit not set for LiberaSt + // display_unit not set for LiberaSt + // format not set for LiberaSt + // max_value not set for LiberaSt + // min_value not set for LiberaSt + // max_alarm not set for LiberaSt + // min_alarm not set for LiberaSt + // max_warning not set for LiberaSt + // min_warning not set for LiberaSt + // delta_t not set for LiberaSt + // delta_val not set for LiberaSt + + liberast->set_default_properties(liberast_prop); + // Not Polled + liberast->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(liberast); + + // Attribute : LiberaNd + LiberaNdAttrib *liberand = new LiberaNdAttrib(); + Tango::UserDefaultAttrProp liberand_prop; + // description not set for LiberaNd + // label not set for LiberaNd + // unit not set for LiberaNd + // standard_unit not set for LiberaNd + // display_unit not set for LiberaNd + // format not set for LiberaNd + // max_value not set for LiberaNd + // min_value not set for LiberaNd + // max_alarm not set for LiberaNd + // min_alarm not set for LiberaNd + // max_warning not set for LiberaNd + // min_warning not set for LiberaNd + // delta_t not set for LiberaNd + // delta_val not set for LiberaNd + + liberand->set_default_properties(liberand_prop); + // Not Polled + liberand->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(liberand); + + // Attribute : IlkEnable + IlkEnableAttrib *ilkenable = new IlkEnableAttrib(); + Tango::UserDefaultAttrProp ilkenable_prop; + // description not set for IlkEnable + // label not set for IlkEnable + // unit not set for IlkEnable + // standard_unit not set for IlkEnable + // display_unit not set for IlkEnable + // format not set for IlkEnable + // max_value not set for IlkEnable + // min_value not set for IlkEnable + // max_alarm not set for IlkEnable + // min_alarm not set for IlkEnable + // max_warning not set for IlkEnable + // min_warning not set for IlkEnable + // delta_t not set for IlkEnable + // delta_val not set for IlkEnable + + ilkenable->set_default_properties(ilkenable_prop); + // Not Polled + ilkenable->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(ilkenable); + + // Attribute : AlOpenId + AlOpenIdAttrib *alopenid = new AlOpenIdAttrib(); + Tango::UserDefaultAttrProp alopenid_prop; + // description not set for AlOpenId + // label not set for AlOpenId + // unit not set for AlOpenId + // standard_unit not set for AlOpenId + // display_unit not set for AlOpenId + // format not set for AlOpenId + // max_value not set for AlOpenId + // min_value not set for AlOpenId + // max_alarm not set for AlOpenId + // min_alarm not set for AlOpenId + // max_warning not set for AlOpenId + // min_warning not set for AlOpenId + // delta_t not set for AlOpenId + // delta_val not set for AlOpenId + + alopenid->set_default_properties(alopenid_prop); + // Not Polled + alopenid->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(alopenid); + + // Attribute : AlDiodeDet + AlDiodeDetAttrib *aldiodedet = new AlDiodeDetAttrib(); + Tango::UserDefaultAttrProp aldiodedet_prop; + // description not set for AlDiodeDet + // label not set for AlDiodeDet + // unit not set for AlDiodeDet + // standard_unit not set for AlDiodeDet + // display_unit not set for AlDiodeDet + // format not set for AlDiodeDet + // max_value not set for AlDiodeDet + // min_value not set for AlDiodeDet + // max_alarm not set for AlDiodeDet + // min_alarm not set for AlDiodeDet + // max_warning not set for AlDiodeDet + // min_warning not set for AlDiodeDet + // delta_t not set for AlDiodeDet + // delta_val not set for AlDiodeDet + + aldiodedet->set_default_properties(aldiodedet_prop); + // Not Polled + aldiodedet->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(aldiodedet); + + // Attribute : AlLiberaSt + AlLiberaStAttrib *alliberast = new AlLiberaStAttrib(); + Tango::UserDefaultAttrProp alliberast_prop; + // description not set for AlLiberaSt + // label not set for AlLiberaSt + // unit not set for AlLiberaSt + // standard_unit not set for AlLiberaSt + // display_unit not set for AlLiberaSt + // format not set for AlLiberaSt + // max_value not set for AlLiberaSt + // min_value not set for AlLiberaSt + // max_alarm not set for AlLiberaSt + // min_alarm not set for AlLiberaSt + // max_warning not set for AlLiberaSt + // min_warning not set for AlLiberaSt + // delta_t not set for AlLiberaSt + // delta_val not set for AlLiberaSt + + alliberast->set_default_properties(alliberast_prop); + // Not Polled + alliberast->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(alliberast); + + // Attribute : AlLiberaNd + AlLiberaNdAttrib *alliberand = new AlLiberaNdAttrib(); + Tango::UserDefaultAttrProp alliberand_prop; + // description not set for AlLiberaNd + // label not set for AlLiberaNd + // unit not set for AlLiberaNd + // standard_unit not set for AlLiberaNd + // display_unit not set for AlLiberaNd + // format not set for AlLiberaNd + // max_value not set for AlLiberaNd + // min_value not set for AlLiberaNd + // max_alarm not set for AlLiberaNd + // min_alarm not set for AlLiberaNd + // max_warning not set for AlLiberaNd + // min_warning not set for AlLiberaNd + // delta_t not set for AlLiberaNd + // delta_val not set for AlLiberaNd + + alliberand->set_default_properties(alliberand_prop); + // Not Polled + alliberand->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(alliberand); + + // Attribute : Seq_num + Seq_numAttrib *seq_num = new Seq_numAttrib(); + Tango::UserDefaultAttrProp seq_num_prop; + // description not set for Seq_num + // label not set for Seq_num + // unit not set for Seq_num + // standard_unit not set for Seq_num + // display_unit not set for Seq_num + // format not set for Seq_num + // max_value not set for Seq_num + // min_value not set for Seq_num + // max_alarm not set for Seq_num + // min_alarm not set for Seq_num + // max_warning not set for Seq_num + // min_warning not set for Seq_num + // delta_t not set for Seq_num + // delta_val not set for Seq_num + + seq_num->set_default_properties(seq_num_prop); + // Not Polled + seq_num->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(seq_num); + + + // Create a list of static attributes + create_static_attribute_list(get_class_attr()->get_attr_list()); + /*----- PROTECTED REGION ID(PLCsocketClass::attribute_factory_after) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::attribute_factory_after +} +//-------------------------------------------------------- +/** + * Method : PLCsocketClass::pipe_factory() + * Description : Create the pipe object(s) + * and store them in the pipe list + */ +//-------------------------------------------------------- +void PLCsocketClass::pipe_factory() +{ + /*----- PROTECTED REGION ID(PLCsocketClass::pipe_factory_before) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::pipe_factory_before + /*----- PROTECTED REGION ID(PLCsocketClass::pipe_factory_after) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::pipe_factory_after +} +//-------------------------------------------------------- +/** + * Method : PLCsocketClass::command_factory() + * Description : Create the command object(s) + * and store them in the command list + */ +//-------------------------------------------------------- +void PLCsocketClass::command_factory() +{ + /*----- PROTECTED REGION ID(PLCsocketClass::command_factory_before) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::command_factory_before + + + // Command Beam_dump + Beam_dumpClass *pBeam_dumpCmd = + new Beam_dumpClass("Beam_dump", + Tango::DEV_VOID, Tango::DEV_STRING, + "", + "", + Tango::OPERATOR); + command_list.push_back(pBeam_dumpCmd); + + // Command Send_ack + Send_ackClass *pSend_ackCmd = + new Send_ackClass("Send_ack", + Tango::DEV_VOID, Tango::DEV_STRING, + "", + "", + Tango::OPERATOR); + command_list.push_back(pSend_ackCmd); + + // Command Seq_state_rst + Seq_state_rstClass *pSeq_state_rstCmd = + new Seq_state_rstClass("Seq_state_rst", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pSeq_state_rstCmd); + + // Command Test_debug + Test_debugClass *pTest_debugCmd = + new Test_debugClass("Test_debug", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pTest_debugCmd); + + // Command EnableBPM11_2 + EnableBPM11_2Class *pEnableBPM11_2Cmd = + new EnableBPM11_2Class("EnableBPM11_2", + Tango::DEV_BOOLEAN, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pEnableBPM11_2Cmd); + + // Command DisableInterlockSCW + DisableInterlockSCWClass *pDisableInterlockSCWCmd = + new DisableInterlockSCWClass("DisableInterlockSCW", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pDisableInterlockSCWCmd); + + // Command DisableInterlockID5 + DisableInterlockID5Class *pDisableInterlockID5Cmd = + new DisableInterlockID5Class("DisableInterlockID5", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pDisableInterlockID5Cmd); + + /*----- PROTECTED REGION ID(PLCsocketClass::command_factory_after) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::command_factory_after +} + +//=================================================================== +// Dynamic attributes related methods +//=================================================================== + +//-------------------------------------------------------- +/** + * method : PLCsocketClass::create_static_attribute_list + * description : Create the a list of static attributes + * + * @param att_list the ceated attribute list + */ +//-------------------------------------------------------- +void PLCsocketClass::create_static_attribute_list(vector<Tango::Attr *> &att_list) +{ + for (unsigned long i=0 ; i<att_list.size() ; i++) + { + string att_name(att_list[i]->get_name()); + transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower); + defaultAttList.push_back(att_name); + } + + cout2 << defaultAttList.size() << " attributes in default list" << endl; + + /*----- PROTECTED REGION ID(PLCsocketClass::create_static_att_list) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::create_static_att_list +} + + +//-------------------------------------------------------- +/** + * method : PLCsocketClass::erase_dynamic_attributes + * description : delete the dynamic attributes if any. + * + * @param devlist_ptr the device list pointer + * @param list of all attributes + */ +//-------------------------------------------------------- +void PLCsocketClass::erase_dynamic_attributes(const Tango::DevVarStringArray *devlist_ptr, 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(((string)(*devlist_ptr)[i]).c_str()); + PLCsocket *dev = static_cast<PLCsocket *> (dev_impl); + + vector<Tango::Attribute *> &dev_att_list = dev->get_device_attr()->get_attribute_list(); + vector<Tango::Attribute *>::iterator ite_att; + for (ite_att=dev_att_list.begin() ; ite_att != dev_att_list.end() ; ++ite_att) + { + string att_name((*ite_att)->get_name_lower()); + if ((att_name == "state") || (att_name == "status")) + continue; + vector<string>::iterator ite_str = find(defaultAttList.begin(), defaultAttList.end(), att_name); + if (ite_str == defaultAttList.end()) + { + cout2 << att_name << " is a UNWANTED dynamic attribute for device " << (*devlist_ptr)[i] << 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(PLCsocketClass::erase_dynamic_attributes) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::erase_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Method : PLCsocketClass::get_attr_by_name() + * Description : returns Tango::Attr * object found by name + */ +//-------------------------------------------------------- +Tango::Attr *PLCsocketClass::get_attr_object_by_name(vector<Tango::Attr *> &att_list, string attname) +{ + 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(PLCsocketClass::Additional Methods) ENABLED START -----*/ + +/*----- PROTECTED REGION END -----*/ // PLCsocketClass::Additional Methods +} // namespace diff --git a/src/PLCsocketClass.h b/src/PLCsocketClass.h new file mode 100644 index 0000000000000000000000000000000000000000..eceb8a888cf4d16708b1be52d41b13aa3253fc07 --- /dev/null +++ b/src/PLCsocketClass.h @@ -0,0 +1,525 @@ +/*----- PROTECTED REGION ID(PLCsocketClass.h) ENABLED START -----*/ +//============================================================================= +// +// file : PLCsocketClass.h +// +// description : Include for the PLCsocket root class. +// This class is the singleton class for +// the PLCsocket device class. +// It contains all properties and methods which the +// PLCsocket requires only once e.g. the commands. +// +// project : PLC interlock server +// +// 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/>. +// +// $Author: graziano $ +// +// $Revision: 1.7 $ +// $Date: 2017-02-23 08:42:46 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#ifndef PLCsocketClass_H +#define PLCsocketClass_H + +#include <tango.h> +#include <PLCsocket.h> + +/*----- PROTECTED REGION END -----*/ // PLCsocketClass.h + + +namespace PLCsocket_ns +{ +/*----- PROTECTED REGION ID(PLCsocketClass::classes for dynamic creation) ENABLED START -----*/ + + +/*----- PROTECTED REGION END -----*/ // PLCsocketClass::classes for dynamic creation + +//========================================= +// Define classes for attributes +//========================================= +// Attribute IThreshold class definition +class IThresholdAttrib: public Tango::Attr +{ +public: + IThresholdAttrib():Attr("IThreshold", + Tango::DEV_BOOLEAN, Tango::READ) {}; + ~IThresholdAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_IThreshold(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_IThreshold_allowed(ty);} +}; + +// Attribute Libera3hc class definition +class Libera3hcAttrib: public Tango::Attr +{ +public: + Libera3hcAttrib():Attr("Libera3hc", + Tango::DEV_BOOLEAN, Tango::READ) {}; + ~Libera3hcAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_Libera3hc(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_Libera3hc_allowed(ty);} +}; + +// Attribute BeamDumpPLCA10 class definition +class BeamDumpPLCA10Attrib: public Tango::Attr +{ +public: + BeamDumpPLCA10Attrib():Attr("BeamDumpPLCA10", + Tango::DEV_BOOLEAN, Tango::READ) {}; + ~BeamDumpPLCA10Attrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_BeamDumpPLCA10(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_BeamDumpPLCA10_allowed(ty);} +}; + +// Attribute BeamAbi class definition +class BeamAbiAttrib: public Tango::Attr +{ +public: + BeamAbiAttrib():Attr("BeamAbi", + Tango::DEV_BOOLEAN, Tango::READ) {}; + ~BeamAbiAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_BeamAbi(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_BeamAbi_allowed(ty);} +}; + +// Attribute CallPm class definition +class CallPmAttrib: public Tango::Attr +{ +public: + CallPmAttrib():Attr("CallPm", + Tango::DEV_BOOLEAN, Tango::READ) {}; + ~CallPmAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_CallPm(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_CallPm_allowed(ty);} +}; + +// Attribute AlIThreshold class definition +class AlIThresholdAttrib: public Tango::Attr +{ +public: + AlIThresholdAttrib():Attr("AlIThreshold", + Tango::DEV_BOOLEAN, Tango::READ) {}; + ~AlIThresholdAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_AlIThreshold(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_AlIThreshold_allowed(ty);} +}; + +// Attribute AlLibera3hc class definition +class AlLibera3hcAttrib: public Tango::Attr +{ +public: + AlLibera3hcAttrib():Attr("AlLibera3hc", + Tango::DEV_BOOLEAN, Tango::READ) {}; + ~AlLibera3hcAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_AlLibera3hc(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_AlLibera3hc_allowed(ty);} +}; + +// Attribute Seq_state class definition +class Seq_stateAttrib: public Tango::Attr +{ +public: + Seq_stateAttrib():Attr("Seq_state", + Tango::DEV_STRING, Tango::READ) {}; + ~Seq_stateAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_Seq_state(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_Seq_state_allowed(ty);} +}; + +// Attribute EnableBPM11_2 class definition +class EnableBPM11_2Attrib: public Tango::Attr +{ +public: + EnableBPM11_2Attrib():Attr("EnableBPM11_2", + Tango::DEV_BOOLEAN, Tango::READ) {}; + ~EnableBPM11_2Attrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_EnableBPM11_2(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_EnableBPM11_2_allowed(ty);} +}; + +// Attribute OpenId class definition +class OpenIdAttrib: public Tango::SpectrumAttr +{ +public: + OpenIdAttrib():SpectrumAttr("OpenId", + Tango::DEV_BOOLEAN, Tango::READ, 16) {}; + ~OpenIdAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_OpenId(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_OpenId_allowed(ty);} +}; + +// Attribute DiodeDet class definition +class DiodeDetAttrib: public Tango::SpectrumAttr +{ +public: + DiodeDetAttrib():SpectrumAttr("DiodeDet", + Tango::DEV_BOOLEAN, Tango::READ, 16) {}; + ~DiodeDetAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_DiodeDet(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_DiodeDet_allowed(ty);} +}; + +// Attribute LiberaSt class definition +class LiberaStAttrib: public Tango::SpectrumAttr +{ +public: + LiberaStAttrib():SpectrumAttr("LiberaSt", + Tango::DEV_BOOLEAN, Tango::READ, 16) {}; + ~LiberaStAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_LiberaSt(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_LiberaSt_allowed(ty);} +}; + +// Attribute LiberaNd class definition +class LiberaNdAttrib: public Tango::SpectrumAttr +{ +public: + LiberaNdAttrib():SpectrumAttr("LiberaNd", + Tango::DEV_BOOLEAN, Tango::READ, 16) {}; + ~LiberaNdAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_LiberaNd(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_LiberaNd_allowed(ty);} +}; + +// Attribute IlkEnable class definition +class IlkEnableAttrib: public Tango::SpectrumAttr +{ +public: + IlkEnableAttrib():SpectrumAttr("IlkEnable", + Tango::DEV_BOOLEAN, Tango::READ, 16) {}; + ~IlkEnableAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_IlkEnable(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_IlkEnable_allowed(ty);} +}; + +// Attribute AlOpenId class definition +class AlOpenIdAttrib: public Tango::SpectrumAttr +{ +public: + AlOpenIdAttrib():SpectrumAttr("AlOpenId", + Tango::DEV_BOOLEAN, Tango::READ, 16) {}; + ~AlOpenIdAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_AlOpenId(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_AlOpenId_allowed(ty);} +}; + +// Attribute AlDiodeDet class definition +class AlDiodeDetAttrib: public Tango::SpectrumAttr +{ +public: + AlDiodeDetAttrib():SpectrumAttr("AlDiodeDet", + Tango::DEV_BOOLEAN, Tango::READ, 16) {}; + ~AlDiodeDetAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_AlDiodeDet(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_AlDiodeDet_allowed(ty);} +}; + +// Attribute AlLiberaSt class definition +class AlLiberaStAttrib: public Tango::SpectrumAttr +{ +public: + AlLiberaStAttrib():SpectrumAttr("AlLiberaSt", + Tango::DEV_BOOLEAN, Tango::READ, 16) {}; + ~AlLiberaStAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_AlLiberaSt(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_AlLiberaSt_allowed(ty);} +}; + +// Attribute AlLiberaNd class definition +class AlLiberaNdAttrib: public Tango::SpectrumAttr +{ +public: + AlLiberaNdAttrib():SpectrumAttr("AlLiberaNd", + Tango::DEV_BOOLEAN, Tango::READ, 16) {}; + ~AlLiberaNdAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_AlLiberaNd(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_AlLiberaNd_allowed(ty);} +}; + +// Attribute Seq_num class definition +class Seq_numAttrib: public Tango::SpectrumAttr +{ +public: + Seq_numAttrib():SpectrumAttr("Seq_num", + Tango::DEV_DOUBLE, Tango::READ, 3) {}; + ~Seq_numAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<PLCsocket *>(dev))->read_Seq_num(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<PLCsocket *>(dev))->is_Seq_num_allowed(ty);} +}; + + +//========================================= +// Define classes for commands +//========================================= +// Command Beam_dump class definition +class Beam_dumpClass : public Tango::Command +{ +public: + Beam_dumpClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + Beam_dumpClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~Beam_dumpClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<PLCsocket *>(dev))->is_Beam_dump_allowed(any);} +}; + +// Command Send_ack class definition +class Send_ackClass : public Tango::Command +{ +public: + Send_ackClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + Send_ackClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~Send_ackClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<PLCsocket *>(dev))->is_Send_ack_allowed(any);} +}; + +// Command Seq_state_rst class definition +class Seq_state_rstClass : public Tango::Command +{ +public: + Seq_state_rstClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + Seq_state_rstClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~Seq_state_rstClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<PLCsocket *>(dev))->is_Seq_state_rst_allowed(any);} +}; + +// Command Test_debug class definition +class Test_debugClass : public Tango::Command +{ +public: + Test_debugClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + Test_debugClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~Test_debugClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<PLCsocket *>(dev))->is_Test_debug_allowed(any);} +}; + +// Command EnableBPM11_2 class definition +class EnableBPM11_2Class : public Tango::Command +{ +public: + EnableBPM11_2Class(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + EnableBPM11_2Class(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~EnableBPM11_2Class() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<PLCsocket *>(dev))->is_EnableBPM11_2_allowed(any);} +}; + +// Command DisableInterlockSCW class definition +class DisableInterlockSCWClass : public Tango::Command +{ +public: + DisableInterlockSCWClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + DisableInterlockSCWClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~DisableInterlockSCWClass() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<PLCsocket *>(dev))->is_DisableInterlockSCW_allowed(any);} +}; + +// Command DisableInterlockID5 class definition +class DisableInterlockID5Class : public Tango::Command +{ +public: + DisableInterlockID5Class(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(name,in,out,in_desc,out_desc, level) {}; + + DisableInterlockID5Class(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~DisableInterlockID5Class() {}; + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<PLCsocket *>(dev))->is_DisableInterlockID5_allowed(any);} +}; + + +/** + * The PLCsocketClass singleton definition + */ + +#ifdef _TG_WINDOWS_ +class __declspec(dllexport) PLCsocketClass : public Tango::DeviceClass +#else +class PLCsocketClass : public Tango::DeviceClass +#endif +{ + /*----- PROTECTED REGION ID(PLCsocketClass::Additionnal DServer data members) ENABLED START -----*/ + + + /*----- PROTECTED REGION END -----*/ // PLCsocketClass::Additionnal 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 PLCsocketClass *init(const char *); + static PLCsocketClass *instance(); + ~PLCsocketClass(); + Tango::DbDatum get_class_property(string &); + Tango::DbDatum get_default_device_property(string &); + Tango::DbDatum get_default_class_property(string &); + + protected: + PLCsocketClass(string &); + static PLCsocketClass *_instance; + void command_factory(); + void attribute_factory(vector<Tango::Attr *> &); + void pipe_factory(); + void write_class_property(); + void set_default_property(); + void get_class_property(); + string get_cvstag(); + string get_cvsroot(); + + private: + void device_factory(const Tango::DevVarStringArray *); + void create_static_attribute_list(vector<Tango::Attr *> &); + void erase_dynamic_attributes(const Tango::DevVarStringArray *,vector<Tango::Attr *> &); + vector<string> defaultAttList; + Tango::Attr *get_attr_object_by_name(vector<Tango::Attr *> &att_list, string attname); +}; + +} // End of namespace + +#endif // PLCsocket_H diff --git a/src/PLCsocketStateMachine.cpp b/src/PLCsocketStateMachine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b2f3acfb9f62c44ff003106be895b0169cf9fb2 --- /dev/null +++ b/src/PLCsocketStateMachine.cpp @@ -0,0 +1,479 @@ +/*----- PROTECTED REGION ID(PLCsocketStateMachine.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: PLCsocketStateMachine.cpp,v 1.6 2017-02-23 08:42:46 graziano Exp $"; +//============================================================================= +// +// file : PLCsocketStateMachine.cpp +// +// description : State machine file for the PLCsocket class +// +// project : PLC interlock server +// +// 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/>. +// +// $Author: graziano $ +// +// $Revision: 1.6 $ +// $Date: 2017-02-23 08:42:46 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + +#include <PLCsocket.h> + +/*----- PROTECTED REGION END -----*/ // PLCsocket::PLCsocketStateMachine.cpp + +//================================================================ +// States | Description +//================================================================ +// ON | * +// FAULT | Severe error occurred +// UNKNOWN | Data timestamp is not coherent +// ALARM | * +// DISABLE | Logging DB connection is not available, the server is not logging + + +namespace PLCsocket_ns +{ +//================================================= +// Attributes Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_IThreshold_allowed() + * Description : Execution allowed for IThreshold attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_IThreshold_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for IThreshold attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::IThresholdStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::IThresholdStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_Libera3hc_allowed() + * Description : Execution allowed for Libera3hc attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_Libera3hc_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for Libera3hc attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::Libera3hcStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::Libera3hcStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_BeamDumpPLCA10_allowed() + * Description : Execution allowed for BeamDumpPLCA10 attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_BeamDumpPLCA10_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for BeamDumpPLCA10 attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::BeamDumpPLCA10StateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::BeamDumpPLCA10StateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_BeamAbi_allowed() + * Description : Execution allowed for BeamAbi attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_BeamAbi_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for BeamAbi attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::BeamAbiStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::BeamAbiStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_CallPm_allowed() + * Description : Execution allowed for CallPm attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_CallPm_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for CallPm attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::CallPmStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::CallPmStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_AlIThreshold_allowed() + * Description : Execution allowed for AlIThreshold attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_AlIThreshold_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for AlIThreshold attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::AlIThresholdStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::AlIThresholdStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_AlLibera3hc_allowed() + * Description : Execution allowed for AlLibera3hc attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_AlLibera3hc_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for AlLibera3hc attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::AlLibera3hcStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::AlLibera3hcStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_Seq_state_allowed() + * Description : Execution allowed for Seq_state attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_Seq_state_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for Seq_state attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::Seq_stateStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::Seq_stateStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_EnableBPM11_2_allowed() + * Description : Execution allowed for EnableBPM11_2 attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_EnableBPM11_2_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for EnableBPM11_2 attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::EnableBPM11_2StateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::EnableBPM11_2StateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_OpenId_allowed() + * Description : Execution allowed for OpenId attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_OpenId_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for OpenId attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::OpenIdStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::OpenIdStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_DiodeDet_allowed() + * Description : Execution allowed for DiodeDet attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_DiodeDet_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for DiodeDet attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::DiodeDetStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::DiodeDetStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_LiberaSt_allowed() + * Description : Execution allowed for LiberaSt attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_LiberaSt_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for LiberaSt attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::LiberaStStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::LiberaStStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_LiberaNd_allowed() + * Description : Execution allowed for LiberaNd attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_LiberaNd_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for LiberaNd attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::LiberaNdStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::LiberaNdStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_IlkEnable_allowed() + * Description : Execution allowed for IlkEnable attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_IlkEnable_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for IlkEnable attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::IlkEnableStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::IlkEnableStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_AlOpenId_allowed() + * Description : Execution allowed for AlOpenId attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_AlOpenId_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for AlOpenId attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::AlOpenIdStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::AlOpenIdStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_AlDiodeDet_allowed() + * Description : Execution allowed for AlDiodeDet attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_AlDiodeDet_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for AlDiodeDet attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::AlDiodeDetStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::AlDiodeDetStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_AlLiberaSt_allowed() + * Description : Execution allowed for AlLiberaSt attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_AlLiberaSt_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for AlLiberaSt attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::AlLiberaStStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::AlLiberaStStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_AlLiberaNd_allowed() + * Description : Execution allowed for AlLiberaNd attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_AlLiberaNd_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for AlLiberaNd attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::AlLiberaNdStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::AlLiberaNdStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_Seq_num_allowed() + * Description : Execution allowed for Seq_num attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_Seq_num_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for Seq_num attribute in read access. + /*----- PROTECTED REGION ID(PLCsocket::Seq_numStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::Seq_numStateAllowed_READ + return true; +} + + +//================================================= +// Commands Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_Beam_dump_allowed() + * Description : Execution allowed for Beam_dump attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_Beam_dump_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for Beam_dump command. + /*----- PROTECTED REGION ID(PLCsocket::Beam_dumpStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::Beam_dumpStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_Send_ack_allowed() + * Description : Execution allowed for Send_ack attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_Send_ack_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for Send_ack command. + /*----- PROTECTED REGION ID(PLCsocket::Send_ackStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::Send_ackStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_Seq_state_rst_allowed() + * Description : Execution allowed for Seq_state_rst attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_Seq_state_rst_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for Seq_state_rst command. + /*----- PROTECTED REGION ID(PLCsocket::Seq_state_rstStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::Seq_state_rstStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_Test_debug_allowed() + * Description : Execution allowed for Test_debug attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_Test_debug_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for Test_debug command. + /*----- PROTECTED REGION ID(PLCsocket::Test_debugStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::Test_debugStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_EnableBPM11_2_allowed() + * Description : Execution allowed for EnableBPM11_2 attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_EnableBPM11_2_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for EnableBPM11_2 command. + /*----- PROTECTED REGION ID(PLCsocket::EnableBPM11_2StateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::EnableBPM11_2StateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_DisableInterlockSCW_allowed() + * Description : Execution allowed for DisableInterlockSCW attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_DisableInterlockSCW_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for DisableInterlockSCW command. + /*----- PROTECTED REGION ID(PLCsocket::DisableInterlockSCWStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::DisableInterlockSCWStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : PLCsocket::is_DisableInterlockID5_allowed() + * Description : Execution allowed for DisableInterlockID5 attribute + */ +//-------------------------------------------------------- +bool PLCsocket::is_DisableInterlockID5_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for DisableInterlockID5 command. + /*----- PROTECTED REGION ID(PLCsocket::DisableInterlockID5StateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // PLCsocket::DisableInterlockID5StateAllowed + return true; +} + + +/*----- PROTECTED REGION ID(PLCsocket::PLCsocketStateAllowed.AdditionalMethods) ENABLED START -----*/ + +// Additional Methods + +/*----- PROTECTED REGION END -----*/ // PLCsocket::PLCsocketStateAllowed.AdditionalMethods + +} // End of namespace diff --git a/src/TangoClassID.txt b/src/TangoClassID.txt new file mode 100644 index 0000000000000000000000000000000000000000..9643973a8bc5d7e87c5c4ea3bf4f99792f62f5b0 --- /dev/null +++ b/src/TangoClassID.txt @@ -0,0 +1,11 @@ +/** + * Device Class Identification: + * + * Class Name : PLCsocket + * Contact : claudio.scafuri@elettra.trieste.it + * Class Family : Misc + * Platform : Unix Like + * Bus : tcp/ip + * Manufacturer : none + * Reference : + */ diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..651558deb59ff2b178f4e2c41bfc13144ed554ac --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,82 @@ +/*----- PROTECTED REGION ID(PLCsocket::main.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: main.cpp,v 1.2 2014-04-22 13:02:39 graziano Exp $"; +//============================================================================= +// +// file : main.cpp +// +// description : C++ source for the PLCsocket device server main. +// The main rule is to initialise (and create) the Tango +// system and to create the DServerClass singleton. +// The main should be the same for every Tango device server. +// +// project : PLC interlock server +// +// 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/>. +// +// $Author: graziano $ +// +// $Revision: 1.2 $ +// $Date: 2014-04-22 13:02:39 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include <tango.h> + + +int main(int argc,char *argv[]) +{ + + Tango::Util *tg; + try + { + // Initialise 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 + //---------------------------------------- + cout << "Ready to accept request" << endl; + tg->server_run(); + } + catch (bad_alloc) + { + cout << "Can't allocate memory to store device object !!!" << endl; + cout << "Exiting" << endl; + } + catch (CORBA::Exception &e) + { + Tango::Except::print_exception(e); + + cout << "Received a CORBA_Exception" << endl; + cout << "Exiting" << endl; + } + tg->server_cleanup(); + return(0); +} + + +/*----- PROTECTED REGION END -----*/ // PLCsocket::main.cpp diff --git a/src/plclgthread.cpp b/src/plclgthread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3ba80d81569f1c9827f177fa552d6045dc1f070e --- /dev/null +++ b/src/plclgthread.cpp @@ -0,0 +1,157 @@ +/* + * plclgthread.cpp + * + * 10.04.06 - SF: first release + * + * + */ + +#include "plclgthread.h" + + +/* + * plclgthread::run() + * Run + */ +void *plclgthread::run_undetached(void *) +{ + struct timeval _pre2, _post2; + int pausesec2,pausenano2; + unsigned char buf_local_tstamp[TSTAMP_SIZE]; + char buf_tmp[10]; + + + //semaphore management + + retval = 0; + id = semget(1000, 1, 0666); + if(id < 0){ + DEBUG_STREAM << "plclgthread::lgThread cannot find semaphore" << endl; + } + else{ + DEBUG_STREAM << "plclgthread::lgThread found semaphore" << endl; + } + + while (!t_PLCsocket->abortflag) { + + //log to db elements of the message list + int k=0; + + PLCsocket_ns::intlck_libera_t m; + + + operations[0].sem_num = 0; + operations[0].sem_op = 0; + operations[0].sem_flg = 0; + lock_ops[0].sem_num = 0; + lock_ops[0].sem_op = 1; + lock_ops[0].sem_flg = 0; + unlock_ops[0].sem_num = 0; + unlock_ops[0].sem_op = -1; + unlock_ops[0].sem_flg = 0; + + while(!t_PLCsocket->mesg_list.empty()){ + retval = semop(id, operations, 1); + m = t_PLCsocket->mesg_list.front(); + t_PLCsocket->log_msg(m); + t_PLCsocket->mesg_list.pop_front(); + //saving old message + bcopy(&t_PLCsocket->message, &t_PLCsocket->old_message, (sizeof(PLCsocket_ns::intlck_libera))); + t_PLCsocket->message = m; + char locbuf[SRV_BUF_LEN]; + bcopy(&t_PLCsocket->message, &locbuf, (sizeof(PLCsocket_ns::intlck_libera))); + //logging on tango debug stream + char tmp_buf[SRV_BUF_LEN]; + string x; + for(int j=0;j<(int)(sizeof(PLCsocket_ns::intlck_libera));j++){ + memset (tmp_buf, 0, sizeof(tmp_buf) ); + sprintf(tmp_buf, "%02X-", locbuf[j]);//change here the format of saved data + x.append(tmp_buf); + } + printf("%s\n",x.c_str()); +//////////////////////////////////////////////////////////////////////////disabled +/* if(t_PLCsocket->logging_msg == 1){ + char tmp_buf[SRV_BUF_LEN]; + string x; + for(int j=0;j<(int)(sizeof(PLCsocket_ns::intlck_libera)/4);j++){ + memset (tmp_buf, 0, sizeof(tmp_buf) ); + sprintf(tmp_buf, "%02X-", locbuf[j]);//change here the format of saved data + x.append(tmp_buf); + } + DEBUG_STREAM << x << endl; + x.clear(); + for(int j=(int)(sizeof(PLCsocket_ns::intlck_libera)/4);j<(int)(sizeof(PLCsocket_ns::intlck_libera)/2);j++){ + memset (tmp_buf, 0, sizeof(tmp_buf) ); + sprintf(tmp_buf, "%02X-", locbuf[j]);//change here the format of saved data + x.append(tmp_buf); + } + DEBUG_STREAM << x << endl; + x.clear(); + for(int j=(int)(sizeof(PLCsocket_ns::intlck_libera)/2);j<(int)(sizeof(PLCsocket_ns::intlck_libera)*3/4);j++){ + memset (tmp_buf, 0, sizeof(tmp_buf) ); + sprintf(tmp_buf, "%02X-", locbuf[j]);//change here the format of saved data + x.append(tmp_buf); + } + DEBUG_STREAM << x << endl; + x.clear(); + for(int j=(int)(sizeof(PLCsocket_ns::intlck_libera)*3/4);j<sizeof(PLCsocket_ns::intlck_libera);j++){ + memset (tmp_buf, 0, sizeof(tmp_buf) ); + sprintf(tmp_buf, "%02X-", locbuf[j]);//change here the format of saved data + x.append(tmp_buf); + } + DEBUG_STREAM << x << endl; + }*/ +/////////////////////////////////////////////////////////////////////////////////// + //detects alarmed inputs + if((m.campo_ingressi_1&m.campo_ingressi_2& + m.campo_ingressi_3&m.campo_ingressi_4& + m.campo_ingressi_5) == 0xffff){//no alarm found + ; + } + else{ + //prepare ack mask and send auto acknowledge + + t_PLCsocket->i_answer.ack_1 = 0xffff&(~(m.memo_allarmi_1)); + t_PLCsocket->i_answer.ack_2 = 0xffff&(~(m.memo_allarmi_2)); + t_PLCsocket->i_answer.ack_3 = 0xffff&(~(m.memo_allarmi_3)); + t_PLCsocket->i_answer.ack_4 = 0xffff&(~(m.memo_allarmi_4)); + t_PLCsocket->i_answer.ack_5 = 0xffff&(~(m.memo_allarmi_5)); + + if((t_PLCsocket->ack_policy)==AUTO_ACK) + t_PLCsocket->send_auto_ack(); + } + + //pushing user events to subscribed clients + //the XOR between old and new monitored signals traces changes + + if ((m.mesg_type & CHANGE_MESG) || \ + (m.mesg_type & BDCA_MESG) || \ + (m.mesg_type & PERIODIC_MESG)) { //if it is NOT a periodic message + t_PLCsocket->push_it(); + t_PLCsocket->seq[1] = m.seq_async; + }//changes not monitored from plc, like beam abi + else { + int condition[9]; + condition[0] = m.campo_ingressi_1^t_PLCsocket->old_message.campo_ingressi_1; + condition[1] = m.campo_ingressi_2^t_PLCsocket->old_message.campo_ingressi_2; + condition[2] = m.campo_ingressi_3^t_PLCsocket->old_message.campo_ingressi_3; + condition[3] = m.campo_ingressi_4^t_PLCsocket->old_message.campo_ingressi_4; + condition[4] = m.campo_ingressi_5^t_PLCsocket->old_message.campo_ingressi_5; + condition[5]=((m.campo_uscite_2&PLCsocket_ns::maskbits[0])^(t_PLCsocket->old_message.campo_uscite_2&PLCsocket_ns::maskbits[0])); + + if((condition[0]|condition[1]|condition[2]|condition[3]|condition[4]|condition[5])!=0x0000){ + t_PLCsocket->push_it(); + } + } + + k++; + } + DEBUG_STREAM << "plclgthread::popped "<< k <<" packets" << endl; + usleep(1000000);//sleep for 1s + + } +} + + + + diff --git a/src/plclgthread.h b/src/plclgthread.h new file mode 100644 index 0000000000000000000000000000000000000000..3a1ff6771daf6166012e404c59d9da46a0dbd341 --- /dev/null +++ b/src/plclgthread.h @@ -0,0 +1,54 @@ +/* + * plclgthread.h + * + * 17.01.07 - SF: heartbeat + */ + +#ifndef plclgthread_H +#define plclgthread_H + +#include <omnithread.h> +#include <tango.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/time.h> +#include <signal.h> +#include <netdb.h> +#include "PLCsocket.h" + +#define SRV_BUF_LEN 2048 +class plclgthread : public omni_thread, public Tango::LogAdapter +{ + private: + PLCsocket_ns::PLCsocket::PLCsocket *t_PLCsocket; + + public: + + plclgthread(PLCsocket_ns::PLCsocket::PLCsocket *s):Tango::LogAdapter(s){ t_PLCsocket = s;}; + + ~plclgthread() {}; + + void *StartUndetached(){ + start_undetached(); + } + void *run_undetached(void *); + + protected: + + struct sembuf operations[1]; + struct sembuf lock_ops[1]; + struct sembuf unlock_ops[1]; + int retval; + int id; + + struct timeval _pre2, _post2; + +}; /* end class plclgthread() */ + + + +#endif + +/* EOF */ diff --git a/src/plcsrvthread.cpp b/src/plcsrvthread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ba6fc9fed5699f5e1195cb5d957ea23bf4ba5aa6 --- /dev/null +++ b/src/plcsrvthread.cpp @@ -0,0 +1,255 @@ +/* + * plcsrvthread.cpp + * + * 10.04.06 - SF: first release + * + * + */ + +#include "plcsrvthread.h" +#include <iomanip> //used for debug dump of db + +/* + * plcsrvthread::run() + * Run + */ +void *plcsrvthread::run_undetached(void *) +{ + + int pausemicro = 3000000; + server_started=0; + first_read=0; + + + while (!t_PLCsocket->abortflag) { + + if(server_started==0) + Srv_Prepare(); + else + t_PLCsocket->set_state(Tango::FAULT); + t_PLCsocket->set_status("srv not connected"); + + usleep(pausemicro); + DEBUG_STREAM << "plcsrvthread::run() trying to reconnect" << endl; + } + +} + + + + +void plcsrvthread::Srv_Prepare(void) +{ + //creating server socket + if (( t_PLCsocket->sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { + server_started=0; + t_PLCsocket->set_state(Tango::FAULT); + t_PLCsocket->set_status("srv sock creating failure"); + DEBUG_STREAM << "plcsrvthread::Srv_Prepare() srv sock creating failure" << endl; + return; + } + myname.sin_family = AF_INET; + myname.sin_port = htons(t_PLCsocket->rport); /// rport=server port + myname.sin_addr.s_addr = inet_addr(t_PLCsocket->srv_host.c_str()); + + if (bind(t_PLCsocket->sock, (const sockaddr*)&myname, sizeof(myname) ) < 0 ) { + close (t_PLCsocket->sock); + server_started=0; + t_PLCsocket->set_state(Tango::FAULT); + t_PLCsocket->set_status("srv sock bind failure"); + DEBUG_STREAM << "plcsrvthread::Srv_Prepare() srv sock bind failure" << endl; + return; + } + + //server socket listening + + if ( listen ( t_PLCsocket->sock, MAX_NUM_SOCK ) < 0 ) { + close (t_PLCsocket->sock); + server_started=0; + t_PLCsocket->set_state(Tango::FAULT); + t_PLCsocket->set_status("srv sock listen failure"); + DEBUG_STREAM << "plcsrvthread::Srv_Prepare() srv sock listen failure" << endl; + return; + } + + while (!t_PLCsocket->abortflag) { + int adrlen = sizeof(struct sockaddr); + server_started=1; //the server is listening + + //semaphore management + retval = 0; + id = semget(1000, 1, 0666); + if(id < 0){ + DEBUG_STREAM << "plcsrvthread::srvThread cannot find semaphore" << endl; + } + else{ + DEBUG_STREAM << "plcsrvthread::srvThread found semaphore" << endl; + } + //assign the accepted socket to new_sd + + if ( ( t_PLCsocket->new_sd = accept ( t_PLCsocket->sock, (sockaddr*)&addr, (socklen_t*)&adrlen ) ) < 0 ) { + t_PLCsocket->set_state(Tango::FAULT); + t_PLCsocket->set_status("srv sock accept failure"); + DEBUG_STREAM << "plcsrvthread::Srv_Prepare() srv sock accept failure" << endl; + } + else{//connection established + t_PLCsocket->set_state(Tango::ON); + t_PLCsocket->set_status("accepted connection"); + DEBUG_STREAM << "plcsrvthread::Srv_Prepare() accepted connection" << endl; + + nptr = (struct sockaddr_in *) &addr; + int counter = 0;//number of read counter + errcount =0; + + do { + memset (buf,0,SRV_BUF_LEN); + + // read message from remote client + int islost = 0; + DEBUG_STREAM << "plcsrvthread::Srv_Prepare() sizes:" << SRV_BUF_LEN <<" "<< (sizeof(PLCsocket_ns::intlck_libera))<<endl; + + if (( cnt = read (t_PLCsocket->new_sd, buf, (sizeof(PLCsocket_ns::intlck_libera)))) < 0 ) { + t_PLCsocket->set_state(Tango::FAULT); + t_PLCsocket->set_status("read failed"); + DEBUG_STREAM << "plcsrvthread::Srv_Prepare() read failed" << endl; + break; + } + else + if (cnt == 0) { + continue; + } + else { //reading ok + //if message.is_valid() + gettimeofday(&_pre,NULL); + + if(cnt == (sizeof(PLCsocket_ns::intlck_libera))){//the message has the right size + + INFO_STREAM << "plcsrvthread::Srv_Prepare() message read" << endl; + DEBUG_STREAM << "plcsrvthread::Srv_Prepare() message cnt:" << cnt<<endl; + for(int k=0;k<cnt;) + { + stringstream tmp; + int g; + tmp << "db50: "<<setw(3)<<setfill(' ')<<k<<" -> "; + for(g=0; g<10; g++) + { + if(k+g>=cnt) + break; + tmp << " " <<hex<<setw(2)<<setfill(' ')<< (int)(unsigned char)buf[k+g]; + } + k+=g; + if(k<cnt) + { + tmp << " | "<<dec<<setw(3)<<setfill(' ')<<k<<hex<<" -> "; + for(g=0; g<10; g++) + { + if(k+g>=cnt) + break; + tmp << " " <<hex<<setw(2)<<setfill(' ')<< (int)(unsigned char)buf[k+g]; + } + k+=g; + } + DEBUG_STREAM<<tmp.str()<<dec<<endl; + } + unsigned short int sbuf[SRV_BUF_LEN];//TODO: stinks... show be made dynamic + unsigned long s1, s2, s3; + memset (sbuf,0,(sizeof(PLCsocket_ns::intlck_libera))); + bcopy(&buf, &sbuf, (sizeof(PLCsocket_ns::intlck_libera))); + for (int i=0; i<cnt; i++){ + sbuf[i] = ntohs(sbuf[i]); + } + + for (int i=0; i<7; i++){ + sbuf[i] = plc_swap(sbuf[i]); + } + + + bcopy(&sbuf, &buf, (sizeof(PLCsocket_ns::intlck_libera))); + + //now saving the old timestamp before overwriting + for(int j=0;j<TSTAMP_SIZE;j++){ + t_PLCsocket->old_timestamp[j] = local_mesg.tstamp_campo[j]; + } + + + //saving message + bcopy(&buf, &local_mesg, (sizeof(PLCsocket_ns::intlck_libera))); + s1 = local_mesg.seq_num; + s2 = local_mesg.seq_async; + s3 = local_mesg.seq_sent; + local_mesg.seq_num = plc_swaplong(s1); + local_mesg.seq_async = plc_swaplong(s2); + local_mesg.seq_sent = plc_swaplong(s3); + + //now saving the new timestamp + for(int j=0;j<TSTAMP_SIZE;j++){ + t_PLCsocket->new_timestamp[j] = local_mesg.tstamp_campo[j]; + } + //sequence number control + if(first_read !=0){ //is not the first message, seq_num control + if((local_mesg.seq_num)!=(first_read+1)){ + t_PLCsocket->seq[0] = local_mesg.seq_num; + t_PLCsocket->s_state = LOSTPK_ST; + islost = 1; + + DEBUG_STREAM << "plcsrvthread::Srv_Prepare() change message lost: " << local_mesg.seq_num \ + << " instead of " << first_read+1 << endl; + } + else islost = 0; + } + first_read = local_mesg.seq_num; + + //lock mesg_list with semaphore + operations[0].sem_num = 0; + operations[0].sem_op = 1; + operations[0].sem_flg = 0; + + retval = semop(id, operations, 1);//semaphore incremented + + //saving message to fifo list + t_PLCsocket->mesg_list.push_back(local_mesg); + + //unlock mesg_list with semaphore + operations[0].sem_num = 0; + operations[0].sem_op = -1; + operations[0].sem_flg = 0; + + retval = semop(id, operations, 1);//semaphore decremented + + if(islost==1){ + gettimeofday(&_post,NULL); + int tempo = (_post.tv_sec - _pre.tv_sec)*1000000 + + (int)((float)(_post.tv_usec - _pre.tv_usec)) ; + // DEBUG_STREAM << "plcsrvthread::Srv_Prepare() read cycle time: "<< tempo << endl; + } + } //end of if count == mesg_len + else{ + if(t_PLCsocket->get_state()!=Tango::FAULT) + t_PLCsocket->set_state(Tango::UNKNOWN); + t_PLCsocket->set_status("wrong message length"); + DEBUG_STREAM << "plcsrvthread::Srv_Prepare() wrong message length: "<< cnt << endl; + } + } // end of message-print else + + // end of do loop statement + }while ((cnt > 0)&&(!t_PLCsocket->abortflag)); // do loop condition + }//end of accept else + } // end of while (1) + server_started=0; + return; + +} + +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)); +} + + + + diff --git a/src/plcsrvthread.h b/src/plcsrvthread.h new file mode 100644 index 0000000000000000000000000000000000000000..8934a9c32e8129123b2bea772035de8eddaf1806 --- /dev/null +++ b/src/plcsrvthread.h @@ -0,0 +1,85 @@ +/* + * plcsrvthread.h + * + * 17.01.07 - SF: first release + * + */ + +#ifndef PLCSRVTHREAD_H +#define PLCSRVTHREAD_H + +#include <omnithread.h> +#include <tango.h> +#include <stdio.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/time.h> +#include <arpa/inet.h> +#include <signal.h> +#include <netdb.h> +#include <PLCsocket.h> + +#define SRV_BUF_LEN 2048 +//number of socket accepted by the server +const short MAX_NUM_SOCK=1; /// + +class plcsrvthread : public omni_thread, public Tango::LogAdapter{ + + private: + PLCsocket_ns::PLCsocket::PLCsocket *t_PLCsocket; + + public: + + plcsrvthread(PLCsocket_ns::PLCsocket::PLCsocket *s):Tango::LogAdapter(s){ + t_PLCsocket = s; + }; + + ~plcsrvthread() { + }; + void *StartUndetached(){ + start_undetached(); + } + void *run_undetached(void *); + + protected: + + int errcount; + struct timeval _pre, _post; + char frame2[SRV_BUF_LEN]; + u_short olddata; + u_long first_read; + PLCsocket_ns::tstamp_t time_before; + PLCsocket_ns::intlck_libera local_mesg; + + struct sembuf operations[1]; + int retval; + int id; + + Tango::DeviceProxy *mydevice; + Tango::DeviceAttribute arl; + + + int cnt, server_started; + + struct sockaddr_in myname; + struct sockaddr_in *nptr; + struct sockaddr addr; + + + char buf[SRV_BUF_LEN]; + + void Srv_Prepare(void); + uint16_t plc_swap(uint16_t in); + uint32_t plc_swaplong(uint32_t in); + +}; /* end class plcsrvthread() */ + + + +#endif + +/* EOF */ diff --git a/src/plctimingthread.cpp b/src/plctimingthread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..43ab869b182ad7d90574fc2865ab825b845974d2 --- /dev/null +++ b/src/plctimingthread.cpp @@ -0,0 +1,293 @@ +/* + * plctimingthread.cpp + * + * 10.04.06 - SF: first release + * + * + */ + +#include "plctimingthread.h" + +//default hour and minute for timeadjust +#define TIMEADJUST_DEF_H 3 +#define TIMEADJUST_DEF_M 5 + +/* + * plctimingthread::run() + * Run + */ +void *plctimingthread::run_undetached(void *) +{ + struct timeval _pre2, _post2; + int pausesec2,pausenano2; + unsigned char buf_local_tstamp[TSTAMP_SIZE]; + char buf_tmp[10]; + + int ch_hour, ch_min; + ch_hour = TIMEADJUST_DEF_H; + ch_min = TIMEADJUST_DEF_M; + char s_hour, s_min, ch_today; + ch_today = 0; + int pos = (t_PLCsocket->timeadjust).find(":"); + if(pos>0){ + ch_hour = atoi(((t_PLCsocket->timeadjust).substr(0, pos)).c_str()); + ch_min = atoi(((t_PLCsocket->timeadjust).substr(pos+1, (t_PLCsocket->timeadjust).length()).c_str())); + if((ch_hour<0)||(ch_hour>23)||(ch_min<0)||(ch_min>59)){ + DEBUG_STREAM << "plctimingthread::run() timeadjust not valid, using "<<TIMEADJUST_DEF_H<<":"<<TIMEADJUST_DEF_M << endl; + ch_hour = TIMEADJUST_DEF_H; + ch_min = TIMEADJUST_DEF_M; + } + } + else{ + DEBUG_STREAM << "plctimingthread::run() timeadjust not valid, using "<<TIMEADJUST_DEF_H<<":"<<TIMEADJUST_DEF_M << endl; + } + memset (buf_tmp,0,10); + sprintf(buf_tmp, "%02d", ch_hour); + s_hour = (buf_tmp[0]-'0'<<4)+buf_tmp[1]-'0'; + memset (buf_tmp,0,10); + sprintf(buf_tmp, "%02d", ch_min); + s_min = (buf_tmp[0]-'0'<<4)+buf_tmp[1]-'0'; + memset (buf_local_tstamp,0,TSTAMP_SIZE); + pausesec2 = (int)((t_PLCsocket->hbeat)/1000); + pausenano2 = ((t_PLCsocket->hbeat)%1000)*1000000; + usleep(pausesec2*1000000+pausenano2/1000);//sleep for heartbeat time, for setup + + + //semaphore management + + retval = 0; + while (!t_PLCsocket->abortflag) { + + //log to db elements of the message list + int k=0; + + PLCsocket_ns::intlck_libera_t m; + for(int k=TSTAMP_SIZE-1;k>=0;k--){ + buf_local_tstamp[k]=t_PLCsocket->new_timestamp[k]; + } + + usleep(pausesec2*1000000+pausenano2/1000);//sleep for heartbeat time + INFO_STREAM << "plctimingthread::run() hbeat ctrl" << endl; + + //verify timestamp + + int equals = 1; + int no_read = 1; + for(int k=TSTAMP_SIZE-1;k>=0;k--){ + if(t_PLCsocket->old_timestamp[k]!=t_PLCsocket->new_timestamp[k]) + equals = 0; + } + for(int k=TSTAMP_SIZE-1;k>=0;k--){ + if(buf_local_tstamp[k]!=t_PLCsocket->new_timestamp[k]) + no_read = 0; + } + + + // calculates timestamp for the time of the server clock + string tst = calc_timest(); + PLCsocket_ns::tstamp_t now; + + for(int k=TSTAMP_SIZE-1;k>=0;k--){ + now[k] = tst.c_str()[k]; + } + + //condition for plc time adjust + if(((now[5]-s_min)==0)&&((now[2]-s_hour)==0)&&((now[3]-ch_today)!=0)){ + t_PLCsocket->sync_plc(now); + ch_today = now[3];//time adjust once a day + } + for(int k=TSTAMP_SIZE-1;k>=0;k--){ + t_PLCsocket->last_ck_read[k] = now[k]; + } + + // translates bcd timestamp into a readable string + + if(equals == 1){ + t_PLCsocket->set_state(Tango::FAULT); + t_PLCsocket->set_status("timestamp is not changing"); + DEBUG_STREAM << "plctimingthread::run() timestamp is not changing" << endl; + } + else if(no_read == 1){ + t_PLCsocket->set_state(Tango::FAULT); + t_PLCsocket->set_status("no new data available"); + DEBUG_STREAM << "plctimingthread::run() no new data available" << endl; + } + else{ + int c = calc_diff_tst(t_PLCsocket->old_timestamp, t_PLCsocket->new_timestamp); + if(c < 0){ + t_PLCsocket->set_state(Tango::FAULT); + t_PLCsocket->set_status("negative difference between timestamps"); + DEBUG_STREAM << "plctimingthread::run() negative difference between timestamps" << endl; + } + else{ + if(c > pausesec2*1000+pausenano2/1000000){ + t_PLCsocket->set_state(Tango::FAULT); + t_PLCsocket->set_status("data too old"); + DEBUG_STREAM << "plctimingthread::run() data too old" << endl; + } + else{ + t_PLCsocket->set_state(Tango::ON); + t_PLCsocket->set_status("timestamp ok"); + DEBUG_STREAM << "plctimingthread::run() timestamp ok" << endl; + } + } + } + } +} + + + + + + +/* + * generates a bcd timestamp for the current time + */ +string plctimingthread::calc_timest() +{ + + timeval seco; + string tstamp; + string out; + int rest; + char c; + char buf[10]; + memset (buf,0,sizeof(buf)); + gettimeofday(&seco,NULL); + time_t tim=time(NULL); + tm *now=localtime(&tim); + out.resize(TSTAMP_SIZE); + sprintf(buf, "%02d", (now->tm_year-100));//change here the format of saved data + tstamp.append(buf); + out[1] = (buf[0]-'0'<<4)+buf[1]-'0'; + + memset (buf,0,sizeof(buf)); + sprintf(buf, "%02d", (now->tm_mon+1));//change here the format of saved data + tstamp.append(buf); + out[0] = (buf[0]-'0'<<4)+buf[1]-'0'; + + memset (buf,0,sizeof(buf)); + sprintf(buf, "%02d", (now->tm_mday));//change here the format of saved data + tstamp.append(buf); + out[3] = (buf[0]-'0'<<4)+buf[1]-'0'; + + memset (buf,0,sizeof(buf)); + sprintf(buf, "%02d", (now->tm_hour));//change here the format of saved data + tstamp.append(buf); + out[2] = (buf[0]-'0'<<4)+buf[1]-'0'; + + memset (buf,0,sizeof(buf)); + sprintf(buf, "%02d", (now->tm_min));//change here the format of saved data + tstamp.append(buf); + out[5] = (buf[0]-'0'<<4)+buf[1]-'0'; + + memset (buf,0,sizeof(buf)); + sprintf(buf, "%02d", (now->tm_sec));//change here the format of saved data + tstamp.append(buf); + out[4] = (buf[0]-'0'<<4)+buf[1]-'0'; + + memset (buf,0,sizeof(buf)); + sprintf(buf, "%03d", ((int)(seco.tv_usec/1000)));//change here the format of saved data + tstamp.append(buf); + out[7] = ((buf[0]-'0'<<4)+buf[1]-'0')&0x00ffff; + rest = buf[2]-'0'; + + memset (buf,0,sizeof(buf)); + sprintf(buf, "%01d", (now->tm_wday+1));//change here the format of saved data + tstamp.append(buf); + out[6] = ((rest<<4)+buf[0]-'0')&0x00ffff; + + memset (buf,0,sizeof(buf)); + tstamp.append("\n"); + out.resize(TSTAMP_SIZE); + +return out; + +} /* end calc_timest() */ + + + +/* + * plctimingthread::calc_diff_tst() + * calculates difference between packet time and now(in seconds) + * controllare t_old e t_new + */ +int plctimingthread::calc_diff_tst(PLCsocket_ns::tstamp_t t_old, PLCsocket_ns::tstamp_t t_new) +{ + char buffer [10]; + int d = 0; + tm t1, t2; + time_t to; + time_t tn; + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_old[4]); + t1.tm_sec = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_old[5]); + t1.tm_min = atoi(buffer);// the hour isn't exact, cut the -1 + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_old[2]); + t1.tm_hour = atoi(buffer);// the hour isn't exact, cut the -1 + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_old[3]); + t1.tm_mday = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_old[0]); + t1.tm_mon = atoi(buffer)-1; + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_old[1]); + t1.tm_year = atoi(buffer)+100; + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_old[6]); + t1.tm_wday = atoi(buffer)-1; + + to = mktime(&t1); + + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[4]); + t2.tm_sec = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[5]); + t2.tm_min = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[2]); + t2.tm_hour = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[3]); + t2.tm_mday = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[0]); + t2.tm_mon = atoi(buffer)-1; + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[1]); + t2.tm_year = atoi(buffer)+100; + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[6]); + t2.tm_wday = atoi(buffer)-1; + + tn = mktime(&t2); + + d = (tn-to)*1000; + int ms_old, ms_new, c1, c2; + ms_old = ms_new = 0; + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_old[7]); + c1 = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_old[6]); + c2 = atoi(buffer); + ms_old = c1*10+((c2)>>4); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[7]); + c1 = atoi(buffer); + memset (buffer,0,sizeof(buffer)); + sprintf (buffer, "%x", t_new[6]); + c2 = atoi(buffer); + ms_new = c1*10+(c2>>4); + d += (ms_new-ms_old); + + return d; + +} /* end calc_diff_tst() */ + + diff --git a/src/plctimingthread.h b/src/plctimingthread.h new file mode 100644 index 0000000000000000000000000000000000000000..a816429e522eba6529ac064fc4ec7ab8cac43fd5 --- /dev/null +++ b/src/plctimingthread.h @@ -0,0 +1,55 @@ +/* + * plctimingthread.h + * + * 17.01.07 - SF: heartbeat + */ + +#ifndef plctimingthread_H +#define plctimingthread_H + +#include <omnithread.h> +#include <tango.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/time.h> +#include <signal.h> +#include <netdb.h> +#include "PLCsocket.h" + +class plctimingthread : public omni_thread, public Tango::LogAdapter +{ + private: + PLCsocket_ns::PLCsocket::PLCsocket *t_PLCsocket; + + public: + + plctimingthread(PLCsocket_ns::PLCsocket::PLCsocket *s):Tango::LogAdapter(s){ t_PLCsocket = s;}; + + ~plctimingthread() {}; + + void *StartUndetached(){ + start_undetached(); + } + void *run_undetached(void *); + + protected: + + struct sembuf operations[1]; + struct sembuf lock_ops[1]; + struct sembuf unlock_ops[1]; + int retval; + int id; + + struct timeval _pre2, _post2; + string calc_timest(); + int calc_diff_tst(PLCsocket_ns::tstamp_t, PLCsocket_ns::tstamp_t); + +}; /* end class plctimingthread() */ + + + +#endif + +/* EOF */