12 files + 471 − 399 Inline Compare changes Side-by-side Inline Show whitespace changes Files 12 conanfile.py +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps class AcquireWaveformLecroyRecipe(ConanFile): name = "acquirewaveformlecroy" executable = "ds_AcquireWaveformLecroy" version = "1.2.0" version = "1.2.1" package_type = "application" user = "soleil" Loading include/ChannelData.hpp +16 −14 Original line number Diff line number Diff line Loading @@ -56,6 +56,8 @@ public: //- operator= ChannelData& operator=(const ChannelData& src) { if(&src != this) { this->channel_name_ = src.channel_name_; this->trigger_time_ = src.trigger_time_; Loading @@ -69,7 +71,7 @@ public: this->wave_array_2_ = src.wave_array_2_; this->vertical_scaled_data_ = src.vertical_scaled_data_; this->raw_waveform_data_ = src.raw_waveform_data_; } return *this; } Loading include/SocketLecroy.h +13 −17 Original line number Diff line number Diff line Loading @@ -27,7 +27,6 @@ #include <winsock2.h> #endif #include "SocketException.h" #include <yat/threading/Mutex.h> //////////////////////////////////////////////////////////////////// // // SocketLecroy :: DEFINITION Loading @@ -45,7 +44,6 @@ typedef struct //- Constants definitions //----------------------------------------------- const int SERVER_PORT = 1861; //- It's the same port number for all Lecroy scope's. const int EOI_FLAG = 0x01; const int SRQ_FLAG = 0x08; const int CLEAR_FLAG = 0x10; Loading @@ -62,8 +60,6 @@ private: SocketLecroy(); //- just one instance of SocketLecroy must be done for all waveforms of a same Lecroy device ~SocketLecroy(); yat::Mutex lock_; static SocketLecroy* SL_instance; //- ptr on the SocketLecroy instance static bool sConnectedFlag; Loading @@ -79,11 +75,11 @@ public: void write_read (char* in_buf, unsigned int in_length, char* out_buf, int* out_length, bool eoi_flag); void TCP_WriteDevice (char *buf, int length,bool eoi_flag) throw (lecroy::SocketException); //- send a cmd to the device void TCP_ReadDevice (char *buf, unsigned int length, int* nb_byte_received) throw (lecroy::SocketException); //- read the device replie void TCP_Connect (char *ip_address) throw (lecroy::SocketException); //- build TCP/IP connection void TCP_Disconnect (void) throw (lecroy::SocketException); //- disconnect the device void TCP_ClearDevice (void) throw (lecroy::SocketException); //- disconnect and reconnect the device void TCP_WriteDevice (char *buf, int length,bool eoi_flag); //- send a cmd to the device void TCP_ReadDevice (char *buf, unsigned int length, int* nb_byte_received); //- read the device replie void TCP_Connect (char *ip_address); //- build TCP/IP connection void TCP_Disconnect (void); //- disconnect the device void TCP_ClearDevice (void); //- disconnect and reconnect the device }; Loading include/Waveform.h +6 −7 Original line number Diff line number Diff line Loading @@ -109,8 +109,7 @@ private: //- time info to acquire waveform data std::string time_to_get_waveformData; void get_waveform_data (ChannelData* channelData) throw (lecroy::WaveformException); //- acquire the waveform data from the scope void get_waveform_data (ChannelData* channelData); //- acquire the waveform data from the scope void get_trigger_time_value (ChannelData* channelData); Loading include/WaveformMgr.hpp +4 −4 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ public: protected: //- process_message (implements yat4tango::DeviceTask pure virtual method) virtual void process_message (yat::Message& msg) throw (Tango::DevFailed); virtual void process_message (yat::Message& msg); //- internal mutex yat::Mutex data_mutex_; Loading pom.xml +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ <groupId>fr.soleil.device</groupId> <artifactId>AcquireWaveformLecroy-${aol}-${mode}</artifactId> <version>1.2.0</version> <version>1.2.1</version> <packaging>nar</packaging> <name>AcquireWaveformLecroy</name> <description>AcquireWaveformLecroy device</description> Loading src/AcquireWaveformLecroy.cpp +58 −97 Original line number Diff line number Diff line Loading @@ -98,9 +98,11 @@ static const char *RcsId = "$Header: /users/chaize/newsvn/cvsroot/Instrumentatio // //=================================================================== #include <AcquireWaveformLecroy.h> #include <AcquireWaveformLecroyClass.h> // #include <AcquireWaveformLecroy.h> #include "AcquireWaveformLecroyClass.h" #include <yat/time/Timer.h> #include <yat4tango/DeviceInfo.h> #include <yat4tango/Logging.h> static const std::size_t MAX_STRING_LENGTH = 1024; Loading Loading @@ -199,14 +201,8 @@ void AcquireWaveformLecroy::delete_device() this->waveform_mgr_ = 0; } /*std::cout << "removing log" << std::endl; // DEBUG_STREAM << "Remove the InnerAppender." << endl; yat4tango::InnerAppender::release(this); // DEBUG_STREAM << "Remove the YatLogAdapter." << endl; yat4tango::YatLogAdapter::release(); std::cout << "removed log : " << log_deleted << std::endl;*/ yat4tango::DeviceInfo::release(this); yat4tango::Logging::release(this); } //+---------------------------------------------------------------------------- Loading Loading @@ -265,21 +261,8 @@ void AcquireWaveformLecroy::init_device() //--------------------------------------------------------- //- instanciate the log_adapter & inner_appender in order to manage logs //--------------------------------------------------------- // try // { // DEBUG_STREAM << "Create the YatLogAdapter in order to use logs from third party library." << endl; // yat4tango::YatLogAdapter::initialize(this); // // DEBUG_STREAM << "Create the InnerAppender in order to manage logs." << endl; // yat4tango::InnerAppender::initialize(this, 512); // } // catch (Tango::DevFailed& df) // { // ERROR_STREAM << df << endl; // set_state(Tango::FAULT); // set_status("OUT OF MEMORY : Failed to create log manager !"); // return; // } yat4tango::DeviceInfo::initialize( this, YAT_XSTR(PROJECT_NAME), YAT_XSTR(PROJECT_VERSION) ); yat4tango::Logging::initialize(this); char * ipAdd = 0; if (!waveform_mgr_) Loading @@ -288,7 +271,9 @@ void AcquireWaveformLecroy::init_device() std::size_t length = iPaddress.size(); ipAdd = new char[length+1]; for(std::size_t i=0; i<length; i++) { ipAdd[i] = iPaddress[i]; } ipAdd[length] = '\0'; //- create the waveform obj waveform_mgr_ = new WaveformMgr(this, ipAdd); Loading @@ -300,8 +285,10 @@ void AcquireWaveformLecroy::init_device() waveform_mgr_->add_channel(channelName); //- start thread (if not already started) if ( !waveform_mgr_->periodic_msg_enabled() ) { waveform_mgr_->go(); } } //- release temporary allocation if (ipAdd) { Loading Loading @@ -380,8 +367,10 @@ void AcquireWaveformLecroy::get_device_property() // End of Automatic code generation //------------------------------------------------------------------ if( !data_put.empty() ) { get_db_device()->put_property(data_put); } } //+---------------------------------------------------------------------------- // Loading Loading @@ -454,7 +443,7 @@ yat::Timer t; throw; } INFO_STREAM << "READ_HW : all data are now updated. DONE in " << t.elapsed_msec() << " milliseconds.\n" << std::endl; DEBUG_STREAM << "READ_HW : all data are now updated. DONE in " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -467,15 +456,11 @@ yat::Timer t; void AcquireWaveformLecroy::read_verticalScaledData(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_verticalScaledData(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; // for(std::size_t idx = 0; idx < data_length_; idx++) // attr_verticalScaledData_read[idx] = channel_data_->vertical_scaled_data_[idx]; // attr.set_value(attr_verticalScaledData_read, data_length_); if ( data_length_ ) { attr.set_value(&channel_data_->vertical_scaled_data_[0], data_length_); DEBUG_STREAM << "read_verticalScaledData : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } } //+---------------------------------------------------------------------------- Loading @@ -488,14 +473,11 @@ yat::Timer t; void AcquireWaveformLecroy::read_triggerTime(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_triggerTime(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; // Add your own code here std::string response = channel_data_->trigger_time_; strcpy(*attr_triggerTime_read, response.c_str()); ::strcpy(*attr_triggerTime_read, response.c_str()); attr.set_value(attr_triggerTime_read); DEBUG_STREAM << "read_triggerTime : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -508,13 +490,11 @@ yat::Timer t; void AcquireWaveformLecroy::read_verticalOffset(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_verticalOffset(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_verticalOffset_read = channel_data_->vertical_offset_; attr.set_value(attr_verticalOffset_read); DEBUG_STREAM << "read_verticalOffset : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -527,13 +507,10 @@ yat::Timer t; void AcquireWaveformLecroy::read_verticalGain(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_verticalGain(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_verticalGain_read = channel_data_->vertical_gain_; attr.set_value(attr_verticalGain_read); DEBUG_STREAM << "read_verticalGain : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -546,13 +523,10 @@ yat::Timer t; void AcquireWaveformLecroy::read_horizontalOffset(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_horizontalOffset(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_horizontalOffset_read = channel_data_->horizontal_offset_; attr.set_value(attr_horizontalOffset_read); DEBUG_STREAM << "read_horizontalOffset : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -565,13 +539,11 @@ void AcquireWaveformLecroy::read_horizontalOffset(Tango::Attribute &attr) void AcquireWaveformLecroy::read_horizontalInterval(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_horizontalInterval(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_horizontalInterval_read = channel_data_->horizontal_interval_; attr.set_value(attr_horizontalInterval_read); DEBUG_STREAM << "read_horizontalInterval : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -584,12 +556,10 @@ void AcquireWaveformLecroy::read_horizontalInterval(Tango::Attribute &attr) void AcquireWaveformLecroy::read_nominalBits(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_nominalBits(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_nominalBits_read = channel_data_->nominal_bits_; attr.set_value(attr_nominalBits_read); DEBUG_STREAM << "read_nominalBits : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -602,12 +572,10 @@ yat::Timer t; void AcquireWaveformLecroy::read_waveArrayCount(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_waveArrayCount(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_waveArrayCount_read = data_length_; attr.set_value(attr_waveArrayCount_read); DEBUG_STREAM << "read_waveArrayCount : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -620,12 +588,10 @@ yat::Timer t; void AcquireWaveformLecroy::read_waveArray2(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_waveArray2(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; // Add your own code here *attr_waveArray2_read = channel_data_->wave_array_2_; attr.set_value(attr_waveArray2_read); DEBUG_STREAM << "read_waveArray2 : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -638,12 +604,10 @@ yat::Timer t; void AcquireWaveformLecroy::read_waveArray1(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_waveArray1(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_waveArray1_read = channel_data_->wave_array_1_; attr.set_value(attr_waveArray1_read); DEBUG_STREAM << "read_waveArray1 : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -657,15 +621,11 @@ void AcquireWaveformLecroy::read_rawWaveformData(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_rawWaveformData(Tango::Attribute &attr) entering... "<< endl; //- Add your own code here yat::Timer t; //- get waveform data //-for(std::size_t idx = 0; idx < data_length_; idx++) //- attr_rawWaveformData_read[idx] = channel_data_->raw_waveform_data_[idx]; //-attr.set_value(attr_rawWaveformData_read, data_length_); if ( data_length_ ) { attr.set_value(&channel_data_->raw_waveform_data_[0], data_length_); DEBUG_STREAM << "read_rawWaveformData : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } } //+---------------------------------------------------------------------------- Loading Loading @@ -733,7 +693,9 @@ yat::Timer t; std::size_t length = resp.size(); if ( length > MAX_STRING_LENGTH ) { length = MAX_STRING_LENGTH; } argout = new char[length+1]; ::strcpy(argout, resp.c_str()); Loading Loading @@ -778,24 +740,23 @@ Tango::DevState AcquireWaveformLecroy::dev_state() set_status("No socket connection with Lecroy."); } if ( !data_length_ ) { argout = Tango::ALARM; set_status("Failed to gather channel data : no data."); } if ( argout != Tango::FAULT && argout != Tango::ALARM ) { errors_ = waveform_mgr_->get_errors(); if ( errors_.empty() ) if ( !errors_.empty() ) { argout = Tango::ON; set_status("No error(s)."); argout = Tango::ALARM; set_status(errors_.c_str()); } else else if ( !data_length_ ) { argout = Tango::ALARM; set_status(errors_.c_str()); set_status("Failed to gather channel data : no data."); } else { argout = Tango::ON; set_status("No error(s)."); } } Loading src/AcquireWaveformLecroy.h +0 −2 Original line number Diff line number Diff line Loading @@ -63,8 +63,6 @@ #define _ACQUIREWAVEFORMLECROY_H #include <tango.h> // #include <yat4tango/InnerAppender.h> // #include <yat4tango/YatLogAdapter.h> //using namespace Tango; #include "SocketException.h" #include "WaveformMgr.hpp" Loading src/LinuxSocketLecroy.cpp +77 −45 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ //- perf!!! #include <yat/time/Timer.h> static int hSocket; static int hSocket = 0; static int sTimeout = 2; //- second(s) static char sCurrentAddress[256]; bool SocketLecroy::sConnectedFlag = false; Loading @@ -54,44 +54,53 @@ static char sCommandBuffer[CMD_BUF_LEN]; //- init of the static instance SocketLecroy* SocketLecroy::SL_instance = 0; //- ptr on the SocketLecroy instance // ============================================================================ // SocketLecroy::get_instance // ============================================================================ SocketLecroy* SocketLecroy::get_instance() { if( !SL_instance ) { SL_instance = new SocketLecroy(); } return SL_instance; } // ============================================================================ // SocketLecroy::delete_instance // ============================================================================ void SocketLecroy::delete_instance() { // std::cout << "\t\t\tSocketLecroy::deleted_instance ... SL_instance = " << SL_instance << std::endl; if(SL_instance) { delete SL_instance; SL_instance = 0; } // std::cout << "\t\t\tSocketLecroy::deleted_instance DONE -> SL_instance = " << SL_instance << std::endl; } //- CTOR // ============================================================================ // SocketLecroy::SocketLecroy() // ============================================================================ SocketLecroy::SocketLecroy() { sConnectedFlag = false; } //- DTOR // ============================================================================ // SocketLecroy::~SocketLecroy() // ============================================================================ SocketLecroy::~SocketLecroy() { // std::cout << "\t\t\tSocketLecroy::DTOR SocketLecroy ..." << std::endl; TCP_Disconnect(); // std::cout << "\t\t\tSocketLecroy::DTOR DONE." << std::endl; } // ============================================================================ // SocketLecroy::TCP_Connect // ============================================================================ //- Build the connection void SocketLecroy::TCP_Connect(char *ip_address) throw (lecroy::SocketException) void SocketLecroy::TCP_Connect(char *ip_address) { yat::Timer t; struct sockaddr_in serverAddr; int result; const int resp = 1; Loading @@ -104,7 +113,9 @@ yat::Timer t; //- connection test if (sConnectedFlag) { return; } strcpy(sCurrentAddress, ip_address); tval.tv_sec = 1; Loading Loading @@ -136,6 +147,13 @@ yat::Timer t; "Unable to set socket option to TCP_NODELAY.", "SocketLecroy::TCP_Connect( )."); } //- set Timeout for write operations if (setsockopt(hSocket, SOL_SOCKET, SO_SNDTIMEO, (const char*)&tval, sizeof(struct timeval)) != 0) { throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Unable to set socket option to TCP_NODELAY.", "SocketLecroy::TCP_Connect( )."); } if (setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (char*)&resp, sizeof(resp)) != 0) { Loading @@ -151,7 +169,9 @@ yat::Timer t; int opts; opts = fcntl (hSocket, F_GETFL); if (opts >= 0) { opts = (opts | O_NONBLOCK); } fcntl (hSocket, F_SETFL, opts); //connect(hSocket, (SOCKADDR FAR *) &serverAddr, sockAddrSize); int status = ::connect(hSocket, ( sockaddr *)&serverAddr, sizeof(serverAddr)); Loading @@ -177,7 +197,9 @@ yat::Timer t; } }// Connection is OK. else { break; } }//TODO : throw ; // Too much attempts, so failure ! }// TODO : throw ; // Not the right error, so failure ! }// Connected at first attempt ! Loading @@ -195,60 +217,76 @@ yat::Timer t; } sConnectedFlag = true; // std::cout << "\t\t\t SocketLecroy::TCP_Connect done in " << t.elapsed_msec() << " ms" << std::endl; } // ============================================================================ // SocketLecroy::TCP_Disconnect() // ============================================================================ //- DisconnectFromScope: disconnect from a network device void SocketLecroy::TCP_Disconnect(void) throw (lecroy::SocketException) void SocketLecroy::TCP_Disconnect(void) { // std::cout << "\t\t\tSocketLecroy::comm closing socket ENTREING ...." << std::endl; if (sConnectedFlag) { // std::cout << "\t\t\tSocketLecroy::comm closing socket ...." << std::endl; close(hSocket); // std::cout << "\t\t\tSocketLecroy::comm closed." << std::endl; sConnectedFlag = false; } // std::cout << "\t\t\tSocketLecroy::comm closing socket DONE ...." << std::endl; } // ============================================================================ // SocketLecroy::TCP_ClearDevice // ============================================================================ //- Clear a connection void SocketLecroy::TCP_ClearDevice(void) throw (lecroy::SocketException) void SocketLecroy::TCP_ClearDevice(void) { if ( !sConnectedFlag ) { throw lecroy::SocketException("COMMUNICATION_BROKEN", "Disconnection already done.", "SocketLecroy::TCP_ClearDevice( )."); } TCP_Disconnect(); TCP_Connect(sCurrentAddress); } // ============================================================================ // SocketLecroy::write_read // ============================================================================ void SocketLecroy::write_read(char* in_buf, unsigned int in_length, char* out_buf, int* out_length, bool eoi_flag) { yat::Timer t; yat::AutoMutex<> guard(lock_); try { TCP_WriteDevice(in_buf, in_length, eoi_flag); // std::cout << "\t\t\t SocketLecroy::write_read WRITE done in " << t.elapsed_msec() << " ms" << std::endl; TCP_ReadDevice(out_buf, *out_length, out_length); // std::cout << "\t\t\t SocketLecroy::write_read done in " << t.elapsed_msec() << " ms" << std::endl; } catch(...) { //- Noop (TODO) } } // ============================================================================ // SocketLecroy::TCP_WriteDevice // ============================================================================ //- Send commands to the remote device void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) throw (lecroy::SocketException) void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) { TCP_HEADER header; int result, bytes_more, bytes_xferd; char *idxPtr; // std::cout << "\t\t\t TCP_WriteDevice -> ENTERING ..." << std::endl; char *idxPtr = 0; //- test connection if ( !sConnectedFlag ) { throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Device not connected.", "SocketLecroy::TCP_WriteDevice( )."); } if (len < CMD_BUF_LEN) { strcpy(sCommandBuffer, buf); } //- set the header info header.bEOI_Flag = DATA_FLAG; Loading @@ -258,16 +296,12 @@ void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) throw (lec header.reserved[2] = 0; header.iLength = htonl(len); // std::cout << "\t\t\t TCP_WriteDevice -> send ..." << std::endl; //- write the header first if (send(hSocket, (char *) &header, sizeof(TCP_HEADER), 0) != sizeof(TCP_HEADER)) if (send(hSocket, (char *) &header, sizeof(TCP_HEADER), 0) < 0) { throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Unable to send header info to the server.", "SocketLecroy::TCP_WriteDevice( )."); return; } // std::cout << "\t\t\t TCP_WriteDevice -> sent!" << std::endl; bytes_more = len; idxPtr = buf; bytes_xferd = 0; Loading @@ -278,10 +312,7 @@ void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) throw (lec if ((result = send(hSocket, (char *) idxPtr, bytes_more, 0)) < 0) { // std::cout << "\t\t\tFATAL TCP_WriteDevice -> send ..." << std::endl; throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Unable to send data to the server.", "SocketLecroy::TCP_WriteDevice( )."); return; } bytes_xferd += result; Loading @@ -289,11 +320,13 @@ void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) throw (lec if (bytes_more <= 0) break; } // std::cout << "\t\t\tFATAL TCP_WriteDevice -> DONE." << std::endl; } // ============================================================================ // SocketLecroy::TCP_ReadDevice // ============================================================================ //- Read the device answer void SocketLecroy::TCP_ReadDevice(char *buf, unsigned int len, int *recv_count) throw (lecroy::SocketException) void SocketLecroy::TCP_ReadDevice(char *buf, unsigned int len, int *recv_count) { TCP_HEADER header; int result; Loading @@ -306,16 +339,20 @@ void SocketLecroy::TCP_ReadDevice(char *buf, unsigned int len, int *recv_count) //- test connection if ( !sConnectedFlag ) { throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Device not connected.", "SocketLecroy::TCP_ReadDevice( )."); } *recv_count = 0; if (!buf) { throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Buffer memory not allocated.", "SocketLecroy::TCP_ReadDevice( )."); } FD_SET(hSocket, &rd_set); tval.tv_sec = 0; Loading @@ -330,7 +367,6 @@ void SocketLecroy::TCP_ReadDevice(char *buf, unsigned int len, int *recv_count) result = select(hSocket, &rd_set, NULL, NULL, &tval); if (result < 0) { // std::cout << "\tSocketLecroy::TCP_ReadDevice -> result < 0." << std::endl; TCP_ClearDevice(); throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Read Timeout.", Loading @@ -356,16 +392,12 @@ void SocketLecroy::TCP_ReadDevice(char *buf, unsigned int len, int *recv_count) break; } // header.iLength = ntohl(header.iLength); unsigned int headerLength = ntohl(header.iLength); //- only read to len amount if (headerLength > space_left) { headerLength = space_left; /* throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Read buffer size is too small.", "SocketLecroy::TCP_ReadDevice( ).");*/ } //- read the rest of the block Loading src/Waveform.cpp +95 −62 Original line number Diff line number Diff line Loading @@ -23,7 +23,9 @@ #include "Waveform.h" #include <yat/time/Timer.h> //- CTOR // ============================================================================ // WaveForm_data::WaveForm_data // ============================================================================ WaveForm_data::WaveForm_data(char* lecroyIPAdd) : ptr_com(0), time_to_get_waveformData("") Loading @@ -38,30 +40,39 @@ WaveForm_data::WaveForm_data(char* lecroyIPAdd) ptr_com->TCP_Connect(lecroyIPAdd); } //- DTOR // ============================================================================ // WaveForm_data::~WaveForm_data // ============================================================================ WaveForm_data::~WaveForm_data() { // std::cout << "\t\tWaveForm_data::DTOR." << std::endl; //- close the socket // ptr_com->TCP_Disconnect(); // std::cout << "\t\tWaveForm_data::TCP_Disconnect DNE." << std::endl; //- delete the SocketLecroy obj if ( ptr_com ) { SocketLecroy::delete_instance(); // std::cout << "\t\tWaveForm_data::delete_instance DNE." << std::endl; // std::cout << "\t\tWaveForm_data::ptrRawData DNE => ptr_com add = " << ptr_com << std::endl; } } // ============================================================================ // WaveForm_data::update_channel_data // ============================================================================ void WaveForm_data::update_channel_data(ChannelData* chdata) { // yat::Timer t; yat::Timer t; try{ get_waveform_data(chdata); get_trigger_time_value(chdata); // std::cout << "\t\tWaveForm_data::update_channel_data -> DONE in " << t.elapsed_msec() << " ms." << std::endl; } catch(const lecroy::SocketException& se) {//- TODO } } // ============================================================================ // WaveForm_data::get_waveform_data // ============================================================================ //- Method to return the raw data of the acquired waveform void WaveForm_data::get_waveform_data(ChannelData* channelData ) throw (lecroy::WaveformException) void WaveForm_data::get_waveform_data(ChannelData* channelData) { std::string cmd(""); char* cmdStr = 0; Loading @@ -69,9 +80,7 @@ unsigned short OFFSET_STRUCT = 0; std::ostringstream oss; //- FOR DEBUG : comment out Timer and STD::COUT !! // yat::Timer t; // std::cout << "\t\t\tget_waveform_data ENTERING ..." << std::endl; yat::Timer t; //- init ptr waveblocdata which point on wavedesc_blocs structure waveBlockData = 0; Loading @@ -79,7 +88,6 @@ std::ostringstream oss; //- get channel name std::string ch_name("") ; ch_name = channelData->channel_name_; // std::cout << "\t\t\tget_waveform_data -> ch name = " << ch_name << std::endl; //- prepare the cmd to get the waveform data cmd = ch_name + std::string(":WF? ALL"); Loading @@ -88,22 +96,32 @@ std::ostringstream oss; ::strncpy(cmdStr, cmd.c_str(), in_length); //- send the request // std::cout << "\t\tget_waveform_data -> write cmd..." << ptr_com << std::endl; int out_length = MAX_WAVEFORM_DATA_LENGTH; try { //- erase previsous data ::memset (ptrRawData, 0, out_length); ptr_com->write_read(cmdStr, in_length, ptrRawData, &out_length, true); // time_to_read_data = t.elapsed_msec(); // std::cout << "\t\tWaveForm_data::Time to WRITE_READ resp lgth = " << out_length << " data : " << t.elapsed_msec() << std::endl; } catch(const lecroy::SocketException& se) {//- TODO //- delete cmd allocation if(cmdStr) { delete [] cmdStr; cmdStr = 0; } return; } catch(const lecroy::WaveformException &) { //- XE : throw lecroy::WaveformException("OPERATION_FAILED", "The TCP_ReadDevice() method failed.", "WaveForm_data::get_waveform_data( )."); //- delete cmd allocation if(cmdStr) { delete [] cmdStr; cmdStr = 0; } return; } //- delete cmd allocation Loading @@ -114,7 +132,7 @@ std::ostringstream oss; } //- calculation of the offset of the structure (it can be 15 or 21) unsigned short i = 0; std::size_t i = 0; for(i=0; i < 22 ; i++) { if(ptrRawData[i] == 'W' && ptrRawData[i+1] == 'A') Loading @@ -127,17 +145,16 @@ std::ostringstream oss; //- test if the OFFSET_STRUCT is found if(!OFFSET_STRUCT) throw lecroy::WaveformException("DATA_OUT_OF_RANGE", "The offset of the structure is not found.", "WaveForm_data::get_waveform_data( )."); // std::cout << "\t\tOFFSET of struct = " << OFFSET_STRUCT << std::endl; { return; } //- update the struct WAVEDESC_BLOC waveBlockData = (WAVEDESC_BLOCK*) (ptrRawData+OFFSET_STRUCT); if(!waveBlockData) throw lecroy::WaveformException("OUT_OF_MEMORY", "The pointer for the receive data can't be allocated before the read operation.", "WaveForm_data::get_waveform_data( )."); { return; } //- copy data channelData->wave_array_count_ = waveBlockData->wave_array_count; Loading @@ -152,45 +169,61 @@ std::ostringstream oss; channelData->raw_waveform_data_.resize(waveBlockData->wave_array_count); channelData->vertical_scaled_data_.resize(waveBlockData->wave_array_count); //- populate vectors for(long idx=0; idx < waveBlockData->wave_array_count; idx++) for(std::size_t idx=0; idx < waveBlockData->wave_array_count; idx++) { //- raw data channelData->raw_waveform_data_[idx] = (ptrRawData + OFFSET_STRUCT + waveBlockData->wave_descriptor)[idx]; //- compute and copy scaled data channelData->vertical_scaled_data_[idx] = (waveBlockData->vertical_gain * channelData->raw_waveform_data_[idx]) - waveBlockData->vertical_offset; } // std::cout << "\t\tWaveForm_data::get_waveform_data done in : " << t.elapsed_msec() << " ms." << std::endl; } // ============================================================================ // WaveForm_data::get_trigger_time_value // ============================================================================ //- Method to return the trigger time of the acquired waveform void WaveForm_data::get_trigger_time_value (ChannelData* channelData) { //- The format is : "Date = month, day, year ; Time = hours:minutes:seconds" std::string str_seconds(""); std::string str_minutes(""); std::string str_hours (""); std::string str_days (""); std::string str_months (""); std::string str_years (""); std::string str_seconds("00"); std::string str_minutes("00"); std::string str_hours ("00"); std::string str_days ("00"); std::string str_months ("00"); std::string str_years ("00"); try { if(waveBlockData) { //- hours, min, sec with 2 digits str_seconds = XString<double>::convertToString(waveBlockData->trigger_time_seconds); if(waveBlockData->trigger_time_seconds<10) { str_seconds = "0" + str_seconds; } str_minutes = XString<int>::convertToString((int)waveBlockData->trigger_time_minutes); if(waveBlockData->trigger_time_minutes<10) { str_minutes = "0" + str_minutes; } str_hours = XString<int>::convertToString(waveBlockData->trigger_time_hours); if(waveBlockData->trigger_time_hours<10) { str_hours = "0" + str_hours; } str_days = XString<int>::convertToString(waveBlockData->trigger_time_days); str_months= XString<int>::convertToString(waveBlockData->trigger_time_months); str_years = XString<short>::convertToString(waveBlockData->trigger_time_year); } } catch(...) { //- Noop } //- Construct the string Trigger Time: channelData->trigger_time_ = "Date = " + str_months + "/" + str_days + "/" + str_years + " ; Time = " + str_hours + ":" + str_minutes + ":" + str_seconds; }
conanfile.py +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps class AcquireWaveformLecroyRecipe(ConanFile): name = "acquirewaveformlecroy" executable = "ds_AcquireWaveformLecroy" version = "1.2.0" version = "1.2.1" package_type = "application" user = "soleil" Loading
include/ChannelData.hpp +16 −14 Original line number Diff line number Diff line Loading @@ -56,6 +56,8 @@ public: //- operator= ChannelData& operator=(const ChannelData& src) { if(&src != this) { this->channel_name_ = src.channel_name_; this->trigger_time_ = src.trigger_time_; Loading @@ -69,7 +71,7 @@ public: this->wave_array_2_ = src.wave_array_2_; this->vertical_scaled_data_ = src.vertical_scaled_data_; this->raw_waveform_data_ = src.raw_waveform_data_; } return *this; } Loading
include/SocketLecroy.h +13 −17 Original line number Diff line number Diff line Loading @@ -27,7 +27,6 @@ #include <winsock2.h> #endif #include "SocketException.h" #include <yat/threading/Mutex.h> //////////////////////////////////////////////////////////////////// // // SocketLecroy :: DEFINITION Loading @@ -45,7 +44,6 @@ typedef struct //- Constants definitions //----------------------------------------------- const int SERVER_PORT = 1861; //- It's the same port number for all Lecroy scope's. const int EOI_FLAG = 0x01; const int SRQ_FLAG = 0x08; const int CLEAR_FLAG = 0x10; Loading @@ -62,8 +60,6 @@ private: SocketLecroy(); //- just one instance of SocketLecroy must be done for all waveforms of a same Lecroy device ~SocketLecroy(); yat::Mutex lock_; static SocketLecroy* SL_instance; //- ptr on the SocketLecroy instance static bool sConnectedFlag; Loading @@ -79,11 +75,11 @@ public: void write_read (char* in_buf, unsigned int in_length, char* out_buf, int* out_length, bool eoi_flag); void TCP_WriteDevice (char *buf, int length,bool eoi_flag) throw (lecroy::SocketException); //- send a cmd to the device void TCP_ReadDevice (char *buf, unsigned int length, int* nb_byte_received) throw (lecroy::SocketException); //- read the device replie void TCP_Connect (char *ip_address) throw (lecroy::SocketException); //- build TCP/IP connection void TCP_Disconnect (void) throw (lecroy::SocketException); //- disconnect the device void TCP_ClearDevice (void) throw (lecroy::SocketException); //- disconnect and reconnect the device void TCP_WriteDevice (char *buf, int length,bool eoi_flag); //- send a cmd to the device void TCP_ReadDevice (char *buf, unsigned int length, int* nb_byte_received); //- read the device replie void TCP_Connect (char *ip_address); //- build TCP/IP connection void TCP_Disconnect (void); //- disconnect the device void TCP_ClearDevice (void); //- disconnect and reconnect the device }; Loading
include/Waveform.h +6 −7 Original line number Diff line number Diff line Loading @@ -109,8 +109,7 @@ private: //- time info to acquire waveform data std::string time_to_get_waveformData; void get_waveform_data (ChannelData* channelData) throw (lecroy::WaveformException); //- acquire the waveform data from the scope void get_waveform_data (ChannelData* channelData); //- acquire the waveform data from the scope void get_trigger_time_value (ChannelData* channelData); Loading
include/WaveformMgr.hpp +4 −4 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ public: protected: //- process_message (implements yat4tango::DeviceTask pure virtual method) virtual void process_message (yat::Message& msg) throw (Tango::DevFailed); virtual void process_message (yat::Message& msg); //- internal mutex yat::Mutex data_mutex_; Loading
pom.xml +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ <groupId>fr.soleil.device</groupId> <artifactId>AcquireWaveformLecroy-${aol}-${mode}</artifactId> <version>1.2.0</version> <version>1.2.1</version> <packaging>nar</packaging> <name>AcquireWaveformLecroy</name> <description>AcquireWaveformLecroy device</description> Loading
src/AcquireWaveformLecroy.cpp +58 −97 Original line number Diff line number Diff line Loading @@ -98,9 +98,11 @@ static const char *RcsId = "$Header: /users/chaize/newsvn/cvsroot/Instrumentatio // //=================================================================== #include <AcquireWaveformLecroy.h> #include <AcquireWaveformLecroyClass.h> // #include <AcquireWaveformLecroy.h> #include "AcquireWaveformLecroyClass.h" #include <yat/time/Timer.h> #include <yat4tango/DeviceInfo.h> #include <yat4tango/Logging.h> static const std::size_t MAX_STRING_LENGTH = 1024; Loading Loading @@ -199,14 +201,8 @@ void AcquireWaveformLecroy::delete_device() this->waveform_mgr_ = 0; } /*std::cout << "removing log" << std::endl; // DEBUG_STREAM << "Remove the InnerAppender." << endl; yat4tango::InnerAppender::release(this); // DEBUG_STREAM << "Remove the YatLogAdapter." << endl; yat4tango::YatLogAdapter::release(); std::cout << "removed log : " << log_deleted << std::endl;*/ yat4tango::DeviceInfo::release(this); yat4tango::Logging::release(this); } //+---------------------------------------------------------------------------- Loading Loading @@ -265,21 +261,8 @@ void AcquireWaveformLecroy::init_device() //--------------------------------------------------------- //- instanciate the log_adapter & inner_appender in order to manage logs //--------------------------------------------------------- // try // { // DEBUG_STREAM << "Create the YatLogAdapter in order to use logs from third party library." << endl; // yat4tango::YatLogAdapter::initialize(this); // // DEBUG_STREAM << "Create the InnerAppender in order to manage logs." << endl; // yat4tango::InnerAppender::initialize(this, 512); // } // catch (Tango::DevFailed& df) // { // ERROR_STREAM << df << endl; // set_state(Tango::FAULT); // set_status("OUT OF MEMORY : Failed to create log manager !"); // return; // } yat4tango::DeviceInfo::initialize( this, YAT_XSTR(PROJECT_NAME), YAT_XSTR(PROJECT_VERSION) ); yat4tango::Logging::initialize(this); char * ipAdd = 0; if (!waveform_mgr_) Loading @@ -288,7 +271,9 @@ void AcquireWaveformLecroy::init_device() std::size_t length = iPaddress.size(); ipAdd = new char[length+1]; for(std::size_t i=0; i<length; i++) { ipAdd[i] = iPaddress[i]; } ipAdd[length] = '\0'; //- create the waveform obj waveform_mgr_ = new WaveformMgr(this, ipAdd); Loading @@ -300,8 +285,10 @@ void AcquireWaveformLecroy::init_device() waveform_mgr_->add_channel(channelName); //- start thread (if not already started) if ( !waveform_mgr_->periodic_msg_enabled() ) { waveform_mgr_->go(); } } //- release temporary allocation if (ipAdd) { Loading Loading @@ -380,8 +367,10 @@ void AcquireWaveformLecroy::get_device_property() // End of Automatic code generation //------------------------------------------------------------------ if( !data_put.empty() ) { get_db_device()->put_property(data_put); } } //+---------------------------------------------------------------------------- // Loading Loading @@ -454,7 +443,7 @@ yat::Timer t; throw; } INFO_STREAM << "READ_HW : all data are now updated. DONE in " << t.elapsed_msec() << " milliseconds.\n" << std::endl; DEBUG_STREAM << "READ_HW : all data are now updated. DONE in " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -467,15 +456,11 @@ yat::Timer t; void AcquireWaveformLecroy::read_verticalScaledData(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_verticalScaledData(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; // for(std::size_t idx = 0; idx < data_length_; idx++) // attr_verticalScaledData_read[idx] = channel_data_->vertical_scaled_data_[idx]; // attr.set_value(attr_verticalScaledData_read, data_length_); if ( data_length_ ) { attr.set_value(&channel_data_->vertical_scaled_data_[0], data_length_); DEBUG_STREAM << "read_verticalScaledData : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } } //+---------------------------------------------------------------------------- Loading @@ -488,14 +473,11 @@ yat::Timer t; void AcquireWaveformLecroy::read_triggerTime(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_triggerTime(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; // Add your own code here std::string response = channel_data_->trigger_time_; strcpy(*attr_triggerTime_read, response.c_str()); ::strcpy(*attr_triggerTime_read, response.c_str()); attr.set_value(attr_triggerTime_read); DEBUG_STREAM << "read_triggerTime : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -508,13 +490,11 @@ yat::Timer t; void AcquireWaveformLecroy::read_verticalOffset(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_verticalOffset(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_verticalOffset_read = channel_data_->vertical_offset_; attr.set_value(attr_verticalOffset_read); DEBUG_STREAM << "read_verticalOffset : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -527,13 +507,10 @@ yat::Timer t; void AcquireWaveformLecroy::read_verticalGain(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_verticalGain(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_verticalGain_read = channel_data_->vertical_gain_; attr.set_value(attr_verticalGain_read); DEBUG_STREAM << "read_verticalGain : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -546,13 +523,10 @@ yat::Timer t; void AcquireWaveformLecroy::read_horizontalOffset(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_horizontalOffset(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_horizontalOffset_read = channel_data_->horizontal_offset_; attr.set_value(attr_horizontalOffset_read); DEBUG_STREAM << "read_horizontalOffset : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -565,13 +539,11 @@ void AcquireWaveformLecroy::read_horizontalOffset(Tango::Attribute &attr) void AcquireWaveformLecroy::read_horizontalInterval(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_horizontalInterval(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_horizontalInterval_read = channel_data_->horizontal_interval_; attr.set_value(attr_horizontalInterval_read); DEBUG_STREAM << "read_horizontalInterval : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -584,12 +556,10 @@ void AcquireWaveformLecroy::read_horizontalInterval(Tango::Attribute &attr) void AcquireWaveformLecroy::read_nominalBits(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_nominalBits(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_nominalBits_read = channel_data_->nominal_bits_; attr.set_value(attr_nominalBits_read); DEBUG_STREAM << "read_nominalBits : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -602,12 +572,10 @@ yat::Timer t; void AcquireWaveformLecroy::read_waveArrayCount(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_waveArrayCount(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_waveArrayCount_read = data_length_; attr.set_value(attr_waveArrayCount_read); DEBUG_STREAM << "read_waveArrayCount : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -620,12 +588,10 @@ yat::Timer t; void AcquireWaveformLecroy::read_waveArray2(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_waveArray2(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; // Add your own code here *attr_waveArray2_read = channel_data_->wave_array_2_; attr.set_value(attr_waveArray2_read); DEBUG_STREAM << "read_waveArray2 : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -638,12 +604,10 @@ yat::Timer t; void AcquireWaveformLecroy::read_waveArray1(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_waveArray1(Tango::Attribute &attr) entering... "<< endl; yat::Timer t; //- Add your own code here *attr_waveArray1_read = channel_data_->wave_array_1_; attr.set_value(attr_waveArray1_read); DEBUG_STREAM << "read_waveArray1 : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } //+---------------------------------------------------------------------------- Loading @@ -657,15 +621,11 @@ void AcquireWaveformLecroy::read_rawWaveformData(Tango::Attribute &attr) { //- DEBUG_STREAM << "AcquireWaveformLecroy::read_rawWaveformData(Tango::Attribute &attr) entering... "<< endl; //- Add your own code here yat::Timer t; //- get waveform data //-for(std::size_t idx = 0; idx < data_length_; idx++) //- attr_rawWaveformData_read[idx] = channel_data_->raw_waveform_data_[idx]; //-attr.set_value(attr_rawWaveformData_read, data_length_); if ( data_length_ ) { attr.set_value(&channel_data_->raw_waveform_data_[0], data_length_); DEBUG_STREAM << "read_rawWaveformData : " << t.elapsed_msec() << " milliseconds.\n" << std::endl; } } //+---------------------------------------------------------------------------- Loading Loading @@ -733,7 +693,9 @@ yat::Timer t; std::size_t length = resp.size(); if ( length > MAX_STRING_LENGTH ) { length = MAX_STRING_LENGTH; } argout = new char[length+1]; ::strcpy(argout, resp.c_str()); Loading Loading @@ -778,24 +740,23 @@ Tango::DevState AcquireWaveformLecroy::dev_state() set_status("No socket connection with Lecroy."); } if ( !data_length_ ) { argout = Tango::ALARM; set_status("Failed to gather channel data : no data."); } if ( argout != Tango::FAULT && argout != Tango::ALARM ) { errors_ = waveform_mgr_->get_errors(); if ( errors_.empty() ) if ( !errors_.empty() ) { argout = Tango::ON; set_status("No error(s)."); argout = Tango::ALARM; set_status(errors_.c_str()); } else else if ( !data_length_ ) { argout = Tango::ALARM; set_status(errors_.c_str()); set_status("Failed to gather channel data : no data."); } else { argout = Tango::ON; set_status("No error(s)."); } } Loading
src/AcquireWaveformLecroy.h +0 −2 Original line number Diff line number Diff line Loading @@ -63,8 +63,6 @@ #define _ACQUIREWAVEFORMLECROY_H #include <tango.h> // #include <yat4tango/InnerAppender.h> // #include <yat4tango/YatLogAdapter.h> //using namespace Tango; #include "SocketException.h" #include "WaveformMgr.hpp" Loading
src/LinuxSocketLecroy.cpp +77 −45 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ //- perf!!! #include <yat/time/Timer.h> static int hSocket; static int hSocket = 0; static int sTimeout = 2; //- second(s) static char sCurrentAddress[256]; bool SocketLecroy::sConnectedFlag = false; Loading @@ -54,44 +54,53 @@ static char sCommandBuffer[CMD_BUF_LEN]; //- init of the static instance SocketLecroy* SocketLecroy::SL_instance = 0; //- ptr on the SocketLecroy instance // ============================================================================ // SocketLecroy::get_instance // ============================================================================ SocketLecroy* SocketLecroy::get_instance() { if( !SL_instance ) { SL_instance = new SocketLecroy(); } return SL_instance; } // ============================================================================ // SocketLecroy::delete_instance // ============================================================================ void SocketLecroy::delete_instance() { // std::cout << "\t\t\tSocketLecroy::deleted_instance ... SL_instance = " << SL_instance << std::endl; if(SL_instance) { delete SL_instance; SL_instance = 0; } // std::cout << "\t\t\tSocketLecroy::deleted_instance DONE -> SL_instance = " << SL_instance << std::endl; } //- CTOR // ============================================================================ // SocketLecroy::SocketLecroy() // ============================================================================ SocketLecroy::SocketLecroy() { sConnectedFlag = false; } //- DTOR // ============================================================================ // SocketLecroy::~SocketLecroy() // ============================================================================ SocketLecroy::~SocketLecroy() { // std::cout << "\t\t\tSocketLecroy::DTOR SocketLecroy ..." << std::endl; TCP_Disconnect(); // std::cout << "\t\t\tSocketLecroy::DTOR DONE." << std::endl; } // ============================================================================ // SocketLecroy::TCP_Connect // ============================================================================ //- Build the connection void SocketLecroy::TCP_Connect(char *ip_address) throw (lecroy::SocketException) void SocketLecroy::TCP_Connect(char *ip_address) { yat::Timer t; struct sockaddr_in serverAddr; int result; const int resp = 1; Loading @@ -104,7 +113,9 @@ yat::Timer t; //- connection test if (sConnectedFlag) { return; } strcpy(sCurrentAddress, ip_address); tval.tv_sec = 1; Loading Loading @@ -136,6 +147,13 @@ yat::Timer t; "Unable to set socket option to TCP_NODELAY.", "SocketLecroy::TCP_Connect( )."); } //- set Timeout for write operations if (setsockopt(hSocket, SOL_SOCKET, SO_SNDTIMEO, (const char*)&tval, sizeof(struct timeval)) != 0) { throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Unable to set socket option to TCP_NODELAY.", "SocketLecroy::TCP_Connect( )."); } if (setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (char*)&resp, sizeof(resp)) != 0) { Loading @@ -151,7 +169,9 @@ yat::Timer t; int opts; opts = fcntl (hSocket, F_GETFL); if (opts >= 0) { opts = (opts | O_NONBLOCK); } fcntl (hSocket, F_SETFL, opts); //connect(hSocket, (SOCKADDR FAR *) &serverAddr, sockAddrSize); int status = ::connect(hSocket, ( sockaddr *)&serverAddr, sizeof(serverAddr)); Loading @@ -177,7 +197,9 @@ yat::Timer t; } }// Connection is OK. else { break; } }//TODO : throw ; // Too much attempts, so failure ! }// TODO : throw ; // Not the right error, so failure ! }// Connected at first attempt ! Loading @@ -195,60 +217,76 @@ yat::Timer t; } sConnectedFlag = true; // std::cout << "\t\t\t SocketLecroy::TCP_Connect done in " << t.elapsed_msec() << " ms" << std::endl; } // ============================================================================ // SocketLecroy::TCP_Disconnect() // ============================================================================ //- DisconnectFromScope: disconnect from a network device void SocketLecroy::TCP_Disconnect(void) throw (lecroy::SocketException) void SocketLecroy::TCP_Disconnect(void) { // std::cout << "\t\t\tSocketLecroy::comm closing socket ENTREING ...." << std::endl; if (sConnectedFlag) { // std::cout << "\t\t\tSocketLecroy::comm closing socket ...." << std::endl; close(hSocket); // std::cout << "\t\t\tSocketLecroy::comm closed." << std::endl; sConnectedFlag = false; } // std::cout << "\t\t\tSocketLecroy::comm closing socket DONE ...." << std::endl; } // ============================================================================ // SocketLecroy::TCP_ClearDevice // ============================================================================ //- Clear a connection void SocketLecroy::TCP_ClearDevice(void) throw (lecroy::SocketException) void SocketLecroy::TCP_ClearDevice(void) { if ( !sConnectedFlag ) { throw lecroy::SocketException("COMMUNICATION_BROKEN", "Disconnection already done.", "SocketLecroy::TCP_ClearDevice( )."); } TCP_Disconnect(); TCP_Connect(sCurrentAddress); } // ============================================================================ // SocketLecroy::write_read // ============================================================================ void SocketLecroy::write_read(char* in_buf, unsigned int in_length, char* out_buf, int* out_length, bool eoi_flag) { yat::Timer t; yat::AutoMutex<> guard(lock_); try { TCP_WriteDevice(in_buf, in_length, eoi_flag); // std::cout << "\t\t\t SocketLecroy::write_read WRITE done in " << t.elapsed_msec() << " ms" << std::endl; TCP_ReadDevice(out_buf, *out_length, out_length); // std::cout << "\t\t\t SocketLecroy::write_read done in " << t.elapsed_msec() << " ms" << std::endl; } catch(...) { //- Noop (TODO) } } // ============================================================================ // SocketLecroy::TCP_WriteDevice // ============================================================================ //- Send commands to the remote device void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) throw (lecroy::SocketException) void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) { TCP_HEADER header; int result, bytes_more, bytes_xferd; char *idxPtr; // std::cout << "\t\t\t TCP_WriteDevice -> ENTERING ..." << std::endl; char *idxPtr = 0; //- test connection if ( !sConnectedFlag ) { throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Device not connected.", "SocketLecroy::TCP_WriteDevice( )."); } if (len < CMD_BUF_LEN) { strcpy(sCommandBuffer, buf); } //- set the header info header.bEOI_Flag = DATA_FLAG; Loading @@ -258,16 +296,12 @@ void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) throw (lec header.reserved[2] = 0; header.iLength = htonl(len); // std::cout << "\t\t\t TCP_WriteDevice -> send ..." << std::endl; //- write the header first if (send(hSocket, (char *) &header, sizeof(TCP_HEADER), 0) != sizeof(TCP_HEADER)) if (send(hSocket, (char *) &header, sizeof(TCP_HEADER), 0) < 0) { throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Unable to send header info to the server.", "SocketLecroy::TCP_WriteDevice( )."); return; } // std::cout << "\t\t\t TCP_WriteDevice -> sent!" << std::endl; bytes_more = len; idxPtr = buf; bytes_xferd = 0; Loading @@ -278,10 +312,7 @@ void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) throw (lec if ((result = send(hSocket, (char *) idxPtr, bytes_more, 0)) < 0) { // std::cout << "\t\t\tFATAL TCP_WriteDevice -> send ..." << std::endl; throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Unable to send data to the server.", "SocketLecroy::TCP_WriteDevice( )."); return; } bytes_xferd += result; Loading @@ -289,11 +320,13 @@ void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) throw (lec if (bytes_more <= 0) break; } // std::cout << "\t\t\tFATAL TCP_WriteDevice -> DONE." << std::endl; } // ============================================================================ // SocketLecroy::TCP_ReadDevice // ============================================================================ //- Read the device answer void SocketLecroy::TCP_ReadDevice(char *buf, unsigned int len, int *recv_count) throw (lecroy::SocketException) void SocketLecroy::TCP_ReadDevice(char *buf, unsigned int len, int *recv_count) { TCP_HEADER header; int result; Loading @@ -306,16 +339,20 @@ void SocketLecroy::TCP_ReadDevice(char *buf, unsigned int len, int *recv_count) //- test connection if ( !sConnectedFlag ) { throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Device not connected.", "SocketLecroy::TCP_ReadDevice( )."); } *recv_count = 0; if (!buf) { throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Buffer memory not allocated.", "SocketLecroy::TCP_ReadDevice( )."); } FD_SET(hSocket, &rd_set); tval.tv_sec = 0; Loading @@ -330,7 +367,6 @@ void SocketLecroy::TCP_ReadDevice(char *buf, unsigned int len, int *recv_count) result = select(hSocket, &rd_set, NULL, NULL, &tval); if (result < 0) { // std::cout << "\tSocketLecroy::TCP_ReadDevice -> result < 0." << std::endl; TCP_ClearDevice(); throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Read Timeout.", Loading @@ -356,16 +392,12 @@ void SocketLecroy::TCP_ReadDevice(char *buf, unsigned int len, int *recv_count) break; } // header.iLength = ntohl(header.iLength); unsigned int headerLength = ntohl(header.iLength); //- only read to len amount if (headerLength > space_left) { headerLength = space_left; /* throw lecroy::SocketException("COMMUNICATION_BROKEN ", "Read buffer size is too small.", "SocketLecroy::TCP_ReadDevice( ).");*/ } //- read the rest of the block Loading
src/Waveform.cpp +95 −62 Original line number Diff line number Diff line Loading @@ -23,7 +23,9 @@ #include "Waveform.h" #include <yat/time/Timer.h> //- CTOR // ============================================================================ // WaveForm_data::WaveForm_data // ============================================================================ WaveForm_data::WaveForm_data(char* lecroyIPAdd) : ptr_com(0), time_to_get_waveformData("") Loading @@ -38,30 +40,39 @@ WaveForm_data::WaveForm_data(char* lecroyIPAdd) ptr_com->TCP_Connect(lecroyIPAdd); } //- DTOR // ============================================================================ // WaveForm_data::~WaveForm_data // ============================================================================ WaveForm_data::~WaveForm_data() { // std::cout << "\t\tWaveForm_data::DTOR." << std::endl; //- close the socket // ptr_com->TCP_Disconnect(); // std::cout << "\t\tWaveForm_data::TCP_Disconnect DNE." << std::endl; //- delete the SocketLecroy obj if ( ptr_com ) { SocketLecroy::delete_instance(); // std::cout << "\t\tWaveForm_data::delete_instance DNE." << std::endl; // std::cout << "\t\tWaveForm_data::ptrRawData DNE => ptr_com add = " << ptr_com << std::endl; } } // ============================================================================ // WaveForm_data::update_channel_data // ============================================================================ void WaveForm_data::update_channel_data(ChannelData* chdata) { // yat::Timer t; yat::Timer t; try{ get_waveform_data(chdata); get_trigger_time_value(chdata); // std::cout << "\t\tWaveForm_data::update_channel_data -> DONE in " << t.elapsed_msec() << " ms." << std::endl; } catch(const lecroy::SocketException& se) {//- TODO } } // ============================================================================ // WaveForm_data::get_waveform_data // ============================================================================ //- Method to return the raw data of the acquired waveform void WaveForm_data::get_waveform_data(ChannelData* channelData ) throw (lecroy::WaveformException) void WaveForm_data::get_waveform_data(ChannelData* channelData) { std::string cmd(""); char* cmdStr = 0; Loading @@ -69,9 +80,7 @@ unsigned short OFFSET_STRUCT = 0; std::ostringstream oss; //- FOR DEBUG : comment out Timer and STD::COUT !! // yat::Timer t; // std::cout << "\t\t\tget_waveform_data ENTERING ..." << std::endl; yat::Timer t; //- init ptr waveblocdata which point on wavedesc_blocs structure waveBlockData = 0; Loading @@ -79,7 +88,6 @@ std::ostringstream oss; //- get channel name std::string ch_name("") ; ch_name = channelData->channel_name_; // std::cout << "\t\t\tget_waveform_data -> ch name = " << ch_name << std::endl; //- prepare the cmd to get the waveform data cmd = ch_name + std::string(":WF? ALL"); Loading @@ -88,22 +96,32 @@ std::ostringstream oss; ::strncpy(cmdStr, cmd.c_str(), in_length); //- send the request // std::cout << "\t\tget_waveform_data -> write cmd..." << ptr_com << std::endl; int out_length = MAX_WAVEFORM_DATA_LENGTH; try { //- erase previsous data ::memset (ptrRawData, 0, out_length); ptr_com->write_read(cmdStr, in_length, ptrRawData, &out_length, true); // time_to_read_data = t.elapsed_msec(); // std::cout << "\t\tWaveForm_data::Time to WRITE_READ resp lgth = " << out_length << " data : " << t.elapsed_msec() << std::endl; } catch(const lecroy::SocketException& se) {//- TODO //- delete cmd allocation if(cmdStr) { delete [] cmdStr; cmdStr = 0; } return; } catch(const lecroy::WaveformException &) { //- XE : throw lecroy::WaveformException("OPERATION_FAILED", "The TCP_ReadDevice() method failed.", "WaveForm_data::get_waveform_data( )."); //- delete cmd allocation if(cmdStr) { delete [] cmdStr; cmdStr = 0; } return; } //- delete cmd allocation Loading @@ -114,7 +132,7 @@ std::ostringstream oss; } //- calculation of the offset of the structure (it can be 15 or 21) unsigned short i = 0; std::size_t i = 0; for(i=0; i < 22 ; i++) { if(ptrRawData[i] == 'W' && ptrRawData[i+1] == 'A') Loading @@ -127,17 +145,16 @@ std::ostringstream oss; //- test if the OFFSET_STRUCT is found if(!OFFSET_STRUCT) throw lecroy::WaveformException("DATA_OUT_OF_RANGE", "The offset of the structure is not found.", "WaveForm_data::get_waveform_data( )."); // std::cout << "\t\tOFFSET of struct = " << OFFSET_STRUCT << std::endl; { return; } //- update the struct WAVEDESC_BLOC waveBlockData = (WAVEDESC_BLOCK*) (ptrRawData+OFFSET_STRUCT); if(!waveBlockData) throw lecroy::WaveformException("OUT_OF_MEMORY", "The pointer for the receive data can't be allocated before the read operation.", "WaveForm_data::get_waveform_data( )."); { return; } //- copy data channelData->wave_array_count_ = waveBlockData->wave_array_count; Loading @@ -152,45 +169,61 @@ std::ostringstream oss; channelData->raw_waveform_data_.resize(waveBlockData->wave_array_count); channelData->vertical_scaled_data_.resize(waveBlockData->wave_array_count); //- populate vectors for(long idx=0; idx < waveBlockData->wave_array_count; idx++) for(std::size_t idx=0; idx < waveBlockData->wave_array_count; idx++) { //- raw data channelData->raw_waveform_data_[idx] = (ptrRawData + OFFSET_STRUCT + waveBlockData->wave_descriptor)[idx]; //- compute and copy scaled data channelData->vertical_scaled_data_[idx] = (waveBlockData->vertical_gain * channelData->raw_waveform_data_[idx]) - waveBlockData->vertical_offset; } // std::cout << "\t\tWaveForm_data::get_waveform_data done in : " << t.elapsed_msec() << " ms." << std::endl; } // ============================================================================ // WaveForm_data::get_trigger_time_value // ============================================================================ //- Method to return the trigger time of the acquired waveform void WaveForm_data::get_trigger_time_value (ChannelData* channelData) { //- The format is : "Date = month, day, year ; Time = hours:minutes:seconds" std::string str_seconds(""); std::string str_minutes(""); std::string str_hours (""); std::string str_days (""); std::string str_months (""); std::string str_years (""); std::string str_seconds("00"); std::string str_minutes("00"); std::string str_hours ("00"); std::string str_days ("00"); std::string str_months ("00"); std::string str_years ("00"); try { if(waveBlockData) { //- hours, min, sec with 2 digits str_seconds = XString<double>::convertToString(waveBlockData->trigger_time_seconds); if(waveBlockData->trigger_time_seconds<10) { str_seconds = "0" + str_seconds; } str_minutes = XString<int>::convertToString((int)waveBlockData->trigger_time_minutes); if(waveBlockData->trigger_time_minutes<10) { str_minutes = "0" + str_minutes; } str_hours = XString<int>::convertToString(waveBlockData->trigger_time_hours); if(waveBlockData->trigger_time_hours<10) { str_hours = "0" + str_hours; } str_days = XString<int>::convertToString(waveBlockData->trigger_time_days); str_months= XString<int>::convertToString(waveBlockData->trigger_time_months); str_years = XString<short>::convertToString(waveBlockData->trigger_time_year); } } catch(...) { //- Noop } //- Construct the string Trigger Time: channelData->trigger_time_ = "Date = " + str_months + "/" + str_days + "/" + str_years + " ; Time = " + str_hours + ":" + str_minutes + ":" + str_seconds; }