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..050e61f20a0a715c2cf8a6fa5d624b51770c98a8 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +NAME_SRV = oceanoptics-srv + +CXXFLAGS = -DRELEASE='""' -I../../lib/libfit2 -I/runtime/include/seabreeze -I../../lib/libseabreeze/include -I../../drv/rnm -I../../drv/rnmshare -L../../lib/libseabreeze/lib -L../../lib/libfit2 -L../../drv/rnm -L../../drv/rnmshare + +LDFLAGS = -lseabreeze -lusb -lfit +HAVE_RNM = 1 +ifeq ($(HAVE_RNM),1) + CXXFLAGS += -DHAVE_RNM + LDFLAGS += -lrnm -lrnmshare +endif + +include ../makefiles/Make-9.3.3.in diff --git a/src/ClassFactory.cpp b/src/ClassFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fdddce7368fd28f4c781a2bce9ce3b4aab9eb7f4 --- /dev/null +++ b/src/ClassFactory.cpp @@ -0,0 +1,50 @@ +/*----- PROTECTED REGION ID(OceanOptics::ClassFactory.cpp) ENABLED START -----*/ +static const char *RcsId = "$Header: /home/cvsadm/cvsroot/fermi/servers/oceanoptics/src/ClassFactory.cpp,v 1.1 2015-03-18 10:38:46 graziano Exp $"; +//+============================================================================= +// +// file : ClassFactory.cpp +// +// description : C++ source for the class_factory method of the DServer +// device class. This method is responsible to create +// all class singletin for a device server. It is called +// at device server startup +// +// project : TANGO Device Server +// +// $Author: graziano $ +// +// $Revision: 1.1 $ +// +// $Log: ClassFactory.cpp,v $ +// Revision 1.1 2015-03-18 10:38:46 graziano +// first commit +// +// +// +// copyleft : European Synchrotron Radiation Facility +// BP 220, Grenoble 38043 +// FRANCE +// +//-============================================================================= +// +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +// +// (c) - Software Engineering Group - ESRF +//============================================================================= + + +#include <tango.h> +#include <OceanOpticsClass.h> + +/** + * Create OceanOpticsClass singleton and store it in DServer object. + */ + +void Tango::DServer::class_factory() +{ + + add_class(OceanOptics_ns::OceanOpticsClass::init("OceanOptics")); + +} +/*----- PROTECTED REGION END -----*/ // OceanOptics::ClassFactory.cpp diff --git a/src/OceanOptics.cpp b/src/OceanOptics.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ac886660cb64680cdff1325fe3e6d85bfa0c2fe --- /dev/null +++ b/src/OceanOptics.cpp @@ -0,0 +1,4399 @@ +/*----- PROTECTED REGION ID(OceanOptics.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: OceanOptics.cpp,v 1.19 2019-04-23 13:32:28 graziano Exp $"; +//============================================================================= +// +// file : OceanOptics.cpp +// +// description : C++ source for the OceanOptics class and its commands. +// The class is derived from Device. It represents the +// CORBA servant object which will be accessed from the +// network. All commands which can be executed on the +// OceanOptics are implemented in this file. +// +// project : SolarLaserSystems S100 +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// $Author: graziano $ +// +// $Revision: 1.19 $ +// $Date: 2019-04-23 13:32:28 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include <tango.h> +#include <OceanOptics.h> +#include <OceanOpticsClass.h> +#include "readthread.h" +#include <arpa/inet.h> +//#include "check_get_rt_buffer.h" +#include "tcheck_get_rt_buffer.hpp" + +/*----- PROTECTED REGION END -----*/ // OceanOptics.cpp + +/** + * OceanOptics class description: + * Tango device server for OceanOptics compact wide-range spectrometer + */ + +//================================================================ +// The following table gives the correspondence +// between command and method names. +// +// Command name | Method name +//================================================================ +// State | Inherited (no method) +// Status | Inherited (no method) +// GetVersion | get_version +// Stop | stop +// StartSingle | start_single +// StartContinuous | start_continuous +// GetLastData | get_last_data +// AcquireNoise | acquire_noise +// SaveReferenceData | save_reference_data +// OpenShutter | open_shutter +// CloseShutter | close_shutter +// GetData | get_data +// GetGaussFitCenter | get_gauss_fit_center +// GetGaussFitWidth | get_gauss_fit_width +// GetFWHMCenter | get_fwhmcenter +// GetFWHMWidth | get_fwhmwidth +// ExportWavelength | export_wavelength +// GetArea | get_area +// GetWave | get_wave +// GetLambda | get_lambda +//================================================================ + +//================================================================ +// Attributes managed are: +//================================================================ +// ExposureTime | Tango::DevDouble Scalar +// IncrSensitivity | Tango::DevBoolean Scalar +// SyncMode | Tango::DevLong Scalar +// NoiseSubtraction | Tango::DevBoolean Scalar +// GaussFitEnable | Tango::DevBoolean Scalar +// FWHMEnable | Tango::DevBoolean Scalar +// GaussFitCenter | Tango::DevDouble Scalar +// GaussFitWidth | Tango::DevDouble Scalar +// FWHMCenter | Tango::DevDouble Scalar +// FWHMWidth | Tango::DevDouble Scalar +// Center | Tango::DevDouble Scalar +// Width | Tango::DevDouble Scalar +// FitType | Tango::DevLong Scalar +// FWHMAvg | Tango::DevLong Scalar +// NoiseLevel | Tango::DevLong Scalar +// DataReferenceFile | Tango::DevString Scalar +// AutoExposure | Tango::DevBoolean Scalar +// LightSourceIntensity | Tango::DevDouble Scalar +// RtMode | Tango::DevBoolean Scalar +// LightSourceEnable | Tango::DevBoolean Scalar +// IntensityCalibrationEnable | Tango::DevBoolean Scalar +// Area | Tango::DevDouble Scalar +// AreaRegion | Tango::DevDouble Scalar +// AreaEnable | Tango::DevBoolean Scalar +// WidhtCorrectionEnable | Tango::DevBoolean Scalar +// NumPixels | Tango::DevLong Spectrum ( max = 2) +// Data | Tango::DevDouble Spectrum ( max = 5000) +// RegionOfInterest | Tango::DevDouble Spectrum ( max = 2) +// AnalysisRegion | Tango::DevDouble Spectrum ( max = 2) +// GaussFit | Tango::DevDouble Spectrum ( max = 4) +// FWHM | Tango::DevDouble Spectrum ( max = 3) +// GaussReference | Tango::DevDouble Spectrum ( max = 4) +// DataReference | Tango::DevDouble Spectrum ( max = 5000) +// IntensityCalibration | Tango::DevDouble Spectrum ( max = 10000) +// NoiseProfile | Tango::DevDouble Spectrum ( max = 5000) +// Wave | Tango::DevDouble Spectrum ( max = 5000) +// Lambda | Tango::DevDouble Spectrum ( max = 5000) +//================================================================ + +namespace OceanOptics_ns +{ +/*----- PROTECTED REGION ID(OceanOptics::namespace_starting) ENABLED START -----*/ + +// static initializations + +/*----- PROTECTED REGION END -----*/ // OceanOptics::namespace_starting + +//-------------------------------------------------------- +/** + * Method : OceanOptics::OceanOptics() + * Description : Constructors for a Tango device + * implementing the classOceanOptics + */ +//-------------------------------------------------------- +OceanOptics::OceanOptics(Tango::DeviceClass *cl, string &s) + : TANGO_BASE_CLASS(cl, s.c_str()) +{ + /*----- PROTECTED REGION ID(OceanOptics::constructor_1) ENABLED START -----*/ + init_device(); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::constructor_1 +} +//-------------------------------------------------------- +OceanOptics::OceanOptics(Tango::DeviceClass *cl, const char *s) + : TANGO_BASE_CLASS(cl, s) +{ + /*----- PROTECTED REGION ID(OceanOptics::constructor_2) ENABLED START -----*/ + init_device(); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::constructor_2 +} +//-------------------------------------------------------- +OceanOptics::OceanOptics(Tango::DeviceClass *cl, const char *s, const char *d) + : TANGO_BASE_CLASS(cl, s, d) +{ + /*----- PROTECTED REGION ID(OceanOptics::constructor_3) ENABLED START -----*/ + init_device(); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::constructor_3 +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::delete_device() + * Description : will be called at device destruction or at init command + */ +//-------------------------------------------------------- +void OceanOptics::delete_device() +{ + DEBUG_STREAM << "OceanOptics::delete_device() " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::delete_device) ENABLED START -----*/ + + // Delete device allocated objects + abortflag = true; + + Tango::DbDatum gr("DefaultGaussRef"); + vector<double> gref; + gref.push_back(attr_GaussReference_read[0]); + gref.push_back(attr_GaussReference_read[1]); + gref.push_back(attr_GaussReference_read[2]); + gref.push_back(attr_GaussReference_read[3]); + gr << gref; + Tango::DbData data; + data.push_back(gr); + Tango::Database *db; + if(host_rw != "") + db = new Tango::Database(host_rw,port_rw); + else + db = new Tango::Database(); + try + { + db->set_timeout_millis(10000); + db->put_device_property(get_name(), data); + } + catch(Tango::DevFailed &e) + { + stringstream o; + o << " Error saving properties='" << e.errors[0].desc << "'"; + WARN_STREAM << __FUNCTION__<< o.str(); + } + delete db; + +/* Tango::DbDatum dsr("DefaultStartRegion"); + dsr << attr_RegionOfInterest_read[0]; + Tango::DbData data2; + data2.push_back(dsr); + get_db_device()->put_property(data2); + + Tango::DbDatum der("DefaultEndRegion"); + der << attr_RegionOfInterest_read[1]; + Tango::DbData data3; + data3.push_back(der); + get_db_device()->put_property(data3);*/ + + usleep(500000); + // Delete device's allocated object + delete attr_ExposureTime_read; + delete attr_IncrSensitivity_read; + delete attr_SyncMode_read; + delete [] attr_NumPixels_read; + delete [] attr_RegionOfInterest_read; + delete [] attr_AnalysisRegion_read; + delete attr_NoiseSubtraction_read; + delete attr_GaussFitEnable_read; + delete attr_AreaEnable_read; + delete attr_FWHMEnable_read; + delete [] attr_GaussFit_read; + delete attr_GaussFitCenter_read; + delete attr_GaussFitWidth_read; + delete [] attr_FWHM_read; + delete attr_FWHMCenter_read; + delete attr_FWHMWidth_read; + delete attr_Center_read; + delete attr_Width_read; + delete [] attr_GaussReference_read; + //delete [] attr_DataReference_read; + //delete [] attr_Data_read; + //delete [] attr_Wave_read; + delete [] x_values; + if(pLiveData_avg) + { + delete [] pLiveData_avg; + pLiveData_avg = NULL; + } + if(pLiveData) + { + pLiveData = NULL; + delete [] pLiveData; + } + if(pNoiseMask_avg) + { + delete [] pNoiseMask_avg; + pNoiseMask_avg = NULL; + } + if(pReferenceData) + { + delete [] pReferenceData; + pReferenceData = NULL; + } + /*if(pMeasData) + { + pMeasData = NULL; + delete [] pMeasData; + }*/ + if(pFrameBuffer) + { + pFrameBuffer = NULL; + delete [] pFrameBuffer; + } + delete m_gaussfit; + delete m_asyngaussfit; + delete m_confiteorfit; + + for(int i=0; i<NUM_BUF; i++) + { + tbuf[i].delete_rt_buffer(); + } + tbuf_array.delete_rt_buffer(); + tbuf_array_w.delete_rt_buffer(); + tbuf_array_l.delete_rt_buffer(); + + disconnect_device(); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::delete_device + delete[] attr_LightSourceIntensity_read; + delete[] attr_RtMode_read; + delete[] attr_LightSourceEnable_read; + delete[] attr_IntensityCalibrationEnable_read; + delete[] attr_Area_read; + delete[] attr_AreaRegion_read; + delete[] attr_WidhtCorrectionEnable_read; + delete[] attr_IntensityCalibration_read; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::init_device() + * Description : will be called at device initialization. + */ +//-------------------------------------------------------- +void OceanOptics::init_device() +{ + DEBUG_STREAM << "OceanOptics::init_device() create device " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::init_device_before) ENABLED START -----*/ + + // Initialization before get_device_property() call + host_rw = ""; + Tango::Database *db = new Tango::Database(); + try + { + Tango::DbData db_data; + db_data.push_back((Tango::DbDatum("Host"))); + db_data.push_back((Tango::DbDatum("Port"))); + db->get_property("Database",db_data); + + db_data[0] >> host_rw; + db_data[1] >> port_rw; + }catch(Tango::DevFailed &e) + { + ERROR_STREAM << __FUNCTION__ << " Error reading Database property='" << e.errors[0].desc << "'"; + } + delete db; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::init_device_before + + + // Get the device properties from database + get_device_property(); + + attr_LightSourceIntensity_read = new Tango::DevDouble[1]; + attr_RtMode_read = new Tango::DevBoolean[1]; + attr_LightSourceEnable_read = new Tango::DevBoolean[1]; + attr_IntensityCalibrationEnable_read = new Tango::DevBoolean[1]; + attr_Area_read = new Tango::DevDouble[1]; + attr_AreaRegion_read = new Tango::DevDouble[1]; + attr_WidhtCorrectionEnable_read = new Tango::DevBoolean[1]; + attr_IntensityCalibration_read = new Tango::DevDouble[10000]; + /*----- PROTECTED REGION ID(OceanOptics::init_device) ENABLED START -----*/ + defaultStartRegion = floor(defaultStartRegion*1000.0)*0.001; + defaultEndRegion = floor(defaultEndRegion*1000.0)*0.001; + for(int i=0; i<10000; i++) + attr_IntensityCalibration_read[i] = 1.0; + *attr_IntensityCalibrationEnable_read = false; + *attr_LightSourceEnable_read = false; + *attr_LightSourceIntensity_read = 0; + // Initialize device + + attr_ExposureTime_read = new Tango::DevDouble(); + attr_IncrSensitivity_read = new Tango::DevBoolean(); + attr_SyncMode_read = new Tango::DevLong(); + attr_NumPixels_read = new Tango::DevLong[2]; + attr_RegionOfInterest_read = new Tango::DevDouble[2]; + attr_AnalysisRegion_read = new Tango::DevDouble[2]; + attr_NoiseSubtraction_read = new Tango::DevBoolean(); + attr_GaussFitEnable_read = new Tango::DevBoolean(); + attr_AreaEnable_read = new Tango::DevBoolean(); + attr_FWHMEnable_read = new Tango::DevBoolean(); + attr_GaussFit_read = new Tango::DevDouble[4]; + attr_GaussFitCenter_read = new Tango::DevDouble(); + attr_GaussFitWidth_read = new Tango::DevDouble(); + attr_FWHM_read = new Tango::DevDouble[3]; + attr_FWHMCenter_read = new Tango::DevDouble(); + attr_FWHMWidth_read = new Tango::DevDouble(); + attr_Center_read = new Tango::DevDouble(); + attr_Width_read = new Tango::DevDouble(); + attr_GaussReference_read = new Tango::DevDouble[4]; + attr_FitType_read = &attr_FitType_write; + attr_FWHMAvg_read = &attr_FWHMAvg_write; + attr_NoiseLevel_read = &attr_NoiseLevel_write; + //attr_DataReference_read = new Tango::DevLong[...]; + attr_AutoExposure_read = &attr_AutoExposure_write; + + //noise_level = *attr_NoiseLevel_read; + attr_DataReference_read = NULL; + attr_Data_read = NULL; + attr_Wave_read = NULL; + *attr_NoiseSubtraction_read = false; + *attr_GaussFitEnable_read = false; + *attr_AreaEnable_read = false; + *attr_FWHMEnable_read = false; + *attr_WidhtCorrectionEnable_read = false; + //data_counter_live = 0; + //data_counter_meas = 0; + FrameBufferIndex = 0; + //pMeasData = NULL; + pLiveData = NULL; + pReferenceData = NULL; + pFrameBuffer = NULL; + + ostringstream tempstr; + tempstr << dataReferenceFile << ends; + strcpy(attr_strchar,tempstr.str().c_str()); + + abortflag = false; + live_mode = false; + init_live_mode = false; + measure_mode = false; + init_measure_mode = false; + acquire_noise_mode = false; + init_acquire_noise_mode = false; + noise_level = 0; + NumPixel = 0; + + y_max_mean = 0; + memset(exposures, 0, sizeof(int)*AUTO_EXPOSURE_MEAN); + exposure_idx = 0; + +// m_gaussfit = new GaussFit(NUM_GAUSS_PARAMETER, gauss_f, gauss_df, gauss_fdf); +// m_gaussfit = new Fit(NUM_GAUSS_PARAMETER, gauss_f, gauss_df, gauss_fdf); + m_gaussfit = new Fit(GAUSS_FIT, GAUSS_FIT_NUM_PARAM, 1); + m_asyngaussfit = new Fit(GAUSS_FIT_ASYMM, GAUSS_FIT_ASYMM_NUM_PARAM, 1); + m_confiteorfit = new Fit(CONFITEOR2_FIT, CONFITEOR_FIT_NUM_PARAM, 1); + loop = new readthread(this); + + x_values = NULL; + pLiveData_avg = NULL; + pNoiseMask_avg = NULL; + pFrameBuffer = NULL; + + for(int i=0; i<NUM_BUF; i++) + { + tbuf[i].init_rt_buffer(BUF_SIZE); + tbuf[i].set_mode(tbuffer::BUF_RT_CIRCULAR); + //set_fill_hole(BUF_RT_FILL_0, buf[i]); + //set_fill_hole(BUF_RT_NO_FILL, buf[i]); + tbuf[i].set_fill_hole(BUF_RT_FILL_1); + } + tbuf_array.init_rt_buffer(BUF_SIZE); + tbuf_array.set_mode(tbuffer::BUF_RT_CIRCULAR); + tbuf_array.set_fill_hole(BUF_RT_FILL_1); + + tbuf_array_w.init_rt_buffer(BUF_SIZE); + tbuf_array_w.set_mode(tbuffer::BUF_RT_CIRCULAR); + tbuf_array_w.set_fill_hole(BUF_RT_FILL_1); + + tbuf_array_l.init_rt_buffer(BUF_SIZE); + tbuf_array_l.set_mode(tbuffer::BUF_RT_CIRCULAR); + tbuf_array_l.set_fill_hole(BUF_RT_FILL_1); + + connect_device(false); + + if(intensityCalibrationFile.length() > 0) + load_intensity_cal_file(intensityCalibrationFile); + + loop->start(); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::init_device +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::get_device_property() + * Description : Read database to initialize property data members. + */ +//-------------------------------------------------------- +void OceanOptics::get_device_property() +{ + /*----- PROTECTED REGION ID(OceanOptics::get_device_property_before) ENABLED START -----*/ + + // Initialize property data members + + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_device_property_before + + + // Read device properties from database. + Tango::DbData dev_prop; + dev_prop.push_back(Tango::DbDatum("DeviceId")); + dev_prop.push_back(Tango::DbDatum("SerialNumber")); + dev_prop.push_back(Tango::DbDatum("NFramesBuffered")); + dev_prop.push_back(Tango::DbDatum("DefaultStartRegion")); + dev_prop.push_back(Tango::DbDatum("DefaultEndRegion")); + dev_prop.push_back(Tango::DbDatum("SleepReading")); + dev_prop.push_back(Tango::DbDatum("DefaultGaussRef")); + dev_prop.push_back(Tango::DbDatum("DataReferenceFile")); + dev_prop.push_back(Tango::DbDatum("PreferFWHM")); + dev_prop.push_back(Tango::DbDatum("AutoExposureRange")); + dev_prop.push_back(Tango::DbDatum("AutoExposureStep")); + dev_prop.push_back(Tango::DbDatum("AutoExposureAmpRange")); + dev_prop.push_back(Tango::DbDatum("IntensityCalibrationFile")); + dev_prop.push_back(Tango::DbDatum("NoiseProfileFile")); + dev_prop.push_back(Tango::DbDatum("WavelengthAttr")); + dev_prop.push_back(Tango::DbDatum("AreaInAnalysisRegion")); + dev_prop.push_back(Tango::DbDatum("WidthCorrection")); + + // is there at least one property to be read ? + if (dev_prop.size()>0) + { + // Call database and extract values + if (Tango::Util::instance()->_UseDb==true) + get_db_device()->get_property(dev_prop); + + // get instance on OceanOpticsClass to get class property + Tango::DbDatum def_prop, cl_prop; + OceanOpticsClass *ds_class = + (static_cast<OceanOpticsClass *>(get_device_class())); + int i = -1; + + // Try to initialize DeviceId from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> deviceId; + else { + // Try to initialize DeviceId from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> deviceId; + } + // And try to extract DeviceId value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> deviceId; + + // Try to initialize SerialNumber from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> serialNumber; + else { + // Try to initialize SerialNumber from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> serialNumber; + } + // And try to extract SerialNumber value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> serialNumber; + + // Try to initialize NFramesBuffered from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> nFramesBuffered; + else { + // Try to initialize NFramesBuffered from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> nFramesBuffered; + } + // And try to extract NFramesBuffered value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> nFramesBuffered; + + // Try to initialize DefaultStartRegion from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> defaultStartRegion; + else { + // Try to initialize DefaultStartRegion from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> defaultStartRegion; + } + // And try to extract DefaultStartRegion value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> defaultStartRegion; + + // Try to initialize DefaultEndRegion from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> defaultEndRegion; + else { + // Try to initialize DefaultEndRegion from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> defaultEndRegion; + } + // And try to extract DefaultEndRegion value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> defaultEndRegion; + + // Try to initialize SleepReading from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> sleepReading; + else { + // Try to initialize SleepReading from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> sleepReading; + } + // And try to extract SleepReading value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> sleepReading; + + // Try to initialize DefaultGaussRef from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> defaultGaussRef; + else { + // Try to initialize DefaultGaussRef from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> defaultGaussRef; + } + // And try to extract DefaultGaussRef value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> defaultGaussRef; + + // Try to initialize DataReferenceFile from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> dataReferenceFile; + else { + // Try to initialize DataReferenceFile from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> dataReferenceFile; + } + // And try to extract DataReferenceFile value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> dataReferenceFile; + + // Try to initialize PreferFWHM from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> preferFWHM; + else { + // Try to initialize PreferFWHM from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> preferFWHM; + } + // And try to extract PreferFWHM value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> preferFWHM; + + // Try to initialize AutoExposureRange from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> autoExposureRange; + else { + // Try to initialize AutoExposureRange from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> autoExposureRange; + } + // And try to extract AutoExposureRange value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> autoExposureRange; + + // Try to initialize AutoExposureStep from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> autoExposureStep; + else { + // Try to initialize AutoExposureStep from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> autoExposureStep; + } + // And try to extract AutoExposureStep value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> autoExposureStep; + + // Try to initialize AutoExposureAmpRange from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> autoExposureAmpRange; + else { + // Try to initialize AutoExposureAmpRange from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> autoExposureAmpRange; + } + // And try to extract AutoExposureAmpRange value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> autoExposureAmpRange; + + // Try to initialize IntensityCalibrationFile from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> intensityCalibrationFile; + else { + // Try to initialize IntensityCalibrationFile from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> intensityCalibrationFile; + } + // And try to extract IntensityCalibrationFile value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> intensityCalibrationFile; + + // Try to initialize NoiseProfileFile from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> noiseProfileFile; + else { + // Try to initialize NoiseProfileFile from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> noiseProfileFile; + } + // And try to extract NoiseProfileFile value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> noiseProfileFile; + + // Try to initialize WavelengthAttr from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> wavelengthAttr; + else { + // Try to initialize WavelengthAttr from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> wavelengthAttr; + } + // And try to extract WavelengthAttr value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> wavelengthAttr; + + // Try to initialize AreaInAnalysisRegion from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> areaInAnalysisRegion; + else { + // Try to initialize AreaInAnalysisRegion from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> areaInAnalysisRegion; + } + // And try to extract AreaInAnalysisRegion value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> areaInAnalysisRegion; + + // Try to initialize WidthCorrection from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> widthCorrection; + else { + // Try to initialize WidthCorrection from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> widthCorrection; + } + // And try to extract WidthCorrection value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> widthCorrection; + + } + + /*----- PROTECTED REGION ID(OceanOptics::get_device_property_after) ENABLED START -----*/ + + // Check device property data members init + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_device_property_after +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::always_executed_hook() + * Description : method always executed before any command is executed + */ +//-------------------------------------------------------- +void OceanOptics::always_executed_hook() +{ + DEBUG_STREAM << "OceanOptics::always_executed_hook() " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::always_executed_hook) ENABLED START -----*/ + + // code always executed before all requests + timespec now; + clock_gettime(CLOCK_MONOTONIC,&now); + double diff_time = (now.tv_sec - last_read.tv_sec) + (double)(now.tv_nsec - last_read.tv_nsec)/1000000000; + if(live_mode && device_id != -1 && diff_time>2) + { + set_state(Tango::ALARM); + set_status("Trigger Missing"); + } + else if(live_mode && device_id != -1 && diff_time<=2 && get_state()==Tango::ALARM) + { + set_state(Tango::RUNNING); + set_status("Continuous Mode"); + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::always_executed_hook +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::read_attr_hardware() + * Description : Hardware acquisition for attributes + */ +//-------------------------------------------------------- +void OceanOptics::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list)) +{ + DEBUG_STREAM << "OceanOptics::read_attr_hardware(vector<long> &attr_list) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_attr_hardware) ENABLED START -----*/ + + // Add your own code + //DEBUG_STREAM << "OceanOptics::read_attr_hardware(vector<long> &attr_list) entering... "<< endl; + // Add your own code here + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_attr_hardware +} +//-------------------------------------------------------- +/** + * Method : OceanOptics::write_attr_hardware() + * Description : Hardware writing for attributes + */ +//-------------------------------------------------------- +void OceanOptics::write_attr_hardware(TANGO_UNUSED(vector<long> &attr_list)) +{ + DEBUG_STREAM << "OceanOptics::write_attr_hardware(vector<long> &attr_list) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::write_attr_hardware) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_attr_hardware +} + +//-------------------------------------------------------- +/** + * Read attribute ExposureTime related method + * Description: Exposure time in milliseconds + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_ExposureTime(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_ExposureTime(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_ExposureTime) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_ExposureTime(Tango::Attribute &attr) entering... "<< endl; + //if(!m_usbCCD.GetParameters()) + // INFO_STREAM << "OceanOptics::read_ExposureTime(): error in GetParameters()" << endl; + if(get_state() == Tango::ON) + { + int error; +#if _SEABREEZE_API > 1 + unsigned long min_integration_time_microsec=0; +#else + char error_str[128]; + long min_integration_time_microsec;/* = seabreeze_get_min_integration_time_microsec(device_id, &error); + seabreeze_get_error_string(error, error_str, 128); + printf("min_integration_time_microsec is %d [%s]\n", min_integration_time_microsec, error_str);*/ + const int SEND_ENDPOINT = 0x01; + const int READ_ENDPOINT = 0x81; + unsigned char request[1]; + unsigned char response[32]; + min_integration_time_microsec = 0; + size_t i = 0; + //for(i=0; i<1; i++) + { + request[0] = 0xfe; + //request[1] = 2+i; + + memset(response, 0, sizeof(response)); + + seabreeze_write_usb(device_id, &error, SEND_ENDPOINT, request, sizeof(request)); + if(error) + { + seabreeze_get_error_string(error, error_str, 128); + printf("Error writing usb [%s]\n", error_str); + set_state(Tango::FAULT); + set_status("Communication error"); + disconnect_device(); + device_id = -1; + ostringstream str; + str << "Error: '" << error_str << "'"; + Tango::Except::throw_exception( + (const char *) "Communication error", + str.str(), + __func__, Tango::ERR); + //continue; + } + + seabreeze_read_usb(device_id, &error, READ_ENDPOINT, response, 17/*sizeof(response)*/); + if(error) + { + seabreeze_get_error_string(error, error_str, 128); + printf("Error reading usb [%s]\n", error_str); + set_state(Tango::FAULT); + set_status("Communication error"); + disconnect_device(); + ostringstream str; + str << "Error: '" << error_str << "'"; + Tango::Except::throw_exception( + (const char *) "Communication error", + str.str(), + __func__, Tango::ERR); + } + + /*unsigned short value = (unsigned short) (response[1] | (response[2] << 8)); + + printf("i=%d: hex 0x%04x dec %5hu (%s)\n", i, value, value, labels[i]); + + i++;*/ + //min_integration_time_microsec = (long) (response[1] << (i*8)); + } + //printf("response 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", response[0], response[1], response[2], response[3], response[4], response[5], response[6], response[7], response[8], response[9], response[10], response[11], response[12], response[13], response[14]); + //min_integration_time_microsec = (long) (response[2] | (response[3] << 8) | (response[4] << 16) | (response[5] << 24)); + uint32_t *tmp = (uint32_t *)&response[2]; + min_integration_time_microsec = (long)(myntohl(*tmp)); +#endif + *attr_ExposureTime_read = (double)min_integration_time_microsec/1000;//TODO + } + attr.set_value(attr_ExposureTime_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_ExposureTime +} +//-------------------------------------------------------- +/** + * Write attribute ExposureTime related method + * Description: Exposure time in milliseconds + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_ExposureTime(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_ExposureTime(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_ExposureTime) ENABLED START -----*/ + if(get_state() == Tango::FAULT) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) "OceanOptics::write_ExposureTime()", Tango::ERR); + } + if(get_state() != Tango::ON && get_state() != Tango::ALARM) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) "OceanOptics::write_ExposureTime()", Tango::ERR); + } + int error; + +#if _SEABREEZE_API > 1 + unsigned long integr_time_usec = (unsigned long)(w_val*1000); + sbapi_spectrometer_set_integration_time_micros (device_id, spectrometer_id, &error, integr_time_usec); +#else + long integr_time_usec = (long)(w_val*1000); + seabreeze_set_integration_time_microsec(device_id, &error, integr_time_usec); +#endif + if(error) + { + char error_str[128]; +#if _SEABREEZE_API > 1 +#else + seabreeze_get_error_string(error, error_str, 128); +#endif + printf("Error is is %d [%s]\n", error, error_str); + TangoSys_MemStream out_stream; + out_stream << "Error writing Exposure Time=" << w_val << ends; + Tango::Except::throw_exception( + (const char *) "Value not Allowed", + out_stream.str(), + (const char *) "OceanOptics::write_ExposureTime()", Tango::ERR); + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_ExposureTime +} +//-------------------------------------------------------- +/** + * Read attribute IncrSensitivity related method + * Description: false: use standard sensitivity\ntrue: use increased sensitivity + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_IncrSensitivity(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_IncrSensitivity(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_IncrSensitivity) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_IncrSensitivity(Tango::Attribute &attr) entering... "<< endl; + //if(!m_usbCCD.GetParameters()) + // INFO_STREAM << "OceanOptics::read_IncrSensitivity(): error in GetParameters()" << endl; + //DEBUG_STREAM << "OceanOptics::read_IncrSensitivity() read sensitivity=" << m_usbCCD.m_dwSensitivity << endl; + *attr_IncrSensitivity_read = 0; //TODO: m_usbCCD.m_dwSensitivity != 0; + attr.set_value(attr_IncrSensitivity_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_IncrSensitivity +} +//-------------------------------------------------------- +/** + * Write attribute IncrSensitivity related method + * Description: false: use standard sensitivity\ntrue: use increased sensitivity + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_IncrSensitivity(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_IncrSensitivity(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_IncrSensitivity) ENABLED START -----*/ + if(get_state() == Tango::FAULT) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) "OceanOptics::write_IncrSensitivity()", Tango::ERR); + } + if(get_state() != Tango::ON) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) "OceanOptics::write_IncrSensitivity()", Tango::ERR); + } + /*if(!(properties & DP_SENSIT)) + { + TangoSys_MemStream out_stream; + out_stream << "Changing Increased Sensitivity not supported on this model" << ends; + Tango::Except::throw_exception( + (const char *) "Not supported", + out_stream.str(), + (const char *) "OceanOptics::write_IncrSensitivity()", Tango::ERR); + } if(!m_usbCCD.SetReadOuts((int)w_val)) + { + TangoSys_MemStream out_stream; + out_stream << "Error writing Increased Sensitivity=" << w_val << ends; + Tango::Except::throw_exception( + (const char *) "Value not Allowed", + out_stream.str(), + (const char *) "OceanOptics::write_IncrSensitivity()", Tango::ERR); + }*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_IncrSensitivity +} +//-------------------------------------------------------- +/** + * Read attribute SyncMode related method + * Description: 0: The camera operates without synchronization.\nSpectra are read out periodically in accordance with NumReadouts attribute.\n\n1: Readout is performed periodically in accordance with NumReadouts attribute.\nAt the beginning of the first readout a positive sync pulse is formed.\n\n2: A sync pulse is formed at beginning of each readout.\n\n3: One sync pulse of negative polarity is generated for the entire readout time.\n\n4: The camera will wait for one sync pulse.\nThe first readout will start at the rising edge of an external sync pulse.\nAll other readouts will be performed as soon as possible.\nNo blanks within limit\n\n5: Each readout starts at the rising edge of an external sync pulse.\nThe camera will wait fo as many sync pulses as much readouts are set. + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_SyncMode(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_SyncMode(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_SyncMode) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_SyncMode(Tango::Attribute &attr) entering... "<< endl; + //if(!m_usbCCD.GetParameters()) + // INFO_STREAM << "OceanOptics::read_SyncMode(): error in GetParameters()" << endl; + /*if(get_state() != Tango::ON) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) __func__, Tango::ERR); + }*/ + /*switch(m_usbCCD.m_dwSynchr) + { + case SYNCHR_NONE: + *attr_SyncMode_read = TG_SYNCHR_NONE; + break; + case SYNCHR_CONTR: + *attr_SyncMode_read = TG_SYNCHR_CONTR; + break; + case SYNCHR_CONTR_FRS: + *attr_SyncMode_read = TG_SYNCHR_CONTR_FRS; + break; + case SYNCHR_CONTR_NEG: + *attr_SyncMode_read = TG_SYNCHR_CONTR_NEG; + break; + case SYNCHR_EXT: + *attr_SyncMode_read = TG_SYNCHR_EXT; + break; + case SYNCHR_EXT_FRS: + *attr_SyncMode_read = TG_SYNCHR_EXT_FRS; + break; + default: + *attr_SyncMode_read = -1; + break; + }*/ + int error; +#if 0 //TODO: not working +#if _SEABREEZE_API > 1 + +#else + char error_str[128]; + uint8_t syncmode; + const int SEND_ENDPOINT = 0x01; + const int READ_ENDPOINT = 0x81; + unsigned char request[1]; + unsigned char response[2]; + + unsigned i = 0; + for(i=0; i<1; i++) + { + //request[0] = 0xfe; + request[0] = 0x0b; + //request[1] = 2+i; + + memset(response, 0, sizeof(response)); + + seabreeze_write_usb(device_id, &error, SEND_ENDPOINT, request, sizeof(request)); + if(error) + { + seabreeze_get_error_string(error, error_str, 128); + printf("Error writing usb [%s]\n", error_str); + continue; + } + + seabreeze_read_usb(device_id, &error, READ_ENDPOINT, response, 2/*sizeof(response)*/); + if(error) + { + seabreeze_get_error_string(error, error_str, 128); + printf("Error reading usb [%s]\n", error_str); + continue; + } + + /*unsigned short value = (unsigned short) (response[1] | (response[2] << 8)); + + printf("i=%d: hex 0x%04x dec %5hu (%s)\n", i, value, value, labels[i]); + + i++;*/ + //min_integration_time_microsec = (long) (response[1] << (i*8)); + } + printf("response 0x%x 0x%x\n", response[0], response[1]); + //min_integration_time_microsec = (long) (response[2] | (response[3] << 8) | (response[4] << 16) | (response[5] << 24)); + syncmode = response[0]; + *attr_SyncMode_read = syncmode; +#endif +#endif + attr.set_value(attr_SyncMode_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_SyncMode +} +//-------------------------------------------------------- +/** + * Write attribute SyncMode related method + * Description: 0: The camera operates without synchronization.\nSpectra are read out periodically in accordance with NumReadouts attribute.\n\n1: Readout is performed periodically in accordance with NumReadouts attribute.\nAt the beginning of the first readout a positive sync pulse is formed.\n\n2: A sync pulse is formed at beginning of each readout.\n\n3: One sync pulse of negative polarity is generated for the entire readout time.\n\n4: The camera will wait for one sync pulse.\nThe first readout will start at the rising edge of an external sync pulse.\nAll other readouts will be performed as soon as possible.\nNo blanks within limit\n\n5: Each readout starts at the rising edge of an external sync pulse.\nThe camera will wait fo as many sync pulses as much readouts are set. + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_SyncMode(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_SyncMode(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevLong w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_SyncMode) ENABLED START -----*/ + int error; + if(get_state() != Tango::ON && get_state() != Tango::ALARM) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + DEBUG_STREAM << "OceanOptics::write_SyncMode(Tango::WAttribute &attr): " << out_stream.str() << endl; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) "OceanOptics::write_SyncMode()", Tango::ERR); + } + Tango::DevLong tmp_SyncMode; + /*switch(w_val) + { + case TG_SYNCHR_NONE: + tmp_SyncMode = SYNCHR_NONE; + break; + case TG_SYNCHR_CONTR: + if(!(properties & DP_SYNCHR_CONTR)) + { + TangoSys_MemStream out_stream; + out_stream << "Sync Mode not supported on this model" << ends; + Tango::Except::throw_exception( + (const char *) "Not supported", + out_stream.str(), + (const char *) "OceanOptics::write_SyncMode()", Tango::ERR); + } + tmp_SyncMode = SYNCHR_CONTR; + break; + case TG_SYNCHR_CONTR_FRS: + if(!(properties & DP_SYNCHR_CONTR_FRS)) + { + TangoSys_MemStream out_stream; + out_stream << "Sync Mode not supported on this model" << ends; + Tango::Except::throw_exception( + (const char *) "Not supported", + out_stream.str(), + (const char *) "OceanOptics::write_SyncMode()", Tango::ERR); + } + tmp_SyncMode = SYNCHR_CONTR_FRS; + break; + case TG_SYNCHR_CONTR_NEG: + if(!(properties & DP_SYNCHR_CONTR_NEG)) + { + TangoSys_MemStream out_stream; + out_stream << "Sync Mode not supported on this model" << ends; + Tango::Except::throw_exception( + (const char *) "Not supported", + out_stream.str(), + (const char *) "OceanOptics::write_SyncMode()", Tango::ERR); + } + tmp_SyncMode = SYNCHR_CONTR_NEG; + break; + case TG_SYNCHR_EXT: + if(!(properties & DP_SYNCHR_EXT)) + { + TangoSys_MemStream out_stream; + out_stream << "Sync Mode not supported on this model" << ends; + Tango::Except::throw_exception( + (const char *) "Not supported", + out_stream.str(), + (const char *) "OceanOptics::write_SyncMode()", Tango::ERR); + } + tmp_SyncMode = SYNCHR_EXT; + break; + case TG_SYNCHR_EXT_FRS: + if(!(properties & DP_SYNCHR_EXT_FRS)) + { + TangoSys_MemStream out_stream; + out_stream << "Sync Mode not supported on this model" << ends; + Tango::Except::throw_exception( + (const char *) "Not supported", + out_stream.str(), + (const char *) "OceanOptics::write_SyncMode()", Tango::ERR); + } + tmp_SyncMode = SYNCHR_EXT_FRS; + break; + default: + { + TangoSys_MemStream out_stream; + out_stream << "Allowed values: 0=SYNCHR_NONE, 1=SYNCHR_CONTR, 2=SYNCHR_CONTR_FRS, 3=SYNCHR_CONTR_NEG, 4=SYNCHR_EXT, 5=SYNCHR_EXT_FRS" << ends; + Tango::Except::throw_exception( + (const char *) "Value Not Allowed", + out_stream.str(), + (const char *) "OceanOptics::write_SyncMode()", Tango::ERR); + } + }*/ +#if _SEABREEZE_API > 1 +#else + DEBUG_STREAM << "OceanOptics::write_SyncMode(Tango::WAttribute &attr): val=" << w_val << endl; + seabreeze_set_trigger_mode(device_id, &error, w_val); + DEBUG_STREAM << "OceanOptics::write_SyncMode(Tango::WAttribute &attr): written , error=" << error << endl; +#endif + if(error) + { + char error_str[128]; + seabreeze_get_error_string(error, error_str, 128); + printf("Result is [%s]\n", error_str); + TangoSys_MemStream out_stream; + out_stream << "Error writing Synchronization Mode=" << w_val <<" err="<<error_str; + DEBUG_STREAM << "OceanOptics::write_SyncMode(Tango::WAttribute &attr): " << out_stream.str() << endl; + Tango::Except::throw_exception( + (const char *) "Value not Allowed", + out_stream.str(), + (const char *) "OceanOptics::write_SyncMode()", Tango::ERR); + } + else + { + *attr_SyncMode_read = w_val; + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_SyncMode +} +//-------------------------------------------------------- +/** + * Read attribute NoiseSubtraction related method + * Description: Enable/Disable subtraction of background noise profile \nacquired with the AcquireNoise command + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_NoiseSubtraction(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_NoiseSubtraction(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_NoiseSubtraction) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_NoiseSubtraction(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_NoiseSubtraction_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_NoiseSubtraction +} +//-------------------------------------------------------- +/** + * Write attribute NoiseSubtraction related method + * Description: Enable/Disable subtraction of background noise profile \nacquired with the AcquireNoise command + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_NoiseSubtraction(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_NoiseSubtraction(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_NoiseSubtraction) ENABLED START -----*/ + *attr_NoiseSubtraction_read = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_NoiseSubtraction +} +//-------------------------------------------------------- +/** + * Read attribute GaussFitEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_GaussFitEnable(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_GaussFitEnable(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_GaussFitEnable) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_GaussFitEnable(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_GaussFitEnable_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_GaussFitEnable +} +//-------------------------------------------------------- +/** + * Write attribute GaussFitEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_GaussFitEnable(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_GaussFitEnable(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_GaussFitEnable) ENABLED START -----*/ + *attr_GaussFitEnable_read = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_GaussFitEnable +} +//-------------------------------------------------------- +/** + * Read attribute FWHMEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_FWHMEnable(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_FWHMEnable(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_FWHMEnable) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_FWHMEnable(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_FWHMEnable_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_FWHMEnable +} +//-------------------------------------------------------- +/** + * Write attribute FWHMEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_FWHMEnable(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_FWHMEnable(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_FWHMEnable) ENABLED START -----*/ + *attr_FWHMEnable_read = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_FWHMEnable +} +//-------------------------------------------------------- +/** + * Read attribute GaussFitCenter related method + * Description: wavelength of peak of Gaussian Fit + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_GaussFitCenter(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_GaussFitCenter(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_GaussFitCenter) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_GaussFitCenter(Tango::Attribute &attr) entering... "<< endl; + if(GaussFit_valid) + { + attr.set_value(attr_GaussFitCenter_read); + } + else + { + attr.set_quality(Tango::ATTR_INVALID); + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_GaussFitCenter +} +//-------------------------------------------------------- +/** + * Read attribute GaussFitWidth related method + * Description: width of Gaussian Fit + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_GaussFitWidth(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_GaussFitWidth(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_GaussFitWidth) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_GaussFitWidth(Tango::Attribute &attr) entering... "<< endl; + if(GaussFit_valid) + { + attr.set_value(attr_GaussFitWidth_read); + } + else + { + attr.set_quality(Tango::ATTR_INVALID); + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_GaussFitWidth +} +//-------------------------------------------------------- +/** + * Read attribute FWHMCenter related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_FWHMCenter(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_FWHMCenter(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_FWHMCenter) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_FWHMCenter(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_FWHMCenter_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_FWHMCenter +} +//-------------------------------------------------------- +/** + * Read attribute FWHMWidth related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_FWHMWidth(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_FWHMWidth(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_FWHMWidth) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_FWHMWidth(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_FWHMWidth_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_FWHMWidth +} +//-------------------------------------------------------- +/** + * Read attribute Center related method + * Description: wavelength of peak of FWHM or of Gaussian Fit + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_Center(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_Center(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_Center) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_Center(Tango::Attribute &attr) entering... "<< endl; + if(*attr_FWHMEnable_read || (*attr_GaussFitEnable_read && GaussFit_valid)) + attr.set_value(attr_Center_read); + else + attr.set_quality(Tango::ATTR_INVALID); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_Center +} +//-------------------------------------------------------- +/** + * Read attribute Width related method + * Description: width of FWHM or of Gaussian Fit + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_Width(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_Width(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_Width) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_Width(Tango::Attribute &attr) entering... "<< endl; + if(*attr_FWHMEnable_read || (*attr_GaussFitEnable_read && GaussFit_valid)) + attr.set_value(attr_Width_read); + else + attr.set_quality(Tango::ATTR_INVALID); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_Width +} +//-------------------------------------------------------- +/** + * Read attribute FitType related method + * Description: 1=Gaussian 2=Gaussian Asymm 3=Confiteor + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_FitType(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_FitType(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_FitType) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_FitType(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_FitType_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_FitType +} +//-------------------------------------------------------- +/** + * Write attribute FitType related method + * Description: 1=Gaussian 2=Gaussian Asymm 3=Confiteor + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_FitType(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_FitType(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevLong w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_FitType) ENABLED START -----*/ + *attr_FitType_read = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_FitType +} +//-------------------------------------------------------- +/** + * Read attribute FWHMAvg related method + * Description: + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_FWHMAvg(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_FWHMAvg(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_FWHMAvg) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_FitType(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_FWHMAvg_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_FWHMAvg +} +//-------------------------------------------------------- +/** + * Write attribute FWHMAvg related method + * Description: + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_FWHMAvg(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_FWHMAvg(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevLong w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_FWHMAvg) ENABLED START -----*/ + *attr_FWHMAvg_read = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_FWHMAvg +} +//-------------------------------------------------------- +/** + * Read attribute NoiseLevel related method + * Description: + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_NoiseLevel(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_NoiseLevel(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_NoiseLevel) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_NoiseLevel(Tango::Attribute &attr) entering... "<< endl; + *attr_NoiseLevel_read = noise_level; + attr.set_value(attr_NoiseLevel_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_NoiseLevel +} +//-------------------------------------------------------- +/** + * Write attribute NoiseLevel related method + * Description: + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_NoiseLevel(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_NoiseLevel(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevLong w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_NoiseLevel) ENABLED START -----*/ + noise_level = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_NoiseLevel +} +//-------------------------------------------------------- +/** + * Read attribute DataReferenceFile related method + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_DataReferenceFile(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_DataReferenceFile(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_DataReferenceFile) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_DataReferenceFile(Tango::Attribute &attr) entering... "<< endl; + attr_tmp_ptr = attr_strchar; + attr_DataReferenceFile_read = &attr_tmp_ptr; + attr.set_value(attr_DataReferenceFile_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_DataReferenceFile +} +//-------------------------------------------------------- +/** + * Write attribute DataReferenceFile related method + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_DataReferenceFile(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_DataReferenceFile(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevString w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_DataReferenceFile) ENABLED START -----*/ + ostringstream tempstr; + + tempstr << w_val << ends; + strcpy(attr_strchar,tempstr.str().c_str()); + if(strlen(attr_strchar) > 0) + { + dataReferenceFile = tempstr.str(); + + ifstream fd; //startup file + fd.open(dataReferenceFile.c_str()); + if (!fd) + { + stringstream tmp; + tmp << "Cannot open Data Reference file:" << strerror(errno) << endl; + INFO_STREAM << "OceanOptics::write_DataReferenceFile(): " << tmp.str(); + Tango::Except::throw_exception( + (const char *) "Error opening file", + tmp.str(), + (const char *) "OceanOptics::write_DataReferenceFile()", Tango::ERR); + } + else{ + DEBUG_STREAM << "OceanOptics::write_DataReferenceFile(): file opened successfully" << endl; + string lineread; + int i=0; + double val; + while(std::getline(fd, lineread, '\n')) + { // Read line by line + if(lineread.length() > 0 && i < NumPixel) + { + sscanf(lineread.c_str(),"%lf",&val); + pReferenceData[i++] = val; + } + } + fd.close(); + } + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_DataReferenceFile +} +//-------------------------------------------------------- +/** + * Read attribute AutoExposure related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_AutoExposure(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_AutoExposure(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_AutoExposure) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_AutoExposure(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_AutoExposure_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_AutoExposure +} +//-------------------------------------------------------- +/** + * Write attribute AutoExposure related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_AutoExposure(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_AutoExposure(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_AutoExposure) ENABLED START -----*/ + *attr_AutoExposure_read = w_val; + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_AutoExposure +} +//-------------------------------------------------------- +/** + * Read attribute LightSourceIntensity related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_LightSourceIntensity(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_LightSourceIntensity(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_LightSourceIntensity) ENABLED START -----*/ + // Set the attribute value + attr.set_value(attr_LightSourceIntensity_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_LightSourceIntensity +} +//-------------------------------------------------------- +/** + * Write attribute LightSourceIntensity related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_LightSourceIntensity(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_LightSourceIntensity(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_LightSourceIntensity) ENABLED START -----*/ + + if(get_state() == Tango::FAULT) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + __func__, Tango::ERR); + } + if(get_state() != Tango::ON && get_state() != Tango::ALARM) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + __func__, Tango::ERR); + } + int error; + +#if _SEABREEZE_API > 1 + unsigned long integr_time_usec = (unsigned long)(w_val*1000); + sbapi_spectrometer_set_integration_time_micros (device_id, spectrometer_id, &error, integr_time_usec); +#else + int count_light_id = seabreeze_get_light_source_count (device_id, &error); + if(count_light_id != 1) + { + TangoSys_MemStream out_stream; + out_stream << "Count of light sources different from 1 but is " << count_light_id; + Tango::Except::throw_exception( + (const char *) "Bad light sources count", + out_stream.str(), + __func__, Tango::ERR); + } + seabreeze_set_light_source_intensity(device_id, &error, 0/*light_id*/, w_val); +#endif + if(error) + { + char error_str[128]; +#if _SEABREEZE_API > 1 +#else + seabreeze_get_error_string(error, error_str, 128); +#endif + printf("Error is is %d [%s]\n", error, error_str); + TangoSys_MemStream out_stream; + out_stream << "Error writing seabreeze_set_light_source_intensity=" << w_val << " err=" << error_str; + Tango::Except::throw_exception( + (const char *) "Error", + out_stream.str(), + __func__, Tango::ERR); + } + *attr_LightSourceIntensity_read = w_val; + + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_LightSourceIntensity +} +//-------------------------------------------------------- +/** + * Read attribute RtMode related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_RtMode(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_RtMode(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_RtMode) ENABLED START -----*/ + // Set the attribute value + attr.set_value(attr_RtMode_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_RtMode +} +//-------------------------------------------------------- +/** + * Write attribute RtMode related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_RtMode(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_RtMode(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_RtMode) ENABLED START -----*/ + *attr_RtMode_read = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_RtMode +} +//-------------------------------------------------------- +/** + * Read attribute LightSourceEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_LightSourceEnable(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_LightSourceEnable(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_LightSourceEnable) ENABLED START -----*/ + if(get_state() == Tango::ON) + { + int error; +#if _SEABREEZE_API > 1 + unsigned long min_integration_time_microsec=0; +#else + char error_str[128]; + long min_integration_time_microsec;/* = seabreeze_get_min_integration_time_microsec(device_id, &error); + seabreeze_get_error_string(error, error_str, 128); + printf("min_integration_time_microsec is %d [%s]\n", min_integration_time_microsec, error_str);*/ + const int SEND_ENDPOINT = 0x01; + const int READ_ENDPOINT = 0x81; + unsigned char request[1]; + unsigned char response[32]; + min_integration_time_microsec = 0; + size_t i = 0; + //for(i=0; i<1; i++) + { + request[0] = 0xfe; + //request[1] = 2+i; + + memset(response, 0, sizeof(response)); + + seabreeze_write_usb(device_id, &error, SEND_ENDPOINT, request, sizeof(request)); + if(error) + { + seabreeze_get_error_string(error, error_str, 128); + printf("Error writing usb [%s]\n", error_str); + set_state(Tango::FAULT); + set_status("Communication error"); + disconnect_device(); + device_id = -1; + ostringstream str; + str << "Error: '" << error_str << "'"; + Tango::Except::throw_exception( + (const char *) "Communication error", + str.str(), + __func__, Tango::ERR); + } + + seabreeze_read_usb(device_id, &error, READ_ENDPOINT, response, 17/*sizeof(response)*/); + if(error) + { + seabreeze_get_error_string(error, error_str, 128); + printf("Error reading usb [%s]\n", error_str); + set_state(Tango::FAULT); + set_status("Communication error"); + disconnect_device(); + device_id = -1; + ostringstream str; + str << "Error: '" << error_str << "'"; + Tango::Except::throw_exception( + (const char *) "Communication error", + str.str(), + __func__, Tango::ERR); + } + + /*unsigned short value = (unsigned short) (response[1] | (response[2] << 8)); + + printf("i=%d: hex 0x%04x dec %5hu (%s)\n", i, value, value, labels[i]); + + i++;*/ + //min_integration_time_microsec = (long) (response[1] << (i*8)); + } + //printf("response 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", response[0], response[1], response[2], response[3], response[4], response[5], response[6], response[7], response[8], response[9], response[10], response[11], response[12], response[13], response[14]); + //min_integration_time_microsec = (long) (response[2] | (response[3] << 8) | (response[4] << 16) | (response[5] << 24)); + uint8_t *tmp = (uint8_t *)&response[8]; +#endif + *attr_LightSourceEnable_read = (tmp != 0);//TODO + } + // Set the attribute value + attr.set_value(attr_LightSourceEnable_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_LightSourceEnable +} +//-------------------------------------------------------- +/** + * Write attribute LightSourceEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_LightSourceEnable(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_LightSourceEnable(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_LightSourceEnable) ENABLED START -----*/ + if(get_state() == Tango::FAULT) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + __func__, Tango::ERR); + } + if(get_state() != Tango::ON && get_state() != Tango::ALARM) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + __func__, Tango::ERR); + } + int error; +#if _SEABREEZE_API > 1 + //unsigned long integr_time_usec = (unsigned long)(w_val*1000); + //sbapi_spectrometer_set_integration_time_micros (device_id, spectrometer_id, &error, integr_time_usec); +#else + int count_light_id = seabreeze_get_light_source_count (device_id, &error); + if(count_light_id != 1) + { + TangoSys_MemStream out_stream; + out_stream << "Count of light sources different from 1 but is " << count_light_id; + Tango::Except::throw_exception( + (const char *) "Bad light sources count", + out_stream.str(), + __func__, Tango::ERR); + } + unsigned char enable = w_val ? 1 : 0; + seabreeze_set_light_source_enable(device_id, &error, 0/*light_id*/, enable); +#endif + if(error) + { + char error_str[128]; +#if _SEABREEZE_API > 1 +#else + seabreeze_get_error_string(error, error_str, 128); +#endif + printf("Error is is %d [%s]\n", error, error_str); + TangoSys_MemStream out_stream; + out_stream << "Error writing seabreeze_set_light_source_enable=" << enable << " err=" << error_str; + Tango::Except::throw_exception( + (const char *) "Error", + out_stream.str(), + __func__, Tango::ERR); + } + + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_LightSourceEnable +} +//-------------------------------------------------------- +/** + * Read attribute IntensityCalibrationEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_IntensityCalibrationEnable(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_IntensityCalibrationEnable(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_IntensityCalibrationEnable) ENABLED START -----*/ + // Set the attribute value + attr.set_value(attr_IntensityCalibrationEnable_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_IntensityCalibrationEnable +} +//-------------------------------------------------------- +/** + * Write attribute IntensityCalibrationEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_IntensityCalibrationEnable(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_IntensityCalibrationEnable(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_IntensityCalibrationEnable) ENABLED START -----*/ + *attr_IntensityCalibrationEnable_read = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_IntensityCalibrationEnable +} +//-------------------------------------------------------- +/** + * Read attribute Area related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_Area(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_Area(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_Area) ENABLED START -----*/ + // Set the attribute value + attr.set_value(attr_Area_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_Area +} +//-------------------------------------------------------- +/** + * Read attribute AreaRegion related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_AreaRegion(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_AreaRegion(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_AreaRegion) ENABLED START -----*/ + // Set the attribute value + attr.set_value(attr_AreaRegion_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_AreaRegion +} +//-------------------------------------------------------- +/** + * Write attribute AreaRegion related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_AreaRegion(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_AreaRegion(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_AreaRegion) ENABLED START -----*/ + *attr_AreaRegion_read = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_AreaRegion +} +//-------------------------------------------------------- +/** + * Read attribute AreaEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_AreaEnable(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_AreaEnable(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_AreaEnable) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_GaussFitEnable(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_AreaEnable_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_AreaEnable +} +//-------------------------------------------------------- +/** + * Write attribute AreaEnable related method + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_AreaEnable(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_AreaEnable(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_AreaEnable) ENABLED START -----*/ + *attr_AreaEnable_read = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_AreaEnable +} +//-------------------------------------------------------- +/** + * Read attribute WidhtCorrectionEnable related method + * Description: enable widht correction + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::read_WidhtCorrectionEnable(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_WidhtCorrectionEnable(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_WidhtCorrectionEnable) ENABLED START -----*/ + // Set the attribute value + attr.set_value(attr_WidhtCorrectionEnable_read); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_WidhtCorrectionEnable +} +//-------------------------------------------------------- +/** + * Write attribute WidhtCorrectionEnable related method + * Description: enable widht correction + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void OceanOptics::write_WidhtCorrectionEnable(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_WidhtCorrectionEnable(Tango::WAttribute &attr) entering... " << endl; + // Retrieve write value + Tango::DevBoolean w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_WidhtCorrectionEnable) ENABLED START -----*/ + *attr_WidhtCorrectionEnable_read = w_val; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_WidhtCorrectionEnable +} +//-------------------------------------------------------- +/** + * Read attribute NumPixels related method + * Description: long[0]: number of pixels horizontally (number of CCD-array columns)\nlong[1]: number of pixels vertically (number of CCD-array lines) + * + * Data type: Tango::DevLong + * Attr type: Spectrum max = 2 + */ +//-------------------------------------------------------- +void OceanOptics::read_NumPixels(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_NumPixels(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_NumPixels) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_NumPixels(Tango::Attribute &attr) entering... "<< endl; + //if(!m_usbCCD.GetParameters()) + // INFO_STREAM << "OceanOptics::read_NumPixels(): error in GetParameters()" << endl; + //attr_NumPixels_read[0] = m_usbCCD.m_dwDigitCapacity; //TODO: returns 12 bit + /*attr_NumPixels_read[0] = m_usbCCD.m_nNumPixelsH; + attr_NumPixels_read[1] = m_usbCCD.m_nNumPixelsV;*/ + attr.set_value(attr_NumPixels_read,2); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_NumPixels +} +//-------------------------------------------------------- +/** + * Read attribute Data related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ +//-------------------------------------------------------- +void OceanOptics::read_Data(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_Data(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_Data) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_Data(Tango::Attribute &attr) entering... "<< endl; +#ifdef _NON_AVERAGE + if(pLiveData) + { + attr_Data_read = (Tango::DevLong *)&(pLiveData[0 + attr_RegionOfInterest_read[0]]); + attr.set_value(attr_Data_read,attr_RegionOfInterest_read[1] - attr_RegionOfInterest_read[0]); + } +#else + if(pLiveData_avg) + { + //DEBUG_STREAM << "OceanOptics::read_Data() ROIStartPix"<<RegionOfInterestStartPix<<" ROIEndPix="<<RegionOfInterestEndPix<<" size="<<RegionOfInterestEndPix - RegionOfInterestStartPix + 1<< endl; + //attr_Data_read = (Tango::DevLong *)&(pLiveData_avg[0 + WaveLenght2Pix(attr_RegionOfInterest_read[0])]); + attr_Data_read = (Tango::DevDouble *)&(pLiveData_avg[0 + RegionOfInterestStartPix]); + //attr.set_value(attr_Data_read,WaveLenght2Pix(attr_RegionOfInterest_read[1]) - WaveLenght2Pix(attr_RegionOfInterest_read[0])); + attr.set_value(attr_Data_read,RegionOfInterestEndPix - RegionOfInterestStartPix + 1); + } +#endif + else + attr.set_quality(Tango::ATTR_INVALID); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_Data +} +//-------------------------------------------------------- +/** + * Read attribute RegionOfInterest related method + * Description: Region of interest returned by the Data attribute\ndouble[0]=start of the region\ndouble[1]=end of the region\n\nValues are in nm according with the conversion factor in x_values\nData attribute property + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 2 + */ +//-------------------------------------------------------- +void OceanOptics::read_RegionOfInterest(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_RegionOfInterest(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_RegionOfInterest) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_RegionOfInterest(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_RegionOfInterest_read,2); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_RegionOfInterest +} +//-------------------------------------------------------- +/** + * Write attribute RegionOfInterest related method + * Description: Region of interest returned by the Data attribute\ndouble[0]=start of the region\ndouble[1]=end of the region\n\nValues are in nm according with the conversion factor in x_values\nData attribute property + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 2 + */ +//-------------------------------------------------------- +void OceanOptics::write_RegionOfInterest(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_RegionOfInterest(Tango::WAttribute &attr) entering... " << endl; + // Retrieve number of write values + int w_length = attr.get_write_value_length(); + + // Retrieve pointer on write values (Do not delete !) + const Tango::DevDouble *w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_RegionOfInterest) ENABLED START -----*/ + if(get_state()==Tango::FAULT) + { + Tango::Except::throw_exception( + (const char *) "CCD not communicating", + (const char *) "CCD not communicating", + (const char *) "OceanOptics::write_RegionOfInterest()", Tango::ERR); + } + if(w_length != 2) + { + Tango::Except::throw_exception( + (const char *) "Wrong parameters", + (const char *) "Expected 2 parameters", + (const char *) "OceanOptics::write_RegionOfInterest()", Tango::ERR); + } + Tango::DevDouble w_val_[2]; + w_val_[0] = floor(w_val[0]*1000.0)*0.001; + w_val_[1] = floor(w_val[1]*1000.0)*0.001; + if(w_val_[0] < x_values[0] || w_val_[0] > x_values[NumPixel-1] || + w_val_[1] < x_values[0] || w_val_[1] > x_values[NumPixel-1] || + w_val_[0] >= w_val_[1]) + { + TangoSys_MemStream out_stream; + out_stream << "Region ["<<w_val_[0]<<","<<w_val_[1]<<"] not allowed, it has to be in ["<<x_values[0]<<"," << x_values[NumPixel-1] << "]" << ends; + Tango::Except::throw_exception( + (const char *) "Value not Allowed", + out_stream.str(), + (const char *) "OceanOptics::write_RegionOfInterest()", Tango::ERR); + } + RegionOfInterestStartPix = WaveLenght2Pix(w_val_[0]); + DEBUG_STREAM << __func__<<": StartROI="<<w_val_[0]<<" -> start pix="<<RegionOfInterestStartPix; + if(x_values[RegionOfInterestStartPix] < w_val_[0]) + { + RegionOfInterestStartPix++; + } + DEBUG_STREAM << __func__<<": ...-> adjusted start pix="<<RegionOfInterestStartPix; + attr_RegionOfInterest_read[0] = x_values[RegionOfInterestStartPix]; + RegionOfInterestEndPix = WaveLenght2Pix(w_val_[1]); + DEBUG_STREAM << __func__<<": EndROI="<<w_val_[1]<<" -> end pix="<<RegionOfInterestEndPix; + if(x_values[RegionOfInterestEndPix] > w_val_[1]) + { + RegionOfInterestEndPix--; + } + DEBUG_STREAM << __func__<<": ...-> adjusted end pix="<<RegionOfInterestEndPix; + attr_RegionOfInterest_read[1] = x_values[RegionOfInterestEndPix]; + tbuf_array_w.reset_rt_buffer(); + tbuf_array_l.reset_rt_buffer(); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_RegionOfInterest +} +//-------------------------------------------------------- +/** + * Read attribute AnalysisRegion related method + * Description: Region used for gaussian and fwhm analysis\ndouble[0]=start of the region\ndouble[1]=end of the region\n\nValues are in nm according with the conversion factor in x_values\nData attribute property + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 2 + */ +//-------------------------------------------------------- +void OceanOptics::read_AnalysisRegion(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_AnalysisRegion(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_AnalysisRegion) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_AnalysisRegion(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_AnalysisRegion_read,2); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_AnalysisRegion +} +//-------------------------------------------------------- +/** + * Write attribute AnalysisRegion related method + * Description: Region used for gaussian and fwhm analysis\ndouble[0]=start of the region\ndouble[1]=end of the region\n\nValues are in nm according with the conversion factor in x_values\nData attribute property + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 2 + */ +//-------------------------------------------------------- +void OceanOptics::write_AnalysisRegion(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_AnalysisRegion(Tango::WAttribute &attr) entering... " << endl; + // Retrieve number of write values + int w_length = attr.get_write_value_length(); + + // Retrieve pointer on write values (Do not delete !) + const Tango::DevDouble *w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_AnalysisRegion) ENABLED START -----*/ + if(get_state()==Tango::FAULT) + { + Tango::Except::throw_exception( + (const char *) "CCD not communicating", + (const char *) "CCD not communicating", + (const char *) "OceanOptics::write_AnalysisRegion()", Tango::ERR); + } if(w_val[0] < x_values[0] || w_val[0] > x_values[NumPixel-1] || + w_val[1] < x_values[0] || w_val[1] > x_values[NumPixel-1] || + w_val[0] >= w_val[1]) + { + TangoSys_MemStream out_stream; + out_stream << "Region not allowed, it has to be in ["<<x_values[0]<<"," << x_values[NumPixel-1] << "]" << ends; + Tango::Except::throw_exception( + (const char *) "Value not Allowed", + out_stream.str(), + (const char *) "OceanOptics::write_AnalysisRegion()", Tango::ERR); + } + AnalysisRegionStartPix = WaveLenght2Pix(w_val[0]); + if(x_values[AnalysisRegionStartPix] < w_val[0]) + { + AnalysisRegionStartPix++; + } + attr_AnalysisRegion_read[0] = x_values[AnalysisRegionStartPix]; + AnalysisRegionEndPix = WaveLenght2Pix(w_val[1]); + if(x_values[AnalysisRegionEndPix] > w_val[1]) + { + AnalysisRegionEndPix--; + } + attr_AnalysisRegion_read[1] = x_values[AnalysisRegionEndPix]; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_AnalysisRegion +} +//-------------------------------------------------------- +/** + * Read attribute GaussFit related method + * Description: double[0]= wavelength of peak of Gaussian Fit\ndouble[1]= width of Gaussian Fit + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 4 + */ +//-------------------------------------------------------- +void OceanOptics::read_GaussFit(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_GaussFit(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_GaussFit) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_GaussFit(Tango::Attribute &attr) entering... "<< endl; + if(GaussFit_valid) + { + attr.set_value(attr_GaussFit_read,4); + } + else + { + attr.set_quality(Tango::ATTR_INVALID); + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_GaussFit +} +//-------------------------------------------------------- +/** + * Read attribute FWHM related method + * Description: double[0]= wavelength of peak of FWHM\ndouble[1]= width of FWHM + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 3 + */ +//-------------------------------------------------------- +void OceanOptics::read_FWHM(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_FWHM(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_FWHM) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_FWHM(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_FWHM_read,3); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_FWHM +} +//-------------------------------------------------------- +/** + * Read attribute GaussReference related method + * Description: Gaussian of reference params + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 4 + */ +//-------------------------------------------------------- +void OceanOptics::read_GaussReference(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_GaussReference(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_GaussReference) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_GaussReference(Tango::Attribute &attr) entering... "<< endl; + attr.set_value(attr_GaussReference_read,4); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_GaussReference +} +//-------------------------------------------------------- +/** + * Write attribute GaussReference related method + * Description: Gaussian of reference params + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 4 + */ +//-------------------------------------------------------- +void OceanOptics::write_GaussReference(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_GaussReference(Tango::WAttribute &attr) entering... " << endl; + // Retrieve number of write values + int w_length = attr.get_write_value_length(); + + // Retrieve pointer on write values (Do not delete !) + const Tango::DevDouble *w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_GaussReference) ENABLED START -----*/ + attr_GaussReference_read[0] = w_val[0]; + attr_GaussReference_read[1] = w_val[1]; + attr_GaussReference_read[2] = w_val[2]; + attr_GaussReference_read[3] = w_val[3]; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_GaussReference +} +//-------------------------------------------------------- +/** + * Read attribute DataReference related method + * Description: A reference curve + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ +//-------------------------------------------------------- +void OceanOptics::read_DataReference(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_DataReference(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_DataReference) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::attr_DataReference_read(Tango::Attribute &attr) entering... "<< endl; + if(pReferenceData) + { + //attr_DataReference_read = (Tango::DevLong *)&(pReferenceData[0 + WaveLenght2Pix(attr_RegionOfInterest_read[0])]); + attr_DataReference_read = (Tango::DevDouble *)&(pReferenceData[0 + RegionOfInterestStartPix]); + //attr.set_value(attr_DataReference_read,WaveLenght2Pix(attr_RegionOfInterest_read[1]) - WaveLenght2Pix(attr_RegionOfInterest_read[0])); + attr.set_value(attr_DataReference_read,RegionOfInterestEndPix - RegionOfInterestStartPix + 1); + } + else + attr.set_quality(Tango::ATTR_INVALID); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_DataReference +} +//-------------------------------------------------------- +/** + * Write attribute DataReference related method + * Description: A reference curve + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ +//-------------------------------------------------------- +void OceanOptics::write_DataReference(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_DataReference(Tango::WAttribute &attr) entering... " << endl; + // Retrieve number of write values + int w_length = attr.get_write_value_length(); + + // Retrieve pointer on write values (Do not delete !) + const Tango::DevDouble *w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_DataReference) ENABLED START -----*/ + if((attr.get_write_value_length() != RegionOfInterestEndPix - RegionOfInterestStartPix + 1) && + (attr.get_write_value_length() != NumPixel)) + { + ostringstream tmp; + tmp << "Accepting attribute size = " << NumPixel << " or " << RegionOfInterestEndPix - RegionOfInterestStartPix + 1 << ends; + Tango::Except::throw_exception( + (const char *) "Wrong size", + tmp.str(), + (const char *) "OceanOptics::write_DataReference()", Tango::ERR); + } if(attr.get_write_value_length() == RegionOfInterestEndPix - RegionOfInterestStartPix + 1) + { + for(unsigned int i=0; i<RegionOfInterestStartPix; i++) + pReferenceData[i] = 0; + for(unsigned int i=RegionOfInterestStartPix; i< RegionOfInterestEndPix + 1; i++) + pReferenceData[i] = w_val[i-RegionOfInterestStartPix]; + for(unsigned int i=RegionOfInterestEndPix + 1; i<NumPixel; i++) + pReferenceData[i] = 0; + } + else if(attr.get_write_value_length() == NumPixel) + { + for(unsigned int i=0; i< NumPixel; i++) + pReferenceData[i] = w_val[i]; + } + + ofstream fd; //startup file + fd.open(dataReferenceFile.c_str()); + if (!fd) + { + stringstream tmp; + tmp << "Cannot open Data Reference default file " << dataReferenceFile<< " err:" << strerror(errno) << endl; + INFO_STREAM << "OceanOptics::write_DataReference(): " << tmp.str(); + } + else + { + DEBUG_STREAM << "OceanOptics::write_DataReference(): file " << dataReferenceFile << " opened successfully" << endl; + for(int i=0; i<NumPixel; i++) + { + fd << pReferenceData[i] << endl; + } + fd.close(); + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_DataReference +} +//-------------------------------------------------------- +/** + * Read attribute IntensityCalibration related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 10000 + */ +//-------------------------------------------------------- +void OceanOptics::read_IntensityCalibration(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_IntensityCalibration(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_IntensityCalibration) ENABLED START -----*/ + // Set the attribute value + attr.set_value(attr_IntensityCalibration_read, NumPixel); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_IntensityCalibration +} +//-------------------------------------------------------- +/** + * Write attribute IntensityCalibration related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 10000 + */ +//-------------------------------------------------------- +void OceanOptics::write_IntensityCalibration(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "OceanOptics::write_IntensityCalibration(Tango::WAttribute &attr) entering... " << endl; + // Retrieve number of write values + int w_length = attr.get_write_value_length(); + + // Retrieve pointer on write values (Do not delete !) + const Tango::DevDouble *w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(OceanOptics::write_IntensityCalibration) ENABLED START -----*/ + if(w_length != NumPixel) + { + ostringstream tmp; + tmp << "Expected size is " << NumPixel << " but read " << w_length << ends; + Tango::Except::throw_exception( + (const char *) "Wrong size", + tmp.str(), + (const char *) "OceanOptics::write_IntensityCalibration()", Tango::ERR); + } + for(int i=0; i<w_length; i++) + { + attr_IntensityCalibration_read[i] = w_val[i]; + } + save_intensity_cal_file(intensityCalibrationFile); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::write_IntensityCalibration +} +//-------------------------------------------------------- +/** + * Read attribute NoiseProfile related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ +//-------------------------------------------------------- +void OceanOptics::read_NoiseProfile(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_NoiseProfile(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_NoiseProfile) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_Data(Tango::Attribute &attr) entering... "<< endl; +#ifdef _NON_AVERAGE + if(pNoiseMask) + { + attr_Data_read = (Tango::DevLong *)&(pNoiseMask[0 + attr_RegionOfInterest_read[0]]); + attr.set_value(attr_NoiseMask_read,attr_RegionOfInterest_read[1] - attr_RegionOfInterest_read[0]); + } +#else + if(pNoiseMask_avg) + { + attr_NoiseProfile_read = (Tango::DevDouble *)&(pNoiseMask_avg[0 + RegionOfInterestStartPix]); + attr.set_value(attr_NoiseProfile_read,RegionOfInterestEndPix - RegionOfInterestStartPix + 1); + } +#endif + else + attr.set_quality(Tango::ATTR_INVALID); + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_NoiseProfile +} +//-------------------------------------------------------- +/** + * Read attribute Wave related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ +//-------------------------------------------------------- +void OceanOptics::read_Wave(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_Wave(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_Wave) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_Wave(Tango::Attribute &attr) entering... "<< endl; +#ifdef _NON_AVERAGE + if(pLiveData) + { + attr_Wave_read = (Tango::DevLong *)&(pLiveData[0 + attr_RegionOfInterest_read[0]]); + attr.set_value(attr_Wave_read,attr_RegionOfInterest_read[1] - attr_RegionOfInterest_read[0]); + } +#else + if(pLiveData_avg) + { + //DEBUG_STREAM << "OceanOptics::read_Wave() ROIStartPix"<<RegionOfInterestStartPix<<" ROIEndPix="<<RegionOfInterestEndPix<<" size="<<RegionOfInterestEndPix - RegionOfInterestStartPix + 1<< endl; + //attr_Wave_read = (Tango::DevLong *)&(pLiveData_avg[0 + WaveLenght2Pix(attr_RegionOfInterest_read[0])]); + attr_Wave_read = (Tango::DevDouble *)&(pLiveData_avg[0 + RegionOfInterestStartPix]); + //attr.set_value(attr_Wave_read,WaveLenght2Pix(attr_RegionOfInterest_read[1]) - WaveLenght2Pix(attr_RegionOfInterest_read[0])); + attr.set_value(attr_Wave_read,RegionOfInterestEndPix - RegionOfInterestStartPix + 1); + } +#endif + else + attr.set_quality(Tango::ATTR_INVALID); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_Wave +} +//-------------------------------------------------------- +/** + * Read attribute Lambda related method + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ +//-------------------------------------------------------- +void OceanOptics::read_Lambda(Tango::Attribute &attr) +{ + DEBUG_STREAM << "OceanOptics::read_Lambda(Tango::Attribute &attr) entering... " << endl; + /*----- PROTECTED REGION ID(OceanOptics::read_Lambda) ENABLED START -----*/ + //DEBUG_STREAM << "OceanOptics::read_Lambda(Tango::Attribute &attr) entering... "<< endl; +#ifdef _NON_AVERAGE + if(pLiveData) + { + attr_Lambda_read = (Tango::DevLong *)&(pLiveData[0 + attr_RegionOfInterest_read[0]]); + attr.set_value(attr_Lambda_read,attr_RegionOfInterest_read[1] - attr_RegionOfInterest_read[0]); + } +#else + if(pLiveData_avg) + { + //DEBUG_STREAM << "OceanOptics::read_Data() ROIStartPix"<<RegionOfInterestStartPix<<" ROIEndPix="<<RegionOfInterestEndPix<<" size="<<RegionOfInterestEndPix - RegionOfInterestStartPix + 1<< endl; + //attr_Lambda_read = (Tango::DevLong *)&(x_values[0 + WaveLenght2Pix(attr_RegionOfInterest_read[0])]); + attr_Lambda_read = (Tango::DevDouble *)&(x_values[0 + RegionOfInterestStartPix]); + //attr.set_value(attr_Lambda_read,WaveLenght2Pix(attr_RegionOfInterest_read[1]) - WaveLenght2Pix(attr_RegionOfInterest_read[0])); + attr.set_value(attr_Lambda_read,RegionOfInterestEndPix - RegionOfInterestStartPix + 1); + } +#endif + else + attr.set_quality(Tango::ATTR_INVALID); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::read_Lambda +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::add_dynamic_attributes() + * Description : Create the dynamic attributes if any + * for specified device. + */ +//-------------------------------------------------------- +void OceanOptics::add_dynamic_attributes() +{ + /*----- PROTECTED REGION ID(OceanOptics::add_dynamic_attributes) ENABLED START -----*/ + + // Add your own code to create and add dynamic attributes if any + + /*----- PROTECTED REGION END -----*/ // OceanOptics::add_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Command GetVersion related method + * Description: Returns serial number + * + * @returns serial number + */ +//-------------------------------------------------------- +Tango::DevString OceanOptics::get_version() +{ + Tango::DevString argout; + DEBUG_STREAM << "OceanOptics::GetVersion() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::get_version) ENABLED START -----*/ + + // Add your own code + // 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) + //------------------------------------------------------------ + // Add your own code to control device here + DEBUG_STREAM << "OceanOptics::get_version(): entering... !" << endl; + string resp; + bool ret = 0;//TODO: m_usbCCD.GetSerialNum(resp); + DEBUG_STREAM << "OceanOptics::get_version(): after GetSerialNum" << endl; + if(!ret) + { + INFO_STREAM << "OceanOptics::get_version() error getting serial num" << endl; + argout = CORBA::string_dup(" "); + } + else + { + argout = CORBA::string_dup(resp.c_str()); + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_version + return argout; +} +//-------------------------------------------------------- +/** + * Command Stop related method + * Description: Reset the CCD: + * stops the current readout, + * initiates the internal DLL variables, + * stops data transfer + * + */ +//-------------------------------------------------------- +void OceanOptics::stop() +{ + DEBUG_STREAM << "OceanOptics::Stop() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::stop) ENABLED START -----*/ + + // Add your own code + if(get_state() == Tango::FAULT) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) "OceanOptics::stop()", Tango::ERR); + } + + // Add your own code to control device here + live_mode = false; + init_live_mode = false; + measure_mode = false; + init_measure_mode = false; + omni_thread::sleep(0,200000000); //0.2 s + //loop->mutex_sleep->lock(); + loop->pausesec = 1; + loop->pausenano = 0; + //loop->mutex_sleep->unlock(); + set_state(Tango::ON); + set_status("Ready"); + /*if(!m_usbCCD.Reset()) + { + TangoSys_MemStream out_stream; + out_stream << "Error resetting CCD" << ends; + Tango::Except::throw_exception( + (const char *) "Error resetting CCD", + out_stream.str(), + (const char *) "OceanOptics::stop()", Tango::ERR); + }*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::stop +} +//-------------------------------------------------------- +/** + * Command StartSingle related method + * Description: Start single (NumReadout frames) acquisition fron the CCD + * + */ +//-------------------------------------------------------- +void OceanOptics::start_single() +{ + DEBUG_STREAM << "OceanOptics::StartSingle() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::start_single) ENABLED START -----*/ + + // Add your own code + if(get_state() != Tango::ON) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) "OceanOptics::start_measuring()", Tango::ERR); + } + set_state(Tango::RUNNING); + set_status("Single Mode"); + live_mode = false; + init_live_mode = false; + acquire_noise_mode = false; + init_acquire_noise_mode = false; + measure_mode = true; + init_measure_mode = true; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::start_single +} +//-------------------------------------------------------- +/** + * Command StartContinuous related method + * Description: Start acquisition in Continuous mode + * + */ +//-------------------------------------------------------- +void OceanOptics::start_continuous() +{ + DEBUG_STREAM << "OceanOptics::StartContinuous() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::start_continuous) ENABLED START -----*/ + + // Add your own code + if(get_state() != Tango::ON) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) "OceanOptics::start_live()", Tango::ERR); + } + clock_gettime(CLOCK_MONOTONIC,&last_read); + set_state(Tango::RUNNING); + set_status("Continuous Mode"); + loop->min_fit_time = 1000000000.0; + loop->max_fit_time = 0; + loop->avg_fit_time = 0; + loop->tot_fit_time = 0; + loop->fit_counter = 0; + measure_mode = false; + init_measure_mode = false; + acquire_noise_mode = false; + init_acquire_noise_mode = false; + live_mode = true; + init_live_mode = true; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::start_continuous +} +//-------------------------------------------------------- +/** + * Command GetLastData related method + * Description: returns the last argin frames saved + * + * @param argin number of frames to return + * @returns + */ +//-------------------------------------------------------- +Tango::DevVarDoubleArray *OceanOptics::get_last_data(Tango::DevLong argin) +{ + Tango::DevVarDoubleArray *argout; + DEBUG_STREAM << "OceanOptics::GetLastData() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::get_last_data) ENABLED START -----*/ + + // Add your own code + // 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) + //------------------------------------------------------------ + if(get_state() == Tango::FAULT) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) "OceanOptics::get_last_data()", Tango::ERR); + } + argout = new Tango::DevVarDoubleArray(); + DEBUG_STREAM << "OceanOptics::get_last_data(): entering... FrameBufferIndex=" << FrameBufferIndex << endl; + + // Add your own code to control device here + if(argin > nFramesBuffered || argin < 1) + { + TangoSys_MemStream out_stream; + out_stream << "MAx number of frames=" << nFramesBuffered << ends; + Tango::Except::throw_exception( + (const char *) "Argin out of bounds", + out_stream.str(), + (const char *) "OceanOptics::get_last_data()", Tango::ERR); + } + //int region_size = RegionOfInterestEndPix - RegionOfInterestStartPix; + //argout->length(argin * NumPixel); + int j; + DEBUG_STREAM << "OceanOptics::get_last_data() (FrameBufferIndex - argin)=" << ((int)FrameBufferIndex - argin) << endl; + if(((int)FrameBufferIndex - argin) >= 0) + { + j = (int)FrameBufferIndex - argin; + } + else + { + j = nFramesBuffered - (argin - FrameBufferIndex); + } + int region_size = RegionOfInterestEndPix - RegionOfInterestStartPix + 1; + argout->length(argin * region_size); + DEBUG_STREAM << "OceanOptics::get_last_data: region size=" << region_size << " new data_counter=" << argin * region_size << endl; + for(int i=0; i < argin; i++) + { + //DEBUG_STREAM << "OceanOptics::get_last_data() copying DATA! from " << j*NumPixel << " to " << i*NumPixel << endl; + //copying only region of interest: + //i*region_size: beginning of frame=i reduced to dimension region_size + //j*NumPixel: beginning of original frame=j of dimension NumPixel + //j*NumPixel + attr_RegionOfInterest_read[0]: beginning of region of interest in frame=j + memcpy(&((*argout)[i*region_size]),&(pFrameBuffer[j*NumPixel + RegionOfInterestStartPix]), region_size*sizeof(double)); + j = (j + 1) % nFramesBuffered; + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_last_data + return argout; +} +//-------------------------------------------------------- +/** + * Command AcquireNoise related method + * Description: Acquire argin frames of background noise + * + * @param argin Number of frames to acquire as noise + */ +//-------------------------------------------------------- +void OceanOptics::acquire_noise(Tango::DevLong argin) +{ + DEBUG_STREAM << "OceanOptics::AcquireNoise() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::acquire_noise) ENABLED START -----*/ + + // Add your own code + if(get_state() != Tango::ON) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + (const char *) "OceanOptics::acquire_noise()", Tango::ERR); + } + if(argin <= 0) + { + TangoSys_MemStream out_stream; + out_stream << "Number of frames has to be > 0" << ends; + Tango::Except::throw_exception( + (const char *) "Wrong argument", + out_stream.str(), + (const char *) "OceanOptics::acquire_noise()", Tango::ERR); + } + noise_frames = argin; + noise_frames_counter = 0; + set_state(Tango::RUNNING); + set_status("Acquiring noise"); + live_mode = false; + init_live_mode = false; + measure_mode = false; + init_measure_mode = false; + acquire_noise_mode = true; + init_acquire_noise_mode = true; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::acquire_noise +} +//-------------------------------------------------------- +/** + * Command SaveReferenceData related method + * Description: Save current curve as reference curve + * + */ +//-------------------------------------------------------- +void OceanOptics::save_reference_data() +{ + DEBUG_STREAM << "OceanOptics::SaveReferenceData() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::save_reference_data) ENABLED START -----*/ + + // Add your own code + ofstream fd; //startup file + fd.open(dataReferenceFile.c_str()); + for(unsigned int i=0; i<NumPixel; i++) + { +#ifdef _NON_AVERAGE + if(pLiveData && pReferenceData) + { + pReferenceData[i] = pLiveData[i]; + if (fd) + { + fd << (long)pReferenceData[i] << endl; + } + } +#else + if(pLiveData_avg && pReferenceData) + { + pReferenceData[i] = pLiveData_avg[i]; + if (fd) + { + fd << (double)pReferenceData[i] << endl; + } + } +#endif + } + + if (!fd) + { + stringstream tmp; + tmp << "Cannot save on Data Reference file " << dataReferenceFile<< " err:" << strerror(errno) << endl; + INFO_STREAM << "OceanOptics::save_reference_data(): " << tmp.str(); + Tango::Except::throw_exception( + (const char *) "File opening exception", + tmp.str(), + (const char *) "OceanOptics::save_reference_data()", Tango::ERR); + } + else + { + fd.close(); + } + + /*----- PROTECTED REGION END -----*/ // OceanOptics::save_reference_data +} +//-------------------------------------------------------- +/** + * Command OpenShutter related method + * Description: + * + */ +//-------------------------------------------------------- +void OceanOptics::open_shutter() +{ + DEBUG_STREAM << "OceanOptics::OpenShutter() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::open_shutter) ENABLED START -----*/ + + // Add your own code + if(get_state() == Tango::FAULT) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + __func__, Tango::ERR); + } + if(get_state() != Tango::ON && get_state() != Tango::ALARM) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + __func__, Tango::ERR); + } + int error; + +#if _SEABREEZE_API > 1 + unsigned long integr_time_usec = (unsigned long)(w_val*1000); + sbapi_spectrometer_set_integration_time_micros (device_id, spectrometer_id, &error, integr_time_usec); +#else + unsigned char opened = 1; + seabreeze_set_shutter_open(device_id, &error, opened); +#endif + if(error) + { + char error_str[128]; +#if _SEABREEZE_API > 1 +#else + seabreeze_get_error_string(error, error_str, 128); +#endif + printf("Error is is %d [%s]\n", error, error_str); + TangoSys_MemStream out_stream; + out_stream << "Error writing seabreeze_set_shutter_open=" << 1 << " err=" << error_str; + Tango::Except::throw_exception( + (const char *) "Error", + out_stream.str(), + __func__, Tango::ERR); + } + /*----- PROTECTED REGION END -----*/ // OceanOptics::open_shutter +} +//-------------------------------------------------------- +/** + * Command CloseShutter related method + * Description: + * + */ +//-------------------------------------------------------- +void OceanOptics::close_shutter() +{ + DEBUG_STREAM << "OceanOptics::CloseShutter() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::close_shutter) ENABLED START -----*/ + + // Add your own code + if(get_state() == Tango::FAULT) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + __func__, Tango::ERR); + } + if(get_state() != Tango::ON && get_state() != Tango::ALARM) + { + TangoSys_MemStream out_stream; + out_stream << "Device not ready, it is in '" << get_status() << "'" << ends; + Tango::Except::throw_exception( + (const char *) "Device not ready", + out_stream.str(), + __func__, Tango::ERR); + } + int error; + +#if _SEABREEZE_API > 1 + unsigned long integr_time_usec = (unsigned long)(w_val*1000); + sbapi_spectrometer_set_integration_time_micros (device_id, spectrometer_id, &error, integr_time_usec); +#else + unsigned char opened = 0; + seabreeze_set_shutter_open(device_id, &error, opened); +#endif + if(error) + { + char error_str[128]; +#if _SEABREEZE_API > 1 +#else + seabreeze_get_error_string(error, error_str, 128); +#endif + printf("Error is is %d [%s]\n", error, error_str); + TangoSys_MemStream out_stream; + out_stream << "Error writing seabreeze_set_shutter_open=" << 0 << " err=" << error_str; + Tango::Except::throw_exception( + (const char *) "Error", + out_stream.str(), + __func__, Tango::ERR); + } + /*----- PROTECTED REGION END -----*/ // OceanOptics::close_shutter +} +//-------------------------------------------------------- +/** + * Command GetData related method + * Description: + * + * @param argin + * @returns + */ +//-------------------------------------------------------- +Tango::DevVarDoubleArray *OceanOptics::get_data(const Tango::DevVarLongArray *argin) +{ + Tango::DevVarDoubleArray *argout; + DEBUG_STREAM << "OceanOptics::GetData() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::get_data) ENABLED START -----*/ + + // Add your own code + if(!(*attr_RtMode_read) && ((*argin)[0] == BUF_GET_BUNCH_MODE || (*argin)[0] == BUF_GET_BUNCH_UNIQUE_MODE || (*argin)[0] == BUF_GET_BUNCH_BUNCH_MODE)) + Tango::Except::throw_exception( + "NON RT MODE", + "Supported only in RT mode", + __func__, Tango::ERR); + long buf_idx[2], num_samples; + unsigned char unique; + + tbuffer::tcheck_get_data_param<tbuffer::_data_array<double> >(argin, &tbuf_array, buf_idx, &num_samples, &unique); + argout = new Tango::DevVarDoubleArray(); + num_samples *= tbuf_array.get_data_size(); + argout->length(num_samples); + tbuffer::_data_array<double> foo; + tbuf_array.read_data(unique, buf_idx, &(*argout)[0], &foo); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_data + return argout; +} +//-------------------------------------------------------- +/** + * Command GetGaussFitCenter related method + * Description: + * + * @param argin + * @returns + */ +//-------------------------------------------------------- +Tango::DevVarDoubleArray *OceanOptics::get_gauss_fit_center(const Tango::DevVarLongArray *argin) +{ + Tango::DevVarDoubleArray *argout; + DEBUG_STREAM << "OceanOptics::GetGaussFitCenter() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::get_gauss_fit_center) ENABLED START -----*/ + + // Add your own code + if(!(*attr_RtMode_read) && ((*argin)[0] == BUF_GET_BUNCH_MODE || (*argin)[0] == BUF_GET_BUNCH_UNIQUE_MODE || (*argin)[0] == BUF_GET_BUNCH_BUNCH_MODE)) + Tango::Except::throw_exception( + "NON RT MODE", + "Supported only in RT mode", + __func__, Tango::ERR); + long buf_idx[2], num_samples; + unsigned char unique; + + tbuffer::tcheck_get_data_param<double>(argin, &tbuf[BUF_ID_GAUSS_CENTER], buf_idx, &num_samples, &unique); + argout = new Tango::DevVarDoubleArray(); + argout->length(num_samples); + tbuf[BUF_ID_GAUSS_CENTER].read_data_calib(unique, buf_idx, &(*argout)[0], 0, 1, 0); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_gauss_fit_center + return argout; +} +//-------------------------------------------------------- +/** + * Command GetGaussFitWidth related method + * Description: + * + * @param argin + * @returns + */ +//-------------------------------------------------------- +Tango::DevVarDoubleArray *OceanOptics::get_gauss_fit_width(const Tango::DevVarLongArray *argin) +{ + Tango::DevVarDoubleArray *argout; + DEBUG_STREAM << "OceanOptics::GetGaussFitWidth() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::get_gauss_fit_width) ENABLED START -----*/ + + // Add your own code + if(!(*attr_RtMode_read) && ((*argin)[0] == BUF_GET_BUNCH_MODE || (*argin)[0] == BUF_GET_BUNCH_UNIQUE_MODE || (*argin)[0] == BUF_GET_BUNCH_BUNCH_MODE)) + Tango::Except::throw_exception( + "NON RT MODE", + "Supported only in RT mode", + __func__, Tango::ERR); + long buf_idx[2], num_samples; + unsigned char unique; + + tbuffer::tcheck_get_data_param<double>(argin, &tbuf[BUF_ID_GAUSS_WIDTH], buf_idx, &num_samples, &unique); + argout = new Tango::DevVarDoubleArray(); + argout->length(num_samples); + tbuf[BUF_ID_GAUSS_WIDTH].read_data_calib(unique, buf_idx, &(*argout)[0], 0, 1, 0); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_gauss_fit_width + return argout; +} +//-------------------------------------------------------- +/** + * Command GetFWHMCenter related method + * Description: + * + * @param argin + * @returns + */ +//-------------------------------------------------------- +Tango::DevVarDoubleArray *OceanOptics::get_fwhmcenter(const Tango::DevVarLongArray *argin) +{ + Tango::DevVarDoubleArray *argout; + DEBUG_STREAM << "OceanOptics::GetFWHMCenter() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::get_fwhmcenter) ENABLED START -----*/ + + // Add your own code + if(!(*attr_RtMode_read) && ((*argin)[0] == BUF_GET_BUNCH_MODE || (*argin)[0] == BUF_GET_BUNCH_UNIQUE_MODE || (*argin)[0] == BUF_GET_BUNCH_BUNCH_MODE)) + Tango::Except::throw_exception( + "NON RT MODE", + "Supported only in RT mode", + __func__, Tango::ERR); + long buf_idx[2], num_samples; + unsigned char unique; + + tbuffer::tcheck_get_data_param<double>(argin, &tbuf[BUF_ID_FWHM_CENTER], buf_idx, &num_samples, &unique); + argout = new Tango::DevVarDoubleArray(); + argout->length(num_samples); + tbuf[BUF_ID_FWHM_CENTER].read_data_calib(unique, buf_idx, &(*argout)[0], 0, 1, 0); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_fwhmcenter + return argout; +} +//-------------------------------------------------------- +/** + * Command GetFWHMWidth related method + * Description: + * + * @param argin + * @returns + */ +//-------------------------------------------------------- +Tango::DevVarDoubleArray *OceanOptics::get_fwhmwidth(const Tango::DevVarLongArray *argin) +{ + Tango::DevVarDoubleArray *argout; + DEBUG_STREAM << "OceanOptics::GetFWHMWidth() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::get_fwhmwidth) ENABLED START -----*/ + + // Add your own code + if(!(*attr_RtMode_read) && ((*argin)[0] == BUF_GET_BUNCH_MODE || (*argin)[0] == BUF_GET_BUNCH_UNIQUE_MODE || (*argin)[0] == BUF_GET_BUNCH_BUNCH_MODE)) + Tango::Except::throw_exception( + "NON RT MODE", + "Supported only in RT mode", + __func__, Tango::ERR); + long buf_idx[2], num_samples; + unsigned char unique; + + tcheck_get_data_param(argin, &tbuf[BUF_ID_FWHM_WIDTH], buf_idx, &num_samples, &unique); + argout = new Tango::DevVarDoubleArray(); + argout->length(num_samples); + tbuf[BUF_ID_FWHM_WIDTH].read_data_calib(unique, buf_idx, &(*argout)[0], 0, 1, 0); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_fwhmwidth + return argout; +} +//-------------------------------------------------------- +/** + * Command ExportWavelength related method + * Description: + * + */ +//-------------------------------------------------------- +void OceanOptics::export_wavelength() +{ + DEBUG_STREAM << "OceanOptics::ExportWavelength() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::export_wavelength) ENABLED START -----*/ + + // Add your own code + if(wavelengthAttr.size() != 2) + { + Tango::Except::throw_exception( + (const char *) "Beam Status Server Not Set", + (const char *) "Beam Status Server Not Set", + (const char *) "SolarS100::export_wavelength()", Tango::ERR); + } + Tango::DeviceProxy *devbeamstatus; + devbeamstatus = new Tango::DeviceProxy(wavelengthAttr[0]); + try + { + Tango::DeviceAttribute Din(wavelengthAttr[1],*attr_Center_read); + devbeamstatus->write_attribute(Din); + } + catch(Tango::DevFailed e) + { + delete devbeamstatus; + stringstream tmp; + tmp << "Failed to write attribute, err=" <<e.errors[0].desc; + Tango::Except::re_throw_exception(e, + (const char *) "Failed", + tmp.str(), + (const char *) "SolarS100::export_wavelength()", Tango::ERR); + } + delete devbeamstatus; + + /*----- PROTECTED REGION END -----*/ // OceanOptics::export_wavelength +} +//-------------------------------------------------------- +/** + * Command GetArea related method + * Description: + * + * @param argin + * @returns + */ +//-------------------------------------------------------- +Tango::DevVarDoubleArray *OceanOptics::get_area(const Tango::DevVarLongArray *argin) +{ + Tango::DevVarDoubleArray *argout; + DEBUG_STREAM << "OceanOptics::GetArea() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::get_area) ENABLED START -----*/ + + // Add your own code + if(!(*attr_RtMode_read) && ((*argin)[0] == BUF_GET_BUNCH_MODE || (*argin)[0] == BUF_GET_BUNCH_UNIQUE_MODE || (*argin)[0] == BUF_GET_BUNCH_BUNCH_MODE)) + Tango::Except::throw_exception( + "NON RT MODE", + "Supported only in RT mode", + __func__, Tango::ERR); + long buf_idx[2], num_samples; + unsigned char unique; + + tbuffer::tcheck_get_data_param<double>(argin, &tbuf[BUF_ID_AREA], buf_idx, &num_samples, &unique); + argout = new Tango::DevVarDoubleArray(); + argout->length(num_samples); + tbuf[BUF_ID_AREA].read_data_calib(unique, buf_idx, &(*argout)[0], 0, 1, 0); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_area + return argout; +} +//-------------------------------------------------------- +/** + * Command GetWave related method + * Description: + * + * @param argin + * @returns + */ +//-------------------------------------------------------- +Tango::DevVarDoubleArray *OceanOptics::get_wave(const Tango::DevVarLongArray *argin) +{ + Tango::DevVarDoubleArray *argout; + DEBUG_STREAM << "OceanOptics::GetWave() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::get_wave) ENABLED START -----*/ + + // Add your own code + if(!(*attr_RtMode_read) && ((*argin)[0] == BUF_GET_BUNCH_MODE || (*argin)[0] == BUF_GET_BUNCH_UNIQUE_MODE || (*argin)[0] == BUF_GET_BUNCH_BUNCH_MODE)) + Tango::Except::throw_exception( + "NON RT MODE", + "Supported only in RT mode", + __func__, Tango::ERR); + long buf_idx[2], num_samples; + unsigned char unique; + + tbuffer::tcheck_get_data_param<tbuffer::_data_array<double> >(argin, &tbuf_array_w, buf_idx, &num_samples, &unique); + argout = new Tango::DevVarDoubleArray(); + num_samples *= tbuf_array_w.get_data_size(); + argout->length(num_samples); + tbuffer::_data_array<double> foo; + tbuf_array_w.read_data(unique, buf_idx, &(*argout)[0], &foo); + + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_wave + return argout; +} +//-------------------------------------------------------- +/** + * Command GetLambda related method + * Description: + * + * @param argin + * @returns + */ +//-------------------------------------------------------- +Tango::DevVarDoubleArray *OceanOptics::get_lambda(const Tango::DevVarLongArray *argin) +{ + Tango::DevVarDoubleArray *argout; + DEBUG_STREAM << "OceanOptics::GetLambda() - " << device_name << endl; + /*----- PROTECTED REGION ID(OceanOptics::get_lambda) ENABLED START -----*/ + + // Add your own code + if(!(*attr_RtMode_read) && ((*argin)[0] == BUF_GET_BUNCH_MODE || (*argin)[0] == BUF_GET_BUNCH_UNIQUE_MODE || (*argin)[0] == BUF_GET_BUNCH_BUNCH_MODE)) + Tango::Except::throw_exception( + "NON RT MODE", + "Supported only in RT mode", + __func__, Tango::ERR); + long buf_idx[2], num_samples; + unsigned char unique; + + tbuffer::tcheck_get_data_param<tbuffer::_data_array<double> >(argin, &tbuf_array_l, buf_idx, &num_samples, &unique); + argout = new Tango::DevVarDoubleArray(); + num_samples *= tbuf_array_l.get_data_size(); + argout->length(num_samples); + tbuffer::_data_array<double> foo; + tbuf_array_l.read_data(unique, buf_idx, &(*argout)[0], &foo); + +#if 0 + size_t num_samples = RegionOfInterestEndPix - RegionOfInterestStartPix + 1; + + argout = new Tango::DevVarDoubleArray(); + argout->length(num_samples); + for(size_t i=0; i<num_samples; i++) + (*argout)[i] = x_values[i+RegionOfInterestStartPix]; +#endif + /*----- PROTECTED REGION END -----*/ // OceanOptics::get_lambda + return argout; +} +//-------------------------------------------------------- +/** + * Method : OceanOptics::add_dynamic_commands() + * Description : Create the dynamic commands if any + * for specified device. + */ +//-------------------------------------------------------- +void OceanOptics::add_dynamic_commands() +{ + /*----- PROTECTED REGION ID(OceanOptics::add_dynamic_commands) ENABLED START -----*/ + + // Add your own code to create and add dynamic commands if any + + /*----- PROTECTED REGION END -----*/ // OceanOptics::add_dynamic_commands +} + +/*----- PROTECTED REGION ID(OceanOptics::namespace_ending) ENABLED START -----*/ + +// Additional Methods +void OceanOptics::init_data(bool reconnection = false) +{ + /*if(!m_usbCCD.GetParameters()) + INFO_STREAM << "OceanOptics::OceanOptics(): error in GetParameters()" << endl; + NumPixel = m_usbCCD.m_nNumPixelsH * m_usbCCD.m_nNumPixelsV;*/ + int error; + int flag; +#if _SEABREEZE_API > 1 + NumPixel = sbapi_spectrometer_get_formatted_spectrum_length(device_id,spectrometer_id, &error); +#else + NumPixel = seabreeze_get_formatted_spectrum_length(device_id, &error); +#endif + attr_NumPixels_read[0] = NumPixel; + attr_NumPixels_read[1] = 1; + + if(x_values != NULL) + { + delete [] x_values; + x_values = NULL; + } + x_values = new Tango::DevDouble[NumPixel]; + //Tango::DbData db_data_get; + try { + /* db_data_get.push_back(Tango::DbDatum("Data")); + get_db_device()->get_attribute_property(db_data_get); + vector<Tango::DevDouble> xval; + for(unsigned int i=0; i<db_data_get.size(); i++) + { + long nb_prop; + //string &att_name = db_data[i].name; + db_data_get[i] >> nb_prop; + i++; + for(int k=0; k < nb_prop; k++) + { + string &prop_name = db_data_get[i].name; + if(prop_name == "x_values") + { + db_data_get[i] >> xval; + break; + } + } + } + if(xval.size() > NumPixel) + { + WARN_STREAM << "OceanOptics::OceanOptics(): x_values property size=" << xval.size() << " greater than frame size=" << NumPixel << endl; + } + else + { + DEBUG_STREAM << "OceanOptics::OceanOptics(): x_values property size=" << xval.size() << ", frame size=" << NumPixel << endl; + for(unsigned int i=0; i<xval.size(); i++) + { + x_values[i] = (Tango::DevDouble)xval[i]; + } + //TEMP: if missing some xval, fill continuing with linear interpulation + if(xval.size() < NumPixel) + { + for(unsigned int i=xval.size(); i<NumPixel; i++) + { + x_values[i] = (Tango::DevDouble)(xval[xval.size()-1] + (xval[xval.size()-1] - xval[xval.size()-2])*(i-xval.size()+1)); + DEBUG_STREAM << "OceanOptics::OceanOptics(): added missing x_values: x_values["<<i<<"]=" << x_values[i] << endl; + } + } + }*/ + Tango::DbDatum db_wavelen("Data"); //TODO: attribute name, property name, ... + db_wavelen << (short)1; //1 attribute properties in "Wavelength" + Tango::DbDatum db_values("x_values"); //TODO: attribute name, property name, ... + Tango::DbData db_data_set; +#if _SEABREEZE_API > 1 + /*TODO: lenght*/flag = sbapi_spectrometer_get_wavelengths(device_id, spectrometer_id, &error, x_values, NumPixel); + if(flag != NumPixel) + { + INFO_STREAM << __func__ << ": sbapi_spectrometer_get_wavelengths returned length="<<flag<<" but NumPixel="<< NumPixel << endl; + } +#else + flag = seabreeze_get_wavelengths(device_id, &error, x_values, NumPixel); +#endif + vector<Tango::DevDouble> xval; + for(unsigned int i=0; i<NumPixel; i++) + { + x_values[i] = floor(x_values[i]*1000.0)*0.001; + //DEBUG_STREAM << "OceanOptics::OceanOptics(): x_values["<<i<<"]=" << x_values[i] << endl; + xval.push_back(x_values[i]); + } + db_values << xval; + db_data_set.push_back(db_wavelen); + db_data_set.push_back(db_values); + get_db_device()->put_attribute_property(db_data_set); + } + catch(Tango::DevFailed e) { + string temp; + temp = e.errors[0].desc; + WARN_STREAM << "OceanOptics::OceanOptics() error setting x_values attribute property: " << temp << endl; + } + if(pLiveData_avg != NULL) + { + delete [] pLiveData_avg; + pLiveData_avg = NULL; + } + pLiveData_avg = new double[NumPixel]; + memset(pLiveData_avg,0,NumPixel*sizeof(double)); + if(pNoiseMask_avg != NULL) + { + delete [] pNoiseMask_avg; + pNoiseMask_avg = NULL; + } + pNoiseMask_avg = new double[NumPixel]; + memset(pNoiseMask_avg,0,NumPixel*sizeof(double)); + if(pReferenceData != NULL) + { + delete [] pReferenceData; + pReferenceData = NULL; + } + pReferenceData = new double[NumPixel]; + memset(pReferenceData,0,NumPixel*sizeof(double)); + + /*defaultEndRegion = (defaultEndRegion > (int)NumPixel) ? NumPixel : + (defaultEndRegion < 0) ? NumPixel : defaultEndRegion; + defaultStartRegion = (defaultStartRegion < 0) ? 0 : + ((defaultStartRegion > (int)NumPixel) ? 0 : + ((defaultStartRegion >= defaultEndRegion) ? defaultEndRegion-1 : defaultStartRegion));*/ + attr_AnalysisRegion_read[0] = attr_RegionOfInterest_read[0] = defaultStartRegion; + RegionOfInterestStartPix = WaveLenght2Pix(attr_RegionOfInterest_read[0]); + DEBUG_STREAM << __func__<<": StartROI="<<defaultStartRegion<<" -> start pix="<<RegionOfInterestStartPix; + while(x_values[RegionOfInterestStartPix] < defaultStartRegion) + { + RegionOfInterestStartPix++; + } + DEBUG_STREAM << __func__<<": ... -> adjusted start pix="<<RegionOfInterestStartPix; + AnalysisRegionStartPix = RegionOfInterestStartPix; + attr_AnalysisRegion_read[1] = attr_RegionOfInterest_read[1] = defaultEndRegion; + RegionOfInterestEndPix = WaveLenght2Pix(attr_RegionOfInterest_read[1]); + DEBUG_STREAM << __func__<<": EndROI="<<defaultEndRegion<<" -> end pix="<<RegionOfInterestEndPix; + while(x_values[RegionOfInterestEndPix] > defaultEndRegion) + { + RegionOfInterestEndPix--; + } + DEBUG_STREAM << __func__<<": ... -> adjusted end pix="<<RegionOfInterestEndPix; + AnalysisRegionEndPix = RegionOfInterestEndPix; + if(defaultGaussRef.size() == 4) + { + int i=0; + for(vector<double>::iterator it = defaultGaussRef.begin(); it != defaultGaussRef.end(); it++) + attr_GaussReference_read[i++] = *it; + /*attr_GaussReference_read[0] = defaultGaussRef[0]; + attr_GaussReference_read[1] = defaultGaussRef[1]; + attr_GaussReference_read[2] = defaultGaussRef[2]; + attr_GaussReference_read[3] = defaultGaussRef[3];*/ + } + else + attr_GaussReference_read[0] = attr_GaussReference_read[1] = attr_GaussReference_read[2] = attr_GaussReference_read[3]= 0; + attr_GaussFit_read[0] = attr_GaussFit_read[1] = attr_GaussFit_read[2] = attr_GaussFit_read[3] = 0; + attr_FWHM_read[0] = attr_FWHM_read[1] = attr_FWHM_read[2] = 0; + *attr_GaussFitCenter_read = 0; + *attr_GaussFitWidth_read = 0; + *attr_FWHMCenter_read = 0; + *attr_FWHMWidth_read = 0; + GaussFit_valid = false; + + Tango::MultiAttribute *attr_list = get_device_attr(); + + vector<double> region_write; + region_write.push_back(x_values[RegionOfInterestStartPix]); + region_write.push_back(x_values[RegionOfInterestEndPix]); + Tango::WAttribute &attr_reg = attr_list->get_w_attr_by_name ("RegionOfInterest"); + attr_reg.set_write_value(region_write,2); + Tango::WAttribute &attr_reg2 = attr_list->get_w_attr_by_name ("AnalysisRegion"); + attr_reg2.set_write_value(region_write,2); + if(reconnection) + { + usleep(500000); + try + { + Tango::WAttribute &attr_reg3 = attr_list->get_w_attr_by_name ("ExposureTime"); + write_ExposureTime(attr_reg3); + }catch (...){} + usleep(100000); + try + { + Tango::WAttribute &attr_reg4 = attr_list->get_w_attr_by_name ("SyncMode"); + write_SyncMode(attr_reg4); + }catch (...){} + usleep(100000); + } + + + if(nFramesBuffered > 0) + { + if(pFrameBuffer != NULL) + { + delete [] pFrameBuffer; + pFrameBuffer = NULL; + } + pFrameBuffer = new double[NumPixel * nFramesBuffered]; + memset(pFrameBuffer,0,NumPixel * nFramesBuffered * sizeof(DWORD)); + } + + + ifstream fd; //startup file + fd.open(dataReferenceFile.c_str()); + if (!fd) + { + stringstream tmp; + tmp << "Cannot open Data Reference default file:" << strerror(errno) << endl; + INFO_STREAM << "OceanOptics::OceanOptics(): " << tmp.str(); + } + else{ + DEBUG_STREAM << "OceanOptics::OceanOptics(): file opened successfully" << endl; + string lineread; + int i=0; + double val; + while(std::getline(fd, lineread, '\n')) + { // Read line by line + if(lineread.length() > 0 && i < NumPixel) + { + sscanf(lineread.c_str(),"%lf",&val); + pReferenceData[i++] = val; + } + } + fd.close(); + } + + fd.open(noiseProfileFile.c_str()); + if (!fd) + { + stringstream tmp; + tmp << "Cannot open Noise Profile default file:" << strerror(errno) << endl; + INFO_STREAM << "OceanOptics::OceanOptics(): " << tmp.str(); + } + else{ + DEBUG_STREAM << "OceanOptics::OceanOptics(): file " << noiseProfileFile << " opened successfully" << endl; + string lineread; + int i=0; + double val; + while(std::getline(fd, lineread, '\n')) + { // Read line by line + if(lineread.length() > 0 && i < NumPixel) + { + sscanf(lineread.c_str(),"%lf",&val); + pNoiseMask_avg[i++] = val; + } + } + fd.close(); + } +} + +unsigned int OceanOptics::WaveLenght2Pix(double val) +{ + if(!x_values || NumPixel==0) + return 0; + double tmp_val; + unsigned int tmp_pix, step; + tmp_pix= (unsigned int)(((double)NumPixel)/2); + step= (unsigned int)(((double)NumPixel)/2); + tmp_val = x_values[tmp_pix]; + //DEBUG_STREAM << "OceanOptics::WaveLenght2Pix: ENTERING: val="<<val<<" tmp_val="<<tmp_val<<" tmp_pix="<<tmp_pix<<" step="<<step<<endl; + if(val <= x_values[0]) + return 0; + else if(val >= x_values[NumPixel-1]) + return NumPixel-1; + while((val != tmp_val) && (step > 1)) + { + step = (unsigned int)((((double)step)/2) + 0.5); //round + //DEBUG_STREAM << "OceanOptics::WaveLenght2Pix: LOOPING: val="<<val<<" tmp_val="<<tmp_val<<" tmp_pix="<<tmp_pix<<" step="<<step<<endl; + if(val > tmp_val) + { + if((((int)tmp_pix) + ((int)step)) < (int)NumPixel) + { + tmp_pix = tmp_pix + step; + } + else + { + //DEBUG_STREAM << "OceanOptics::WaveLenght2Pix("<<val<<"): LOOPING: tmp_pix="<<tmp_pix<<"+step="<<step<<" >=NumPixel="<<NumPixel<<endl; + tmp_pix = NumPixel-1; + //break; + } + } + else if(val < tmp_val) + { + if((((int)tmp_pix) - ((int)step)) >= 0) + { + //DEBUG_STREAM << "OceanOptics::WaveLenght2Pix("<<val<<"): LOOPING: tmp_pix="<<tmp_pix<<"-step="<<step<<" ="<<tmp_pix - step<<" new tmp_val=" << x_values[tmp_pix- step] << endl; + tmp_pix = tmp_pix - step; + } + else + { + //DEBUG_STREAM << "OceanOptics::WaveLenght2Pix("<<val<<"): LOOPING: tmp_pix="<<tmp_pix<<"-step="<<step<<" <=0"<<endl; + tmp_pix = 0; + //break; + } + } + else + { + break; + } + tmp_val = x_values[tmp_pix]; + } + if(step == 1) + { + //DEBUG_STREAM << "OceanOptics::WaveLenght2Pix: LAST TEST: val="<<val<<" tmp_val="<<tmp_val<<" tmp_pix="<<tmp_pix<<" step="<<step<<endl; + if(val > tmp_val) + { + if((((int)tmp_pix) + ((int)step)) < (int)NumPixel) + { + tmp_pix = tmp_pix + step; + } + else + { + //DEBUG_STREAM << "OceanOptics::WaveLenght2Pix("<<val<<"): LAST TEST: tmp_pix="<<tmp_pix<<"+step="<<step<<" >=NumPixel="<<NumPixel<<endl; + tmp_pix = NumPixel-1; + //break; + } + } + else if(val < tmp_val) + { + if((((int)tmp_pix) - ((int)step)) >= 0) + { + //DEBUG_STREAM << "OceanOptics::WaveLenght2Pix("<<val<<"): LAST TEST: tmp_pix="<<tmp_pix<<"-step="<<step<<" ="<<tmp_pix - step<<" new tmp_val=" << x_values[tmp_pix- step] << endl; + tmp_pix = tmp_pix - step; + } + else + { + DEBUG_STREAM << "OceanOptics::WaveLenght2Pix("<<val<<"): LAST TEST: tmp_pix="<<tmp_pix<<"-step="<<step<<" <=0"<<endl; + tmp_pix = 0; + //break; + } + } + } + //DEBUG_STREAM << "OceanOptics::WaveLenght2Pix: EXITING: val="<<val<<" tmp_val="<<tmp_val<<" tmp_pix="<<tmp_pix<<" step="<<step<<endl; + return (unsigned int)tmp_pix; +} +//==== argin: +// DWORD *data_array: sequence of "num_frames" frames +// int dim_frame: dimensione of one frame +// int x_start_analysis: start of region of analysis within the frame +// int x_end_analysis: end of region of analysis within the frame +// int num_frames: number of frames passed for the average between frames +// int avg_val: number of adjacent values with which calculate the average +// +//==== argout: +// int x_peak: x of the peak +// int y_peak: y of the peak +// int x_half_min: smallest x of the value at half maximum +// int x_half_max: largest x of the value at half maximum + +bool OceanOptics::fwhm_calculate(double *data_array, size_t dim_frame, size_t x_start_analysis, size_t x_end_analysis, size_t num_frames, size_t avg_val, size_t &x_peak, double &y_peak, size_t &x_half_min, size_t &x_half_max) +{ + bool ret = true; + if(num_frames < 1) + num_frames = 1; + int dim_frame_analysis = x_end_analysis - x_start_analysis + 1; + if(avg_val-1 > dim_frame_analysis) + { + avg_val = dim_frame_analysis; + } + if(avg_val < 1) + avg_val = 1; + if((avg_val % 2) != 1) //has to be odd + avg_val += 1; + + size_t half_avg_val = (size_t)(floor((double)avg_val)/2); + + double *data_tmp = new double[dim_frame_analysis]; + //memset(data_tmp, 0, sizeof(double)*dim_frame_analysis); + double y_min=1E17; //TODO: start from max value + x_peak = x_start_analysis + avg_val; + y_peak = -1E17; + x_half_min=x_start_analysis + avg_val; + x_half_max=x_end_analysis-(int)(((double)avg_val)/2); + + double inv_num_frame = 1.0/(double)num_frames; + double inv_avg_val = 1.0/(double)avg_val; + //cout << "GGG avg_val="<<avg_val<<" looping ["<<x_start_analysis + avg_val<<","<<x_end_analysis - avg_val<<"]" << endl; + //calculate average and max + //if(int_num_frames > 1) + { + for(size_t i=x_start_analysis + avg_val; i < x_end_analysis - avg_val; i++) + { + //average with num_frames before + for(size_t j=0; j < num_frames; j++) + { + if(avg_val == 1) + { + data_tmp[i-x_start_analysis] = ((double)data_array[i + j*num_frames])*inv_num_frame; + } + else + { + double tmp_val=0; + //average from (size_t)(((double)avg_val)/2) before value i to (size_t)(((double)avg_val)/2) after + for(size_t k=i-half_avg_val; k<=i+half_avg_val; k++) + { + tmp_val += ((double)data_array[k + j*num_frames]); + //cout << "GGG i="<<i<<" k="<<k<<" data_array["<<k + j*num_frames<<"]="<< ((double)data_array[k + j*num_frames]) << endl; + } + data_tmp[i-x_start_analysis] = tmp_val*inv_num_frame*inv_avg_val; + //cout << "GGG i="<<i<<" data_tmp["<<i-x_start_analysis<<"]="<< data_tmp[i-x_start_analysis] << endl; + } + } + if(data_tmp[i-x_start_analysis] > y_peak) + { + y_peak = (data_tmp[i-x_start_analysis]); + x_peak = i; + //cout << "GGG FOUND peak: i="<<i<<" data_tmp["<<i-x_start_analysis<<"]="<< data_tmp[i-x_start_analysis] << endl; + } + if(data_tmp[i-x_start_analysis] < y_min) + { + y_min = (data_tmp[i-x_start_analysis]); + } + } + + //now search for x at half maximum + //exterior half maximum on the left + //for(int i=x_start_analysis + avg_val; i < x_peak; i++) + for(int i=x_peak-1; i>=x_start_analysis + avg_val; i--) + { + //cout << "GGG i="<<i<<" data_tmp["<<i-x_start_analysis<<"]="<< data_tmp[i-x_start_analysis] <<" y_min="<<y_min<<" y_peak="<<y_peak<<" x_peak="<<x_peak<< endl; + //if(data_tmp[i-x_start_analysis] >= (double)y_min + ((double)y_peak-y_min)/2) + if(data_tmp[i-x_start_analysis] < (double)y_min + ((double)y_peak-y_min)/2) + { + //cout << "GGG FOUND x_half_min="<<i<< endl; + //x_half_min = i; + x_half_min = i+1; + break; + } + } + + //exterior half maximum on the right + //for(int i=x_end_analysis - avg_val; i > x_peak; i--) + for(int i = x_peak+1; i <= x_end_analysis - avg_val; i++) + { + //cout << "GGG i="<<i<<" data_tmp["<<i-x_start_analysis<<"]="<< data_tmp[i-x_start_analysis] <<" y_min="<<y_min<<" y_peak="<<y_peak<<" x_peak="<<x_peak<< endl; + //if(data_tmp[i-x_start_analysis] >= (double)y_min + ((double)y_peak-y_min)/2) + if(data_tmp[i-x_start_analysis] < (double)y_min + ((double)y_peak-y_min)/2) + { + //cout << "GGG FOUND x_half_max="<<i<< endl; + //x_half_max = i; + x_half_max = i-1; + break; + } + } + } + delete [] data_tmp; + return ret; +} + +uint32_t OceanOptics::myntohl(uint32_t val_l) +{ + volatile uint32_t ret_val=val_l; + uint32_t volatile *pval_l; + pval_l = (uint32_t volatile *)&ret_val; + +#if __BYTE_ORDER == __BIG_ENDIAN //NOT STANDARD: ASSUMING __LITTLE_ENDIAN as the network ordering + *pval_l = __bswap_32(*pval_l); +#else + *pval_l = *pval_l; +#endif + + return ret_val; +} + +int OceanOptics::connect_device(bool reconnection = false) +{ + int ret=0; + + device_id = -1; +#if _SEABREEZE_API > 1 + spectrometer_id = -1; + { + int result=1; + int number_of_devices; + long *device_ids; + int i; + int test_index; + int flag; + int error = 0; + char nameBuffer[80]; + + /* Give the driver a chance to initialize itself */ + sbapi_initialize(); + + printf("Probing for devices...\n"); fflush(stdout); + sbapi_probe_devices(); + + printf("Getting device count...\n"); fflush(stdout); + number_of_devices = sbapi_get_number_of_device_ids(); + + printf("Device count is %d\n", number_of_devices); + if(0 == number_of_devices) + { + result = 0; + } + + printf("Getting device IDs...\n"); + device_ids = (long *)calloc(number_of_devices, sizeof(long)); + number_of_devices = sbapi_get_device_ids(device_ids, number_of_devices); + printf("Got %d device ID%s.\n", number_of_devices, number_of_devices == 1 ? "" : "s"); + + for(i = 0; i < number_of_devices; i++) + { + + + printf("%d: Device 0x%02lX:\n", i, device_ids[i]); + printf("\tGetting device type...\n"); + flag = sbapi_get_device_type(device_ids[i], &error, nameBuffer, 79); + printf("\t\tResult is (%d) [%s]\n", flag, sbapi_get_error_string(error)); + if(flag > 0) + { + printf("\tDevice type: [%s]\n", nameBuffer); + } + + /* Open the device */ + printf("\tAttempting to open:\n"); + flag = sbapi_open_device(device_ids[i], &error); + printf("\t\tResult is (%d) [%s]\n", flag, sbapi_get_error_string(error)); + if(flag != 0) + { + continue; + } + + int error = 0; + int number_of_serial_numbers; + long *serial_number_ids = 0; + int j; + char buffer[80]; + + printf("\tTesting serial number features:\n"); + + printf("\t\tGetting number of serial numbers:\n"); + number_of_serial_numbers = sbapi_get_number_of_serial_number_features(device_ids[i], &error); + printf("\t\t\tResult is %d [%s]\n", number_of_serial_numbers, + sbapi_get_error_string(error)); + + if(0 == number_of_serial_numbers) + { + printf("\tNo serial number capabilities found.\n"); + continue; + } + + serial_number_ids = (long *)calloc(number_of_serial_numbers, sizeof(long)); + printf("\t\tGetting serial number feature IDs...\n"); + number_of_serial_numbers = sbapi_get_serial_number_features(device_ids[i], &error, + serial_number_ids, number_of_serial_numbers); + printf("\t\t\tResult is %d [%s]\n", number_of_serial_numbers, + sbapi_get_error_string(error)); + + for(j = 0; j < number_of_serial_numbers; j++) + { + printf("\t\t%d: Testing device 0x%02lX, serial number 0x%02lX\n", + j, device_ids[i], serial_number_ids[j]); + + printf("\t\t\tAttempting to get serial number...\n"); + memset(buffer, (int)0, sizeof(buffer)); + sbapi_get_serial_number(device_ids[i],serial_number_ids[j], &error, buffer, 79); + printf("\t\t\t\tResult is [%s]\n", sbapi_get_error_string(error)); + if(0 == error) + { + printf("\t\t\t\tSerial number: [%s]\n", buffer); + if(string(buffer) == serialNumber) + { + device_id = device_ids[i]; + DEBUG_STREAM << "OceanOptics::OceanOptics(): found serial num '" <<serialNumber<<"' on USB dev ID=" <<device_ids[i]; + break; + } + } + printf("\t\t%d: Finished testing device 0x%02lX, serial number 0x%02lX\n", + j, device_ids[i], serial_number_ids[j]); + } + free(serial_number_ids); + if(device_id != -1) + break; + else + { + /* Close the device */ + printf("\tAttempting to close:\n"); + sbapi_close_device(device_ids[i], &error); + printf("\t\tResult is (%d) [%s]\n", flag, sbapi_get_error_string(error)); + } + } + free(device_ids); + + + if(device_id != -1) + { + int error = 0; + int length; + long integration_time; + int number_of_spectrometers; + long *spectrometer_ids = 0; + int i; + double *doubleBuffer = 0; + unsigned char *byteBuffer = 0; + int *edarkBuffer = 0; + int j; + + printf("\tTesting spectrometer features:\n"); + + printf("\t\tGetting number of spectrometers:\n"); + number_of_spectrometers = sbapi_get_number_of_spectrometer_features(device_id, &error); + printf("\t\t\tResult is %d [%s]\n", number_of_spectrometers, + sbapi_get_error_string(error)); + + if(0 == number_of_spectrometers) + { + printf("\tNo spectrometer capabilities found.\n"); + return; + } + + spectrometer_ids = (long *)calloc(number_of_spectrometers, sizeof(long)); + printf("\t\tGetting spectrometer feature IDs...\n"); + number_of_spectrometers = sbapi_get_spectrometer_features(device_id, &error, + spectrometer_ids, number_of_spectrometers); + printf("\t\t\tResult is %d [%s]\n", number_of_spectrometers, + sbapi_get_error_string(error)); + if(number_of_spectrometers == 1) + { + spectrometer_id = spectrometer_ids[0]; + } + else + { + printf("\nNumber of spectrometer features = %d. Only 1 supported! EXITING\n", number_of_spectrometers); + exit(-1); + } + } + } + //else + if(device_id == -1) +#else + int flag; + int error; + char error_str[128]; + char type[16]; + int device_count = 0; + int i; + for(i = 0; i < SEABREEZE_MAX_DEVICES; i++) + { + printf("Opening spectrometer %d.\n", i); + flag = seabreeze_open_spectrometer(i, &error); + seabreeze_get_error_string(error, error_str, 128); + printf("Result is (%d) [%s]\n", flag, error_str); + if(0 == flag) + { + char serial_number[32]; + printf("Getting serial number.\n"); + flag = seabreeze_get_serial_number(i, &error, serial_number, 32); + seabreeze_get_error_string(error, error_str, 128); + printf("Result is (%d) [%s]\n", flag, error_str); + serial_number[31] = '\0'; + if(flag > 0) + { + printf("Serial number: [%s]\n", serial_number); + if(string(serial_number) == serialNumber) + { + device_id = i; + printf("Getting device %d name.\n", i); + seabreeze_get_model(i, &error, type, sizeof(type)); + seabreeze_get_error_string(error, error_str, 128); + printf("Result is (%s) [%s]\n", type, error_str); + DEBUG_STREAM << "OceanOptics::OceanOptics(): found serial num '" <<serialNumber<<"' on USB dev ID=" <<i<<" Type="<<type; + break; + } + } + printf("Closing spectrometer %d.\n", i); + flag = seabreeze_close_spectrometer(i, &error); + seabreeze_get_error_string(error, error_str, 128); + printf("Result is (%d) [%s]\n", flag, error_str); + } + else + { + break; + } + } + if(device_id == -1) +#endif + { + ERROR_STREAM << "OceanOptics::OceanOptics(): error initing CCD!" << endl; + set_state(Tango::FAULT); + set_status("Communication error"); + //exit(0); + return -1; + } + //set temporary state on to allow write attr in init_data + set_state(Tango::ON); + init_data(reconnection); + + if(device_id != -1) + { + if(live_mode) + { + set_state(Tango::RUNNING); + set_status("Continuous Mode"); + } + else + { + set_state(Tango::ON); + set_status("Ready"); + } + } + + return ret; +} + +int OceanOptics::disconnect_device() +{ +#if _SEABREEZE_API > 1 + if(device_id != -1) + { + int flag; + int error; + printf("\tAttempting to close:\n"); + sbapi_close_device(device_id, &error); + printf("\t\tResult is (%d) [%s]\n", flag, sbapi_get_error_string(error)); + } + /* Clean up memory allocated by the driver */ + sbapi_shutdown(); +#else + if(device_id != -1) + { + int flag; + int error; + char error_str[128]; + printf("Closing spectrometer %d.\n", device_id); + flag = seabreeze_close_spectrometer(device_id, &error); + seabreeze_get_error_string(error, error_str, 128); + printf("Result is (%d) [%s]\n", flag, error_str); + } + seabreeze_shutdown(); +#endif +} + +//+------------------------------------------------------------------ +/** + * method: PLCintll::string_explode + * Explode a string +*/ +//+------------------------------------------------------------------ +void OceanOptics::string_explode(string str, string separator, vector<string>* results) +{ + size_t found; + + found = str.find_first_of(separator); + while(found != string::npos) { + if(found > 0) { + results->push_back(str.substr(0,found)); + } + str = str.substr(found+1); + found = str.find_first_of(separator); + } + if(str.length() > 0) { + results->push_back(str); + } + +} + +int OceanOptics::load_intensity_cal_file(string filename) +{ + string line; + ifstream infile (filename.c_str(), ios_base::in); + while (getline(infile, line, '\n')) + { + vector<string> results; + string_explode(line, "\t", &results); + if(results.size() == 3) + { + int ind; + float wl, cal; + int ret = sscanf(line.c_str(), "%d\t%f\t%f", &ind, &wl, &cal); + DEBUG_STREAM <<__func__ << ":Parsed from " << filename << " ret=" << ret << " cal[" << ind << "]=" << cal; + if(ret == 3 && ind >=1 && ind <= NumPixel) + { + attr_IntensityCalibration_read[ind-1] = cal; + } + } + } + + infile.close(); + //DEBUG_STREAM <<__func__ << ": Read from " << filename << " " << tmp.size << " lines or " << tmp.size_d << " reals"; +} + +int OceanOptics::save_intensity_cal_file(string filename) +{ + string line; + ofstream outfile (filename.c_str(), ios_base::out | ios_base::trunc); + for(size_t i=0; i<NumPixel; i++) + { + outfile << i+1 << "\t" << x_values[i] << "\t" << attr_IntensityCalibration_read[i] << endl; + } + + outfile.close(); +} + +#if 0 +//f(x) = base + amp*exp(-0.5 * ((x-center)/width)^2) +int gauss_f (const gsl_vector * x, void *data, gsl_vector * f) +{ + size_t n = ((struct internal_data *)data)->n; + double *y = ((struct internal_data *)data)->y; + double *sigma = ((struct internal_data *) data)->sigma; + double *x_values = ((struct internal_data *) data)->x_values; + +#ifdef _DEBUG_FIT + printf ("gauss_f: xval[0]= % 15.8f xval[%u]=% 15.8f\n",x_values[0],n-1,x_values[n-1]); +#endif + /*double A = gsl_vector_get (x, 0); + double lambda = gsl_vector_get (x, 1); + double b = gsl_vector_get (x, 2);*/ + + double base = gsl_vector_get (x, 0); + double amp = gsl_vector_get (x, 1); + double center = gsl_vector_get (x, 2); + double width = gsl_vector_get (x, 3); + + //TODO: add here bounds to center?? + //TEST!!!!!!!!!!!!!!!!!!!!!!!!!! +/* if(center < x_values[0]) + { + center = x_values[1]; + gsl_vector_set(x,2,center); + } + if(center > x_values[n-1]) + { + center = x_values[n-2]; + gsl_vector_set(x,2,center); + } + if(amp < 0) + { + amp = 1; + gsl_vector_set(x,1,amp); + }*/ + //END TEST!!!!!!!!!!!!!!!!!!!!!! + + size_t i; + + for (i = 0; i < n; i++) + { + //Model Yi = base + amp * exp((-0.5) * ((i-center)/width)^2) + double Yi = base + amp * exp((-0.5) * pow((x_values[i]-center)/width,2)); + gsl_vector_set (f, i, (Yi - y[i])/sigma[i]); + } + + return GSL_SUCCESS; +} +int gauss_df (const gsl_vector * x, void *data, gsl_matrix * J) +{ + size_t n = ((struct internal_data *)data)->n; + double *sigma = ((struct internal_data *) data)->sigma; + double *x_values = ((struct internal_data *) data)->x_values; + +#ifdef _DEBUG_FIT + printf ("gauss_df: xval[0]= % 15.8f xval[%u]=% 15.8f\n",x_values[0],n-1,x_values[n-1]); +#endif + + /*double A = gsl_vector_get (x, 0); + double lambda = gsl_vector_get (x, 1); + double b = gsl_vector_get (x, 2);*/ + + double base = gsl_vector_get (x, 0); + double amp = gsl_vector_get (x, 1); + double center = gsl_vector_get (x, 2); + double width = gsl_vector_get (x, 3); + + //TODO: add here bounds to center?? + //TEST!!!!!!!!!!!!!!!!!!!!!!!!!! + /*if(center < x_values[0]) + { + center = x_values[1]; + gsl_vector_set(x,2,center); + } + if(center > x_values[n-1]) + { + center = x_values[n-2]; + gsl_vector_set(x,2,center); + } + if(amp < 0) + { + amp = 1; + gsl_vector_set(x,1,amp); + }*/ + //END TEST!!!!!!!!!!!!!!!!!!!!!! + + size_t i; + + for (i = 0; i < n; i++) + { + double s = sigma[i]; + + //the four partial derivative of + //base + amp * exp((-0.5) * pow((i-center)/width,2)) + double d_base = 1; + double d_amp = exp((-0.5) * pow((x_values[i]-center)/width,2)); + double d_center = (amp * exp((-0.5) * pow((x_values[i]-center)/width,2))) * ((x_values[i]-center)/pow(width,2)); + double d_width = (amp * exp((-0.5) * pow((x_values[i]-center)/width,2))) * (pow(x_values[i]-center,2)/pow(width,3)); + //populate the Jacobian + gsl_matrix_set (J, i, 0, d_base/s); + gsl_matrix_set (J, i, 1, d_amp/s); + gsl_matrix_set (J, i, 2, d_center/s); + gsl_matrix_set (J, i, 3, d_width/s); + + } + return GSL_SUCCESS; +} +int gauss_fdf (const gsl_vector * x, void *data, gsl_vector * f, gsl_matrix * J) +{ + gauss_f (x, data, f); + gauss_df (x, data, J); + + return GSL_SUCCESS; +} +#endif + + +/*----- PROTECTED REGION END -----*/ // OceanOptics::namespace_ending +} // namespace diff --git a/src/OceanOptics.h b/src/OceanOptics.h new file mode 100644 index 0000000000000000000000000000000000000000..f162f6d268af76a2936b0ea8ede0956d860c07ab --- /dev/null +++ b/src/OceanOptics.h @@ -0,0 +1,895 @@ +/*----- PROTECTED REGION ID(OceanOptics.h) ENABLED START -----*/ +//============================================================================= +// +// file : OceanOptics.h +// +// description : Include file for the OceanOptics class +// +// project : SolarLaserSystems S100 +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// $Author: graziano $ +// +// $Revision: 1.11 $ +// $Date: 2019-04-23 13:32:28 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#ifndef OceanOptics_H +#define OceanOptics_H + +#define _SEABREEZE_API 1 + +#include <tango.h> +#include <stdint.h> +//#include "UsbCDD.h" +//#include "GaussFit.h" +#if _SEABREEZE_API > 1 +#include "api/seabreezeapi/SeaBreezeAPI.h" +#else +#include "api/SeaBreezeWrapper.h" +#endif +#include "Fit.h" +//#include "buffer.h" + +#include "tbuffer.hpp" + +#define DWORD uint32_t +#define MAX_GAUSS_ITERATION 25 +#define MAX_CONFITEOR_ITERATION 20 +#define NUM_GAUSS_PARAMETER 4 +#define AUTO_EXPOSURE_MEAN 4 +#define SIGMA_TO_FWHM_FACTOR 0.4246609 + +#define NUM_BUF 5 +#define BUF_SIZE 10000 +#define BUF_ID_FWHM_CENTER 0 +#define BUF_ID_FWHM_WIDTH 1 +#define BUF_ID_GAUSS_CENTER 2 +#define BUF_ID_GAUSS_WIDTH 3 +#define BUF_ID_AREA 4 + + +// The synchronization mode +// Without synchronization. +#define TG_SYNCHR_NONE 0 +// In the beginning of the first accumulation the positive +// pulse of synchronization is formed. +#define TG_SYNCHR_CONTR 1 +// Clock pulse is formed in the beginning of each accumulation. +#define TG_SYNCHR_CONTR_FRS 2 +// One pulse of synchronization is formed on all time of registration. +// A pulse of negative polarity. +#define TG_SYNCHR_CONTR_NEG 3 + +// The beginning of the first accumulation is adhered to growing +// front of external clock pulse. +//All other accumulation occur so quickly as it is possible. +// In a limit -- without the misses. +#define TG_SYNCHR_EXT 4 + +// The beginning of each accumulation is adhered to growing front of clock pulse. +// How much accumulation, so much clock pulses are expected. +#define TG_SYNCHR_EXT_FRS 5 + +class readthread; + +#if 0 +//f(x) = base + amp*exp(-0.5 * ((x-center)/width)^2) +int gauss_f (const gsl_vector * x, void *data, gsl_vector * f); + +int gauss_df (const gsl_vector * x, void *data, gsl_matrix * J); + +int gauss_fdf (const gsl_vector * x, void *data, gsl_vector * f, gsl_matrix * J); +#endif + +/*----- PROTECTED REGION END -----*/ // OceanOptics.h + +/** + * OceanOptics class description: + * Tango device server for OceanOptics compact wide-range spectrometer + */ + +namespace OceanOptics_ns +{ +/*----- PROTECTED REGION ID(OceanOptics::Additional Class Declarations) ENABLED START -----*/ + +// Additional Class Declarations + +/*----- PROTECTED REGION END -----*/ // OceanOptics::Additional Class Declarations + +class OceanOptics : public TANGO_BASE_CLASS +{ + +/*----- PROTECTED REGION ID(OceanOptics::Data Members) ENABLED START -----*/ + +// Add your own data members +public: + + Tango::DevLong attr_FitType_write; + Tango::DevLong attr_FWHMAvg_write; + Tango::DevLong attr_NoiseLevel_write; + Tango::DevBoolean attr_AutoExposure_write; + Tango::DevDouble attr_ExposureTime_write; +#if _SEABREEZE_API > 1 + long device_id; + long spectrometer_id; +#else + int device_id; +#endif + uint32_t myntohl(uint32_t val_l); + //struct _buffer *buf[NUM_BUF]; + tbuffer::buffer_t<double> tbuf[NUM_BUF]; + tbuffer::buffer_t<tbuffer::_data_array<double> > tbuf_array;//GetData + tbuffer::buffer_t<tbuffer::_data_array<double> > tbuf_array_w;//GetWave + tbuffer::buffer_t<tbuffer::_data_array<double> > tbuf_array_l;//GetLambda + +/*----- PROTECTED REGION END -----*/ // OceanOptics::Data Members + +// Device property data members +public: + // DeviceId: USB Id of the device + Tango::DevLong deviceId; + // SerialNumber: Serial number of the device + string serialNumber; + // NFramesBuffered: number of frames buffered when in live mode + Tango::DevLong nFramesBuffered; + // DefaultStartRegion: Beginning of the region of interest + Tango::DevDouble defaultStartRegion; + // DefaultEndRegion: End of the region of interest + Tango::DevDouble defaultEndRegion; + // SleepReading: Sleep time between reading 2 frames (ms) + Tango::DevLong sleepReading; + // DefaultGaussRef: Default Gauss Reference + vector<Tango::DevDouble> defaultGaussRef; + // DataReferenceFile: Default Data Reference File + string dataReferenceFile; + // PreferFWHM: Choose FWHM instead og GaussianFit if both enabled + Tango::DevBoolean preferFWHM; + // AutoExposureRange: AutoExposure Range + vector<Tango::DevDouble> autoExposureRange; + // AutoExposureStep: AutoExposure Step + Tango::DevDouble autoExposureStep; + // AutoExposureAmpRange: AutoExposure Range + vector<Tango::DevDouble> autoExposureAmpRange; + // IntensityCalibrationFile: + string intensityCalibrationFile; + // NoiseProfileFile: Default Noise Profile File + string noiseProfileFile; + // WavelengthAttr: device name + // attribute name + vector<string> wavelengthAttr; + // AreaInAnalysisRegion: use AnalysisRegion for area instead of AreaRegion + Tango::DevBoolean areaInAnalysisRegion; + // WidthCorrection: widht_in^2 + widthcorrection^2 = widht_out^2 + Tango::DevDouble widthCorrection; + +// Attribute data members +public: + Tango::DevDouble *attr_ExposureTime_read; + Tango::DevBoolean *attr_IncrSensitivity_read; + Tango::DevLong *attr_SyncMode_read; + Tango::DevBoolean *attr_NoiseSubtraction_read; + Tango::DevBoolean *attr_GaussFitEnable_read; + Tango::DevBoolean *attr_FWHMEnable_read; + Tango::DevDouble *attr_GaussFitCenter_read; + Tango::DevDouble *attr_GaussFitWidth_read; + Tango::DevDouble *attr_FWHMCenter_read; + Tango::DevDouble *attr_FWHMWidth_read; + Tango::DevDouble *attr_Center_read; + Tango::DevDouble *attr_Width_read; + Tango::DevLong *attr_FitType_read; + Tango::DevLong *attr_FWHMAvg_read; + Tango::DevLong *attr_NoiseLevel_read; + Tango::DevString *attr_DataReferenceFile_read; + Tango::DevBoolean *attr_AutoExposure_read; + Tango::DevDouble *attr_LightSourceIntensity_read; + Tango::DevBoolean *attr_RtMode_read; + Tango::DevBoolean *attr_LightSourceEnable_read; + Tango::DevBoolean *attr_IntensityCalibrationEnable_read; + Tango::DevDouble *attr_Area_read; + Tango::DevDouble *attr_AreaRegion_read; + Tango::DevBoolean *attr_AreaEnable_read; + Tango::DevBoolean *attr_WidhtCorrectionEnable_read; + Tango::DevLong *attr_NumPixels_read; + Tango::DevDouble *attr_Data_read; + Tango::DevDouble *attr_RegionOfInterest_read; + Tango::DevDouble *attr_AnalysisRegion_read; + Tango::DevDouble *attr_GaussFit_read; + Tango::DevDouble *attr_FWHM_read; + Tango::DevDouble *attr_GaussReference_read; + Tango::DevDouble *attr_DataReference_read; + Tango::DevDouble *attr_IntensityCalibration_read; + Tango::DevDouble *attr_NoiseProfile_read; + Tango::DevDouble *attr_Wave_read; + Tango::DevDouble *attr_Lambda_read; + +// Constructors and destructors +public: + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + OceanOptics(Tango::DeviceClass *cl,string &s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + OceanOptics(Tango::DeviceClass *cl,const char *s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + OceanOptics(Tango::DeviceClass *cl,const char *s,const char *d); + /** + * The device object destructor. + */ + ~OceanOptics() {delete_device();}; + + +// Miscellaneous methods +public: + /* + * will be called at device destruction or at init command. + */ + void delete_device(); + /* + * Initialize the device + */ + virtual void init_device(); + /* + * Read the device properties from database + */ + void get_device_property(); + /* + * Always executed method before execution command method. + */ + virtual void always_executed_hook(); + + +// Attribute methods +public: + //-------------------------------------------------------- + /* + * Method : OceanOptics::read_attr_hardware() + * Description : Hardware acquisition for attributes. + */ + //-------------------------------------------------------- + virtual void read_attr_hardware(vector<long> &attr_list); + //-------------------------------------------------------- + /* + * Method : OceanOptics::write_attr_hardware() + * Description : Hardware writing for attributes. + */ + //-------------------------------------------------------- + virtual void write_attr_hardware(vector<long> &attr_list); + +/** + * Attribute ExposureTime related methods + * Description: Exposure time in milliseconds + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_ExposureTime(Tango::Attribute &attr); + virtual void write_ExposureTime(Tango::WAttribute &attr); + virtual bool is_ExposureTime_allowed(Tango::AttReqType type); +/** + * Attribute IncrSensitivity related methods + * Description: false: use standard sensitivity\ntrue: use increased sensitivity + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_IncrSensitivity(Tango::Attribute &attr); + virtual void write_IncrSensitivity(Tango::WAttribute &attr); + virtual bool is_IncrSensitivity_allowed(Tango::AttReqType type); +/** + * Attribute SyncMode related methods + * Description: 0: The camera operates without synchronization.\nSpectra are read out periodically in accordance with NumReadouts attribute.\n\n1: Readout is performed periodically in accordance with NumReadouts attribute.\nAt the beginning of the first readout a positive sync pulse is formed.\n\n2: A sync pulse is formed at beginning of each readout.\n\n3: One sync pulse of negative polarity is generated for the entire readout time.\n\n4: The camera will wait for one sync pulse.\nThe first readout will start at the rising edge of an external sync pulse.\nAll other readouts will be performed as soon as possible.\nNo blanks within limit\n\n5: Each readout starts at the rising edge of an external sync pulse.\nThe camera will wait fo as many sync pulses as much readouts are set. + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ + virtual void read_SyncMode(Tango::Attribute &attr); + virtual void write_SyncMode(Tango::WAttribute &attr); + virtual bool is_SyncMode_allowed(Tango::AttReqType type); +/** + * Attribute NoiseSubtraction related methods + * Description: Enable/Disable subtraction of background noise profile \nacquired with the AcquireNoise command + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_NoiseSubtraction(Tango::Attribute &attr); + virtual void write_NoiseSubtraction(Tango::WAttribute &attr); + virtual bool is_NoiseSubtraction_allowed(Tango::AttReqType type); +/** + * Attribute GaussFitEnable related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_GaussFitEnable(Tango::Attribute &attr); + virtual void write_GaussFitEnable(Tango::WAttribute &attr); + virtual bool is_GaussFitEnable_allowed(Tango::AttReqType type); +/** + * Attribute FWHMEnable related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_FWHMEnable(Tango::Attribute &attr); + virtual void write_FWHMEnable(Tango::WAttribute &attr); + virtual bool is_FWHMEnable_allowed(Tango::AttReqType type); +/** + * Attribute GaussFitCenter related methods + * Description: wavelength of peak of Gaussian Fit + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_GaussFitCenter(Tango::Attribute &attr); + virtual bool is_GaussFitCenter_allowed(Tango::AttReqType type); +/** + * Attribute GaussFitWidth related methods + * Description: width of Gaussian Fit + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_GaussFitWidth(Tango::Attribute &attr); + virtual bool is_GaussFitWidth_allowed(Tango::AttReqType type); +/** + * Attribute FWHMCenter related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_FWHMCenter(Tango::Attribute &attr); + virtual bool is_FWHMCenter_allowed(Tango::AttReqType type); +/** + * Attribute FWHMWidth related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_FWHMWidth(Tango::Attribute &attr); + virtual bool is_FWHMWidth_allowed(Tango::AttReqType type); +/** + * Attribute Center related methods + * Description: wavelength of peak of FWHM or of Gaussian Fit + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_Center(Tango::Attribute &attr); + virtual bool is_Center_allowed(Tango::AttReqType type); +/** + * Attribute Width related methods + * Description: width of FWHM or of Gaussian Fit + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_Width(Tango::Attribute &attr); + virtual bool is_Width_allowed(Tango::AttReqType type); +/** + * Attribute FitType related methods + * Description: 1=Gaussian 2=Gaussian Asymm 3=Confiteor + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ + virtual void read_FitType(Tango::Attribute &attr); + virtual void write_FitType(Tango::WAttribute &attr); + virtual bool is_FitType_allowed(Tango::AttReqType type); +/** + * Attribute FWHMAvg related methods + * Description: + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ + virtual void read_FWHMAvg(Tango::Attribute &attr); + virtual void write_FWHMAvg(Tango::WAttribute &attr); + virtual bool is_FWHMAvg_allowed(Tango::AttReqType type); +/** + * Attribute NoiseLevel related methods + * Description: + * + * Data type: Tango::DevLong + * Attr type: Scalar + */ + virtual void read_NoiseLevel(Tango::Attribute &attr); + virtual void write_NoiseLevel(Tango::WAttribute &attr); + virtual bool is_NoiseLevel_allowed(Tango::AttReqType type); +/** + * Attribute DataReferenceFile related methods + * Description: + * + * Data type: Tango::DevString + * Attr type: Scalar + */ + virtual void read_DataReferenceFile(Tango::Attribute &attr); + virtual void write_DataReferenceFile(Tango::WAttribute &attr); + virtual bool is_DataReferenceFile_allowed(Tango::AttReqType type); +/** + * Attribute AutoExposure related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_AutoExposure(Tango::Attribute &attr); + virtual void write_AutoExposure(Tango::WAttribute &attr); + virtual bool is_AutoExposure_allowed(Tango::AttReqType type); +/** + * Attribute LightSourceIntensity related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_LightSourceIntensity(Tango::Attribute &attr); + virtual void write_LightSourceIntensity(Tango::WAttribute &attr); + virtual bool is_LightSourceIntensity_allowed(Tango::AttReqType type); +/** + * Attribute RtMode related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_RtMode(Tango::Attribute &attr); + virtual void write_RtMode(Tango::WAttribute &attr); + virtual bool is_RtMode_allowed(Tango::AttReqType type); +/** + * Attribute LightSourceEnable related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_LightSourceEnable(Tango::Attribute &attr); + virtual void write_LightSourceEnable(Tango::WAttribute &attr); + virtual bool is_LightSourceEnable_allowed(Tango::AttReqType type); +/** + * Attribute IntensityCalibrationEnable related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_IntensityCalibrationEnable(Tango::Attribute &attr); + virtual void write_IntensityCalibrationEnable(Tango::WAttribute &attr); + virtual bool is_IntensityCalibrationEnable_allowed(Tango::AttReqType type); +/** + * Attribute Area related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_Area(Tango::Attribute &attr); + virtual bool is_Area_allowed(Tango::AttReqType type); +/** + * Attribute AreaRegion related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_AreaRegion(Tango::Attribute &attr); + virtual void write_AreaRegion(Tango::WAttribute &attr); + virtual bool is_AreaRegion_allowed(Tango::AttReqType type); +/** + * Attribute AreaEnable related methods + * Description: + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_AreaEnable(Tango::Attribute &attr); + virtual void write_AreaEnable(Tango::WAttribute &attr); + virtual bool is_AreaEnable_allowed(Tango::AttReqType type); +/** + * Attribute WidhtCorrectionEnable related methods + * Description: enable widht correction + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_WidhtCorrectionEnable(Tango::Attribute &attr); + virtual void write_WidhtCorrectionEnable(Tango::WAttribute &attr); + virtual bool is_WidhtCorrectionEnable_allowed(Tango::AttReqType type); +/** + * Attribute NumPixels related methods + * Description: long[0]: number of pixels horizontally (number of CCD-array columns)\nlong[1]: number of pixels vertically (number of CCD-array lines) + * + * Data type: Tango::DevLong + * Attr type: Spectrum max = 2 + */ + virtual void read_NumPixels(Tango::Attribute &attr); + virtual bool is_NumPixels_allowed(Tango::AttReqType type); +/** + * Attribute Data related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ + virtual void read_Data(Tango::Attribute &attr); + virtual bool is_Data_allowed(Tango::AttReqType type); +/** + * Attribute RegionOfInterest related methods + * Description: Region of interest returned by the Data attribute\ndouble[0]=start of the region\ndouble[1]=end of the region\n\nValues are in nm according with the conversion factor in x_values\nData attribute property + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 2 + */ + virtual void read_RegionOfInterest(Tango::Attribute &attr); + virtual void write_RegionOfInterest(Tango::WAttribute &attr); + virtual bool is_RegionOfInterest_allowed(Tango::AttReqType type); +/** + * Attribute AnalysisRegion related methods + * Description: Region used for gaussian and fwhm analysis\ndouble[0]=start of the region\ndouble[1]=end of the region\n\nValues are in nm according with the conversion factor in x_values\nData attribute property + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 2 + */ + virtual void read_AnalysisRegion(Tango::Attribute &attr); + virtual void write_AnalysisRegion(Tango::WAttribute &attr); + virtual bool is_AnalysisRegion_allowed(Tango::AttReqType type); +/** + * Attribute GaussFit related methods + * Description: double[0]= wavelength of peak of Gaussian Fit\ndouble[1]= width of Gaussian Fit + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 4 + */ + virtual void read_GaussFit(Tango::Attribute &attr); + virtual bool is_GaussFit_allowed(Tango::AttReqType type); +/** + * Attribute FWHM related methods + * Description: double[0]= wavelength of peak of FWHM\ndouble[1]= width of FWHM + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 3 + */ + virtual void read_FWHM(Tango::Attribute &attr); + virtual bool is_FWHM_allowed(Tango::AttReqType type); +/** + * Attribute GaussReference related methods + * Description: Gaussian of reference params + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 4 + */ + virtual void read_GaussReference(Tango::Attribute &attr); + virtual void write_GaussReference(Tango::WAttribute &attr); + virtual bool is_GaussReference_allowed(Tango::AttReqType type); +/** + * Attribute DataReference related methods + * Description: A reference curve + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ + virtual void read_DataReference(Tango::Attribute &attr); + virtual void write_DataReference(Tango::WAttribute &attr); + virtual bool is_DataReference_allowed(Tango::AttReqType type); +/** + * Attribute IntensityCalibration related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 10000 + */ + virtual void read_IntensityCalibration(Tango::Attribute &attr); + virtual void write_IntensityCalibration(Tango::WAttribute &attr); + virtual bool is_IntensityCalibration_allowed(Tango::AttReqType type); +/** + * Attribute NoiseProfile related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ + virtual void read_NoiseProfile(Tango::Attribute &attr); + virtual bool is_NoiseProfile_allowed(Tango::AttReqType type); +/** + * Attribute Wave related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ + virtual void read_Wave(Tango::Attribute &attr); + virtual bool is_Wave_allowed(Tango::AttReqType type); +/** + * Attribute Lambda related methods + * Description: + * + * Data type: Tango::DevDouble + * Attr type: Spectrum max = 5000 + */ + virtual void read_Lambda(Tango::Attribute &attr); + virtual bool is_Lambda_allowed(Tango::AttReqType type); + + + //-------------------------------------------------------- + /** + * Method : OceanOptics::add_dynamic_attributes() + * Description : Add dynamic attributes if any. + */ + //-------------------------------------------------------- + void add_dynamic_attributes(); + + + + +// Command related methods +public: + /** + * Command GetVersion related method + * Description: Returns serial number + * + * @returns serial number + */ + virtual Tango::DevString get_version(); + virtual bool is_GetVersion_allowed(const CORBA::Any &any); + /** + * Command Stop related method + * Description: Reset the CCD: + * stops the current readout, + * initiates the internal DLL variables, + * stops data transfer + * + */ + virtual void stop(); + virtual bool is_Stop_allowed(const CORBA::Any &any); + /** + * Command StartSingle related method + * Description: Start single (NumReadout frames) acquisition fron the CCD + * + */ + virtual void start_single(); + virtual bool is_StartSingle_allowed(const CORBA::Any &any); + /** + * Command StartContinuous related method + * Description: Start acquisition in Continuous mode + * + */ + virtual void start_continuous(); + virtual bool is_StartContinuous_allowed(const CORBA::Any &any); + /** + * Command GetLastData related method + * Description: returns the last argin frames saved + * + * @param argin number of frames to return + * @returns + */ + virtual Tango::DevVarDoubleArray *get_last_data(Tango::DevLong argin); + virtual bool is_GetLastData_allowed(const CORBA::Any &any); + /** + * Command AcquireNoise related method + * Description: Acquire argin frames of background noise + * + * @param argin Number of frames to acquire as noise + */ + virtual void acquire_noise(Tango::DevLong argin); + virtual bool is_AcquireNoise_allowed(const CORBA::Any &any); + /** + * Command SaveReferenceData related method + * Description: Save current curve as reference curve + * + */ + virtual void save_reference_data(); + virtual bool is_SaveReferenceData_allowed(const CORBA::Any &any); + /** + * Command OpenShutter related method + * Description: + * + */ + virtual void open_shutter(); + virtual bool is_OpenShutter_allowed(const CORBA::Any &any); + /** + * Command CloseShutter related method + * Description: + * + */ + virtual void close_shutter(); + virtual bool is_CloseShutter_allowed(const CORBA::Any &any); + /** + * Command GetData related method + * Description: + * + * @param argin + * @returns + */ + virtual Tango::DevVarDoubleArray *get_data(const Tango::DevVarLongArray *argin); + virtual bool is_GetData_allowed(const CORBA::Any &any); + /** + * Command GetGaussFitCenter related method + * Description: + * + * @param argin + * @returns + */ + virtual Tango::DevVarDoubleArray *get_gauss_fit_center(const Tango::DevVarLongArray *argin); + virtual bool is_GetGaussFitCenter_allowed(const CORBA::Any &any); + /** + * Command GetGaussFitWidth related method + * Description: + * + * @param argin + * @returns + */ + virtual Tango::DevVarDoubleArray *get_gauss_fit_width(const Tango::DevVarLongArray *argin); + virtual bool is_GetGaussFitWidth_allowed(const CORBA::Any &any); + /** + * Command GetFWHMCenter related method + * Description: + * + * @param argin + * @returns + */ + virtual Tango::DevVarDoubleArray *get_fwhmcenter(const Tango::DevVarLongArray *argin); + virtual bool is_GetFWHMCenter_allowed(const CORBA::Any &any); + /** + * Command GetFWHMWidth related method + * Description: + * + * @param argin + * @returns + */ + virtual Tango::DevVarDoubleArray *get_fwhmwidth(const Tango::DevVarLongArray *argin); + virtual bool is_GetFWHMWidth_allowed(const CORBA::Any &any); + /** + * Command ExportWavelength related method + * Description: + * + */ + virtual void export_wavelength(); + virtual bool is_ExportWavelength_allowed(const CORBA::Any &any); + /** + * Command GetArea related method + * Description: + * + * @param argin + * @returns + */ + virtual Tango::DevVarDoubleArray *get_area(const Tango::DevVarLongArray *argin); + virtual bool is_GetArea_allowed(const CORBA::Any &any); + /** + * Command GetWave related method + * Description: + * + * @param argin + * @returns + */ + virtual Tango::DevVarDoubleArray *get_wave(const Tango::DevVarLongArray *argin); + virtual bool is_GetWave_allowed(const CORBA::Any &any); + /** + * Command GetLambda related method + * Description: + * + * @param argin + * @returns + */ + virtual Tango::DevVarDoubleArray *get_lambda(const Tango::DevVarLongArray *argin); + virtual bool is_GetLambda_allowed(const CORBA::Any &any); + + + //-------------------------------------------------------- + /** + * Method : OceanOptics::add_dynamic_commands() + * Description : Add dynamic commands if any. + */ + //-------------------------------------------------------- + void add_dynamic_commands(); + +/*----- PROTECTED REGION ID(OceanOptics::Additional Method prototypes) ENABLED START -----*/ + +// Additional Method prototypes +public: + bool abortflag; + bool live_mode; + bool init_live_mode; + bool measure_mode; + bool init_measure_mode; + bool acquire_noise_mode; + bool init_acquire_noise_mode; + + int noise_frames; + int noise_frames_counter; + int noise_level; + string host_rw; + long port_rw; + timespec last_read; + + //int data_counter_live; + //int data_counter_meas; +// CUsbCDD m_usbCCD; +// GaussFit *m_gaussfit;// + /*LibFit_ns::*/Fit *m_gaussfit;// + /*LibFit_ns::*/Fit *m_asyngaussfit;// + /*LibFit_ns::*/Fit *m_confiteorfit;// + bool GaussFit_valid; + + //DWORD *pMeasData; + double *pLiveData; + double *pLiveData_avg; + double *pNoiseMask_avg; + double *pFrameBuffer; //bi-dimensional array + double *pReferenceData; + unsigned int FrameBufferIndex; + unsigned int NumPixel; + Tango::DevDouble *x_values; + unsigned int RegionOfInterestStartPix; + unsigned int RegionOfInterestEndPix; + unsigned int AnalysisRegionStartPix; + unsigned int AnalysisRegionEndPix; + void init_data(bool reconnection); + unsigned int WaveLenght2Pix(double val); + bool fwhm_calculate(double */*restrict*/ data_array, size_t dim_frame, size_t x_start_analysis, size_t x_end_analisys, size_t num_frames, size_t avg_val, size_t &x_peak, double &y_peak, size_t &x_half_min, size_t &x_half_max); + int y_max_mean; + int exposures[AUTO_EXPOSURE_MEAN]; + int exposure_idx; + int connect_device(bool reconnection); + int disconnect_device(); + void string_explode(string str, string separator, vector<string>* results); + int load_intensity_cal_file(string filename); + int save_intensity_cal_file(string filename); + +protected : + readthread *loop; + unsigned int properties; + + char attr_strchar[1024]; + Tango::DevString attr_tmp_ptr; + +/*----- PROTECTED REGION END -----*/ // OceanOptics::Additional Method prototypes +}; + +/*----- PROTECTED REGION ID(OceanOptics::Additional Classes Definitions) ENABLED START -----*/ + +// Additional Classes Definitions + +/*----- PROTECTED REGION END -----*/ // OceanOptics::Additional Classes Definitions + +} // End of namespace + +#endif // OceanOptics_H diff --git a/src/OceanOptics.xmi b/src/OceanOptics.xmi new file mode 100644 index 0000000000000000000000000000000000000000..0f61f07e06cca14c041a2688375605f358737ffe --- /dev/null +++ b/src/OceanOptics.xmi @@ -0,0 +1,537 @@ +<?xml version="1.0" encoding="ASCII"?> +<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl"> + <classes name="OceanOptics" pogoRevision="9.4"> + <description description="Tango device server for OceanOptics compact wide-range spectrometer" title="OceanOptics Spectrometers" sourcePath="/home/graziano/workspace/fermi/servers/oceanoptics/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false"> + <inheritances classname="Device_4Impl" sourcePath=""/> + <identification contact="at elettra.eu - graziano.scalamera" author="graziano.scalamera" emailDomain="elettra.eu" classFamily="MeasureInstruments" siteSpecific="" platform="Unix Like" bus="USB" manufacturer="OceanOptics" reference=""/> + </description> + <deviceProperties name="DeviceId" description="USB Id of the device"> + <type xsi:type="pogoDsl:IntType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="SerialNumber" description="Serial number of the device"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="NFramesBuffered" description="number of frames buffered when in live mode"> + <type xsi:type="pogoDsl:IntType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="DefaultStartRegion" description="Beginning of the region of interest"> + <type xsi:type="pogoDsl:DoubleType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="DefaultEndRegion" description="End of the region of interest"> + <type xsi:type="pogoDsl:DoubleType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="SleepReading" description="Sleep time between reading 2 frames (ms)"> + <type xsi:type="pogoDsl:IntType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="DefaultGaussRef" description="Default Gauss Reference"> + <type xsi:type="pogoDsl:DoubleVectorType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="DataReferenceFile" description="Default Data Reference File"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="PreferFWHM" description="Choose FWHM instead og GaussianFit if both enabled"> + <type xsi:type="pogoDsl:BooleanType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="AutoExposureRange" description="AutoExposure Range"> + <type xsi:type="pogoDsl:DoubleVectorType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="AutoExposureStep" description="AutoExposure Step"> + <type xsi:type="pogoDsl:DoubleType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="AutoExposureAmpRange" description="AutoExposure Range"> + <type xsi:type="pogoDsl:DoubleVectorType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="IntensityCalibrationFile" description=""> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="NoiseProfileFile" description="Default Noise Profile File"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="WavelengthAttr" description="device name
attribute name"> + <type xsi:type="pogoDsl:StringVectorType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="AreaInAnalysisRegion" description="use AnalysisRegion for area instead of AreaRegion"> + <type xsi:type="pogoDsl:BooleanType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <DefaultPropValue>false</DefaultPropValue> + </deviceProperties> + <deviceProperties name="WidthCorrection" description="widht_in^2 + widthcorrection^2 = widht_out^2"> + <type xsi:type="pogoDsl:DoubleType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <DefaultPropValue>0</DefaultPropValue> + </deviceProperties> + <commands name="State" description="This command gets the device state (stored in its <i>device_state</i> data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="none."> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="State Code"> + <type xsi:type="pogoDsl:StateType"/> + </argout> + <status abstract="true" inherited="true" concrete="true" concreteHere="false"/> + </commands> + <commands name="Status" description="This command gets the device status (stored in its <i>device_status</i> data member) and returns it to the caller." execMethod="dev_status" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="none."> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Status description"> + <type xsi:type="pogoDsl:ConstStringType"/> + </argout> + <status abstract="true" inherited="true" concrete="true" concreteHere="false"/> + </commands> + <commands name="GetVersion" description="Returns serial number" execMethod="get_version" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="serial number"> + <type xsi:type="pogoDsl:StringType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="Stop" description="Reset the CCD:
stops the current readout,
initiates the internal DLL variables,
stops data transfer" execMethod="stop" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="StartSingle" description="Start single (NumReadout frames) acquisition fron the CCD" execMethod="start_single" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="StartContinuous" description="Start acquisition in Continuous mode" execMethod="start_continuous" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="GetLastData" description="returns the last argin frames saved" execMethod="get_last_data" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="number of frames to return"> + <type xsi:type="pogoDsl:IntType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="AcquireNoise" description="Acquire argin frames of background noise" execMethod="acquire_noise" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="Number of frames to acquire as noise"> + <type xsi:type="pogoDsl:IntType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="SaveReferenceData" description="Save current curve as reference curve" execMethod="save_reference_data" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="OpenShutter" description="" execMethod="open_shutter" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="CloseShutter" description="" execMethod="close_shutter" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="GetData" description="" execMethod="get_data" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:IntArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="GetGaussFitCenter" description="" execMethod="get_gauss_fit_center" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:IntArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="GetGaussFitWidth" description="" execMethod="get_gauss_fit_width" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:IntArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="GetFWHMCenter" description="" execMethod="get_fwhmcenter" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:IntArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="GetFWHMWidth" description="" execMethod="get_fwhmwidth" displayLevel="OPERATOR" polledPeriod="0"> + <argin description=""> + <type xsi:type="pogoDsl:IntArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="ExportWavelength" description="" execMethod="export_wavelength" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="GetArea" description="" execMethod="get_area" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:IntArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="GetWave" description="" execMethod="get_wave" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:IntArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="GetLambda" description="" execMethod="get_lambda" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:IntArrayType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:DoubleArrayType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <attributes name="ExposureTime" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="Exposure time in milliseconds" label="" unit="ms" standardUnit="1.0" displayUnit="ms" format="%6.2f" maxValue="" minValue="0" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="IncrSensitivity" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="false: use standard sensitivity\ntrue: use increased sensitivity" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="SyncMode" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true"> + <dataType xsi:type="pogoDsl:IntType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="0: The camera operates without synchronization.\nSpectra are read out periodically in accordance with NumReadouts attribute.\n\n1: Readout is performed periodically in accordance with NumReadouts attribute.\nAt the beginning of the first readout a positive sync pulse is formed.\n\n2: A sync pulse is formed at beginning of each readout.\n\n3: One sync pulse of negative polarity is generated for the entire readout time.\n\n4: The camera will wait for one sync pulse.\nThe first readout will start at the rising edge of an external sync pulse.\nAll other readouts will be performed as soon as possible.\nNo blanks within limit\n\n5: Each readout starts at the rising edge of an external sync pulse.\nThe camera will wait fo as many sync pulses as much readouts are set." label="" unit="" standardUnit="" displayUnit="" format="" maxValue="5" minValue="0" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="NoiseSubtraction" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="Enable/Disable subtraction of background noise profile \nacquired with the AcquireNoise command" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="GaussFitEnable" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="FWHMEnable" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="GaussFitCenter" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="wavelength of peak of Gaussian Fit" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="GaussFitWidth" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="width of Gaussian Fit" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="FWHMCenter" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="FWHMWidth" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="Center" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="wavelength of peak of FWHM or of Gaussian Fit" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="Width" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="width of FWHM or of Gaussian Fit" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="FitType" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:IntType"/> + <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="1=Gaussian 2=Gaussian Asymm 3=Confiteor" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="3" minValue="1" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="FWHMAvg" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:IntType"/> + <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="NoiseLevel" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:IntType"/> + <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="DataReferenceFile" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true"> + <dataType xsi:type="pogoDsl:StringType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="AutoExposure" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="LightSourceIntensity" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" memorized="true" memorizedAtInit="true" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="RtMode" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" memorized="true" memorizedAtInit="true" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="LightSourceEnable" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" memorized="true" memorizedAtInit="true" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="IntensityCalibrationEnable" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" memorized="true" memorizedAtInit="true" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="Area" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="AreaRegion" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" memorized="true" memorizedAtInit="true" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="AreaEnable" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="0" maxY="0" memorized="true" memorizedAtInit="true" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="WidhtCorrectionEnable" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" memorized="true" memorizedAtInit="true" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="enable widht correction" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="NumPixels" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="2" maxY="0"> + <dataType xsi:type="pogoDsl:IntType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="long[0]: number of pixels horizontally (number of CCD-array columns)\nlong[1]: number of pixels vertically (number of CCD-array lines)" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="Data" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="5000" maxY="0" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="RegionOfInterest" attType="Spectrum" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="2" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="Region of interest returned by the Data attribute\ndouble[0]=start of the region\ndouble[1]=end of the region\n\nValues are in nm according with the conversion factor in x_values\nData attribute property" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="AnalysisRegion" attType="Spectrum" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="2" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="Region used for gaussian and fwhm analysis\ndouble[0]=start of the region\ndouble[1]=end of the region\n\nValues are in nm according with the conversion factor in x_values\nData attribute property" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="GaussFit" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="4" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="double[0]= wavelength of peak of Gaussian Fit\ndouble[1]= width of Gaussian Fit" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="FWHM" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="3" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="double[0]= wavelength of peak of FWHM\ndouble[1]= width of FWHM" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="GaussReference" attType="Spectrum" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="4" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="Gaussian of reference params" label="" unit="" standardUnit="" displayUnit="" format="%7.2f" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="DataReference" attType="Spectrum" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="5000" maxY="0"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="A reference curve" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="IntensityCalibration" attType="Spectrum" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="10000" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="NoiseProfile" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="5000" maxY="0" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="Wave" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="5000" maxY="0" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="Lambda" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="5000" maxY="0" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <preferences docHome="./doc_html" makefileHome="/usr/local/tango-9.2.5a/share/pogo/preferences"/> + </classes> +</pogoDsl:PogoSystem> diff --git a/src/OceanOpticsClass.cpp b/src/OceanOpticsClass.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aaf5872e22a93068195faefee3c8e5806f1de83c --- /dev/null +++ b/src/OceanOpticsClass.cpp @@ -0,0 +1,2202 @@ +/*----- PROTECTED REGION ID(OceanOpticsClass.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: OceanOpticsClass.cpp,v 1.10 2019-04-23 13:35:55 graziano Exp $"; +static const char *TagName = "$Name: $"; +static const char *CvsPath = "$Source: /home/cvsadm/cvsroot/fermi/servers/oceanoptics/src/OceanOpticsClass.cpp,v $"; +static const char *SvnPath = "$HeadURL: $"; +static const char *HttpServer = "http://www.esrf.eu/computing/cs/tango/tango_doc/ds_doc/"; +//============================================================================= +// +// file : OceanOpticsClass.cpp +// +// description : C++ source for the OceanOpticsClass. +// A singleton class derived from DeviceClass. +// It implements the command and attribute list +// and all properties and methods required +// by the OceanOptics once per process. +// +// project : SolarLaserSystems S100 +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// $Author: graziano $ +// +// $Revision: 1.10 $ +// $Date: 2019-04-23 13:35:55 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include <tango.h> +#include <OceanOptics.h> +#include <OceanOpticsClass.h> + +/*----- PROTECTED REGION END -----*/ // OceanOpticsClass.cpp + +//------------------------------------------------------------------- +/** + * Create OceanOpticsClass singleton and + * return it in a C function for Python usage + */ +//------------------------------------------------------------------- +extern "C" { +#ifdef _TG_WINDOWS_ + +__declspec(dllexport) + +#endif + + Tango::DeviceClass *_create_OceanOptics_class(const char *name) { + return OceanOptics_ns::OceanOpticsClass::init(name); + } +} + +namespace OceanOptics_ns +{ +//=================================================================== +// Initialize pointer for singleton pattern +//=================================================================== +OceanOpticsClass *OceanOpticsClass::_instance = NULL; + +//-------------------------------------------------------- +/** + * method : OceanOpticsClass::OceanOpticsClass(string &s) + * description : constructor for the OceanOpticsClass + * + * @param s The class name + */ +//-------------------------------------------------------- +OceanOpticsClass::OceanOpticsClass(string &s):Tango::DeviceClass(s) +{ + cout2 << "Entering OceanOpticsClass constructor" << endl; + set_default_property(); + write_class_property(); + + /*----- PROTECTED REGION ID(OceanOpticsClass::constructor) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::constructor + + cout2 << "Leaving OceanOpticsClass constructor" << endl; +} + +//-------------------------------------------------------- +/** + * method : OceanOpticsClass::~OceanOpticsClass() + * description : destructor for the OceanOpticsClass + */ +//-------------------------------------------------------- +OceanOpticsClass::~OceanOpticsClass() +{ + /*----- PROTECTED REGION ID(OceanOpticsClass::destructor) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::destructor + + _instance = NULL; +} + + +//-------------------------------------------------------- +/** + * method : OceanOpticsClass::init + * description : Create the object if not already done. + * Otherwise, just return a pointer to the object + * + * @param name The class name + */ +//-------------------------------------------------------- +OceanOpticsClass *OceanOpticsClass::init(const char *name) +{ + if (_instance == NULL) + { + try + { + string s(name); + _instance = new OceanOpticsClass(s); + } + catch (bad_alloc &) + { + throw; + } + } + return _instance; +} + +//-------------------------------------------------------- +/** + * method : OceanOpticsClass::instance + * description : Check if object already created, + * and return a pointer to the object + */ +//-------------------------------------------------------- +OceanOpticsClass *OceanOpticsClass::instance() +{ + if (_instance == NULL) + { + cerr << "Class is not initialised !!" << endl; + exit(-1); + } + return _instance; +} + + + +//=================================================================== +// Command execution method calls +//=================================================================== +//-------------------------------------------------------- +/** + * method : GetVersionClass::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 *GetVersionClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "GetVersionClass::execute(): arrived" << endl; + return insert((static_cast<OceanOptics *>(device))->get_version()); +} + +//-------------------------------------------------------- +/** + * method : StopClass::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 *StopClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "StopClass::execute(): arrived" << endl; + ((static_cast<OceanOptics *>(device))->stop()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : StartSingleClass::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 *StartSingleClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "StartSingleClass::execute(): arrived" << endl; + ((static_cast<OceanOptics *>(device))->start_single()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : StartContinuousClass::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 *StartContinuousClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "StartContinuousClass::execute(): arrived" << endl; + ((static_cast<OceanOptics *>(device))->start_continuous()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : GetLastDataClass::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 *GetLastDataClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "GetLastDataClass::execute(): arrived" << endl; + Tango::DevLong argin; + extract(in_any, argin); + return insert((static_cast<OceanOptics *>(device))->get_last_data(argin)); +} + +//-------------------------------------------------------- +/** + * method : AcquireNoiseClass::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 *AcquireNoiseClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "AcquireNoiseClass::execute(): arrived" << endl; + Tango::DevLong argin; + extract(in_any, argin); + ((static_cast<OceanOptics *>(device))->acquire_noise(argin)); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : SaveReferenceDataClass::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 *SaveReferenceDataClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "SaveReferenceDataClass::execute(): arrived" << endl; + ((static_cast<OceanOptics *>(device))->save_reference_data()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : OpenShutterClass::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 *OpenShutterClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "OpenShutterClass::execute(): arrived" << endl; + ((static_cast<OceanOptics *>(device))->open_shutter()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : CloseShutterClass::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 *CloseShutterClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "CloseShutterClass::execute(): arrived" << endl; + ((static_cast<OceanOptics *>(device))->close_shutter()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : GetDataClass::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 *GetDataClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "GetDataClass::execute(): arrived" << endl; + const Tango::DevVarLongArray *argin; + extract(in_any, argin); + return insert((static_cast<OceanOptics *>(device))->get_data(argin)); +} + +//-------------------------------------------------------- +/** + * method : GetGaussFitCenterClass::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 *GetGaussFitCenterClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "GetGaussFitCenterClass::execute(): arrived" << endl; + const Tango::DevVarLongArray *argin; + extract(in_any, argin); + return insert((static_cast<OceanOptics *>(device))->get_gauss_fit_center(argin)); +} + +//-------------------------------------------------------- +/** + * method : GetGaussFitWidthClass::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 *GetGaussFitWidthClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "GetGaussFitWidthClass::execute(): arrived" << endl; + const Tango::DevVarLongArray *argin; + extract(in_any, argin); + return insert((static_cast<OceanOptics *>(device))->get_gauss_fit_width(argin)); +} + +//-------------------------------------------------------- +/** + * method : GetFWHMCenterClass::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 *GetFWHMCenterClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "GetFWHMCenterClass::execute(): arrived" << endl; + const Tango::DevVarLongArray *argin; + extract(in_any, argin); + return insert((static_cast<OceanOptics *>(device))->get_fwhmcenter(argin)); +} + +//-------------------------------------------------------- +/** + * method : GetFWHMWidthClass::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 *GetFWHMWidthClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "GetFWHMWidthClass::execute(): arrived" << endl; + const Tango::DevVarLongArray *argin; + extract(in_any, argin); + return insert((static_cast<OceanOptics *>(device))->get_fwhmwidth(argin)); +} + +//-------------------------------------------------------- +/** + * method : ExportWavelengthClass::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 *ExportWavelengthClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + cout2 << "ExportWavelengthClass::execute(): arrived" << endl; + ((static_cast<OceanOptics *>(device))->export_wavelength()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : GetAreaClass::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 *GetAreaClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "GetAreaClass::execute(): arrived" << endl; + const Tango::DevVarLongArray *argin; + extract(in_any, argin); + return insert((static_cast<OceanOptics *>(device))->get_area(argin)); +} + +//-------------------------------------------------------- +/** + * method : GetWaveClass::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 *GetWaveClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "GetWaveClass::execute(): arrived" << endl; + const Tango::DevVarLongArray *argin; + extract(in_any, argin); + return insert((static_cast<OceanOptics *>(device))->get_wave(argin)); +} + +//-------------------------------------------------------- +/** + * method : GetLambdaClass::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 *GetLambdaClass::execute(Tango::DeviceImpl *device, const CORBA::Any &in_any) +{ + cout2 << "GetLambdaClass::execute(): arrived" << endl; + const Tango::DevVarLongArray *argin; + extract(in_any, argin); + return insert((static_cast<OceanOptics *>(device))->get_lambda(argin)); +} + + +//=================================================================== +// Properties management +//=================================================================== +//-------------------------------------------------------- +/** + * Method : OceanOpticsClass::get_class_property() + * Description : Get the class property for specified name. + */ +//-------------------------------------------------------- +Tango::DbDatum OceanOpticsClass::get_class_property(string &prop_name) +{ + for (unsigned int i=0 ; i<cl_prop.size() ; i++) + if (cl_prop[i].name == prop_name) + return cl_prop[i]; + // if not found, returns an empty DbDatum + return Tango::DbDatum(prop_name); +} + +//-------------------------------------------------------- +/** + * Method : OceanOpticsClass::get_default_device_property() + * Description : Return the default value for device property. + */ +//-------------------------------------------------------- +Tango::DbDatum OceanOpticsClass::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 : OceanOpticsClass::get_default_class_property() + * Description : Return the default value for class property. + */ +//-------------------------------------------------------- +Tango::DbDatum OceanOpticsClass::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 : OceanOpticsClass::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 OceanOpticsClass::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 = "DeviceId"; + prop_desc = "USB Id of the device"; + 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 = "SerialNumber"; + prop_desc = "Serial number of the device"; + 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 = "NFramesBuffered"; + prop_desc = "number of frames buffered when in live mode"; + 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 = "DefaultStartRegion"; + prop_desc = "Beginning of the region of interest"; + 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 = "DefaultEndRegion"; + prop_desc = "End of the region of interest"; + 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 = "SleepReading"; + prop_desc = "Sleep time between reading 2 frames (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 = "DefaultGaussRef"; + prop_desc = "Default Gauss Reference"; + 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 = "DataReferenceFile"; + prop_desc = "Default Data Reference File"; + 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 = "PreferFWHM"; + prop_desc = "Choose FWHM instead og GaussianFit if both enabled"; + 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 = "AutoExposureRange"; + prop_desc = "AutoExposure Range"; + 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 = "AutoExposureStep"; + prop_desc = "AutoExposure Step"; + 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 = "AutoExposureAmpRange"; + prop_desc = "AutoExposure Range"; + 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 = "IntensityCalibrationFile"; + 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 = "NoiseProfileFile"; + prop_desc = "Default Noise Profile File"; + 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 = "WavelengthAttr"; + prop_desc = "device name\nattribute name"; + 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 = "AreaInAnalysisRegion"; + prop_desc = "use AnalysisRegion for area instead of AreaRegion"; + prop_def = "false"; + vect_data.clear(); + vect_data.push_back("false"); + 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 = "WidthCorrection"; + prop_desc = "widht_in^2 + widthcorrection^2 = widht_out^2"; + 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); +} + +//-------------------------------------------------------- +/** + * Method : OceanOpticsClass::write_class_property() + * Description : Set class description fields as property in database + */ +//-------------------------------------------------------- +void OceanOpticsClass::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("OceanOptics Spectrometers"); + title << str_title; + data.push_back(title); + + // Put Description + Tango::DbDatum description("Description"); + vector<string> str_desc; + str_desc.push_back("Tango device server for OceanOptics compact wide-range spectrometer"); + description << str_desc; + data.push_back(description); + + // put cvs or svn location + string filename("OceanOptics"); + filename += "Class.cpp"; + + // check for cvs information + string src_path(CvsPath); + start = src_path.find("/"); + if (start!=string::npos) + { + end = src_path.find(filename); + if (end>start) + { + string strloc = src_path.substr(start, end-start); + // Check if specific repository + start = strloc.find("/cvsroot/"); + if (start!=string::npos && start>0) + { + string repository = strloc.substr(0, start); + if (repository.find("/segfs/")!=string::npos) + strloc = "ESRF:" + strloc.substr(start, strloc.length()-start); + } + Tango::DbDatum cvs_loc("cvs_location"); + cvs_loc << strloc; + data.push_back(cvs_loc); + } + } + + // check for svn information + else + { + string src_path(SvnPath); + start = src_path.find("://"); + if (start!=string::npos) + { + end = src_path.find(filename); + if (end>start) + { + header = "$HeadURL: "; + start = header.length(); + string strloc = src_path.substr(start, (end-start)); + + Tango::DbDatum svn_loc("svn_location"); + svn_loc << strloc; + data.push_back(svn_loc); + } + } + } + + // Get CVS or SVN revision tag + + // CVS tag + string tagname(TagName); + header = "$Name: "; + start = header.length(); + string endstr(" $"); + + end = tagname.find(endstr); + if (end!=string::npos && end>start) + { + string strtag = tagname.substr(start, end-start); + Tango::DbDatum cvs_tag("cvs_tag"); + cvs_tag << strtag; + data.push_back(cvs_tag); + } + + // SVN tag + string svnpath(SvnPath); + header = "$HeadURL: "; + start = header.length(); + + end = svnpath.find(endstr); + if (end!=string::npos && end>start) + { + string strloc = svnpath.substr(start, end-start); + + string tagstr ("/tags/"); + start = strloc.find(tagstr); + if ( start!=string::npos ) + { + start = start + tagstr.length(); + end = strloc.find(filename); + string strtag = strloc.substr(start, end-start-1); + + Tango::DbDatum svn_tag("svn_tag"); + svn_tag << strtag; + data.push_back(svn_tag); + } + } + + // Get URL location + string httpServ(HttpServer); + if (httpServ.length()>0) + { + Tango::DbDatum db_doc_url("doc_url"); + db_doc_url << httpServ; + data.push_back(db_doc_url); + } + + // Put inheritance + Tango::DbDatum inher_datum("InheritedFrom"); + vector<string> inheritance; + inheritance.push_back("TANGO_BASE_CLASS"); + inher_datum << inheritance; + data.push_back(inher_datum); + + // Call database and and values + get_db_class()->put_property(data); +} + +//=================================================================== +// Factory methods +//=================================================================== + +//-------------------------------------------------------- +/** + * Method : OceanOpticsClass::device_factory() + * Description : Create the device object(s) + * and store them in the device list + */ +//-------------------------------------------------------- +void OceanOpticsClass::device_factory(const Tango::DevVarStringArray *devlist_ptr) +{ + /*----- PROTECTED REGION ID(OceanOpticsClass::device_factory_before) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::device_factory_before + + // Create devices and add it into the device list + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + cout4 << "Device name : " << (*devlist_ptr)[i].in() << endl; + device_list.push_back(new OceanOptics(this, (*devlist_ptr)[i])); + } + + // Manage dynamic attributes if any + erase_dynamic_attributes(devlist_ptr, get_class_attr()->get_attr_list()); + + // Export devices to the outside world + for (unsigned long i=1 ; i<=devlist_ptr->length() ; i++) + { + // Add dynamic attributes if any + OceanOptics *dev = static_cast<OceanOptics *>(device_list[device_list.size()-i]); + dev->add_dynamic_attributes(); + + // Check before if database used. + if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false)) + export_device(dev); + else + export_device(dev, dev->get_name().c_str()); + } + + /*----- PROTECTED REGION ID(OceanOpticsClass::device_factory_after) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::device_factory_after +} +//-------------------------------------------------------- +/** + * Method : OceanOpticsClass::attribute_factory() + * Description : Create the attribute object(s) + * and store them in the attribute list + */ +//-------------------------------------------------------- +void OceanOpticsClass::attribute_factory(vector<Tango::Attr *> &att_list) +{ + /*----- PROTECTED REGION ID(OceanOpticsClass::attribute_factory_before) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::attribute_factory_before + // Attribute : ExposureTime + ExposureTimeAttrib *exposuretime = new ExposureTimeAttrib(); + Tango::UserDefaultAttrProp exposuretime_prop; + exposuretime_prop.set_description("Exposure time in milliseconds"); + // label not set for ExposureTime + exposuretime_prop.set_unit("ms"); + exposuretime_prop.set_standard_unit("1.0"); + exposuretime_prop.set_display_unit("ms"); + exposuretime_prop.set_format("%6.2f"); + // max_value not set for ExposureTime + exposuretime_prop.set_min_value("0"); + // max_alarm not set for ExposureTime + // min_alarm not set for ExposureTime + // max_warning not set for ExposureTime + // min_warning not set for ExposureTime + // delta_t not set for ExposureTime + // delta_val not set for ExposureTime + + exposuretime->set_default_properties(exposuretime_prop); + // Not Polled + exposuretime->set_disp_level(Tango::OPERATOR); + exposuretime->set_memorized(); + exposuretime->set_memorized_init(true); + att_list.push_back(exposuretime); + + // Attribute : IncrSensitivity + IncrSensitivityAttrib *incrsensitivity = new IncrSensitivityAttrib(); + Tango::UserDefaultAttrProp incrsensitivity_prop; + incrsensitivity_prop.set_description("false: use standard sensitivity\ntrue: use increased sensitivity"); + // label not set for IncrSensitivity + // unit not set for IncrSensitivity + // standard_unit not set for IncrSensitivity + // display_unit not set for IncrSensitivity + // format not set for IncrSensitivity + // max_value not set for IncrSensitivity + // min_value not set for IncrSensitivity + // max_alarm not set for IncrSensitivity + // min_alarm not set for IncrSensitivity + // max_warning not set for IncrSensitivity + // min_warning not set for IncrSensitivity + // delta_t not set for IncrSensitivity + // delta_val not set for IncrSensitivity + + incrsensitivity->set_default_properties(incrsensitivity_prop); + // Not Polled + incrsensitivity->set_disp_level(Tango::OPERATOR); + incrsensitivity->set_memorized(); + incrsensitivity->set_memorized_init(true); + att_list.push_back(incrsensitivity); + + // Attribute : SyncMode + SyncModeAttrib *syncmode = new SyncModeAttrib(); + Tango::UserDefaultAttrProp syncmode_prop; + syncmode_prop.set_description("0: The camera operates without synchronization.\nSpectra are read out periodically in accordance with NumReadouts attribute.\n\n1: Readout is performed periodically in accordance with NumReadouts attribute.\nAt the beginning of the first readout a positive sync pulse is formed.\n\n2: A sync pulse is formed at beginning of each readout.\n\n3: One sync pulse of negative polarity is generated for the entire readout time.\n\n4: The camera will wait for one sync pulse.\nThe first readout will start at the rising edge of an external sync pulse.\nAll other readouts will be performed as soon as possible.\nNo blanks within limit\n\n5: Each readout starts at the rising edge of an external sync pulse.\nThe camera will wait fo as many sync pulses as much readouts are set."); + // label not set for SyncMode + // unit not set for SyncMode + // standard_unit not set for SyncMode + // display_unit not set for SyncMode + // format not set for SyncMode + syncmode_prop.set_max_value("5"); + syncmode_prop.set_min_value("0"); + // max_alarm not set for SyncMode + // min_alarm not set for SyncMode + // max_warning not set for SyncMode + // min_warning not set for SyncMode + // delta_t not set for SyncMode + // delta_val not set for SyncMode + + syncmode->set_default_properties(syncmode_prop); + // Not Polled + syncmode->set_disp_level(Tango::OPERATOR); + syncmode->set_memorized(); + syncmode->set_memorized_init(true); + att_list.push_back(syncmode); + + // Attribute : NoiseSubtraction + NoiseSubtractionAttrib *noisesubtraction = new NoiseSubtractionAttrib(); + Tango::UserDefaultAttrProp noisesubtraction_prop; + noisesubtraction_prop.set_description("Enable/Disable subtraction of background noise profile \nacquired with the AcquireNoise command"); + // label not set for NoiseSubtraction + // unit not set for NoiseSubtraction + // standard_unit not set for NoiseSubtraction + // display_unit not set for NoiseSubtraction + // format not set for NoiseSubtraction + // max_value not set for NoiseSubtraction + // min_value not set for NoiseSubtraction + // max_alarm not set for NoiseSubtraction + // min_alarm not set for NoiseSubtraction + // max_warning not set for NoiseSubtraction + // min_warning not set for NoiseSubtraction + // delta_t not set for NoiseSubtraction + // delta_val not set for NoiseSubtraction + + noisesubtraction->set_default_properties(noisesubtraction_prop); + // Not Polled + noisesubtraction->set_disp_level(Tango::OPERATOR); + noisesubtraction->set_memorized(); + noisesubtraction->set_memorized_init(true); + att_list.push_back(noisesubtraction); + + // Attribute : GaussFitEnable + GaussFitEnableAttrib *gaussfitenable = new GaussFitEnableAttrib(); + Tango::UserDefaultAttrProp gaussfitenable_prop; + // description not set for GaussFitEnable + // label not set for GaussFitEnable + // unit not set for GaussFitEnable + // standard_unit not set for GaussFitEnable + // display_unit not set for GaussFitEnable + // format not set for GaussFitEnable + // max_value not set for GaussFitEnable + // min_value not set for GaussFitEnable + // max_alarm not set for GaussFitEnable + // min_alarm not set for GaussFitEnable + // max_warning not set for GaussFitEnable + // min_warning not set for GaussFitEnable + // delta_t not set for GaussFitEnable + // delta_val not set for GaussFitEnable + + gaussfitenable->set_default_properties(gaussfitenable_prop); + // Not Polled + gaussfitenable->set_disp_level(Tango::OPERATOR); + gaussfitenable->set_memorized(); + gaussfitenable->set_memorized_init(true); + att_list.push_back(gaussfitenable); + + // Attribute : FWHMEnable + FWHMEnableAttrib *fwhmenable = new FWHMEnableAttrib(); + Tango::UserDefaultAttrProp fwhmenable_prop; + // description not set for FWHMEnable + // label not set for FWHMEnable + // unit not set for FWHMEnable + // standard_unit not set for FWHMEnable + // display_unit not set for FWHMEnable + // format not set for FWHMEnable + // max_value not set for FWHMEnable + // min_value not set for FWHMEnable + // max_alarm not set for FWHMEnable + // min_alarm not set for FWHMEnable + // max_warning not set for FWHMEnable + // min_warning not set for FWHMEnable + // delta_t not set for FWHMEnable + // delta_val not set for FWHMEnable + + fwhmenable->set_default_properties(fwhmenable_prop); + // Not Polled + fwhmenable->set_disp_level(Tango::OPERATOR); + fwhmenable->set_memorized(); + fwhmenable->set_memorized_init(true); + att_list.push_back(fwhmenable); + + // Attribute : GaussFitCenter + GaussFitCenterAttrib *gaussfitcenter = new GaussFitCenterAttrib(); + Tango::UserDefaultAttrProp gaussfitcenter_prop; + gaussfitcenter_prop.set_description("wavelength of peak of Gaussian Fit"); + // label not set for GaussFitCenter + // unit not set for GaussFitCenter + // standard_unit not set for GaussFitCenter + // display_unit not set for GaussFitCenter + // format not set for GaussFitCenter + // max_value not set for GaussFitCenter + // min_value not set for GaussFitCenter + // max_alarm not set for GaussFitCenter + // min_alarm not set for GaussFitCenter + // max_warning not set for GaussFitCenter + // min_warning not set for GaussFitCenter + // delta_t not set for GaussFitCenter + // delta_val not set for GaussFitCenter + + gaussfitcenter->set_default_properties(gaussfitcenter_prop); + // Not Polled + gaussfitcenter->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(gaussfitcenter); + + // Attribute : GaussFitWidth + GaussFitWidthAttrib *gaussfitwidth = new GaussFitWidthAttrib(); + Tango::UserDefaultAttrProp gaussfitwidth_prop; + gaussfitwidth_prop.set_description("width of Gaussian Fit"); + // label not set for GaussFitWidth + // unit not set for GaussFitWidth + // standard_unit not set for GaussFitWidth + // display_unit not set for GaussFitWidth + // format not set for GaussFitWidth + // max_value not set for GaussFitWidth + // min_value not set for GaussFitWidth + // max_alarm not set for GaussFitWidth + // min_alarm not set for GaussFitWidth + // max_warning not set for GaussFitWidth + // min_warning not set for GaussFitWidth + // delta_t not set for GaussFitWidth + // delta_val not set for GaussFitWidth + + gaussfitwidth->set_default_properties(gaussfitwidth_prop); + // Not Polled + gaussfitwidth->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(gaussfitwidth); + + // Attribute : FWHMCenter + FWHMCenterAttrib *fwhmcenter = new FWHMCenterAttrib(); + Tango::UserDefaultAttrProp fwhmcenter_prop; + // description not set for FWHMCenter + // label not set for FWHMCenter + // unit not set for FWHMCenter + // standard_unit not set for FWHMCenter + // display_unit not set for FWHMCenter + // format not set for FWHMCenter + // max_value not set for FWHMCenter + // min_value not set for FWHMCenter + // max_alarm not set for FWHMCenter + // min_alarm not set for FWHMCenter + // max_warning not set for FWHMCenter + // min_warning not set for FWHMCenter + // delta_t not set for FWHMCenter + // delta_val not set for FWHMCenter + + fwhmcenter->set_default_properties(fwhmcenter_prop); + // Not Polled + fwhmcenter->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(fwhmcenter); + + // Attribute : FWHMWidth + FWHMWidthAttrib *fwhmwidth = new FWHMWidthAttrib(); + Tango::UserDefaultAttrProp fwhmwidth_prop; + // description not set for FWHMWidth + // label not set for FWHMWidth + // unit not set for FWHMWidth + // standard_unit not set for FWHMWidth + // display_unit not set for FWHMWidth + // format not set for FWHMWidth + // max_value not set for FWHMWidth + // min_value not set for FWHMWidth + // max_alarm not set for FWHMWidth + // min_alarm not set for FWHMWidth + // max_warning not set for FWHMWidth + // min_warning not set for FWHMWidth + // delta_t not set for FWHMWidth + // delta_val not set for FWHMWidth + + fwhmwidth->set_default_properties(fwhmwidth_prop); + // Not Polled + fwhmwidth->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(fwhmwidth); + + // Attribute : Center + CenterAttrib *center = new CenterAttrib(); + Tango::UserDefaultAttrProp center_prop; + center_prop.set_description("wavelength of peak of FWHM or of Gaussian Fit"); + // label not set for Center + // unit not set for Center + // standard_unit not set for Center + // display_unit not set for Center + // format not set for Center + // max_value not set for Center + // min_value not set for Center + // max_alarm not set for Center + // min_alarm not set for Center + // max_warning not set for Center + // min_warning not set for Center + // delta_t not set for Center + // delta_val not set for Center + + center->set_default_properties(center_prop); + // Not Polled + center->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(center); + + // Attribute : Width + WidthAttrib *width = new WidthAttrib(); + Tango::UserDefaultAttrProp width_prop; + width_prop.set_description("width of FWHM or of Gaussian Fit"); + // label not set for Width + // unit not set for Width + // standard_unit not set for Width + // display_unit not set for Width + // format not set for Width + // max_value not set for Width + // min_value not set for Width + // max_alarm not set for Width + // min_alarm not set for Width + // max_warning not set for Width + // min_warning not set for Width + // delta_t not set for Width + // delta_val not set for Width + + width->set_default_properties(width_prop); + // Not Polled + width->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(width); + + // Attribute : FitType + FitTypeAttrib *fittype = new FitTypeAttrib(); + Tango::UserDefaultAttrProp fittype_prop; + fittype_prop.set_description("1=Gaussian 2=Gaussian Asymm 3=Confiteor"); + // label not set for FitType + // unit not set for FitType + // standard_unit not set for FitType + // display_unit not set for FitType + // format not set for FitType + fittype_prop.set_max_value("3"); + fittype_prop.set_min_value("1"); + // max_alarm not set for FitType + // min_alarm not set for FitType + // max_warning not set for FitType + // min_warning not set for FitType + // delta_t not set for FitType + // delta_val not set for FitType + + fittype->set_default_properties(fittype_prop); + // Not Polled + fittype->set_disp_level(Tango::OPERATOR); + fittype->set_memorized(); + fittype->set_memorized_init(true); + att_list.push_back(fittype); + + // Attribute : FWHMAvg + FWHMAvgAttrib *fwhmavg = new FWHMAvgAttrib(); + Tango::UserDefaultAttrProp fwhmavg_prop; + // description not set for FWHMAvg + // label not set for FWHMAvg + // unit not set for FWHMAvg + // standard_unit not set for FWHMAvg + // display_unit not set for FWHMAvg + // format not set for FWHMAvg + // max_value not set for FWHMAvg + // min_value not set for FWHMAvg + // max_alarm not set for FWHMAvg + // min_alarm not set for FWHMAvg + // max_warning not set for FWHMAvg + // min_warning not set for FWHMAvg + // delta_t not set for FWHMAvg + // delta_val not set for FWHMAvg + + fwhmavg->set_default_properties(fwhmavg_prop); + // Not Polled + fwhmavg->set_disp_level(Tango::OPERATOR); + fwhmavg->set_memorized(); + fwhmavg->set_memorized_init(true); + att_list.push_back(fwhmavg); + + // Attribute : NoiseLevel + NoiseLevelAttrib *noiselevel = new NoiseLevelAttrib(); + Tango::UserDefaultAttrProp noiselevel_prop; + // description not set for NoiseLevel + // label not set for NoiseLevel + // unit not set for NoiseLevel + // standard_unit not set for NoiseLevel + // display_unit not set for NoiseLevel + // format not set for NoiseLevel + // max_value not set for NoiseLevel + // min_value not set for NoiseLevel + // max_alarm not set for NoiseLevel + // min_alarm not set for NoiseLevel + // max_warning not set for NoiseLevel + // min_warning not set for NoiseLevel + // delta_t not set for NoiseLevel + // delta_val not set for NoiseLevel + + noiselevel->set_default_properties(noiselevel_prop); + // Not Polled + noiselevel->set_disp_level(Tango::OPERATOR); + noiselevel->set_memorized(); + noiselevel->set_memorized_init(true); + att_list.push_back(noiselevel); + + // Attribute : DataReferenceFile + DataReferenceFileAttrib *datareferencefile = new DataReferenceFileAttrib(); + Tango::UserDefaultAttrProp datareferencefile_prop; + // description not set for DataReferenceFile + // label not set for DataReferenceFile + // unit not set for DataReferenceFile + // standard_unit not set for DataReferenceFile + // display_unit not set for DataReferenceFile + // format not set for DataReferenceFile + // max_value not set for DataReferenceFile + // min_value not set for DataReferenceFile + // max_alarm not set for DataReferenceFile + // min_alarm not set for DataReferenceFile + // max_warning not set for DataReferenceFile + // min_warning not set for DataReferenceFile + // delta_t not set for DataReferenceFile + // delta_val not set for DataReferenceFile + + datareferencefile->set_default_properties(datareferencefile_prop); + // Not Polled + datareferencefile->set_disp_level(Tango::OPERATOR); + datareferencefile->set_memorized(); + datareferencefile->set_memorized_init(true); + att_list.push_back(datareferencefile); + + // Attribute : AutoExposure + AutoExposureAttrib *autoexposure = new AutoExposureAttrib(); + Tango::UserDefaultAttrProp autoexposure_prop; + // description not set for AutoExposure + // label not set for AutoExposure + // unit not set for AutoExposure + // standard_unit not set for AutoExposure + // display_unit not set for AutoExposure + // format not set for AutoExposure + // max_value not set for AutoExposure + // min_value not set for AutoExposure + // max_alarm not set for AutoExposure + // min_alarm not set for AutoExposure + // max_warning not set for AutoExposure + // min_warning not set for AutoExposure + // delta_t not set for AutoExposure + // delta_val not set for AutoExposure + + autoexposure->set_default_properties(autoexposure_prop); + // Not Polled + autoexposure->set_disp_level(Tango::OPERATOR); + autoexposure->set_memorized(); + autoexposure->set_memorized_init(true); + att_list.push_back(autoexposure); + + // Attribute : LightSourceIntensity + LightSourceIntensityAttrib *lightsourceintensity = new LightSourceIntensityAttrib(); + Tango::UserDefaultAttrProp lightsourceintensity_prop; + // description not set for LightSourceIntensity + // label not set for LightSourceIntensity + // unit not set for LightSourceIntensity + // standard_unit not set for LightSourceIntensity + // display_unit not set for LightSourceIntensity + // format not set for LightSourceIntensity + // max_value not set for LightSourceIntensity + // min_value not set for LightSourceIntensity + // max_alarm not set for LightSourceIntensity + // min_alarm not set for LightSourceIntensity + // max_warning not set for LightSourceIntensity + // min_warning not set for LightSourceIntensity + // delta_t not set for LightSourceIntensity + // delta_val not set for LightSourceIntensity + + lightsourceintensity->set_default_properties(lightsourceintensity_prop); + // Not Polled + lightsourceintensity->set_disp_level(Tango::OPERATOR); + lightsourceintensity->set_memorized(); + lightsourceintensity->set_memorized_init(true); + att_list.push_back(lightsourceintensity); + + // Attribute : RtMode + RtModeAttrib *rtmode = new RtModeAttrib(); + Tango::UserDefaultAttrProp rtmode_prop; + // description not set for RtMode + // label not set for RtMode + // unit not set for RtMode + // standard_unit not set for RtMode + // display_unit not set for RtMode + // format not set for RtMode + // max_value not set for RtMode + // min_value not set for RtMode + // max_alarm not set for RtMode + // min_alarm not set for RtMode + // max_warning not set for RtMode + // min_warning not set for RtMode + // delta_t not set for RtMode + // delta_val not set for RtMode + + rtmode->set_default_properties(rtmode_prop); + // Not Polled + rtmode->set_disp_level(Tango::OPERATOR); + rtmode->set_memorized(); + rtmode->set_memorized_init(true); + att_list.push_back(rtmode); + + // Attribute : LightSourceEnable + LightSourceEnableAttrib *lightsourceenable = new LightSourceEnableAttrib(); + Tango::UserDefaultAttrProp lightsourceenable_prop; + // description not set for LightSourceEnable + // label not set for LightSourceEnable + // unit not set for LightSourceEnable + // standard_unit not set for LightSourceEnable + // display_unit not set for LightSourceEnable + // format not set for LightSourceEnable + // max_value not set for LightSourceEnable + // min_value not set for LightSourceEnable + // max_alarm not set for LightSourceEnable + // min_alarm not set for LightSourceEnable + // max_warning not set for LightSourceEnable + // min_warning not set for LightSourceEnable + // delta_t not set for LightSourceEnable + // delta_val not set for LightSourceEnable + + lightsourceenable->set_default_properties(lightsourceenable_prop); + // Not Polled + lightsourceenable->set_disp_level(Tango::OPERATOR); + lightsourceenable->set_memorized(); + lightsourceenable->set_memorized_init(true); + att_list.push_back(lightsourceenable); + + // Attribute : IntensityCalibrationEnable + IntensityCalibrationEnableAttrib *intensitycalibrationenable = new IntensityCalibrationEnableAttrib(); + Tango::UserDefaultAttrProp intensitycalibrationenable_prop; + // description not set for IntensityCalibrationEnable + // label not set for IntensityCalibrationEnable + // unit not set for IntensityCalibrationEnable + // standard_unit not set for IntensityCalibrationEnable + // display_unit not set for IntensityCalibrationEnable + // format not set for IntensityCalibrationEnable + // max_value not set for IntensityCalibrationEnable + // min_value not set for IntensityCalibrationEnable + // max_alarm not set for IntensityCalibrationEnable + // min_alarm not set for IntensityCalibrationEnable + // max_warning not set for IntensityCalibrationEnable + // min_warning not set for IntensityCalibrationEnable + // delta_t not set for IntensityCalibrationEnable + // delta_val not set for IntensityCalibrationEnable + + intensitycalibrationenable->set_default_properties(intensitycalibrationenable_prop); + // Not Polled + intensitycalibrationenable->set_disp_level(Tango::OPERATOR); + intensitycalibrationenable->set_memorized(); + intensitycalibrationenable->set_memorized_init(true); + att_list.push_back(intensitycalibrationenable); + + // Attribute : Area + AreaAttrib *area = new AreaAttrib(); + Tango::UserDefaultAttrProp area_prop; + // description not set for Area + // label not set for Area + // unit not set for Area + // standard_unit not set for Area + // display_unit not set for Area + // format not set for Area + // max_value not set for Area + // min_value not set for Area + // max_alarm not set for Area + // min_alarm not set for Area + // max_warning not set for Area + // min_warning not set for Area + // delta_t not set for Area + // delta_val not set for Area + + area->set_default_properties(area_prop); + // Not Polled + area->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(area); + + // Attribute : AreaRegion + AreaRegionAttrib *arearegion = new AreaRegionAttrib(); + Tango::UserDefaultAttrProp arearegion_prop; + // description not set for AreaRegion + // label not set for AreaRegion + // unit not set for AreaRegion + // standard_unit not set for AreaRegion + // display_unit not set for AreaRegion + // format not set for AreaRegion + // max_value not set for AreaRegion + // min_value not set for AreaRegion + // max_alarm not set for AreaRegion + // min_alarm not set for AreaRegion + // max_warning not set for AreaRegion + // min_warning not set for AreaRegion + // delta_t not set for AreaRegion + // delta_val not set for AreaRegion + + arearegion->set_default_properties(arearegion_prop); + // Not Polled + arearegion->set_disp_level(Tango::OPERATOR); + arearegion->set_memorized(); + arearegion->set_memorized_init(true); + att_list.push_back(arearegion); + + // Attribute : AreaEnable + AreaEnableAttrib *areaenable = new AreaEnableAttrib(); + Tango::UserDefaultAttrProp areaenable_prop; + // description not set for AreaEnable + // label not set for AreaEnable + // unit not set for AreaEnable + // standard_unit not set for AreaEnable + // display_unit not set for AreaEnable + // format not set for AreaEnable + // max_value not set for AreaEnable + // min_value not set for AreaEnable + // max_alarm not set for AreaEnable + // min_alarm not set for AreaEnable + // max_warning not set for AreaEnable + // min_warning not set for AreaEnable + // delta_t not set for AreaEnable + // delta_val not set for AreaEnable + + areaenable->set_default_properties(areaenable_prop); + // Not Polled + areaenable->set_disp_level(Tango::OPERATOR); + areaenable->set_memorized(); + areaenable->set_memorized_init(true); + att_list.push_back(areaenable); + + // Attribute : WidhtCorrectionEnable + WidhtCorrectionEnableAttrib *widhtcorrectionenable = new WidhtCorrectionEnableAttrib(); + Tango::UserDefaultAttrProp widhtcorrectionenable_prop; + widhtcorrectionenable_prop.set_description("enable widht correction"); + // label not set for WidhtCorrectionEnable + // unit not set for WidhtCorrectionEnable + // standard_unit not set for WidhtCorrectionEnable + // display_unit not set for WidhtCorrectionEnable + // format not set for WidhtCorrectionEnable + // max_value not set for WidhtCorrectionEnable + // min_value not set for WidhtCorrectionEnable + // max_alarm not set for WidhtCorrectionEnable + // min_alarm not set for WidhtCorrectionEnable + // max_warning not set for WidhtCorrectionEnable + // min_warning not set for WidhtCorrectionEnable + // delta_t not set for WidhtCorrectionEnable + // delta_val not set for WidhtCorrectionEnable + + widhtcorrectionenable->set_default_properties(widhtcorrectionenable_prop); + // Not Polled + widhtcorrectionenable->set_disp_level(Tango::OPERATOR); + widhtcorrectionenable->set_memorized(); + widhtcorrectionenable->set_memorized_init(true); + att_list.push_back(widhtcorrectionenable); + + // Attribute : NumPixels + NumPixelsAttrib *numpixels = new NumPixelsAttrib(); + Tango::UserDefaultAttrProp numpixels_prop; + numpixels_prop.set_description("long[0]: number of pixels horizontally (number of CCD-array columns)\nlong[1]: number of pixels vertically (number of CCD-array lines)"); + // label not set for NumPixels + // unit not set for NumPixels + // standard_unit not set for NumPixels + // display_unit not set for NumPixels + // format not set for NumPixels + // max_value not set for NumPixels + // min_value not set for NumPixels + // max_alarm not set for NumPixels + // min_alarm not set for NumPixels + // max_warning not set for NumPixels + // min_warning not set for NumPixels + // delta_t not set for NumPixels + // delta_val not set for NumPixels + + numpixels->set_default_properties(numpixels_prop); + // Not Polled + numpixels->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(numpixels); + + // Attribute : Data + DataAttrib *data = new DataAttrib(); + Tango::UserDefaultAttrProp data_prop; + // description not set for Data + // label not set for Data + // unit not set for Data + // standard_unit not set for Data + // display_unit not set for Data + // format not set for Data + // max_value not set for Data + // min_value not set for Data + // max_alarm not set for Data + // min_alarm not set for Data + // max_warning not set for Data + // min_warning not set for Data + // delta_t not set for Data + // delta_val not set for Data + + data->set_default_properties(data_prop); + // Not Polled + data->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(data); + + // Attribute : RegionOfInterest + RegionOfInterestAttrib *regionofinterest = new RegionOfInterestAttrib(); + Tango::UserDefaultAttrProp regionofinterest_prop; + regionofinterest_prop.set_description("Region of interest returned by the Data attribute\ndouble[0]=start of the region\ndouble[1]=end of the region\n\nValues are in nm according with the conversion factor in x_values\nData attribute property"); + // label not set for RegionOfInterest + // unit not set for RegionOfInterest + // standard_unit not set for RegionOfInterest + // display_unit not set for RegionOfInterest + // format not set for RegionOfInterest + // max_value not set for RegionOfInterest + // min_value not set for RegionOfInterest + // max_alarm not set for RegionOfInterest + // min_alarm not set for RegionOfInterest + // max_warning not set for RegionOfInterest + // min_warning not set for RegionOfInterest + // delta_t not set for RegionOfInterest + // delta_val not set for RegionOfInterest + + regionofinterest->set_default_properties(regionofinterest_prop); + // Not Polled + regionofinterest->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(regionofinterest); + + // Attribute : AnalysisRegion + AnalysisRegionAttrib *analysisregion = new AnalysisRegionAttrib(); + Tango::UserDefaultAttrProp analysisregion_prop; + analysisregion_prop.set_description("Region used for gaussian and fwhm analysis\ndouble[0]=start of the region\ndouble[1]=end of the region\n\nValues are in nm according with the conversion factor in x_values\nData attribute property"); + // label not set for AnalysisRegion + // unit not set for AnalysisRegion + // standard_unit not set for AnalysisRegion + // display_unit not set for AnalysisRegion + // format not set for AnalysisRegion + // max_value not set for AnalysisRegion + // min_value not set for AnalysisRegion + // max_alarm not set for AnalysisRegion + // min_alarm not set for AnalysisRegion + // max_warning not set for AnalysisRegion + // min_warning not set for AnalysisRegion + // delta_t not set for AnalysisRegion + // delta_val not set for AnalysisRegion + + analysisregion->set_default_properties(analysisregion_prop); + // Not Polled + analysisregion->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(analysisregion); + + // Attribute : GaussFit + GaussFitAttrib *gaussfit = new GaussFitAttrib(); + Tango::UserDefaultAttrProp gaussfit_prop; + gaussfit_prop.set_description("double[0]= wavelength of peak of Gaussian Fit\ndouble[1]= width of Gaussian Fit"); + // label not set for GaussFit + // unit not set for GaussFit + // standard_unit not set for GaussFit + // display_unit not set for GaussFit + // format not set for GaussFit + // max_value not set for GaussFit + // min_value not set for GaussFit + // max_alarm not set for GaussFit + // min_alarm not set for GaussFit + // max_warning not set for GaussFit + // min_warning not set for GaussFit + // delta_t not set for GaussFit + // delta_val not set for GaussFit + + gaussfit->set_default_properties(gaussfit_prop); + // Not Polled + gaussfit->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(gaussfit); + + // Attribute : FWHM + FWHMAttrib *fwhm = new FWHMAttrib(); + Tango::UserDefaultAttrProp fwhm_prop; + fwhm_prop.set_description("double[0]= wavelength of peak of FWHM\ndouble[1]= width of FWHM"); + // label not set for FWHM + // unit not set for FWHM + // standard_unit not set for FWHM + // display_unit not set for FWHM + // format not set for FWHM + // max_value not set for FWHM + // min_value not set for FWHM + // max_alarm not set for FWHM + // min_alarm not set for FWHM + // max_warning not set for FWHM + // min_warning not set for FWHM + // delta_t not set for FWHM + // delta_val not set for FWHM + + fwhm->set_default_properties(fwhm_prop); + // Not Polled + fwhm->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(fwhm); + + // Attribute : GaussReference + GaussReferenceAttrib *gaussreference = new GaussReferenceAttrib(); + Tango::UserDefaultAttrProp gaussreference_prop; + gaussreference_prop.set_description("Gaussian of reference params"); + // label not set for GaussReference + // unit not set for GaussReference + // standard_unit not set for GaussReference + // display_unit not set for GaussReference + gaussreference_prop.set_format("%7.2f"); + // max_value not set for GaussReference + // min_value not set for GaussReference + // max_alarm not set for GaussReference + // min_alarm not set for GaussReference + // max_warning not set for GaussReference + // min_warning not set for GaussReference + // delta_t not set for GaussReference + // delta_val not set for GaussReference + + gaussreference->set_default_properties(gaussreference_prop); + // Not Polled + gaussreference->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(gaussreference); + + // Attribute : DataReference + DataReferenceAttrib *datareference = new DataReferenceAttrib(); + Tango::UserDefaultAttrProp datareference_prop; + datareference_prop.set_description("A reference curve"); + // label not set for DataReference + // unit not set for DataReference + // standard_unit not set for DataReference + // display_unit not set for DataReference + // format not set for DataReference + // max_value not set for DataReference + // min_value not set for DataReference + // max_alarm not set for DataReference + // min_alarm not set for DataReference + // max_warning not set for DataReference + // min_warning not set for DataReference + // delta_t not set for DataReference + // delta_val not set for DataReference + + datareference->set_default_properties(datareference_prop); + // Not Polled + datareference->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(datareference); + + // Attribute : IntensityCalibration + IntensityCalibrationAttrib *intensitycalibration = new IntensityCalibrationAttrib(); + Tango::UserDefaultAttrProp intensitycalibration_prop; + // description not set for IntensityCalibration + // label not set for IntensityCalibration + // unit not set for IntensityCalibration + // standard_unit not set for IntensityCalibration + // display_unit not set for IntensityCalibration + // format not set for IntensityCalibration + // max_value not set for IntensityCalibration + // min_value not set for IntensityCalibration + // max_alarm not set for IntensityCalibration + // min_alarm not set for IntensityCalibration + // max_warning not set for IntensityCalibration + // min_warning not set for IntensityCalibration + // delta_t not set for IntensityCalibration + // delta_val not set for IntensityCalibration + + intensitycalibration->set_default_properties(intensitycalibration_prop); + // Not Polled + intensitycalibration->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(intensitycalibration); + + // Attribute : NoiseProfile + NoiseProfileAttrib *noiseprofile = new NoiseProfileAttrib(); + Tango::UserDefaultAttrProp noiseprofile_prop; + // description not set for NoiseProfile + // label not set for NoiseProfile + // unit not set for NoiseProfile + // standard_unit not set for NoiseProfile + // display_unit not set for NoiseProfile + // format not set for NoiseProfile + // max_value not set for NoiseProfile + // min_value not set for NoiseProfile + // max_alarm not set for NoiseProfile + // min_alarm not set for NoiseProfile + // max_warning not set for NoiseProfile + // min_warning not set for NoiseProfile + // delta_t not set for NoiseProfile + // delta_val not set for NoiseProfile + + noiseprofile->set_default_properties(noiseprofile_prop); + // Not Polled + noiseprofile->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(noiseprofile); + + // Attribute : Wave + WaveAttrib *wave = new WaveAttrib(); + Tango::UserDefaultAttrProp wave_prop; + // description not set for Wave + // label not set for Wave + // unit not set for Wave + // standard_unit not set for Wave + // display_unit not set for Wave + // format not set for Wave + // max_value not set for Wave + // min_value not set for Wave + // max_alarm not set for Wave + // min_alarm not set for Wave + // max_warning not set for Wave + // min_warning not set for Wave + // delta_t not set for Wave + // delta_val not set for Wave + + wave->set_default_properties(wave_prop); + // Not Polled + wave->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(wave); + + // Attribute : Lambda + LambdaAttrib *lambda = new LambdaAttrib(); + Tango::UserDefaultAttrProp lambda_prop; + // description not set for Lambda + // label not set for Lambda + // unit not set for Lambda + // standard_unit not set for Lambda + // display_unit not set for Lambda + // format not set for Lambda + // max_value not set for Lambda + // min_value not set for Lambda + // max_alarm not set for Lambda + // min_alarm not set for Lambda + // max_warning not set for Lambda + // min_warning not set for Lambda + // delta_t not set for Lambda + // delta_val not set for Lambda + + lambda->set_default_properties(lambda_prop); + // Not Polled + lambda->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(lambda); + + + // Create a list of static attributes + create_static_attribute_list(get_class_attr()->get_attr_list()); + /*----- PROTECTED REGION ID(OceanOpticsClass::attribute_factory_after) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::attribute_factory_after +} +//-------------------------------------------------------- +/** + * Method : OceanOpticsClass::pipe_factory() + * Description : Create the pipe object(s) + * and store them in the pipe list + */ +//-------------------------------------------------------- +void OceanOpticsClass::pipe_factory() +{ + /*----- PROTECTED REGION ID(OceanOpticsClass::pipe_factory_before) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::pipe_factory_before + /*----- PROTECTED REGION ID(OceanOpticsClass::pipe_factory_after) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::pipe_factory_after +} +//-------------------------------------------------------- +/** + * Method : OceanOpticsClass::command_factory() + * Description : Create the command object(s) + * and store them in the command list + */ +//-------------------------------------------------------- +void OceanOpticsClass::command_factory() +{ + /*----- PROTECTED REGION ID(OceanOpticsClass::command_factory_before) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::command_factory_before + + + // Command GetVersion + GetVersionClass *pGetVersionCmd = + new GetVersionClass("GetVersion", + Tango::DEV_VOID, Tango::DEV_STRING, + "", + "serial number", + Tango::OPERATOR); + command_list.push_back(pGetVersionCmd); + + // Command Stop + StopClass *pStopCmd = + new StopClass("Stop", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pStopCmd); + + // Command StartSingle + StartSingleClass *pStartSingleCmd = + new StartSingleClass("StartSingle", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pStartSingleCmd); + + // Command StartContinuous + StartContinuousClass *pStartContinuousCmd = + new StartContinuousClass("StartContinuous", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pStartContinuousCmd); + + // Command GetLastData + GetLastDataClass *pGetLastDataCmd = + new GetLastDataClass("GetLastData", + Tango::DEV_LONG, Tango::DEVVAR_DOUBLEARRAY, + "number of frames to return", + "", + Tango::OPERATOR); + command_list.push_back(pGetLastDataCmd); + + // Command AcquireNoise + AcquireNoiseClass *pAcquireNoiseCmd = + new AcquireNoiseClass("AcquireNoise", + Tango::DEV_LONG, Tango::DEV_VOID, + "Number of frames to acquire as noise", + "", + Tango::OPERATOR); + command_list.push_back(pAcquireNoiseCmd); + + // Command SaveReferenceData + SaveReferenceDataClass *pSaveReferenceDataCmd = + new SaveReferenceDataClass("SaveReferenceData", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pSaveReferenceDataCmd); + + // Command OpenShutter + OpenShutterClass *pOpenShutterCmd = + new OpenShutterClass("OpenShutter", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pOpenShutterCmd); + + // Command CloseShutter + CloseShutterClass *pCloseShutterCmd = + new CloseShutterClass("CloseShutter", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pCloseShutterCmd); + + // Command GetData + GetDataClass *pGetDataCmd = + new GetDataClass("GetData", + Tango::DEVVAR_LONGARRAY, Tango::DEVVAR_DOUBLEARRAY, + "", + "", + Tango::OPERATOR); + command_list.push_back(pGetDataCmd); + + // Command GetGaussFitCenter + GetGaussFitCenterClass *pGetGaussFitCenterCmd = + new GetGaussFitCenterClass("GetGaussFitCenter", + Tango::DEVVAR_LONGARRAY, Tango::DEVVAR_DOUBLEARRAY, + "", + "", + Tango::OPERATOR); + command_list.push_back(pGetGaussFitCenterCmd); + + // Command GetGaussFitWidth + GetGaussFitWidthClass *pGetGaussFitWidthCmd = + new GetGaussFitWidthClass("GetGaussFitWidth", + Tango::DEVVAR_LONGARRAY, Tango::DEVVAR_DOUBLEARRAY, + "", + "", + Tango::OPERATOR); + command_list.push_back(pGetGaussFitWidthCmd); + + // Command GetFWHMCenter + GetFWHMCenterClass *pGetFWHMCenterCmd = + new GetFWHMCenterClass("GetFWHMCenter", + Tango::DEVVAR_LONGARRAY, Tango::DEVVAR_DOUBLEARRAY, + "", + "", + Tango::OPERATOR); + command_list.push_back(pGetFWHMCenterCmd); + + // Command GetFWHMWidth + GetFWHMWidthClass *pGetFWHMWidthCmd = + new GetFWHMWidthClass("GetFWHMWidth", + Tango::DEVVAR_LONGARRAY, Tango::DEVVAR_DOUBLEARRAY, + "", + "", + Tango::OPERATOR); + command_list.push_back(pGetFWHMWidthCmd); + + // Command ExportWavelength + ExportWavelengthClass *pExportWavelengthCmd = + new ExportWavelengthClass("ExportWavelength", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pExportWavelengthCmd); + + // Command GetArea + GetAreaClass *pGetAreaCmd = + new GetAreaClass("GetArea", + Tango::DEVVAR_LONGARRAY, Tango::DEVVAR_DOUBLEARRAY, + "", + "", + Tango::OPERATOR); + command_list.push_back(pGetAreaCmd); + + // Command GetWave + GetWaveClass *pGetWaveCmd = + new GetWaveClass("GetWave", + Tango::DEVVAR_LONGARRAY, Tango::DEVVAR_DOUBLEARRAY, + "", + "", + Tango::OPERATOR); + command_list.push_back(pGetWaveCmd); + + // Command GetLambda + GetLambdaClass *pGetLambdaCmd = + new GetLambdaClass("GetLambda", + Tango::DEVVAR_LONGARRAY, Tango::DEVVAR_DOUBLEARRAY, + "", + "", + Tango::OPERATOR); + command_list.push_back(pGetLambdaCmd); + + /*----- PROTECTED REGION ID(OceanOpticsClass::command_factory_after) ENABLED START -----*/ + + // Add your own code + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::command_factory_after +} + +//=================================================================== +// Dynamic attributes related methods +//=================================================================== + +//-------------------------------------------------------- +/** + * method : OceanOpticsClass::create_static_attribute_list + * description : Create the a list of static attributes + * + * @param att_list the ceated attribute list + */ +//-------------------------------------------------------- +void OceanOpticsClass::create_static_attribute_list(vector<Tango::Attr *> &att_list) +{ + for (unsigned long i=0 ; i<att_list.size() ; i++) + { + string att_name(att_list[i]->get_name()); + transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower); + defaultAttList.push_back(att_name); + } + + cout2 << defaultAttList.size() << " attributes in default list" << endl; + + /*----- PROTECTED REGION ID(OceanOpticsClass::create_static_att_list) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::create_static_att_list +} + + +//-------------------------------------------------------- +/** + * method : OceanOpticsClass::erase_dynamic_attributes + * description : delete the dynamic attributes if any. + * + * @param devlist_ptr the device list pointer + * @param list of all attributes + */ +//-------------------------------------------------------- +void OceanOpticsClass::erase_dynamic_attributes(const Tango::DevVarStringArray *devlist_ptr, vector<Tango::Attr *> &att_list) +{ + Tango::Util *tg = Tango::Util::instance(); + + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + Tango::DeviceImpl *dev_impl = tg->get_device_by_name(((string)(*devlist_ptr)[i]).c_str()); + OceanOptics *dev = static_cast<OceanOptics *> (dev_impl); + + vector<Tango::Attribute *> &dev_att_list = dev->get_device_attr()->get_attribute_list(); + vector<Tango::Attribute *>::iterator ite_att; + for (ite_att=dev_att_list.begin() ; ite_att != dev_att_list.end() ; ++ite_att) + { + string att_name((*ite_att)->get_name_lower()); + if ((att_name == "state") || (att_name == "status")) + continue; + vector<string>::iterator ite_str = find(defaultAttList.begin(), defaultAttList.end(), att_name); + if (ite_str == defaultAttList.end()) + { + cout2 << att_name << " is a UNWANTED dynamic attribute for device " << (*devlist_ptr)[i] << endl; + Tango::Attribute &att = dev->get_device_attr()->get_attr_by_name(att_name.c_str()); + dev->remove_attribute(att_list[att.get_attr_idx()], true, false); + --ite_att; + } + } + } + /*----- PROTECTED REGION ID(OceanOpticsClass::erase_dynamic_attributes) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::erase_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Method : OceanOpticsClass::get_attr_by_name() + * Description : returns Tango::Attr * object found by name + */ +//-------------------------------------------------------- +Tango::Attr *OceanOpticsClass::get_attr_object_by_name(vector<Tango::Attr *> &att_list, string attname) +{ + vector<Tango::Attr *>::iterator it; + for (it=att_list.begin() ; it<att_list.end() ; ++it) + if ((*it)->get_name()==attname) + return (*it); + // Attr does not exist + return NULL; +} + + +/*----- PROTECTED REGION ID(OceanOpticsClass::Additional Methods) ENABLED START -----*/ + +/*----- PROTECTED REGION END -----*/ // OceanOpticsClass::Additional Methods +} // namespace diff --git a/src/OceanOpticsClass.h b/src/OceanOpticsClass.h new file mode 100644 index 0000000000000000000000000000000000000000..96eb0da36a5b419948eeb569da8c5797d72d65d9 --- /dev/null +++ b/src/OceanOpticsClass.h @@ -0,0 +1,1058 @@ +/*----- PROTECTED REGION ID(OceanOpticsClass.h) ENABLED START -----*/ +//============================================================================= +// +// file : OceanOpticsClass.h +// +// description : Include for the OceanOptics root class. +// This class is the singleton class for +// the OceanOptics device class. +// It contains all properties and methods which the +// OceanOptics requires only once e.g. the commands. +// +// project : SolarLaserSystems S100 +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// $Author: graziano $ +// +// $Revision: 1.9 $ +// $Date: 2019-04-23 11:16:11 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#ifndef OceanOpticsClass_H +#define OceanOpticsClass_H + +#include <tango.h> +#include <OceanOptics.h> + +/*----- PROTECTED REGION END -----*/ // OceanOpticsClass.h + + +namespace OceanOptics_ns +{ +/*----- PROTECTED REGION ID(OceanOpticsClass::classes for dynamic creation) ENABLED START -----*/ + + +/*----- PROTECTED REGION END -----*/ // OceanOpticsClass::classes for dynamic creation + +//========================================= +// Define classes for attributes +//========================================= +// Attribute ExposureTime class definition +class ExposureTimeAttrib: public Tango::Attr +{ +public: + ExposureTimeAttrib():Attr("ExposureTime", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {}; + ~ExposureTimeAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_ExposureTime(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_ExposureTime(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_ExposureTime_allowed(ty);} +}; + +// Attribute IncrSensitivity class definition +class IncrSensitivityAttrib: public Tango::Attr +{ +public: + IncrSensitivityAttrib():Attr("IncrSensitivity", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~IncrSensitivityAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_IncrSensitivity(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_IncrSensitivity(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_IncrSensitivity_allowed(ty);} +}; + +// Attribute SyncMode class definition +class SyncModeAttrib: public Tango::Attr +{ +public: + SyncModeAttrib():Attr("SyncMode", + Tango::DEV_LONG, Tango::READ_WRITE) {}; + ~SyncModeAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_SyncMode(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_SyncMode(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_SyncMode_allowed(ty);} +}; + +// Attribute NoiseSubtraction class definition +class NoiseSubtractionAttrib: public Tango::Attr +{ +public: + NoiseSubtractionAttrib():Attr("NoiseSubtraction", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~NoiseSubtractionAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_NoiseSubtraction(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_NoiseSubtraction(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_NoiseSubtraction_allowed(ty);} +}; + +// Attribute GaussFitEnable class definition +class GaussFitEnableAttrib: public Tango::Attr +{ +public: + GaussFitEnableAttrib():Attr("GaussFitEnable", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~GaussFitEnableAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_GaussFitEnable(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_GaussFitEnable(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_GaussFitEnable_allowed(ty);} +}; + +// Attribute FWHMEnable class definition +class FWHMEnableAttrib: public Tango::Attr +{ +public: + FWHMEnableAttrib():Attr("FWHMEnable", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~FWHMEnableAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_FWHMEnable(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_FWHMEnable(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_FWHMEnable_allowed(ty);} +}; + +// Attribute GaussFitCenter class definition +class GaussFitCenterAttrib: public Tango::Attr +{ +public: + GaussFitCenterAttrib():Attr("GaussFitCenter", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~GaussFitCenterAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_GaussFitCenter(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_GaussFitCenter_allowed(ty);} +}; + +// Attribute GaussFitWidth class definition +class GaussFitWidthAttrib: public Tango::Attr +{ +public: + GaussFitWidthAttrib():Attr("GaussFitWidth", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~GaussFitWidthAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_GaussFitWidth(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_GaussFitWidth_allowed(ty);} +}; + +// Attribute FWHMCenter class definition +class FWHMCenterAttrib: public Tango::Attr +{ +public: + FWHMCenterAttrib():Attr("FWHMCenter", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~FWHMCenterAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_FWHMCenter(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_FWHMCenter_allowed(ty);} +}; + +// Attribute FWHMWidth class definition +class FWHMWidthAttrib: public Tango::Attr +{ +public: + FWHMWidthAttrib():Attr("FWHMWidth", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~FWHMWidthAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_FWHMWidth(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_FWHMWidth_allowed(ty);} +}; + +// Attribute Center class definition +class CenterAttrib: public Tango::Attr +{ +public: + CenterAttrib():Attr("Center", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~CenterAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_Center(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_Center_allowed(ty);} +}; + +// Attribute Width class definition +class WidthAttrib: public Tango::Attr +{ +public: + WidthAttrib():Attr("Width", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~WidthAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_Width(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_Width_allowed(ty);} +}; + +// Attribute FitType class definition +class FitTypeAttrib: public Tango::Attr +{ +public: + FitTypeAttrib():Attr("FitType", + Tango::DEV_LONG, Tango::READ_WRITE) {}; + ~FitTypeAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_FitType(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_FitType(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_FitType_allowed(ty);} +}; + +// Attribute FWHMAvg class definition +class FWHMAvgAttrib: public Tango::Attr +{ +public: + FWHMAvgAttrib():Attr("FWHMAvg", + Tango::DEV_LONG, Tango::READ_WRITE) {}; + ~FWHMAvgAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_FWHMAvg(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_FWHMAvg(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_FWHMAvg_allowed(ty);} +}; + +// Attribute NoiseLevel class definition +class NoiseLevelAttrib: public Tango::Attr +{ +public: + NoiseLevelAttrib():Attr("NoiseLevel", + Tango::DEV_LONG, Tango::READ_WRITE) {}; + ~NoiseLevelAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_NoiseLevel(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_NoiseLevel(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_NoiseLevel_allowed(ty);} +}; + +// Attribute DataReferenceFile class definition +class DataReferenceFileAttrib: public Tango::Attr +{ +public: + DataReferenceFileAttrib():Attr("DataReferenceFile", + Tango::DEV_STRING, Tango::READ_WRITE) {}; + ~DataReferenceFileAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_DataReferenceFile(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_DataReferenceFile(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_DataReferenceFile_allowed(ty);} +}; + +// Attribute AutoExposure class definition +class AutoExposureAttrib: public Tango::Attr +{ +public: + AutoExposureAttrib():Attr("AutoExposure", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~AutoExposureAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_AutoExposure(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_AutoExposure(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_AutoExposure_allowed(ty);} +}; + +// Attribute LightSourceIntensity class definition +class LightSourceIntensityAttrib: public Tango::Attr +{ +public: + LightSourceIntensityAttrib():Attr("LightSourceIntensity", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {}; + ~LightSourceIntensityAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_LightSourceIntensity(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_LightSourceIntensity(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_LightSourceIntensity_allowed(ty);} +}; + +// Attribute RtMode class definition +class RtModeAttrib: public Tango::Attr +{ +public: + RtModeAttrib():Attr("RtMode", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~RtModeAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_RtMode(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_RtMode(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_RtMode_allowed(ty);} +}; + +// Attribute LightSourceEnable class definition +class LightSourceEnableAttrib: public Tango::Attr +{ +public: + LightSourceEnableAttrib():Attr("LightSourceEnable", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~LightSourceEnableAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_LightSourceEnable(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_LightSourceEnable(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_LightSourceEnable_allowed(ty);} +}; + +// Attribute IntensityCalibrationEnable class definition +class IntensityCalibrationEnableAttrib: public Tango::Attr +{ +public: + IntensityCalibrationEnableAttrib():Attr("IntensityCalibrationEnable", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~IntensityCalibrationEnableAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_IntensityCalibrationEnable(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_IntensityCalibrationEnable(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_IntensityCalibrationEnable_allowed(ty);} +}; + +// Attribute Area class definition +class AreaAttrib: public Tango::Attr +{ +public: + AreaAttrib():Attr("Area", + Tango::DEV_DOUBLE, Tango::READ) {}; + ~AreaAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_Area(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_Area_allowed(ty);} +}; + +// Attribute AreaRegion class definition +class AreaRegionAttrib: public Tango::Attr +{ +public: + AreaRegionAttrib():Attr("AreaRegion", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {}; + ~AreaRegionAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_AreaRegion(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_AreaRegion(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_AreaRegion_allowed(ty);} +}; + +// Attribute AreaEnable class definition +class AreaEnableAttrib: public Tango::Attr +{ +public: + AreaEnableAttrib():Attr("AreaEnable", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~AreaEnableAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_AreaEnable(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_AreaEnable(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_AreaEnable_allowed(ty);} +}; + +// Attribute WidhtCorrectionEnable class definition +class WidhtCorrectionEnableAttrib: public Tango::Attr +{ +public: + WidhtCorrectionEnableAttrib():Attr("WidthCorrectionEnable", + Tango::DEV_BOOLEAN, Tango::READ_WRITE) {}; + ~WidhtCorrectionEnableAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_WidhtCorrectionEnable(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_WidhtCorrectionEnable(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_WidhtCorrectionEnable_allowed(ty);} +}; + +// Attribute NumPixels class definition +class NumPixelsAttrib: public Tango::SpectrumAttr +{ +public: + NumPixelsAttrib():SpectrumAttr("NumPixels", + Tango::DEV_LONG, Tango::READ, 2) {}; + ~NumPixelsAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_NumPixels(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_NumPixels_allowed(ty);} +}; + +// Attribute Data class definition +class DataAttrib: public Tango::SpectrumAttr +{ +public: + DataAttrib():SpectrumAttr("Data", + Tango::DEV_DOUBLE, Tango::READ, 5000) {}; + ~DataAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_Data(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_Data_allowed(ty);} +}; + +// Attribute RegionOfInterest class definition +class RegionOfInterestAttrib: public Tango::SpectrumAttr +{ +public: + RegionOfInterestAttrib():SpectrumAttr("RegionOfInterest", + Tango::DEV_DOUBLE, Tango::READ_WRITE, 2) {}; + ~RegionOfInterestAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_RegionOfInterest(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_RegionOfInterest(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_RegionOfInterest_allowed(ty);} +}; + +// Attribute AnalysisRegion class definition +class AnalysisRegionAttrib: public Tango::SpectrumAttr +{ +public: + AnalysisRegionAttrib():SpectrumAttr("AnalysisRegion", + Tango::DEV_DOUBLE, Tango::READ_WRITE, 2) {}; + ~AnalysisRegionAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_AnalysisRegion(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_AnalysisRegion(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_AnalysisRegion_allowed(ty);} +}; + +// Attribute GaussFit class definition +class GaussFitAttrib: public Tango::SpectrumAttr +{ +public: + GaussFitAttrib():SpectrumAttr("GaussFit", + Tango::DEV_DOUBLE, Tango::READ, 4) {}; + ~GaussFitAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_GaussFit(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_GaussFit_allowed(ty);} +}; + +// Attribute FWHM class definition +class FWHMAttrib: public Tango::SpectrumAttr +{ +public: + FWHMAttrib():SpectrumAttr("FWHM", + Tango::DEV_DOUBLE, Tango::READ, 3) {}; + ~FWHMAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_FWHM(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_FWHM_allowed(ty);} +}; + +// Attribute GaussReference class definition +class GaussReferenceAttrib: public Tango::SpectrumAttr +{ +public: + GaussReferenceAttrib():SpectrumAttr("GaussReference", + Tango::DEV_DOUBLE, Tango::READ_WRITE, 4) {}; + ~GaussReferenceAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_GaussReference(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_GaussReference(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_GaussReference_allowed(ty);} +}; + +// Attribute DataReference class definition +class DataReferenceAttrib: public Tango::SpectrumAttr +{ +public: + DataReferenceAttrib():SpectrumAttr("DataReference", + Tango::DEV_DOUBLE, Tango::READ_WRITE, 5000) {}; + ~DataReferenceAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_DataReference(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_DataReference(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_DataReference_allowed(ty);} +}; + +// Attribute IntensityCalibration class definition +class IntensityCalibrationAttrib: public Tango::SpectrumAttr +{ +public: + IntensityCalibrationAttrib():SpectrumAttr("IntensityCalibration", + Tango::DEV_DOUBLE, Tango::READ_WRITE, 10000) {}; + ~IntensityCalibrationAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_IntensityCalibration(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<OceanOptics *>(dev))->write_IntensityCalibration(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_IntensityCalibration_allowed(ty);} +}; + +// Attribute NoiseProfile class definition +class NoiseProfileAttrib: public Tango::SpectrumAttr +{ +public: + NoiseProfileAttrib():SpectrumAttr("NoiseProfile", + Tango::DEV_DOUBLE, Tango::READ, 5000) {}; + ~NoiseProfileAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_NoiseProfile(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_NoiseProfile_allowed(ty);} +}; + +// Attribute Wave class definition +class WaveAttrib: public Tango::SpectrumAttr +{ +public: + WaveAttrib():SpectrumAttr("Wave", + Tango::DEV_DOUBLE, Tango::READ, 5000) {}; + ~WaveAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_Wave(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_Wave_allowed(ty);} +}; + +// Attribute Lambda class definition +class LambdaAttrib: public Tango::SpectrumAttr +{ +public: + LambdaAttrib():SpectrumAttr("Lambda", + Tango::DEV_DOUBLE, Tango::READ, 5000) {}; + ~LambdaAttrib() {}; + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<OceanOptics *>(dev))->read_Lambda(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<OceanOptics *>(dev))->is_Lambda_allowed(ty);} +}; + + +//========================================= +// Define classes for commands +//========================================= +// Command GetVersion class definition +class GetVersionClass : public Tango::Command +{ +public: + GetVersionClass(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) {}; + + GetVersionClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetVersionClass() {}; + + 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<OceanOptics *>(dev))->is_GetVersion_allowed(any);} +}; + +// Command Stop class definition +class StopClass : public Tango::Command +{ +public: + StopClass(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) {}; + + StopClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~StopClass() {}; + + 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<OceanOptics *>(dev))->is_Stop_allowed(any);} +}; + +// Command StartSingle class definition +class StartSingleClass : public Tango::Command +{ +public: + StartSingleClass(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) {}; + + StartSingleClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~StartSingleClass() {}; + + 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<OceanOptics *>(dev))->is_StartSingle_allowed(any);} +}; + +// Command StartContinuous class definition +class StartContinuousClass : public Tango::Command +{ +public: + StartContinuousClass(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) {}; + + StartContinuousClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~StartContinuousClass() {}; + + 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<OceanOptics *>(dev))->is_StartContinuous_allowed(any);} +}; + +// Command GetLastData class definition +class GetLastDataClass : public Tango::Command +{ +public: + GetLastDataClass(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) {}; + + GetLastDataClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetLastDataClass() {}; + + 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<OceanOptics *>(dev))->is_GetLastData_allowed(any);} +}; + +// Command AcquireNoise class definition +class AcquireNoiseClass : public Tango::Command +{ +public: + AcquireNoiseClass(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) {}; + + AcquireNoiseClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~AcquireNoiseClass() {}; + + 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<OceanOptics *>(dev))->is_AcquireNoise_allowed(any);} +}; + +// Command SaveReferenceData class definition +class SaveReferenceDataClass : public Tango::Command +{ +public: + SaveReferenceDataClass(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) {}; + + SaveReferenceDataClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~SaveReferenceDataClass() {}; + + 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<OceanOptics *>(dev))->is_SaveReferenceData_allowed(any);} +}; + +// Command OpenShutter class definition +class OpenShutterClass : public Tango::Command +{ +public: + OpenShutterClass(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) {}; + + OpenShutterClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~OpenShutterClass() {}; + + 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<OceanOptics *>(dev))->is_OpenShutter_allowed(any);} +}; + +// Command CloseShutter class definition +class CloseShutterClass : public Tango::Command +{ +public: + CloseShutterClass(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) {}; + + CloseShutterClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~CloseShutterClass() {}; + + 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<OceanOptics *>(dev))->is_CloseShutter_allowed(any);} +}; + +// Command GetData class definition +class GetDataClass : public Tango::Command +{ +public: + GetDataClass(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) {}; + + GetDataClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetDataClass() {}; + + 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<OceanOptics *>(dev))->is_GetData_allowed(any);} +}; + +// Command GetGaussFitCenter class definition +class GetGaussFitCenterClass : public Tango::Command +{ +public: + GetGaussFitCenterClass(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) {}; + + GetGaussFitCenterClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetGaussFitCenterClass() {}; + + 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<OceanOptics *>(dev))->is_GetGaussFitCenter_allowed(any);} +}; + +// Command GetGaussFitWidth class definition +class GetGaussFitWidthClass : public Tango::Command +{ +public: + GetGaussFitWidthClass(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) {}; + + GetGaussFitWidthClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetGaussFitWidthClass() {}; + + 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<OceanOptics *>(dev))->is_GetGaussFitWidth_allowed(any);} +}; + +// Command GetFWHMCenter class definition +class GetFWHMCenterClass : public Tango::Command +{ +public: + GetFWHMCenterClass(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) {}; + + GetFWHMCenterClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetFWHMCenterClass() {}; + + 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<OceanOptics *>(dev))->is_GetFWHMCenter_allowed(any);} +}; + +// Command GetFWHMWidth class definition +class GetFWHMWidthClass : public Tango::Command +{ +public: + GetFWHMWidthClass(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) {}; + + GetFWHMWidthClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetFWHMWidthClass() {}; + + 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<OceanOptics *>(dev))->is_GetFWHMWidth_allowed(any);} +}; + +// Command ExportWavelength class definition +class ExportWavelengthClass : public Tango::Command +{ +public: + ExportWavelengthClass(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) {}; + + ExportWavelengthClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~ExportWavelengthClass() {}; + + 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<OceanOptics *>(dev))->is_ExportWavelength_allowed(any);} +}; + +// Command GetArea class definition +class GetAreaClass : public Tango::Command +{ +public: + GetAreaClass(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) {}; + + GetAreaClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetAreaClass() {}; + + 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<OceanOptics *>(dev))->is_GetArea_allowed(any);} +}; + +// Command GetWave class definition +class GetWaveClass : public Tango::Command +{ +public: + GetWaveClass(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) {}; + + GetWaveClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetWaveClass() {}; + + 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<OceanOptics *>(dev))->is_GetWave_allowed(any);} +}; + +// Command GetLambda class definition +class GetLambdaClass : public Tango::Command +{ +public: + GetLambdaClass(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) {}; + + GetLambdaClass(const char *name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(name,in,out) {}; + ~GetLambdaClass() {}; + + 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<OceanOptics *>(dev))->is_GetLambda_allowed(any);} +}; + + +/** + * The OceanOpticsClass singleton definition + */ + +#ifdef _TG_WINDOWS_ +class __declspec(dllexport) OceanOpticsClass : public Tango::DeviceClass +#else +class OceanOpticsClass : public Tango::DeviceClass +#endif +{ + /*----- PROTECTED REGION ID(OceanOpticsClass::Additionnal DServer data members) ENABLED START -----*/ + + + /*----- PROTECTED REGION END -----*/ // OceanOpticsClass::Additionnal DServer data members + + public: + // write class properties data members + Tango::DbData cl_prop; + Tango::DbData cl_def_prop; + Tango::DbData dev_def_prop; + + // Method prototypes + static OceanOpticsClass *init(const char *); + static OceanOpticsClass *instance(); + ~OceanOpticsClass(); + Tango::DbDatum get_class_property(string &); + Tango::DbDatum get_default_device_property(string &); + Tango::DbDatum get_default_class_property(string &); + + protected: + OceanOpticsClass(string &); + static OceanOpticsClass *_instance; + void command_factory(); + void attribute_factory(vector<Tango::Attr *> &); + void pipe_factory(); + void write_class_property(); + void set_default_property(); + void get_class_property(); + string get_cvstag(); + string get_cvsroot(); + + private: + void device_factory(const Tango::DevVarStringArray *); + void create_static_attribute_list(vector<Tango::Attr *> &); + void erase_dynamic_attributes(const Tango::DevVarStringArray *,vector<Tango::Attr *> &); + vector<string> defaultAttList; + Tango::Attr *get_attr_object_by_name(vector<Tango::Attr *> &att_list, string attname); +}; + +} // End of namespace + +#endif // OceanOptics_H diff --git a/src/OceanOpticsStateMachine.cpp b/src/OceanOpticsStateMachine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..be95cc30b08a01ff0a041938b20db3e6d3b98ed0 --- /dev/null +++ b/src/OceanOpticsStateMachine.cpp @@ -0,0 +1,1019 @@ +/*----- PROTECTED REGION ID(OceanOpticsStateMachine.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: OceanOpticsStateMachine.cpp,v 1.7 2019-04-23 11:16:11 graziano Exp $"; +//============================================================================= +// +// file : OceanOpticsStateMachine.cpp +// +// description : State machine file for the OceanOptics class +// +// project : SolarLaserSystems S100 +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// $Author: graziano $ +// +// $Revision: 1.7 $ +// $Date: 2019-04-23 11:16:11 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + +#include <OceanOptics.h> + +/*----- PROTECTED REGION END -----*/ // OceanOptics::OceanOpticsStateMachine.cpp + +//================================================================ +// States | Description +//================================================================ + + +namespace OceanOptics_ns +{ +//================================================= +// Attributes Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_ExposureTime_allowed() + * Description : Execution allowed for ExposureTime attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_ExposureTime_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for ExposureTime attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::ExposureTimeStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::ExposureTimeStateAllowed_WRITE + + // Not any excluded states for ExposureTime attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::ExposureTimeStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::ExposureTimeStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_IncrSensitivity_allowed() + * Description : Execution allowed for IncrSensitivity attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_IncrSensitivity_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for IncrSensitivity attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::IncrSensitivityStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::IncrSensitivityStateAllowed_WRITE + + // Not any excluded states for IncrSensitivity attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::IncrSensitivityStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::IncrSensitivityStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_SyncMode_allowed() + * Description : Execution allowed for SyncMode attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_SyncMode_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for SyncMode attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::SyncModeStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::SyncModeStateAllowed_WRITE + + // Not any excluded states for SyncMode attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::SyncModeStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::SyncModeStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_NoiseSubtraction_allowed() + * Description : Execution allowed for NoiseSubtraction attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_NoiseSubtraction_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for NoiseSubtraction attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::NoiseSubtractionStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::NoiseSubtractionStateAllowed_WRITE + + // Not any excluded states for NoiseSubtraction attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::NoiseSubtractionStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::NoiseSubtractionStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GaussFitEnable_allowed() + * Description : Execution allowed for GaussFitEnable attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GaussFitEnable_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for GaussFitEnable attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::GaussFitEnableStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GaussFitEnableStateAllowed_WRITE + + // Not any excluded states for GaussFitEnable attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::GaussFitEnableStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GaussFitEnableStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_FWHMEnable_allowed() + * Description : Execution allowed for FWHMEnable attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_FWHMEnable_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for FWHMEnable attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::FWHMEnableStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::FWHMEnableStateAllowed_WRITE + + // Not any excluded states for FWHMEnable attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::FWHMEnableStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::FWHMEnableStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GaussFitCenter_allowed() + * Description : Execution allowed for GaussFitCenter attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GaussFitCenter_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for GaussFitCenter attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::GaussFitCenterStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GaussFitCenterStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GaussFitWidth_allowed() + * Description : Execution allowed for GaussFitWidth attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GaussFitWidth_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for GaussFitWidth attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::GaussFitWidthStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GaussFitWidthStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_FWHMCenter_allowed() + * Description : Execution allowed for FWHMCenter attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_FWHMCenter_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for FWHMCenter attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::FWHMCenterStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::FWHMCenterStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_FWHMWidth_allowed() + * Description : Execution allowed for FWHMWidth attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_FWHMWidth_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for FWHMWidth attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::FWHMWidthStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::FWHMWidthStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_Center_allowed() + * Description : Execution allowed for Center attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_Center_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for Center attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::CenterStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::CenterStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_Width_allowed() + * Description : Execution allowed for Width attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_Width_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for Width attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::WidthStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::WidthStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_FitType_allowed() + * Description : Execution allowed for FitType attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_FitType_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for FitType attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::FitTypeStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::FitTypeStateAllowed_WRITE + + // Not any excluded states for FitType attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::FitTypeStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::FitTypeStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_FWHMAvg_allowed() + * Description : Execution allowed for FWHMAvg attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_FWHMAvg_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for FWHMAvg attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::FWHMAvgStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::FWHMAvgStateAllowed_WRITE + + // Not any excluded states for FWHMAvg attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::FWHMAvgStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::FWHMAvgStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_NoiseLevel_allowed() + * Description : Execution allowed for NoiseLevel attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_NoiseLevel_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for NoiseLevel attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::NoiseLevelStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::NoiseLevelStateAllowed_WRITE + + // Not any excluded states for NoiseLevel attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::NoiseLevelStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::NoiseLevelStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_DataReferenceFile_allowed() + * Description : Execution allowed for DataReferenceFile attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_DataReferenceFile_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for DataReferenceFile attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::DataReferenceFileStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::DataReferenceFileStateAllowed_WRITE + + // Not any excluded states for DataReferenceFile attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::DataReferenceFileStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::DataReferenceFileStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_AutoExposure_allowed() + * Description : Execution allowed for AutoExposure attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_AutoExposure_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for AutoExposure attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::AutoExposureStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::AutoExposureStateAllowed_WRITE + + // Not any excluded states for AutoExposure attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::AutoExposureStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::AutoExposureStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_LightSourceIntensity_allowed() + * Description : Execution allowed for LightSourceIntensity attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_LightSourceIntensity_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for LightSourceIntensity attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::LightSourceIntensityStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::LightSourceIntensityStateAllowed_WRITE + + // Not any excluded states for LightSourceIntensity attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::LightSourceIntensityStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::LightSourceIntensityStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_RtMode_allowed() + * Description : Execution allowed for RtMode attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_RtMode_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for RtMode attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::RtModeStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::RtModeStateAllowed_WRITE + + // Not any excluded states for RtMode attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::RtModeStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::RtModeStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_LightSourceEnable_allowed() + * Description : Execution allowed for LightSourceEnable attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_LightSourceEnable_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for LightSourceEnable attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::LightSourceEnableStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::LightSourceEnableStateAllowed_WRITE + + // Not any excluded states for LightSourceEnable attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::LightSourceEnableStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::LightSourceEnableStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_IntensityCalibrationEnable_allowed() + * Description : Execution allowed for IntensityCalibrationEnable attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_IntensityCalibrationEnable_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for IntensityCalibrationEnable attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::IntensityCalibrationEnableStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::IntensityCalibrationEnableStateAllowed_WRITE + + // Not any excluded states for IntensityCalibrationEnable attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::IntensityCalibrationEnableStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::IntensityCalibrationEnableStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_Area_allowed() + * Description : Execution allowed for Area attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_Area_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for Area attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::AreaStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::AreaStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_AreaRegion_allowed() + * Description : Execution allowed for AreaRegion attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_AreaRegion_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for AreaRegion attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::AreaRegionStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::AreaRegionStateAllowed_WRITE + + // Not any excluded states for AreaRegion attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::AreaRegionStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::AreaRegionStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_AreaEnable_allowed() + * Description : Execution allowed for AreaEnable attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_AreaEnable_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for AreaEnable attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::AreaEnableStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::AreaEnableStateAllowed_WRITE + + // Not any excluded states for AreaEnable attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::AreaEnableStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::AreaEnableStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_WidhtCorrectionEnable_allowed() + * Description : Execution allowed for WidhtCorrectionEnable attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_WidhtCorrectionEnable_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for WidhtCorrectionEnable attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::WidhtCorrectionEnableStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::WidhtCorrectionEnableStateAllowed_WRITE + + // Not any excluded states for WidhtCorrectionEnable attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::WidhtCorrectionEnableStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::WidhtCorrectionEnableStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_NumPixels_allowed() + * Description : Execution allowed for NumPixels attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_NumPixels_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for NumPixels attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::NumPixelsStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::NumPixelsStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_Data_allowed() + * Description : Execution allowed for Data attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_Data_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for Data attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::DataStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::DataStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_RegionOfInterest_allowed() + * Description : Execution allowed for RegionOfInterest attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_RegionOfInterest_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for RegionOfInterest attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::RegionOfInterestStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::RegionOfInterestStateAllowed_WRITE + + // Not any excluded states for RegionOfInterest attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::RegionOfInterestStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::RegionOfInterestStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_AnalysisRegion_allowed() + * Description : Execution allowed for AnalysisRegion attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_AnalysisRegion_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for AnalysisRegion attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::AnalysisRegionStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::AnalysisRegionStateAllowed_WRITE + + // Not any excluded states for AnalysisRegion attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::AnalysisRegionStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::AnalysisRegionStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GaussFit_allowed() + * Description : Execution allowed for GaussFit attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GaussFit_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for GaussFit attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::GaussFitStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GaussFitStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_FWHM_allowed() + * Description : Execution allowed for FWHM attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_FWHM_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for FWHM attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::FWHMStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::FWHMStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GaussReference_allowed() + * Description : Execution allowed for GaussReference attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GaussReference_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for GaussReference attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::GaussReferenceStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GaussReferenceStateAllowed_WRITE + + // Not any excluded states for GaussReference attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::GaussReferenceStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GaussReferenceStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_DataReference_allowed() + * Description : Execution allowed for DataReference attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_DataReference_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for DataReference attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::DataReferenceStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::DataReferenceStateAllowed_WRITE + + // Not any excluded states for DataReference attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::DataReferenceStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::DataReferenceStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_IntensityCalibration_allowed() + * Description : Execution allowed for IntensityCalibration attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_IntensityCalibration_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for IntensityCalibration attribute in Write access. + /*----- PROTECTED REGION ID(OceanOptics::IntensityCalibrationStateAllowed_WRITE) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::IntensityCalibrationStateAllowed_WRITE + + // Not any excluded states for IntensityCalibration attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::IntensityCalibrationStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::IntensityCalibrationStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_NoiseProfile_allowed() + * Description : Execution allowed for NoiseProfile attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_NoiseProfile_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for NoiseProfile attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::NoiseProfileStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::NoiseProfileStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_Wave_allowed() + * Description : Execution allowed for Wave attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_Wave_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for Wave attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::WaveStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::WaveStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_Lambda_allowed() + * Description : Execution allowed for Lambda attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_Lambda_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for Lambda attribute in read access. + /*----- PROTECTED REGION ID(OceanOptics::LambdaStateAllowed_READ) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::LambdaStateAllowed_READ + return true; +} + + +//================================================= +// Commands Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GetVersion_allowed() + * Description : Execution allowed for GetVersion attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GetVersion_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for GetVersion command. + /*----- PROTECTED REGION ID(OceanOptics::GetVersionStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GetVersionStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_Stop_allowed() + * Description : Execution allowed for Stop attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_Stop_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for Stop command. + /*----- PROTECTED REGION ID(OceanOptics::StopStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::StopStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_StartSingle_allowed() + * Description : Execution allowed for StartSingle attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_StartSingle_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for StartSingle command. + /*----- PROTECTED REGION ID(OceanOptics::StartSingleStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::StartSingleStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_StartContinuous_allowed() + * Description : Execution allowed for StartContinuous attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_StartContinuous_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for StartContinuous command. + /*----- PROTECTED REGION ID(OceanOptics::StartContinuousStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::StartContinuousStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GetLastData_allowed() + * Description : Execution allowed for GetLastData attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GetLastData_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for GetLastData command. + /*----- PROTECTED REGION ID(OceanOptics::GetLastDataStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GetLastDataStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_AcquireNoise_allowed() + * Description : Execution allowed for AcquireNoise attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_AcquireNoise_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for AcquireNoise command. + /*----- PROTECTED REGION ID(OceanOptics::AcquireNoiseStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::AcquireNoiseStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_SaveReferenceData_allowed() + * Description : Execution allowed for SaveReferenceData attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_SaveReferenceData_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for SaveReferenceData command. + /*----- PROTECTED REGION ID(OceanOptics::SaveReferenceDataStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::SaveReferenceDataStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_OpenShutter_allowed() + * Description : Execution allowed for OpenShutter attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_OpenShutter_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for OpenShutter command. + /*----- PROTECTED REGION ID(OceanOptics::OpenShutterStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::OpenShutterStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_CloseShutter_allowed() + * Description : Execution allowed for CloseShutter attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_CloseShutter_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for CloseShutter command. + /*----- PROTECTED REGION ID(OceanOptics::CloseShutterStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::CloseShutterStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GetData_allowed() + * Description : Execution allowed for GetData attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GetData_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for GetData command. + /*----- PROTECTED REGION ID(OceanOptics::GetDataStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GetDataStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GetGaussFitCenter_allowed() + * Description : Execution allowed for GetGaussFitCenter attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GetGaussFitCenter_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for GetGaussFitCenter command. + /*----- PROTECTED REGION ID(OceanOptics::GetGaussFitCenterStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GetGaussFitCenterStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GetGaussFitWidth_allowed() + * Description : Execution allowed for GetGaussFitWidth attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GetGaussFitWidth_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for GetGaussFitWidth command. + /*----- PROTECTED REGION ID(OceanOptics::GetGaussFitWidthStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GetGaussFitWidthStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GetFWHMCenter_allowed() + * Description : Execution allowed for GetFWHMCenter attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GetFWHMCenter_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for GetFWHMCenter command. + /*----- PROTECTED REGION ID(OceanOptics::GetFWHMCenterStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GetFWHMCenterStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GetFWHMWidth_allowed() + * Description : Execution allowed for GetFWHMWidth attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GetFWHMWidth_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for GetFWHMWidth command. + /*----- PROTECTED REGION ID(OceanOptics::GetFWHMWidthStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GetFWHMWidthStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_ExportWavelength_allowed() + * Description : Execution allowed for ExportWavelength attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_ExportWavelength_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for ExportWavelength command. + /*----- PROTECTED REGION ID(OceanOptics::ExportWavelengthStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::ExportWavelengthStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GetArea_allowed() + * Description : Execution allowed for GetArea attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GetArea_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for GetArea command. + /*----- PROTECTED REGION ID(OceanOptics::GetAreaStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GetAreaStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GetWave_allowed() + * Description : Execution allowed for GetWave attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GetWave_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for GetWave command. + /*----- PROTECTED REGION ID(OceanOptics::GetWaveStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GetWaveStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : OceanOptics::is_GetLambda_allowed() + * Description : Execution allowed for GetLambda attribute + */ +//-------------------------------------------------------- +bool OceanOptics::is_GetLambda_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for GetLambda command. + /*----- PROTECTED REGION ID(OceanOptics::GetLambdaStateAllowed) ENABLED START -----*/ + + /*----- PROTECTED REGION END -----*/ // OceanOptics::GetLambdaStateAllowed + return true; +} + + +/*----- PROTECTED REGION ID(OceanOptics::OceanOpticsStateAllowed.AdditionalMethods) ENABLED START -----*/ + +// Additional Methods + +/*----- PROTECTED REGION END -----*/ // OceanOptics::OceanOpticsStateAllowed.AdditionalMethods + +} // End of namespace diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..381103a90d1c8d4dee39d6cfc17bcc0c6b2dcd80 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,76 @@ +/*----- PROTECTED REGION ID(OceanOptics::main.cpp) ENABLED START -----*/ +static const char *RcsId = "$Id: main.cpp,v 1.1 2015-03-18 10:38:47 graziano Exp $"; +//============================================================================= +// +// file : main.cpp +// +// description : C++ source for the OceanOptics 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 : SolarLaserSystems S100 +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// $Author: graziano $ +// +// $Revision: 1.1 $ +// $Date: 2015-03-18 10:38:47 $ +// +// $HeadURL: $ +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= +#include <tango.h> + +int main(int argc,char *argv[]) +{ + try + { + // Initialise the device server + //---------------------------------------- + Tango::Util *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; + } + Tango::Util::instance()->server_cleanup(); + return(0); +} + +/*----- PROTECTED REGION END -----*/ // OceanOptics::main.cpp diff --git a/src/readthread.cpp b/src/readthread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e781cd27af431b048db0fd3e442f06c20e8e82eb --- /dev/null +++ b/src/readthread.cpp @@ -0,0 +1,1004 @@ +// +// file : readthread.cpp +// +// description : reading thread +// +// project : TANGO Device Server +// +// $Author: graziano $ +// +// $Revision: 1.13 $ +// +// +// +// copyleft : Sincrotrone Trieste S.C.p.A. +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34012 Basovizza, Trieste ITALY +// + +#include "readthread.h" +#ifdef HAVE_RNM +#include "k_rnmshare.h" +#endif + +static const char __FILE__rev[] = __FILE__ " $Revision: 1.13 $"; + +//+------------------------------------------------------------------ +// +// method: readthread::readthread() +// +// description: readthread constructor +// +//------------------------------------------------------------------- +readthread::readthread(OceanOptics_ns::OceanOptics *s):Tango::LogAdapter(s) +{ + DEBUG_STREAM << "readthread::readthread(): constructor... !" << endl; + mysolar = s; + //mutex_sleep = new omni_mutex(); + min_fit_time = 1000000000.0; + max_fit_time = 0; + avg_fit_time = 0; + tot_fit_time = 0; + fit_counter = 0; + use_last_fit = false; +#ifdef HAVE_RNM + int ret = rnmshare_init(0); +#endif +} + +//+------------------------------------------------------------------ +// +// method: readthread::~readthread() +// +// description: readthread destructor +// +//------------------------------------------------------------------- +readthread::~readthread() +{ + DEBUG_STREAM << "readthread::~readthread(): destructor... !" << endl; + //delete mutex_sleep; +#ifdef HAVE_RNM + rnmshare_deinit(); +#endif +} + +//+------------------------------------------------------------------ +// +// method: readthread::run() +// +// description: Run +// +//------------------------------------------------------------------- +void readthread::run(void *) +{ + INFO_STREAM << "readthread::run(): running... !" << endl; + int cnt_err = 0, + max_cnt_err = 3; +// im540_map::iterator it;// = myim540->read_data.begin(); + + string id; + //update_scheduler(); + string resp; + //mutex_sleep->lock(); + pausesec = 1; + pausenano = 0; + //mutex_sleep->unlock(); + int counter = 0; + bool ret; + double *pNoiseData=NULL; + int flag; + int error; + char error_str[128]; + just_reconnected = false; + + while (!mysolar->abortflag) + { + if(mysolar->device_id == -1) + { + mysolar->connect_device(true); + + if(mysolar->device_id == -1) + { + abort_sleep(pausesec + ((double)pausenano)/1000000000); + continue; + } + else + { + just_reconnected = true; + } + } + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// + //+++++++++++++++++++++++++++++INIT MODE+++++++++++++++++++++++++++++++// + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// + if(mysolar->init_live_mode || mysolar->init_measure_mode || mysolar->init_acquire_noise_mode) + { + wait_counter = 0; + /*ret = mysolar->m_usbCCD.GetParameters(); + if(!ret) + { + INFO_STREAM << "readthread::run(): error in GetParameters()" << endl; + mysolar->init_live_mode = false; + mysolar->init_measure_mode = false; + mysolar->init_acquire_noise_mode = false; + mysolar->live_mode = false; + mysolar->measure_mode = false; + mysolar->acquire_noise_mode = false; + mysolar->set_state(Tango::ON); + mysolar->set_status("Error Initializing Acquisition"); + continue; + } + else*/ + { + //mysolar->NumPixel = mysolar->m_usbCCD.m_nNumPixelsH * mysolar->m_usbCCD.m_nNumPixelsV; +#if _SEABREEZE_API > 1 + mysolar->NumPixel = sbapi_spectrometer_get_formatted_spectrum_length(mysolar->device_id,mysolar->spectrometer_id, &error); +#else + mysolar->NumPixel = seabreeze_get_formatted_spectrum_length(mysolar->device_id, &error); +#endif + DEBUG_STREAM << "readthread::run() allocating for Data size=" << ((int)mysolar->NumPixel)/**((int)mysolar->m_usbCCD.m_nNumReadOuts)*/ << endl; + if((!mysolar->init_acquire_noise_mode) && mysolar->pLiveData) + { + delete [] mysolar->pLiveData; + mysolar->pLiveData = NULL; + } + if(!mysolar->init_acquire_noise_mode) + { + mysolar->pLiveData = new double[((int)mysolar->NumPixel)/**((int)mysolar->m_usbCCD.m_nNumReadOuts)*/]; + } + else + { + pNoiseData = new double[((int)mysolar->NumPixel)/**((int)mysolar->m_usbCCD.m_nNumReadOuts)*/ * mysolar->noise_frames]; + + } + //DEBUG_STREAM << "readthread::run() allocated for Data size=" << ((int)mysolar->NumPixel)*((int)mysolar->m_usbCCD.m_nNumReadOuts) << endl; + /*ret= mysolar->m_usbCCD.StartMeasuring(mysolar->pLiveData); + if(!ret) + { + INFO_STREAM << "readthread::run(): error in StartMeasuring()" << endl; + mysolar->init_live_mode = false; + mysolar->live_mode = false; + mysolar->set_state(Tango::ON); + mysolar->set_status("Error Starting Continuous Mode"); + continue; + }*/ + /*if(mysolar->nFramesBuffered > 0) + { + mysolar->pFrameBuffer = new DWORD[mysolar->NumPixel * mysolar->nFramesBuffered]; + memset(mysolar->pFrameBuffer,0,mysolar->NumPixel * mysolar->nFramesBuffered * sizeof(DWORD)); + }*/ + //mutex_sleep->lock(); + pausesec = 0; + //pausenano = 1000000; //TODO: 1 msec, it should depend on freq of CCD + //pausenano = (*(mysolar->attr_ExposureTime_read) * *(mysolar->attr_NumReadouts_read) * 300000); //TODO: 10 msec, it should depend on freq of CCD + pausenano = 0; + DEBUG_STREAM << "readthread::run(): setting sleep_time(ns)="<<pausenano<<endl; + //mutex_sleep->unlock(); + mysolar->init_live_mode = false; + mysolar->init_measure_mode = false; + mysolar->init_acquire_noise_mode = false; + } + } + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// + //+++++++++++++++++++++++++++ACQUIRE MODE++++++++++++++++++++++++++++++// + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// + if(mysolar->live_mode || mysolar->measure_mode) + { + DWORD stat; + //DEBUG_STREAM << "readthread::run(): before GetMeasStatus"<<endl; + //mysolar->m_usbCCD.GetMeasStatus(&stat); + //if(stat == STATUS_DATA_READY) + if(1) + { + wait_counter = 0; + //if(mysolar->m_usbCCD.m_nNumReadOuts == 1) + if(1) + { + if(*(mysolar->attr_NoiseSubtraction_read)) + { + //DEBUG_STREAM << "readthread::run(): before GetData readouts=1, noise subtraction"<<endl; + //mysolar->m_usbCCD.GetData(mysolar->pLiveData); +#if _SEABREEZE_API > 1 + /*TODO: length*/flag = sbapi_spectrometer_get_formatted_spectrum(mysolar->device_id, mysolar->spectrometer_id, &error, mysolar->pLiveData, (int)mysolar->NumPixel); +#else + flag = seabreeze_get_formatted_spectrum(mysolar->device_id, &error, mysolar->pLiveData, (int)mysolar->NumPixel); +#endif + DEBUG_STREAM << "readthread::run(): seabreeze_get_formatted_spectrum: -> "<<flag<<endl; + if(flag == 0) + { + seabreeze_get_error_string(error, error_str, 128); + DEBUG_STREAM << "readthread::run(): error in seabreeze_get_formatted_spectrum: '"<<error_str<<"'"<<endl; + mysolar->set_state(Tango::FAULT); + mysolar->set_status("Communication error"); + mysolar->disconnect_device(); + mysolar->device_id = -1; + if(mysolar->live_mode) + mysolar->init_live_mode = true; + if(mysolar->measure_mode) + mysolar->init_measure_mode = true; + } + for(unsigned int j=0; j < mysolar->NumPixel; j++) + { + //mysolar->pLiveData[j] = (((int)mysolar->pLiveData[j] - mysolar->noise_level) > 0) ? ((int)mysolar->pLiveData[j] - mysolar->noise_level) : 0; + if(*mysolar->attr_IntensityCalibrationEnable_read) + { + mysolar->pLiveData_avg[j] = (mysolar->pLiveData[j] - mysolar->pNoiseMask_avg[j]); + if(mysolar->pLiveData_avg[j] > 0) + mysolar->pLiveData_avg[j] *= mysolar->attr_IntensityCalibration_read[j]; + } + else + { + mysolar->pLiveData_avg[j] = (mysolar->pLiveData[j] - mysolar->pNoiseMask_avg[j]); + } + /*//TTTTTTTTTTTTTTTTEEEEEEEEEEEEEEEEESSSSSSSSSSSSSSTTTTTTTTTTTTTTTTTTTTTTTTTTTT: generate fake gaussian + double base = 0 + (-1 + 2*(counter%2)) * counter%101; + double amp =15000 + (1 - 2*(counter%2)) * counter%547; + double center = 350 + (-1 + 2*(counter%2)) * counter%3; + double width = 10 + (1 - 2*(counter%2)) * counter%2; + mysolar->pLiveData_avg[j] += base + amp*exp((-0.5) * pow((mysolar->x_values[j]-center)/width,2));*/ + } + //memcpy(mysolar->pLiveData_avg,mysolar->pLiveData,mysolar->NumPixel * sizeof(DWORD)); + } + else + { + //DEBUG_STREAM << "readthread::run(): before GetData readouts=1"<<endl; + //mysolar->m_usbCCD.GetData(mysolar->pLiveData); +#if _SEABREEZE_API > 1 + /*TODO: length*/flag = sbapi_spectrometer_get_formatted_spectrum(mysolar->device_id, mysolar->spectrometer_id, &error, mysolar->pLiveData, (int)mysolar->NumPixel); +#else + flag = seabreeze_get_formatted_spectrum(mysolar->device_id, &error, mysolar->pLiveData, (int)mysolar->NumPixel); +#endif + //mysolar->m_usbCCD.GetData(mysolar->pLiveData_avg); + if(*mysolar->attr_IntensityCalibrationEnable_read) + { + for(unsigned int j=0; j < mysolar->NumPixel; j++) + mysolar->pLiveData_avg[j] = (mysolar->attr_IntensityCalibration_read[j] * mysolar->pLiveData[j]); + } + else + { + memcpy(mysolar->pLiveData_avg,mysolar->pLiveData,mysolar->NumPixel * sizeof(double)); + } + } + /*for(unsigned int i=0; i<mysolar->NumPixel; i++) + { + DEBUG_STREAM << "OceanOptics::OceanOptics(): mysolar->pLiveData["<<i<<"]=" << mysolar->pLiveData[i] << endl; + }*/ + DEBUG_STREAM << __func__<<": READ DATA" << endl; + clock_gettime(CLOCK_MONOTONIC,&mysolar->last_read); + } + /*else + { + //DEBUG_STREAM << "readthread::run(): before GetData readouts>1"<<endl; + mysolar->m_usbCCD.GetData(mysolar->pLiveData); + //memset(&(mysolar->pLiveData_avg[0]), 0,mysolar->NumPixel*sizeof(DWORD)); + + //for every pixel + for(unsigned int j=0; j < mysolar->NumPixel; j++) + { + mysolar->pLiveData_avg[j] = 0; + //sum value in this pixel point for every frame + for(int i=0; i < mysolar->m_usbCCD.m_nNumReadOuts; i++) + { + mysolar->pLiveData_avg[j] += mysolar->pLiveData[i * mysolar->NumPixel + j]; + } + //divide the sum per the number of frames + mysolar->pLiveData_avg[j] = (DWORD)((((double)mysolar->pLiveData_avg[j])/((double)mysolar->m_usbCCD.m_nNumReadOuts)) + 0.5); //+0.5 to round and not truncate + if(*(mysolar->attr_NoiseSubtraction_read)) + { + //mysolar->pLiveData_avg[j] = (((int)mysolar->pLiveData_avg[j] - mysolar->noise_level) > 0) ? ((int)mysolar->pLiveData_avg[j] - mysolar->noise_level) : 0; + mysolar->pLiveData_avg[j] = (int)mysolar->pLiveData_avg[j] - mysolar->noise_level; + } + } + }*/ + if(mysolar->nFramesBuffered > 0) + { + //copy the average frame + memcpy(&(mysolar->pFrameBuffer[mysolar->NumPixel * mysolar->FrameBufferIndex]), &(mysolar->pLiveData_avg[0]),mysolar->NumPixel*sizeof(DWORD)); + ////update index in buffer once for all readout frames + mysolar->FrameBufferIndex = (mysolar->FrameBufferIndex + 1) % mysolar->nFramesBuffered; + } + + if(just_reconnected) + { + Tango::MultiAttribute *attr_list = mysolar->get_device_attr(); + try + { + Tango::WAttribute &attr_reg4 = attr_list->get_w_attr_by_name ("SyncMode"); + //mysolar->write_SyncMode(attr_reg4); + Tango::DevLong w_val; + attr_reg4.get_write_value(w_val); + DEBUG_STREAM << "seabreeze_set_trigger_mode val=" << w_val << endl; + seabreeze_set_trigger_mode(mysolar->device_id, &error, w_val); + DEBUG_STREAM << "seabreeze_set_trigger_mode written , error=" << error << endl; + }catch (...){} + if(error == 0) + just_reconnected = false; + usleep(100000); + } + + struct timeval buf_time; + gettimeofday(&buf_time,NULL); +#if __GNUC__ +#if __x86_64__ || __ppc64__ + int32_t buf_bunch_num; +#else + long buf_bunch_num; +#endif +#else + long buf_bunch_num; +#endif + + char check; + + + if(*mysolar->attr_RtMode_read) + { +#ifdef HAVE_RNM + rnm_bunch_number_get_value(0, 1, &buf_bunch_num, &check); + //buf_bunch_num = fit_counter; +#endif + if(old_bunch_number != buf_bunch_num-1) + { + //INFO_STREAM << "readthread::run(): BUNCH error: previous="<<old_bunch_number<<" present="<<bunch_number; + //cout << "--------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>> BUNCH error: previous="<<old_bunch_number<<" present="<<bunch_number<<"<<<<<<<<<<<<<<<<<<<<<<<<<---------------------------"<<endl; + INFO_STREAM << "--->>> BUNCH error: previous="<<old_bunch_number<<" present="<<buf_bunch_num<<"<<<---"<<endl; + old_bunch_number = buf_bunch_num; + } + else + { + old_bunch_number++; + } + } + else + { + buf_bunch_num = fit_counter; + } + //cout << __func__<<": before push_data data[0]="<<mysolar->pLiveData_avg[0]<<" data[1]="<<mysolar->pLiveData_avg[1]<<" data[2]="<<mysolar->pLiveData_avg[2]<<" data[1000]="<<mysolar->pLiveData_avg[1000]<<" data[1001]="<<mysolar->pLiveData_avg[1001]<<" data[1002]="<<mysolar->pLiveData_avg[1002]<<endl; + tbuffer::_data_array<double> val_array(mysolar->pLiveData_avg, mysolar->NumPixel); + mysolar->tbuf_array.push_data(&val_array,buf_time,buf_bunch_num); + tbuffer::_data_array<double> val_array_w(&(mysolar->pLiveData_avg[0 + mysolar->RegionOfInterestStartPix]), mysolar->RegionOfInterestEndPix - mysolar->RegionOfInterestStartPix + 1); + mysolar->tbuf_array_w.push_data(&val_array_w,buf_time,buf_bunch_num); + tbuffer::_data_array<double> val_array_l(&(mysolar->x_values[0 + mysolar->RegionOfInterestStartPix]), mysolar->RegionOfInterestEndPix - mysolar->RegionOfInterestStartPix + 1); + mysolar->tbuf_array_l.push_data(&val_array_l,buf_time,buf_bunch_num); + //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + //::::::::::::::::::::::: FWHM processing ::::::::::::::::::::::: + //________________________________________________________________ + if(*(mysolar->attr_FWHMEnable_read)) + { + size_t x_peak, x_half_min, x_half_max; + double y_peak; + mysolar->fwhm_calculate(mysolar->pLiveData_avg,mysolar->NumPixel, + mysolar->AnalysisRegionStartPix,mysolar->AnalysisRegionEndPix, + 1, //average on 1 frame + *(mysolar->attr_FWHMAvg_read), //average between 3 adjacent values + x_peak, y_peak, + x_half_min, x_half_max); + mysolar->attr_FWHM_read[0]=mysolar->x_values[x_peak]; + mysolar->attr_FWHM_read[1]=y_peak; + if(*(mysolar->attr_WidhtCorrectionEnable_read)) + { + mysolar->attr_FWHM_read[2]=sqrt((mysolar->x_values[x_half_max] - mysolar->x_values[x_half_min])*(mysolar->x_values[x_half_max] - mysolar->x_values[x_half_min]) + mysolar->widthCorrection*mysolar->widthCorrection); + } + else + { + mysolar->attr_FWHM_read[2]=mysolar->x_values[x_half_max] - mysolar->x_values[x_half_min]; + } + *(mysolar->attr_FWHMCenter_read) = mysolar->attr_FWHM_read[0]; + *(mysolar->attr_FWHMWidth_read) = mysolar->attr_FWHM_read[2]; + double val_buff; + val_buff = *(mysolar->attr_FWHMCenter_read); + mysolar->tbuf[BUF_ID_FWHM_CENTER].push_data(&val_buff,buf_time,buf_bunch_num); + val_buff = *(mysolar->attr_FWHMWidth_read); + mysolar->tbuf[BUF_ID_FWHM_WIDTH].push_data(&val_buff,buf_time,buf_bunch_num); + if(!(*(mysolar->attr_GaussFitEnable_read)) || mysolar->preferFWHM) + *(mysolar->attr_Center_read) = mysolar->attr_FWHM_read[0]; + *(mysolar->attr_Width_read) = mysolar->attr_FWHM_read[2]; + } + //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + //:::::::::::::::::::::::: AUTO EXPOSURE :::::::::::::::::::::::: + //________________________________________________________________ + if(*(mysolar->attr_AutoExposure_read)) + { + int y_max; + if(*(mysolar->attr_FWHMEnable_read)) + { + y_max=(int)mysolar->attr_FWHM_read[1]; + } + else + { + size_t x_peak, x_half_min, x_half_max; + double y_peak; + mysolar->fwhm_calculate(mysolar->pLiveData_avg,mysolar->NumPixel, + mysolar->AnalysisRegionStartPix,mysolar->AnalysisRegionEndPix, + 1, //average on 1 frame + *(mysolar->attr_FWHMAvg_read), //average between 3 adjacent values + x_peak, y_peak, + x_half_min, x_half_max); + y_max = y_peak; + } + mysolar->exposures[mysolar->exposure_idx] = y_max; + mysolar->exposure_idx = (mysolar->exposure_idx + 1)%AUTO_EXPOSURE_MEAN; + mysolar->y_max_mean = 0; + for(int i=0; i<AUTO_EXPOSURE_MEAN; i++) + mysolar->y_max_mean += mysolar->exposures[i]; + mysolar->y_max_mean = (int)(((double)mysolar->y_max_mean)/AUTO_EXPOSURE_MEAN); + + DEBUG_STREAM << "readthread::run(): AutoExposure: max="<<mysolar->y_max_mean<<endl; + + if(mysolar->y_max_mean > mysolar->autoExposureAmpRange[1]) + { + double exposure = *(mysolar->attr_ExposureTime_read); + if(exposure - mysolar->autoExposureStep >= mysolar->autoExposureRange[0]) + { + exposure -= mysolar->autoExposureStep; + } + else + { + exposure = mysolar->autoExposureRange[0]; + } + if(exposure != mysolar->attr_ExposureTime_write) + { + DEBUG_STREAM << "readthread::run(): AutoExposure: decresing to "<<exposure<<endl; + //mysolar->m_usbCCD.SetExpTime((float)exposure); +#if _SEABREEZE_API > 1 + unsigned long integr_time_usec = (unsigned long)(exposure*1000); + sbapi_spectrometer_set_integration_time_micros (mysolar->device_id, mysolar->spectrometer_id, &error, integr_time_usec); +#else + long integr_time_usec = (long)(exposure*1000); + seabreeze_set_integration_time_microsec(mysolar->device_id, &error, integr_time_usec); +#endif + mysolar->attr_ExposureTime_write = exposure; + } + } + else if(mysolar->y_max_mean < mysolar->autoExposureAmpRange[0]) + { + double exposure = *(mysolar->attr_ExposureTime_read); + if(exposure + mysolar->autoExposureStep <= mysolar->autoExposureRange[1]) + { + exposure += mysolar->autoExposureStep; + } + else + { + exposure = mysolar->autoExposureRange[1]; + } + if(exposure != mysolar->attr_ExposureTime_write) + { + DEBUG_STREAM << "readthread::run(): AutoExposure: increasing to "<<exposure<<endl; + //mysolar->m_usbCCD.SetExpTime((float)exposure); +#if _SEABREEZE_API > 1 + unsigned long integr_time_usec = (unsigned long)(exposure*1000); + sbapi_spectrometer_set_integration_time_micros (mysolar->device_id, mysolar->spectrometer_id, &error, integr_time_usec); +#else + long integr_time_usec = (long)(exposure*1000); + seabreeze_set_integration_time_microsec(mysolar->device_id, &error, integr_time_usec); +#endif + mysolar->attr_ExposureTime_write = exposure; + } + } + } + //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + //:::::::::::::::::::::: Gaussian Fitting :::::::::::::::::::::::: + //________________________________________________________________ + if(*(mysolar->attr_GaussFitEnable_read)) + { + int ret_fun; + double fit[CONFITEOR_FIT_NUM_PARAM]; + //if last fit ok, initial guess is last fit + if(mysolar->GaussFit_valid || use_last_fit) + { + fit[0] = mysolar->attr_GaussFit_read[0]; + fit[1] = (mysolar->attr_GaussFit_read[1] > 0) ? mysolar->attr_GaussFit_read[1] : + ((*(mysolar->attr_FWHMEnable_read) && (mysolar->attr_FWHM_read[1] > 0)) ? + mysolar->attr_FWHM_read[1] : 50 + (10*counter % 950)); + int center_ind=(int)(((double)(mysolar->AnalysisRegionEndPix - mysolar->AnalysisRegionStartPix + 1))/2); + //if center is inside analysis region use it, otherwise use fwhm, otherwise use center of analysis region + fit[2] = (mysolar->attr_GaussFit_read[2] > mysolar->x_values[mysolar->AnalysisRegionStartPix] && mysolar->attr_GaussFit_read[2] < mysolar->x_values[mysolar->AnalysisRegionEndPix]) ? + mysolar->attr_GaussFit_read[2] : ((*(mysolar->attr_FWHMEnable_read) && (mysolar->attr_FWHM_read[0] > 0)) ? mysolar->attr_FWHM_read[0] : mysolar->x_values[center_ind]); + double width = (mysolar->x_values[mysolar->AnalysisRegionEndPix] - mysolar->x_values[mysolar->AnalysisRegionStartPix]); + + double width_fit_uncalibr; + if(*(mysolar->attr_WidhtCorrectionEnable_read)) + { + width_fit_uncalibr=sqrt(mysolar->attr_GaussFit_read[3]*mysolar->attr_GaussFit_read[3] - mysolar->widthCorrection*mysolar->widthCorrection); + } + else + { + width_fit_uncalibr=mysolar->attr_GaussFit_read[3]; + } + + //if rms computed is too big, use last fwhm, otherwise use a fraction of analysis region + fit[3] = (width_fit_uncalibr > 0 && width_fit_uncalibr < width) ? width_fit_uncalibr*SIGMA_TO_FWHM_FACTOR : + ((*(mysolar->attr_FWHMEnable_read) && (mysolar->attr_FWHM_read[2] > 0)) ? mysolar->attr_FWHM_read[2]*SIGMA_TO_FWHM_FACTOR : width/10.0); + fit[4] = fit[3]; + DEBUG_STREAM << __func__<<": initial guess with GaussFit_valid"<<endl; + } + //otherwise if center and width reference are defined, use that (but not always, maybe they are set to bad values) + else if ((mysolar->attr_GaussReference_read[2]) != 0 && (mysolar->attr_GaussReference_read[3]) && (counter % 10 == 0)) + { + fit[0] = mysolar->attr_GaussReference_read[0]; + fit[1] = mysolar->attr_GaussReference_read[1]; + fit[2] = mysolar->attr_GaussReference_read[2]; + + double width_ref_uncalibr; + if(*(mysolar->attr_WidhtCorrectionEnable_read)) + { + width_ref_uncalibr=sqrt(mysolar->attr_GaussReference_read[3]*mysolar->attr_GaussReference_read[3] - mysolar->widthCorrection*mysolar->widthCorrection); + } + else + { + width_ref_uncalibr=mysolar->attr_GaussReference_read[3]; + } + fit[3] = width_ref_uncalibr*SIGMA_TO_FWHM_FACTOR; //TODO: user is aware of using fwhm instead of sigma? + fit[4] = fit[3]; + DEBUG_STREAM << __func__<<": initial guess from attr_GaussReference_read"<<endl; + } + //otherwise start with some default values + else + { + //fit[0] = mysolar->noise_level; //TODO: +//#ifdef _NON_AVERAGE +// fit[0] = //TODO: +//#else + //average on 4 points: (2 at beginning + 2 at end)/4 + fit[0] = (mysolar->pLiveData_avg[2 + mysolar->AnalysisRegionStartPix] + + mysolar->pLiveData_avg[5 + mysolar->AnalysisRegionStartPix] + + mysolar->pLiveData_avg[mysolar->AnalysisRegionEndPix -3] + + mysolar->pLiveData_avg[mysolar->AnalysisRegionEndPix -6])/4; +//#endif + //try the range 50...10000 as amplitude + fit[1] = (mysolar->attr_FWHM_read[1] > 0 && *(mysolar->attr_FWHMEnable_read)) ? mysolar->attr_FWHM_read[1] : 50 + (10*counter % 950); + //if don't have a value from FWHM, use as center the middle of analysis region + int analysis_region_size = mysolar->AnalysisRegionEndPix - mysolar->AnalysisRegionStartPix + 1; + int center_ind=(int)(((double)(analysis_region_size + ((-1 + 2*(counter%2)) * counter%(analysis_region_size/5))))/2); + fit[2] = (mysolar->attr_FWHM_read[0] > 0 && *(mysolar->attr_FWHMEnable_read)) ? mysolar->attr_FWHM_read[0] : mysolar->x_values[center_ind]; + //if don't have a value from FWHM, use as rms a fraction of analysis region + double width = (mysolar->x_values[mysolar->AnalysisRegionEndPix] - mysolar->x_values[mysolar->AnalysisRegionStartPix]) / (10.0 + ((1 - 2*(counter%2)) * counter%9)); + fit[3] = (mysolar->attr_FWHM_read[2] > 0 && *(mysolar->attr_FWHMEnable_read)) ? mysolar->attr_FWHM_read[2]*SIGMA_TO_FWHM_FACTOR : width; + fit[4] = (mysolar->attr_FWHM_read[2] > 0 && *(mysolar->attr_FWHMEnable_read)) ? mysolar->attr_FWHM_read[2]*SIGMA_TO_FWHM_FACTOR : width; + DEBUG_STREAM << __func__<<": initial guess GENERIC center_ind="<<center_ind<<endl; + } + fit[5] = 2; + fit[6] = 2; + //DEBUG_STREAM << "readthread::run(): gaussfit initial guess="<<fit[0]<<","<<fit[1]<<","<<fit[2]<<","<<fit[3]<<","<<endl; + double *data = new double[mysolar->AnalysisRegionEndPix - mysolar->AnalysisRegionStartPix + 1]; + for(unsigned int i=mysolar->AnalysisRegionStartPix; i <= mysolar->AnalysisRegionEndPix; i++) + { + data[i-mysolar->AnalysisRegionStartPix] = mysolar->pLiveData_avg[i]; + } + //size_t fitting_iter; + unsigned int fitting_iter; + //SYSTEMTIME ts_end, ts_start; + //GetSystemTime(&ts_start); +// ret_fun = (mysolar->m_gaussfit)->perform(data,mysolar->AnalysisRegionEndPix - mysolar->AnalysisRegionStartPix + 1, MAX_GAUSS_ITERATION, fitting_iter, &(mysolar->x_values[mysolar->AnalysisRegionStartPix]), fit); + double tmperr[CONFITEOR_FIT_NUM_PARAM], tmpchi; + double mean, rms; + int ret_fun2; + timespec start, now; + clock_gettime(CLOCK_MONOTONIC,&start); + switch(*(mysolar->attr_FitType_read)) + { + case GAUSS_FIT: + default: + ret_fun = (mysolar->m_gaussfit)->perform(data,&(mysolar->x_values[mysolar->AnalysisRegionStartPix]), mysolar->AnalysisRegionEndPix - mysolar->AnalysisRegionStartPix + 1, MAX_GAUSS_ITERATION, 0, fitting_iter, NULL/*weights*/, fit, tmperr, tmpchi); + ret_fun2 = (mysolar->m_gaussfit)->compute_rms(fit, &mean, &rms); + break; + case GAUSS_FIT_ASYMM: + ret_fun = (mysolar->m_asyngaussfit)->perform(data,&(mysolar->x_values[mysolar->AnalysisRegionStartPix]), mysolar->AnalysisRegionEndPix - mysolar->AnalysisRegionStartPix + 1, MAX_GAUSS_ITERATION, 0, fitting_iter, NULL/*weights*/, fit, tmperr, tmpchi); + ret_fun2 = (mysolar->m_asyngaussfit)->compute_rms(fit, &mean, &rms); + break; + case CONFITEOR_FIT: + ret_fun = (mysolar->m_confiteorfit)->perform(data,&(mysolar->x_values[mysolar->AnalysisRegionStartPix]), mysolar->AnalysisRegionEndPix - mysolar->AnalysisRegionStartPix + 1, MAX_CONFITEOR_ITERATION, 0, fitting_iter, NULL/*weights*/, fit, tmperr, tmpchi); + ret_fun2 = (mysolar->m_confiteorfit)->compute_rms(fit, &mean, &rms); + break; + } + delete [] data; + clock_gettime(CLOCK_MONOTONIC,&now); + //printf ("gauss_f: f[0]=%f f[50]=%f\n",f[0],f[50]); + double fit_time =(now.tv_sec - start.tv_sec)*1000000 + ((double)(now.tv_nsec - start.tv_nsec))/1000; + fit_counter++; + if(fit_time < min_fit_time) + min_fit_time = fit_time; + if(fit_time > max_fit_time) + max_fit_time = fit_time; + tot_fit_time += fit_time; + //if(fit_counter > 1) + avg_fit_time = tot_fit_time/(fit_counter); + //GetSystemTime(&ts_end); + //DEBUG_STREAM << "readthread::run(): gaussfit performing time: start="<<ts_start.wSecond<<"."<<ts_start.wMilliseconds<<" end="<<ts_end.wSecond<<"."<<ts_end.wMilliseconds<<endl; + //if(ret_fun) + bool fit_valid = false; + //TODO: adjust rms thresh with fwhm + //eg: if(*(mysolar->attr_FWHMEnable_read)) + //rms_thresh=fabs(mysolar->attr_FWHM_read[2]*SIGMA_TO_FWHM_FACTOR/2) + if(ret_fun >= 0 && fabs(rms) > 0.08) + { + use_last_fit = true; + mysolar->attr_GaussFit_read[0] = fit[0]; + mysolar->attr_GaussFit_read[1] = fit[1]; + //mysolar->attr_GaussFit_read[2] = fit[2]; + mysolar->attr_GaussFit_read[2] = mean; + //double temp = fit[3]/(double)(SIGMA_TO_FWHM_FACTOR); + double temp = rms/(double)(SIGMA_TO_FWHM_FACTOR); + if(*(mysolar->attr_WidhtCorrectionEnable_read)) + { + mysolar->attr_GaussFit_read[3]=sqrt(temp*temp + mysolar->widthCorrection*mysolar->widthCorrection); + } + else + { + mysolar->attr_GaussFit_read[3] = (temp > 0) ? temp : -temp; + } + } + else + { + use_last_fit = false; + } + if(!ret_fun && !ret_fun2) + { + //if constraints amp > 0, mean inside analysis region and rms > 1 + if(fit[1] > 0 && mean > mysolar->x_values[mysolar->AnalysisRegionStartPix] && mean < mysolar->x_values[mysolar->AnalysisRegionEndPix] && fabs(rms) > 0.08) + fit_valid = true; + } + if(fit_valid) + { + mysolar->attr_GaussFit_read[0] = fit[0]; + mysolar->attr_GaussFit_read[1] = fit[1]; + //mysolar->attr_GaussFit_read[2] = fit[2]; + mysolar->attr_GaussFit_read[2] = mean; + //double temp = fit[3]/(double)(SIGMA_TO_FWHM_FACTOR); + double temp = rms/(double)(SIGMA_TO_FWHM_FACTOR); + if(*(mysolar->attr_WidhtCorrectionEnable_read)) + { + mysolar->attr_GaussFit_read[3]=sqrt(temp*temp + mysolar->widthCorrection*mysolar->widthCorrection); + } + else + { + mysolar->attr_GaussFit_read[3] = (temp > 0) ? temp : -temp; + } + *(mysolar->attr_GaussFitCenter_read) = mysolar->attr_GaussFit_read[2]; + *(mysolar->attr_GaussFitWidth_read) = mysolar->attr_GaussFit_read[3]; + double val_buff; + val_buff = *(mysolar->attr_GaussFitCenter_read); + mysolar->tbuf[BUF_ID_GAUSS_CENTER].push_data(&val_buff,buf_time,buf_bunch_num); + val_buff = *(mysolar->attr_GaussFitWidth_read); + mysolar->tbuf[BUF_ID_GAUSS_WIDTH].push_data(&val_buff,buf_time,buf_bunch_num); + mysolar->GaussFit_valid = true; + if(!(*(mysolar->attr_FWHMEnable_read)) || !mysolar->preferFWHM) + *(mysolar->attr_Center_read) = mysolar->attr_GaussFit_read[2]; + *(mysolar->attr_Width_read) = mysolar->attr_GaussFit_read[3]; + DEBUG_STREAM << "readthread::run(): FIT VALID! fit_time="<<fit_time << "["<<min_fit_time<<","<<max_fit_time<<"]->"<<avg_fit_time << " fit[1]="<<fit[1]<<" mean="<<mean<<" rms="<<rms; + } + else + { + DEBUG_STREAM << "readthread::run(): FIT NOT VALID: ret_fun="<<ret_fun<<" ret_fun2="<<ret_fun2<<" fit[1]="<<fit[1]<<" mean="<<mean<<" rms="<<rms<<" fit_time="<<fit_time << "["<<min_fit_time<<","<<max_fit_time<<"]->"<<avg_fit_time; + mysolar->GaussFit_valid = false; + } + + } + //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + //::::::::::::::::::::::: AREA processing ::::::::::::::::::::::: + //________________________________________________________________ + if(*(mysolar->attr_AreaEnable_read)) + { + size_t x_start, x_end; + double wl_start, wl_end; + bool region_ok = false; + if((*(mysolar->attr_FWHMEnable_read) || (*(mysolar->attr_GaussFitEnable_read) && mysolar->GaussFit_valid)) && + *(mysolar->attr_Center_read) > mysolar->attr_RegionOfInterest_read[0] && + *(mysolar->attr_Center_read) < mysolar->attr_RegionOfInterest_read[1] && !mysolar->areaInAnalysisRegion) + { + wl_start = *(mysolar->attr_Center_read) - (*(mysolar->attr_AreaRegion_read)/2); + if(wl_start < mysolar->attr_RegionOfInterest_read[0]) + wl_start = mysolar->attr_RegionOfInterest_read[0]; + wl_end = *(mysolar->attr_Center_read) + (*(mysolar->attr_AreaRegion_read)/2); + if(wl_end > mysolar->attr_RegionOfInterest_read[1]) + wl_end = mysolar->attr_RegionOfInterest_read[1]; + x_start = mysolar->WaveLenght2Pix(wl_start); + x_end = mysolar->WaveLenght2Pix(wl_end); + region_ok = true; + } + else if(mysolar->attr_AnalysisRegion_read[0] >= mysolar->attr_RegionOfInterest_read[0] && + mysolar->attr_AnalysisRegion_read[1] <= mysolar->attr_RegionOfInterest_read[1] && mysolar->areaInAnalysisRegion) + { + wl_start = mysolar->attr_AnalysisRegion_read[0]; + wl_end = mysolar->attr_AnalysisRegion_read[1]; + x_start = mysolar->WaveLenght2Pix(wl_start); + x_end = mysolar->WaveLenght2Pix(wl_end); + region_ok = true; + } + + if(region_ok) + { + double area=0; + for(size_t x = x_start; x <= x_end; x++) + area += fabs(mysolar->pLiveData_avg[x]); + *(mysolar->attr_Area_read) = area; + mysolar->tbuf[BUF_ID_AREA].push_data(&area,buf_time,buf_bunch_num); + } + } + //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + //:::::::::::::::: End of Single Mode Acquirement :::::::::::::::: + //________________________________________________________________ + if(mysolar->measure_mode) + { + //mutex_sleep->lock(); + pausesec = 1; + pausenano = 0; + //mutex_sleep->unlock(); + mysolar->init_measure_mode = false; + mysolar->measure_mode = false; + mysolar->set_state(Tango::ON); + mysolar->set_status("Data ready"); + } + /*ret= mysolar->m_usbCCD.StartMeasuring(&(pNoiseData[mysolar->noise_frames_counter * mysolar->m_usbCCD.m_nNumReadOuts * mysolar->NumPixel])); + if(!ret) + { + INFO_STREAM << "readthread::run(): error in StartMeasuring()" << endl; + }*/ + } +#if 0 + else if(stat == STATUS_WAIT_DATA) + { + if((wait_counter % 50) == 0) + DEBUG_STREAM << "readthread::run() WAIT_DATA!! wait_counter=" << wait_counter << endl; + abort_sleep(1.0/100); //TODO: 10 msec, + wait_counter++; + if(wait_counter > 1000) //10 sec + { + mysolar->live_mode = false; + mysolar->init_live_mode = false; + mysolar->init_measure_mode = false; + mysolar->measure_mode = false; + pausesec = 1; + pausenano = 0; + mysolar->set_state(Tango::ON); + mysolar->set_status("Timeout waiting data"); + if(!mysolar->m_usbCCD.Reset()) + { + TangoSys_MemStream out_stream; + out_stream << "Error resetting CCD" << ends; + INFO_STREAM << "readthread::run(): " << out_stream.str() << endl; + } + } + } + else if(stat == STATUS_WAIT_TRIG) + { + if((wait_counter % 50) == 0) + DEBUG_STREAM << "readthread::run() WAIT_TRIG!! wait_counter=" << wait_counter << endl; + abort_sleep(1.0/100); //TODO: 10 msec, + wait_counter++; + if(wait_counter > 1000) //10 sec + { + mysolar->live_mode = false; + mysolar->init_live_mode = false; + mysolar->init_measure_mode = false; + mysolar->measure_mode = false; + pausesec = 1; + pausenano = 0; + mysolar->set_state(Tango::ON); + mysolar->set_status("Timeout waiting trigger"); + if(!mysolar->m_usbCCD.Reset()) + { + TangoSys_MemStream out_stream; + out_stream << "Error resetting CCD" << ends; + INFO_STREAM << "readthread::run(): " << out_stream.str() << endl; + } + } + } +#endif + } + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// + //++++++++++++++++++++++++ACQUIRE NOISE MODE+++++++++++++++++++++++++++// + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// + if(mysolar->acquire_noise_mode) + { + DWORD stat; + //mysolar->m_usbCCD.GetMeasStatus(&stat); + //if(stat == STATUS_DATA_READY) + if(1) + { + wait_counter = 0; + //mysolar->m_usbCCD.GetData(&(pNoiseData[mysolar->noise_frames_counter * mysolar->m_usbCCD.m_nNumReadOuts * mysolar->NumPixel])); +#if _SEABREEZE_API > 1 + /*TODO: length*/flag = sbapi_spectrometer_get_formatted_spectrum(mysolar->device_id, mysolar->spectrometer_id, &error, &(pNoiseData[mysolar->noise_frames_counter * mysolar->NumPixel]), (int)mysolar->NumPixel); +#else + flag = seabreeze_get_formatted_spectrum(mysolar->device_id, &error, &(pNoiseData[mysolar->noise_frames_counter * mysolar->NumPixel]), (int)mysolar->NumPixel); +#endif + mysolar->noise_frames_counter++; + DEBUG_STREAM << "readthread::run() DATA_READY!! noise_frames_counter="<<mysolar->noise_frames_counter <<" noise_frames="<<mysolar->noise_frames << endl; + if(mysolar->noise_frames_counter >= mysolar->noise_frames) + { + double noise_avg=0; + double min_val=0, max_val=10000; + int tmp_count=0; + //for every pixel + for(unsigned int j=0; j < mysolar->noise_frames * mysolar->NumPixel; j++) + { + if(pNoiseData[j] >= min_val && pNoiseData[j] <= max_val) + { + noise_avg += pNoiseData[j]; + tmp_count++; + } + } + DEBUG_STREAM << "readthread::run() DATA_READY!! noise sum="<<noise_avg <<" noise pixel counter="<<tmp_count<<" noise pixel total=" << mysolar->noise_frames * mysolar->NumPixel<< endl; + //divide the sum per the number of frames + noise_avg = noise_avg/((double)tmp_count); + //noise_avg = noise_avg/((double)mysolar->noise_frames * mysolar->m_usbCCD.m_nNumReadOuts * mysolar->NumPixel); + mysolar->noise_level = (int)noise_avg; //truncate + mysolar->attr_NoiseLevel_write = mysolar->noise_level; + + for(size_t k=0; k<mysolar->NumPixel; k++) + { + noise_avg=0; + for(size_t j=0; j<mysolar->noise_frames; j++) + { + noise_avg += pNoiseData[j* mysolar->NumPixel + k]; + } + mysolar->pNoiseMask_avg[k] = noise_avg/mysolar->noise_frames; + } + + ofstream fd; //startup file + fd.open(mysolar->noiseProfileFile.c_str()); + if (!fd) + { + stringstream tmp; + tmp << "Cannot open Noise Profile default file " << mysolar->noiseProfileFile<< " err:" << strerror(errno) << endl; + INFO_STREAM << "readthread::acquire_noise(): " << tmp.str(); + } + else + { + DEBUG_STREAM << "readthread::acquire_noise(): file " << mysolar->noiseProfileFile << " opened successfully" << endl; + for(int i=0; i<mysolar->NumPixel; i++) + { + fd << mysolar->pNoiseMask_avg[i] << endl; + } + fd.close(); + } + + try + { + Tango::MultiAttribute *attr_list; + attr_list = mysolar->get_device_attr(); + Tango::WAttribute &attr_l = attr_list->get_w_attr_by_name ("NoiseLevel"); + attr_l.set_write_value(mysolar->attr_NoiseLevel_write); + } catch(...) + { + DEBUG_STREAM << "readthread::run(): failed setting write value of 'NoiseLevel'"; + } + DEBUG_STREAM << "readthread::run(): calculated noise average="<<noise_avg<<" -> noise_level="<<mysolar->noise_level<<endl; + + delete [] pNoiseData; + pNoiseData=NULL; + + //mutex_sleep->lock(); + pausesec = 1; + pausenano = 0; + //mutex_sleep->unlock(); + mysolar->init_acquire_noise_mode = false; + mysolar->acquire_noise_mode = false; + mysolar->set_state(Tango::ON); + mysolar->set_status("Data ready"); + } + /*else + { + ret= mysolar->m_usbCCD.StartMeasuring(&(pNoiseData[mysolar->noise_frames_counter * mysolar->m_usbCCD.m_nNumReadOuts * mysolar->NumPixel])); + if(!ret) + { + INFO_STREAM << "readthread::run(): error in StartMeasuring()" << endl; + } + }*/ + } +#if 0 + else if(stat == STATUS_WAIT_DATA) + { + if((wait_counter % 50) == 0) + DEBUG_STREAM << "readthread::run() WAIT_DATA!! noise_frames_counter="<<mysolar->noise_frames_counter <<" noise_frames="<<mysolar->noise_frames << " wait_counter=" << wait_counter<< endl; + abort_sleep(1.0/100); //TODO: 10 msec, + wait_counter++; + if(wait_counter > 1000) //10 sec + { + mysolar->init_acquire_noise_mode = false; + mysolar->acquire_noise_mode = false; + pausesec = 1; + pausenano = 0; + mysolar->set_state(Tango::ON); + mysolar->set_status("Timeout waiting noise data"); + if(!mysolar->m_usbCCD.Reset()) + { + TangoSys_MemStream out_stream; + out_stream << "Error resetting CCD" << ends; + INFO_STREAM << "readthread::run(): " << out_stream.str() << endl; + } + } + } + else if(stat == STATUS_WAIT_TRIG) + { + if((wait_counter % 50) == 0) + DEBUG_STREAM << "readthread::run() WAIT_TRIG!! wait_counter=" << wait_counter << endl; + abort_sleep(1.0/100); //TODO: 10 msec, + wait_counter++; + if(wait_counter > 1000) //10 sec + { + mysolar->init_acquire_noise_mode = false; + mysolar->acquire_noise_mode = false; + pausesec = 1; + pausenano = 0; + mysolar->set_state(Tango::ON); + mysolar->set_status("Timeout waiting trigger"); + if(!mysolar->m_usbCCD.Reset()) + { + TangoSys_MemStream out_stream; + out_stream << "Error resetting CCD" << ends; + INFO_STREAM << "readthread::run(): " << out_stream.str() << endl; + } + } + } +#endif + } + if(((mysolar->measure_mode || mysolar->live_mode || mysolar->acquire_noise_mode) && ((counter % 100) == 0)) || + (!mysolar->measure_mode && !mysolar->live_mode && !mysolar->acquire_noise_mode)) + { + //DEBUG_STREAM << "readthread::run(): measure_mode=" << mysolar->measure_mode << " mysolar->live_mode=" << mysolar->live_mode << endl; + //DEBUG_STREAM << "readthread::run(): pausesec=" << pausesec << " pausenano=" << pausenano << endl; + //DEBUG_STREAM << "readthread::run(): before GetParameters()" << endl; +#if 0 + if(!mysolar->m_usbCCD.HitTest()) + { + INFO_STREAM << "readthread::run(): error in HitTest()" << endl; + mysolar->set_state(Tango::FAULT); + mysolar->set_status("Error communicating with CCD"); + pausesec = 1; + pausenano = 0; + mysolar->live_mode = false; + mysolar->init_live_mode = false; + mysolar->init_measure_mode = false; + mysolar->measure_mode = false; + mysolar->init_acquire_noise_mode = false; + mysolar->acquire_noise_mode = false; + if(mysolar->m_usbCCD.InitInstance()) + { + mysolar->m_usbCCD.Attach(mysolar->deviceId); + mysolar->set_state(Tango::ON); + mysolar->set_status("Ready"); + mysolar->init_data(); + } + } + if(!mysolar->m_usbCCD.GetParameters()) + { + //INFO_STREAM << "readthread::run(): error in GetParameters()" << endl; + if(mysolar->m_usbCCD.InitInstance()) + { + mysolar->m_usbCCD.Attach(mysolar->deviceId); + mysolar->set_state(Tango::ON); + mysolar->set_status("Ready"); + mysolar->init_data(); + } + } +#endif + } + abort_sleep(pausesec + ((double)pausenano)/1000000000); + counter++; + } + INFO_STREAM << "readthread::run(): exit!!!" << endl; +} + +//+------------------------------------------------------------------ +// +// 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 (mysolar->abortflag) + break; + if(mysolar->init_live_mode) + break; + if(mysolar->init_measure_mode) + break; + omni_thread::sleep(0,100000000); + } +} + + + diff --git a/src/readthread.h b/src/readthread.h new file mode 100644 index 0000000000000000000000000000000000000000..573abda81db14573f2b73d80aa7745dd18549840 --- /dev/null +++ b/src/readthread.h @@ -0,0 +1,56 @@ +// +// file : readthread.h +// +// description : reading thread +// +// project : TANGO Device Server +// +// $Author: graziano $ +// +// $Revision: 1.1 $ +// +// +// +// copyleft : Sincrotrone Trieste S.C.p.A. +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34012 Basovizza, Trieste ITALY +// + +#ifndef READTHREAD_H_ +#define READTHREAD_H_ + +#include <tango.h> +#include <omnithread.h> +#include "OceanOptics.h" +//#include "UsbCDD.h" + +class readthread : public omni_thread, public Tango::LogAdapter +{ + private: + OceanOptics_ns::OceanOptics *mysolar; + + void abort_sleep(double time); + int wait_counter; + bool use_last_fit; + unsigned long old_bunch_number; + bool just_reconnected; + + public: + + readthread(OceanOptics_ns::OceanOptics *s); + ~readthread(); + + omni_mutex *mutex_sleep; + int pausesec,pausenano; + double min_fit_time; + double max_fit_time; + double tot_fit_time; + double avg_fit_time; + size_t fit_counter; + + protected: + void run(void *); + +}; /* end class readthread() */ + +#endif /*READTHREAD_H_*/ diff --git a/src/tbuffer.hpp b/src/tbuffer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d1c57d1a74cb3b6794befa9d57f0e0117b1cbe4d --- /dev/null +++ b/src/tbuffer.hpp @@ -0,0 +1,2347 @@ +#ifndef __TBUFFER_H +#define __TBUFFER_H + +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <sys/time.h> +#include <math.h> //for NAN +#include <bits/nan.h> //for NAN +#include <stdint.h> + +#define BUF_RT_NO_FILL 0 +#define BUF_RT_FILL_1 1 +#define BUF_RT_FILL_PREV 2 +#define BUF_RT_FILL_0 3 + +#define FILL_ZERO 0x00000000 +#define FILL_NAN NAN +#define FILL_ONE_CHAR (char)0xf +#define FILL_ONE_SHORT (short)0xfff +#define FILL_ONE_LONG (int32_t)0xfffffff +#define FILL_ONE_LONG_LONG (int64_t)(0xfffffffffffffffULL) + +#define BUF_GET_LAST_MODE 0 +#define BUF_GET_BUNCH_MODE 1 +#define BUF_GET_TIME_MODE 2 +#define BUF_GET_LAST_UNIQUE_MODE 3 +#define BUF_GET_BUNCH_UNIQUE_MODE 4 +#define BUF_GET_TIME_UNIQUE_MODE 5 +#define BUF_GET_LAST_BUNCH_MODE 6 +#define BUF_GET_BUNCH_BUNCH_MODE 7 +#define BUF_GET_TIME_BUNCH_MODE 8 + +#define BUF_FILT_STD 0x00000001 +#define BUF_FILT_MEDIAN 0x00000002 +#define BUF_FILT_KALMAN 0x00000004 + +#define MAX_MEDIAN_SAMPLE 4096 + +//#define DEBUG_BUFF 1 + +#ifdef DEBUG_BUFF +#define PRINT(...) (DEBUG_BUFF ? (printf("%s: ", __func__), \ +printf(__VA_ARGS__)) : 0) +#else +#define PRINT(...) +#endif + +namespace tbuffer +{ + +typedef enum +{ + BUF_RT_LINEAR, + BUF_RT_CIRCULAR +} bufRtMode_t; + +typedef enum +{ + typeChar, + typeShort, + typeLong, + typeFloat, + typeDouble, + typeLongLong, + typeCharArray, + typeShortArray, + typeLongArray, + typeFloatArray, + typeDoubleArray, + typeLongLongArray +} type_t; + +/*template <typename T> +class _buffer_data +{ + uint32_t bunchnr; // bunch number -unambiguous- + T data; // data + struct timeval time; // timestamp +};*/ + +/*template <typename T> +class _buffer_data +{ + T data; // data +};*/ + +/*class _bunch_time +{ + uint32_t bunchnr; // bunch number -unambiguous- + struct timeval time; // timestamp +};*/ + +template <typename T> +class _data_array +{ + T *data; // data + size_t count; +public: + _data_array(size_t num){data=new T[num]; count=num;} + _data_array(T *val, size_t num) + { + data=new T[num]; + count=num; + memcpy(data, val, sizeof(T)*num); +// cout<<"copyed num="<<num<<" in _data_array, data[0]="<<data[0]<<" data[1]="<<data[1]<<" data[2]="<<data[2]<<" data[1000]="<<data[1000]<<" data[1001]="<<data[1001]<<" data[1002]="<<data[1002]<<endl; + } + _data_array(){data=NULL; count=0;} + ~_data_array(){if(data) delete [] data;} + T& operator[] (const size_t& i){ return data[i]; } + //T& operator new [] (const int& i){ return data[i]; } + //const _data_array& operator= (const _data_array<T>&){ _data_array<T> ret(count); memcpy(ret.data, data, sizeof(T)*count); return ret; } + const _data_array& operator= (const _data_array<T>& arg) + { + if(count != arg.count) + { + delete [] data; + data=new T[arg.count]; + count=arg.count; + } + memcpy(data, arg.data, sizeof(T)*arg.count); return *this; + } + const _data_array& operator= (const T& arg) + { + if(data) + delete [] data; + data=new T[1]; + count=1; + memcpy(data, &arg, sizeof(T)*1); + return *this; + } + size_t extract_data(T* arg) + { + //cout << __func__<<": entering, count="<<count<<endl; + if(count > 0) + memcpy(arg, &data[0], sizeof(T)*count); + //cout << __func__<<": after memcpy, count="<<count<<" data[0]="<<data[0]<<" data[1]="<<data[1]<<" data[2]="<<data[2]<<" data[1000]="<<data[1000]<<" data[1001]="<<data[1001]<<" data[1002]="<<data[1002]<<endl; + return count; + } + size_t get_count() + { + return count; + } +}; + + +template<typename T> +struct identity { typedef T type; }; + +//----------------------------------------------------------------------------------------------------------------- + +int tv_compare(struct timeval ts1, struct timeval ts2); + +template <typename T> +class buffer_t +{ +private: + long size; // size of circular buffer + type_t type; //type of data + long idx; // index inside the buffer + unsigned long counter; // number of push executed + unsigned long mode; // flag that enables circular buffer, when 0 and the buffer is + // full, push will return false + unsigned long fill_hole;// is a bunch hole happens, this flag determines behaviour: + // 0 = no fill + // 1 = fill with 0xffffffff or NaN + // 2 = fill with previous value inside the buffer + // 3 = fill with 0 + //T *buffer_data; // data + uint32_t *bunchnr; // bunch number -unambiguous- + T *data; // data + timeval *time; // timestamp + //()()()()()()()()()()()()()()() KALMAN ()()()()()()()()()()()()()()() + double sigmav; //observation noise covariance + double sigmaw; //observation noise covariance + double P; //error covariance + double x; //real state + double x_; //predicted state + double z; //observation + +type_t get_type(T foo) +{ + return m_get_type(foo); +} + +public: +//template <typename TL> +type_t get_type() +{ + return get_type(identity<T>()); +} +void fill0(T *val) +{ + *val = 0; +} +void fill1(T *val) +{ + fill1(val, identity<T>()); +} +private: +template<typename TL> +type_t get_type(identity<TL>) +{ + //return NULL;//TODO +} + +type_t get_type(identity<int8_t>) +{ + return typeChar; +} +type_t get_type(identity<int16_t>) +{ + return typeShort; +} +type_t get_type(identity<int32_t>) +{ + return typeLong; +} +type_t get_type(identity<int64_t>) +{ + return typeLongLong; +} +type_t get_type(identity<float>) +{ + return typeFloat; +} +type_t get_type(identity<double>) +{ + return typeDouble; +} +type_t get_type(identity<_data_array<int8_t> >) +{ + return typeCharArray; +} +type_t get_type(identity<_data_array<int16_t> >) +{ + return typeShortArray; +} +type_t get_type(identity<_data_array<int32_t> >) +{ + return typeLongArray; +} +type_t get_type(identity<_data_array<int64_t> >) +{ + return typeLongLongArray; +} +type_t get_type(identity<_data_array<float> >) +{ + return typeFloatArray; +} +type_t get_type(identity<_data_array<double> >) +{ + return typeDoubleArray; +} + +template<typename TL> +void fill1(TL *val, identity<TL>) +{ + //TODO: data_array!!!!!!!!!!!!!!!!!!!!!! +} +void fill1(int8_t *val, identity<int8_t>) +{ + *val = FILL_ONE_CHAR; +} +void fill1(int16_t *val, identity<int16_t>) +{ + *val = FILL_ONE_SHORT; +} +void fill1(int32_t *val, identity<int32_t>) +{ + *val = FILL_ONE_LONG; +} +void fill1(int64_t *val, identity<int64_t>) +{ + *val = FILL_ONE_LONG_LONG; +} +void fill1(float *val, identity<float>) +{ + *val = FILL_NAN; +} +void fill1(double *val, identity<double>) +{ + *val = FILL_NAN; +} +void fill1(_data_array<int8_t> *val, identity<_data_array<int8_t> >) +{ + *val = _data_array<int8_t>(FILL_ONE_CHAR); +} +void fill1(_data_array<int16_t> *val, identity<_data_array<int16_t> >) +{ + *val = _data_array<int16_t>(FILL_ONE_SHORT); +} +void fill1(_data_array<int32_t> *val, identity<_data_array<int32_t> >) +{ + *val = _data_array<int32_t>(FILL_ONE_LONG); +} +void fill1(_data_array<int64_t> *val, identity<_data_array<int64_t> >) +{ + *val = _data_array<int64_t>(FILL_ONE_LONG_LONG); +} +void fill1(_data_array<float> *val, identity<_data_array<float> >) +{ + *val = _data_array<float>(FILL_NAN); +} +void fill1(_data_array<double> *val, identity<_data_array<double> >) +{ + *val = _data_array<double>(FILL_NAN); +} + + +public: +/*********************************** + * allocates memory + ***********************************/ +int init_rt_buffer(long numsamples) +{ + + unsigned long type_size; + //PRINT("entering... ver: %s %s file: %s\n", version_string, release_string, __FILE__rev); + //trick to have release string in the binary, but I don't want the printf to be executed + + type = get_type(); //TODO + //PRINT("setting type=%d\n",buffer.type); + if(numsamples == 0) + return -1; + + // allocates memory + /*buffer_data = new T[numsamples]; + if (!buffer_data) + return -ENOMEM;*/ + bunchnr = NULL; + data = NULL; + time = NULL; + bunchnr = new uint32_t[numsamples]; // bunch number -unambiguous- + data = new T[numsamples]; // data + time = new timeval[numsamples]; // timestamp + if (!bunchnr || !data || !time) + return -ENOMEM; + +// clean buffer + //memset(buffer_data, 0, sizeof(buffer_data)*numsamples); + memset(bunchnr, 0, sizeof(uint32_t)*numsamples); + memset(data, 0, sizeof(T)*numsamples); + memset(time, 0, sizeof(timeval)*numsamples); + +// init size + size = numsamples; + +// init index + idx = 0; + counter = 0; + mode = BUF_RT_CIRCULAR; + fill_hole = BUF_RT_NO_FILL; + + return 0; +} + +/*********************************** + * free memory + ***********************************/ +int delete_rt_buffer() +{ +// frees memory + //delete [] buffer_data; + delete [] bunchnr; + delete [] data; + delete [] time; + return 0; +} + +/*********************************** + * reset buffer + ***********************************/ +int reset_rt_buffer() +{ +// init index + idx = 0; + counter = 0; + return 0; +} + +/*********************************** + * push data into buffer + ***********************************/ +int push_data(T *value, timeval timestamp, uint32_t bunchnumber) +{ + struct timeval now; + struct timezone tz; + +//manage -full- condition + if((counter < size)||(mode == BUF_RT_CIRCULAR)) + { + +//buffer not full or circular => hole check + if(counter!=0) //first push skip hole check + { + long prev_idx = (idx-1+size)%size; +//found a hole + while(((bunchnumber > bunchnr[prev_idx]) && (bunchnumber!=(bunchnr[prev_idx])+1)&&((counter != size)||(mode == BUF_RT_CIRCULAR)))&&(fill_hole!=BUF_RT_NO_FILL)){ + PRINT("data pushed pos: %li\n", idx); + switch(fill_hole) + { + case BUF_RT_FILL_1: //fill with 0xffffffff, NAN + fill1(&data[idx]); + gettimeofday(&now,&tz); + (time[idx]).tv_sec = now.tv_sec; + (time[idx]).tv_usec = now.tv_usec; + /*printf("pushed: %d, %d, %d-%d\n", FILL_ONE_LONG, (bunchnr_ptr[prev_idx])+1, now.tv_sec, now.tv_usec);*/ + PRINT("fill policy: added 1 on pos=%li\n", idx); + break; + case BUF_RT_FILL_0: //fill with 0 + fill0(&data[idx]); + gettimeofday(&now,&tz); + (time[idx]).tv_sec = now.tv_sec; + (time[idx]).tv_usec = now.tv_usec; + /*printf("pushed: %d, %d, %d-%d\n", FILL_ONE_LONG, (bunchnr_ptr[prev_idx])+1, now.tv_sec, now.tv_usec);*/ + PRINT("fill policy: added 0 on pos=%li\n", idx); + break; + case BUF_RT_FILL_PREV: //fill with previous value + data[idx] = data[prev_idx]; + (time[idx]).tv_sec = (time[prev_idx]).tv_sec; + (time[idx]).tv_usec = (time[prev_idx]).tv_usec; + /*PRINT("pushed: %f, %d, %d-%d\n", data_ptr[prev_idx], (bunchnr_ptr[prev_idx])+1, time_ptr[prev_idx].tv_sec, time_ptr[prev_idx].tv_usec);*/ + PRINT("fill policy: added previous on pos=%li\n", idx); + break; + } + bunchnr[idx] = bunchnr[prev_idx]+1; + //TODO: why counter limited to size? + //this->counter = (this->counter==this->size)?this->size:this->counter+1; + counter++; + idx = ((idx + 1) % size); + prev_idx = (idx-1+size)%size; + } + } + else + { + //PRINT("no holes check\n"); + } +//insertion + if((counter != size)||(mode == BUF_RT_CIRCULAR)) + { + data[idx] = *value; + (time[idx]).tv_sec = timestamp.tv_sec; + (time[idx]).tv_usec = timestamp.tv_usec; + bunchnr[idx] = bunchnumber; + //TODO: why counter limited to size? + //this->counter = (this->counter==this->size)?this->size:this->counter+1; + counter++; + //TODO: memory barrier here? +#ifndef __KERNEL__ +#if __BYTE_ORDER == __BIG_ENDIAN //powerpc + asm volatile("lwsync"); +#else + asm volatile("mfence"); +#endif +#endif + idx = ((idx + 1) % size); + return 0; + } + else{ + PRINT("no push after holes check: buffer is full counter=%li size=%li\n",counter,size); + return -1; + } + } + else{ + PRINT("no push: buffer is full counter=%li size=%li\n",counter,size); + return -1; + } +}; + +/*********************************** + * extract data from buffer + ***********************************/ +int pop_data(unsigned char unique, long idx[2], T *data_buf) +{ + long i = idx[0]; + long h = idx[1]; + long size_tmp1 = 0; + long size_tmp2 = 0; + read_data(unique, idx, data_buf); + if(i < h) + { + size_tmp1 = h-i; + } + else if(i > h) + { + size_tmp1 = this->size - i; //i -> buffer size + size_tmp2 = h; //0 -> h + } + idx = ((this->idx)-(size_tmp1 + size_tmp2)+size)%size; + return 0; +}; + +/*int read_data(unsigned char unique, long idx[2], T *data_buf) +{ + return read_data(unsigned char unique, long idx[2], T *data_buf); +}; +private: +template<typename TL> +long get_data_size(identity<TL>) +{ + return this->size; +} +template<typename TL> +long get_data_size(identity<_data_array<TL> >) +{ + long ret_size=0; + for(int i=0; i<size; i++) + { + ret_size += data[i].count; + } + return ret_size; +} + +private:*/ +/*********************************** + * read data from buffer + ***********************************/ +int read_data(unsigned char unique, long idx[2], T *data_buf){ + + long i = idx[0]; + long h = idx[1]; + long size_tmp1 = 0; + long size_tmp2 = 0; + int k = 0, j=0; + long ns; + unsigned long last_bunchnr = -1; + T *data_ptr = &data[0]; + uint32_t *bunchnr_ptr = (uint32_t *)&bunchnr[0]; + if(i < 0 || h < 0) + return -1; + //long ns = (h-i+this->size)%this->size; + PRINT("from idx[0] = %li, to idx[1] = %li\n", idx[0], idx[1]); + /*while(k<ns){ //TODO: memcpy + switch(this->type) + { + case typeChar: + ((char*)data_buf)[k] = ((char*)data_ptr)[i]; + break; + case typeShort: + ((short*)data_buf)[k] = ((short*)data_ptr)[i]; + break; + case typeLong: + ((long*)data_buf)[k] = ((long*)data_ptr)[i]; + break; + case typeFloat: + ((float*)data_buf)[k] = ((float*)data_ptr)[i]; + break; + case typeDouble: + ((double*)data_buf)[k] = ((double*)data_ptr)[i]; + break; + case typeLongLong: + ((long long*)data_buf)[k] = ((long long*)data_ptr)[i]; + break; + default: + break; + } + i+=1; + if(i==this->size)i=0; + k+=1; + PRINT("saving index %d to pos %d\n", i, k); + }*/ + if(unique!=1) + { + //case 1: just memcpy between indexes + if(i <= h) + { + size_tmp1 = h-i+1; + switch(type) + { + case typeChar: + case typeShort: + memcpy(&((T*)data_buf)[0], &((T*)data_ptr)[i], size_tmp1 * sizeof(T)); + break; + case typeLong: + memcpy(&((T*)data_buf)[0], &((T*)data_ptr)[i], size_tmp1 * sizeof(T)); + if(unique == 2) + memcpy(&((T)data_buf)[size_tmp1], &bunchnr_ptr[i], size_tmp1 * sizeof(T)); + //PRINT("copied from %li, to %li\n", ((long*)data_ptr)[i],((long*)data_buf)[0]); + break; + case typeFloat: + case typeDouble: + case typeLongLong: + memcpy(&((T*)data_buf)[0], &((T*)data_ptr)[i], size_tmp1 * sizeof(T)); + if(unique == 2) + { + for(k=0; k < size_tmp1; k++) + { + ((T*)data_buf)[size_tmp1+k] = (T)bunchnr_ptr[i+k]; + } + } + break; + default: + break; + } + } + //case 2: memcpy from i -> buffer size and from 0 to h + else if(i > h) + { + size_tmp1 = size - i; //i -> buffer size + size_tmp2 = h+1; //0 -> h + switch(type) + { + case typeChar: + case typeShort: + memcpy(&((T*)data_buf)[0], &((T*)data_ptr)[i], size_tmp1 * sizeof(T)); + memcpy(&((T*)data_buf)[size_tmp1], &((T*)data_ptr)[0], size_tmp2 * sizeof(T)); + break; + case typeLong: + memcpy(&((T*)data_buf)[0], &((T*)data_ptr)[i], size_tmp1 * sizeof(T)); + memcpy(&((T*)data_buf)[size_tmp1], &((T*)data_ptr)[0], size_tmp2 * sizeof(T)); + if(unique == 2) + { + memcpy(&((T*)data_buf)[size_tmp1+size_tmp2], &bunchnr_ptr[i], size_tmp1 * sizeof(T)); + memcpy(&((T*)data_buf)[size_tmp1+size_tmp2+size_tmp1], &bunchnr_ptr[0], size_tmp2 * sizeof(T)); + } + break; + case typeFloat: + case typeDouble: + case typeLongLong: + memcpy(&((T*)data_buf)[0], &((T*)data_ptr)[i], size_tmp1 * sizeof(T)); + memcpy(&((T*)data_buf)[size_tmp1], &((T*)data_ptr)[0], size_tmp2 * sizeof(T)); + if(unique == 2) + { + for(k=0; k < size_tmp1; k++) + { + ((T*)data_buf)[size_tmp1+size_tmp2+k] = (T)bunchnr_ptr[i+k]; + } + for(k=0; k < size_tmp2; k++) + { + ((T*)data_buf)[size_tmp1+size_tmp2+size_tmp1+k] = (T)bunchnr_ptr[k]; + } + } + break; + default: + break; + } + } + } + else //unique + { + //ns = (h-i+1+this->size)%this->size; + if(h > i) + { + ns = h - i; + } + else if(h < i) + { + ns = this->size - i + h; + } + else + { + ns = 0; + } + ns+=1; + PRINT("from idx[0] = %li, to idx[1] = %li, unique size=%li\n", idx[0], idx[1], ns); + while(j<ns) + { + if(last_bunchnr == bunchnr_ptr[i]) + { + i+=1; + if(i==size)i=0; + j++; + PRINT("skipped bunchnr=%li, now i=%li, j=%i\n", last_bunchnr, i,j); + continue; + } + else + { + last_bunchnr = bunchnr_ptr[i]; + j++; + PRINT("now bunchnr=%li, i=%li,j=%i\n", last_bunchnr, i,j); + } + ((T*)data_buf)[k] = ((T*)data_ptr)[i]; + i+=1; + if(i==size)i=0; + k+=1; + } + } + return 0; +}; + +/*********************************** + * read data from buffer + ***********************************/ +template <typename TL> int read_data(unsigned char unique, long idx[2], TL *data_buf, _data_array<TL> *foo){ + + long i = idx[0]; + long h = idx[1]; + long size_tmp1 = 0; + long size_tmp2 = 0; + int k = 0, j=0; + long ns; + unsigned long last_bunchnr = -1; + T *data_ptr = &data[0]; + uint32_t *bunchnr_ptr = (uint32_t *)&bunchnr[0]; + if(i < 0 || h < 0) + return -1; + //long ns = (h-i+this->size)%this->size; + PRINT("from idx[0] = %li, to idx[1] = %li\n", idx[0], idx[1]); + /*while(k<ns){ //TODO: memcpy + switch(this->type) + { + case typeChar: + ((char*)data_buf)[k] = ((char*)data_ptr)[i]; + break; + case typeShort: + ((short*)data_buf)[k] = ((short*)data_ptr)[i]; + break; + case typeLong: + ((long*)data_buf)[k] = ((long*)data_ptr)[i]; + break; + case typeFloat: + ((float*)data_buf)[k] = ((float*)data_ptr)[i]; + break; + case typeDouble: + ((double*)data_buf)[k] = ((double*)data_ptr)[i]; + break; + case typeLongLong: + ((long long*)data_buf)[k] = ((long long*)data_ptr)[i]; + break; + default: + break; + } + i+=1; + if(i==this->size)i=0; + k+=1; + PRINT("saving index %d to pos %d\n", i, k); + }*/ + if(unique!=1) + { + //case 1: just memcpy between indexes + if(i <= h) + { + size_tmp1 = h-i+1; + switch(type) + { + case typeCharArray: + case typeShortArray: + case typeLongArray: + case typeFloatArray: + case typeDoubleArray: + case typeLongLongArray: + { + int z=0; + for(k=0; k < size_tmp1; k++) + { + PRINT("k=%d size_tmp1=%d\n", k, size_tmp1); + int ret=data_ptr[i+k].extract_data(&data_buf[z]); + z+=ret; + PRINT("z=%d\n", z); + } + if(unique == 2) + { + for(k=0; k < size_tmp1; k++) + { + int ret=data_ptr[i+k].get_count(); + PRINT("k=%d size_tmp1=%d ret=%d\n", k, size_tmp1, ret); + for(int bp=0; bp<ret; bp++) + { + ((TL*)data_buf)[z+bp] = (TL)bunchnr_ptr[i+k]; //copy ret times bunchnumber + } + z+=ret; + PRINT("z=%d\n", z); + } + } + break; + } + default: + break; + } + } + //case 2: memcpy from i -> buffer size and from 0 to h + else if(i > h) + { + size_tmp1 = size - i; //i -> buffer size + size_tmp2 = h+1; //0 -> h + switch(type) + { + case typeCharArray: + case typeShortArray: + case typeLongArray: + case typeFloatArray: + case typeDoubleArray: + case typeLongLongArray: + { + int z=0; + for(k=0; k < size_tmp1; k++) + { + int ret=data_ptr[i+k].extract_data(&data_buf[z]); + z+=ret; + } + for(k=0; k < size_tmp2; k++) + { + int ret=data_ptr[0+k].extract_data(&data_buf[z]); + z+=ret; + } + if(unique == 2) + { + for(k=0; k < size_tmp1; k++) + { + int ret=data_ptr[i+k].get_count(); + for(int bp=0; bp<ret; bp++) + { + ((TL*)data_buf)[z+bp] = (TL)bunchnr_ptr[i+k]; //copy ret times bunchnumber + } + z+=ret; + } + for(k=0; k < size_tmp2; k++) + { + int ret=data_ptr[0+k].get_count(); + for(int bp=0; bp<ret; bp++) + { + ((TL*)data_buf)[z+bp] = (TL)bunchnr_ptr[0+k]; //copy ret times bunchnumber + } + z+=ret; + } + } + break; + } + default: + break; + } + } + } + else //unique + { + //ns = (h-i+1+this->size)%this->size; + if(h > i) + { + ns = h - i; + } + else if(h < i) + { + ns = this->size - i + h; + } + else + { + ns = 0; + } + ns+=1; + PRINT("from idx[0] = %li, to idx[1] = %li, unique size=%li\n", idx[0], idx[1], ns); + while(j<ns) + { + if(last_bunchnr == bunchnr_ptr[i]) + { + i+=1; + if(i==size)i=0; + j++; + PRINT("skipped bunchnr=%li, now i=%li, j=%i\n", last_bunchnr, i,j); + continue; + } + else + { + last_bunchnr = bunchnr_ptr[i]; + j++; + PRINT("now bunchnr=%li, i=%li,j=%i\n", last_bunchnr, i,j); + } + int ret=data_ptr[i].extract_data(&data_buf[k]); + i+=1; + if(i==size)i=0; + k+=ret; + } + } + return 0; +}; + +public: + +#define ELEM_SWAP_L(a,b) { register int32_t t=(a);(a)=(b);(b)=t; } +#define ELEM_SWAP_D(a,b) { register double t=(a);(a)=(b);(b)=t; } + +int read_data_filter(unsigned char unique, long idx[2], double x2, double x1, double x0, double *std, double *mean, void *median, double *kalman, int mask, void *skip) +{ + long i = idx[0]; + long h = idx[1]; + int ns; + char to_be_skipped=0; + + uint32_t last_bunchnr = -1; + int k = 0, j=0; + int count=0; + double val; + double delta = 0.0; + double M2 = 0.0; + + int low, high ; + int median_idx; + int middle, ll, hh; + unsigned long type_size; +// long *arr_l; + int32_t arr_l[MAX_MEDIAN_SAMPLE]; +// double *arr_d; + double arr_d[MAX_MEDIAN_SAMPLE]; + + T *data_ptr = &data[0]; + uint32_t *bunchnr_ptr = (uint32_t *)&bunchnr[0]; + + if(mean) + *mean=0; + if(std) + *std=0; + if(median) + { + switch(this->type) + { + case typeChar: + case typeShort: + case typeFloat: + case typeLongLong: + break; + case typeLong: + case typeDouble: + *(T *)median=0; + break; + } + } + if(kalman) + *kalman=0; + + if(mask == 0) //if no mask selected + { + //return last (average of 1) + mask = BUF_FILT_STD; + i=h; + } + + if(h > i) + ns = h - i; + else if(h < i) + ns = size - i + h; + else + ns = 0; + ns+=1; + + if(i < 0 || h < 0) + return -1; + //long ns = (h-i+this->size)%this->size; + PRINT("from idx[0] = %li, to idx[1] = %li numsample=%i\n", idx[0], idx[1], ns); + //std/mean algorithm due to Knuth + if(mask & BUF_FILT_STD) + { + while(j<ns) + { + if(unique==1) + { + if(last_bunchnr == bunchnr_ptr[i]) + { + i+=1; + if(i==this->size)i=0; + j++; + continue; + } + else + { + last_bunchnr = bunchnr_ptr[i]; + } + } + + switch(this->type) + { + case typeChar: + case typeShort: + case typeLong: + case typeLongLong: + val = x2 * ((T*)data_ptr)[i] * ((T*)data_ptr)[i] + x1 * ((T*)data_ptr)[i] + x0; + to_be_skipped = (skip != NULL) ? ((((T*)data_ptr)[i] == *(T*)skip) ? 1 : 0) : 0; + break; + case typeFloat: + case typeDouble: + val = x2 * ((T*)data_ptr)[i] * ((T*)data_ptr)[i] + x1 * ((T*)data_ptr)[i] + x0; + to_be_skipped = (skip != NULL) ? ((((T*)data_ptr)[i] == *(T*)skip) ? 1 : ((isnan(((T*)data_ptr)[i]) || isinf(((T*)data_ptr)[i])) ? 1 : 0)) : 0; + break; + case typeCharArray: + case typeShortArray: + case typeLongArray: + case typeFloatArray: + case typeDoubleArray: + case typeLongLongArray: + break; + default: + break; + } + + i+=1; + if(i==this->size)i=0; + k+=1; + j++; + if(to_be_skipped == 1) + continue; + //std/mean algorithm due to Knuth + count++; + delta = val - (*mean); + *mean = *mean + delta/count; + M2 = M2 + delta*(val - *mean); // This expression uses the new value of mean + PRINT("MEAN/STD: count=%d val=%f mean=%f\n", count, val, *mean); + } + if(count < 1) + { + return -1; + } + else if(count == 1) + { + *std = 0; + } + else + { + *std = M2/(count - 1); + *std = sqrt(*std); + } + } + if(mask & BUF_FILT_MEDIAN) + { + if(ns > MAX_MEDIAN_SAMPLE) + return -1; + switch(this->type) + { + case typeChar: + type_size = sizeof(char); + break; + case typeShort: + type_size = sizeof(short); + break; + case typeLong: + type_size = sizeof(int32_t); + break; + case typeFloat: + type_size = sizeof(float); + break; + case typeDouble: + type_size = sizeof(double); + break; + case typeLongLong: + type_size = sizeof(int64_t); + break; + default: + type_size = 0; + break; + } + + + +// allocates memory + switch(this->type) + { + case typeChar: + case typeShort: + case typeFloat: + case typeLongLong: + break; + case typeLong: + /*arr_l = malloc(type_size*ns); + if (!arr_l) + { + return -ENOMEM; + }*/ + read_data(unique%2, idx, (void *)arr_l); //not interested in bunchnumbers if unique=2 here + break; + case typeDouble: + /*arr_d = malloc(type_size*ns); + if (!arr_d) + { + return -ENOMEM; + }*/ + read_data(unique%2, idx, (void *)arr_d); //not interested in bunchnumbers if unique=2 here + break; + } + + switch(this->type) + { + case typeChar: + case typeShort: + case typeFloat: + case typeLongLong: + break; + case typeLong: + if(skip != NULL) + { + j=0; + for(i=0; i<ns; i++) + { + if(arr_l[i] != *(int32_t*)skip) + { + arr_l[j++] = arr_l[i]; + PRINT("MEDIAN: skipping... arr_l[%d]=%li\n", j, arr_l[j-1]); + } + /*else //to be skipped + */ + + } + ns = j; + } + low = 0 ; high = ns-1 ; median_idx = (low + high) / 2; + for (;;) { + PRINT("MEDIAN: low=%d high=%d median_idx=%d\n", low, high, median_idx); + if (high <= low) /* One element only */ + goto found_median; + + if (high == low + 1) { /* Two elements only */ + if (arr_l[low] > arr_l[high]) + ELEM_SWAP_L(arr_l[low], arr_l[high]); + goto found_median; + } + + /* Find median of low, middle and high items; swap into position low */ + middle = (low + high) / 2; + if (arr_l[middle] > arr_l[high]) ELEM_SWAP_L(arr_l[middle], arr_l[high]) ; + if (arr_l[low] > arr_l[high]) ELEM_SWAP_L(arr_l[low], arr_l[high]) ; + if (arr_l[middle] > arr_l[low]) ELEM_SWAP_L(arr_l[middle], arr_l[low]) ; + + /* Swap low item (now in position middle) into position (low+1) */ + ELEM_SWAP_L(arr_l[middle], arr_l[low+1]) ; + + /* Nibble from each end towards middle, swapping items when stuck */ + ll = low + 1; + hh = high; + for (;;) { + do ll++; while (arr_l[low] > arr_l[ll]) ; + do hh--; while (arr_l[hh] > arr_l[low]) ; + + if (hh < ll) + break; + + ELEM_SWAP_L(arr_l[ll], arr_l[hh]) ; + } + + /* Swap middle item (in position low) back into correct position */ + ELEM_SWAP_L(arr_l[low], arr_l[hh]) ; + + /* Re-set active partition */ + if (hh <= median_idx) + low = ll; + if (hh >= median_idx) + high = hh - 1; + } + break; + case typeDouble: + if(skip != NULL) + { + j=0; + for(i=0; i<ns; i++) + { + if(arr_d[i] != *(double*)skip) + { + arr_d[j++] = arr_d[i]; + PRINT("MEDIAN: skipping... arr_d[%d]=%f\n", j, arr_d[j-1]); + } + /*else //to be skipped + */ + + } + ns = j; + } + low = 0 ; high = ns-1 ; median_idx = (low + high) / 2; + for (;;) { + PRINT("MEDIAN: low=%d high=%d median_idx=%d\n", low, high, median_idx); + if (high <= low) /* One element only */ + goto found_median; + + if (high == low + 1) { /* Two elements only */ + if (arr_d[low] > arr_d[high]) + ELEM_SWAP_D(arr_d[low], arr_d[high]); + goto found_median; + } + + /* Find median of low, middle and high items; swap into position low */ + middle = (low + high) / 2; + if (arr_d[middle] > arr_d[high]) ELEM_SWAP_D(arr_d[middle], arr_d[high]) ; + if (arr_d[low] > arr_d[high]) ELEM_SWAP_D(arr_d[low], arr_d[high]) ; + if (arr_d[middle] > arr_d[low]) ELEM_SWAP_D(arr_d[middle], arr_d[low]) ; + + /* Swap low item (now in position middle) into position (low+1) */ + ELEM_SWAP_D(arr_d[middle], arr_d[low+1]) ; + + /* Nibble from each end towards middle, swapping items when stuck */ + ll = low + 1; + hh = high; + for (;;) { + do ll++; while (arr_d[low] > arr_d[ll]) ; + do hh--; while (arr_d[hh] > arr_d[low]) ; + + if (hh < ll) + break; + + ELEM_SWAP_D(arr_d[ll], arr_d[hh]) ; + } + + /* Swap middle item (in position low) back into correct position */ + ELEM_SWAP_D(arr_d[low], arr_d[hh]) ; + + /* Re-set active partition */ + if (hh <= median_idx) + low = ll; + if (hh >= median_idx) + high = hh - 1; + } + break; + } +found_median: + switch(this->type) + { + case typeChar: + case typeShort: + case typeFloat: + case typeLongLong: + break; + case typeLong: + *(double *)median = x2*arr_l[median_idx]*arr_l[median_idx] + x1*arr_l[median_idx] + x0; + break; + case typeDouble: + *(double *)median = x2*arr_d[median_idx]*arr_d[median_idx] + x1*arr_d[median_idx] +x0; + break; + } +// frees memory + switch(this->type) + { + case typeChar: + case typeShort: + case typeFloat: + case typeLongLong: + break; + case typeLong: + // free(arr_l); + break; + case typeDouble: + // free(arr_d); + break; + } + } + return 0; +} + + +/**************************************** + * read data calibrated from buffer + * each data is calibrated as: + * x2 * d^2 + x1 * d + x0 + * return the number of data read + ****************************************/ +int read_data_calib(unsigned char unique, long idx[2], double *data_buf, double x2, double x1, double x0){ + + long i = idx[0]; + long h = idx[1]; + int k = 0, j=0; + int ns; + uint32_t last_bunchnr = -1; + + T *data_ptr = &data[0]; + uint32_t *bunchnr_ptr = (uint32_t *)&bunchnr[0]; + + if(h > i) + ns = h - i; + else if(h < i) + ns = this->size - i + h; + else + ns = 0; + ns+=1; + + if(i < 0 || h < 0) + return -1; + //long ns = (h-i+this->size)%this->size; + //PRINT("from idx[0] = %li, to idx[1] = %li numsample=%i\n", idx[0], idx[1], ns); + while(j<ns) + { + if(unique == 1) + { + if(last_bunchnr == bunchnr_ptr[i]) + { + i+=1; + if(i==this->size)i=0; + j++; + continue; + } + else + { + last_bunchnr = bunchnr_ptr[i]; + } + } + switch(this->type) + { + case typeChar: + data_buf[k] = x2 * ((int8_t*)data_ptr)[i] * ((int8_t*)data_ptr)[i] + x1 * ((int8_t*)data_ptr)[i] + x0; + break; + case typeShort: + data_buf[k] = x2 * ((int16_t*)data_ptr)[i] * ((int16_t*)data_ptr)[i] + x1 * ((int16_t*)data_ptr)[i] + x0; + break; + case typeLong: + data_buf[k] = x2 * ((int32_t*)data_ptr)[i] * ((int32_t*)data_ptr)[i] + x1 * ((int32_t*)data_ptr)[i] + x0; + break; + case typeFloat: + data_buf[k] = x2 * ((float*)data_ptr)[i] * ((float*)data_ptr)[i] + x1 * ((float*)data_ptr)[i] + x0; + break; + case typeDouble: + data_buf[k] = x2 * ((double*)data_ptr)[i] * ((double*)data_ptr)[i] + x1 * ((double*)data_ptr)[i] + x0; + break; + case typeLongLong: + data_buf[k] = x2 * ((int64_t*)data_ptr)[i] * ((int64_t*)data_ptr)[i] + x1 * ((int64_t*)data_ptr)[i] + x0; + break; + case typeCharArray: + case typeShortArray: + case typeLongArray: + case typeFloatArray: + case typeDoubleArray: + case typeLongLongArray: + /*{ + int ret=data_ptr[i].extract_data(&data_buf[k]); + for(int zz=i; zz<i+ret; zz++) + { + data_buf[zz] = x2 * (data_buf)[zz] * (data_buf)[zz] + x1 * (data_buf)[zz] + x0; + } + break; + }*/ + default: + break; + } + if(unique == 2) + data_buf[k+ns] = (double)bunchnr_ptr[i]; //concatenate bunchnumbers + i+=1; + if(i==this->size)i=0; + k+=1; + j++; + //PRINT("saving index %ld to pos %d\n", i, k); + } + return 0; +}; +//#endif +//#ifndef __KERNEL__ //TODO: __floatdidf +//std/mean algorithm due to Knuth +template <typename TL> int read_std_calib(unsigned char unique, long idx[2], double x2, double x1, double x0, double *std, double *mean) +{ + long i = idx[0]; + long h = idx[1]; + int k = 0, j=0; + int ns; + uint32_t last_bunchnr = -1; + + int count=0; + double val; + double delta = 0; + double M2 = 0; + + TL *data_ptr = &data[0]; + uint32_t *bunchnr_ptr = (uint32_t *)&bunchnr[0]; + + *mean=0; + *std=0; + + if(h > i) + ns = h - i; + else if(h < i) + ns = this->size - i + h; + else + ns = 0; + ns+=1; + + if(i < 0 || h < 0) + return -1; + //long ns = (h-i+this->size)%this->size; + PRINT("from idx[0] = %li, to idx[1] = %li numsample=%i\n", idx[0], idx[1], ns); + while(j<ns) + { + if(unique==1) + { + if(last_bunchnr == bunchnr_ptr[i]) + { + i+=1; + if(i==this->size)i=0; + j++; + continue; + } + else + { + last_bunchnr = bunchnr_ptr[i]; + } + } + switch(this->type) + { + case typeChar: + val = x2 * ((int8_t*)data_ptr)[i] * ((int8_t*)data_ptr)[i] + x1 * ((int8_t*)data_ptr)[i] + x0; + break; + case typeShort: + val = x2 * ((int16_t*)data_ptr)[i] * ((int16_t*)data_ptr)[i] + x1 * ((int16_t*)data_ptr)[i] + x0; + break; + case typeLong: + val = x2 * ((int32_t*)data_ptr)[i] * ((int32_t*)data_ptr)[i] + x1 * ((int32_t*)data_ptr)[i] + x0; + break; + case typeFloat: + val = x2 * ((float*)data_ptr)[i] * ((float*)data_ptr)[i] + x1 * ((float*)data_ptr)[i] + x0; + break; + case typeDouble: + val = x2 * ((double*)data_ptr)[i] * ((double*)data_ptr)[i] + x1 * ((double*)data_ptr)[i] + x0; + break; + case typeLongLong: + val = x2 * ((int64_t*)data_ptr)[i] * ((int64_t*)data_ptr)[i] + x1 * ((int64_t*)data_ptr)[i] + x0; + break; + case typeCharArray: + case typeShortArray: + case typeLongArray: + case typeFloatArray: + case typeDoubleArray: + case typeLongLongArray: + { + /*int ret=data_ptr[i].extract_data(&data_buf[k]); + for(int zz=i; zz<i+ret; zz++) + { + data_ptr[zz] = x2 * ((T*)data_ptr)[zz] * ((T*)data_ptr)[zz] + x1 * ((T*)data_ptr)[zz] + x0; + }*/ + break; + } + default: + break; + } + i+=1; + if(i==this->size)i=0; + k+=1; + j++; + + //std/mean algorithm due to Knuth + count++; + delta = val - *mean; + *mean = *mean + delta/count; + M2 = M2 + delta*(val - *mean); // This expression uses the new value of mean + } + if(count < 1) + { + return -1; + } + else if(count == 1) + { + *std = 0; + } + else + { + *std = M2/(count - 1); + *std = sqrt(*std); + } + return 0; +} + +int init_kalman(double sigmav, double sigmaw, double P) +{ + long idx; + T *data_ptr = &data[0]; + + this->sigmav = sigmav; + this->sigmaw = sigmaw; + this->P = P; //initial error covariance + + //initial predicted state + if(this->counter != 0) + { + idx = (this->idx-1+this->size)%this->size; + switch(this->type) + { + case typeChar: + this->x_ = ((char*)data_ptr)[idx]; + break; + case typeShort: + this->x_ = ((short*)data_ptr)[idx]; + break; + case typeLong: + this->x_ = ((int32_t*)data_ptr)[idx]; + break; + case typeFloat: + this->x_ = ((float*)data_ptr)[idx]; + break; + case typeDouble: + this->x_ = ((double*)data_ptr)[idx]; + break; + case typeLongLong: + this->x_ = ((int64_t*)data_ptr)[idx]; + break; + default: + break; + } + } + else + { + this->x_ = 0; + } + return 0; +} + +int read_kalman(double *data_buf, unsigned int num_samples) +{ + unsigned long num; + long idx[2]; + unsigned int i; + long ind; + T *data_ptr = this->data; + double Q,R; + double S; + double K; + + Q = this->sigmav * this->sigmav; + R = this->sigmaw * this->sigmaw; + num = get_last_idx(num_samples, 0, idx); + PRINT("read_kalman entering: Q=%f R=%f P=%.11e num_samples=%ld x_=%f\n", Q, R, this->P, num, this->x_); + if(num > 0) + { + ind = idx[0]; + for(i=0; i<num; i++) + { + this->P = this->P + Q; //Prediction of the plant covariance + S = this->P + R; //Innovation Covariance + K = this->P/S; //Kalman's gain + + switch(this->type) + { + case typeChar: + this->z = ((char*)data_ptr)[ind]; + break; + case typeShort: + this->z = ((short*)data_ptr)[ind]; + break; + case typeLong: + this->z = ((int32_t*)data_ptr)[ind]; + break; + case typeFloat: + this->z = ((float*)data_ptr)[ind]; + break; + case typeDouble: + this->z = ((double*)data_ptr)[ind]; + break; + case typeLongLong: + this->z = ((int64_t*)data_ptr)[ind]; + break; + default: + break; + } + this->x_ = this->x_ + K * (this->z - this->x_); + this->P = (1 - K) * this->P; + ind = ((ind + 1) % this->size); + PRINT("read_kalman filtering: P=%.13e K=%.11e i=%d/%ld index=%ld | z=%f x_=%.20f\n", this->P,K, i, num, ind, this->z, this->x_); + } + } + else + return -1; + + *data_buf = this->x_; + return 0; +} + +/*************************************** + * read last data, last timestamp * + * and last bunch number * + * return -1 on error, 0 if OK * + ***************************************/ +int read_last(void *dat, struct timeval *timestamp, uint32_t *bunchnumber) +{ + long idx; + T *data_ptr = &data[0]; + struct timeval *time_ptr = (struct timeval *)&time[0]; + uint32_t *bunchnr_ptr = (uint32_t *)&bunchnr[0]; + if(this->counter != 0) + { + PRINT("read_last this->counter=%ld\n",this->counter); + idx = (this->idx-1+this->size)%this->size; + switch(this->type) + { + case typeChar: + memcpy(&((char*)dat)[0], &((char*)data_ptr)[idx], 1 * sizeof(char)); + break; + case typeShort: + memcpy(&((short*)dat)[0], &((short*)data_ptr)[idx], 1 * sizeof(short)); + break; + case typeLong: + memcpy(&((int32_t*)dat)[0], &((int32_t*)data_ptr)[idx], 1 * sizeof(int32_t)); + break; + case typeFloat: + memcpy(&((float*)dat)[0], &((float*)data_ptr)[idx], 1 * sizeof(float)); + break; + case typeDouble: + memcpy(&((double*)dat)[0], &((double*)data_ptr)[idx], 1 * sizeof(double)); + //PRINT("read_last: copying %f in %f\n", ((double*)data_ptr)[idx], *(double*)dat); + break; + case typeLongLong: + memcpy(&((int64_t*)dat)[0], &((int64_t*)data_ptr)[idx], 1 * sizeof(int64_t)); + break; + default: + break; + } + *bunchnumber = bunchnr_ptr[idx]; + *timestamp = time_ptr[idx]; + } + else + { + return -1; + } + return 0; +} + + +/*********************************** + * search pop time indexes + ***********************************/ +unsigned long get_time_idx(struct timeval tval_start, struct timeval tval_end, unsigned char unique, long idx[2]) +{ + long ini; + long fin; + unsigned long result; + unsigned long count; + int k=0,i; + uint32_t last_bunchnr=-1; + long tmp_idx = this->idx; + + struct timeval *time_ptr = (struct timeval *)this->time; + uint32_t *bunchnr_ptr = (uint32_t *)this->bunchnr; + + if(this->counter <= this->size) + { + ini = (tmp_idx - this->counter+this->size)%this->size; //TODO: ini = 0; ? + fin =(tmp_idx-1+this->size)%this->size; + } + else + { + ini = tmp_idx; + fin =(tmp_idx-1+this->size)%this->size; + } + idx[0] = -1; + idx[1] = -1; + PRINT("this->idx: %li, this->counter: %li, this->size: %li\n", tmp_idx, this->counter, this->size); + PRINT("ini: %li\n", ini); + PRINT("fin: %li\n", fin); + + if((tval_start.tv_sec > tval_end.tv_sec)||((tval_start.tv_sec == tval_end.tv_sec)&&(tval_start.tv_usec > tval_end.tv_usec))){//reverse order + //idx[0] = this->idx; + //idx[1] = this->idx; + idx[0] = -1; + idx[1] = -1; + + PRINT("reverse order: lower = %d, upper = %d\n", (int)tval_start.tv_sec, (int)tval_end.tv_sec); + return 0; + + } + else if((tval_start.tv_sec == tval_end.tv_sec)&&(tval_start.tv_usec == tval_end.tv_usec)){// one sample, one search + long ind = -1; + ind = search_time(tval_start, ini, fin); + + PRINT("one sample: tval_start, ini, fin: %d, %li, %li\n", (int)tval_start.tv_sec, ini, fin); + + if(ind!=-1){ + idx[0] = ind; + idx[1] = ind; + + PRINT("found idx[0] = %li, idx[1] = %li, ind = %li\n", idx[0], idx[1], ind); + if(idx[1] == ini) //if returned first index + { + if(tv_compare(time_ptr[ini],tval_end) > 0) //and if tval_end is older than the first present in buffer + { + idx[0] = -1; // -> not found + idx[1] = -1; // -> not found + return 0; + } + } + + } + else + { + PRINT("not found \n"); + return 0; + } + + } + else{// more samples + long ind = -1; + + PRINT("right order: tval_start.sec, tval_end.sec, ini, fin: %d, %d, %li, %li\n", (int)tval_start.tv_sec, (int)tval_end.tv_sec, ini, fin); + PRINT("right order: lower = %d, upper = %d\n", (int)tval_start.tv_sec, (int)tval_end.tv_sec); + + ind = search_time(tval_start, ini, fin); + if(ind!=-1){ + idx[0] = ind; + + PRINT("found idx[0] = %li\n", idx[0]); + ini = ind; + } + else + PRINT("not found tval_start\n"); + + ind = -1; + ind = search_time(tval_end, ini, fin); + if(ind!=-1){ + idx[1] = ind; + + PRINT("found idx[1] = %li\n", idx[1]); + + } + + else + PRINT("not found tval_end\n"); + + if(idx[1] == ini && idx[1] == idx[0]) //if tval_end and tval_start returned first index + { + if(tv_compare(time_ptr[ini],tval_end) > 0) //and if tval_end is older than the first present in buffer + { + idx[0] = -1; // -> not found + idx[1] = -1; // -> not found + return 0; + } + } + + } + if(idx[1] > idx[0]) + count = idx[1] - idx[0]; + else if(idx[1] < idx[0]) + count = this->size - idx[0] + idx[1]; + else + count = 0; + result = count+1; + + if(unique==1) + { + count = 0; + i=idx[0]; + while(k<result) + { + if(last_bunchnr != bunchnr_ptr[i]) + { + last_bunchnr = bunchnr_ptr[i]; + count++; + } + i+=1; + if(i==this->size)i=0; + k++; + } + result = count; + } + return result; +}; + +/*********************************** + * search pop bunch indexes + ***********************************/ +unsigned long get_bunch_idx(uint32_t bunch_start, uint32_t bunch_end, unsigned char unique, long idx[2]) +{ + long ini,fin; + unsigned long result,count; + int k=0,i; + uint32_t last_bunchnr=-1; + long tmp_idx = this->idx; + uint32_t *bunchnr_ptr = (uint32_t *)&bunchnr[0]; + + if(this->counter <= this->size) + { + ini = (tmp_idx - this->counter+this->size)%this->size; //TODO: ini = 0; ? + fin =(tmp_idx-1+this->size)%this->size; + } + else + { + ini = tmp_idx; + fin =(tmp_idx-1+this->size)%this->size; + } + idx[0] = -1; + idx[1] = -1; + //PRINT("buffer=0x%lx\n", (unsigned long)buffer); //TEMP!! + PRINT("this->idx: %li, this->counter: %li, this->size: %li\n", tmp_idx, this->counter, this->size); + PRINT("ini: %li\n", ini); + PRINT("fin: %li\n", fin); + + if(bunch_start > bunch_end) + {//reverse order + //idx[0] = this->idx; + //idx[1] = this->idx; + idx[0] = -1; + idx[1] = -1; + + PRINT("reverse order: lower = %li, upper = %li\n", bunch_start, bunch_end); + return 0; + } + else if(bunch_start == bunch_end) + {// one sample, one search + long ind = -1; + ind = search_limit(bunch_start, ini, fin, unique); + + PRINT("one sample: bunch_start, ini, fin: %li, %li, %li\n", bunch_start, ini, fin); + idx[0] = ind; + idx[1] = ind; + if(ind!=-1) + { + PRINT("found idx[0] = %li, idx[1] = %li, ind = %li\n", idx[0], idx[1], ind); + if((bunchnr_ptr[ini] > bunch_end) && (unique != 2)) //and if bunch_end is older than the first present in buffer + { + idx[0] = -1; // -> not found + idx[1] = -1; // -> not found + return 0; + } + } + else + { + PRINT("not found \n"); + } + if((idx[0] == -1) || (idx[1] == -1)) + return 0; + + } + else + {// more samples + long ind = -1; + + PRINT("right order: bunch_start, bunch_end, ini, fin: %li, %li, %li, %li\n", bunch_start, bunch_end, ini, fin); + PRINT("right order: lower = %li, upper = %li\n", bunch_start, bunch_end); + + ind = search_limit(bunch_start, ini, fin, unique); + idx[0] = ind; + if(ind!=-1){ + + PRINT("found idx[0] = %li\n", idx[0]); + ini = ind; + } + else + { + PRINT("not found bunch_start\n"); + } + + ind = search_limit(bunch_end, ini, fin, unique); + idx[1] = ind; + if(ind!=-1){ + PRINT("found idx[1] = %li\n", idx[1]); + } + else + { + PRINT("not found bunch_end\n"); + } + + if(idx[1] == ini && idx[1] == idx[0]) //if bunch_end and bunch_start returned first index + { + if((bunchnr_ptr[ini] > bunch_end) && (unique != 2)) //and if bunch_end is older than the first present in buffer + { + idx[0] = -1; // -> not found + idx[1] = -1; // -> not found + return 0; + } + } + if((idx[0] == -1) || (idx[1] == -1)) + return 0; + + } + if(idx[1] > idx[0]) + count = idx[1] - idx[0]; + else if(idx[1] < idx[0]) + count = this->size - idx[0] + idx[1]; + else + count = 0; + result = count+1; + + if(unique==1) + { + count = 0; + i=idx[0]; + while(k<result) + { + if(last_bunchnr != bunchnr_ptr[i]) + { + last_bunchnr = bunchnr_ptr[i]; + count++; + } + i+=1; + if(i==this->size)i=0; + k++; + } + result = count; + } + return result; +}; + +/*********************************** + * search pop last indexes + ***********************************/ +unsigned long get_last_idx(unsigned long last_samples, unsigned char unique, long idx[2]) +{ + unsigned long result; + int k=0,i,j=0,z; + uint32_t last_bunchnr=-1; + long tmp_idx = this->idx; + uint32_t *bunchnr_ptr = (uint32_t *)&bunchnr[0]; + PRINT("requested %li values, pushed %li values, size=%li\n",last_samples, this->counter, this->size); + PRINT("type=%d idx=%li mode=%li fill_hole=%li\n",this->type, tmp_idx,this->mode,this->fill_hole); + //PRINT("buff=0x%lx data=0x%lx time=0x%lx bunchnr=0x%lx\n",(unsigned long)buffer, (unsigned long)this->data,(unsigned long)this->time,(unsigned long)this->bunchnr); + + if(last_samples > this->size) + last_samples = this->size; + if(last_samples > this->counter) + last_samples = this->counter; + if(this->counter != 0) + { + if(unique!=1) + { + idx[1] = (tmp_idx-1+this->size)%this->size; + idx[0] = (tmp_idx - last_samples + this->size)%this->size; + } + else + { + i = tmp_idx; + //look for the first value with this bunchnumber + do + { + i = (i-1+this->size)%this->size; + j = (i-1+this->size)%this->size; + k++; + if(k>this->counter) + { + idx[1]=i; + idx[0]=i; + return 1; + } + } + while(bunchnr_ptr[i] == bunchnr_ptr[j]); + + idx[1] = i; + last_bunchnr = bunchnr_ptr[i]; + j=1; + k=1; + //go back of last_samples bunch numbers + while(k<last_samples) + { + j++; + if(j > this->counter) + break; + i = (i-1+this->size)%this->size; + if(last_bunchnr != bunchnr_ptr[i]) + { + last_bunchnr = bunchnr_ptr[i]; + k++; + } + } + z = j; + //look for the first value with this bunchnumber + j = (i-1+this->size)%this->size; + while(bunchnr_ptr[i] == bunchnr_ptr[j]) + { + i = (i-1+this->size)%this->size; + j = (i-1+this->size)%this->size; + z++; + if(z>this->counter) + { + idx[1]=i; + idx[0]=i; + return 1; + } + } + idx[0] = i; + return k; + } + } + else + { + idx[0] = -1; + idx[1] = -1; + return 0; + } + if(idx[1] > idx[0]) + result = idx[1] - idx[0]; + else if(idx[1] < idx[0]) + result = this->size - idx[0] + idx[1]; + else + result = 0; + return result+1; +}; + +/*********************************** + * set method for mode + ***********************************/ +int set_mode(unsigned long mod) +{ + switch(mod){ + case BUF_RT_LINEAR: //buffer not circular + case BUF_RT_CIRCULAR: //buffer circular + this->mode = mod; + return 0; + break; + default: //unexpected value + PRINT("value not allowed\n"); + return -1; + break; + } +}; + +/*********************************** + * get method for mode + ***********************************/ +ulong get_mode() +{ + return this->mode; +}; + +/*********************************** + * get method for size + ***********************************/ +long get_size() +{ + return this->size; +}; + +/*********************************** + * get data size + ***********************************/ +long get_data_size() +{ + return get_data_size(identity<T>()); +}; +private: +template<typename TL> +long get_data_size(identity<TL>) +{ + return (size > 0) ? 1 : 0; +} +template<typename TL> +long get_data_size(identity<_data_array<TL> >) +{ + return (size > 0) ? data[0].get_count() : 0; +} + +public: + +/*********************************** + * set method for fill_hole + ***********************************/ +int set_fill_hole(unsigned long fill){ + + switch(fill){ + case BUF_RT_NO_FILL: // 0 = no fill + case BUF_RT_FILL_1: // 1 = fill with 0xffffffff or NaN + case BUF_RT_FILL_PREV: // 2 = fill with previous value inside the buffer + case BUF_RT_FILL_0: // 3 = fill with 0 + this->fill_hole = fill; + return 0; + break; + default: //unexpected value + + PRINT("value not allowed\n"); + + return -1; + break; + } +}; + +/*********************************** + * get method for fill_hole + ***********************************/ +ulong get_fill_hole(){ + return this->fill_hole; +}; + +/*********************************** + * get method for type + ***********************************/ +/*type_t get_type() +{ + switch(this->type) + { + case typeChar: + PRINT("type is char: %d\n",this->type); + break; + case typeShort: + PRINT("type is short: %d\n",this->type); + break; + case typeLong: + PRINT("type is long: %d\n",this->type); + break; + case typeFloat: + PRINT("type is float: %d\n",this->type); + break; + case typeDouble: + PRINT("type is double: %d\n",this->type); + break; + case typeLongLong: + PRINT("type is long long: %d\n",this->type); + break; + default: + break; + } + return this->type; +};*/ + +/*********************************** + * search method + ***********************************/ +long search_limit(uint32_t nr, long lower, long upper, unsigned char unique) +{ + int found = -1; + long ini = lower; + long fin = upper; + long med = (ini+((fin-ini+this->size)%this->size)/2)%this->size; + long result = med; + int counter = 0; + + uint32_t *bunchnr_ptr = (uint32_t *)this->bunchnr; + + PRINT("searching from ini = %li, to fin = %li\n", ini, fin); + if((ini==fin) && (bunchnr_ptr[ini] != nr)) + { + if(unique != 2) + return -1; + else + return ini; + } + while(found<0) + { + if(bunchnr_ptr[med] == nr) + { //equals + found = 0; + while(bunchnr_ptr[(med-1+this->size)%this->size]==nr && med >= lower) + { + med = (med-1+this->size)%this->size; + PRINT("changing med to %li\n", med); + } + PRINT("found med=%li, bunchnr[med]=%li, med-1=%li, bunchnr[med-1]=%li\n", med, bunchnr_ptr[med], (med-1+this->size)%this->size, bunchnr_ptr[(med-1+this->size)%this->size]); + result = med; + } + else + { + if(((fin-ini+this->size)%this->size)==1) + { + //PRINT("in step=1: ini=%li, fin=%li bunchnr[ini]=%li bunchnr[fin]=%li\n", ini, fin ,bunchnr_ptr[ini], bunchnr_ptr[fin]); + //step == 1, last test + if(bunchnr_ptr[ini]==nr) + { + found = 0; + while(bunchnr_ptr[(ini-1+this->size)%this->size]==nr && ini >= lower) + { + ini = (ini-1+this->size)%this->size; + PRINT("changing ini to %li\n", ini); + } + PRINT("found ini=%li, bunchnr[ini]=%li, ini-1=%li, bunchnr[ini-1]=%li\n", ini, bunchnr_ptr[ini], (ini-1+this->size)%this->size, bunchnr_ptr[(ini-1+this->size)%this->size]); + result = ini; + } + else if(bunchnr_ptr[ini]>nr) + { + found = 0; + if(unique != 2) + result = -1; + else + result = ini; + } + else if(bunchnr_ptr[fin]==nr) + { + found = 0; + while(bunchnr_ptr[(fin-1+this->size)%this->size]==nr && fin >= lower) + { + fin = (fin-1+this->size)%this->size; + PRINT("changing fin to %li\n", fin); + } + PRINT("found fin=%li, bunchnr[fin]=%li, fin-1=%li, bunchnr[fin-1]=%li\n", fin, bunchnr_ptr[fin], (fin-1+this->size)%this->size, bunchnr_ptr[(fin-1+this->size)%this->size]); + result = fin; + } + else if(bunchnr_ptr[fin]<nr) + { + found = 0; + if(unique != 2) + result = -1; + else + result = fin; + } + //between ini and fin, but step == 1, hole? + else + { + found = 0; + //result = ini; + if(unique != 2) + result = -1; + else + result = ini; + } + break; + } + med = (ini+((fin-ini+this->size)%this->size)/2)%this->size; + if(bunchnr_ptr[med] < nr) + { //lower + ini = med/*%this->size*/; + //PRINT("adjusted ini: ini=%li, fin=%li bunchnr[ini]=%li\n", ini, fin, bunchnr_ptr[ini]); + } + else + { //greater + fin = med/*%this->size*/; + //PRINT("adjusted fin: ini=%li, fin=%li bunchnr[fin]=%li\n", ini, fin, bunchnr_ptr[fin]); + } + } + counter+=1; + } + + PRINT("Result: idx=%li bunchnr[idx]=%li bunchnr[lower]=%li bunchnr[upper]=%li\n", result, (result != -1) ? bunchnr_ptr[result] : -1, bunchnr_ptr[lower], bunchnr_ptr[upper]); + + return result; +}; + +int tv_compare(struct timeval ts1, struct timeval ts2) +{ + if(ts1.tv_sec < ts2.tv_sec) + return - 1; + else if(ts1.tv_sec == ts2.tv_sec) + { + if(ts1.tv_usec < ts2.tv_usec) + return -1; + if(ts1.tv_usec == ts2.tv_usec) + return 0; + else + return 1; + } + else + return 1; + +} + +long search_time(struct timeval p, long lower, long upper) +{ + int found = -2; + long ini = lower; + long fin = upper; + long med = (ini+((fin-ini+this->size)%this->size)/2)%this->size; + long result = med; +// long reslow = med; +// long reshi = med; + int counter = 0; +// int counter2 = 0; + + struct timeval *time_ptr = (struct timeval *)this->time; + + + PRINT("searching from ini = %li, to fin = %li\n", ini, fin); +#if 0 + while(found<0){ + if(time_ptr[med].tv_sec == p.tv_sec){ //equals + found +=1; + reslow = med; + reshi = med; + while(time_ptr[reslow].tv_sec == p.tv_sec){ + reslow=(reslow-1+this->size)%this->size; + } + while(time_ptr[reshi].tv_sec == p.tv_sec){ + reshi = (reshi+1)%this->size; + } + reslow = (reslow+1)%this->size; + reshi = (reshi-1+this->size)%this->size; + } + else{ + if(((fin-ini+this->size)%this->size)==1) + { + if(time_ptr[fin].tv_sec!=p.tv_sec){ + found +=1; + reslow = ini; + } + else{ + found +=1; + reshi = fin; + } + } + med = (ini+((fin-ini+this->size)%this->size)/2)%this->size; + if(time_ptr[med].tv_sec < p.tv_sec){ //lower + ini = med/*%this->size*/; + } + else{ //greater + fin = med/*%this->size*/; + } + } + counter+=1; + } + + PRINT("reslow %li reshi %li\n", reslow, reshi); + + + //finding usec + found = -1; + + PRINT("searching from reslow = %li, to reshi = %li\n", reslow, reshi); + + med = reslow+((reshi-reslow+this->size)%this->size)/2; + result = med; + while(found<0){ + if(time_ptr[med].tv_usec == p.tv_usec){ //equals + found = 0; + while(time_ptr[med].tv_usec == p.tv_usec){ + med=(med-1+this->size)%this->size; + } + result =(med+1)%this->size; + } + else{ + if(((reshi-reslow+this->size)%this->size)==1) + { + if(time_ptr[reshi].tv_usec!=p.tv_usec){ + found = 0; + result = reslow; + } + else{ + found = 0; + result = reshi; + } + } + med = reslow+((reshi-reslow+this->size)%this->size)/2; + if(time_ptr[med].tv_usec < p.tv_usec){ //lower + reslow = med%this->size; + } + else{ //greater + reshi = med%this->size; + } + } + counter2+=1; + } +#else + if((ini==fin) && (tv_compare(time_ptr[ini],p)!=0)) + return -1; + while(found<0){ + if(tv_compare(time_ptr[med],p)==0){ //equals + found = 0; + result = med; + } + else{ + if(((fin-ini+this->size)%this->size)==1) + { + //step == 1, last test + if(tv_compare(time_ptr[ini],p)>=0){ //equal to p, or p lower than the min + found = 0; + result = ini; + } + else if(tv_compare(time_ptr[fin],p)<=0){ //equal to p, or p greater than the max + found = 0; + result = fin; + } + //between ini and fin, but step == 1 + else{ + found = 0; + result = ini; + } + break; + } + med = (ini+((fin-ini+this->size)%this->size)/2)%this->size; + if(tv_compare(time_ptr[med],p)<0){ //lower + ini = med/*%this->size*/; + } + else{ //greater + fin = med/*%this->size*/; + } + } + counter+=1; + } +#endif + PRINT("Searched %d.%d, result %li time[lower]=%d.%d time[upper]=%d.%d\n", (int)p.tv_sec, (int)p.tv_usec, result, (int)time_ptr[lower].tv_sec, (int)time_ptr[lower].tv_usec, (int)time_ptr[upper].tv_sec, (int)time_ptr[upper].tv_usec); + + + return result; + +}; + +}; +} //namespace tbuffer + +#endif //__TBUFFER_H diff --git a/src/tcheck_get_rt_buffer.hpp b/src/tcheck_get_rt_buffer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cafb15be3a0a9a61d0d4f72cc579793ee567624d --- /dev/null +++ b/src/tcheck_get_rt_buffer.hpp @@ -0,0 +1,391 @@ +//============================================================================= +// +// file : tcheck_get_rt_buffer.hpp +// +// description : Include with utility to read rt buffers. +// +// project : RT BUFFER +// +// $Author: graziano $ +// +// $Revision: 1.1 $ +// +// $Log: tcheck_get_rt_buffer.hpp,v $ +// Revision 1.1 2015-09-08 09:00:52 graziano +// upgraded to template buffer +// +// +// +// +// copyleft : Sincrotrone Trieste S.C.p.A. +// Strada Statale 14 - km 163,5 in AREA Science Park +// 34012 Basovizza (TS) +// ITALY +// +//============================================================================= +#ifndef _T_CHECK_GET_RT_BUFFER_H +#define _T_CHECK_GET_RT_BUFFER_H + +#include <tango.h> +#include <tbuffer.hpp> + +namespace tbuffer +{ + +//+------------------------------------------------------------------ +/** + * method: check_get_data_param + * + * description: get data indexes + * + * @param[in] buffer search params + * @param[in] rt buffer + * @param[out] buffer indexes + * @param[out] num samples between indexes + * @param[in] unique + * @return + * + */ +//+------------------------------------------------------------------ +template <typename T> void tcheck_get_data_param(const Tango::DevVarLongArray *argin, buffer_t<T> *tbuf, long *buf_idx, long *data_size, unsigned char *unique) +{ + long nargin = argin->length(); + long ret_num_samples; + //struct _buffer *locbuf; + long mode = (*argin)[0]; + + if ((*argin)[0] <= BUF_GET_TIME_MODE) + *unique = 0; + else if((*argin)[0] <= BUF_GET_TIME_UNIQUE_MODE) + *unique = 1; + else + *unique = 2; + /* non unique modes (0,1,2); unique modes (3,4,5); bunch modes (6,7,8) */ + mode = mode - (*unique) * 3; + + /* get last values */ + if (nargin == 2) + { + long num_samples = (*argin)[1]; + + if ((num_samples < 0) || (num_samples > tbuf->get_size())) + { + Tango::Except::throw_exception ( + (const char *)"Invalid number of data requested", + (const char *)"Failed to retreive last data", + (const char *)__FUNCTION__); + } + + if (mode == BUF_GET_LAST_MODE) + { + ret_num_samples = tbuf->get_last_idx(num_samples, *unique, buf_idx); + } + else + { + Tango::Except::throw_exception ( + (const char *)"Wrong get mode parameter (0,1,2)", + (const char *)"Failed to retreive last data", + (const char *)__FUNCTION__); + } + + if (ret_num_samples != num_samples && (*unique != 2)) + { + stringstream tmp; + tmp << " Can't retreive all data requested: requested="<<num_samples << " received="<<ret_num_samples; + //DEBUG_STREAM << __FUNCTION__ << tmp.str(); + Tango::Except::throw_exception ( + (const char *)"Can't retreive all data requested", + tmp.str(), + (const char *)__FUNCTION__); + } + else if (ret_num_samples == 0) + { + stringstream tmp; + tmp << " Can't retreive all data requested: requested="<<num_samples << " but buffer empty!"; + //DEBUG_STREAM << __FUNCTION__ << tmp.str(); + Tango::Except::throw_exception ( + (const char *)"Can't retreive all data requested", + tmp.str(), + (const char *)__FUNCTION__); + } + *data_size = ret_num_samples; + if(*unique == 2) + *data_size *= 2; //concatenate bunchnumbers + } + /* get bunch mode values */ + else if (nargin == 3) + { + long bunch_start = (*argin)[1], bunch_end = (*argin)[2]; + + if (((bunch_end-bunch_start) < 0) || ((bunch_end-bunch_start) > tbuf->get_size())) + { + stringstream out_stream; + out_stream << "Invalid bunch numbers: bunch start=" << bunch_start << ", bunch end=" << bunch_end << ends; + //DEBUG_STREAM << __FUNCTION__ << out_stream.str(); + Tango::Except::throw_exception ( + out_stream.str(), + (const char *)"Failed to retreive bunch data", + (const char *)__FUNCTION__); + } + + if (mode == BUF_GET_BUNCH_MODE) + { + ret_num_samples = tbuf->get_bunch_idx(bunch_start, bunch_end, *unique, buf_idx); + } + else + { + stringstream out_stream; + out_stream << "Invalid mode=" << mode << ends; + //DEBUG_STREAM << __FUNCTION__ << out_stream.str(); + Tango::Except::throw_exception ( + out_stream.str(), + (const char *)"Failed to retrive bunch data", + (const char *)__FUNCTION__); + } + + /* check data size */ + if ((((ret_num_samples-1) != (bunch_end-bunch_start)) && (*unique ==1)) || + (((ret_num_samples-1) < (bunch_end-bunch_start)) && (*unique == 0))) + { + stringstream out_stream; + out_stream << "Invalid bunch numbers: bunch start=" << bunch_start << ", bunch end=" << bunch_end << ", ret_num_samples=" << + (ret_num_samples-1) << ends; + //DEBUG_STREAM << __FUNCTION__ << out_stream.str(); + Tango::Except::throw_exception ( + (const char *)"Failed to retreive bunch data", + out_stream.str(), + (const char *)__FUNCTION__); + } + else if(ret_num_samples == 0) + { + stringstream out_stream; + out_stream << "Invalid bunch numbers."; + if(buf_idx[0] == -1) + out_stream<< " Bunch start=" << bunch_start << " not valid."; + if(buf_idx[1] == -1) + out_stream<< " Bunch end=" << bunch_end << " not valid."; + out_stream << ends; + //DEBUG_STREAM << __FUNCTION__ << out_stream.str(); + Tango::Except::throw_exception ( + (const char *)"Failed to retreive bunch data", + out_stream.str(), + (const char *)__FUNCTION__); + } + *data_size = ret_num_samples; + if(*unique == 2) + *data_size *= 2; //concatenate bunchnumbers + } + /* get time mode values */ + else if (nargin == 5) + { + struct timeval time_start, time_end; + + time_start.tv_sec = (*argin)[1]; time_start.tv_usec = (*argin)[2]; + time_end.tv_sec = (*argin)[3]; time_end.tv_usec = (*argin)[4]; + + if (((time_end.tv_sec-time_start.tv_sec)*1000000+(time_end.tv_usec-time_start.tv_usec)) < 0) + { + Tango::Except::throw_exception ( + (const char *)"Invalid time slice requested", + (const char *)"Failed to retreive timed data", + (const char *)__FUNCTION__); + } + + if (mode == BUF_GET_TIME_MODE) + { + ret_num_samples = tbuf->get_time_idx(time_start, time_end, *unique, buf_idx); + } + else + { + Tango::Except::throw_exception ( + (const char *)"Wrong get mode parameter (0,1,2)", + (const char *)"Failed to retreive timed data", + (const char *)__FUNCTION__); + } + *data_size = ret_num_samples; + if(*unique == 2) + *data_size *= 2; //concatenate bunchnumbers + } + /* invalid number of input parameters */ + else + { + Tango::Except::throw_exception ( + (const char *)"Invalid number of input parameters", + (const char *)"Failed to get data", + (const char *)__FUNCTION__); + } + +} + +template <typename T> void tcheck_get_data_param(const Tango::DevVarLongArray *argin, buffer_t<tbuffer::_data_array<T> > *tbuf, long *buf_idx, long *data_size, unsigned char *unique) +{ + long nargin = argin->length(); + long ret_num_samples; + //struct _buffer *locbuf; + long mode = (*argin)[0]; + + if ((*argin)[0] <= BUF_GET_TIME_MODE) + *unique = 0; + else if((*argin)[0] <= BUF_GET_TIME_UNIQUE_MODE) + *unique = 1; + else + *unique = 2; + /* non unique modes (0,1,2); unique modes (3,4,5); bunch modes (6,7,8) */ + mode = mode - (*unique) * 3; + + /* get last values */ + if (nargin == 2) + { + long num_samples = (*argin)[1]; + + if ((num_samples < 0) || (num_samples > tbuf->get_size())) + { + Tango::Except::throw_exception ( + (const char *)"Invalid number of data requested", + (const char *)"Failed to retreive last data", + (const char *)__FUNCTION__); + } + + if (mode == BUF_GET_LAST_MODE) + { + ret_num_samples = tbuf->get_last_idx(num_samples, *unique, buf_idx); + } + else + { + Tango::Except::throw_exception ( + (const char *)"Wrong get mode parameter (0,1,2)", + (const char *)"Failed to retreive last data", + (const char *)__FUNCTION__); + } + + if (ret_num_samples != num_samples && (*unique != 2)) + { + stringstream tmp; + tmp << " Can't retreive all data requested: requested="<<num_samples << " received="<<ret_num_samples; + //DEBUG_STREAM << __FUNCTION__ << tmp.str(); + Tango::Except::throw_exception ( + (const char *)"Can't retreive all data requested", + tmp.str(), + (const char *)__FUNCTION__); + } + else if (ret_num_samples == 0) + { + stringstream tmp; + tmp << " Can't retreive all data requested: requested="<<num_samples << " but buffer empty!"; + //DEBUG_STREAM << __FUNCTION__ << tmp.str(); + Tango::Except::throw_exception ( + (const char *)"Can't retreive all data requested", + tmp.str(), + (const char *)__FUNCTION__); + } + *data_size = ret_num_samples; + if(*unique == 2) + *data_size *= 2; //concatenate bunchnumbers + } + /* get bunch mode values */ + else if (nargin == 3) + { + long bunch_start = (*argin)[1], bunch_end = (*argin)[2]; + + if (((bunch_end-bunch_start) < 0) || ((bunch_end-bunch_start) > tbuf->get_size())) + { + stringstream out_stream; + out_stream << "Invalid bunch numbers: bunch start=" << bunch_start << ", bunch end=" << bunch_end << ends; + //DEBUG_STREAM << __FUNCTION__ << out_stream.str(); + Tango::Except::throw_exception ( + out_stream.str(), + (const char *)"Failed to retreive bunch data", + (const char *)__FUNCTION__); + } + + if (mode == BUF_GET_BUNCH_MODE) + { + ret_num_samples = tbuf->get_bunch_idx(bunch_start, bunch_end, *unique, buf_idx); + } + else + { + stringstream out_stream; + out_stream << "Invalid mode=" << mode << ends; + //DEBUG_STREAM << __FUNCTION__ << out_stream.str(); + Tango::Except::throw_exception ( + out_stream.str(), + (const char *)"Failed to retrive bunch data", + (const char *)__FUNCTION__); + } + + /* check data size */ + if ((((ret_num_samples-1) != (bunch_end-bunch_start)) && (*unique ==1)) || + (((ret_num_samples-1) < (bunch_end-bunch_start)) && (*unique == 0))) + { + stringstream out_stream; + out_stream << "Invalid bunch numbers: bunch start=" << bunch_start << ", bunch end=" << bunch_end << ", ret_num_samples=" << + (ret_num_samples-1) << ends; + //DEBUG_STREAM << __FUNCTION__ << out_stream.str(); + Tango::Except::throw_exception ( + (const char *)"Failed to retreive bunch data", + out_stream.str(), + (const char *)__FUNCTION__); + } + else if(ret_num_samples == 0) + { + stringstream out_stream; + out_stream << "Invalid bunch numbers."; + if(buf_idx[0] == -1) + out_stream<< " Bunch start=" << bunch_start << " not valid."; + if(buf_idx[1] == -1) + out_stream<< " Bunch end=" << bunch_end << " not valid."; + out_stream << ends; + //DEBUG_STREAM << __FUNCTION__ << out_stream.str(); + Tango::Except::throw_exception ( + (const char *)"Failed to retreive bunch data", + out_stream.str(), + (const char *)__FUNCTION__); + } + *data_size = ret_num_samples; + if(*unique == 2) + *data_size *= 2; //concatenate bunchnumbers + } + /* get time mode values */ + else if (nargin == 5) + { + struct timeval time_start, time_end; + + time_start.tv_sec = (*argin)[1]; time_start.tv_usec = (*argin)[2]; + time_end.tv_sec = (*argin)[3]; time_end.tv_usec = (*argin)[4]; + + if (((time_end.tv_sec-time_start.tv_sec)*1000000+(time_end.tv_usec-time_start.tv_usec)) < 0) + { + Tango::Except::throw_exception ( + (const char *)"Invalid time slice requested", + (const char *)"Failed to retreive timed data", + (const char *)__FUNCTION__); + } + + if (mode == BUF_GET_TIME_MODE) + { + ret_num_samples = tbuf->get_time_idx(time_start, time_end, *unique, buf_idx); + } + else + { + Tango::Except::throw_exception ( + (const char *)"Wrong get mode parameter (0,1,2)", + (const char *)"Failed to retreive timed data", + (const char *)__FUNCTION__); + } + *data_size = ret_num_samples; + if(*unique == 2) + *data_size *= 2; //concatenate bunchnumbers + } + /* invalid number of input parameters */ + else + { + Tango::Except::throw_exception ( + (const char *)"Invalid number of input parameters", + (const char *)"Failed to get data", + (const char *)__FUNCTION__); + } + +} + +}//namespace +#endif //_T_CHECK_GET_RT_BUFFER_H