Skip to content
Snippets Groups Projects
Commit f44bc022 authored by Xavier ELATTAOUI's avatar Xavier ELATTAOUI
Browse files

CI-1963: exceptions management fixed

parent e06f4758
No related branches found
No related tags found
No related merge requests found
......@@ -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_;
......@@ -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;
}
......
......@@ -27,7 +27,6 @@
#include <winsock2.h>
#endif
#include "SocketException.h"
#include <yat/threading/Mutex.h>
////////////////////////////////////////////////////////////////////
//
// SocketLecroy :: DEFINITION
......@@ -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;
......@@ -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;
......@@ -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
};
......
......@@ -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);
......
......@@ -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_;
......
......@@ -9,7 +9,7 @@
<groupId>fr.soleil.device</groupId>
<artifactId>AcquireWaveformLecroy-${aol}-${mode}</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>1.2.1</version>
<packaging>nar</packaging>
<name>AcquireWaveformLecroy</name>
<description>AcquireWaveformLecroy device</description>
......
......@@ -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;
......@@ -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);
}
//+----------------------------------------------------------------------------
......@@ -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_)
......@@ -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);
......@@ -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)
{
......@@ -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);
}
}
//+----------------------------------------------------------------------------
//
......@@ -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;
}
//+----------------------------------------------------------------------------
......@@ -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;
}
}
//+----------------------------------------------------------------------------
......@@ -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;
}
//+----------------------------------------------------------------------------
......@@ -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;
}
//+----------------------------------------------------------------------------
......@@ -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;
}
//+----------------------------------------------------------------------------
......@@ -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;
}
//+----------------------------------------------------------------------------
......@@ -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;
}
//+----------------------------------------------------------------------------
......@@ -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;
}
//+----------------------------------------------------------------------------
......@@ -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;
}
//+----------------------------------------------------------------------------
......@@ -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;
}
//+----------------------------------------------------------------------------
......@@ -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;
}
//+----------------------------------------------------------------------------
......@@ -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;
}
}
//+----------------------------------------------------------------------------
......@@ -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());
......@@ -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).");
}
}
......
......@@ -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"
......
......@@ -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;
......@@ -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;
......@@ -104,7 +113,9 @@ yat::Timer t;
//- connection test
if (sConnectedFlag)
{
return;
}
strcpy(sCurrentAddress, ip_address);
tval.tv_sec = 1;
......@@ -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)
{
......@@ -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));
......@@ -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 !
......@@ -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;
......@@ -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;
......@@ -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;
......@@ -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;
......@@ -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;
......@@ -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.",
......@@ -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
......
......@@ -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("")
......@@ -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;
......@@ -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;
......@@ -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");
......@@ -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
......@@ -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')
......@@ -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;
......@@ -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;
}
......@@ -56,7 +56,7 @@ WaveformMgr::~WaveformMgr (void)
// ============================================================================
// WaveformMgr::process_message
// ============================================================================
void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
void WaveformMgr::process_message (yat::Message& _msg)
{
DEBUG_STREAM << "WaveformMgr::handle_message::receiving msg " << _msg.to_string() << std::endl;
......@@ -72,7 +72,10 @@ void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
yat::Timer t;
if ( !waveform_ptr_ )
{
waveform_ptr_ = new WaveForm_data(ipAddress_);
}
if (waveform_ptr_)
{
//- check socket is up
......@@ -97,26 +100,22 @@ void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
DEBUG_STREAM << "WaveformMgr::handle_message::THREAD_EXIT::thread is quitting" << std::endl;
//- "release" code goes here
//----------------------------------------------------
// yat::Timer t;
if ( waveform_ptr_ )
{
delete waveform_ptr_;
waveform_ptr_ = 0;
}
// std::cout << "\tWaveformMgr::TASK_EXIT -> waveform_ptr_ in " << t.elapsed_msec() << " ms." << std::endl;
yat::AutoMutex<> guard(this->data_mutex_);
if ( channel_data_ )
{
delete channel_data_;
channel_data_ = 0;
}
// std::cout << "\tWaveformMgr::TASK_EXIT -> channel_data_" << t.elapsed_msec() << " ms." << std::endl;
}
break;
//- THREAD_PERIODIC ------------------
case yat::TASK_PERIODIC:
{
DEBUG_STREAM << "WaveformMgr::handle_message::handling THREAD_PERIODIC msg" << std::endl;
//- code relative to the task's periodic job goes here
//----------------------------------------------------
yat::Timer t;
......@@ -127,7 +126,6 @@ void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
{
ChannelData tmp_channel(channel_data_->channel_name_);
waveform_ptr_->update_channel_data(&tmp_channel);
// std::cout << "\n\n\tWaveformMgr::TASK_PERIODIC -> update_channel_data in " << t.elapsed_msec() << " ms." << std::endl;
{//- critical section
yat::AutoMutex<> guard(this->data_mutex_);
*channel_data_ = tmp_channel;
......@@ -138,15 +136,26 @@ void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
}
INFO_STREAM << "\tWaveformMgr::TASK_PERIODIC -> done in " << t.elapsed_msec() << " ms." << std::endl;
}
catch(lecroy::SocketException& se)
{
ERROR_STREAM << "[...] WaveformMgr::handle_message::handling THREAD_PERIODIC -> [SocketException]" << std::endl;
Tango::DevFailed df = lecroy_to_tango_exception(se);
ERROR_STREAM << df << std::endl;
{
yat::AutoMutex<> guard(this->error_mutex_);
errors_ = "Manager : failed to update channel structure to update data.\n Caught a lecroy::SocketException exception.";
}
throw df;
}
catch(const lecroy::WaveformException& we)
{
Tango::DevFailed df = lecroy_to_tango_exception(we);
FATAL_STREAM << df << std::endl;
ERROR_STREAM << df << std::endl;
{
yat::AutoMutex<> guard(this->error_mutex_);
errors_ = "Manager : failed to update channel structure to update data.\n Caught a Lecroy exception -> check logs.";
errors_ = "Manager : failed to update channel structure to update data.\n Caught a lecroy::WaveformException exception -> check logs.";
}
// std::cout << "[LECROY] WaveformMgr::handle_message::handling THREAD_PERIODIC -> [...]" << std::endl;
throw df;
}
catch(Tango::DevFailed& df)
{
......@@ -155,6 +164,7 @@ void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
yat::AutoMutex<> guard(this->error_mutex_);
errors_ = "Manager : failed to update channel structure to update data.\n Caught a DevFailed exception -> check logs.";
}
throw df;
}
catch(...)
{
......@@ -163,6 +173,7 @@ void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
yat::AutoMutex<> guard(this->error_mutex_);
errors_ = "Manager : failed to update channel structure to update data.\n Caught a generic exception.";
}
throw;
}
}
else
......@@ -171,7 +182,6 @@ void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
yat::AutoMutex<> guard(this->error_mutex_);
errors_ = "Failed to create channel structure to update data.";
}
}
break;
//- WRITE_READ
......@@ -179,7 +189,6 @@ void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
{
//- code relative to the task's STORE_DATA handling goes here
YAT_LOG("CurrentTrendFileTask::handle_message::handling WRITE_READ msg");
// std::cout << "\nCurrentTrendFileTask::handle_message::handling WRITE_READ msg" << std::endl;
yat::Timer t;
try
......@@ -213,7 +222,9 @@ void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
}
}
else
{
::strcpy(resp, "No communication with Lecroy device!");
}
if (command)
{
......@@ -259,7 +270,6 @@ void WaveformMgr::process_message (yat::Message& _msg) throw (Tango::DevFailed)
case yat::TASK_TIMEOUT:
{
//- code relative to the task's tmo handling goes here
std::cout << "WaveformMgr::handle_message::handling THREAD_TIMEOUT msg" << std::endl;
}
break;
//- UNHANDLED MSG --------------------
......@@ -282,7 +292,9 @@ void WaveformMgr::add_channel(std::string ch_name)
//- insert the new channel (in critical section)
yat::AutoMutex<> guard(this->data_mutex_);
if ( !channel_data_ )
{
channel_data_ = new ChannelData(ch_name);
}
//- allocate data memory
channel_data_->vertical_scaled_data_.reserve(MAX_WAVEFORM_DATA_LENGTH);
......
......@@ -31,14 +31,22 @@ 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(SocketLecroy* SL_instance)
{
if(SL_instance)
......@@ -48,18 +56,25 @@ void SocketLecroy::delete_instance(SocketLecroy* SL_instance)
}
}
//- CTOR
// ============================================================================
// SocketLecroy::SocketLecroy
// ============================================================================
SocketLecroy::SocketLecroy()
{
sConnectedFlag = false;
}
//- DTOR
// ============================================================================
// SocketLecroy::~SocketLecroy
// ============================================================================
SocketLecroy::~SocketLecroy()
{
TCP_Disconnect();
}
// ============================================================================
// SocketLecroy::TCP_Connect
// ============================================================================
//- Build the connection
void SocketLecroy::TCP_Connect(char *ip_address) throw (lecroy::SocketException)
{
......@@ -162,6 +177,9 @@ void SocketLecroy::TCP_Connect(char *ip_address) throw (lecroy::SocketException)
sConnectedFlag = true;
}
// ============================================================================
// SocketLecroy::TCP_Disconnect
// ============================================================================
//- DisconnectFromScope: disconnect from a network device
void SocketLecroy::TCP_Disconnect(void)
{
......@@ -172,20 +190,28 @@ void SocketLecroy::TCP_Disconnect(void)
}
}
// ============================================================================
// 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::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;
......@@ -193,12 +219,16 @@ void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) throw (lec
//- 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;
......@@ -238,8 +268,11 @@ void SocketLecroy::TCP_WriteDevice(char *buf, int len, bool eoi_flag) throw (lec
}
}
// ============================================================================
// SocketLecroy::TCP_ReadDevice
// ============================================================================
//- Read the device answer
void SocketLecroy::TCP_ReadDevice(char *buf, int len, int *recv_count) throw (lecroy::SocketException)
void SocketLecroy::TCP_ReadDevice(char *buf, int len, int *recv_count)
{
TCP_HEADER header;
int result, accum, space_left, bytes_more, buf_count;
......@@ -250,16 +283,20 @@ void SocketLecroy::TCP_ReadDevice(char *buf, int len, int *recv_count) throw (le
//- 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( ).");
}
rd_set.fd_array[0] = hSocket;
tval.tv_sec = sTimeout;
......@@ -294,8 +331,10 @@ void SocketLecroy::TCP_ReadDevice(char *buf, int len, int *recv_count) throw (le
accum += result;
if (accum>=sizeof(header))
{
break;
}
}
header.iLength = ntohl(header.iLength);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment