V1724_board_channel.cpp

Go to the documentation of this file.
00001 
00002 // Name:        V1724_board_channel.cpp
00003 // Purpose:     
00004 // Author:      NDA
00005 // Modified by: 
00006 // Created:     04/03/06 14:18:40
00007 // RCS-ID:      
00008 // Copyright:   CAEN S.p.A. All rights reserved
00009 // Licence:     
00011 
00012 //#define __TEST__
00013 
00014 #if defined(__GNUG__) && !defined(__APPLE__)
00015 #pragma implementation "V1724_board_channel.h"
00016 #endif
00017 
00018 // For compilers that support precompilation, includes "wx/wx.h".
00019 #include "wx/wxprec.h"
00020 
00021 #ifdef __BORLANDC__
00022 #pragma hdrstop
00023 #endif
00024 
00025 #ifndef WX_PRECOMP
00026 #include "wx/wx.h"
00027 #endif
00028 
00029 #include "appsettings.h"
00030 #include "V1724_board_channel.h"
00031 extern "C" 
00032 {
00033         #include "../include/CAENVMETool/cvt_v1724.h"
00034 }
00035 
00036 
00037 V1724BoardChannel::V1724BoardChannel( GenericBoard* parent, int ch_index, cvt_board_data* p_data, void ( *scope_refresh)( int, bool), wxMutex* p_data_mutex, AppSettings *p_app_settings):
00038                                                                         PhysicalBoardChannel( parent, ch_index, p_data, scope_refresh, p_data_mutex, p_app_settings)
00039 {
00040 }
00041 
00042 V1724BoardChannel::~V1724BoardChannel( void)
00043 {
00044 }
00045 
00046 #ifdef SAMPLE_LOCK
00047 bool V1724BoardChannel:: ReadSamplesCache( UINT32 num_samples)
00048 {
00049         bool ret= false;
00050         int max_log_X;
00051         {
00052                 wxMutexLocker lock( *this->m_p_data_mutex);
00053                 max_log_X= num_samples;
00054         }
00055 
00056         if( !this->m_enabled)
00057         {
00058                 wxMutexLocker lock( this->m_samples_mutex);
00059                 this->m_sample_buffer_count= 0;
00060                 return false;
00061         }
00062         // Check if enough storage
00063         if( max_log_X> (int)this->m_tmp_sample_buffer_size)
00064         {
00065                 delete this->m_p_tmp_sample_buffer;
00066                 this->m_tmp_sample_buffer_size= max_log_X;
00067                 this->m_p_tmp_sample_buffer= new UINT16[ this->m_tmp_sample_buffer_size];
00068         }
00069         // Set the number of requested samples
00070         this->m_tmp_sample_buffer_count= max_log_X;
00071 
00072 #ifdef __TEST__
00073         static double phase= 0;
00074         for( unsigned int i= 0; i< this->m_sample_buffer_count; i++)
00075         {
00076                 this->m_p_tmp_sample_buffer[i]= 0x8000+ (int)(double)( 1000.0* sin( phase+ 6.28*i*10.0/( this->m_tmp_sample_buffer_count)));
00077                 //this->m_p_sample_buffer[i]= 0;
00078         }
00079         ++phase;
00080 
00081     {
00082         //
00083         // Copy to final buffer
00084         wxMutexLocker lock( this->m_samples_mutex);
00085         if( max_log_X> (int)this->m_sample_buffer_size)
00086         {
00087             delete this->m_p_sample_buffer;
00088             this->m_sample_buffer_size= max_log_X;
00089             this->m_p_sample_buffer= new UINT16[ this->m_sample_buffer_size];
00090         }
00091         // Set the number of requested samples
00092         this->m_sample_buffer_count= this->m_tmp_sample_buffer_count;
00093         memcpy( this->m_p_sample_buffer, this->m_p_tmp_sample_buffer, this->m_sample_buffer_count<< 1);
00094 
00095     }
00096         ret= true;
00097 
00098 #else
00099         {
00100                 UINT32 read= this->m_tmp_sample_buffer_count;
00101                 UINT8 board_id;
00102                 UINT32 trigger_time_tag, event_counter;
00103                 if( cvt_V1724_get_buffer_cache( ( cvt_V1724_data*)this->m_p_data, 0, this->m_ch_index, this->m_p_tmp_sample_buffer, &read, &board_id, &trigger_time_tag, &event_counter)== FALSE)
00104                         return false;
00105                 if( read)
00106                 {
00107 
00108                         //
00109                         // Copy to final buffer
00110                         wxMutexLocker lock( this->m_samples_mutex);
00111                         if( max_log_X> (int)this->m_sample_buffer_size)
00112                         {
00113                                 delete this->m_p_sample_buffer;
00114                                 this->m_sample_buffer_size= max_log_X;
00115                                 this->m_p_sample_buffer= new UINT16[ this->m_sample_buffer_size];
00116                         }
00117                         // Set the number of requested samples
00118                         memcpy( this->m_p_sample_buffer, this->m_p_tmp_sample_buffer, read<< 1);
00119 
00120                         this->m_sample_buffer_count= read;
00121                         ret= true;
00122                 }
00123         }
00124 #endif
00125         return ret;
00126 
00127 }
00128 #else
00129 
00130 bool V1724BoardChannel:: ReadSamplesCache( UINT32 num_samples)
00131 {
00132 
00133         bool ret= false;
00134         wxMutexLocker lock( *this->m_p_data_mutex);
00135         if( !this->m_enabled)
00136         {
00137                 this->m_sample_buffer_count= 0;
00138                 return false;
00139         }
00140         // Check if enough storage
00141         if( num_samples> (int)this->m_sample_buffer_size)
00142         {
00143                 delete this->m_p_sample_buffer;
00144                 this->m_sample_buffer_size= num_samples;
00145                 this->m_p_sample_buffer= new UINT16[ this->m_sample_buffer_size];
00146         }
00147         // Set the number of requested samples
00148         this->m_sample_buffer_count= num_samples;
00149 
00150 #ifdef __TEST__
00151         static double phase= 0;
00152         for( unsigned int i= 0; i< this->m_sample_buffer_count; i++)
00153         {
00154                 this->m_p_sample_buffer[i]= 0x8000+ (int)(double)( 1000.0* sin( phase+ 6.28*i*10.0/( this->m_sample_buffer_count)));
00155                 //this->m_p_sample_buffer[i]= 0;
00156         }
00157         ++phase;
00158         ret= true;
00159 #else
00160         {
00161                 UINT32 read= this->m_sample_buffer_count;
00162                 if( cvt_V1724_get_buffer_cache( ( cvt_V1724_data*)this->m_p_data, this->m_ch_index, this->m_p_sample_buffer, &read)== FALSE)
00163                         return false;
00164                 if( read)
00165                 {
00166                         this->m_sample_buffer_count= read;
00167                         ret= true;
00168                 }
00169         }
00170 #endif
00171         return ret;
00172 
00173 }
00174 #endif
00175 
00176 bool V1724BoardChannel:: WriteDACOffset( void)
00177 {
00178         // board offset
00179         int dac_offset= -this->m_DAC_offset_bit;
00180         if( dac_offset> 0x7fff)
00181         {
00182                 dac_offset= 0x7fff;
00183         }
00184         else if( dac_offset< -0x8000)
00185         {
00186                 dac_offset= -0x8000;
00187         }
00188         dac_offset+= 0x8000;
00189         return cvt_V1724_set_channel_offset( ( cvt_V1724_data*) this->m_p_data, 1<< this->m_ch_index, dac_offset)!= FALSE;
00190 }
00191 
00192 bool V1724BoardChannel:: WriteChannelTrigger( void)
00193 {
00194         // channel trigger settings
00195         // bool is_out_enabled= this->m_enabled&& ( this->m_trigger_edge_type!= GenericBoardChannel::TRIGGER_EDGE_TYPE::NO_TRIGGER);
00196         // bool is_in_enabled= this->m_enabled;
00197         // return cvt_V1724_set_channel_trigger( ( cvt_V1724_data*) this->m_p_data, 1<< this->m_ch_index, this->m_trigger_edge_type== GenericBoardChannel::TRIGGER_EDGE_TYPE::FALLING_EDGE, trigger_threshold, this->m_trigger_thr_sample)!= FALSE;
00198         int trigger_threshold= (int)( double)( this->m_trigger_threshold_volt* this->m_volt_2_bit);
00199         if( trigger_threshold> 0x7fff)
00200         {
00201                 trigger_threshold= 0x7fff;
00202         }
00203         else if( trigger_threshold< -0x8000)
00204         {
00205                 trigger_threshold= -0x8000;
00206         }
00207         trigger_threshold+= 0x8000;
00208         return cvt_V1724_set_channel_trigger( ( cvt_V1724_data*) this->m_p_data, 1<< this->m_ch_index, trigger_threshold, this->m_trigger_thr_sample)!= FALSE;
00209 }

Generated on Mon Mar 19 17:14:08 2007 for CAENScope by  doxygen 1.4.6-NO