Commit cf27dd1f authored by Alessio Igor Bogani's avatar Alessio Igor Bogani
Browse files

Complete revision of the server

parent 1a359f4b
......@@ -7,4 +7,4 @@ LDFLAGS =
include ../makefiles/Make-9.3.3.in
test: bin/${NAME_SRV}
LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(SDKTARGETSYSROOT)/usr/lib $(LOADER) bin/${NAME_SRV} test -v4
LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(SDKTARGETSYSROOT)/usr/lib $(SDKTARGETSYSROOT)/usr/lib/ld-linux-x86-64.so.2 bin/${NAME_SRV} test -v4
Subproject commit 19a15caa600f79cc66a1a75369252734a3025e52
Subproject commit 2f9df3b698a4524c252c6c09232c8bde79daa606
Subproject commit bbebd3e523a530a607ab8afa109613c95d1ff596
Subproject commit 67275450e778cfafc02dee7744db90fe6540b86e
Subproject commit 10769ee9428a5b12a8015ff804efac6ad4352b85
Subproject commit accf00d9014fb425b32ed46a59f4358dc3eaa36e
Subproject commit 5fa2980f5656473d6329be8b05212252bc00b833
Subproject commit ed75bef6f9cb2d4761916ec41873b96cf2af95d3
This diff is collapsed.
......@@ -53,33 +53,28 @@ namespace Agilent4uhv_ns
/*----- PROTECTED REGION ID(Agilent4uhv::Additional Class Declarations) ENABLED START -----*/
// Additional Class Declarations
class Worker;
struct Data {
string model;
string serial_number;
Tango::DevFloat temperature_fan;
int hvch[4];
Tango::DevLong device_number[4];
Tango::DevUShort power_max[4];
Tango::DevUShort vtarget[4];
Tango::DevUShort iprotect[4];
Tango::DevDouble setpoint[4];
Tango::DevFloat temperaturehv[4];
Tango::DevDouble vmeasured[4];
Tango::DevDouble imeasured[4];
Tango::DevDouble pressure[4];
vector<unsigned char> autostart;
vector<unsigned char> protect;
vector<unsigned char> fs;
vector<unsigned char> ssp;
vector<unsigned char> is;
vector<unsigned char> ec;
Tango::DevState state;
string status;
#define MAX_WINDOWS 2100 /* Necessary fot the 206 + channel trick */
enum windowType { READ_WINDOW = 0x30, WRITE_WINDOW = 0x31 };
class Cache {
omni_mutex mutex[MAX_WINDOWS];
vector<unsigned char> data[MAX_WINDOWS];
Cache(const Cache &source);
public:
Cache() {}
void get(const int index, vector<unsigned char> &v) {
assert(index > 0 && index < MAX_WINDOWS);
omni_mutex_lock guard(mutex[index]);
v = data[index];
}
void set(const int index, const vector<unsigned char> &v) {
assert(index > 0 && index < MAX_WINDOWS);
omni_mutex_lock guard(mutex[index]);
data[index] = v;
}
};
class Agilent4uhvWorker;
/*----- PROTECTED REGION END -----*/ // Agilent4uhv::Additional Class Declarations
class Agilent4uhv : public Serial2Client_ns::Serial2Client
......@@ -88,21 +83,22 @@ class Agilent4uhv : public Serial2Client_ns::Serial2Client
/*----- PROTECTED REGION ID(Agilent4uhv::Data Members) ENABLED START -----*/
// Add your own data members
Tango::DevUShort nchannel;
vector<string> channels;
string init_error;
bool odd_channel_quirk;
public:
omni_mutex iomutex;
public:
Worker *worker;
Data data;
omni_mutex data_mutex;
Agilent4uhvWorker *worker;
vector<int> polled_windows;
Cache cache;
/*----- PROTECTED REGION END -----*/ // Agilent4uhv::Data Members
// Device property data members
public:
// PollingSleep: Sleep between hardware requests made by internal thread
Tango::DevLong pollingSleep;
bool mandatoryNotDefined;
......@@ -110,7 +106,7 @@ public:
public:
Tango::DevString *attr_Model_read;
Tango::DevString *attr_SerialNumber_read;
Tango::DevFloat *attr_Temperature_read;
Tango::DevDouble *attr_TemperatureFan_read;
// Constructors and destructors
public:
......@@ -152,6 +148,10 @@ public:
* Initialize the device
*/
virtual void init_device();
/*
* Read the device properties from database
*/
void get_device_property();
/*
* Always executed method before execution command method.
*/
......@@ -191,14 +191,14 @@ public:
virtual void read_SerialNumber(Tango::Attribute &attr);
virtual bool is_SerialNumber_allowed(Tango::AttReqType type);
/**
* Attribute Temperature related methods
* Attribute TemperatureFan related methods
* Description:
*
* Data type: Tango::DevFloat
* Data type: Tango::DevDouble
* Attr type: Scalar
*/
virtual void read_Temperature(Tango::Attribute &attr);
virtual bool is_Temperature_allowed(Tango::AttReqType type);
virtual void read_TemperatureFan(Tango::Attribute &attr);
virtual bool is_TemperatureFan_allowed(Tango::AttReqType type);
// Dynamic attribute methods
public:
......@@ -236,7 +236,7 @@ public:
* Attribute PowerMaxX related methods
* Description:
*
* Data type: Tango::DevUShort
* Data type: Tango::DevLong
* Attr type: Scalar
*/
virtual void read_PowerMaxX(Tango::Attribute &attr);
......@@ -244,14 +244,14 @@ public:
virtual bool is_PowerMaxX_allowed(Tango::AttReqType type);
void add_PowerMaxX_dynamic_attribute(string attname);
void remove_PowerMaxX_dynamic_attribute(string attname);
Tango::DevUShort *get_PowerMaxX_data_ptr(string &name);
map<string,Tango::DevUShort> PowerMaxX_data;
Tango::DevLong *get_PowerMaxX_data_ptr(string &name);
map<string,Tango::DevLong> PowerMaxX_data;
/**
* Attribute VTargetX related methods
* Description:
*
* Data type: Tango::DevUShort
* Data type: Tango::DevLong
* Attr type: Scalar
*/
virtual void read_VTargetX(Tango::Attribute &attr);
......@@ -259,14 +259,14 @@ public:
virtual bool is_VTargetX_allowed(Tango::AttReqType type);
void add_VTargetX_dynamic_attribute(string attname);
void remove_VTargetX_dynamic_attribute(string attname);
Tango::DevUShort *get_VTargetX_data_ptr(string &name);
map<string,Tango::DevUShort> VTargetX_data;
Tango::DevLong *get_VTargetX_data_ptr(string &name);
map<string,Tango::DevLong> VTargetX_data;
/**
* Attribute IProtectX related methods
* Description:
*
* Data type: Tango::DevUShort
* Data type: Tango::DevLong
* Attr type: Scalar
*/
virtual void read_IProtectX(Tango::Attribute &attr);
......@@ -274,8 +274,8 @@ public:
virtual bool is_IProtectX_allowed(Tango::AttReqType type);
void add_IProtectX_dynamic_attribute(string attname);
void remove_IProtectX_dynamic_attribute(string attname);
Tango::DevUShort *get_IProtectX_data_ptr(string &name);
map<string,Tango::DevUShort> IProtectX_data;
Tango::DevLong *get_IProtectX_data_ptr(string &name);
map<string,Tango::DevLong> IProtectX_data;
/**
* Attribute SetPointX related methods
......@@ -296,15 +296,15 @@ public:
* Attribute TemperatureHVX related methods
* Description:
*
* Data type: Tango::DevFloat
* Data type: Tango::DevDouble
* Attr type: Scalar
*/
virtual void read_TemperatureHVX(Tango::Attribute &attr);
virtual bool is_TemperatureHVX_allowed(Tango::AttReqType type);
void add_TemperatureHVX_dynamic_attribute(string attname);
void remove_TemperatureHVX_dynamic_attribute(string attname);
Tango::DevFloat *get_TemperatureHVX_data_ptr(string &name);
map<string,Tango::DevFloat> TemperatureHVX_data;
Tango::DevDouble *get_TemperatureHVX_data_ptr(string &name);
map<string,Tango::DevDouble> TemperatureHVX_data;
/**
* Attribute VoltageX related methods
......@@ -475,64 +475,28 @@ public:
// Command related methods
public:
// Dynamic commands methods
public:
/**
* Command OffHV1 related method
* Description:
*
*/
virtual void off_hv1();
virtual bool is_OffHV1_allowed(const CORBA::Any &any);
/**
* Command OffHV2 related method
* Description:
*
*/
virtual void off_hv2();
virtual bool is_OffHV2_allowed(const CORBA::Any &any);
/**
* Command OnHV1 related method
* Description:
*
*/
virtual void on_hv1();
virtual bool is_OnHV1_allowed(const CORBA::Any &any);
/**
* Command OnHV2 related method
* Description:
*
*/
virtual void on_hv2();
virtual bool is_OnHV2_allowed(const CORBA::Any &any);
/**
* Command OffHV3 related method
* Description:
*
*/
virtual void off_hv3();
virtual bool is_OffHV3_allowed(const CORBA::Any &any);
/**
* Command OffHV4 related method
* Description:
*
*/
virtual void off_hv4();
virtual bool is_OffHV4_allowed(const CORBA::Any &any);
/**
* Command OnHV3 related method
* Command OffHVX related method
* Description:
*
*/
virtual void on_hv3();
virtual bool is_OnHV3_allowed(const CORBA::Any &any);
virtual void off_hvx(Tango::Command &command);
virtual bool is_OffHVX_allowed(const CORBA::Any &any);
void add_OffHVX_dynamic_command(string cmdname, bool device);
void remove_OffHVX_dynamic_command(string cmdname);
/**
* Command OnHV4 related method
* Command OnHVX related method
* Description:
*
*/
virtual void on_hv4();
virtual bool is_OnHV4_allowed(const CORBA::Any &any);
virtual void on_hvx(Tango::Command &command);
virtual bool is_OnHVX_allowed(const CORBA::Any &any);
void add_OnHVX_dynamic_command(string cmdname, bool device);
void remove_OnHVX_dynamic_command(string cmdname);
//--------------------------------------------------------
/**
......@@ -545,57 +509,39 @@ public:
/*----- PROTECTED REGION ID(Agilent4uhv::Additional Method prototypes) ENABLED START -----*/
// Additional Method prototypes
void write(const int win, string &value);
template<typename T> void write(const int win, T &value)
{
string data;
convert(value, data);
write(win, data);
}
void read(const int win, string &value);
template<typename T> void read(const int win, T &value)
{
string answer;
read(win, answer);
convert(answer, value);
}
void write(const int win, vector<unsigned char> &data);
void read(const int win, vector<unsigned char> &answer);
void check_ack();
void write_message(const string win_s, const unsigned char com, vector<unsigned char> &data);
void read_answer(const string win_s, const unsigned char com, vector<unsigned char> &answer);
unsigned char calc_crc(const vector<unsigned char> &message);
template<typename F, typename T> void convert(const F &reply, T &reply_converted)
{
stringstream conv;
convert(reply, conv);
conv >> reply_converted;
if (conv.fail())
Tango::Except::throw_exception(
"API_ConverionError",
"Conversion fail " + conv.str(),
"Agilent4uhv::convert()");
}
template<typename F> void convert(const F &reply, stringstream &conv)
{
conv << reply << flush;
if (conv.fail())
Tango::Except::throw_exception(
"API_ConverionError",
"Conversion fail " + conv.str(),
"Agilent4uhv::convert()");
}
template<typename F> void convert(const F &reply, string &reply_converted)
{
stringstream conv;
convert(reply, conv);
reply_converted = conv.str();
}
void check_init_error(void);
void check_init();
void init_header(const int win, const windowType type,
vector<unsigned char> &header);
int calc_crc(const vector<unsigned char> &header,
const vector<unsigned char> &payload);
void check_crc(const vector<unsigned char> &header,
const vector<unsigned char> &payload,
const vector<unsigned char> &footer);
void init_footer(const int computed_crc, vector<unsigned char> &footer);
void send_message(const int win, const windowType type,
const vector<unsigned char> &payload);
void receive_message(vector<unsigned char> &payload);
void _send_receive_message(const int win, const windowType type,
const vector<unsigned char> &answer, vector<unsigned char> &reply);
void send_receive_message(const int win, const windowType type,
const vector<unsigned char> &answer, vector<unsigned char> &reply);
void decode(const vector<unsigned char> &payload, bool &data);
void decode(const vector<unsigned char> &payload, int &data);
void decode(const vector<unsigned char> &payload, double &data);
void decode(const vector<unsigned char> &payload, string &data);
void encode(const bool &data, vector<unsigned char> &payload);
void encode(const int &data, vector<unsigned char> &payload);
void encode(const double &data, vector<unsigned char> &payload);
void encode(const string &data, vector<unsigned char> &payload);
template<typename T> void read_window(const int win, T &data);
template<typename T> void _write_window(const int win, const T &data);
template<typename T> void write_window(const int win, const T &data);
template<typename T> void read_window_from_cache(const int win, T &data);
void _read_window_into_cache(const int win);
void read_window_into_cache(const int win);
void check_state();
/*----- PROTECTED REGION END -----*/ // Agilent4uhv::Additional Method prototypes
};
......@@ -603,39 +549,25 @@ public:
/*----- PROTECTED REGION ID(Agilent4uhv::Additional Classes Definitions) ENABLED START -----*/
// Additional Classes Definitions
class Worker : public omni_thread, public Tango::LogAdapter
class Agilent4uhvWorker : public omni_thread, public Tango::LogAdapter
{
Agilent4uhv *device;
void* run_undetached(void*);
bool cont;
volatile bool cont;
public:
void start(void) {
public:
Agilent4uhvWorker(Agilent4uhv *device_) :
LogAdapter((Tango::DeviceImpl*)device_),
device(device_), cont(false) {}
void start() {
cont = true;
start_undetached();
}
void stop(void) {
void stop() {
cont = false;
}
void wait(unsigned int millisecs)
{
while(cont && millisecs) {
if (millisecs >= 250) {
omni_thread::self()->sleep(0, 250000000);
millisecs -= 250;
} else {
omni_thread::self()->sleep(0, millisecs * 1000000);
millisecs = 0;
}
}
}
Worker(Agilent4uhv *device_) :
LogAdapter((Tango::DeviceImpl*)device_),
device(device_) {
cont = true;
}
};
......
This diff is collapsed.
/*----- PROTECTED REGION ID(Agilent4uhvClass.cpp) ENABLED START -----*/
static const char *RcsId = "$Id: Agilent4uhvClass.cpp,v 1.3 2016-05-23 07:50:11 alessio Exp $";
static const char *TagName = "Agilent4uhv $Name: release_06 $";
static const char *CvsPath = "$Source: /home/cvsadm/cvsroot/fermi/servers/4uhv/src/Agilent4uhvClass.cpp,v $";
static const char *SvnPath = "$HeadURL: $";
......@@ -160,7 +159,7 @@ Agilent4uhvClass *Agilent4uhvClass::instance()
//===================================================================
//--------------------------------------------------------
/**
* method : OffHV1Class::execute()
* method : OffHVXClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
......@@ -169,16 +168,16 @@ Agilent4uhvClass *Agilent4uhvClass::instance()
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *OffHV1Class::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
CORBA::Any *OffHVXClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "OffHV1Class::execute(): arrived" << endl;
((static_cast<Agilent4uhv *>(device))->off_hv1());
cout2 << "OffHVXClass::execute(): arrived" << endl;
((static_cast<Agilent4uhv *>(device))->off_hvx(*this));
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : OffHV2Class::execute()
* method : OnHVXClass::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
......@@ -187,118 +186,10 @@ CORBA::Any *OffHV1Class::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const C
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *OffHV2Class::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
CORBA::Any *OnHVXClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "OffHV2Class::execute(): arrived" << endl;
((static_cast<Agilent4uhv *>(device))->off_hv2());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : OnHV1Class::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *OnHV1Class::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "OnHV1Class::execute(): arrived" << endl;
((static_cast<Agilent4uhv *>(device))->on_hv1());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : OnHV2Class::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *OnHV2Class::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "OnHV2Class::execute(): arrived" << endl;
((static_cast<Agilent4uhv *>(device))->on_hv2());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : OffHV3Class::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *OffHV3Class::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "OffHV3Class::execute(): arrived" << endl;
((static_cast<Agilent4uhv *>(device))->off_hv3());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : OffHV4Class::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *OffHV4Class::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "OffHV4Class::execute(): arrived" << endl;
((static_cast<Agilent4uhv *>(device))->off_hv4());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : OnHV3Class::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *OnHV3Class::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "OnHV3Class::execute(): arrived" << endl;
((static_cast<Agilent4uhv *>(device))->on_hv3());
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : OnHV4Class::execute()
* description : method to trigger the execution of the command.
*
* @param device The device on which the command must be executed
* @param in_any The command input data
*
* returns The command output data (packed in the Any object)
*/
//--------------------------------------------------------
CORBA::Any *OnHV4Class::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "OnHV4Class::execute(): arrived" << endl;
((static_cast<Agilent4uhv *>(device))->on_hv4());
cout2 << "OnHVXClass::execute(): arrived" << endl;
((static_cast<Agilent4uhv *>(device))->on_hvx(*this));
return new CORBA::Any();
}
......@@ -371,6 +262,20 @@ void Agilent4uhvClass::set_default_property()
// Set Default Class Properties
// Set Default device Properties
prop_name = "PollingSleep";
prop_desc = "Sleep between hardware requests made by internal thread (max value is 1000000)";
prop_def = "0";
vect_data.clear();
vect_data.push_back("0");
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);
}
//--------------------------------------------------------
......@@ -547,6 +452,7 @@ void Agilent4uhvClass::device_factory(const Tango::DevVarStringArray *devlist_pt
// Add dynamic attributes if any
Agilent4uhv *dev = static_cast<Agilent4uhv *>(device_list[device_list.size()-i]);
dev->add_dynamic_attributes();
dev->add_dynamic_commands();
// Check before if database used.