Commit 6a35db6f authored by Yuelong Yu's avatar Yuelong Yu
Browse files

code refactoring

parent fc56baf5
......@@ -68,28 +68,31 @@ static const char *RcsId = "$Id: $";
// StartVaccumAndAnalogCards | start_vaccum_and_analog_cards
// StartModuleFPGA | start_module_fpga
// StartASICs | start_asics
// StartAutomaticPowerUp | start_automatic_power_up
//================================================================
//================================================================
// Attributes managed are:
//================================================================
// Temperature1 | Tango::DevString Scalar
// Temperature2 | Tango::DevString Scalar
// Temperature3 | Tango::DevString Scalar
// Temperature4 | Tango::DevString Scalar
// Temperature5 | Tango::DevString Scalar
// Temperature6 | Tango::DevString Scalar
// Temperature7 | Tango::DevString Scalar
// Temperature8 | Tango::DevString Scalar
// RawMatrix | Tango::DevShort Spectrum ( max = 6000)
// LTCC1 | Tango::DevDouble Spectrum ( max = 200)
// LTCC2 | Tango::DevDouble Spectrum ( max = 200)
// LTCC3 | Tango::DevDouble Spectrum ( max = 200)
// LTCC4 | Tango::DevDouble Spectrum ( max = 200)
// LTCC5 | Tango::DevDouble Spectrum ( max = 200)
// LTCC6 | Tango::DevDouble Spectrum ( max = 200)
// LTCC7 | Tango::DevDouble Spectrum ( max = 200)
// LTCC8 | Tango::DevDouble Spectrum ( max = 200)
// Temperature1 | Tango::DevString Scalar
// Temperature2 | Tango::DevString Scalar
// Temperature3 | Tango::DevString Scalar
// Temperature4 | Tango::DevString Scalar
// Temperature5 | Tango::DevString Scalar
// Temperature6 | Tango::DevString Scalar
// Temperature7 | Tango::DevString Scalar
// Temperature8 | Tango::DevString Scalar
// OPMODE | Tango::DevUShort Scalar
// AutomaticMode | Tango::DevUShort Scalar
// RawMatrix | Tango::DevShort Spectrum ( max = 6000)
// LTCC1 | Tango::DevDouble Spectrum ( max = 200)
// LTCC2 | Tango::DevDouble Spectrum ( max = 200)
// LTCC3 | Tango::DevDouble Spectrum ( max = 200)
// LTCC4 | Tango::DevDouble Spectrum ( max = 200)
// LTCC5 | Tango::DevDouble Spectrum ( max = 200)
// LTCC6 | Tango::DevDouble Spectrum ( max = 200)
// LTCC7 | Tango::DevDouble Spectrum ( max = 200)
// LTCC8 | Tango::DevDouble Spectrum ( max = 200)
//================================================================
namespace AGIPDMC_ns
......@@ -166,6 +169,8 @@ void AGIPDMC::delete_device()
delete[] attr_Temperature6_read;
delete[] attr_Temperature7_read;
delete[] attr_Temperature8_read;
delete[] attr_OPMODE_read;
delete[] attr_AutomaticMode_read;
delete[] attr_RawMatrix_read;
delete[] attr_LTCC1_read;
delete[] attr_LTCC2_read;
......@@ -207,6 +212,8 @@ void AGIPDMC::init_device()
attr_Temperature6_read = new Tango::DevString[1];
attr_Temperature7_read = new Tango::DevString[1];
attr_Temperature8_read = new Tango::DevString[1];
attr_OPMODE_read = new Tango::DevUShort[1];
attr_AutomaticMode_read = new Tango::DevUShort[1];
attr_RawMatrix_read = new Tango::DevShort[6000];
attr_LTCC1_read = new Tango::DevDouble[200];
attr_LTCC2_read = new Tango::DevDouble[200];
......@@ -236,8 +243,8 @@ void AGIPDMC::init_device()
m_nDataLength = 6000;
m_nMaxHistoryTemperatureSize = 200;
m_vlLTCCTemperatures.resize(8);
m_nOpMode = -1;
m_bAutomatic = false;
m_bSysExit = false;
......@@ -262,8 +269,11 @@ void AGIPDMC::init_device()
exit(0);
}
*attr_OPMODE_read = ReadAttr<Tango::DevShort>("OPMODE");
*attr_AutomaticMode_read = ReadAttr<Tango::DevShort>("AUTOMATIC");
m_thData = new UpdateDataThread(this,m_sptrDP.get(),m_mtxData);
//cout<<"start updating data..."<<endl;
cout<<"Microcontroller starts..."<<endl;
......@@ -513,6 +523,42 @@ void AGIPDMC::read_Temperature8(Tango::Attribute &attr)
/*----- PROTECTED REGION END -----*/ // AGIPDMC::read_Temperature8
}
//--------------------------------------------------------
/**
* Read attribute OPMODE related method
* Description:
*
* Data type: Tango::DevUShort
* Attr type: Scalar
*/
//--------------------------------------------------------
void AGIPDMC::read_OPMODE(Tango::Attribute &attr)
{
DEBUG_STREAM << "AGIPDMC::read_OPMODE(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(AGIPDMC::read_OPMODE) ENABLED START -----*/
// Set the attribute value
attr.set_value(attr_OPMODE_read);
/*----- PROTECTED REGION END -----*/ // AGIPDMC::read_OPMODE
}
//--------------------------------------------------------
/**
* Read attribute AutomaticMode related method
* Description:
*
* Data type: Tango::DevUShort
* Attr type: Scalar
*/
//--------------------------------------------------------
void AGIPDMC::read_AutomaticMode(Tango::Attribute &attr)
{
DEBUG_STREAM << "AGIPDMC::read_AutomaticMode(Tango::Attribute &attr) entering... " << endl;
/*----- PROTECTED REGION ID(AGIPDMC::read_AutomaticMode) ENABLED START -----*/
// Set the attribute value
attr.set_value(attr_AutomaticMode_read);
/*----- PROTECTED REGION END -----*/ // AGIPDMC::read_AutomaticMode
}
//--------------------------------------------------------
/**
* Read attribute RawMatrix related method
* Description:
......@@ -817,6 +863,38 @@ void AGIPDMC::start_asics()
RunCycle(6);
/*----- PROTECTED REGION END -----*/ // AGIPDMC::start_asics
}
//--------------------------------------------------------
/**
* Command StartAutomaticPowerUp related method
* Description:
*
*/
//--------------------------------------------------------
void AGIPDMC::start_automatic_power_up()
{
DEBUG_STREAM << "AGIPDMC::StartAutomaticPowerUp() - " << device_name << endl;
/*----- PROTECTED REGION ID(AGIPDMC::start_automatic_power_up) ENABLED START -----*/
// Add your own code
if(*attr_OPMODE_read != 0)
Tango::Except::throw_exception((const char *)""
,"The power up is already running or finished."
,(const char *)"");
else
{
if(WriteAttr<Tango::DevShort>("AUTOMATIC",1))
{
m_bAutomatic = true;
*attr_AutomaticMode_read = 1;
}
}
/*----- PROTECTED REGION END -----*/ // AGIPDMC::start_automatic_power_up
}
/*----- PROTECTED REGION ID(AGIPDMC::namespace_ending) ENABLED START -----*/
void AGIPDMC::SetState(Tango::DevState dState)
{
set_state(dState);
......@@ -853,9 +931,32 @@ void AGIPDMC::start_asics()
}
}
template<typename T>
T AGIPDMC::ReadAttr(string strAttr)
{
try
{
Tango::DeviceAttribute objAttr = m_sptrDP->read_attribute(strAttr);
T tVal;
(objAttr)>>tVal;
return tVal;
}
catch(Tango::DevFailed& df)
{
cout<<"Tango::DevFailed exception during reading attribute"<<endl;
for(int err=0; err<df.errors.length(); err++)
{
cout<<"Error: " << df.errors[err].desc.in() <<endl;
}
}
catch(exception& e)
{
cout<<"read:"<<strAttr<<" error!!!"<<e.what()<<endl;
}
}
bool AGIPDMC::RunCommand(string strCmd)
{
try
{
m_sptrDP->command_inout(strCmd);
......@@ -881,7 +982,7 @@ void AGIPDMC::start_asics()
{
SetState(Tango::MOVING);
bool bTrue = WriteAttr<Tango::DevShort>("OpMode",nMode);
bool bTrue = WriteAttr<Tango::DevShort>("OPMODE",nMode);
//aux and analog voltage
if(nMode == 3)
......@@ -892,12 +993,12 @@ void AGIPDMC::start_asics()
// automatic is not 0, then Execute command is necessary to update the matrix.
// otherwise, matrix will not be updated.
// automatic is 1 then it is not.
bTrue = bTrue && RunCommand("Execute");
bTrue = bTrue && RunCommand("EXECUTE");
if(bTrue)
{
omni_mutex_lock l(m_mtxData);
m_nOpMode = nMode;
*attr_OPMODE_read = nMode;
}
else
{
......@@ -905,7 +1006,6 @@ void AGIPDMC::start_asics()
SetState(Tango::ON);
}
}
/*----- PROTECTED REGION ID(AGIPDMC::namespace_ending) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // AGIPDMC::namespace_ending
} // namespace
......@@ -73,11 +73,10 @@ class AGIPDMC : public TANGO_BASE_CLASS
omni_mutex m_mtxData;
public:
bool m_bSysExit;
bool m_bSysExit,m_bAutomatic;
int m_nDataLength;
int m_nMaxHistoryTemperatureSize;
vector<list<double>> m_vlLTCCTemperatures;
int m_nOpMode;
/*----- PROTECTED REGION END -----*/ // AGIPDMC::Data Members
......@@ -98,6 +97,8 @@ public:
Tango::DevString *attr_Temperature6_read;
Tango::DevString *attr_Temperature7_read;
Tango::DevString *attr_Temperature8_read;
Tango::DevUShort *attr_OPMODE_read;
Tango::DevUShort *attr_AutomaticMode_read;
Tango::DevShort *attr_RawMatrix_read;
Tango::DevDouble *attr_LTCC1_read;
Tango::DevDouble *attr_LTCC2_read;
......@@ -240,6 +241,24 @@ public:
*/
virtual void read_Temperature8(Tango::Attribute &attr);
virtual bool is_Temperature8_allowed(Tango::AttReqType type);
/**
* Attribute OPMODE related methods
* Description:
*
* Data type: Tango::DevUShort
* Attr type: Scalar
*/
virtual void read_OPMODE(Tango::Attribute &attr);
virtual bool is_OPMODE_allowed(Tango::AttReqType type);
/**
* Attribute AutomaticMode related methods
* Description:
*
* Data type: Tango::DevUShort
* Attr type: Scalar
*/
virtual void read_AutomaticMode(Tango::Attribute &attr);
virtual bool is_AutomaticMode_allowed(Tango::AttReqType type);
/**
* Attribute RawMatrix related methods
* Description:
......@@ -377,6 +396,13 @@ public:
*/
virtual void start_asics();
virtual bool is_StartASICs_allowed(const CORBA::Any &any);
/**
* Command StartAutomaticPowerUp related method
* Description:
*
*/
virtual void start_automatic_power_up();
virtual bool is_StartAutomaticPowerUp_allowed(const CORBA::Any &any);
/*----- PROTECTED REGION ID(AGIPDMC::Additional Method prototypes) ENABLED START -----*/
......@@ -387,12 +413,10 @@ public:
void SetStatus(string strMsg);
template<typename T>
bool WriteAttr(string strAttr, T tVal);
template<typename T>
T ReadAttr(string strAttr);
bool RunCommand(string strCmd);
void RunCycle(int nMode);
/*----- PROTECTED REGION END -----*/ // AGIPDMC::Additional Method prototypes
};
......
......@@ -85,6 +85,15 @@
</argout>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</commands>
<commands name="StartAutomaticPowerUp" description="" execMethod="start_automatic_power_up" displayLevel="OPERATOR" polledPeriod="0">
<argin description="">
<type xsi:type="pogoDsl:VoidType"/>
</argin>
<argout description="">
<type xsi:type="pogoDsl:VoidType"/>
</argout>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</commands>
<attributes name="Temperature1" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:StringType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
......@@ -149,6 +158,22 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="" label="Temperature8" unit="Celsius" standardUnit="Celsius" displayUnit="Celsius" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="OPMODE" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:UShortType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="AutomaticMode" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:UShortType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="RawMatrix" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="6000" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:ShortType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
......
......@@ -266,6 +266,24 @@ CORBA::Any *StartASICsClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(con
return new CORBA::Any();
}
//--------------------------------------------------------
/**
* method : StartAutomaticPowerUpClass::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 *StartAutomaticPowerUpClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any))
{
cout2 << "StartAutomaticPowerUpClass::execute(): arrived" << endl;
((static_cast<AGIPDMC *>(device))->start_automatic_power_up());
return new CORBA::Any();
}
//===================================================================
// Properties management
......@@ -760,6 +778,54 @@ void AGIPDMCClass::attribute_factory(vector<Tango::Attr *> &att_list)
// Not Memorized
att_list.push_back(temperature8);
// Attribute : OPMODE
OPMODEAttrib *opmode = new OPMODEAttrib();
Tango::UserDefaultAttrProp opmode_prop;
// description not set for OPMODE
// label not set for OPMODE
// unit not set for OPMODE
// standard_unit not set for OPMODE
// display_unit not set for OPMODE
// format not set for OPMODE
// max_value not set for OPMODE
// min_value not set for OPMODE
// max_alarm not set for OPMODE
// min_alarm not set for OPMODE
// max_warning not set for OPMODE
// min_warning not set for OPMODE
// delta_t not set for OPMODE
// delta_val not set for OPMODE
opmode->set_default_properties(opmode_prop);
// Not Polled
opmode->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(opmode);
// Attribute : AutomaticMode
AutomaticModeAttrib *automaticmode = new AutomaticModeAttrib();
Tango::UserDefaultAttrProp automaticmode_prop;
// description not set for AutomaticMode
// label not set for AutomaticMode
// unit not set for AutomaticMode
// standard_unit not set for AutomaticMode
// display_unit not set for AutomaticMode
// format not set for AutomaticMode
// max_value not set for AutomaticMode
// min_value not set for AutomaticMode
// max_alarm not set for AutomaticMode
// min_alarm not set for AutomaticMode
// max_warning not set for AutomaticMode
// min_warning not set for AutomaticMode
// delta_t not set for AutomaticMode
// delta_val not set for AutomaticMode
automaticmode->set_default_properties(automaticmode_prop);
// Not Polled
automaticmode->set_disp_level(Tango::OPERATOR);
// Not Memorized
att_list.push_back(automaticmode);
// Attribute : RawMatrix
RawMatrixAttrib *rawmatrix = new RawMatrixAttrib();
Tango::UserDefaultAttrProp rawmatrix_prop;
......@@ -1054,6 +1120,15 @@ void AGIPDMCClass::command_factory()
Tango::OPERATOR);
command_list.push_back(pStartASICsCmd);
// Command StartAutomaticPowerUp
StartAutomaticPowerUpClass *pStartAutomaticPowerUpCmd =
new StartAutomaticPowerUpClass("StartAutomaticPowerUp",
Tango::DEV_VOID, Tango::DEV_VOID,
"",
"",
Tango::OPERATOR);
command_list.push_back(pStartAutomaticPowerUpCmd);
/*----- PROTECTED REGION ID(AGIPDMCClass::command_factory_after) ENABLED START -----*/
// Add your own code
......
......@@ -163,6 +163,32 @@ public:
{return (static_cast<AGIPDMC *>(dev))->is_Temperature8_allowed(ty);}
};
// Attribute OPMODE class definition
class OPMODEAttrib: public Tango::Attr
{
public:
OPMODEAttrib():Attr("OPMODE",
Tango::DEV_USHORT, Tango::READ) {};
~OPMODEAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<AGIPDMC *>(dev))->read_OPMODE(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<AGIPDMC *>(dev))->is_OPMODE_allowed(ty);}
};
// Attribute AutomaticMode class definition
class AutomaticModeAttrib: public Tango::Attr
{
public:
AutomaticModeAttrib():Attr("AutomaticMode",
Tango::DEV_USHORT, Tango::READ) {};
~AutomaticModeAttrib() {};
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{(static_cast<AGIPDMC *>(dev))->read_AutomaticMode(att);}
virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
{return (static_cast<AGIPDMC *>(dev))->is_AutomaticMode_allowed(ty);}
};
// Attribute RawMatrix class definition
class RawMatrixAttrib: public Tango::SpectrumAttr
{
......@@ -422,6 +448,29 @@ public:
{return (static_cast<AGIPDMC *>(dev))->is_StartASICs_allowed(any);}
};
// Command StartAutomaticPowerUp class definition
class StartAutomaticPowerUpClass : public Tango::Command
{
public:
StartAutomaticPowerUpClass(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) {};
StartAutomaticPowerUpClass(const char *name,
Tango::CmdArgType in,
Tango::CmdArgType out)
:Command(name,in,out) {};
~StartAutomaticPowerUpClass() {};
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<AGIPDMC *>(dev))->is_StartAutomaticPowerUp_allowed(any);}
};
/**
* The AGIPDMCClass singleton definition
......
......@@ -181,6 +181,38 @@ bool AGIPDMC::is_Temperature8_allowed(TANGO_UNUSED(Tango::AttReqType type))
return true;
}
//--------------------------------------------------------
/**
* Method : AGIPDMC::is_OPMODE_allowed()
* Description : Execution allowed for OPMODE attribute
*/
//--------------------------------------------------------
bool AGIPDMC::is_OPMODE_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Not any excluded states for OPMODE attribute in read access.
/*----- PROTECTED REGION ID(AGIPDMC::OPMODEStateAllowed_READ) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // AGIPDMC::OPMODEStateAllowed_READ
return true;
}
//--------------------------------------------------------
/**
* Method : AGIPDMC::is_AutomaticMode_allowed()
* Description : Execution allowed for AutomaticMode attribute
*/
//--------------------------------------------------------
bool AGIPDMC::is_AutomaticMode_allowed(TANGO_UNUSED(Tango::AttReqType type))
{
// Not any excluded states for AutomaticMode attribute in read access.
/*----- PROTECTED REGION ID(AGIPDMC::AutomaticModeStateAllowed_READ) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // AGIPDMC::AutomaticModeStateAllowed_READ
return true;
}
//--------------------------------------------------------
/**
* Method : AGIPDMC::is_RawMatrix_allowed()
......@@ -419,4 +451,19 @@ bool AGIPDMC::is_StartASICs_allowed(TANGO_UNUSED(const CORBA::Any &any))
return true;
}
//--------------------------------------------------------
/**
* Method : AGIPDMC::is_StartAutomaticPowerUp_allowed()
* Description : Execution allowed for StartAutomaticPowerUp attribute
*/
//--------------------------------------------------------
bool AGIPDMC::is_StartAutomaticPowerUp_allowed(TANGO_UNUSED(const CORBA::Any &any))
{
// Not any excluded states for StartAutomaticPowerUp command.
/*----- PROTECTED REGION ID(AGIPDMC::StartAutomaticPowerUpStateAllowed) ENABLED START -----*/
/*----- PROTECTED REGION END -----*/ // AGIPDMC::StartAutomaticPowerUpStateAllowed
return true;
}
} // End of namespace
......@@ -72,7 +72,7 @@ namespace AGIPDMC_ns
case 6:
return PowerUpStep6();
default:
return false;
return 1;
}
}
......@@ -226,7 +226,7 @@ namespace AGIPDMC_ns
int MicroController::PowerUpStep4()
{
sleep(5);
sleep(10);
return 0;
}
......@@ -235,8 +235,8 @@ namespace AGIPDMC_ns
//this step should be checked manually.
//there is no feed back from sub modules
///
sleep(5);
return 1;
sleep(10);
return 0;
// sleep(5);
// return 0;
......@@ -245,7 +245,7 @@ namespace AGIPDMC_ns
int MicroController::PowerUpStep6()
{
//TODO : Check digital IO
sleep(5);
sleep(10);
return 0;
}
}
......@@ -37,13 +37,61 @@ namespace AGIPDMC_ns
if(m_objAGIPDMC->m_bSysExit)
break;
ReadOutSpectrum(string("MATRIX"));
DoWork();
}
}
omni_thread::exit();
}
void UpdateDataThread::DoWork()
{
int nMode = *(m_objAGIPDMC->attr_OPMODE_read);
if(!(m_objAGIPDMC->m_bAutomatic))
m_objAGIPDMC->RunCommand("EXECUTE");
if(ReadoutSpectrum("MATRIX"))
{
int nCounter = GetMatrixCounter(m_vMatrixData);
cout<<"counter"<<nCounter<<endl;