diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0d4c71819862b7cc2ae7bfe9f0d3cb4cc01cb606 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.nse_depinfo +bin +obj + +# Eclipse +.cproject +.project +.settings diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..1d3100ed2dc3573a45beab27d4445722155faca1 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +NAME_SRV = lfc-srv + +CXXFLAGS = +LDFLAGS = -lmenlo + +include ../makefiles/Make-9.3.4.in diff --git a/src/ClassFactory.cpp b/src/ClassFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..159da27580e1614264ebadbbcd2cdf8e6e0d76cc --- /dev/null +++ b/src/ClassFactory.cpp @@ -0,0 +1,38 @@ +static const char *RcsId = ""; +//+============================================================================= +// +// file : ClassFactory.cpp +// +// description : C++ source for the class_factory method of the DServer +// device class. This method is responsible for the creation of +// all class singleton for a device server. It is called +// at device server startup +// +// project : TANGO Device Server +// +// Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34149 Basovizza, Trieste ITALY +// +//-============================================================================= +// +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +// +// (c) - Software Engineering Group - ESRF +//============================================================================= + + +#include <tango.h> +#include <MenloLFCClass.h> + +/** + * Create MenloLFCClass singleton and store it in DServer object. + */ + +void Tango::DServer::class_factory() +{ + + add_class(MenloLFC_ns::MenloLFCClass::init("MenloLFC")); + +} diff --git a/src/MenloLFC.cpp b/src/MenloLFC.cpp new file mode 100644 index 0000000000000000000000000000000000000000..723968ae155827118104c9cb1881acc13fec3269 --- /dev/null +++ b/src/MenloLFC.cpp @@ -0,0 +1,3163 @@ +static const char *RcsId = ""; +//+============================================================================= +// +// file : MenloLFC.cpp +// +// description : C++ source for the MenloLFC 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 +// MenloLFC are implemented in this file. +// +// project : TANGO Device Server +// +// Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34149 Basovizza, Trieste ITALY +// +//-============================================================================= +// +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +// +// (c) - Software Engineering Group - ESRF +//============================================================================= + + + +//=================================================================== +// +// The following table gives the correspondence +// between commands and method name. +// +// Command name | Method name +// ---------------------------------------- +// State | dev_state() +// Status | dev_status() +// DeviceAddress | device_address() +// DeviceID | device_id() +// DeviceHWver | device_hwver() +// DeviceFWver | device_fwver() +// DeviceSerial | device_serial() +// +//=================================================================== + + +#include <tango.h> +#include <MenloLFC.h> +#include <MenloLFCClass.h> +//#include <Serial.h> //for SL_RAW, SL_NCHAR, SL_LINE, SL_RETRY +#define SL_RAW 0 /* raw read/write mode */ +#define SL_NCHAR 1 /* character read/write mode */ +#define SL_LINE 2 /* line read mode */ +#define SL_RETRY 3 /* retry read mode */ +#include <errno.h> +#include <math.h> //for ceil +#include <iomanip> //used for debug dump of db + +#include "readthread.h" + +namespace MenloLFC_ns +{ + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::MenloLFC(string &s) +// +// description : constructor for simulated MenloLFC +// +// in : - cl : Pointer to the DeviceClass object +// - s : Device name +// +//----------------------------------------------------------------------------- +MenloLFC::MenloLFC(Tango::DeviceClass *cl,string &s) +:TANGO_BASE_CLASS(cl,s.c_str()) +{ + init_device(); +} + +MenloLFC::MenloLFC(Tango::DeviceClass *cl,const char *s) +:TANGO_BASE_CLASS(cl,s) +{ + init_device(); +} + +MenloLFC::MenloLFC(Tango::DeviceClass *cl,const char *s,const char *d) +:TANGO_BASE_CLASS(cl,s,d) +{ + init_device(); +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::delete_device() +// +// description : will be called at device destruction or at init command. +// +//----------------------------------------------------------------------------- +void MenloLFC::delete_device() +{ + // Delete device allocated objects + abortflag = true; + sleep(1); + delete mutex; + if(moxa) + delete devserial; + + delete menlo; + delete attr_ISET_read; + delete attr_IACT_read; + delete attr_PACT_read; + delete attr_DIODE_TSET_read; + delete attr_DIODE_TACT_read; + delete attr_MODULE_TACT_read; + delete attr_TCORR_read; + delete [] attr_TC0_ADJ_ISET_read; + delete [] attr_TC0_ADJ_TSET_read; + delete [] attr_TC0_ADJ_IACT_read; + delete [] attr_TM0_ADJ_TACT_read; + delete [] attr_TM0_ADJ_PACT_read; + delete attr_Amplifier_State_read; + delete [] attr_Snapshot_read; + + delete [] attr_Date_read; + delete [] attr_Time_read; + delete attr_RTstamp_read; + delete attr_Tstamp_read; + delete attr_TstampDiff_read; + delete attr_TstampStart_read; + delete attr_Uptime_read; + + delete [] attr_ADJ_PACT_1_read; + delete attr_PACT_1_read; + delete attr_PMIN_1_read; + delete attr_PMAX_1_read; + delete attr_Remote__ServiceMode_read; +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::init_device() +// +// description : will be called at device initialization. +// +//----------------------------------------------------------------------------- +void MenloLFC::init_device() +{ + INFO_STREAM << "MenloLFC::MenloLFC() create device " << device_name << endl; + + // Initialise variables to default values + //-------------------------------------------- + abortflag = false; + th_sleep = 1000; + moxa = false; + counter = 0; + + set_change_event("state", true, false); //attribute name, implemented, detect, if not setting detect=false have to set abs_change or rel_change for each attribute + get_device_property(); + dev_add_loc = dev_add + 1; //define local address as device address + 1 + int found = serialdevice.find(":"); + if(found != string::npos) + { + //vector<unsigned int> parsed_ip_cpu; + //int i=0; + //unsigned char uc_cpu_ip[4]; + string ip_str(serialdevice.substr(0,found)); +/* string_explode(ip_str, ".", &parsed_ip_cpu); + if(parsed_ip_cpu.size() == 4) + { + for(vector<unsigned int>::iterator it=parsed_ip_cpu.begin(); it != parsed_ip_cpu.end(); it++) + uc_cpu_ip[i++] = (unsigned char)*it; + }*/ + strcpy(servIP, ip_str.c_str()); + string port_str(serialdevice.substr(found+1)); + std::istringstream tmp(port_str); + tmp >> servPort; + moxa = true; + if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) + { + /*set_state(Tango::FAULT); + set_status("socket() failed"); + conn_error = true;*/ + ERROR_STREAM << "MenloLFC::MenloLFC(): socket error"; + exit(1); + } + memset(&servAddr, 0, sizeof(servAddr)); /* Zero out structure {} */ + servAddr.sin_family = AF_INET; /* Internet address family */ + servAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */ + servAddr.sin_port = htons(servPort); /* Server port */ + /* Establish the connection to the echo server */ + if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) + { + stringstream tmp; + tmp << "Connection failed to " << servIP << ":" << servPort << ends; + set_state(Tango::FAULT); + set_status(tmp.str()); + conn_error = true; + INFO_STREAM << "MenloLFC::MenloLFC(): " << tmp.str(); + } + else + { + stringstream tmp; + tmp << "Connected to " << servIP << ":" << servPort << ends; + DEBUG_STREAM << "MenloLFC::MenloLFC(): " << tmp.str(); + conn_error = false; + } + + + } + else + { + moxa = false; + Tango::Database *db = new Tango::Database(); + Tango::DbData db_data; + try { + db_data.push_back(Tango::DbDatum("timeout")); + string in_prop("timeout"); + // devserial->get_property(in_prop, db_data); + db->get_device_property(serialdevice,db_data); + db_data[0] >> serial_timeout; + delete db; + } + catch(Tango::DevFailed e) { + string temp; + temp = e.errors[0].desc; + WARN_STREAM << "MenloLFC::MenloLFC() error getting timeout property from serial device: " << temp << endl; + delete db; + } + if(serial_timeout < 0 || serial_timeout > 2000) + serial_timeout = 500; + /* connect to serialdevice */ + devserial = new Tango::DeviceProxy(serialdevice); + + /* check if serialdevice is responding */ + try { + if (devserial->ping()) + { + devserial->set_timeout_millis(serial_timeout); + //set_state(Tango::ON); + set_status("Connected to serialdevice " + serialdevice); + INFO_STREAM << "Connected to serialdevice " + serialdevice << endl; + } + } + catch(Tango::DevFailed e) { + set_state(Tango::FAULT); + Tango::DevState st = Tango::FAULT; + push_change_event("state", &st); + set_status("Failed to connect to serialdevice " + serialdevice); + INFO_STREAM << "Failed to connect to serialdevice " + serialdevice << endl; + conn_error = true; + } + + Tango::DeviceData Din; + Tango::DevLong flush = 2; //flush input and output + Din << flush; + try { + devserial->command_inout("DevSerFlush",Din); + } + catch(Tango::DevFailed e) { + string temp; + temp = e.errors[0].desc; + WARN_STREAM << "MenloLFC::MenloLFC() error flushing serial device: " << temp << endl; + } + } + + attr_ISET_read = new Tango::DevLong(); + attr_IACT_read = new Tango::DevLong(); + attr_PACT_read = new Tango::DevLong(); + attr_DIODE_TSET_read = new Tango::DevLong(); + attr_DIODE_TACT_read = new Tango::DevLong(); + attr_MODULE_TACT_read = new Tango::DevLong(); + attr_TCORR_read = new Tango::DevLong(); + attr_TC0_ADJ_ISET_read = new Tango::DevLong[6]; + attr_TC0_ADJ_TSET_read = new Tango::DevLong[6]; + attr_TC0_ADJ_IACT_read = new Tango::DevLong[4]; + attr_TM0_ADJ_TACT_read = new Tango::DevLong[4]; + attr_TM0_ADJ_PACT_read = new Tango::DevLong[4]; + attr_Amplifier_State_read = new Tango::DevBoolean(); + attr_Snapshot_read = new Tango::DevLong[256*256]; + + attr_Date_read = new Tango::DevLong[3]; + attr_Time_read = new Tango::DevLong[3]; + attr_RTstamp_read = new Tango::DevDouble(); + attr_Tstamp_read = new Tango::DevDouble(); + attr_TstampDiff_read = new Tango::DevDouble(); + attr_TstampStart_read = new Tango::DevDouble(); + attr_Uptime_read = new Tango::DevDouble(); + + attr_ADJ_PACT_1_read = new Tango::DevLong[4]; + attr_PACT_1_read = new Tango::DevDouble(); + attr_PMIN_1_read = new Tango::DevDouble(); + attr_PMAX_1_read = new Tango::DevDouble(); + attr_Remote__ServiceMode_read = new Tango::DevLong(); + attr_EnableAutoSave_read = &attr_EnableAutoSave_write; + + menlo = new Menlo(dev_add, dev_add_loc, true); + mutex = new omni_mutex(); + vector<string> names; + string reg_s; + data_t rdata; + rdata.max_subdev = 1; + names.push_back(S_DEV); + names.push_back(S_ADDR); + menlo->NamesCat(reg_s, names); + DEBUG_STREAM << "MenloLFC::MenloLFC: prepared name " << reg_s << endl; + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() == 0)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device Address, err=" << rdata.msg << endl; + set_status("error reading Device Address, err=" + rdata.msg); + } + else + { + dev_add = rdata.data[0].front().u8; //update device address with the one read from the device + dev_add_loc = dev_add + 1; //define local address as device address + 1 + } + rdata.data[0].clear(); + abort_sleep(wr_sleep/2000); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_ID); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() == 0)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device ID, err=" << rdata.msg << endl; + set_status("error reading Device ID, err=" + rdata.msg); + strcpy(dev_id, ""); + } + else + { + strcpy(dev_id, rdata.data[0].front().cstring); + } + + rdata.data[0].clear(); + abort_sleep(wr_sleep/2000); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_VER_HW); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 4)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device HW Version, err=" << rdata.msg << endl; + set_status("error reading Device HW Version, err=" + rdata.msg); + strcpy(dev_hw_ver, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int major,minor,patchlevel,build; + deque<data_union>::iterator it = rdata.data[0].begin(); + build = it->u8; + it++; + patchlevel = it->u8; + it++; + minor = it->u8; + it++; + major = it->u8; + sprintf(dev_hw_ver,"%d,%d,%d,%d", major,minor,patchlevel,build); + } + rdata.data[0].clear(); + abort_sleep(wr_sleep/2000); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_VER_FW); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 4)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device FW Version, err=" << rdata.msg << endl; + set_status("error reading Device FW Version, err=" + rdata.msg); + strcpy(dev_fw_ver, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int major,minor,patchlevel,build; + deque<data_union>::iterator it = rdata.data[0].begin(); + build = it->u8; + it++; + patchlevel = it->u8; + it++; + minor = it->u8; + it++; + major = it->u8; + sprintf(dev_fw_ver,"%d,%d,%d,%d", major,minor,patchlevel,build); + } + rdata.data[0].clear(); + abort_sleep(wr_sleep/2000); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_VER_DISPFW); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 4)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device FW Version, err=" << rdata.msg << endl; + set_status("error reading Device FW Version, err=" + rdata.msg); + strcpy(display_fw_ver, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int major,minor,patchlevel,build; + deque<data_union>::iterator it = rdata.data[0].begin(); + build = it->u8; + it++; + patchlevel = it->u8; + it++; + minor = it->u8; + it++; + major = it->u8; + sprintf(display_fw_ver,"%d,%d,%d,%d", major,minor,patchlevel,build); + } + rdata.data[0].clear(); + abort_sleep(wr_sleep/2000); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_SER); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 3)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device Serial, err=" << rdata.msg << endl; + set_status("error reading Device Serial, err=" + rdata.msg); + strcpy(dev_serial, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int year,month,serial; + deque<data_union>::iterator it = rdata.data[0].begin(); + year = it->u8; + it++; + month = it->u8; + it++; + serial = it->u16; + sprintf(dev_serial,"%d,%d,%d", year,month,serial); + } + + int timeout = (int)(((7) * (serial_timeout+th_sleep+wr_sleep))+5000); + + struct timeval curr_time; + gettimeofday(&curr_time,NULL); + //data_union u8((unsigned char)0); + deque<data_union> dv; + data_t c_t1 = {1,1,{dv},Hi_pri,"",(byte)(-1),curr_time,timeout}; + data_t c_t2 = {1,1,{dv},Low_pri,"",(byte)(-1),curr_time,timeout}; + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_ISET); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t1)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_IACT); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t1)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_PACT); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t1)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_DIODE_TSET); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t1)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_DIODE_TACT); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t1)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_MODULE_TACT); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t1)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_TCORR); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t1)); + names.clear(); + names.push_back(S_DET4); + names.push_back(S_PACT_1); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t1)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_TC0_ADJ_ISET); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_TC0_ADJ_TSET); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_TC0_ADJ_IACT); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_TM0_ADJ_TACT); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + names.clear(); + names.push_back(S_MDD0); + names.push_back(S_TM0_ADJ_PACT); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + names.clear(); + names.push_back(S_DET4); + names.push_back(S_ADJ_PACT_1); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + names.clear(); + names.push_back(S_DET4); + names.push_back(S_PMIN_1); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + names.clear(); + names.push_back(S_DET4); + names.push_back(S_PMAX_1); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + + names.clear(); + names.push_back(S_REMOTE); + names.push_back(S_STATE_AMP1); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t1)); + +/* names.clear(); + names.push_back(S_DEV_FILE); + names.push_back(S_EDIPBMP); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2));*/ + + names.clear(); + names.push_back(S_DEV); + names.push_back(S_TIME); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + + names.clear(); + names.push_back(S_DEV); + names.push_back(S_DATE); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + + names.clear(); + names.push_back(S_DEV); + names.push_back(S_RTSTAMP); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + + names.clear(); + names.push_back(S_DEV); + names.push_back(S_TSTAMP); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + + names.clear(); + names.push_back(S_DEV); + names.push_back(S_TSTAMPDIFF); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + + names.clear(); + names.push_back(S_DEV); + names.push_back(S_TSTAMPSTART); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + + names.clear(); + names.push_back(S_DEV); + names.push_back(S_UPTIME); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + + names.clear(); + names.push_back(S_REMOTE); + names.push_back(S_SERVICE); + menlo->NamesCat(reg_s, names); + read_data.insert(make_pair(reg_s,c_t2)); + + int numHi=0, numLow=0; + for(data_map::iterator it2 = read_data.begin(); it2 != read_data.end(); it2++) + { + if(it2->second.pri == Hi_pri) + numHi++; + else if(it2->second.pri == Low_pri) + numLow++; + } + int completeLoop = numHi*PRIORITY_FACTOR + numLow; + //int hiPrioLoop = (int) ceil((double)(completeLoop / PRIORITY_FACTOR)); + int loPrioLoop = completeLoop + 1; + int loLoopPeriod; + if(numLow > 0) + loLoopPeriod = (long) (((double)completeLoop) / numLow); + if(loLoopPeriod==1) //TODO: if so few high priority reads invert computation (hiLoopPeriod) + loLoopPeriod++; + int hiPrioLoop = (int)ceil((numHi + ((double)(numHi))/(loLoopPeriod-1) + 1)); + timeoutHiPrio = (int)(3*((hiPrioLoop+2) * (serial_timeout+th_sleep+wr_sleep))+5000); + timeoutLowPrio = (int)(3*3*((loPrioLoop+2) * (serial_timeout+th_sleep+wr_sleep))+5000); // 3* because of force_scheduler + DEBUG_STREAM << "MenloLFC::MenloLFC(): hiPrioLoop=" << hiPrioLoop << " loPrioLoop=" << loPrioLoop << " timeoutHiPrio=" << timeoutHiPrio << " timeoutLowPrio=" << timeoutLowPrio << endl; + //update timeout + for(data_map::iterator it3 = read_data.begin(); it3 != read_data.end(); it3++) + { + if(it3->second.pri == Hi_pri) + it3->second.timeout = timeoutHiPrio; + else if(it3->second.pri == Low_pri) + it3->second.timeout = timeoutLowPrio; + } + + + readloop = new readthread(this); + readloop->start(); +} + + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::get_device_property() +// +// description : Read the device properties from database. +// +//----------------------------------------------------------------------------- +void MenloLFC::get_device_property() +{ + // Initialize your default values here (if not done with POGO). + //------------------------------------------------------------------ + + // Read device properties from database.(Automatic code generation) + //------------------------------------------------------------------ + Tango::DbData dev_prop; + dev_prop.push_back(Tango::DbDatum("Serialdevice")); + dev_prop.push_back(Tango::DbDatum("Serial_timeout")); + dev_prop.push_back(Tango::DbDatum("Th_sleep")); + dev_prop.push_back(Tango::DbDatum("Wr_sleep")); + dev_prop.push_back(Tango::DbDatum("Dev_add")); + + // Call database and extract values + //-------------------------------------------- + if (Tango::Util::instance()->_UseDb==true) + get_db_device()->get_property(dev_prop); + Tango::DbDatum def_prop, cl_prop; + MenloLFCClass *ds_class = + (static_cast<MenloLFCClass *>(get_device_class())); + int i = -1; + + // Try to initialize Serialdevice from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> serialdevice; + else { + // Try to initialize Serialdevice from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> serialdevice; + } + // And try to extract Serialdevice value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> serialdevice; + + // Try to initialize Serial_timeout from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> serial_timeout; + else { + // Try to initialize Serial_timeout from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> serial_timeout; + } + // And try to extract Serial_timeout value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> serial_timeout; + + // Try to initialize Th_sleep from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> th_sleep; + else { + // Try to initialize Th_sleep from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> th_sleep; + } + // And try to extract Th_sleep value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> th_sleep; + + // Try to initialize Wr_sleep from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> wr_sleep; + else { + // Try to initialize Wr_sleep from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> wr_sleep; + } + // And try to extract Wr_sleep value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> wr_sleep; + + // Try to initialize Dev_add from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> dev_add; + else { + // Try to initialize Dev_add from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> dev_add; + } + // And try to extract Dev_add value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> dev_add; + + + + // End of Automatic code generation + //------------------------------------------------------------------ + +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::always_executed_hook() +// +// description : method always executed before any command is executed +// +//----------------------------------------------------------------------------- +void MenloLFC::always_executed_hook() +{ + +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_attr_hardware +// +// description : Hardware acquisition for attributes. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_attr_hardware(vector<long> &attr_list) +{ + //DEBUG_STREAM << "MenloLFC::read_attr_hardware(vector<long> &attr_list) entering... "<< endl; + // Add your own code here + +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_IACT +// +// description : Extract real attribute values for IACT acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_IACT(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_IACT(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_IACT); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_IACT_read, /*factor*/1.0, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_PACT +// +// description : Extract real attribute values for PACT acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_PACT(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_PACT(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_PACT); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_PACT_read, /*factor*/1.0, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_DIODE_TSET +// +// description : Extract real attribute values for DIODE_TSET acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_DIODE_TSET(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_DIODE_TSET(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_DIODE_TSET); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_DIODE_TSET_read, /*factor*/1.0, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_DIODE_TSET +// +// description : Write DIODE_TSET attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_DIODE_TSET(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_DIODE_TSET(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_DIODE_TSET); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, &attr_DIODE_TSET_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_DIODE_TACT +// +// description : Extract real attribute values for DIODE_TACT acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_DIODE_TACT(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_DIODE_TACT(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_DIODE_TACT); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_DIODE_TACT_read, /*factor*/1.0, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_MODULE_TACT +// +// description : Extract real attribute values for MODULE_TACT acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_MODULE_TACT(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_MODULE_TACT(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_MODULE_TACT); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_MODULE_TACT_read, /*factor*/1.0, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_TCORR +// +// description : Extract real attribute values for TCORR acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_TCORR(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_TCORR(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TCORR); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_TCORR_read, /*factor*/1.0, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_TCORR +// +// description : Write TCORR attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_TCORR(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_TCORR(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TCORR); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, &attr_TCORR_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_ISET +// +// description : Extract real attribute values for ISET acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_ISET(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_ISET(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_ISET); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_ISET_read, /*factor*/1.0, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_ISET +// +// description : Write ISET attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_ISET(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_ISET(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_ISET); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, &attr_ISET_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_TC0_ADJ_ISET +// +// description : Extract real attribute values for TC0_ADJ_ISET acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_TC0_ADJ_ISET(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_TC0_ADJ_ISET(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TC0_ADJ_ISET); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_TC0_ADJ_ISET_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/6); + apply_attr_value_dacs(attr, reg_s, attr_TC0_ADJ_ISET_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_TC0_ADJ_ISET +// +// description : Write TC0_ADJ_ISET attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_TC0_ADJ_ISET(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_TC0_ADJ_ISET(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TC0_ADJ_ISET); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, attr_TC0_ADJ_ISET_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_TC0_ADJ_TSET +// +// description : Extract real attribute values for TC0_ADJ_TSET acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_TC0_ADJ_TSET(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_TC0_ADJ_TSET(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TC0_ADJ_TSET); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_TC0_ADJ_TSET_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/6); + apply_attr_value_dacs(attr, reg_s, attr_TC0_ADJ_TSET_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_TC0_ADJ_TSET +// +// description : Write TC0_ADJ_TSET attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_TC0_ADJ_TSET(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_TC0_ADJ_TSET(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TC0_ADJ_TSET); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, attr_TC0_ADJ_TSET_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_TC0_ADJ_IACT +// +// description : Extract real attribute values for TC0_ADJ_IACT acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_TC0_ADJ_IACT(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_TC0_ADJ_IACT(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TC0_ADJ_IACT); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_TC0_ADJ_IACT_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/4); + apply_attr_value_adcs(attr, reg_s, attr_TC0_ADJ_IACT_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_TC0_ADJ_IACT +// +// description : Write TC0_ADJ_IACT attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_TC0_ADJ_IACT(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_TC0_ADJ_IACT(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TC0_ADJ_IACT); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, attr_TC0_ADJ_IACT_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_TM0_ADJ_TACT +// +// description : Extract real attribute values for TM0_ADJ_TACT acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_TM0_ADJ_TACT(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_TM0_ADJ_TACT(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TM0_ADJ_TACT); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_TM0_ADJ_TACT_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/4); + apply_attr_value_adcs(attr, reg_s, attr_TM0_ADJ_TACT_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_TM0_ADJ_TACT +// +// description : Write TM0_ADJ_TACT attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_TM0_ADJ_TACT(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_TM0_ADJ_TACT(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TM0_ADJ_TACT); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, attr_TM0_ADJ_TACT_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_TM0_ADJ_PACT +// +// description : Extract real attribute values for TM0_ADJ_PACT acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_TM0_ADJ_PACT(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_TM0_ADJ_PACT(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TM0_ADJ_PACT); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_TM0_ADJ_PACT_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/4); + apply_attr_value_adcs(attr, reg_s, attr_TM0_ADJ_PACT_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_TM0_ADJ_PACT +// +// description : Write TM0_ADJ_PACT attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_TM0_ADJ_PACT(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_TM0_ADJ_PACT(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_MDD0); + names.push_back(S_TM0_ADJ_PACT); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, attr_TM0_ADJ_PACT_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_Amplifier_State +// +// description : Extract real attribute values for Amplifier_State acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_Amplifier_State(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_Amplifier_State(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_REMOTE); + names.push_back(S_STATE_AMP1); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevBoolean>(attr, reg_s, attr_Amplifier_State_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_Amplifier_State +// +// description : Write Amplifier_State attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_Amplifier_State(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_Amplifier_State(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_REMOTE); + names.push_back(S_STATE_AMP1); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevBoolean *>(attr, reg_s, &attr_Amplifier_State_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_Snapshot +// +// description : Extract real attribute values for Snapshot acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_Snapshot(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_Snapshot_State(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DEV_FILE); + names.push_back(S_EDIPBMP); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_Snapshot_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/256*256); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_Date +// +// description : Extract real attribute values for Date acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_Date(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_Date(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DEV); + names.push_back(S_DATE); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_Date_read, /*factor*/1.0, /*index*/-1, /*subdevice*/0, /*size*/3); + //apply_attr_value_datetime(attr, S_DATE, attr_Date_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_Date +// +// description : Write Date attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_Date(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_Date(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DEV); + names.push_back(S_DATE); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, attr_Date_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_Time +// +// description : Extract real attribute values for Time acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_Time(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_Time(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DEV); + names.push_back(S_TIME); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_Time_read, /*factor*/1.0, /*index*/-1, /*subdevice*/0, /*size*/3); + //apply_attr_value_datetime(attr, S_DATE, attr_Time_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_Time +// +// description : Write Time attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_Time(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_Time(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DEV); + names.push_back(S_TIME); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, attr_Time_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_RTstamp +// +// description : Extract real attribute values for Tstamp acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_RTstamp(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_RTstamp(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DEV); + names.push_back(S_RTSTAMP); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_RTstamp_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/6); + apply_attr_value_tstamp(attr, reg_s, attr_RTstamp_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_Tstamp +// +// description : Extract real attribute values for Tstamp acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_Tstamp(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_Tstamp(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DEV); + names.push_back(S_TSTAMP); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_Tstamp_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/6); + apply_attr_value_tstamp(attr, reg_s, attr_Tstamp_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_TstampDiff +// +// description : Extract real attribute values for TstampDiff acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_TstampDiff(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_TstampDiff(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DEV); + names.push_back(S_TSTAMPDIFF); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_TstampDiff_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/6); + apply_attr_value_tstamp(attr, reg_s, attr_TstampDiff_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_TstampStart +// +// description : Extract real attribute values for TstampStart acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_TstampStart(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_TstampStart(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DEV); + names.push_back(S_TSTAMPSTART); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_TstampStart_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/6); + apply_attr_value_tstamp(attr, reg_s, attr_TstampStart_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_Uptime +// +// description : Extract real attribute values for Uptime acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_Uptime(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_Uptime(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DEV); + names.push_back(S_UPTIME); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_Uptime_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/6); + apply_attr_value_tstamp(attr, reg_s, attr_Uptime_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_ADJ_PACT_1 +// +// description : Extract real attribute values for ADJ_PACT_1 acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_ADJ_PACT_1(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_ADJ_PACT_1(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DET4); + names.push_back(S_ADJ_PACT_1); + menlo->NamesCat(reg_s, names); + //apply_attr_value<long>(attr, reg_s, attr_ADJ_PACT_1_read, /*factor*/1, /*index*/0, /*subdevice*/0, /*size*/4); + apply_attr_value_adcs(attr, reg_s, attr_ADJ_PACT_1_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_ADJ_PACT_1 +// +// description : Write ADJ_PACT_1 attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_ADJ_PACT_1(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "MenloLFC::write_ADJ_PACT_1(Tango::WAttribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DET4); + names.push_back(S_ADJ_PACT_1); + menlo->NamesCat(reg_s, names); + write_attr_value<const Tango::DevLong *>(attr, reg_s, attr_ADJ_PACT_1_write,/*subdevice*/-1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_PACT_1 +// +// description : Extract real attribute values for PACT_1 acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_PACT_1(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_PACT_1(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DET4); + names.push_back(S_PACT_1); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevDouble>(attr, reg_s, attr_PACT_1_read, /*factor*/800.0/300.0, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_PMIN_1 +// +// description : Extract real attribute values for PMIN_1 acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_PMIN_1(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_PMIN_1(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DET4); + names.push_back(S_PMIN_1); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevDouble>(attr, reg_s, attr_PMIN_1_read, /*factor*/800.0/300.0, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_PMAX_1 +// +// description : Extract real attribute values for PMAX_1 acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_PMAX_1(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_PMAX_1(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + names.push_back(S_DET4); + names.push_back(S_PMAX_1); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevDouble>(attr, reg_s, attr_PMAX_1_read, /*factor*/800.0/300.0, /*index*/0, /*subdevice*/0, /*size*/1); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_Remote__ServiceMode +// +// description : Extract real attribute values for Remote__ServiceMode acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_Remote__ServiceMode(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_Remote__ServiceMode(Tango::Attribute &attr) entering... "<< endl; + vector<string> names; + string reg_s; + + names.push_back(S_REMOTE); + names.push_back(S_SERVICE); + menlo->NamesCat(reg_s, names); + apply_attr_value<Tango::DevLong>(attr, reg_s, attr_Remote__ServiceMode_read, /*factor*/1.0, /*index*/0, /*subdevice*/0, /*size*/1); + +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::read_EnableAutoSave +// +// description : Extract real attribute values for EnableAutoSave acquisition result. +// +//----------------------------------------------------------------------------- +void MenloLFC::read_EnableAutoSave(Tango::Attribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::read_EnableAutoSave(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_EnableAutoSave_read); +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::write_EnableAutoSave +// +// description : Write EnableAutoSave attribute values to hardware. +// +//----------------------------------------------------------------------------- +void MenloLFC::write_EnableAutoSave(Tango::WAttribute &attr) +{ + //DEBUG_STREAM << "MenloLFC::write_EnableAutoSave(Tango::WAttribute &attr) entering... "<< endl; + attr.get_write_value(attr_EnableAutoSave_write); +} + +//+------------------------------------------------------------------ +/** + * method: MenloLFC::device_address + * + * description: method to execute "DeviceAddress" + * Read Device Address + * + * @return Device Address + * + */ +//+------------------------------------------------------------------ +Tango::DevLong MenloLFC::device_address() +{ + Tango::DevLong argout ; + DEBUG_STREAM << "MenloLFC::device_address(): entering... !" << endl; + + // Add your own code to control device here + argout = dev_add; + return argout; +} + +//+------------------------------------------------------------------ +/** + * method: MenloLFC::device_id + * + * description: method to execute "DeviceID" + * Read Device ID + * + * @return Device ID + * + */ +//+------------------------------------------------------------------ +Tango::DevString MenloLFC::device_id() +{ + // POGO has generated a method core with argout allocation. + // If you would like to use a static reference without copying, + // See "TANGO Device Server Programmer's Manual" + // (chapter : Writing a TANGO DS / Exchanging data) + //------------------------------------------------------------ + Tango::DevString argout = new char[6]; + //strcpy(argout, "dummy"); + DEBUG_STREAM << "MenloLFC::device_id(): entering... !" << endl; + vector<string> names; + string reg_s; + data_t rdata; + rdata.max_subdev = 1; + rdata.data[0].clear(); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_ID); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() == 0)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device ID, err=" << rdata.msg << endl; + set_status("error reading Device ID, err=" + rdata.msg); + strcpy(dev_id, ""); + } + else + { + strcpy(dev_id, rdata.data[0].front().cstring); + } + + // Add your own code to control device here + argout = CORBA::string_dup(dev_id); + return argout; +} + +//+------------------------------------------------------------------ +/** + * method: MenloLFC::device_hwver + * + * description: method to execute "DeviceHWver" + * Read Device Hw Ver + * + * @return Device HW Ver + * + */ +//+------------------------------------------------------------------ +Tango::DevString MenloLFC::device_hwver() +{ + // POGO has generated a method core with argout allocation. + // If you would like to use a static reference without copying, + // See "TANGO Device Server Programmer's Manual" + // (chapter : Writing a TANGO DS / Exchanging data) + //------------------------------------------------------------ + Tango::DevString argout = new char[6]; + //strcpy(argout, "dummy"); + DEBUG_STREAM << "MenloLFC::device_hwver(): entering... !" << endl; + vector<string> names; + string reg_s; + data_t rdata; + rdata.max_subdev = 1; + rdata.data[0].clear(); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_VER_HW); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 4)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device HW Version, err=" << rdata.msg << endl; + set_status("error reading Device HW Version, err=" + rdata.msg); + strcpy(dev_hw_ver, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int major,minor,patchlevel,build; + deque<data_union>::iterator it = rdata.data[0].begin(); + build = it->u8; + it++; + patchlevel = it->u8; + it++; + minor = it->u8; + it++; + major = it->u8; + sprintf(dev_hw_ver,"%d,%d,%d,%d", major,minor,patchlevel,build); + } + // Add your own code to control device here + argout = CORBA::string_dup(dev_hw_ver); + return argout; +} + +//+------------------------------------------------------------------ +/** + * method: MenloLFC::device_fwver + * + * description: method to execute "DeviceFWver" + * Read Device Fw Ver + * + * @return Device FW Ver + * + */ +//+------------------------------------------------------------------ +Tango::DevString MenloLFC::device_fwver() +{ + // POGO has generated a method core with argout allocation. + // If you would like to use a static reference without copying, + // See "TANGO Device Server Programmer's Manual" + // (chapter : Writing a TANGO DS / Exchanging data) + //------------------------------------------------------------ + Tango::DevString argout = new char[6]; + //strcpy(argout, "dummy"); + DEBUG_STREAM << "MenloLFC::device_fwver(): entering... !" << endl; + vector<string> names; + string reg_s; + data_t rdata; + rdata.max_subdev = 1; + rdata.data[0].clear(); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_VER_FW); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 4)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device FW Version, err=" << rdata.msg << endl; + set_status("error reading Device FW Version, err=" + rdata.msg); + strcpy(dev_fw_ver, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int major,minor,patchlevel,build; + deque<data_union>::iterator it = rdata.data[0].begin(); + build = it->u8; + it++; + patchlevel = it->u8; + it++; + minor = it->u8; + it++; + major = it->u8; + sprintf(dev_fw_ver,"%d,%d,%d,%d", major,minor,patchlevel,build); + } + // Add your own code to control device here + argout = CORBA::string_dup(dev_fw_ver); + return argout; +} + +//+------------------------------------------------------------------ +/** + * method: MenloLFC::display_fwver + * + * description: method to execute "DisplayFWver" + * Read Device Fw Ver + * + * @return Device FW Ver + * + */ +//+------------------------------------------------------------------ +Tango::DevString MenloLFC::display_fwver() +{ + // POGO has generated a method core with argout allocation. + // If you would like to use a static reference without copying, + // See "TANGO Device Server Programmer's Manual" + // (chapter : Writing a TANGO DS / Exchanging data) + //------------------------------------------------------------ + Tango::DevString argout = new char[6]; + //strcpy(argout, "dummy"); + DEBUG_STREAM << "MenloLFC::display_fwver(): entering... !" << endl; + vector<string> names; + string reg_s; + data_t rdata; + rdata.max_subdev = 1; + rdata.data[0].clear(); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_VER_DISPFW); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 4)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device FW Version, err=" << rdata.msg << endl; + set_status("error reading Device FW Version, err=" + rdata.msg); + strcpy(display_fw_ver, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int major,minor,patchlevel,build; + deque<data_union>::iterator it = rdata.data[0].begin(); + build = it->u8; + it++; + patchlevel = it->u8; + it++; + minor = it->u8; + it++; + major = it->u8; + sprintf(display_fw_ver,"%d,%d,%d,%d", major,minor,patchlevel,build); + } + // Add your own code to control device here + argout = CORBA::string_dup(display_fw_ver); + return argout; +} + +//+------------------------------------------------------------------ +/** + * method: MenloLFC::device_serial + * + * description: method to execute "DeviceSerial" + * Read Device Serial + * + * @return Device Serial + * + */ +//+------------------------------------------------------------------ +Tango::DevString MenloLFC::device_serial() +{ + // POGO has generated a method core with argout allocation. + // If you would like to use a static reference without copying, + // See "TANGO Device Server Programmer's Manual" + // (chapter : Writing a TANGO DS / Exchanging data) + //------------------------------------------------------------ + Tango::DevString argout = new char[6]; + //strcpy(argout, "dummy"); + DEBUG_STREAM << "MenloLFC::device_serial(): entering... !" << endl; + vector<string> names; + string reg_s; + data_t rdata; + rdata.max_subdev = 1; + rdata.data[0].clear(); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_SER); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, reg_s, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 3)) + { + INFO_STREAM << "MenloLFC::MenloLFC: error reading Device Serial, err=" << rdata.msg << endl; + set_status("error reading Device Serial, err=" + rdata.msg); + strcpy(dev_serial, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int year,month,serial; + deque<data_union>::iterator it = rdata.data[0].begin(); + year = it->u8; + it++; + month = it->u8; + it++; + serial = it->u16; + sprintf(dev_serial,"%d,%d,%d", year,month,serial); + } + // Add your own code to control device here + argout = CORBA::string_dup(dev_serial); + return argout; +} + +//+------------------------------------------------------------------ +/** + * method: MenloLFC::reset_device + * + * description: method to execute "EnterServiceCode" + * Save configuration + * + * @return + * + */ +//+------------------------------------------------------------------ +void MenloLFC::enter_service_code(Tango::DevUShort argin) +{ + // POGO has generated a method core with argout allocation. + // If you would like to use a static reference without copying, + // See "TANGO Device Server Programmer's Manual" + // (chapter : Writing a TANGO DS / Exchanging data) + //------------------------------------------------------------ + DEBUG_STREAM << "MenloLFC::enter_service_code(): entering... !" << endl; + vector<string> names; + string reg_s; + data_t rdata; + int subdev=0; + rdata.max_subdev = 1; + rdata.data[0].clear(); + names.clear(); + names.push_back(S_REMOTE); + names.push_back(S_SERVICE); + menlo->NamesCat(reg_s, names); + rdata.data[subdev].push_back((uint16_t)argin); + DEBUG_STREAM << "MenloLFC::enter_service_code(): 4 !" << endl; + WriteRead(PROTO_CMD_WRITE, reg_s, -1, rdata); + DEBUG_STREAM << "MenloLFC::enter_service_code(): 5 !" << endl; + if(rdata.msg != "") + { + stringstream out_stream; + out_stream << "Error entering service code: " << rdata.msg; + Tango::Except::throw_exception( + (const char *) "SERVICE_CODE_ERROR", + out_stream.str(), + (const char *) "MenloLFC::enter_service_code()", Tango::ERR); + } +} + +//+------------------------------------------------------------------ +/** + * method: MenloLFC::save_config + * + * description: method to execute "SaveConfig" + * Save configuration + * + * @return + * + */ +//+------------------------------------------------------------------ +void MenloLFC::save_config() +{ + // POGO has generated a method core with argout allocation. + // If you would like to use a static reference without copying, + // See "TANGO Device Server Programmer's Manual" + // (chapter : Writing a TANGO DS / Exchanging data) + //------------------------------------------------------------ + DEBUG_STREAM << "MenloLFC::save_config(): entering... !" << endl; + vector<string> names; + string reg_s; + data_t rdata; + int subdev=0; + rdata.max_subdev = 1; + rdata.data[0].clear(); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_SAVSET); + menlo->NamesCat(reg_s, names); + rdata.data[subdev].push_back((unsigned char)1); + WriteRead(PROTO_CMD_WRITE, reg_s, -1, rdata); + if(rdata.msg != "") + { + stringstream out_stream; + out_stream << "Error saving settings: " << rdata.msg; + Tango::Except::throw_exception( + (const char *) "SAVE_ERROR", + out_stream.str(), + (const char *) "MenloLFC::save_config()", Tango::ERR); + } +} + + +int MenloLFC::WriteRead(int cmd, string s_reg, int subdevice, data_t &rdata) +{ + mutex->lock(); +// DEBUG_STREAM << "MenloLFC::WriteRead(): entering... !" << endl; + char outbuf[256], + inbuf[256]; + stringstream temp; + //data_map::iterator it; + //string cmd = it->first; + bool ok = false; + int nretries = 0; + long read_len=0; + long write_len; + + /*it = read_data.find(cmd); + if(it == read_data.end()) + { + ERROR_STREAM << "MenloLFC::WriteRead() command not found: " << cmd << endl; + return -1; + }*/ + + //sprintf(outbuf,"%s%s%s",cmd.c_str(),arg.c_str(),"\xa"); + + + + + if(conn_error) + { +#if 0 + data_t tmp; + tmp.data[0].push_back((int)counter); + write_len = menlo->PrepareMsg(PROTO_CMD_ECHO, "", /*subdevice*/-1, tmp, outbuf); + if(write_len < 0) + { + counter++; + mutex->unlock(); + return -1; + } + dump_msg("MenloLFC::WriteRead write echo:", write_len, outbuf); + try { + if(!moxa) + write_serial(outbuf,write_len); + else + write_socket(outbuf,write_len); + abort_sleep(wr_sleep/1000); //abort_sleep(sec) + //read_serial(inbuf); + } + catch(Tango::DevFailed &e) { + TangoSys_MemStream out_stream; + out_stream << "Error writing cmd = " << PROTO_CMD_ECHO << ", err = " << e.errors[0].desc << ends; + WARN_STREAM << "MenloLFC::WriteRead(): " << out_stream.str() << endl; + rdata.msg = out_stream.str(); + counter++; + mutex->unlock(); + return -1; + } + tmp.data[0].clear(); + memset(inbuf,0,256); + try { + if(!moxa) + read_serial(inbuf,read_len); + else + read_socket(inbuf,read_len); + } + catch(Tango::DevFailed &e) { + if(get_state() != Tango::FAULT) + { + Tango::DevState st = Tango::FAULT; + set_state(st); + push_change_event("state", &st); + } + set_status("Errors from device" + serialdevice); + TangoSys_MemStream out_stream; + out_stream << "Error reading cmd = " << PROTO_CMD_ECHO << ", err = " << e.errors[0].desc << ends; + WARN_STREAM << "MenloLFC::WriteRead(): " << out_stream.str() << endl; + tmp.msg = out_stream.str(); + counter++; + mutex->unlock(); + return -1; + } + dump_msg("MenloLFC::WriteRead read echo:", read_len, inbuf); + menlo->ParseResponse(inbuf,read_len, tmp, 0); + if(tmp.data[0].size() == 0) + { + INFO_STREAM << "MenloLFC::WriteRead: error parsing echo response, size==0" << endl; + counter++; + if(get_state() != Tango::FAULT) + { + Tango::DevState st = Tango::FAULT; + set_state(st); + push_change_event("state", &st); + } + set_status("Errors from device" + serialdevice); + mutex->unlock(); + return -1; + } + else + { + if(tmp.data[0][0].s32 == counter++) //subdevice=0, index=0 + { + if(get_state() != Tango::RUNNING) + { + Tango::DevState st = Tango::RUNNING; + set_state(st); + push_change_event("state", &st); + } + set_status("Reconnected to device" + serialdevice); + conn_error = false; + reconnect(); + } + else + { + if(get_state() != Tango::FAULT) + { + Tango::DevState st = Tango::FAULT; + set_state(st); + push_change_event("state", &st); + } + set_status("Errors from serialdevice" + serialdevice); + mutex->unlock(); + return -1; + } + } +#else + +#endif + } + + + + write_len = menlo->PrepareMsg(cmd, s_reg, subdevice, rdata, outbuf); + if(write_len < 0) + { + mutex->unlock(); + return -1; + } + //DEBUG_STREAM << "MenloLFC::WriteRead now1 reg_type=" << hex << (int)rdata.reg_type << dec; + dump_msg("MenloLFC::WriteRead write cmd:", write_len, outbuf); + try { + if(!moxa) + write_serial(outbuf,write_len); + else + write_socket(outbuf,write_len); + abort_sleep(wr_sleep/1000); //abort_sleep(sec) + //read_serial(inbuf); + } + catch(Tango::DevFailed &e) { + TangoSys_MemStream out_stream; + out_stream << "Error writing cmd = " << cmd << ", err = " << e.errors[0].desc << ends; + WARN_STREAM << "MenloLFC::WriteRead(): " << out_stream.str() << endl; + rdata.msg = out_stream.str(); + mutex->unlock(); + return -1; + } + DEBUG_STREAM << "MenloLFC::WriteRead now reg_type=" << hex << (int)rdata.reg_type << dec; + memset(inbuf,0,256); + try { + if(!moxa) + read_serial(inbuf,read_len); + else + read_socket(inbuf,read_len); + dump_msg("MenloLFC::WriteRead read resp:", read_len, inbuf); + menlo->ParseResponse(inbuf,read_len, rdata, subdevice); + } + catch(Tango::DevFailed &e) { + TangoSys_MemStream out_stream; + out_stream << "Error reading cmd = " << cmd << ", err = " << e.errors[0].desc << ends; + WARN_STREAM << "MenloLFC::WriteRead(): " << out_stream.str() << endl; + rdata.msg = out_stream.str(); + read_len = 0; + } + + mutex->unlock(); + return 0; +} + + + +//+------------------------------------------------------------------ +// +// method: MenloLFC::write_serial +// +// description: method to execute "write_serial" +// Write a string to serial interface +// +//------------------------------------------------------------------- +void MenloLFC::write_serial(char *write_str, long size) +//void Chiller::write_serial(string write_str) +{ + //DEBUG_STREAM << "MenloLFC::write_serial(): entering... =" << write_str << endl; + // Add your own code to control device here + Tango::DeviceData Din,Din2; + int i; + Tango::DevLong flush = 2; + Tango::DevVarCharArray *input = new Tango::DevVarCharArray(); + input->length(size); +// input->length(write_str.length()); + stringstream temp; + +// for (int i=0; i < write_str.length(); i++) + for (int i=0; i < size; i++) + { + //(*input)[i] = (unsigned char) write_str.at(i); + (*input)[i] = write_str[i]; + temp << showbase << hex << (int)(*input)[i] << " "; + } + //DEBUG_STREAM << "MenloLFC::write_serial(): writing=" << write_str << "=" << temp.str() << endl; + DEBUG_STREAM << "MenloLFC::write_serial(): writing=" << temp.str() << endl; + + try { + Din << input; + devserial->command_inout("DevSerWriteChar",Din); +/* Din2 << flush; + devserial->command_inout("DevSerFlush",Din2);*/ + } + catch(Tango::DevFailed e) { + TangoSys_MemStream out_stream; + conn_error = true; + out_stream << "Write command to SerialDeviceServer failed" << ends; + if(get_state() != Tango::FAULT) + { + set_state(Tango::FAULT); + Tango::DevState st = Tango::FAULT; + push_change_event("state", &st); + } + set_status("Errors from serialdevice " + serialdevice); + Tango::Except::re_throw_exception(e, + (const char *) "Error writing serial", + out_stream.str(), + (const char *) "MenloLFC::write_serial()", Tango::ERR); + } +// set_state(Tango::ON); +// set_status("Connected to serialdevice " + serialdevice); +} + +//+------------------------------------------------------------------ +// +// method: MenloLFC::write_socket +// +// description: method to execute "write_serial" +// Write a string to serial interface +// +//------------------------------------------------------------------- +void MenloLFC::write_socket(char *write_str, long size) +{ + int ret; + if(conn_error) + { + close (sock); + if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) + { + /*set_state(Tango::FAULT); + set_status("socket() failed"); + conn_error = true;*/ + ERROR_STREAM << "MenloLFC::write_socket(): socket error"; + stringstream tmp; + tmp << "Creation of socket failed" << ends; + set_state(Tango::FAULT); + set_status(tmp.str()); + conn_error = true; + INFO_STREAM << "MenloLFC::write_socket(): " << tmp.str(); + Tango::Except::throw_exception( + (const char *) "Error writing socket", + tmp.str(), + (const char *) "MenloLFC::write_socket()", Tango::ERR); + } + memset(&servAddr, 0, sizeof(servAddr)); /* Zero out structure {} */ + servAddr.sin_family = AF_INET; /* Internet address family */ + servAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */ + servAddr.sin_port = htons(servPort); /* Server port */ + if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) + { + stringstream tmp; + tmp << "Connection failed to " << servIP << ":" << servPort << ends; + set_state(Tango::FAULT); + set_status(tmp.str()); + conn_error = true; + INFO_STREAM << "MenloLFC::write_socket(): " << tmp.str(); + Tango::Except::throw_exception( + (const char *) "Error writing socket", + tmp.str(), + (const char *) "MenloLFC::write_socket()", Tango::ERR); + //return; + } + } + ret = send(sock, write_str, size, 0); + if(ret == -1) + { + stringstream tmp; + tmp << "Write failed to " << servIP << ":" << servPort << " errno=" << errno << "->" << strerror(errno)<< ends; + set_state(Tango::FAULT); + set_status(tmp.str()); + conn_error = true; + INFO_STREAM << "MenloLFC::write_socket(): " << tmp.str(); + Tango::Except::throw_exception( + (const char *) "Error writing socket", + tmp.str(), + (const char *) "MenloLFC::write_socket()", Tango::ERR); + //return; + } + else if(get_state() != Tango::ON) + { + stringstream tmp; + tmp << "Connected to " << servIP << ":" << servPort << ends; + set_state(Tango::ON); + set_status(tmp.str()); + conn_error = false; + } +} + +//+------------------------------------------------------------------ +// +// method: MenloLFC::read_serial +// +// description: method to execute "read_serial" +// Read from serial interface +// +//------------------------------------------------------------------- +void MenloLFC::read_serial(char *read_str, long &read_len) +{ + //DEBUG_STREAM << "MenloLFC::write_serial(): entering... !" << endl; + // Add your own code to control device here + Tango::DevVarLongStringArray strin; + string input, strout, strout_filt; + Tango::DeviceData Din,Dout; + const Tango::DevVarCharArray *out; + //long attr_read_param = SL_RAW; + long attr_read_param; + //attr_read_param = SAALEN << 8; + //attr_read_param = 1 << 8; //provo a leggere solo un carattere + //attr_read_param |= SL_NCHAR; + attr_read_param = SL_LINE; + + //attr_read_param = 2 << 8; //provo a leggere per 2 tentativi + //attr_read_param |= SL_RETRY; + long temp_len; + int i; + + try { + Din << attr_read_param; + Dout = devserial->command_inout("DevSerReadChar",Din); + } + catch(Tango::DevFailed e) { + TangoSys_MemStream out_stream; + conn_error = true; + out_stream << "DevSerReadNChar command to SerialDeviceServer failed" << ends; + //set_state(Tango::FAULT); + //set_status("Errors from serialdevice " + serialdevice); + WARN_STREAM << "MenloLFC::read_serial(): " << out_stream.str() << endl; + Tango::Except::re_throw_exception(e, + (const char *) "Error reading serial", + out_stream.str(), + (const char *) "MenloLFC::read_serial()", Tango::ERR); + } + if(!Dout.is_empty()) + Dout >> out; + else + { + //set_state(Tango::FAULT); + //set_status("Errors from serialdevice " + serialdevice); + Tango::Except::throw_exception( + (const char *) "Serialline timeout", + (const char *) "No data from serialline", + (const char *) "MenloLFC::read_serial()", Tango::ERR); + } + + memset(read_str,0,256); + temp_len = out->length(); + if(temp_len > 256) + { + WARN_STREAM << "MenloLFC::read_serial(): read buffer overflow, " << + temp_len << " > " << 256 << endl; + temp_len = 256; + } + read_len = temp_len; + stringstream temp; + for (int i = 0; i < temp_len; i++) + { + read_str[i] = (*out)[i]; + temp << showbase << hex << (int)(*out)[i] << " "; + } + DEBUG_STREAM << "MenloLFC::read_serial(): read=" << temp.str() << endl; +} + +//+------------------------------------------------------------------ +// +// method: MenloLFC::read_socket +// +// description: method to execute "read_serial" +// Read from serial interface +// +//------------------------------------------------------------------- +void MenloLFC::read_socket(char *read_str, long &read_len) +{ + int ret; +// char tmp_read[64]; + int i=0; + int len=0; + DEBUG_STREAM << "MenloLFC::read_socket(): entering conn_error=" << (int)conn_error << endl; + if(conn_error) + { + close (sock); + if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) + { + /*set_state(Tango::FAULT); + set_status("socket() failed"); + conn_error = true;*/ + ERROR_STREAM << "MenloLFC::read_socket(): socket error"; + stringstream tmp; + tmp << "Creation of socket failed" << ends; + set_state(Tango::FAULT); + set_status(tmp.str()); + conn_error = true; + INFO_STREAM << "MenloLFC::read_socket(): " << tmp.str(); + Tango::Except::throw_exception( + (const char *) "Error reading socket", + tmp.str(), + (const char *) "MenloLFC::read_socket()", Tango::ERR); + } + memset(&servAddr, 0, sizeof(servAddr)); /* Zero out structure {} */ + servAddr.sin_family = AF_INET; /* Internet address family */ + servAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */ + servAddr.sin_port = htons(servPort); /* Server port */ + if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) + { + stringstream tmp; + tmp << "Connection failed to " << servIP << ":" << servPort << ends; + set_state(Tango::FAULT); + set_status(tmp.str()); + conn_error = true; + INFO_STREAM << "MenloLFC::read_socket(): " << tmp.str(); + Tango::Except::throw_exception( + (const char *) "Error reading socket", + tmp.str(), + (const char *) "MenloLFC::read_socket()", Tango::ERR); + //return; + } + } + do + { + DEBUG_STREAM << "MenloLFC::read_socket(): before recv 256-len=" << 256-len << endl; + //ret = recv(sock, &read_str[len], 256-len, 0); + ret = recv(sock, &read_str[len], 256-len, MSG_DONTWAIT); + DEBUG_STREAM << "MenloLFC::read_socket(): after recv ret=" << ret << endl; + if(ret == -1) + { + /*stringstream tmp; + tmp << "Read failed from " << servIP << ":" << servPort << " errno=" << errno << "->" << strerror(errno)<< ends; + set_state(Tango::FAULT); + set_status(tmp.str()); + conn_error = true; + INFO_STREAM << "MenloLFC::read_socket(): " << tmp.str(); + Tango::Except::throw_exception( + (const char *) "Error reading socket", + tmp.str(), + (const char *) "MenloLFC::read_socket()", Tango::ERR);*/ + abort_sleep(2*wr_sleep/1000); + //return; + } + else if(get_state() != Tango::ON) + { + stringstream tmp; + tmp << "Connected to " << servIP << ":" << servPort << ends; + set_state(Tango::ON); + set_status(tmp.str()); + conn_error = false; + len += ret; + } + else + { + len += ret; + } + i++; + } + while(len == 0 && i < 8); + if(len == 0) + { + stringstream tmp; + tmp << "Read failed from " << servIP << ":" << servPort << " errno=" << errno << "->" << strerror(errno)<< ends; + set_state(Tango::FAULT); + set_status(tmp.str()); + conn_error = true; + INFO_STREAM << "MenloLFC::read_socket(): " << tmp.str(); + Tango::Except::throw_exception( + (const char *) "Error reading socket", + tmp.str(), + (const char *) "MenloLFC::read_socket()", Tango::ERR); + } + read_len = len; +} + +//+------------------------------------------------------------------ +// +// method: MenloLFC::apply_attr_value +// +// description: +// +//------------------------------------------------------------------- +template <typename Attr_type> void MenloLFC::apply_attr_value(Tango::Attribute &attr, string reg, Attr_type/*Tango::DevDouble*/ *attr_read, double factor, int index, int subdevice, int size) +{ + data_map::iterator it = read_data.find(reg); + if (it == read_data.end()) + { + INFO_STREAM << "MenloLFC::apply_attr_value: error reading: reg=0x" << hex << reg << " not found!" << endl; + Tango::Except::throw_exception( + "Error not found reg=" + reg, + "Error not found reg=" + reg, + (const char *) "MenloLFC::apply_attr_value", Tango::ERR); + } + bool timeout = false; + vector<int> types; + int num_types; + byte reg_type = it->second.reg_type; + //DEBUG_STREAM << "MenloLFC::apply_attr_value: found it->first=" << it->first<<" reg_type=0x" << hex << (int)reg_type << dec << endl; + cmd_type_map::iterator it2; + int id_type; + if (check_timeout(it->second.time, it->second.timeout) < 0) { + if (it->second.msg != "") { + INFO_STREAM << "MenloLFC::apply_attr_value: error reading: reg=" << it->first << " reg_type=0x" << hex << (int)reg_type << " err=" << it->second.msg << endl; + Tango::Except::throw_exception( + "Error reading reg=" + it->first, + (const char *) it->second.msg.c_str(), + (const char *) "MenloLFC::apply_attr_value", Tango::ERR); + } + else { + DEBUG_STREAM << "MenloLFC::apply_attr_value: reg=" << it->first << " reg_type=0x" << hex << (int)reg_type << " data is not refreshed" << dec << endl; + timeout = true; + } + } + + it2 = menlo->cmd_type.find(reg_type); + if(it2 == menlo->cmd_type.end()) + { + stringstream tmp; + tmp << "Register " << it->first << " reg_type=0x" << hex << (int)reg_type << dec << " not found!!" << ends; + Tango::Except::throw_exception( + "Error reading " + it->first, + tmp.str(), + (const char *) "MenloLFC::apply_attr_value", Tango::ERR); + } + types = it2->second; + num_types = types.size(); + if(index == -1) + { + if(it->second.data[subdevice].size() < num_types) + { + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_INVALID, num_types, 0, false); + INFO_STREAM << "MenloLFC::apply_attr_value: INVALID: index == -1 and it->second.data[subdevice].size()=" << it->second.data[subdevice].size() << " < num_types=" << num_types << endl; + return; + } + } + else if(it->second.data[subdevice].size() < index) + { + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_INVALID, num_types, 0, false); + INFO_STREAM << "MenloLFC::apply_attr_value: INVALID: it->second.data[subdevice].size()=" << it->second.data[subdevice].size() << " < index=" << index << endl; + return; + } + int attr_size = (size <= num_types) ? size : num_types; + //DEBUG_STREAM << "MenloLFC::apply_attr_value: attr_size=" << attr_size; + if(index == -1) //set size values + { + for(int i=0; i<attr_size; i++) + { + id_type = types[i]; + switch(id_type) + { + case U8: + attr_read[i] = (Attr_type)(it->second.data[subdevice][i].u8*factor); + break; + case U16: + attr_read[i] = (Attr_type)(it->second.data[subdevice][i].u16*factor); + break; + case U32: + attr_read[i] = (Attr_type)(it->second.data[subdevice][i].u32*factor); + break; + case S16: + attr_read[i] = (Attr_type)(it->second.data[subdevice][i].s16*factor); + break; + case S32: + attr_read[i] = (Attr_type)(it->second.data[subdevice][i].s32*factor); + break; + } + } + } + else + { + id_type = types[index]; + //DEBUG_STREAM << "MenloLFC::apply_attr_value: 222 id_type=" << id_type; + switch(id_type) + { + case U8: + *attr_read = (Attr_type)(it->second.data[subdevice][index].u8*factor); + break; + case U16: + *attr_read = (Attr_type)(it->second.data[subdevice][index].u16*factor); + //DEBUG_STREAM << "MenloLFC::apply_attr_value: 222 read U16=" << attr_read; + break; + case U32: + *attr_read = (Attr_type)(it->second.data[subdevice][index].u32*factor); + break; + case S16: + *attr_read = (Attr_type)(it->second.data[subdevice][index].s16*factor); + //DEBUG_STREAM << "MenloLFC::apply_attr_value: 222 read S16=" << attr_read; + break; + case S32: + *attr_read = (Attr_type)(it->second.data[subdevice][index].s32*factor); + break; + } + } + + if(index == -1) + { + if(!timeout) + attr.set_value(attr_read,attr_size); + else + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_WARNING, attr_size, 0, false); + } + else + { + if(!timeout) + attr.set_value(attr_read,1); + else + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_WARNING, 1, 0, false); + } +} + +//+------------------------------------------------------------------ +// +// method: MenloLFC::apply_attr_value_state +// +// description: +// +//------------------------------------------------------------------- +void MenloLFC::apply_attr_value_state(Tango::Attribute &attr, string reg, Tango::DevLong *attr_read, int index) +{ + data_map::iterator it = read_data.find(reg); + int subdevice=0; + if (it == read_data.end()) + { + INFO_STREAM << "MenloLFC::apply_attr_value_state: error reading: reg=0x" << hex << reg << " not found!" << endl; + Tango::Except::throw_exception( + "Error not found reg=" + reg, + "Error not found reg=" + reg, + (const char *) "MenloLFC::apply_attr_value_state", Tango::ERR); + } + bool timeout = false; + if (check_timeout(it->second.time, it->second.timeout) < 0) { + if (it->second.msg != "") { + INFO_STREAM << "MenloLFC::apply_attr_value_state: error reading: reg=0x" << hex << it->first << " err=" << it->second.msg << endl; + Tango::Except::throw_exception( + "Error reading reg=" + it->first, + (const char *) it->second.msg.c_str(), + (const char *) "MenloLFC::apply_attr_value_state", Tango::ERR); + } + else { + DEBUG_STREAM << "MenloLFC::apply_attr_value_state: reg=0x" << hex << it->first << " data is not refreshed" << dec << endl; + timeout = true; + } + } + + if(it->second.data[subdevice].size() < index) + { + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_INVALID, 1, 0, false); + INFO_STREAM << "MenloLFC::apply_attr_value_state: INVALID: it->second.data[subdevice].size()=" << it->second.data[subdevice].size() << " < index=" << index << endl; + return; + } + + switch(it->second.data[subdevice][index].u16) + { + case 0: //OFF + *attr_read = (Tango::DevLong)0; + break; + case 0x10: //ON + *attr_read = (Tango::DevLong)1; + break; + case 0x1: //off-to-on transition step 1 + *attr_read = (Tango::DevLong)2; + break; + case 0x2: //off-to-on transition step 2 + *attr_read = (Tango::DevLong)3; + break; + case 0x11: //on-to-off transition step 1 + *attr_read = (Tango::DevLong)4; + break; + case 0x12: //on-to-off transition step 2 + *attr_read = (Tango::DevLong)5; + break; + case 0x80: //initialization + *attr_read = (Tango::DevLong)6; + break; + case 0x08: //fault + *attr_read = (Tango::DevLong)-1; + break; + } + + + + if(!timeout) + attr.set_value(attr_read,1); + else + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_WARNING, 1, 0, false); +} + +//+------------------------------------------------------------------ +// +// method: MenloLFC::apply_attr_value_adcs +// +// description: +// +//------------------------------------------------------------------- +void MenloLFC::apply_attr_value_dacs(Tango::Attribute &attr, string reg, Tango::DevLong *attr_read) +{ + data_map::iterator it = read_data.find(reg); + bool timeout = false; + int subdevice = 0; + if (check_timeout(it->second.time, it->second.timeout) < 0) { + if (it->second.msg != "") { + Tango::Except::throw_exception( + "Error reading " + it->first, + (const char *) it->second.msg.c_str(), + (const char *) "MenloLFC::apply_attr_value_dacs", Tango::ERR); + } + else { + DEBUG_STREAM << "MenloLFC::apply_attr_value_dacs: " << it->first << " data is not refreshed" << endl; + timeout = true; + } + } + if(it->second.data[subdevice].size() < 6) + { + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_INVALID, 6, 0, false); + return; + } + + attr_read[0] = ((Tango::DevLong)it->second.data[subdevice][0].s32); + attr_read[1] = ((Tango::DevLong)it->second.data[subdevice][1].s32); + attr_read[2] = ((Tango::DevLong)it->second.data[subdevice][2].s32); + attr_read[3] = ((Tango::DevLong)it->second.data[subdevice][3].s32); + attr_read[4] = ((Tango::DevLong)it->second.data[subdevice][4].u16); + attr_read[5] = ((Tango::DevLong)it->second.data[subdevice][5].u16); + + + if(!timeout) + attr.set_value(attr_read,6); + else + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_WARNING, 6, 0, false); +} + +//+------------------------------------------------------------------ +// +// method: MenloLFC::apply_attr_value_adcs +// +// description: +// +//------------------------------------------------------------------- +void MenloLFC::apply_attr_value_adcs(Tango::Attribute &attr, string reg, Tango::DevLong *attr_read) +{ + data_map::iterator it = read_data.find(reg); + bool timeout = false; + int subdevice = 0; + if(it == read_data.end()) + { + Tango::Except::throw_exception( + "Error reading " + reg, + reg + " not present in polling thread", + (const char *) "MenloLFC::apply_attr_value_adcs", Tango::ERR); + } + if (check_timeout(it->second.time, it->second.timeout) < 0) { + if (it->second.msg != "") { + Tango::Except::throw_exception( + "Error reading " + it->first, + (const char *) it->second.msg.c_str(), + (const char *) "MenloLFC::apply_attr_value_adcs", Tango::ERR); + } + else { + DEBUG_STREAM << "MenloLFC::apply_attr_value_adcs: " << it->first << " data is not refreshed" << endl; + timeout = true; + } + } + if(it->second.data[subdevice].size() < 4) + { + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_INVALID, 4, 0, false); + return; + } + + attr_read[0] = ((Tango::DevLong)it->second.data[subdevice][0].s32); + attr_read[1] = ((Tango::DevLong)it->second.data[subdevice][1].s32); + attr_read[2] = ((Tango::DevLong)it->second.data[subdevice][2].s32); + attr_read[3] = ((Tango::DevLong)it->second.data[subdevice][3].s32); + + if(!timeout) + attr.set_value(attr_read,4); + else + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_WARNING, 4, 0, false); +} + +//+------------------------------------------------------------------ +// +// method: MenloLFC::apply_attr_value_tstamp +// +// description: +// +//------------------------------------------------------------------- +void MenloLFC::apply_attr_value_tstamp(Tango::Attribute &attr, string reg, Tango::DevDouble *attr_read) +{ + data_map::iterator it = read_data.find(reg); + bool timeout = false; + int subdevice = 0; + int tmp_s, tmp_ms; + if(it == read_data.end()) + { + Tango::Except::throw_exception( + "Error reading " + reg, + reg + " not present in polling thread", + (const char *) "MenloLFC::apply_attr_value_tstamp", Tango::ERR); + } + if (check_timeout(it->second.time, it->second.timeout) < 0) { + if (it->second.msg != "") { + Tango::Except::throw_exception( + "Error reading " + it->first, + (const char *) it->second.msg.c_str(), + (const char *) "MenloLFC::apply_attr_value_tstamp", Tango::ERR); + } + else { + DEBUG_STREAM << "MenloLFC::apply_attr_value_tstamp: " << it->first << " data is not refreshed" << endl; + timeout = true; + } + } + if(it->second.data[subdevice].size() < 2) + { + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_INVALID, 1, 0, false); + return; + } + + tmp_s = ((Tango::DevLong)it->second.data[subdevice][0].s32); + tmp_ms = ((Tango::DevLong)it->second.data[subdevice][1].s16); + + *attr_read = (double)(tmp_s + ((double)(tmp_ms))/1000.0); + + if(!timeout) + attr.set_value(attr_read); + else + attr.set_value_date_quality(attr_read,0/*gettime()*/,Tango::ATTR_WARNING, 1, 0, false); +} + +//+------------------------------------------------------------------ +// +// method: MenloLFC::write_attr_value +// +// description: +// +//------------------------------------------------------------------- +template <typename Attr_type> void MenloLFC::write_attr_value(Tango::WAttribute &attr, string reg, Attr_type/*Tango::DevLong*/ attr_write, int subdevice) +{ + DEBUG_STREAM << "MenloLFC::write_attr_value(Tango::WAttribute &attr) entering... "<< endl; + vector<int> types; + int num_types; + cmd_type_map::iterator it; + int id_type; + attr.get_write_value(attr_write); + data_t rdata; + int subdev=0; + int i=0; + int ret; + byte reg_type; + ret = menlo->FindRegType(reg, reg_type); + if(ret == -1) + { + stringstream tmp; + tmp << "reg type for register " << reg << " not found!!" << ends; + INFO_STREAM << "MenloLFC::write_attr_value(): " << tmp.str() << endl; + Tango::Except::throw_exception( + (const char *) "Error", + tmp.str(), + (const char *) "MenloLFC::write_attr_value()", Tango::ERR); + } + it = menlo->cmd_type.find(reg_type); + if(it == menlo->cmd_type.end()) + { + stringstream tmp; + tmp << "register " << reg << ", reg_type 0x" << hex << (int)reg_type << dec << " not found!!" << ends; + INFO_STREAM << "MenloLFC::write_attr_value(): " << tmp.str() << endl; + Tango::Except::throw_exception( + (const char *) "Error", + tmp.str(), + (const char *) "MenloLFC::write_attr_value()", Tango::ERR); + } + types = it->second; + num_types = types.size(); + + if(attr.get_write_value_length() != num_types) + { + stringstream tmp; + tmp << "Expeting " << num_types << " values" << ends; + INFO_STREAM << "MenloLFC::write_attr_value(): " << tmp.str() << endl; + Tango::Except::throw_exception( + (const char *) "Error", + tmp.str(), + (const char *) "MenloLFC::write_attr_value()", Tango::ERR); + } + if(subdevice != -1) + { + subdev = subdevice; + rdata.max_subdev = 2; //to enable writing of subdev (if > 1) + rdata.num_subdev = -1; + } + else + { + rdata.max_subdev = 1; + rdata.num_subdev = 1; + } + for(int y=0; y<num_types; y++) + { + id_type = types[y]; + DEBUG_STREAM << "MenloLFC::write_attr_value(): writing id_type=" << id_type << endl; + switch(id_type) + { + case U8: + { + rdata.data[subdev].push_back((unsigned char)attr_write[i++]); + } + break; + + case U16: + { + rdata.data[subdev].push_back((unsigned short)attr_write[i++]); + + } + break; + + case U32: + { + rdata.data[subdev].push_back((unsigned int)attr_write[i++]); + + } + break; + + case S16: + { + rdata.data[subdev].push_back((short)attr_write[i++]); + + } + break; + + case S32: + { + rdata.data[subdev].push_back((int)attr_write[i++]); + } + break; + } + + } + + + WriteRead(PROTO_CMD_WRITE, reg, subdevice, rdata); + if(rdata.msg != "") + { + INFO_STREAM << "MenloLFC::write_attr_value: error writing, err=" << rdata.msg << endl; + Tango::Except::throw_exception( + "Error writing", + (const char *) rdata.msg.c_str(), + (const char *) "MenloLFC::write_attr_value", Tango::ERR); + } + readloop->force_scheduler(reg); + if(*attr_EnableAutoSave_read) + { + save_config(); + } +} + +//+------------------------------------------------------------------ +// +// method: MenloLFC::check_timeout +// +// description: method to execute "check_timeout" +// Return -1 if timeout [msec.] exceeded +// +//------------------------------------------------------------------- +int MenloLFC::check_timeout(timeval time, double timeout) +{ + struct timeval timenow; + gettimeofday(&timenow,NULL); + + if ((timenow.tv_sec - time.tv_sec) > (timeout/1000)) { + DEBUG_STREAM << "MenloLFC::check_timeout(): TIMEOUT! sec diff=" << (timenow.tv_sec - time.tv_sec) << " > timeout=" << (timeout/1000) << endl; + return -1; + } + if (((timenow.tv_sec - time.tv_sec)*1000 - + (int)((double)(timenow.tv_usec - time.tv_usec)/1000)) > timeout) { + return -1; + } + return 0; + +} /* end check_timeout() */ + + +//+------------------------------------------------------------------ +// +// method: MenloLFC::abort_sleep +// +// description: Resume from sleep if abort_flag set (sec.) +// +//------------------------------------------------------------------- +void MenloLFC::abort_sleep(double time) +{ + + for (int i = 0; i < (time/0.1); i++) { + if (abortflag) + break; + omni_thread::sleep(0,100000000); + } + +} + +//+------------------------------------------------------------------ +/** + * method: MenloLFC::string_explode + * Explode a string +*/ +//+------------------------------------------------------------------ +void MenloLFC::string_explode(string str, string separator, vector<unsigned int>* results, bool b_hex) +{ + int found; + + found = str.find_first_of(separator); + while(found != string::npos) { + if(found > 0) { + unsigned int x; + bool err = false; + if(!b_hex) + { + std::istringstream i(str.substr(0,found)); + if (!(i >> x)) + { + err = true; + } + } + else + { + std::stringstream i; + i << hex << (str.substr(0,found)); + if (!(i >> x)) + { + err = true; + } + } + + if (err) + { + DEBUG_STREAM << "MenloLFC::string_explode error converting '" << str << "'"; + } + else + { + results->push_back(x); + DEBUG_STREAM << "MenloLFC::string_explode pushing " << x << "=0x" << hex << x << dec; + } + } + str = str.substr(found+1); + found = str.find_first_of(separator); + } + if(str.length() > 0) { + unsigned int x; + bool err = false; + if(!b_hex) + { + std::istringstream i(str); + if (!(i >> x)) + { + err = true; + } + } + else + { + std::stringstream i; + i << hex << (str); + if (!(i >> x)) + { + err = true; + } + } + if (err) + { + DEBUG_STREAM << "MenloLFC::string_explode error converting '" << str << "'"; + } + else + { + results->push_back(x); + DEBUG_STREAM << "MenloLFC::string_explode pushing " << x << "=0x" << hex << x << dec; + } + } + +} + +void MenloLFC::reconnect() +{ +#if 0 + if(moxa) + { + /* Establish the connection to the server */ + if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) + { + stringstream tmp; + tmp << "Connection failed to " << servIP << ":" << servPort << ends; + set_state(Tango::FAULT); + set_status(tmp.str()); + conn_error = true; + INFO_STREAM << "MenloLFC::reconnect(): " << tmp.str(); + return; + } + + } + else + { + /* check if serialdevice is responding */ + try { + if (devserial->ping()) + { + devserial->set_timeout_millis(serial_timeout); + //set_state(Tango::ON); + set_status("Connected to serialdevice " + serialdevice); + INFO_STREAM << "Connected to serialdevice " + serialdevice << endl; + } + } + catch(Tango::DevFailed e) { + set_state(Tango::FAULT); + Tango::DevState st = Tango::FAULT; + push_change_event("state", &st); + set_status("Failed to connect to serialdevice " + serialdevice); + INFO_STREAM << "MenloLFC::reconnect Failed to connect to serialdevice " + serialdevice << endl; + conn_error = true; + return; + } + + Tango::DeviceData Din; + Tango::DevLong flush = 2; //flush input and output + Din << flush; + try { + devserial->command_inout("DevSerFlush",Din); + } + catch(Tango::DevFailed e) { + string temp; + temp = e.errors[0].desc; + WARN_STREAM << "MenloLFC::reconnect error flushing serial device: " << temp << endl; + } + } +#endif + vector<string> names; + string reg_s; + data_t rdata; + names.push_back(S_DEV); + names.push_back(S_ADDR); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, S_DEV, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() == 0)) + { + INFO_STREAM << "MenloTheta::reconnect: error reading Device Address, err=" << rdata.msg << endl; + set_status("error reading Device Address, err=" + rdata.msg); + } + else + { + dev_add = rdata.data[0].front().u8; //update device address with the one read from the device + dev_add_loc = dev_add + 1; //define local address as device address + 1 + } + rdata.data[0].clear(); + abort_sleep(wr_sleep/1000); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_ID); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, S_ID, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() == 0)) + { + INFO_STREAM << "MenloTheta::reconnect: error reading Device ID, err=" << rdata.msg << endl; + set_status("error reading Device ID, err=" + rdata.msg); + strcpy(dev_id, ""); + } + else + { + strcpy(dev_id, rdata.data[0].front().cstring); + } + + rdata.data[0].clear(); + abort_sleep(wr_sleep/1000); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_VER_HW); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, S_VER_HW, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 4)) + { + INFO_STREAM << "MenloTheta::reconnect: error reading Device HW Version, err=" << rdata.msg << endl; + set_status("error reading Device HW Version, err=" + rdata.msg); + strcpy(dev_hw_ver, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int major,minor,patchlevel,build; + deque<data_union>::iterator it = rdata.data[0].begin(); + build = it->u8; + it++; + patchlevel = it->u8; + it++; + minor = it->u8; + it++; + major = it->u8; + sprintf(dev_hw_ver,"%d,%d,%d,%d", major,minor,patchlevel,build); + } + rdata.data[0].clear(); + abort_sleep(wr_sleep/1000); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_VER_FW); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, S_VER_FW, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 4)) + { + INFO_STREAM << "MenloTheta::reconnect: error reading Device FW Version, err=" << rdata.msg << endl; + set_status("error reading Device FW Version, err=" + rdata.msg); + strcpy(dev_fw_ver, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int major,minor,patchlevel,build; + deque<data_union>::iterator it = rdata.data[0].begin(); + build = it->u8; + it++; + patchlevel = it->u8; + it++; + minor = it->u8; + it++; + major = it->u8; + sprintf(dev_fw_ver,"%d,%d,%d,%d", major,minor,patchlevel,build); + } + rdata.data[0].clear(); + abort_sleep(wr_sleep/1000); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_VER_DISPFW); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, S_VER_DISPFW, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 4)) + { + INFO_STREAM << "MenloTheta::reconnect: error reading Display FW Version, err=" << rdata.msg << endl; + set_status("error reading Display FW Version, err=" + rdata.msg); + strcpy(display_fw_ver, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int major,minor,patchlevel,build; + deque<data_union>::iterator it = rdata.data[0].begin(); + build = it->u8; + it++; + patchlevel = it->u8; + it++; + minor = it->u8; + it++; + major = it->u8; + sprintf(display_fw_ver,"%d,%d,%d,%d", major,minor,patchlevel,build); + } + rdata.data[0].clear(); + abort_sleep(wr_sleep/1000); + names.clear(); + names.push_back(S_DEV); + names.push_back(S_SER); + menlo->NamesCat(reg_s, names); + WriteRead(PROTO_CMD_READ, S_SER, -1, rdata); + if((rdata.msg != "") || (rdata.data[0].size() < 3)) + { + INFO_STREAM << "MenloTheta::reconnect: error reading Device Serial, err=" << rdata.msg << endl; + set_status("error reading Device Serial, err=" + rdata.msg); + strcpy(dev_serial, ""); + } + else + { + //strcpy(dev_id, rdata.data.front().cstring); + int year,month,serial; + deque<data_union>::iterator it = rdata.data[0].begin(); + year = it->u8; + it++; + month = it->u8; + it++; + serial = it->u16; + sprintf(dev_serial,"%d,%d,%d", year,month,serial); + } + +} + +void MenloLFC::dump_msg(string label, int cnt, char *buf) +{ + stringstream tmp; + for(int k=0;k<cnt;) + { + stringstream tmp; + int g; + tmp << label << ": "<<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; + } + +} + + + +} // namespace diff --git a/src/MenloLFC.h b/src/MenloLFC.h new file mode 100644 index 0000000000000000000000000000000000000000..5878a6b8eb622bf44ac31dc78c10435413cda384 --- /dev/null +++ b/src/MenloLFC.h @@ -0,0 +1,618 @@ +//============================================================================= +// +// file : MenloLFC.h +// +// description : Include for the MenloLFC class. +// +// project : Low Level RF +// +// Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34149 Basovizza, Trieste ITALY +// +//============================================================================= +// +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +// +// (c) - Software Engineering Group - ESRF +//============================================================================= +#ifndef _MenloLFC_H +#define _MenloLFC_H + +#include <tango.h> +#include "Menlo.h" +#include <sys/socket.h> /* for socket(), connect(), send(), and recv() */ +#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */ + +#define PRIORITY_FACTOR 2 //priority multiplier factor + +//using namespace Tango; + +/** + * @author $Author: graziano $ + * @version $Revision: 1.7 $ + */ + + // Add your own constant definitions here. + //----------------------------------------------- +class readthread; + + + +namespace MenloLFC_ns +{ + + +/** + * Class Description: + * + */ + +/* + * Device States Description: + */ + + +class MenloLFC: public TANGO_BASE_CLASS +{ +public : + // Add your own data members here + //----------------------------------------- + + + // Here is the Start of the automatic code generation part + //------------------------------------------------------------- +/** + * @name attributes + * Attribute member data. + */ +//@{ + Tango::DevLong *attr_ISET_read; + Tango::DevLong attr_ISET_write; + Tango::DevLong *attr_IACT_read; + Tango::DevLong *attr_PACT_read; + Tango::DevLong *attr_DIODE_TSET_read; + Tango::DevLong attr_DIODE_TSET_write; + Tango::DevLong *attr_DIODE_TACT_read; + Tango::DevLong *attr_MODULE_TACT_read; + Tango::DevLong *attr_TCORR_read; + Tango::DevLong attr_TCORR_write; + Tango::DevLong *attr_TC0_ADJ_ISET_read; + const Tango::DevLong * attr_TC0_ADJ_ISET_write; + Tango::DevLong *attr_TC0_ADJ_TSET_read; + const Tango::DevLong * attr_TC0_ADJ_TSET_write; + Tango::DevLong *attr_TC0_ADJ_IACT_read; + const Tango::DevLong * attr_TC0_ADJ_IACT_write; + Tango::DevLong *attr_TM0_ADJ_TACT_read; + const Tango::DevLong * attr_TM0_ADJ_TACT_write; + Tango::DevLong *attr_TM0_ADJ_PACT_read; + const Tango::DevLong * attr_TM0_ADJ_PACT_write; + Tango::DevBoolean *attr_Amplifier_State_read; + Tango::DevBoolean attr_Amplifier_State_write; + Tango::DevLong *attr_Snapshot_read; + const Tango::DevLong * attr_Date_write; + Tango::DevLong *attr_Date_read; + const Tango::DevLong * attr_Time_write; + Tango::DevLong *attr_Time_read; + Tango::DevDouble *attr_RTstamp_read; + Tango::DevDouble *attr_Tstamp_read; + Tango::DevDouble *attr_TstampDiff_read; + Tango::DevDouble *attr_TstampStart_read; + Tango::DevDouble *attr_Uptime_read; + Tango::DevLong *attr_ADJ_PACT_1_read; + const Tango::DevLong * attr_ADJ_PACT_1_write; + Tango::DevDouble *attr_PACT_1_read; + Tango::DevDouble *attr_PMIN_1_read; + Tango::DevDouble *attr_PMAX_1_read; + Tango::DevLong *attr_Remote__ServiceMode_read; + Tango::DevBoolean *attr_EnableAutoSave_read; + Tango::DevBoolean attr_EnableAutoSave_write; +//@} + +/** + * @name Device properties + * Device properties member data. + */ +//@{ +/** + * Serial device proxy or IP_addr:port of Moxa + */ + string serialdevice; +/** + * + */ + Tango::DevLong serial_timeout; +/** + * Sleep time in the polling thread in ms + */ + Tango::DevDouble th_sleep; +/** + * Sleep time between writing and reading on the serial proxy in ms + */ + Tango::DevDouble wr_sleep; +/** + * + */ + Tango::DevLong dev_add; +//@} + +/** + * @name Device properties + * Device property member data. + */ +//@{ + string deviceSerial; +//@} + +/**@name Constructors + * Miscellaneous constructors */ +//@{ +/** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device Name + */ + MenloLFC(Tango::DeviceClass *cl,string &s); +/** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device Name + */ + MenloLFC(Tango::DeviceClass *cl,const char *s); +/** + * Constructs a newly allocated Command object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + MenloLFC(Tango::DeviceClass *cl,const char *s,const char *d); +//@} + +/**@name Destructor + * Only one destructor is defined for this class */ +//@{ +/** + * The object destructor. + */ + ~MenloLFC() {delete_device();}; +/** + * will be called at device destruction or at init command. + */ + void delete_device(); +//@} + + +/**@name Miscellaneous methods */ +//@{ +/** + * Initialize the device + */ + virtual void init_device(); +/** + * Always executed method before execution command method. + */ + virtual void always_executed_hook(); + +//@} + +/** + * @name MenloLFC methods prototypes + */ + +//@{ +/** + * Hardware acquisition for attributes. + */ + virtual void read_attr_hardware(vector<long> &attr_list); +/** + * Extract real attribute values for ISET acquisition result. + */ + virtual void read_ISET(Tango::Attribute &attr); +/** + * Write ISET attribute values to hardware. + */ + virtual void write_ISET(Tango::WAttribute &attr); +/** + * Extract real attribute values for Amplifier_State acquisition result. + */ + virtual void read_Amplifier_State(Tango::Attribute &attr); +/** + * Write Amplifier_State attribute values to hardware. + */ + virtual void write_Amplifier_State(Tango::WAttribute &attr); +/** + * Extract real attribute values for Snapshot acquisition result. + */ + virtual void read_Snapshot(Tango::Attribute &attr); +/** + * Extract real attribute values for Tstamp acquisition result. + */ + virtual void read_Tstamp(Tango::Attribute &attr); +/** + * Extract real attribute values for RTstamp acquisition result. + */ + virtual void read_RTstamp(Tango::Attribute &attr); +/** + * Extract real attribute values for TstampDiff acquisition result. + */ + virtual void read_TstampDiff(Tango::Attribute &attr); +/** + * Extract real attribute values for TstampStart acquisition result. + */ + virtual void read_TstampStart(Tango::Attribute &attr); +/** + * Extract real attribute values for Uptime acquisition result. + */ + virtual void read_Uptime(Tango::Attribute &attr); +/** + * Extract real attribute values for IACT acquisition result. + */ + virtual void read_IACT(Tango::Attribute &attr); +/** + * Extract real attribute values for PACT acquisition result. + */ + virtual void read_PACT(Tango::Attribute &attr); +/** + * Extract real attribute values for DIODE_TSET acquisition result. + */ + virtual void read_DIODE_TSET(Tango::Attribute &attr); +/** + * Write DIODE_TSET attribute values to hardware. + */ + virtual void write_DIODE_TSET(Tango::WAttribute &attr); +/** + * Extract real attribute values for DIODE_TACT acquisition result. + */ + virtual void read_DIODE_TACT(Tango::Attribute &attr); +/** + * Extract real attribute values for MODULE_TACT acquisition result. + */ + virtual void read_MODULE_TACT(Tango::Attribute &attr); +/** + * Extract real attribute values for TCORR acquisition result. + */ + virtual void read_TCORR(Tango::Attribute &attr); +/** + * Write TCORR attribute values to hardware. + */ + virtual void write_TCORR(Tango::WAttribute &attr); +/** + * Extract real attribute values for TC0_ADJ_ISET acquisition result. + */ + virtual void read_TC0_ADJ_ISET(Tango::Attribute &attr); +/** + * Write TC0_ADJ_ISET attribute values to hardware. + */ + virtual void write_TC0_ADJ_ISET(Tango::WAttribute &attr); +/** + * Extract real attribute values for TC0_ADJ_TSET acquisition result. + */ + virtual void read_TC0_ADJ_TSET(Tango::Attribute &attr); +/** + * Write TC0_ADJ_TSET attribute values to hardware. + */ + virtual void write_TC0_ADJ_TSET(Tango::WAttribute &attr); +/** + * Extract real attribute values for TC0_ADJ_IACT acquisition result. + */ + virtual void read_TC0_ADJ_IACT(Tango::Attribute &attr); +/** + * Write TC0_ADJ_IACT attribute values to hardware. + */ + virtual void write_TC0_ADJ_IACT(Tango::WAttribute &attr); +/** + * Extract real attribute values for TM0_ADJ_TACT acquisition result. + */ + virtual void read_TM0_ADJ_TACT(Tango::Attribute &attr); +/** + * Write TM0_ADJ_TACT attribute values to hardware. + */ + virtual void write_TM0_ADJ_TACT(Tango::WAttribute &attr); +/** + * Extract real attribute values for TM0_ADJ_PACT acquisition result. + */ + virtual void read_TM0_ADJ_PACT(Tango::Attribute &attr); +/** + * Write TM0_ADJ_PACT attribute values to hardware. + */ + virtual void write_TM0_ADJ_PACT(Tango::WAttribute &attr); +/** + * Extract real attribute values for Date acquisition result. + */ + virtual void read_Date(Tango::Attribute &attr); +/** + * Write Date attribute values to hardware. + */ + virtual void write_Date(Tango::WAttribute &attr); +/** + * Extract real attribute values for Time acquisition result. + */ + virtual void read_Time(Tango::Attribute &attr); +/** + * Write Time attribute values to hardware. + */ + virtual void write_Time(Tango::WAttribute &attr); +/** + * Extract real attribute values for ADJ_PACT_1 acquisition result. + */ + virtual void read_ADJ_PACT_1(Tango::Attribute &attr); +/** + * Write ADJ_PACT_1 attribute values to hardware. + */ + virtual void write_ADJ_PACT_1(Tango::WAttribute &attr); +/** + * Extract real attribute values for PACT_1 acquisition result. + */ + virtual void read_PACT_1(Tango::Attribute &attr); +/** + * Extract real attribute values for PMIN_1 acquisition result. + */ + virtual void read_PMIN_1(Tango::Attribute &attr); +/** + * Extract real attribute values for PMAX_1 acquisition result. + */ + virtual void read_PMAX_1(Tango::Attribute &attr); +/** + * Extract real attribute values for Remote__ServiceMode acquisition result. + */ + virtual void read_Remote__ServiceMode(Tango::Attribute &attr); +/** + * Extract real attribute values for EnableAutoSave acquisition result. + */ + virtual void read_EnableAutoSave(Tango::Attribute &attr); +/** + * Write EnableAutoSave attribute values to hardware. + */ + virtual void write_EnableAutoSave(Tango::WAttribute &attr); +/** + * Read/Write allowed for ISET attribute. + */ + virtual bool is_ISET_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for Amplifier_State attribute. + */ + virtual bool is_Amplifier_State_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for Tstamp attribute. + */ + virtual bool is_Tstamp_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for RTstamp attribute. + */ + virtual bool is_RTstamp_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for TstampDiff attribute. + */ + virtual bool is_TstampDiff_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for TstampStart attribute. + */ + virtual bool is_TstampStart_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for Uptime attribute. + */ + virtual bool is_Uptime_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for IACT attribute. + */ + virtual bool is_IACT_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for PACT attribute. + */ + virtual bool is_PACT_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for DIODE_TSET attribute. + */ + virtual bool is_DIODE_TSET_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for DIODE_TACT attribute. + */ + virtual bool is_DIODE_TACT_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for MODULE_TACT attribute. + */ + virtual bool is_MODULE_TACT_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for TCORR attribute. + */ + virtual bool is_TCORR_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for TC0_ADJ_ISET attribute. + */ + virtual bool is_TC0_ADJ_ISET_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for TC0_ADJ_TSET attribute. + */ + virtual bool is_TC0_ADJ_TSET_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for TC0_ADJ_IACT attribute. + */ + virtual bool is_TC0_ADJ_IACT_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for TM0_ADJ_TACT attribute. + */ + virtual bool is_TM0_ADJ_TACT_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for TM0_ADJ_PACT attribute. + */ + virtual bool is_TM0_ADJ_PACT_allowed(Tango::AttReqType type); +/** + * Read allowed for Snapshot attribute. + */ + virtual bool is_Snapshot_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for Date attribute. + */ + virtual bool is_Date_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for Time attribute. + */ + virtual bool is_Time_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for ADJ_PACT_1 attribute. + */ + virtual bool is_ADJ_PACT_1_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for PACT_1 attribute. + */ + virtual bool is_PACT_1_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for PMIN_1 attribute. + */ + virtual bool is_PMIN_1_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for PMAX_1 attribute. + */ + virtual bool is_PMAX_1_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for Remote__ServiceMode attribute. + */ + virtual bool is_Remote__ServiceMode_allowed(Tango::AttReqType type); +/** + * Read/Write allowed for EnableAutoSave attribute. + */ + virtual bool is_EnableAutoSave_allowed(Tango::AttReqType type); +/** + * Execution allowed for DeviceAddress command. + */ + virtual bool is_DeviceAddress_allowed(const CORBA::Any &any); +/** + * Execution allowed for DeviceID command. + */ + virtual bool is_DeviceID_allowed(const CORBA::Any &any); +/** + * Execution allowed for DeviceHWver command. + */ + virtual bool is_DeviceHWver_allowed(const CORBA::Any &any); +/** + * Execution allowed for DeviceFWver command. + */ + virtual bool is_DeviceFWver_allowed(const CORBA::Any &any); +/** + * Execution allowed for DeviceDispFWver command. + */ + virtual bool is_DisplayFWver_allowed(const CORBA::Any &any); +/** + * Execution allowed for DeviceSerial command. + */ + virtual bool is_DeviceSerial_allowed(const CORBA::Any &any); +/** + * Execution allowed for EnterServiceCode command. + */ + virtual bool is_EnterServiceCode_allowed(const CORBA::Any &any); +/** + * Execution allowed for SaveConfig command. + */ + virtual bool is_SaveConfig_allowed(const CORBA::Any &any); +/** + * Read Device Address + * @return Device Address + * @exception DevFailed + */ + Tango::DevLong device_address(); +/** + * Read Device ID + * @return Device ID + * @exception DevFailed + */ + Tango::DevString device_id(); +/** + * Read Device Hw Ver + * @return Device HW Ver + * @exception DevFailed + */ + Tango::DevString device_hwver(); +/** + * Read Device Fw Ver + * @return Device FW Ver + * @exception DevFailed + */ + Tango::DevString device_fwver(); +/** + * Read Display Fw Ver + * @return Display FW Ver + * @exception DevFailed + */ + Tango::DevString display_fwver(); +/** + * Read Device Serial + * @return Device Serial + * @exception DevFailed + */ + Tango::DevString device_serial(); +/** + * enter service code + * @return + * @exception DevFailed + */ + void enter_service_code(Tango::DevUShort); +/** + * Save config + * @return + * @exception DevFailed + */ + void save_config(); + +/** + * Read the device properties from database + */ + void get_device_property(); +//@} + + // Here is the end of the automatic code generation part + //------------------------------------------------------------- + + +protected : + // Add your own data members here + //----------------------------------------- + void write_serial(char *, long); + void read_serial(char *, long &); + void write_socket(char *write_str, long size); + void read_socket(char *, long &); + readthread *readloop; + + template <typename Attr_type> void apply_attr_value(Tango::Attribute &attr, string reg, Attr_type/*Tango::DevDouble*/ *attr_read, double factor, int index, int subdevice, int size); + void apply_attr_value_state(Tango::Attribute &attr, string reg, Tango::DevLong *attr_read, int index); + void apply_attr_value_dacs(Tango::Attribute &attr, string reg, Tango::DevLong *attr_read); + void apply_attr_value_adcs(Tango::Attribute &attr, string reg, Tango::DevLong *attr_read); + void apply_attr_value_tstamp(Tango::Attribute &attr, string reg, Tango::DevDouble *attr_read); + template <typename Attr_type> void write_attr_value(Tango::WAttribute &attr, string reg, Attr_type/*Tango::DevLong*/ attr_write, int subdevice); + void string_explode(string str, string separator, vector<unsigned int>* results, bool b_hex=false); + byte dev_add_loc; //local device address + char dev_id[256]; + char dev_hw_ver[256]; + char dev_fw_ver[256]; + char display_fw_ver[256]; + char dev_serial[256]; + bool moxa; + char servIP[INET_ADDRSTRLEN]; + unsigned short servPort; + int sock; + struct sockaddr_in servAddr; + int counter; + Menlo *menlo; + + void reconnect(); + void dump_msg(string label, int cnt, char *buf); + int timeoutHiPrio; + int timeoutLowPrio; + +public: + Tango::DeviceProxy *devserial; + int abortflag; // flag used to abort reading loop + int check_timeout(timeval, double); + void abort_sleep(double time); + omni_mutex *mutex; + int WriteRead(int cmd, string s_reg, int subdevice, data_t &rdata); + data_map read_data; + bool conn_error; +}; + +} // namespace_ns + +#endif // _MenloLFC_H diff --git a/src/MenloLFCClass.cpp b/src/MenloLFCClass.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f6dc4331d82c8ef9e1a33f7c48faab0caf3276b --- /dev/null +++ b/src/MenloLFCClass.cpp @@ -0,0 +1,946 @@ +static const char *ClassId = ""; +static const char *TagName = ""; +static const char *CvsPath = ""; +static const char *SvnPath = ""; +static const char *HttpServer = ""; +//+============================================================================= +// +// file : MenloLFCClass.cpp +// +// description : C++ source for the MenloLFCClass. A singleton +// class derived from DeviceClass. It implements the +// command list and all properties and methods required +// by the MenloLFC once per process. +// +// project : TANGO Device Server +// +// Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34149 Basovizza, Trieste ITALY +// +//-============================================================================= +// +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +// +// (c) - Software Engineering Group - ESRF +//============================================================================= + + +#include <tango.h> + +#include <MenloLFC.h> +#include <MenloLFCClass.h> + + +//+---------------------------------------------------------------------------- +/** + * Create MenloLFCClass singleton and return it in a C function for Python usage + */ +//+---------------------------------------------------------------------------- +extern "C" { +#ifdef WIN32 + +__declspec(dllexport) + +#endif + + Tango::DeviceClass *_create_MenloLFC_class(const char *name) { + return MenloLFC_ns::MenloLFCClass::init(name); + } +} + + +namespace MenloLFC_ns +{ +//+---------------------------------------------------------------------------- +// +// method : DeviceSerialCmd::execute() +// +// description : method to trigger the execution of the command. +// PLEASE DO NOT MODIFY this method core without pogo +// +// in : - device : The device on which the command must be executed +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *DeviceSerialCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout << "DeviceSerialCmd::execute(): arrived" << endl; + + return insert((static_cast<MenloLFC *>(device))->device_serial()); +} + +//+---------------------------------------------------------------------------- +// +// method : DeviceFWverCmd::execute() +// +// description : method to trigger the execution of the command. +// PLEASE DO NOT MODIFY this method core without pogo +// +// in : - device : The device on which the command must be executed +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *DeviceFWverCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout << "DeviceFWverCmd::execute(): arrived" << endl; + + return insert((static_cast<MenloLFC *>(device))->device_fwver()); +} + +//+---------------------------------------------------------------------------- +// +// method : DisplayFWverCmd::execute() +// +// description : method to trigger the execution of the command. +// PLEASE DO NOT MODIFY this method core without pogo +// +// in : - device : The device on which the command must be executed +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *DisplayFWverCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout << "DisplayFWverCmd::execute(): arrived" << endl; + + return insert((static_cast<MenloLFC *>(device))->display_fwver()); +} + +//+---------------------------------------------------------------------------- +// +// method : DeviceHWverCmd::execute() +// +// description : method to trigger the execution of the command. +// PLEASE DO NOT MODIFY this method core without pogo +// +// in : - device : The device on which the command must be executed +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *DeviceHWverCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout << "DeviceHWverCmd::execute(): arrived" << endl; + + return insert((static_cast<MenloLFC *>(device))->device_hwver()); +} + +//+---------------------------------------------------------------------------- +// +// method : DeviceIDCmd::execute() +// +// description : method to trigger the execution of the command. +// PLEASE DO NOT MODIFY this method core without pogo +// +// in : - device : The device on which the command must be executed +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *DeviceIDCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout << "DeviceIDCmd::execute(): arrived" << endl; + + return insert((static_cast<MenloLFC *>(device))->device_id()); +} + +//+---------------------------------------------------------------------------- +// +// method : DeviceAddressCmd::execute() +// +// description : method to trigger the execution of the command. +// PLEASE DO NOT MODIFY this method core without pogo +// +// in : - device : The device on which the command must be executed +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *DeviceAddressCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout << "DeviceAddressCmd::execute(): arrived" << endl; + + return insert((static_cast<MenloLFC *>(device))->device_address()); +} + +//+---------------------------------------------------------------------------- +// +// method : EnterServiceCodeClass::execute() +// +// description : method to trigger the execution of the command. +// PLEASE DO NOT MODIFY this method core without pogo +// +// in : - device : The device on which the command must be excuted +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *EnterServiceCodeClass::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout << "EnterServiceCodeClass::execute(): arrived" << endl; + Tango::DevUShort argin; + extract(in_any, argin); + + ((static_cast<MenloLFC *>(device))->enter_service_code(argin)); + return new CORBA::Any(); +} + +//+---------------------------------------------------------------------------- +// +// method : SaveConfigClass::execute() +// +// description : method to trigger the execution of the command. +// PLEASE DO NOT MODIFY this method core without pogo +// +// in : - device : The device on which the command must be excuted +// - in_any : The command input data +// +// returns : The command output data (packed in the Any object) +// +//----------------------------------------------------------------------------- +CORBA::Any *SaveConfigClass::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any) +{ + + cout << "SaveConfigClass::execute(): arrived" << endl; + + ((static_cast<MenloLFC *>(device))->save_config()); + return new CORBA::Any(); +} + +// +//---------------------------------------------------------------- +// Initialize pointer for singleton pattern +//---------------------------------------------------------------- +// +MenloLFCClass *MenloLFCClass::_instance = NULL; + +//+---------------------------------------------------------------------------- +// +// method : MenloLFCClass::MenloLFCClass(string &s) +// +// description : constructor for the MenloLFCClass +// +// in : - s : The class name +// +//----------------------------------------------------------------------------- +MenloLFCClass::MenloLFCClass(string &s):DeviceClass(s) +{ + + cout << "Entering MenloLFCClass constructor" << endl; + set_default_property(); + get_class_property(); + write_class_property(); + + cout << "Leaving MenloLFCClass constructor" << endl; + +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFCClass::~MenloLFCClass() +// +// description : destructor for the MenloLFCClass +// +//----------------------------------------------------------------------------- +MenloLFCClass::~MenloLFCClass() +{ + _instance = NULL; +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFCClass::instance +// +// description : Create the object if not already done. Otherwise, just +// return a pointer to the object +// +// in : - name : The class name +// +//----------------------------------------------------------------------------- +MenloLFCClass *MenloLFCClass::init(const char *name) +{ + if (_instance == NULL) + { + try + { + string s(name); + _instance = new MenloLFCClass(s); + } + catch (bad_alloc) + { + throw; + } + } + return _instance; +} + +MenloLFCClass *MenloLFCClass::instance() +{ + if (_instance == NULL) + { + cerr << "Class is not initialised !!" << endl; + exit(-1); + } + return _instance; +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFCClass::command_factory +// +// description : Create the command object(s) and store them in the +// command list +// +//----------------------------------------------------------------------------- +void MenloLFCClass::command_factory() +{ + command_list.push_back(new DeviceAddressCmd("DeviceAddress", + Tango::DEV_VOID, Tango::DEV_LONG, + "", + "Device Address", + Tango::OPERATOR)); + command_list.push_back(new DeviceIDCmd("DeviceID", + Tango::DEV_VOID, Tango::DEV_STRING, + "", + "Device ID", + Tango::OPERATOR)); + command_list.push_back(new DeviceHWverCmd("DeviceHWver", + Tango::DEV_VOID, Tango::DEV_STRING, + "", + "Device HW Ver", + Tango::OPERATOR)); + command_list.push_back(new DeviceFWverCmd("DeviceFWver", + Tango::DEV_VOID, Tango::DEV_STRING, + "", + "Device FW Ver", + Tango::OPERATOR)); + command_list.push_back(new DisplayFWverCmd("DisplayFWver", + Tango::DEV_VOID, Tango::DEV_STRING, + "", + "Display FW Ver", + Tango::OPERATOR)); + command_list.push_back(new DeviceSerialCmd("DeviceSerial", + Tango::DEV_VOID, Tango::DEV_STRING, + "", + "Device Serial", + Tango::OPERATOR)); + command_list.push_back(new EnterServiceCodeClass("EnterServiceCode", + Tango::DEV_USHORT, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR)); + command_list.push_back(new SaveConfigClass("SaveConfig", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR)); + + // add polling if any + for (unsigned int i=0 ; i<command_list.size(); i++) + { + } +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFCClass::get_class_property +// +// description : Get the class property for specified name. +// +// in : string name : The property name +// +//+---------------------------------------------------------------------------- +Tango::DbDatum MenloLFCClass::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, return an empty DbDatum + return Tango::DbDatum(prop_name); +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFCClass::get_default_device_property() +// +// description : Return the default value for device property. +// +//----------------------------------------------------------------------------- +Tango::DbDatum MenloLFCClass::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 : MenloLFCClass::get_default_class_property() +// +// description : Return the default value for class property. +// +//----------------------------------------------------------------------------- +Tango::DbDatum MenloLFCClass::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 : MenloLFCClass::device_factory +// +// description : Create the device object(s) and store them in the +// device list +// +// in : Tango::DevVarStringArray *devlist_ptr : The device name list +// +//----------------------------------------------------------------------------- +void MenloLFCClass::device_factory(const Tango::DevVarStringArray *devlist_ptr) +{ + // Erase all the dynamic attributes previously added to the class + //------------------------------------------------------------- + // Create all devices.(Automatic code generation) + //------------------------------------------------------------- + for (unsigned long i=0 ; i < devlist_ptr->length() ; i++) + { + cout << "Device name : " << (*devlist_ptr)[i].in() << endl; + + // Create devices and add it into the device list + //---------------------------------------------------- + device_list.push_back(new MenloLFC(this, (*devlist_ptr)[i])); + + // Export device to the outside world + // Check before if database used. + //--------------------------------------------- + if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false)) + export_device(device_list.back()); + else + export_device(device_list.back(), (*devlist_ptr)[i]); + } + // End of Automatic code generation + //------------------------------------------------------------- + +} +//+---------------------------------------------------------------------------- +// Method: MenloLFCClass::attribute_factory(vector<Tango::Attr *> &att_list) +//----------------------------------------------------------------------------- +void MenloLFCClass::attribute_factory(vector<Tango::Attr *> &att_list) +{ + // Attribute : ISET + ISETAttrib *iset = new ISETAttrib(); + Tango::UserDefaultAttrProp iset_prop; + iset_prop.set_unit("mA"); + iset_prop.set_standard_unit("1.0"); + iset_prop.set_display_unit("mA"); + iset_prop.set_description("Read/Write iset in mA"); + iset->set_default_properties(iset_prop); + att_list.push_back(iset); + + // Attribute : Amplifier_State + Amplifier_StateAttrib *amplifier__state = new Amplifier_StateAttrib(); + Tango::UserDefaultAttrProp amplifier__state_prop; + amplifier__state_prop.set_description("Switch Amplifier(1=on, 0=off)"); + amplifier__state->set_default_properties(amplifier__state_prop); + att_list.push_back(amplifier__state); + + // Attribute : Tstamp + TstampAttrib *tstamp = new TstampAttrib(); + Tango::UserDefaultAttrProp tstamp_prop; + tstamp_prop.set_unit("s"); + tstamp_prop.set_standard_unit("1.0"); + tstamp_prop.set_display_unit("s"); + tstamp_prop.set_description("Read timestamp (system time)"); + tstamp->set_default_properties(tstamp_prop); + att_list.push_back(tstamp); + + // Attribute : RTstamp + RTstampAttrib *rtstamp = new RTstampAttrib(); + Tango::UserDefaultAttrProp rtstamp_prop; + rtstamp_prop.set_unit("s"); + rtstamp_prop.set_standard_unit("1.0"); + rtstamp_prop.set_display_unit("s"); + rtstamp_prop.set_description("Read timestamp (RTC)"); + rtstamp->set_default_properties(rtstamp_prop); + att_list.push_back(rtstamp); + + // Attribute : TstampDiff + TstampDiffAttrib *tstamp_diff = new TstampDiffAttrib(); + Tango::UserDefaultAttrProp tstamp_diff_prop; + tstamp_diff_prop.set_unit("s"); + tstamp_diff_prop.set_standard_unit("1.0"); + tstamp_diff_prop.set_display_unit("s"); + tstamp_diff_prop.set_description("Difference between RTC and system time"); + tstamp_diff->set_default_properties(tstamp_diff_prop); + att_list.push_back(tstamp_diff); + + // Attribute : TstampStart + TstampStartAttrib *tstamp_start = new TstampStartAttrib(); + Tango::UserDefaultAttrProp tstamp_start_prop; + tstamp_start_prop.set_unit("s"); + tstamp_start_prop.set_standard_unit("1.0"); + tstamp_start_prop.set_display_unit("s"); + tstamp_start_prop.set_description("Starting time (RTC) as a timestamp"); + tstamp_start->set_default_properties(tstamp_start_prop); + att_list.push_back(tstamp_start); + + // Attribute : Uptime + UptimeAttrib *uptime = new UptimeAttrib(); + Tango::UserDefaultAttrProp uptime_prop; + uptime_prop.set_unit("s"); + uptime_prop.set_standard_unit("1.0"); + uptime_prop.set_display_unit("s"); + uptime_prop.set_description("Uptime"); + uptime->set_default_properties(uptime_prop); + att_list.push_back(uptime); + + // Attribute : IACT + IACTAttrib *iact = new IACTAttrib(); + Tango::UserDefaultAttrProp iact_prop; + iact_prop.set_unit("mA"); + iact_prop.set_standard_unit("1.0"); + iact_prop.set_display_unit("mA"); + iact_prop.set_description("Read actual value of diode current in mA"); + iact->set_default_properties(iact_prop); + att_list.push_back(iact); + + // Attribute : PACT + PACTAttrib *pact = new PACTAttrib(); + Tango::UserDefaultAttrProp pact_prop; + pact_prop.set_unit("mW"); + pact_prop.set_standard_unit("1.0"); + pact_prop.set_display_unit("mW"); + pact_prop.set_description("Read actual output power of diode"); + pact->set_default_properties(pact_prop); + att_list.push_back(pact); + + // Attribute : DIODE_TSET + DIODE_TSETAttrib *diode__tset = new DIODE_TSETAttrib(); + Tango::UserDefaultAttrProp diode__tset_prop; + diode__tset_prop.set_unit("uC"); + diode__tset_prop.set_standard_unit("1.0"); + diode__tset_prop.set_display_unit("uC"); + diode__tset_prop.set_description("Read/Write value of diode temperature controller in uC"); + diode__tset->set_default_properties(diode__tset_prop); + att_list.push_back(diode__tset); + + // Attribute : DIODE_TACT + DIODE_TACTAttrib *diode__tact = new DIODE_TACTAttrib(); + Tango::UserDefaultAttrProp diode__tact_prop; + diode__tact_prop.set_unit("uC"); + diode__tact_prop.set_standard_unit("1.0"); + diode__tact_prop.set_display_unit("uC"); + diode__tact_prop.set_description("Read actual diode temperature in uC"); + diode__tact->set_default_properties(diode__tact_prop); + att_list.push_back(diode__tact); + + // Attribute : MODULE_TACT + MODULE_TACTAttrib *module__tact = new MODULE_TACTAttrib(); + Tango::UserDefaultAttrProp module__tact_prop; + module__tact_prop.set_unit("uC"); + module__tact_prop.set_standard_unit("1.0"); + module__tact_prop.set_display_unit("uC"); + module__tact_prop.set_description("Read actual module temperature in uC"); + module__tact->set_default_properties(module__tact_prop); + att_list.push_back(module__tact); + + // Attribute : TCORR + TCORRAttrib *tcorr = new TCORRAttrib(); + Tango::UserDefaultAttrProp tcorr_prop; + tcorr_prop.set_unit("-K/A"); + tcorr_prop.set_standard_unit("1.0"); + tcorr_prop.set_display_unit("-K/A"); + tcorr_prop.set_description("Current dependent temperature shift (-K/A)"); + tcorr->set_default_properties(tcorr_prop); + att_list.push_back(tcorr); + + // Attribute : TC0_ADJ_ISET + TC0_ADJ_ISETAttrib *tc0__adj__iset = new TC0_ADJ_ISETAttrib(); + Tango::UserDefaultAttrProp tc0__adj__iset_prop; + tc0__adj__iset_prop.set_description("iset adjustment and range:\n [0]=raw_0\n [1]=phys_0\n [2]=raw_1\n [3]=phys_1\n [4]=range_min\n [5]=range_max"); + tc0__adj__iset->set_default_properties(tc0__adj__iset_prop); + att_list.push_back(tc0__adj__iset); + + // Attribute : TC0_ADJ_TSET + TC0_ADJ_TSETAttrib *tc0__adj__tset = new TC0_ADJ_TSETAttrib(); + Tango::UserDefaultAttrProp tc0__adj__tset_prop; + tc0__adj__tset_prop.set_description("tset adjustment and range:\n [0]=raw_0\n [1]=phys_0\n [2]=raw_1\n [3]=phys_1\n [4]=range_min\n [5]=range_max"); + tc0__adj__tset->set_default_properties(tc0__adj__tset_prop); + att_list.push_back(tc0__adj__tset); + + // Attribute : TC0_ADJ_IACT + TC0_ADJ_IACTAttrib *tc0__adj__iact = new TC0_ADJ_IACTAttrib(); + Tango::UserDefaultAttrProp tc0__adj__iact_prop; + tc0__adj__iact_prop.set_description("iact adjustment:\n [0]=raw_0\n [1]=phys_0\n [2]=raw_1\n [3]=phys_1"); + tc0__adj__iact->set_default_properties(tc0__adj__iact_prop); + att_list.push_back(tc0__adj__iact); + + // Attribute : TM0_ADJ_TACT + TM0_ADJ_TACTAttrib *tm0__adj__tact = new TM0_ADJ_TACTAttrib(); + Tango::UserDefaultAttrProp tm0__adj__tact_prop; + tm0__adj__tact_prop.set_description("tact adjustment:\n [0]=raw_0\n [1]=phys_0\n [2]=raw_1\n [3]=phys_1"); + tm0__adj__tact->set_default_properties(tm0__adj__tact_prop); + att_list.push_back(tm0__adj__tact); + + // Attribute : TM0_ADJ_PACT + TM0_ADJ_PACTAttrib *tm0__adj__pact = new TM0_ADJ_PACTAttrib(); + Tango::UserDefaultAttrProp tm0__adj__pact_prop; + tm0__adj__pact_prop.set_description("pact adjustment:\n [0]=raw_0\n [1]=phys_0\n [2]=raw_1\n [3]=phys_1"); + tm0__adj__pact->set_default_properties(tm0__adj__pact_prop); + att_list.push_back(tm0__adj__pact); + + // Attribute : Date + DateAttrib *date = new DateAttrib(); + Tango::UserDefaultAttrProp date_prop; + date_prop.set_description("RTC date setting:\n [0]=day of month(1-31)\n [1]=month(1-12)\n [2]=year after 2000(0-99)"); + date->set_default_properties(date_prop); + att_list.push_back(date); + + // Attribute : Time + TimeAttrib *time = new TimeAttrib(); + Tango::UserDefaultAttrProp time_prop; + time_prop.set_description("RTC time setting:\n [0]=hour(0-23)\n [1]=minute(0-59)\n [2]=second(0-59)"); + time->set_default_properties(time_prop); + att_list.push_back(time); + + // Attribute : ADJ_PACT_1 + ADJ_PACT_1Attrib *adj__pact__1 = new ADJ_PACT_1Attrib(); + Tango::UserDefaultAttrProp adj__pact__1_prop; + adj__pact__1_prop.set_description("pact 1 adjustment:\n [0]=raw_0\n [1]=phys_0\n [2]=raw_1\n [3]=phys_1"); + adj__pact__1->set_default_properties(adj__pact__1_prop); + att_list.push_back(adj__pact__1); + + // Attribute : PACT_1 + PACT_1Attrib *pact__1 = new PACT_1Attrib(); + Tango::UserDefaultAttrProp pact__1_prop; + pact__1_prop.set_unit("uW"); + pact__1_prop.set_standard_unit("1.0"); + pact__1_prop.set_display_unit("uW"); + pact__1_prop.set_description("Read actual output power of diode 1"); + pact__1->set_default_properties(pact__1_prop); + att_list.push_back(pact__1); + + // Attribute : PMIN_1 + PMIN_1Attrib *pmin__1 = new PMIN_1Attrib(); + Tango::UserDefaultAttrProp pmin__1_prop; + pmin__1_prop.set_unit("uW"); + pmin__1_prop.set_standard_unit("1.0"); + pmin__1_prop.set_display_unit("uW"); + pmin__1_prop.set_description("Lower limit of power of diode 1"); + pmin__1->set_default_properties(pmin__1_prop); + att_list.push_back(pmin__1); + + // Attribute : PMAX_1 + PMAX_1Attrib *pmax__1 = new PMAX_1Attrib(); + Tango::UserDefaultAttrProp pmax__1_prop; + pmax__1_prop.set_unit("uW"); + pmax__1_prop.set_standard_unit("1.0"); + pmax__1_prop.set_display_unit("uW"); + pmax__1_prop.set_description("Upper limit of power of diode 1"); + pmax__1->set_default_properties(pmax__1_prop); + att_list.push_back(pmax__1); + + // Attribute : Remote__ServiceMode + Remote__ServiceModeAttrib *remote__service_mode = new Remote__ServiceModeAttrib(); + Tango::UserDefaultAttrProp remote__service_mode_prop; + remote__service_mode_prop.set_description("Service Mode enabled"); + remote__service_mode->set_default_properties(remote__service_mode_prop); + att_list.push_back(remote__service_mode); + + // Attribute : EnableAutoSave + EnableAutoSaveAttrib *enable_auto_save = new EnableAutoSaveAttrib(); + Tango::UserDefaultAttrProp enable_auto_save_prop; + enable_auto_save_prop.set_description("Enable/Disable auto_saves on this device"); + enable_auto_save->set_default_properties(enable_auto_save_prop); + enable_auto_save->set_memorized(); + enable_auto_save->set_memorized_init(true); + att_list.push_back(enable_auto_save); + + // End of Automatic code generation + //------------------------------------------------------------- +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFCClass::get_class_property() +// +// description : Read the class properties from database. +// +//----------------------------------------------------------------------------- +void MenloLFCClass::get_class_property() +{ + // Initialize your default values here (if not done with POGO). + //------------------------------------------------------------------ + + // Read class properties from database.(Automatic code generation) + //------------------------------------------------------------------ + + // Call database and extract values + //-------------------------------------------- + if (Tango::Util::instance()->_UseDb==true) + get_db_class()->get_property(cl_prop); + Tango::DbDatum def_prop; + int i = -1; + + + // End of Automatic code generation + //------------------------------------------------------------------ + +} + +//+---------------------------------------------------------------------------- +// +// method : MenloLFCClass::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 MenloLFCClass::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 = "Serialdevice"; + prop_desc = "Serial device proxy or IP_addr:port of Moxa"; + 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 = "Serial_timeout"; + 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 = "Th_sleep"; + prop_desc = "Sleep time in the polling thread in ms"; + 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 = "Wr_sleep"; + prop_desc = "Sleep time between writing and reading on the serial proxy in ms"; + 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 = "Dev_add"; + 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 : MenloLFCClass::write_class_property +// +// description : Set class description as property in database +// +//----------------------------------------------------------------------------- +void MenloLFCClass::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("Low Level RF"); + 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(classname); + filename += "Class.cpp"; + + // Create a string with the class ID to + // get the string into the binary + string class_id(ClassId); + + // 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); +} + +} // namespace diff --git a/src/MenloLFCClass.h b/src/MenloLFCClass.h new file mode 100644 index 0000000000000000000000000000000000000000..fa4db35cb63a5dd9d18e5e88a805263710b57dcd --- /dev/null +++ b/src/MenloLFCClass.h @@ -0,0 +1,609 @@ +//============================================================================= +// +// file : MenloLFCClass.h +// +// description : Include for the MenloLFCClass root class. +// This class is the singleton class for +// the MenloLFC device class. +// It contains all properties and methods which the +// MenloLFC requires only once e.g. the commands. +// +// project : TANGO Device Server +// +// Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34149 Basovizza, Trieste ITALY +// +//============================================================================= +// +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +// +// (c) - Software Engineering Group - ESRF +//============================================================================= + +#ifndef _MenloLFCCLASS_H +#define _MenloLFCCLASS_H + +#include <tango.h> +#include <MenloLFC.h> + + +namespace MenloLFC_ns +{//===================================== +// Define classes for attributes +//===================================== +class EnableAutoSaveAttrib: public Tango::Attr +{ +public: + EnableAutoSaveAttrib():Attr("EnableAutoSave", Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~EnableAutoSaveAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_EnableAutoSave(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_EnableAutoSave(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_EnableAutoSave_allowed(ty);} +}; + +class Remote__ServiceModeAttrib: public Tango::Attr +{ +public: + Remote__ServiceModeAttrib():Attr("Remote__ServiceMode", Tango::DEV_LONG, Tango::READ) {}; + ~Remote__ServiceModeAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_Remote__ServiceMode(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_Remote__ServiceMode_allowed(ty);} +}; + +class PMAX_1Attrib: public Tango::Attr +{ +public: + PMAX_1Attrib():Attr("PMAX_1", Tango::DEV_DOUBLE, Tango::READ) {}; + ~PMAX_1Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_PMAX_1(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_PMAX_1_allowed(ty);} +}; + +class PMIN_1Attrib: public Tango::Attr +{ +public: + PMIN_1Attrib():Attr("PMIN_1", Tango::DEV_DOUBLE, Tango::READ) {}; + ~PMIN_1Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_PMIN_1(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_PMIN_1_allowed(ty);} +}; + +class PACT_1Attrib: public Tango::Attr +{ +public: + PACT_1Attrib():Attr("PACT_1", Tango::DEV_DOUBLE, Tango::READ) {}; + ~PACT_1Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_PACT_1(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_PACT_1_allowed(ty);} +}; + +class ADJ_PACT_1Attrib: public Tango::SpectrumAttr +{ +public: + ADJ_PACT_1Attrib():SpectrumAttr("ADJ_PACT_1", Tango::DEV_LONG, Tango::READ_WRITE, 4) {}; + ~ADJ_PACT_1Attrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_ADJ_PACT_1(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_ADJ_PACT_1(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_ADJ_PACT_1_allowed(ty);} +}; + +class TimeAttrib: public Tango::SpectrumAttr +{ +public: + TimeAttrib():SpectrumAttr("Time", Tango::DEV_LONG, Tango::READ_WRITE, 3) {}; + ~TimeAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_Time(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_Time(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_Time_allowed(ty);} +}; + +class DateAttrib: public Tango::SpectrumAttr +{ +public: + DateAttrib():SpectrumAttr("Date", Tango::DEV_LONG, Tango::READ_WRITE, 3) {}; + ~DateAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_Date(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_Date(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_Date_allowed(ty);} +}; + +class TM0_ADJ_PACTAttrib: public Tango::SpectrumAttr +{ +public: + TM0_ADJ_PACTAttrib():SpectrumAttr("TM0_ADJ_PACT", Tango::DEV_LONG, Tango::READ_WRITE, 4) {}; + ~TM0_ADJ_PACTAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_TM0_ADJ_PACT(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_TM0_ADJ_PACT(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_TM0_ADJ_PACT_allowed(ty);} +}; + +class TM0_ADJ_TACTAttrib: public Tango::SpectrumAttr +{ +public: + TM0_ADJ_TACTAttrib():SpectrumAttr("TM0_ADJ_TACT", Tango::DEV_LONG, Tango::READ_WRITE, 4) {}; + ~TM0_ADJ_TACTAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_TM0_ADJ_TACT(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_TM0_ADJ_TACT(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_TM0_ADJ_TACT_allowed(ty);} +}; + +class TC0_ADJ_IACTAttrib: public Tango::SpectrumAttr +{ +public: + TC0_ADJ_IACTAttrib():SpectrumAttr("TC0_ADJ_IACT", Tango::DEV_LONG, Tango::READ_WRITE, 4) {}; + ~TC0_ADJ_IACTAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_TC0_ADJ_IACT(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_TC0_ADJ_IACT(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_TC0_ADJ_IACT_allowed(ty);} +}; + +class TC0_ADJ_TSETAttrib: public Tango::SpectrumAttr +{ +public: + TC0_ADJ_TSETAttrib():SpectrumAttr("TC0_ADJ_TSET", Tango::DEV_LONG, Tango::READ_WRITE, 6) {}; + ~TC0_ADJ_TSETAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_TC0_ADJ_TSET(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_TC0_ADJ_TSET(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_TC0_ADJ_TSET_allowed(ty);} +}; + +class TC0_ADJ_ISETAttrib: public Tango::SpectrumAttr +{ +public: + TC0_ADJ_ISETAttrib():SpectrumAttr("TC0_ADJ_ISET", Tango::DEV_LONG, Tango::READ_WRITE, 6) {}; + ~TC0_ADJ_ISETAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_TC0_ADJ_ISET(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_TC0_ADJ_ISET(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_TC0_ADJ_ISET_allowed(ty);} +}; + +class TCORRAttrib: public Tango::Attr +{ +public: + TCORRAttrib():Attr("TCORR", Tango::DEV_LONG, Tango::READ_WRITE) {}; + ~TCORRAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_TCORR(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_TCORR(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_TCORR_allowed(ty);} +}; + +class MODULE_TACTAttrib: public Tango::Attr +{ +public: + MODULE_TACTAttrib():Attr("MODULE_TACT", Tango::DEV_LONG, Tango::READ) {}; + ~MODULE_TACTAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_MODULE_TACT(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_MODULE_TACT_allowed(ty);} +}; + +class DIODE_TACTAttrib: public Tango::Attr +{ +public: + DIODE_TACTAttrib():Attr("DIODE_TACT", Tango::DEV_LONG, Tango::READ) {}; + ~DIODE_TACTAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_DIODE_TACT(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_DIODE_TACT_allowed(ty);} +}; + +class DIODE_TSETAttrib: public Tango::Attr +{ +public: + DIODE_TSETAttrib():Attr("DIODE_TSET", Tango::DEV_LONG, Tango::READ_WRITE) {}; + ~DIODE_TSETAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_DIODE_TSET(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_DIODE_TSET(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_DIODE_TSET_allowed(ty);} +}; + +class PACTAttrib: public Tango::Attr +{ +public: + PACTAttrib():Attr("PACT", Tango::DEV_LONG, Tango::READ) {}; + ~PACTAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_PACT(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_PACT_allowed(ty);} +}; + +class IACTAttrib: public Tango::Attr +{ +public: + IACTAttrib():Attr("IACT", Tango::DEV_LONG, Tango::READ) {}; + ~IACTAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_IACT(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_IACT_allowed(ty);} +}; + +class UptimeAttrib: public Tango::Attr +{ +public: + UptimeAttrib():Attr("Uptime", Tango::DEV_DOUBLE, Tango::READ) {}; + ~UptimeAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_Uptime(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_Uptime_allowed(ty);} +}; + +class TstampStartAttrib: public Tango::Attr +{ +public: + TstampStartAttrib():Attr("TstampStart", Tango::DEV_DOUBLE, Tango::READ) {}; + ~TstampStartAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_TstampStart(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_TstampStart_allowed(ty);} +}; + +class TstampDiffAttrib: public Tango::Attr +{ +public: + TstampDiffAttrib():Attr("TstampDiff", Tango::DEV_DOUBLE, Tango::READ) {}; + ~TstampDiffAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_TstampDiff(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_TstampDiff_allowed(ty);} +}; + +class RTstampAttrib: public Tango::Attr +{ +public: + RTstampAttrib():Attr("RTstamp", Tango::DEV_DOUBLE, Tango::READ) {}; + ~RTstampAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_RTstamp(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_RTstamp_allowed(ty);} +}; + +class TstampAttrib: public Tango::Attr +{ +public: + TstampAttrib():Attr("Tstamp", Tango::DEV_DOUBLE, Tango::READ) {}; + ~TstampAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_Tstamp(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_Tstamp_allowed(ty);} +}; + +class Amplifier_StateAttrib: public Tango::Attr +{ +public: + Amplifier_StateAttrib():Attr("Amplifier_State", Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~Amplifier_StateAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_Amplifier_State(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_Amplifier_State(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_Amplifier_State_allowed(ty);} +}; + +class ISETAttrib: public Tango::Attr +{ +public: + ISETAttrib():Attr("ISET", Tango::DEV_LONG, Tango::READ_WRITE) {}; + ~ISETAttrib() {}; + + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<MenloLFC *>(dev))->read_ISET(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<MenloLFC *>(dev))->write_ISET(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<MenloLFC *>(dev))->is_ISET_allowed(ty);} +}; + +//========================================= +// Define classes for commands +//========================================= +class SaveConfigClass : public Tango::Command +{ +public: + SaveConfigClass(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) {}; + + SaveConfigClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~SaveConfigClass() {}; + + 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<MenloLFC *>(dev))->is_SaveConfig_allowed(any);} +}; + +class EnterServiceCodeClass : public Tango::Command +{ +public: + EnterServiceCodeClass(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) {}; + + EnterServiceCodeClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~EnterServiceCodeClass() {}; + + 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<MenloLFC *>(dev))->is_EnterServiceCode_allowed(any);} +}; + +class DeviceSerialCmd : public Tango::Command +{ +public: + DeviceSerialCmd(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) {}; + + DeviceSerialCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~DeviceSerialCmd() {}; + + 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<MenloLFC *>(dev))->is_DeviceSerial_allowed(any);} +}; + + + +class DeviceFWverCmd : public Tango::Command +{ +public: + DeviceFWverCmd(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) {}; + + DeviceFWverCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~DeviceFWverCmd() {}; + + 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<MenloLFC *>(dev))->is_DeviceFWver_allowed(any);} +}; + +class DisplayFWverCmd : public Tango::Command +{ +public: + DisplayFWverCmd(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) {}; + + DisplayFWverCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~DisplayFWverCmd() {}; + + 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<MenloLFC *>(dev))->is_DisplayFWver_allowed(any);} +}; + + +class DeviceHWverCmd : public Tango::Command +{ +public: + DeviceHWverCmd(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) {}; + + DeviceHWverCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~DeviceHWverCmd() {}; + + 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<MenloLFC *>(dev))->is_DeviceHWver_allowed(any);} +}; + + + +class DeviceIDCmd : public Tango::Command +{ +public: + DeviceIDCmd(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) {}; + + DeviceIDCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~DeviceIDCmd() {}; + + 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<MenloLFC *>(dev))->is_DeviceID_allowed(any);} +}; + + + +class DeviceAddressCmd : public Tango::Command +{ +public: + DeviceAddressCmd(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) {}; + + DeviceAddressCmd(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~DeviceAddressCmd() {}; + + 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<MenloLFC *>(dev))->is_DeviceAddress_allowed(any);} +}; + + + +// +// The MenloLFCClass singleton definition +// + +class +#ifdef WIN32 + __declspec(dllexport) +#endif + MenloLFCClass : public Tango::DeviceClass +{ +public: +// properties member data + +// add your own data members here +//------------------------------------ + +public: + Tango::DbData cl_prop; + Tango::DbData cl_def_prop; + Tango::DbData dev_def_prop; + +// Method prototypes + static MenloLFCClass *init(const char *); + static MenloLFCClass *instance(); + ~MenloLFCClass(); + Tango::DbDatum get_class_property(string &); + Tango::DbDatum get_default_device_property(string &); + Tango::DbDatum get_default_class_property(string &); + +protected: + MenloLFCClass(string &); + static MenloLFCClass *_instance; + void command_factory(); + void get_class_property(); + void attribute_factory(vector<Tango::Attr *> &); + void write_class_property(); + void set_default_property(); + string get_cvstag(); + string get_cvsroot(); + +private: + void device_factory(const Tango::DevVarStringArray *); +}; + + +} // namespace MenloLFC_ns + +#endif // _MENLOLFCCLASS_H diff --git a/src/MenloLFCStateMachine.cpp b/src/MenloLFCStateMachine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b59e36f765cd6a9851ae39d55bfe9be90636736 --- /dev/null +++ b/src/MenloLFCStateMachine.cpp @@ -0,0 +1,538 @@ +static const char *RcsId = "$Id $"; +//+============================================================================= +// +// file : MenloLFCStateMachine.cpp +// +// description : C++ source for the MenloLFC and its alowed +// methods for commands and attributes +// +// project : TANGO Device Server +// +// Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34149 Basovizza, Trieste ITALY +// +//-============================================================================= +// +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +// +// (c) - Software Engineering Group - ESRF +//============================================================================= + +#include <tango.h> +#include <MenloLFC.h> +#include <MenloLFCClass.h> + +/*==================================================================== + * This file contains the methods to allow commands and attributes + * read or write execution. + * + * If you wand to add your own code, add it between + * the "End/Re-Start of Generated Code" comments. + * + * If you want, you can also add your own methods. + *==================================================================== + */ + +namespace MenloLFC_ns +{ + +//================================================= +// Attributes Allowed Methods +//================================================= +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_ISET_allowed +// +// description : Read/Write allowed for ISET attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_ISET_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_TC0_ADJ_ISET_allowed +// +// description : Read/Write allowed for TC0_ADJ_ISET attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_TC0_ADJ_ISET_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_TC0_ADJ_TSET_allowed +// +// description : Read/Write allowed for TC0_ADJ_TSET attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_TC0_ADJ_TSET_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_TC0_ADJ_IACT_allowed +// +// description : Read/Write allowed for TC0_ADJ_IACT attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_TC0_ADJ_IACT_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_TM0_ADJ_TACT_allowed +// +// description : Read/Write allowed for TM0_ADJ_TACT attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_TM0_ADJ_TACT_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_TM0_ADJ_PACT_allowed +// +// description : Read/Write allowed for TM0_ADJ_PACT attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_TM0_ADJ_PACT_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_Amplifier_State_allowed +// +// description : Read/Write allowed for Amplifier_State attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_Amplifier_State_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_Snapshot_allowed +// +// description : Read allowed for Snapshot attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_Snapshot_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_Date_allowed +// +// description : Read allowed for Date attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_Date_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_Time_allowed +// +// description : Read allowed for Time attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_Time_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_RTstamp_allowed +// +// description : Read allowed for RTstamp attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_RTstamp_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_Tstamp_allowed +// +// description : Read allowed for Tstamp attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_Tstamp_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_TstampDiff_allowed +// +// description : Read allowed for TstampDiff attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_TstampDiff_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_TstampStart_allowed +// +// description : Read allowed for TstampStart attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_TstampStart_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_Uptime_allowed +// +// description : Read allowed for Uptime attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_Uptime_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_IACT_allowed +// +// description : Read allowed for IACT attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_IACT_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_PACT_allowed +// +// description : Read allowed for PACT attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_PACT_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_DIODE_TSET_allowed +// +// description : Read allowed for DIODE_TSET attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_DIODE_TSET_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_DIODE_TACT_allowed +// +// description : Read allowed for DIODE_TACT attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_DIODE_TACT_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_MODULE_TACT_allowed +// +// description : Read allowed for MODULE_TACT attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_MODULE_TACT_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_TCORR_allowed +// +// description : Read allowed for TCORR attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_TCORR_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_ADJ_PACT_1_allowed +// +// description : Read/Write allowed for ADJ_PACT_1 attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_ADJ_PACT_1_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_PACT_1_allowed +// +// description : Read/Write allowed for PACT_1 attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_PACT_1_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_PMIN_1_allowed +// +// description : Read/Write allowed for PMIN_1 attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_PMIN_1_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_PMAX_1_allowed +// +// description : Read/Write allowed for PMAX_1 attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_PMAX_1_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_Remote__ServiceMode_allowed +// +// description : Read/Write allowed for Remote__ServiceMode attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_Remote__ServiceMode_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_EnableAutoSave_allowed +// +// description : Read/Write allowed for EnableAutoSave attribute. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_EnableAutoSave_allowed(Tango::AttReqType type) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//================================================= +// Commands Allowed Methods +//================================================= +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_DeviceAddress_allowed +// +// description : Execution allowed for DeviceAddress command. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_DeviceAddress_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_DeviceID_allowed +// +// description : Execution allowed for DeviceID command. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_DeviceID_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_DeviceHWver_allowed +// +// description : Execution allowed for DeviceHWver command. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_DeviceHWver_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_DeviceFWver_allowed +// +// description : Execution allowed for DeviceFWver command. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_DeviceFWver_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_DisplayFWver_allowed +// +// description : Execution allowed for DisplayFWver command. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_DisplayFWver_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_DeviceSerial_allowed +// +// description : Execution allowed for DeviceSerial command. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_DeviceSerial_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_EnterServiceCode_allowed +// +// description : Execution allowed for EnterServiceCode command. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_EnterServiceCode_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} +//+---------------------------------------------------------------------------- +// +// method : MenloLFC::is_SaveConfig_allowed +// +// description : Execution allowed for SaveConfig command. +// +//----------------------------------------------------------------------------- +bool MenloLFC::is_SaveConfig_allowed(const CORBA::Any &any) +{ + // End of Generated Code + + // Re-Start of Generated Code + return true; +} + +} // namespace MenloLFC_ns diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1f2f5a1a89d2901a46153211145462e410ef12a3 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,62 @@ +static const char *RcsId = ""; +//+============================================================================= +// +// file : main.cpp +// +// description : C++ source for a TANGO 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 : TANGO Device Server +// +// Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34149 Basovizza, Trieste ITALY +// +//-============================================================================= +// +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +// +// (c) - Software Engineering Group - ESRF +//============================================================================= + +#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); +} diff --git a/src/readthread.cpp b/src/readthread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff417322739307b2b198a9c7b58231eec9f51a6e --- /dev/null +++ b/src/readthread.cpp @@ -0,0 +1,170 @@ +// +// file : readthread.cpp +// +// description : reading thread +// +// project : TANGO Device Server +// +// Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34149 Basovizza, Trieste ITALY +// + +#include "readthread.h" +static const char __FILE__rev[] = __FILE__ " $Revision: 1.2 $"; + +//+------------------------------------------------------------------ +// +// method: readthread::readthread() +// +// description: readthread constructor +// +//------------------------------------------------------------------- +readthread::readthread(MenloLFC_ns::MenloLFC *s):Tango::LogAdapter(s) +{ + DEBUG_STREAM << "readthread::readthread(): constructor... :" << __FILE__rev << endl; + mydevice = s; + //readSched = NULL; + sched_mutex = new omni_mutex(); +} + +//+------------------------------------------------------------------ +// +// method: readthread::~readthread() +// +// description: readthread destructor +// +//------------------------------------------------------------------- +readthread::~readthread() +{ + DEBUG_STREAM << "readthread::~readthread(): destructor... !" << endl; + /*if(readSched) + { + delete readSched; + readSched = NULL; + }*/ + delete sched_mutex; +} + +//+------------------------------------------------------------------ +// +// method: readthread::run() +// +// description: Run +// +//------------------------------------------------------------------- +void readthread::run(void *) +{ + INFO_STREAM << "readthread::run(): running... !" << endl; + int pausesec,pausenano,pausesec_dfl,pausenano_dfl, + cnt_err = 0, + max_cnt_err = 3, + ret; + + string reg; + update_scheduler(); + INFO_STREAM << "readthread::run(): after update_scheduler" << endl; + + pausesec = pausesec_dfl = (int)(mydevice->th_sleep/1000); + pausenano = pausenano_dfl = (int)(mydevice->th_sleep-pausesec*1000)*1000000; + + data_map::iterator it;// = mydevice->read_data.begin(); + //data_map::iterator it = mydevice->read_data.begin(); + + while (!mydevice->abortflag) + { + //mydevice->mutex->lock(); + sched_mutex->lock(); + //reg = readSched->next(); + reg = readSched.next(); + sched_mutex->unlock(); + it = mydevice->read_data.find(reg); + /*reg = it->first*/ + ret = mydevice->WriteRead(PROTO_CMD_READ, reg, -1, it->second); + //mydevice->mutex->unlock(); + + /*it++; + if(it == mydevice->read_data.end()) + it = mydevice->read_data.begin();*/ + if (ret < 0) + cnt_err++; + else + cnt_err = 0; + if (cnt_err > max_cnt_err) { + pausesec = 5; + pausenano = 0; + } + else { + pausesec = pausesec_dfl; + pausenano = pausenano_dfl; + } + //omni_thread::sleep(pausesec,pausenano); + abort_sleep(mydevice->th_sleep/1000); + } + INFO_STREAM << "readthread::run(): exit!!!" << endl; +} + +//+------------------------------------------------------------------ +// +// method: readthread::update_scheduler() +// +// description: update scheduler after new sensor has been detected +// +//------------------------------------------------------------------- +void readthread::update_scheduler() +{ + INFO_STREAM << "readthread::update_scheduler(): entering..." << endl; + scheduler<string>::sched_t hi, low; + sched_mutex->lock(); + /*if(readSched) + { + delete readSched; + readSched = NULL; + }*/ + for(data_map::iterator it2 = mydevice->read_data.begin(); it2 != mydevice->read_data.end(); it2++) + { + if(it2->second.pri == Hi_pri) + hi.push_back(it2->first); + else if(it2->second.pri == Low_pri) + low.push_back(it2->first); + } + //readSched = new scheduler<string>(hi, low, PRIORITY_FACTOR); + readSched.update(hi, low, PRIORITY_FACTOR); + sched_mutex->unlock(); +} + +//+------------------------------------------------------------------ +// +// method: readthread::force_scheduler() +// +// description: force scheduler to execute id as the first between +// that with its priority +// +//------------------------------------------------------------------- +void readthread::force_scheduler(string id) +{ + sched_mutex->lock(); + //readSched->force(id); + readSched.force(id); + sched_mutex->unlock(); +} + +//+------------------------------------------------------------------ +// +// method: readthread::abort_sleep +// +// description: Resume from sleep if abort_flag set (sec.) +// +//------------------------------------------------------------------- +void readthread::abort_sleep(double time) +{ + +/* for (int i = 0; i < (time/0.1); i++) { + if (mydevice->abortflag) + break; + omni_thread::sleep(0,100000000); + }*/ + usleep(long(time*1000000)); + +} + diff --git a/src/readthread.h b/src/readthread.h new file mode 100644 index 0000000000000000000000000000000000000000..d18ca7f5f039163a9ebc6932d67762ebf156de1c --- /dev/null +++ b/src/readthread.h @@ -0,0 +1,47 @@ +// +// file : readthread.h +// +// description : reading thread +// +// project : TANGO Device Server +// +// Elettra-Sincrotrone Trieste S.C.p.A. di interesse nazionale +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34149 Basovizza, Trieste ITALY +// + + +#ifndef READTHREAD_H +#define READTHREAD_H + +#include <omnithread.h> +#include <tango.h> +#include <MenloLFC.h> +#include "scheduler.h" + +class readthread : public omni_thread, public Tango::LogAdapter +{ + private: + MenloLFC_ns::MenloLFC *mydevice; + //scheduler<string> *readSched; + scheduler<string> readSched; + omni_mutex *sched_mutex; + void abort_sleep(double time); + + public: + + readthread(MenloLFC_ns::MenloLFC *s); + ~readthread(); + void force_scheduler(string id); + void update_scheduler(); + + protected: + void run(void *); + +}; /* end class readthread() */ + + + +#endif + +/* EOF */