📄 power.cpp
字号:
gettimeofday(&time_stop_tmp,(struct timezone *)0); tmp=time_stop_tmp.tv_usec-time_start_tmp.tv_usec; if(tmp>=100000){ //exit if time out qWarning("Warning Sample Phase C timeout"); goto exit; } } } break; default: break; } for(i=1;i<129;i+=2){ switch(Phase_channel){ case 0: Aconf[(i-1)/2]=(double)(AD_tmp[i]-1931/*直流分量*/)*(-1.0); Vconf[(i-1)/2]=(double)(AD_tmp[i+1]-1942/*直流分量*/); break; case 1: Aconf[(i-1)/2]=(double)(AD_tmp[i]-1920/*直流分量*/)*(-1.0); Vconf[(i-1)/2]=(double)(AD_tmp[i+1]-1911/*直流分量*/); break; case 2: Aconf[(i-1)/2]=(double)(AD_tmp[i]-1931/*直流分量*/)*(-1.0); Vconf[(i-1)/2]=(double)(AD_tmp[i+1]-1932/*直流分量*/); break; default: break; } }/**********采集模拟数据结束****************/#if TIME_DEBUG gettimeofday(&timer_debug[1],(struct timezone *)0);#endif/*************FFT运算开始*****************/ FFT(Vconf,64,ArrayFFT0,64); //FFT conversion FFT(Aconf,64,ArrayFFT1,64);/*************FFT运算结束*****************/#if TIME_DEBUG gettimeofday(&timer_debug[2],(struct timezone *)0);#endif/************电压电流变比计算**************//* tmp=(ArrayFFT0[1].R)*(ArrayFFT0[1].R)+(ArrayFFT0[1].I)*(ArrayFFT0[1].I); tmp=sqrt(tmp); FFT_Factor0=380/tmp; tmp=(ArrayFFT1[1].R)*(ArrayFFT1[1].R)+(ArrayFFT1[1].I)*(ArrayFFT1[1].I); tmp=sqrt(tmp); FFT_Factor1=380/tmp;*//************电压电流变比计算结束**********//************电压谐波的幅值计算***********/ for(i=0;i<64;i++){ tmp=(ArrayFFT0[i].R)*(ArrayFFT0[i].R)+(ArrayFFT0[i].I)*(ArrayFFT0[i].I); tmp=sqrt(tmp); if(i==0) tmp/=2; if(Phase_channel==0){ HarmonicV[i]=tmp*=voltage_factor_PhaseA_double; }else if(Phase_channel==1){ HarmonicV[i]=tmp*=voltage_factor_PhaseB_double; }else if(Phase_channel==2){ HarmonicV[i]=tmp*=voltage_factor_PhaseC_double; } if(listview_stat==GENERAL_REPORT){ sprintf(buff,"%.4f",tmp); StringList1<< buff; //filled StringList with Harmonic factors memset(buff,0,sizeof(buff)); } }/***********电压谐波的幅值计算结束**********//************电流谐波的幅值计算***********/ for(i=0;i<64;i++){ tmp=(ArrayFFT1[i].R)*(ArrayFFT1[i].R)+(ArrayFFT1[i].I)*(ArrayFFT1[i].I); tmp=sqrt(tmp); if(i==0) tmp/=2; if(Phase_channel==0){ HarmonicA[i]=tmp*=current_factor_PhaseA_double; }else if(Phase_channel==1){ HarmonicA[i]=tmp*=current_factor_PhaseB_double; }else if(Phase_channel==2){ HarmonicA[i]=tmp*=current_factor_PhaseB_double; } if(listview_stat==GENERAL_REPORT){ sprintf(buff,"%.4f",tmp); StringList2<< buff; //filled StringList with Harmonic factors memset(buff,0,sizeof(buff)); } }/***********电流谐波的幅值计算结束**********/#if TIME_DEBUG gettimeofday(&timer_debug[3],(struct timezone *)0);#endif/**************刷新系统界面***************/ switch(Phase_channel){ case 0: if(listview_stat==GENERAL_VAHZ){ Vrms=this->count_rms(HarmonicV,64); Arms=this->count_rms(HarmonicA,64); VHZ=this->count_HZ(Vconf,64); vahz->setLcdNumber1(Vrms); vahz->setLcdNumber4(Arms); vahz->setLcdNumber7(VHZ); }else if(listview_stat==GENERAL_REPORT){ report1->setTableColumn(StringList1,Phase_channel*2); report1->setTableColumn(StringList2,Phase_channel*2+1); }else if(listview_stat==GENERAL_WPF){ Vrms=this->count_rms(HarmonicV,64); Arms=this->count_rms(HarmonicA,64); S_Phase=Vrms*Arms; wpf->setLcdNumber4(S_Phase); W_Phase=this->count_W(Vconf,64,voltage_factor_PhaseA_double*32,Aconf,64,current_factor_PhaseA_double*32); if(W_Phase>S_Phase) //参数修整 W_Phase=S_Phase; wpf->setLcdNumber1(W_Phase); PF_Phase=this->W_Phase/this->S_Phase; wpf->setLcdNumber7(PF_Phase); }else if(listview_stat==PHASE_A_HARMONIC){ BarPhA_A->setBarColor(red); BarPhA_A->drawBar(HarmonicA,64); BarPhA_V->setBarColor(blue); BarPhA_V->drawBar(HarmonicV,64); } break; case 1: if(listview_stat==GENERAL_VAHZ){ Vrms=this->count_rms(HarmonicV,64); Arms=this->count_rms(HarmonicA,64); VHZ=this->count_HZ(Vconf,64); vahz->setLcdNumber2(Vrms); vahz->setLcdNumber5(Arms); vahz->setLcdNumber8(VHZ); }else if(listview_stat==GENERAL_REPORT){ report1->setTableColumn(StringList1,Phase_channel*2); report1->setTableColumn(StringList2,Phase_channel*2+1); }else if(listview_stat==GENERAL_WPF){ Vrms=this->count_rms(HarmonicV,64); Arms=this->count_rms(HarmonicA,64); S_Phase=Vrms*Arms; wpf->setLcdNumber5(S_Phase); W_Phase=this->count_W(Vconf,64,voltage_factor_PhaseB_double*32,Aconf,64,current_factor_PhaseB_double*32); if(W_Phase>S_Phase) //参数修整 W_Phase=S_Phase; wpf->setLcdNumber2(W_Phase); PF_Phase=this->W_Phase/this->S_Phase; wpf->setLcdNumber8(PF_Phase); }else if(listview_stat==PHASE_B_HARMONIC){ BarPhB_A->setBarColor(red); BarPhB_A->drawBar(HarmonicA,64); BarPhB_V->setBarColor(blue); BarPhB_V->drawBar(HarmonicV,64); } break; case 2: if(listview_stat==GENERAL_VAHZ){ Vrms=this->count_rms(HarmonicV,64); Arms=this->count_rms(HarmonicA,64); VHZ=this->count_HZ(Vconf,64); vahz->setLcdNumber3(Vrms); vahz->setLcdNumber6(Arms); vahz->setLcdNumber9(VHZ); }else if(listview_stat==GENERAL_REPORT){ report1->setTableColumn(StringList1,Phase_channel*2); report1->setTableColumn(StringList2,Phase_channel*2+1); }else if(listview_stat==GENERAL_WPF){ Vrms=this->count_rms(HarmonicV,64); Arms=this->count_rms(HarmonicA,64); S_Phase=Vrms*Arms; wpf->setLcdNumber6(S_Phase); W_Phase=this->count_W(Vconf,64,voltage_factor_PhaseC_double*32,Aconf,64,current_factor_PhaseC_double*32); if(W_Phase>S_Phase) //参数修整 W_Phase=S_Phase; wpf->setLcdNumber3(W_Phase); PF_Phase=this->W_Phase/this->S_Phase; wpf->setLcdNumber9(PF_Phase); }else if(listview_stat==PHASE_C_HARMONIC){ BarPhC_A->setBarColor(red); BarPhC_A->drawBar(HarmonicA,64); BarPhC_V->setBarColor(blue); BarPhC_V->drawBar(HarmonicV,64); } break; default: break; } #if TIME_DEBUG gettimeofday(&timer_debug[4],(struct timezone *)0); for(i=0;i<4;i++){ timer_elapsed[i]=1000000*(timer_debug[i+1].tv_sec-timer_debug[i].tv_sec)+(timer_debug[i+1].tv_usec-timer_debug[i].tv_usec); } qDebug("采集数据花费%.2f",timer_elapsed[0]); qDebug("FFT运算花费%.2f",timer_elapsed[1]); qDebug("FFT幅值计算花费%.2f",timer_elapsed[2]); qDebug("计算并显示数据花费%.2f",timer_elapsed[3]); qDebug("总计花费%.2f",timer_elapsed[0]+timer_elapsed[1]+timer_elapsed[2]+timer_elapsed[3]); qDebug("\n\n");#endif /************刷新系统界面结束*************/exit: Phase_channel++; if(Phase_channel>=3) Phase_channel=0; }/***********以下是界面处理代码*************/void Power::fstart(){ qDebug("start clicked"); if(system_stat==START) return; vahz->show(); //显示LED窗口 sys_timer->start(1000); //启动系统定时器 listview_stat=GENERAL_VAHZ; system_stat=START;}void Power::fstop(){ qDebug("stop clicked"); if(system_stat==STOP) return; switch(listview_stat){ case GENERAL_VAHZ: vahz->hide(); break; case GENERAL_REPORT: report1->hide(); break; case GENERAL_WPF: wpf->hide(); break; case PHASE_A_HARMONIC: BarPhA_A->hide(); BarPhA_V->hide(); break; case PHASE_B_HARMONIC: BarPhB_A->hide(); BarPhB_V->hide(); break; case PHASE_C_HARMONIC: BarPhC_A->hide(); BarPhC_V->hide(); break; default: break; } sys_timer->stop(); //停止系统定时器 listview_stat=NONE; system_stat=STOP; Phase_channel=0;}void Power::fsetting(){ int i; char flag=0; if(system_stat==START){ sys_timer->stop(); //停止系统定时器 system_stat=STOP; flag=2; } if(SetDialog!=NULL){//delete by tymanium 070205// ioctl(fd,1,1); //set signal sample model SetDialog->set_factors(current_factor_PhaseA_int,voltage_factor_PhaseA_int, \ current_factor_PhaseB_int,voltage_factor_PhaseB_int, \ current_factor_PhaseC_int,voltage_factor_PhaseC_int ); SetDialog->start_timer(); i=SetDialog->exec(); SetDialog->stop_timer(); if(i==QDialog::Accepted){ SetDialog->get_factors(¤t_factor_PhaseA_int,&voltage_factor_PhaseA_int, \ ¤t_factor_PhaseB_int,&voltage_factor_PhaseB_int, \ ¤t_factor_PhaseC_int,&voltage_factor_PhaseC_int ); current_factor_PhaseA_double=(double)0.0000001*current_factor_PhaseA_int; voltage_factor_PhaseA_double=(double)0.00001*voltage_factor_PhaseA_int; current_factor_PhaseB_double=(double)0.0000001*current_factor_PhaseB_int; voltage_factor_PhaseB_double=(double)0.00001*voltage_factor_PhaseB_int; current_factor_PhaseC_double=(double)0.0000001*current_factor_PhaseC_int; voltage_factor_PhaseC_double=(double)0.00001*voltage_factor_PhaseC_int; } }//delete by tymanium 070205 // ioctl(fd,0,1); //set cycle sample model if(flag==2){ qDebug("setting clicked"); sys_timer->start(1000); system_stat=START; } }void Power::flistClicked(QListViewItem *listItem){ if(listItem==NULL || system_stat==STOP) return; switch(listview_stat){ //关闭正在的显示窗口 case GENERAL_VAHZ: vahz->hide(); break; case GENERAL_REPORT: report1->hide(); break; case GENERAL_WPF: wpf->hide(); break; case PHASE_A_HARMONIC: BarPhA_A->hide(); BarPhA_V->hide(); break; case PHASE_B_HARMONIC: BarPhB_A->hide(); BarPhB_V->hide(); break; case PHASE_C_HARMONIC: BarPhC_A->hide(); BarPhC_V->hide(); break; default: break; } if(listItem==Phase_A_Harmonic){ qDebug("Phase_A_Harmonic double cliked"); BarPhA_A->show(); BarPhA_V->show(); listview_stat=PHASE_A_HARMONIC; }else if(listItem==Phase_A_Waveforms){ qDebug("Phase_A_Waveforms double cliked"); }else if(listItem==Phase_B_Harmonic){ qDebug("Phase_B_Harmonic double cliked"); BarPhB_A->show(); BarPhB_V->show(); listview_stat=PHASE_B_HARMONIC; }else if(listItem==Phase_B_Waveforms){ qDebug("Phase_B_Waveforms double cliked"); }else if(listItem==Phase_C_Harmonic){ qDebug("Phase_C_Harmonic double cliked"); BarPhC_A->show(); BarPhC_V->show(); listview_stat=PHASE_C_HARMONIC; }else if(listItem==Phase_C_Waveforms){ qDebug("Phase_C_Waveforms double cliked"); }else if(listItem==General_VAHZ){ qDebug("General_Realtime double cliked"); vahz->show(); //显示LED窗口 listview_stat=GENERAL_VAHZ; }else if(listItem==General_Report){ qDebug("General_Report double cliked"); report1->show(); listview_stat=GENERAL_REPORT; }else if(listItem==General_WPF){ qDebug("General_WPF double cliked"); wpf->show(); listview_stat=GENERAL_WPF; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -