generic_board_channel.cpp

Go to the documentation of this file.
00001 
00002 // Name:        generic_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 
00013 #if defined(__GNUG__) && !defined(__APPLE__)
00014 #pragma implementation "generic_board_channel.h"
00015 #endif
00016 
00017 // For compilers that support precompilation, includes "wx/wx.h".
00018 #include "wx/wxprec.h"
00019 
00020 #ifdef __BORLANDC__
00021 #pragma hdrstop
00022 #endif
00023 
00024 #ifndef WX_PRECOMP
00025 #include "wx/wx.h"
00026 #endif
00027 #include <wx/filename.h>
00028 
00029 
00030 #include "generic_board_channel.h"
00031 #include "common_ch_control_base.h"
00032 #include "cursor_ch_control.h"
00033 #include "appsettings.h"
00034 #include "drawing_panel.h"
00035 #include "generic_board.h"
00036 
00037 GenericBoardChannel::GenericBoardChannel( GenericBoard* parent, int ch_index, cvt_board_data* p_data, void ( *scope_refresh)( int, bool), wxMutex* p_data_mutex, AppSettings *p_app_settings):
00038                 ScopeRefresh( scope_refresh), m_p_data_mutex( p_data_mutex),
00039                 m_p_data( p_data), m_ch_index( ch_index), m_p_app_settings( p_app_settings), m_p_record_file( NULL),
00040         m_samples_mutex( wxMUTEX_RECURSIVE), m_record_mutex( wxMUTEX_RECURSIVE), m_p_common_ch_control( NULL)
00041 {
00042 
00043         this->m_parent= parent;
00044         this->m_is_recording= false;
00045 
00046         this->m_medium_value= 0;
00047         this->m_overload_up= false;
00048         this->m_overload_down= false;
00049         for( int i= 0; i< SCOPE_NUM_PANELS; i++)
00050         {
00051                 this->m_line_pen[ i]= NULL;
00052                 this->m_trigger_pen[ i]= NULL;
00053                 this->m_trigger_brush[ i]= NULL;
00054                 this->m_volt_2_div[ i]= 1.0;
00055                 this->m_cursor_position[ i]= 0;
00056                 this->m_cursor_enabled[ i]= false;
00057                 this->m_div_2_pix_Y[ i]= 0;
00058 
00059                 this->m_offset_y[ i]= 0;
00060                 this->m_volt_2_pix[ i]= 0;
00061                 this->m_div_2_pix_X[ i]= 0;
00062                 this->m_div_2_pix_Y[ i]= 0;
00063                 this->m_pix_Y[ i]= 0;
00064                 this->m_pix_X[ i]= 0;
00065                 this->m_left_div_2_pix_Y[ i]= 0;
00066                 this->m_left_pix_Y[ i]= 0;
00067                 this->m_left_pix_X[ i]= 0;
00068                 this->m_cursor_position[ i]= 0;
00069                 this->m_cursor_enabled[ i]= false;
00070         }
00071 }
00072 
00073 GenericBoardChannel::~GenericBoardChannel(void)
00074 {
00075         for( int i= 0; i< SCOPE_NUM_PANELS; i++)
00076         {
00077                 if( this->m_line_pen[ i]!= NULL)
00078                 {
00079                         delete this->m_line_pen[ i];
00080                         this->m_line_pen[ i]= NULL;
00081                 }
00082 
00083                 if( this->m_trigger_pen[ i]!= NULL)
00084                 {
00085                         delete this->m_trigger_pen[ i];
00086                         this->m_trigger_pen[ i]= NULL;
00087                 }
00088                 if( this->m_trigger_brush[ i]!= NULL)
00089                 {
00090                         delete this->m_trigger_brush[ i];
00091                         this->m_trigger_brush[ i]= NULL;
00092                 }
00093         }
00094         if( this->m_p_record_file)
00095         {
00096                 delete this->m_p_record_file;
00097                 this->m_p_record_file= NULL;
00098         }
00099 }
00100 
00101 bool GenericBoardChannel::LoadConfig( wxConfigBase* p_config, const wxString& base_section)
00102 {
00103         /*
00104                 Application setting channel parameters' file structure
00105 
00106           |- ENABLED= 1
00107           |- SCOPE_VIEW_ENABLED_0= 1       // Enable channel view in scope 1
00108           |- SCOPE_VIEW_ENABLED_1= 1       // Enable channel view in scope 2
00109           |- SCOPE_VIEW_ENABLED_2= 1       // Enable channel view in scope 3
00110           |- SCOPE_VIEW_ENABLED_3= 1       // Enable channel view in scope 4
00111           |- LINE_COLOR_0= 0xaaff00        // RGB color Scope 1
00112           |- LINE_WIDTH_0= 1               // Pixels Scope 1
00113           |- OFFSET_VOLT_0= 0.0            // Volts Scope 1
00114           |- VOLT_2_DIV_0= 4               // Div/ Volts conversion factor ( div_val= VOLT_2_DIV* volt_val) Scope 1
00115           |- LINE_COLOR_1= 0xaaff00        // RGB color Scope 2
00116           |- LINE_WIDTH_1= 1               // Pixels Scope 2
00117           |- OFFSET_VOLT_1= 0.0            // Volts Scope 2
00118           |- VOLT_2_DIV_1= 4               // Div/ Volts conversion factor ( div_val= VOLT_2_DIV* volt_val) Scope 2
00119           |- LINE_COLOR_2= 0xaaff00        // RGB color Scope 3
00120           |- LINE_WIDTH_2= 1               // Pixels Scope 3
00121           |- OFFSET_VOLT_2= 0.0            // Volts Scope 3
00122           |- VOLT_2_DIV_2= 4               // Div/ Volts conversion factor ( div_val= VOLT_2_DIV* volt_val) Scope 3
00123           |- LINE_COLOR_3= 0xaaff00        // RGB color Scope 4
00124           |- LINE_WIDTH_3= 1               // Pixels Scope 4
00125           |- OFFSET_VOLT_3= 0.0            // Volts Scope 4
00126           |- VOLT_2_DIV_3= 4               // Div/ Volts conversion factor ( div_val= VOLT_2_DIV* volt_val) Scope 4
00127                   |- VOLT_2_BIT= 26214.4           // Bits/ Volt conversion factor ( bit_val= VOLT_2_BIT* volt_val) (2^16/2.500) Scope 1
00128           |- RECORD_RATE_DIVIDER= 1        // Samples' recording rate divider
00129           |- RECORD_ENABLED= 1             // Samples' recording enabled
00130           |- RECORD_FORMAT= 0              // Record save format 0: hex 1: ASCII decimal 2: ASCII hexdecimal
00131         */
00132 
00133         //
00134         // Get channel enable bit
00135         this->m_enabled= FALSE;
00136         p_config->Read( base_section+ _("ENABLED"), &this->m_enabled, 0);
00137 
00138         //
00139         // Get Enable channel view in scope #
00140         for( int scope_index= 0; scope_index< SCOPE_NUM_PANELS; scope_index++)
00141         {
00142                 wxString scope_index_string= wxString::Format( "_%d", scope_index);
00143 
00144                 this->m_scope_view_enabled[ scope_index]= FALSE;
00145                 p_config->Read( base_section+ _("SCOPE_VIEW_ENABLED")+ scope_index_string, &this->m_scope_view_enabled[ scope_index], 0);
00146         }
00147 
00148         for( int scope_index= 0; scope_index< SCOPE_NUM_PANELS; scope_index++)
00149         {
00150                 wxString scope_index_string= wxString::Format( "_%d", scope_index);
00151                 //
00152                 // Get line color
00153                 wxString line_color_rgb_string= _("");
00154                 p_config->Read( base_section+ _("LINE_COLOR")+ scope_index_string , &line_color_rgb_string, _("0xffffff"));
00155                 unsigned long line_color_rgb;
00156                 wxString hex_part;
00157                 if( line_color_rgb_string.Upper().StartsWith(_("0X"), &hex_part))
00158                 {
00159                         // Hex format
00160                         if( !hex_part.Trim().ToULong( &line_color_rgb, 16))
00161                         {
00162                                 line_color_rgb= 0x00ffffff;
00163                         }
00164                 }
00165                 else
00166                 {
00167                         // Decimal format
00168                         if( !line_color_rgb_string.Trim().ToULong( &line_color_rgb, 10))
00169                         {
00170                                 line_color_rgb= 0x00ffffff;
00171                         }
00172                 }
00173                 this->m_line_color[ scope_index].Set( (line_color_rgb>> 16)& 0xff, (line_color_rgb>> 8)& 0xff, line_color_rgb& 0xff);
00174                 //
00175                 // Get line width
00176                 this->m_line_width[ scope_index]= 1;
00177                 p_config->Read( base_section+ _("LINE_WIDTH")+ scope_index_string , &this->m_line_width[ scope_index], 1);
00178                 //
00179                 // Get offset_volt
00180                 this->m_offset_y[ scope_index]= 0;
00181                 p_config->Read( base_section+ _("OFFSET_Y")+ scope_index_string , &this->m_offset_y[ scope_index], 0.0);
00182                 //
00183                 // Get div_2_volt
00184                 double value= 1.0;
00185                 p_config->Read( base_section+ _("VOLT_2_DIV")+ scope_index_string , &value, 4.0);
00186                 this->SetVolt2Div( scope_index, value);
00187         }
00188         //
00189         // Get volt_2_bit
00190         this->m_bit_2_volt= 1.0;
00191         this->m_volt_2_bit= 1.0;
00192         p_config->Read( base_section+ _("VOLT_2_BIT"), &this->m_volt_2_bit, 26214.4);
00193         if( this->m_volt_2_bit== 0)
00194                 this->m_volt_2_bit= 1.0;
00195         this->m_bit_2_volt= 1/ this->m_volt_2_bit;
00196 
00197         //
00198         // Get record rate divider
00199         this->m_record_rate_divider= 1;
00200         p_config->Read( base_section+ _("RECORD_RATE_DIVIDER"), &this->m_record_rate_divider, 1);
00201         if( this->m_record_rate_divider<= 0)
00202         {
00203                 this->m_record_rate_divider= 1;
00204         }
00205         //
00206         // Get record enable bit
00207         this->m_record_enabled= FALSE;
00208         p_config->Read( base_section+ _("RECORD_ENABLED"), &this->m_record_enabled, 0);
00209         //
00210         // Get record format type
00211         int record_format_type;
00212         p_config->Read( base_section+ _("RECORD_FORMAT"), &record_format_type, (int)GenericBoardChannel::HEX);
00213         this->m_record_format_type= (GenericBoardChannel::RECORD_FORMAT_TYPE)record_format_type;
00214 
00215         return true;
00216 
00217 }
00218 bool GenericBoardChannel::SaveConfig( wxConfigBase* p_config, const wxString& base_section)
00219 {
00220 
00221         //
00222         // Set channel enable bit
00223         if( !p_config->Write( base_section+ _("ENABLED"), this->m_enabled? 1: 0))
00224                 return false;
00225 
00226         //
00227         // Set Enable channel view in scope #
00228         for( int scope_index= 0; scope_index< SCOPE_NUM_PANELS; scope_index++)
00229         {
00230                 wxString scope_index_string= wxString::Format( "_%d", scope_index);
00231 
00232                 if( !p_config->Write( base_section+ _("SCOPE_VIEW_ENABLED")+ scope_index_string, this->m_scope_view_enabled[ scope_index]? 1: 0))
00233                         return false;
00234         }
00235 
00236         for( int scope_index= 0; scope_index< SCOPE_NUM_PANELS; scope_index++)
00237         {
00238                 wxString scope_index_string= wxString::Format( "_%d", scope_index);
00239                 //
00240                 // Set line color
00241                 wxString line_color_rgb_string= wxString::Format( "0x%02x%02x%02x", this->m_line_color[ scope_index].Red(), this->m_line_color[ scope_index].Green(), this->m_line_color[ scope_index].Blue());
00242                 if( !p_config->Write( base_section+ _("LINE_COLOR")+ scope_index_string, line_color_rgb_string))
00243                         return false;
00244                 //
00245                 // Set line width
00246                 if( !p_config->Write( base_section+ _("LINE_WIDTH")+ scope_index_string, this->m_line_width[ scope_index]))
00247                         return false;
00248                 //
00249                 // Set offset_volt
00250                 if( !p_config->Write( base_section+ _("OFFSET_Y")+ scope_index_string, this->m_offset_y[ scope_index]))
00251                         return false;
00252                 //
00253                 // Set volt_2_div
00254                 if( !p_config->Write( base_section+ _("VOLT_2_DIV")+ scope_index_string, this->m_volt_2_div[ scope_index]))
00255                         return false;
00256         }
00257         //
00258         // Set volt_2_bit
00259         if( !p_config->Write( base_section+ _("VOLT_2_BIT"), this->m_volt_2_bit))
00260                 return false;
00261 
00262         //
00263         // Set record rate divider
00264         if( this->m_record_rate_divider<= 0)
00265         {
00266                 this->m_record_rate_divider= 1;
00267         }
00268         if( !p_config->Write( base_section+ _("RECORD_RATE_DIVIDER"), this->m_record_rate_divider))
00269                 return false;
00270         //
00271         // Set record enable bit
00272         if( !p_config->Write( base_section+ _("RECORD_ENABLED"), this->m_record_enabled? 1: 0))
00273                 return false;
00274 
00275         //
00276         // Set record format type
00277         if( !p_config->Write( base_section+ _("RECORD_FORMAT"), (int)this->m_record_format_type))
00278                 return false;
00279         return true;
00280 }
00281 
00282 bool GenericBoardChannel::SetLinePen( int scope_index, const wxPen* line_pen, const wxPen* trigger_pen)
00283 {
00284         if( this->m_line_pen[ scope_index]!= NULL)
00285         {
00286                 delete this->m_line_pen[ scope_index];
00287                 this->m_line_pen[ scope_index]= NULL;
00288         }
00289         this->m_line_pen[ scope_index]= ( line_pen== NULL)? NULL: new wxPen( *line_pen);
00290 
00291         if( this->m_trigger_pen[ scope_index]!= NULL)
00292         {
00293                 delete this->m_trigger_pen[ scope_index];
00294                 this->m_trigger_pen[ scope_index]= NULL;
00295         }
00296         if( this->m_trigger_brush[ scope_index]!= NULL)
00297         {
00298                 delete this->m_trigger_brush[ scope_index];
00299                 this->m_trigger_brush[ scope_index]= NULL;
00300         }
00301         if( trigger_pen== NULL)
00302         {
00303                 this->m_trigger_pen[ scope_index]= ( line_pen== NULL)? NULL: new wxPen( *line_pen);
00304                 this->m_trigger_brush[ scope_index]= new wxBrush( line_pen->GetColour());
00305         }
00306         else
00307         {
00308                 this->m_trigger_pen[ scope_index]= new wxPen( *trigger_pen);
00309                 this->m_trigger_brush[ scope_index]= new wxBrush( line_pen->GetColour());
00310         }
00311 
00312         if( this->ScopeRefresh!= NULL)
00313                 (this->ScopeRefresh)( scope_index, false);
00314         return true;
00315 }
00316 void GenericBoardChannel::DrawPosition( int scope_index, wxDC &dc)
00317 {
00318         wxMutexLocker lock( this->m_p_app_settings->m_mutex);
00319 
00320         const int MARKER_SIZE_PIX_Y= 2;
00321         const int CANVAS_SIZE_PIX_X= 17;
00322         const int MARKER_ARROW_PIX_X= 5;
00323         
00324         static wxPoint marker[ ] =
00325         {
00326                 wxPoint( 2, -MARKER_SIZE_PIX_Y),
00327                 wxPoint( CANVAS_SIZE_PIX_X- MARKER_ARROW_PIX_X, -MARKER_SIZE_PIX_Y),
00328                 wxPoint( CANVAS_SIZE_PIX_X, 0),
00329                 wxPoint( CANVAS_SIZE_PIX_X- MARKER_ARROW_PIX_X, +MARKER_SIZE_PIX_Y),
00330                 wxPoint( 2, +MARKER_SIZE_PIX_Y),
00331         };
00332         const int marker_points= sizeof( marker)/ sizeof( marker[0]);
00333 
00334         if( !( this->m_enabled&& this->m_scope_view_enabled[ scope_index])|| 
00335                 ( this->m_trigger_pen== NULL)||
00336                 ( this->m_trigger_brush== NULL))
00337                 return;
00338         double offset_y= this->m_left_div_2_pix_Y[ scope_index]*( (double)( DrawingCanvas::NUM_DIV_PER_SCREEN>> 1)+ this->m_offset_y[ scope_index] );
00339 
00340         if( this->m_trigger_brush[ scope_index])
00341                 dc.SetBrush( *this->m_trigger_brush[ scope_index]);
00342         if( this->m_trigger_pen[ scope_index])
00343                 dc.SetPen( *this->m_trigger_pen[ scope_index]);
00344         dc.DrawPolygon( marker_points, marker, 0, (int)(double)( this->m_left_pix_Y[ scope_index]- offset_y), wxODDEVEN_RULE);
00345         dc.SetPen( wxNullPen);
00346         dc.SetBrush( wxNullBrush);
00347 }
00348 
00349 void GenericBoardChannel::DrawCursor( int scope_index, wxDC &dc)
00350 {
00351         wxMutexLocker lock( this->m_p_app_settings->m_mutex);
00352         if( !( this->m_enabled&& this->m_scope_view_enabled[ scope_index])|| 
00353                 !this->m_cursor_enabled[ scope_index]|| 
00354                 ( this->m_trigger_pen[ scope_index]== NULL))
00355                 return;
00356         if( this->m_trigger_pen[ scope_index])
00357                 dc.SetPen( *this->m_trigger_pen[ scope_index]);
00358         int offset_x= this->Sec2Pix( scope_index, this->m_p_app_settings->m_offset_sec[ scope_index]+ this->Sample2Sec( this->m_cursor_position[ scope_index]));
00359         dc.DrawLine( offset_x, 0, offset_x, this->m_pix_Y[ scope_index]);
00360         
00361         // Restore original pen
00362         dc.SetPen( wxNullPen);
00363 }
00364 
00365 void GenericBoardChannel::DrawSamples( int scope_index, wxDC &dc)
00366 {
00367         wxMutexLocker lock( this->m_p_app_settings->m_mutex);
00368 #ifdef SAMPLE_LOCK
00369         wxMutexLocker sample_lock( this->m_samples_mutex);
00370 #endif
00371         if( !( this->m_enabled&& this->m_scope_view_enabled[ scope_index]))
00372                 return;
00373         UINT32 buffer_count= this->GetBufferCount();
00374         if( !buffer_count)
00375                 return;
00376 
00377         double cursor_value= 0;
00378         int sample_bit;
00379         int cursor_pos_x= this->m_cursor_position[ scope_index];
00380         if( this->m_line_pen[ scope_index])
00381                 dc.SetPen( *this->m_line_pen[ scope_index]);
00382         double offset_x= this->m_p_app_settings->m_offset_sec[ scope_index];
00383         //double offset_y= this->m_offset_volt;
00384         double offset_y= this->m_div_2_pix_Y[ scope_index]*( (double)(int)( DrawingCanvas::NUM_DIV_PER_SCREEN>> 1)+ this->m_offset_y[ scope_index]);
00385 
00386         int x0, y0, x1, y1;
00387         int i= this->Sec2Sample( this->Pix2Sec( scope_index, 0)- offset_x);
00388         if( i< 0)
00389         {
00390                 i= 0;
00391         }
00392         else if(( (UINT32)i>= buffer_count)&& ( i>= this->m_p_app_settings->m_max_log_X))
00393         {
00394                 i= ( (int)buffer_count> this->m_p_app_settings->m_max_log_X)? this->m_p_app_settings->m_max_log_X: buffer_count;
00395         }
00396         double sample_volt= this->GetSampleVolt( i);
00397         sample_bit= this->GetSample(i);
00398         x0= this->Sec2Pix( scope_index, offset_x+ this->Sample2Sec( i));
00399         //y0= this->PixY2Dc( this->Volt2Pix( offset_y+ sample_volt));
00400         y0= this->PixY2Dc( scope_index, (int)(double)( offset_y+ (double)this->Volt2Pix( scope_index, sample_volt)));
00401         bool overload_down= false;
00402         bool overload_up= false;
00403     int medium_value_count= 1;
00404         this->m_medium_value= sample_volt;
00405         if( sample_bit>= (0x7ffc))
00406         {
00407                 overload_up= true;
00408         }
00409         else if( sample_bit<= -0x7ffc)
00410         {
00411                 overload_down= true;
00412         }
00413         if( cursor_pos_x== 0)
00414         {
00415                 cursor_value= sample_volt* 1000;
00416         }
00417         int step= this->Sec2Sample( this->Pix2Sec( scope_index, 1));
00418         if( step== 0)
00419                 step= 1;
00420         i+= step;
00421         for( ; ( (UINT32)i< buffer_count)&& ( i< this->m_p_app_settings->m_max_log_X); i+= step)
00422         {
00423                 sample_volt= this->GetSampleVolt( i);
00424                 sample_bit= this->GetSample(i);
00425                 if( sample_bit>= 0x7ffc)
00426                 {
00427                         overload_up= true;
00428                 }
00429                 else if( sample_bit<= -0x7ffc)
00430                 {
00431                         overload_down= true;
00432                 }
00433                 this->m_medium_value+= sample_volt;
00434         ++medium_value_count;
00435                 x1= this->Sec2Pix( scope_index, offset_x+ this->Sample2Sec( i));
00436                 y1= this->PixY2Dc( scope_index, (int)(double)(offset_y+ (double)this->Volt2Pix( scope_index, sample_volt)));
00437 
00438                 if(( cursor_pos_x>= i)&&
00439                         ( cursor_pos_x< i+ step))
00440                 {
00441                         cursor_value= sample_volt* 1000;
00442                 }
00443                 if( x0== x1)
00444                         continue;
00445                 if( x1> this->m_pix_X[ scope_index]+ 10)
00446                         break;
00447                 if( x1>= -10)
00448                         dc.DrawLine( x0, y0, x1, y1);
00449                 x0= x1;
00450                 y0= y1;
00451         }
00452         dc.SetPen( wxNullPen);
00453         this->m_medium_value/= medium_value_count;
00454 
00455         // Update controls here
00456         this->m_p_common_ch_control->SetMediumLabel( this->m_medium_value* 1000);
00457         if( ( overload_down^ this->m_overload_down) || ( overload_up^ this->m_overload_up))
00458         {
00459                 this->m_p_common_ch_control->SetOverloadBackground( ( overload_down|| overload_up)? wxColour(255, 0, 0): wxColour(0, 255, 0));
00460                 this->m_overload_down= overload_down;
00461                 this->m_overload_up= overload_up;
00462         }
00463         if( this->m_cursor_enabled[ scope_index])
00464         {
00465                 this->m_p_cursor_ch_control[ scope_index]->m_cursor_value_control->SetLabel( wxString::Format( "%.3f", cursor_value));
00466         }
00467 }
00468 void GenericBoardChannel::SetVolt2Div( int scope_index, double volt_2_div)
00469 {
00470         if( volt_2_div< 0.0000001)
00471                 volt_2_div= 0.0000001;
00472         this->m_volt_2_div[ scope_index]= volt_2_div;
00473         //this->m_div_2_volt= 1/ volt_2_div;
00474 
00475         this->m_volt_2_pix[ scope_index]= this->m_volt_2_div[ scope_index]* this->m_div_2_pix_Y[ scope_index];
00476 }
00477 inline int GenericBoardChannel::Sec2Pix( int scope_index, double value)
00478 { 
00479         return (int)(double)( this->m_p_app_settings->m_sec_2_pix[ scope_index]* value);
00480 }
00481 inline double GenericBoardChannel::Sample2Sec( int value)
00482 { 
00483         return this->m_p_app_settings->m_sample_2_sec* (double)value;
00484 }
00485 inline double GenericBoardChannel::Pix2Sec( int scope_index, int value)
00486 { 
00487         return (double)( value)/ this->m_p_app_settings->m_sec_2_pix[ scope_index];
00488 }
00489 inline int GenericBoardChannel::Sec2Sample( double value)
00490 { 
00491         return (int)(double)( (double)value/ this->m_p_app_settings->m_sample_2_sec);
00492 }
00493 void GenericBoardChannel::SetDiv2Pix( int scope_index, double div_2_pix_Y)
00494 {
00495         wxMutexLocker lock( this->m_p_app_settings->m_mutex);
00496 
00497         this->m_div_2_pix_Y[ scope_index]= div_2_pix_Y;
00498         this->m_volt_2_pix[ scope_index]= this->m_volt_2_div[ scope_index]* this->m_div_2_pix_Y[ scope_index];  
00499 }
00500 void GenericBoardChannel::SetLeftDiv2Pix( int scope_index, double div_2_pix_Y)
00501 {
00502         wxMutexLocker lock( this->m_p_app_settings->m_mutex);
00503 
00504         this->m_left_div_2_pix_Y[ scope_index]= div_2_pix_Y;
00505         //this->m_volt_2_pix= this->m_volt_2_div* this->m_div_2_pix_Y;  
00506 }
00507 wxString GenericBoardChannel::GetRecordChannelNumber( void)
00508 {
00509         return wxString::Format( "C%02d", this->m_ch_index);
00510 }
00511 bool GenericBoardChannel::ToggleRecordStatus( const wxString &path, const wxString &file_name, const wxString &timestamp, bool start)
00512 {
00513         wxMutexLocker lock( this->m_record_mutex);
00514         if( start)
00515         {
00516                 // Start recording request
00517                 if( this->m_is_recording)
00518                         // Already recording
00519                         return true;
00520                 if( !this->m_record_enabled)
00521                         return true;
00522                 // Create recording file
00523                 if( this->m_p_record_file)
00524                 {
00525                         delete this->m_p_record_file;
00526                         this->m_p_record_file= NULL;
00527                 }
00528                 wxString file_ext= _("hex");
00529                 switch( this->m_record_format_type)
00530                 {
00531                 case ASCII_DEC:
00532                         file_ext= _("adc");
00533                         break;
00534                 case ASCII_HEX:
00535                         file_ext= _("ahx");
00536                         break;
00537                 case HEX:
00538                 default:
00539                         this->m_record_format_type= HEX;
00540                         file_ext= _("bhx");
00541                         break;
00542                 }
00543                 this->m_record_sample_counter= 0;
00544                 // Append channel id & timestamp
00545                 wxString new_file_name( wxString::Format( "%s%s_%s", file_name.c_str(), this->GetRecordChannelNumber( ), timestamp.c_str()));
00546                 wxFileName filename( path, new_file_name, file_ext);
00547                 filename.Normalize();
00548                 this->m_p_record_file= new wxFile( filename.GetFullPath(), wxFile::write_append);
00549                 if( !this->m_p_record_file->IsOpened())
00550                 {
00551                         delete this->m_p_record_file;
00552                         this->m_p_record_file= NULL;
00553                         return false;
00554                 }
00555         }
00556         else
00557         {
00558                 // Stop recording request
00559                 if( !this->m_is_recording)
00560                         // Nothing to do
00561                         return true;
00562 
00563                 // Close recording buffer
00564                 if( this->m_p_record_file)
00565                 {
00566                         this->m_p_record_file->Close();
00567                         delete this->m_p_record_file;
00568                         this->m_p_record_file= NULL;
00569                 }
00570         }
00571         this->m_is_recording= start;
00572         return true;
00573 }
00574 bool GenericBoardChannel::RecordSamples( void)
00575 {
00576         wxMutexLocker lock( this->m_record_mutex);
00577         if( !this->m_record_enabled)
00578                 return true;
00579         if( !this->m_p_record_file)
00580                 return false;
00581 
00582         // Do Save to file ...
00583         switch( this->m_record_format_type)
00584         {
00585         case ASCII_DEC:
00586                 {
00587                         // Text dec format
00588                         wxString line;
00589                         for( UINT32 i= 0; i< this->GetBufferCount(); i++)
00590                         {
00591                                 if( !this->m_record_sample_counter)
00592                                 {
00593                                         // record converted data
00594                                         line= wxString::Format( "%d\r\n", this->GetSample( i));
00595                                         this->m_p_record_file->Write( line);
00596                                 }
00597                                 if( ++this->m_record_sample_counter>= (UINT32)this->m_record_rate_divider)
00598                                 {
00599                                         this->m_record_sample_counter= 0;
00600                                 }
00601                         }
00602                 }
00603                 break;
00604         case ASCII_HEX:
00605                 {
00606                         // Text hex format
00607                         wxString line;
00608                         for( UINT32 i= 0; i< this->GetBufferCount(); i++)
00609                         {
00610                                 if( !this->m_record_sample_counter)
00611                                 {
00612                                         // record raw data
00613                                         line= wxString::Format( "%08X\r\n", this->GetSample( i));
00614                                         this->m_p_record_file->Write( line);
00615                                 }
00616                                 if( ++this->m_record_sample_counter>= (UINT32)this->m_record_rate_divider)
00617                                 {
00618                                         this->m_record_sample_counter= 0;
00619                                 }
00620                         }
00621                 }
00622                 break;
00623         case HEX:
00624         default:
00625                 {
00626                         // Binary hex format
00627                         INT32 sample;
00628                         for( UINT32 i= 0; i< this->GetBufferCount(); i++)
00629                         {
00630                                 if( !this->m_record_sample_counter)
00631                                 {
00632                                         // record raw data
00633                                         sample= this->GetSample( i);
00634                                         this->m_p_record_file->Write( &sample, sizeof( sample));
00635                                 }
00636                                 if( ++this->m_record_sample_counter>= (UINT32)this->m_record_rate_divider)
00637                                 {
00638                                         this->m_record_sample_counter= 0;
00639                                 }
00640                         }
00641                 }
00642                 break;
00643         }
00644         return true;
00645 }
00646 void GenericBoardChannel::SetEnable( bool enable)
00647 {
00648         if( this->m_p_common_ch_control)
00649                 this->m_p_common_ch_control->SetEnable( enable);
00650 }
00651 

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