00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifdef WX_PRECOMP
00010 #include "wx_pch.h"
00011 #endif
00012 #include "ChannelPanelImpl.h"
00013 #include "N1568DemoMain.h"
00014
00015 ChannelPanelImpl::ChannelPanelImpl( wxWindow* parent, N1568DemoFrame* p_main_frame)
00016 : ChannelPanel( parent), m_channel_id( -1), m_is_connect( false), m_p_main_frame( p_main_frame) {
00017 this->m_p_board_data= m_p_main_frame->GetBoardData();
00018 this->SetDirty( false);
00019 }
00020
00021 ChannelPanelImpl::~ChannelPanelImpl() {
00022
00023 }
00024
00025 void ChannelPanelImpl::ShowLabels( bool show) {
00026 this->m_cfd_threshold_staticText->Show( show);
00027 this->m_cfd30_out_width_staticText->Show( show);
00028 this->m_pole_zero_adj_staticText->Show( show);
00029 this->m_fine_gain_staticText->Show( show);
00030 this->m_shaping_time_staticText->Show( show);
00031 this->m_coarse_gain_staticText->Show( show);
00032 this->m_gain_timing_staticText->Show( show);
00033 this->m_input_polarity_staticText->Show( show);
00034 this->m_stretcher_enable_staticText->Show( show);
00035 }
00036
00037 void ChannelPanelImpl::SetChannelId( int channel_id) {
00038 this->m_channel_id= channel_id;
00039
00040 wxString text( _("Ch "));
00041 this->m_channel_staticText->SetLabel( text<< channel_id);
00042 }
00043 void ChannelPanelImpl::EnableCommunication( bool enable) {
00044 this->m_is_connect= enable;
00045 this->m_read_button->Enable( this->m_is_connect);
00046 this->m_write_button->Enable( this->m_is_dirty&& this->m_is_connect);
00047 }
00048 void ChannelPanelImpl::OnCFThChanged( wxSpinEvent& ) {
00049 this->m_CFTh_changed= true;
00050 this->SetDirty( true);
00051 }
00052 void ChannelPanelImpl::OnCFWdtChanged( wxSpinEvent& ) {
00053 this->m_CFWdt_changed= true;
00054 this->SetDirty( true);
00055 }
00056 void ChannelPanelImpl::OnPZChanged( wxSpinEvent& ) {
00057 this->m_PZ_changed= true;
00058 this->SetDirty( true);
00059 }
00060 void ChannelPanelImpl::OnFGChanged( wxSpinEvent& ) {
00061 this->m_FG_changed= true;
00062 this->SetDirty( true);
00063 }
00064 void ChannelPanelImpl::OnSHChanged( wxSpinEvent& ) {
00065 this->m_SH_changed= true;
00066 this->SetDirty( true);
00067 }
00068 void ChannelPanelImpl::OnCGChanged( wxSpinEvent& ) {
00069 this->m_CG_changed= true;
00070 this->SetDirty( true);
00071 }
00072 void ChannelPanelImpl::OnCGTChanged( wxSpinEvent& ) {
00073 this->m_CGT_changed= true;
00074 this->SetDirty( true);
00075 }
00076 void ChannelPanelImpl::OnInChanged( wxCommandEvent& ) {
00077 this->m_In_changed= true;
00078 this->SetDirty( true);
00079 }
00080 void ChannelPanelImpl::OnSTRChanged( wxCommandEvent& ) {
00081 this->m_STR_changed= true;
00082 this->SetDirty( true);
00083 }
00084 void ChannelPanelImpl::ResetChangeFlags() {
00085 this->m_CFTh_changed= false;
00086 this->m_CFWdt_changed= false;
00087 this->m_PZ_changed= false;
00088 this->m_FG_changed= false;
00089 this->m_SH_changed= false;
00090 this->m_CG_changed= false;
00091 this->m_CGT_changed= false;
00092 this->m_In_changed= false;
00093 this->m_STR_changed= false;
00094 }
00095 void ChannelPanelImpl::AddToLogger( const wxString &msg, LOG_MESSAGE_TYPE type) {
00096 this->m_p_main_frame->AddToLogger( msg, type);
00097 }
00098 void ChannelPanelImpl::OnWriteClicked( wxCommandEvent& ) {
00099
00100 if ( !N1568_set_channel( this->m_p_board_data, this->m_channel_id, NULL)) {
00101 wxString msg( _("Error while writing channel id "));
00102 msg<< this->m_channel_id;
00103 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00104 dlg.ShowModal();
00105 this->AddToLogger( msg);
00106 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00107 return;
00108 } else {
00109 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00110 }
00111
00112 N1568_channel_status channel_status;
00113
00114 if ( this->m_CFTh_changed) {
00115 UINT8 value= (UINT8)this->m_cfd_threshold_spinCtrl->GetValue();
00116 if ( !N1568_set_discr_thr( this->m_p_board_data, value, &channel_status)) {
00117 wxString msg( _("Error while writing CFTh "));
00118 msg<< value;
00119 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00120 dlg.ShowModal();
00121 this->AddToLogger( msg);
00122 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00123 return;
00124 } else {
00125 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00126
00127 UINT8 read_value= channel_status.m_discr_thr;
00128 if ( read_value!= value) {
00129 wxString msg( _("CFTh readout mismatch: "));
00130 msg<< _("written: ")<< value<< _(" read: ")<< read_value;
00131 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00132 dlg.ShowModal();
00133 this->AddToLogger( msg);
00134 }
00135 }
00136 }
00137 if ( this->m_CFWdt_changed) {
00138 UINT8 value= (UINT8)this->m_cfd30_out_width_spinCtrl->GetValue();
00139 if ( !N1568_set_cfd_out_width( this->m_p_board_data, value, &channel_status)) {
00140 wxString msg( _("Error while writing CFWdt "));
00141 msg<< value;
00142 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00143 dlg.ShowModal();
00144 this->AddToLogger( msg);
00145 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00146 return;
00147 } else {
00148 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00149
00150 UINT8 read_value= channel_status.m_cfd_out_width;
00151 if ( read_value!= value) {
00152 wxString msg( _("CFWdt readout mismatch: "));
00153 msg<< _("written: ")<< value<< _(" read: ")<< read_value;
00154 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00155 dlg.ShowModal();
00156 this->AddToLogger( msg);
00157 }
00158 }
00159 }
00160 if ( this->m_PZ_changed) {
00161 UINT8 value= (UINT8)this->m_pole_zero_adj_spinCtrl->GetValue();
00162 if ( !N1568_set_pole_zero_adj( this->m_p_board_data, value, &channel_status)) {
00163 wxString msg( _("Error while writing P/Z adjust "));
00164 msg<< value;
00165 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00166 dlg.ShowModal();
00167 this->AddToLogger( msg);
00168 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00169 return;
00170 } else {
00171 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00172
00173 UINT8 read_value= channel_status.m_pole_zero_adj;
00174 if ( read_value!= value) {
00175 wxString msg( _("P/Z adjust readout mismatch: "));
00176 msg<< _("written: ")<< value<< _(" read: ")<< read_value;
00177 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00178 dlg.ShowModal();
00179 this->AddToLogger( msg);
00180 }
00181 }
00182 }
00183 if ( this->m_FG_changed) {
00184 UINT8 value= (UINT8)this->m_fine_gain_spinCtrl->GetValue();
00185 if ( !N1568_set_fine_gain( this->m_p_board_data, value, &channel_status)) {
00186 wxString msg( _("Error while writing Fine gain "));
00187 msg<< value;
00188 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00189 dlg.ShowModal();
00190 this->AddToLogger( msg);
00191 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00192 return;
00193 } else {
00194 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00195
00196 UINT8 read_value= channel_status.m_fine_gain;
00197 if ( read_value!= value) {
00198 wxString msg( _("Fine gain readout mismatch: "));
00199 msg<< _("written: ")<< value<< _(" read: ")<< read_value;
00200 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00201 dlg.ShowModal();
00202 this->AddToLogger( msg);
00203 }
00204 }
00205 }
00206 if ( this->m_SH_changed) {
00207 UINT8 value= (UINT8)this->m_shaping_time_spinCtrl->GetValue();
00208 if ( !N1568_set_shape( this->m_p_board_data, value, &channel_status)) {
00209 wxString msg( _("Error while writing Shaping time "));
00210 msg<< value;
00211 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00212 dlg.ShowModal();
00213 this->AddToLogger( msg);
00214 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00215 return;
00216 } else {
00217 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00218
00219 UINT8 read_value= channel_status.m_shape_setting;
00220 if ( read_value!= value) {
00221 wxString msg( _("Shaping time readout mismatch: "));
00222 msg<< _("written: ")<< value<< _(" read: ")<< read_value;
00223 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00224 dlg.ShowModal();
00225 this->AddToLogger( msg);
00226 }
00227 }
00228 }
00229 if ( this->m_CG_changed) {
00230 UINT8 value= (UINT8)this->m_coarse_gain_spinCtrl->GetValue();
00231 if ( !N1568_set_coarse_gain( this->m_p_board_data, value, &channel_status)) {
00232 wxString msg( _("Error while writing coarse gain "));
00233 msg<< value;
00234 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00235 dlg.ShowModal();
00236 this->AddToLogger( msg);
00237 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00238 return;
00239 } else {
00240 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00241
00242 UINT8 read_value= channel_status.m_coarse_gain;
00243 if ( read_value!= value) {
00244 wxString msg( _("Coarse gain readout mismatch: "));
00245 msg<< _("written: ")<< value<< _(" read: ")<< read_value;
00246 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00247 dlg.ShowModal();
00248 this->AddToLogger( msg);
00249 }
00250 }
00251 }
00252 if ( this->m_CGT_changed) {
00253 UINT8 value= (UINT8)this->m_gain_timing_spinCtrl->GetValue();
00254 if ( !N1568_set_gain_of_timing( this->m_p_board_data, value, &channel_status)) {
00255 wxString msg( _("Error while writing coarse gain timing "));
00256 msg<< value;
00257 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00258 dlg.ShowModal();
00259 this->AddToLogger( msg);
00260 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00261 return;
00262 } else {
00263 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00264
00265 UINT8 read_value= channel_status.m_gain_timing;
00266 if ( read_value!= value) {
00267 wxString msg( _("Coarse gain timing readout mismatch: "));
00268 msg<< _("written: ")<< value<< _(" read: ")<< read_value;
00269 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00270 dlg.ShowModal();
00271 this->AddToLogger( msg);
00272 }
00273 }
00274 }
00275 if ( this->m_In_changed) {
00276 UINT8 value= (UINT8)this->m_input_polarity_choice->GetSelection();
00277 if ( !N1568_set_input_polarity( this->m_p_board_data, value!= 0, &channel_status)) {
00278 wxString msg( _("Error while writing input polarity "));
00279 msg<< value;
00280 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00281 dlg.ShowModal();
00282 this->AddToLogger( msg);
00283 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00284 return;
00285 } else {
00286 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00287
00288 UINT8 read_value= channel_status.m_is_polarity_negative? 1: 0;
00289 if ( read_value!= value) {
00290 wxString msg( _("Input polarity readout mismatch: "));
00291 msg<< _("written: ")<< value<< _(" read: ")<< read_value;
00292 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00293 dlg.ShowModal();
00294 this->AddToLogger( msg);
00295 }
00296 }
00297 }
00298 if ( this->m_STR_changed) {
00299 UINT8 value= (UINT8)this->m_stretcher_enable_choice->GetSelection();
00300 if ( !N1568_set_stretcher( this->m_p_board_data, value!= 0, &channel_status)) {
00301 wxString msg( _("Error while writing stretcher enable "));
00302 msg<< value;
00303 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00304 dlg.ShowModal();
00305 this->AddToLogger( msg);
00306 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00307 return;
00308 } else {
00309 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00310
00311 UINT8 read_value= channel_status.m_is_strecher_enabled? 1: 0;
00312 if ( read_value!= value) {
00313 wxString msg( _("Stretcher enable readout mismatch: "));
00314 msg<< _("written: ")<< value<< _(" read: ")<< read_value;
00315 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00316 dlg.ShowModal();
00317 this->AddToLogger( msg);
00318 }
00319 }
00320 }
00321 this->SetDirty( false);
00322 this->m_p_main_frame->DoSetMuxOut();
00323 }
00324 void ChannelPanelImpl::OnReadClicked( wxCommandEvent& ) {
00325 this->ReadFromBoard( true, true);
00326 }
00327 void ChannelPanelImpl::UpdateControls( N1568_channel_status& channel_status, bool force) {
00328 if( !this->m_CFTh_changed|| force) {
00329 this->m_cfd_threshold_spinCtrl->SetValue( channel_status.m_discr_thr);
00330 }
00331 if( !this->m_CFWdt_changed|| force) {
00332 this->m_cfd30_out_width_spinCtrl->SetValue( channel_status.m_cfd_out_width);
00333 }
00334 if( !this->m_PZ_changed|| force) {
00335 this->m_pole_zero_adj_spinCtrl->SetValue( channel_status.m_pole_zero_adj);
00336 }
00337 if( !this->m_FG_changed|| force) {
00338 this->m_fine_gain_spinCtrl->SetValue( channel_status.m_fine_gain);
00339 }
00340 if( !this->m_SH_changed|| force) {
00341 this->m_shaping_time_spinCtrl->SetValue( channel_status.m_shape_setting);
00342 }
00343 if( !this->m_CG_changed|| force) {
00344 this->m_coarse_gain_spinCtrl->SetValue( channel_status.m_coarse_gain);
00345 }
00346 if( !this->m_CGT_changed|| force) {
00347 this->m_gain_timing_spinCtrl->SetValue( channel_status.m_gain_timing);
00348 }
00349 if( !this->m_In_changed|| force) {
00350 this->m_input_polarity_choice->SetSelection( channel_status.m_is_polarity_negative? 1: 0);
00351 }
00352 if( !this->m_STR_changed|| force) {
00353 this->m_stretcher_enable_choice->SetSelection( channel_status.m_is_strecher_enabled? 1: 0);
00354 }
00355 }
00356 void ChannelPanelImpl::SetDirty( bool is_dirty) {
00357 this->m_is_dirty= is_dirty;
00358 if ( !this->m_is_dirty) {
00359 this->ResetChangeFlags();
00360 }
00361 this->m_read_button->Enable( this->m_is_connect);
00362 this->m_write_button->Enable( this->m_is_dirty&& this->m_is_connect);
00363 }
00364 bool ChannelPanelImpl::ReadFromBoard( bool force_update, bool set_muxout) {
00365 N1568_channel_status channel_status;
00366
00367
00368 if ( !N1568_set_channel( this->m_p_board_data, this->m_channel_id, &channel_status)) {
00369 wxString msg( _("Error while writing channel id "));
00370 msg<< this->m_channel_id;
00371 wxMessageDialog dlg( this, msg, ("Error"), wxOK| wxICON_ERROR);
00372 dlg.ShowModal();
00373 this->AddToLogger( msg);
00374 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00375 return false;
00376 } else {
00377 this->AddToLogger( N1568_get_last_answer( this->m_p_board_data), LMT_COMMUNICATION);
00378 this->UpdateControls( channel_status, force_update);
00379 }
00380 if( force_update) {
00381 this->SetDirty( false);
00382 }
00383 if( set_muxout) {
00384 this->m_p_main_frame->DoSetMuxOut();
00385 }
00386 return true;
00387 }