12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751 |
- #include "TestService.h"
- #include "pid.h"
- #include "valve.h"
- #include "ballvalve.h"
- #include "PressureSensor.h"
- #include "Calibrationpara.h"
- #include<QDateTime>
- #include<QTime>
- #include<QEventLoop>
- #include<QMessageBox>
- #include<cmath>
- #include <QSignalSpy>
- #include <QDebug>
- #include <QFile>
- #include <QDir>
- TestService::TestService(QThread *parent)
- :QThread(parent)
- ,m_SerialUi3(nullptr)
- ,m_SerialUi4(nullptr)
- ,m_pTimer_1(nullptr)
- ,m_pTimer_2(nullptr)
- ,m_compartmentid(0)
- {
- m_bRunning=false;
- m_bRealEnd = true;
- for(int i=0; i<MAX_COMPARTMENT_NUM; i++ ){
- m_tank.m_comparts[i].m_id = i;
- }
- //moveToThread(&m_Thread);
- //connect(this, SIGNAL(operate()), this, SLOT(doTest()));
- }
- TestService::~TestService()
- {
- }
- void TestService::init()
- {
- m_pTimer_1 = new QTimer(this);
- connect(m_pTimer_1, SIGNAL(timeout()), this, SLOT(OnTimer1()));
- //m_pTimer_2 = new QTimer(this);
- // connect(m_pTimer_2, SIGNAL(timeout()), this, SLOT(OnTimer2()));
- if(!m_SerialUi3.serialConnect("COM3", "9600", "8", "0", "1")){
- QString str = "打开串口COM3失败";
- emit onNotice(str);
- }
- #if 1
- if(!m_SerialUi4.serialConnect("COM4", "9600", "8", "2", "1")){
- QString str = "打开串口COM4失败";
- emit onNotice(str);
- }
- #endif
- connect(&m_report, SIGNAL(onProgress(QString)), this, SLOT(receive_reportprogress(QString)));
- }
- bool TestService::setTankinfo(const QVariantList& list)
- {
- QString standard_name;
- QString licenseplate_str;
- QString companyname_str;
- int compartment_num = 0;
- int total_volume = 0;
- int volume[MAX_COMPARTMENT_NUM] ={0};
- for(int i=0; i<list.count(); i++){
- QString item_string = list[i].toString();
- if(0 == i){
- standard_name = item_string;
- }else if(1 == i){
- licenseplate_str = item_string;
- }else if(2 == i){
- companyname_str = item_string;
- }else if(3 == i){
- total_volume = item_string.toInt();
- }else if(4 == i){
- compartment_num = item_string.toInt();
- }else{
- if(i< (8+5))
- volume[i-5] = item_string.toInt();
- }
- }
- //check invalid
- bool ret_bool = true;
- if( compartment_num > 0 && compartment_num <= MAX_COMPARTMENT_NUM){
- int volume_sum =0;
- for(int i=0; i<compartment_num; i++){
- volume_sum += volume[i];
- }
- if(total_volume != volume_sum){
- ret_bool = false;
- }
- }else{
- ret_bool = false;
- }
- if(true == ret_bool){
- //m_standardname = standard_name;
- qDebug("setTankinfo: standard_name:[%s]", standard_name.toStdString().c_str());
- m_tank.licenseplate_str = licenseplate_str;
- qDebug("setTankinfo: licenseplate:[%s]", licenseplate_str.toStdString().c_str());
- m_tank.companyname_str = companyname_str;
- qDebug("setTankinfo: companyname:[%s]", companyname_str.toStdString().c_str());
- m_tank.total_volume = total_volume;
- qDebug("setTankinfo: total_volume:[%d]", total_volume);
- m_tank.compartment_num = compartment_num;
- qDebug("setTankinfo: compartment_num:[%d]", compartment_num);
- //Standard standard;
- if(g_StandardManager->getStandard(standard_name, m_standard)){
- for(int i=0; i<compartment_num; i++){
- m_tank.m_comparts[i].m_volume = volume[i];
- qDebug("setTankinfo: volume [%d]:[%d]", i, volume[i]);
- for(int j=0; j<m_standard.item_count; j++){
- if(volume[i] >= m_standard.item[j].oilcompartment_volume){
- m_tank.m_comparts[i].m_standarditem = m_standard.item[j];
- qDebug("setTankinfo: compart [%d]: volume[%d]", i, m_standard.item[j].oilcompartment_volume);
- qDebug("setTankinfo: compart [%d]: sys[%f]", i, m_standard.item[j].system_threshold);
- qDebug("setTankinfo: compart [%d]: valve[%f]", i, m_standard.item[j].valve_threshold);
- break;
- }
- }
- #if 0
- ParaItem pid_para;
- g_CalibrationPara->get_pidPara(volume[i], pid_para);
- qDebug("setTankinfo: pid max_volume:[%d]", pid_para.max_volume);
- qDebug("setTankinfo: pid keep_time:[%d]", pid_para.keep_time);
- qDebug("setTankinfo: pid outermax:[%f]", pid_para.outermax);
- qDebug("setTankinfo: pid outermin:[%f]", pid_para.outermin);
- qDebug("setTankinfo: pid outerkp:[%f]", pid_para.outerkp);
- qDebug("setTankinfo: pid outerki:[%f]", pid_para.outerki);
- qDebug("setTankinfo: pid outerkd:[%f]", pid_para.outerkd);
- qDebug("setTankinfo: pid innermax:[%f]", pid_para.innermax);
- qDebug("setTankinfo: pid innermin:[%f]", pid_para.innermin);
- qDebug("setTankinfo: pid innerkp:[%f]", pid_para.innerkp);
- #endif
- }
- }else{
- QString str = "所选标准不存在!";
- emit onNotice(str);
- ret_bool = false;
- }
- }
- return ret_bool;
- }
- bool TestService::tstart(int compartmentid, int direction)
- {
- if(m_bRunning){
- QString str = "当前有任务正在进行中...";
- emit onNotice(str);
- return false;
- }
- if(false == m_bRealEnd){
- QString str = "当前有任务还未完全结束...";
- emit onNotice(str);
- return false;
- }
- m_compartmentid = compartmentid-1;
- if(0 == direction)
- m_direction = Test_Direction_Positive;
- else
- m_direction = Test_Direction_Negative;
- m_stage = Test_Stage_SysTest;
- m_step = Test_Step_Start;
- m_pressuremutex.lock();
- m_pressurelist.clear(); //用来计算平均压力
- m_pressuremutex.unlock();
- QMessageBox::StandardButton result = QMessageBox::information(NULL, "提示:", "请对油气回收系统相关部件进行检查", QMessageBox::Ok|QMessageBox::Abort, QMessageBox::Ok);
- switch (result)
- {
- case QMessageBox::Ok:
- qDebug()<<"Ok";
- m_pTimer_1->start(1*500); // 500 ms
- m_bRunning = true;
- start();
- break;
- case QMessageBox::Abort:
- qDebug()<<"Abort";
- return false;
- break;
- default:
- qDebug()<<"default";
- return false;
- break;
- }
- return true;
- }
- bool TestService::tselfstart(int compartmentid, int direction)
- {
- if(m_bRunning){
- QString str = "当前有任务正在进行中...";
- emit onNotice(str);
- return false;
- }
- if(false == m_bRealEnd){
- QString str = "当前有任务还未完全结束...";
- emit onNotice(str);
- return false;
- }
- m_compartmentid = compartmentid-1;
- if(0 == direction)
- m_direction = Test_Direction_Positive;
- else
- m_direction = Test_Direction_Negative;
- m_stage = Test_Stage_SysTest;
- m_step = Test_Step_Start;
- m_pressuremutex.lock();
- m_pressurelist.clear(); //用来计算平均压力
- m_pressuremutex.unlock();
- QMessageBox::StandardButton result = QMessageBox::question(NULL, "提示:", "系统即将自检,请确认所有部件都己接好", QMessageBox::Ok|QMessageBox::Abort, QMessageBox::Ok);
- switch (result)
- {
- case QMessageBox::Ok:
- qDebug()<<"Ok";
- m_pTimer_1->start(1*500); // 1s
- m_bRunning = true;
- start();
- break;
- case QMessageBox::Abort:
- qDebug()<<"Abort";
- return false;
- break;
- default:
- qDebug()<<"default";
- return false;
- break;
- }
- return true;
- }
- bool TestService::tstop(int compartmentid)
- {
- if(m_compartmentid != compartmentid-1){
- return false;
- }
- if(m_pTimer_1->isActive())
- m_pTimer_1->stop();
- //if(m_pTimer_2->isActive())
- // m_pTimer_2->stop();
- if(m_bRunning){
- //stop();
- m_bRunning = false;
- }
- return true;
- }
- bool TestService::reportpic_Ready(int compartmentid)
- {
- Compartment& com = m_tank.get_compartment(compartmentid-1);
- com.m_bpicReady = true;
- return true;
- }
- bool TestService::check_alltest_ok()
- {
- bool ret_flag = true;
- for(int i=0; i< m_tank.compartment_num; i++){
- Compartment& com = m_tank.get_compartment(i);
- if(com.m_bpicReady == false ){
- ret_flag = false;
- break;
- }
- }
- if(false == ret_flag){
- QMessageBox::StandardButton result = QMessageBox::question(NULL, "提示:", "有油仓还未进行检测,是否强制生成报告?", QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
- switch (result)
- {
- case QMessageBox::Yes:
- ret_flag = true;
- break;
- case QMessageBox::No:
- break;
- default:
- break;
- }
- }
- return ret_flag;
- }
- void TestService::receive_reportprogress(QString qstr)
- {
- qDebug() << "TestService::receive_reportprogress ";
- qDebug() << qstr;
- emit onGenreportProgress(qstr);
- }
- bool TestService::genReport(QString word_path, QString pic_dir)
- {
- if(word_path.contains(".doc")){
- return m_report.make_Word(m_tank, word_path, pic_dir);
- }else if(word_path.contains(".pdf")){
- return m_report.make_PDF(m_tank, word_path, pic_dir);
- }
- QString str = "word_path invalid!";
- qDebug() << str;
- return false;
- }
- QJsonObject TestService::get_vrs_items()
- {
- return m_tank.get_vrs_items();
- }
- QJsonObject TestService::get_bls_items()
- {
- return m_tank.get_bls_items();
- }
- bool TestService::set_item_result(const QString& jsonStr )
- {
- return m_tank.set_item_result(jsonStr);
- }
- void TestService::push_pressurelist(float pressure)
- {
- m_pressuremutex.lock();
- if(m_pressurelist.size() == AVERAGE_PRESSURE_COUNT){
- m_pressurelist.removeAt(0);
- }
- m_pressurelist.append(pressure);
- m_pressuremutex.unlock();
- }
- void TestService::clear_pressurelist()
- {
- m_pressuremutex.lock();
- m_pressurelist.clear(); //用来计算平均压力
- m_pressuremutex.unlock();
- }
- float TestService::calculate_averagepressure()
- {
- float average = 0.0;
- m_pressuremutex.lock();
- int n = m_pressurelist.size();
- if(n>0){
- float sum = 0.0;
- for(int i=0; i<n; i++){
- sum += m_pressurelist.at(i);
- //qDebug("push_pressurelist 333 size[%f]", m_pressurelist.at(i));
- }
- average = sum/n;
- }
- m_pressuremutex.unlock();
- return average;
- }
- bool TestService::valve_open(Valve_ID id)
- {
- if(Valve_ID_All == id){
- Valve v(&m_SerialUi3, ALL_VALVE);
- return v.Open();
- }else{
- Valve v(&m_SerialUi3, id);
- return v.Open();
- }
- }
- bool TestService::valve_close(Valve_ID id)
- {
- if(Valve_ID_All == id){
- Valve v(&m_SerialUi3, ALL_VALVE);
- return v.Close();
- }else{
- Valve v(&m_SerialUi3, id);
- return v.Close();
- }
- }
- QString TestService::read_PressureValue()
- {
- float pressure = 0.0;
- static int timeout_count =0;
- PressureSensor ps(&m_SerialUi4);
- if(ps.Read(pressure)){
- push_pressurelist(pressure);
- timeout_count=0;
- }else{
- pressure = calculate_averagepressure();
- qDebug("Read_PressureValue failed");
- timeout_count++;
- if(timeout_count >= AVERAGE_PRESSURE_COUNT){
- //data is to old, clear
- clear_pressurelist();
- qDebug("clear_pressurelist ");
- }
- }
- int _ipressure = pressure*1000;
- _ipressure = (_ipressure/PRESSURE_DIVISION_VALUE)*PRESSURE_DIVISION_VALUE;
- pressure = _ipressure/1000.0;
- QString pressure_str = QString("%1").arg(pressure, 4,'f',2,QLatin1Char('0'));
- return pressure_str;
- }
- bool TestService::pressure_zero()
- {
- PressureSensor ps(&m_SerialUi4);
- return ps.Set_Zero();
- }
- bool TestService::ballvalve_control(QString position_str)
- {
- bool ok;
- ushort position = position_str.toUShort(&ok, 10);
- BallValve ball_v(&m_SerialUi4);
- return ball_v.SetPosition(position);
- }
- QJsonObject TestService::ballvalve_status()
- {
- unsigned char status;
- unsigned short value = 0;
- QJsonObject rootObj;
- BallValve ball_v(&m_SerialUi4);
- if(ball_v.GetSP(status, value)){
- switch(status){
- case BALLVALVE_STATUS_OPENING:
- rootObj.insert("status", "opening");
- break;
- case BALLVALVE_STATUS_CLOSING:
- rootObj.insert("status", "closing");
- break;
- case BALLVALVE_STATUS_OPENEND:
- rootObj.insert("status", "opened");
- break;
- case BALLVALVE_STATUS_CLOSEEND:
- rootObj.insert("status", "closed");
- break;
- case BALLVALVE_STATUS_BREAK:
- rootObj.insert("status", "break");
- break;
- case BALLVALVE_STATUS_FAULT:
- rootObj.insert("status", "fault");
- break;
- default:
- rootObj.insert("status", "unkown");
- break;
- }
- rootObj.insert("position", value);
- }else{
- rootObj.insert("status", "unkown");
- rootObj.insert("position", 0);
- }
- return rootObj;
- }
- void TestService::dump_comstatistic()
- {
- QString filepath = "D:/VaporRecoverySystemTest/comstatistic.txt";
- Valve in_v(&m_SerialUi3, VALVE_INTAKE);
- in_v.Dump_Statistics(filepath);
- PressureSensor ps(&m_SerialUi4);
- ps.Dump_Statistics(filepath);
- BallValve bv(&m_SerialUi4);
- bv.Dump_Statistics(filepath);
- }
- void TestService::OnTimer1()
- {
- float pressure = 0.00;
- static int timeout_count =0;
- static int times_count = 0;
- PressureSensor ps(&m_SerialUi4);
- if(ps.Read(pressure)){
- push_pressurelist(pressure);
- timeout_count=0;
- }else{
- qDebug("Read_PressureValue failed");
- pressure = calculate_averagepressure();
- timeout_count++;
- if(timeout_count >= AVERAGE_PRESSURE_COUNT){
- //data is to old, clear
- clear_pressurelist();
- qDebug("clear_pressurelist ");
- }
- }
- times_count++;
- if(0 == times_count%2){
- int _ipressure = 0;
- _ipressure = pressure*1000;
- _ipressure = (_ipressure/PRESSURE_DIVISION_VALUE)*PRESSURE_DIVISION_VALUE;
- pressure = _ipressure/1000.0;
- QString pressure_str = QString("%1").arg(pressure, 4,'f',2,QLatin1Char('0'));
- PressureItem item;
- //item.m_pressure = pressure_str;
- item.m_testDirection = m_direction;
- item.m_testStage = m_stage;
- item.m_testStep = m_step;
- QVariantMap map;
- map.clear();
- map.insert("pressure", pressure_str);
- map.insert("direction", item.m_testDirection);
- map.insert("stage", item.m_testStage);
- map.insert("step", item.m_testStep);
- //QString pressure_str = QString("%1").arg(pressure, 5,'f',3,QLatin1Char('0'));
- //m_tank.m_comparts[m_compartmentid].m_currentpressure= pressure_str.toFloat();
- emit sigPressure(m_compartmentid+1, map);
- }
- }
- void TestService::OnTimer2()
- {
- //qDebug("OnTimer2 >>>enter ");
- //float pressure;
- //Read_pressure(pressure);
- //QThread::sleep(5);
- //emit Pressure_changed(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
- //qDebug("OnTimer2 >>>leave ");
- }
- Ret_Value TestService::PositivePressure_Add(const TestExpect& expect, bool bSavedata)
- {
- Ret_Value ret_v = Ret_OK;
- int interval_time = 500; // ms
- int count = 0;
- int delay_count = 0;
- int exceed_times =0;
- QElapsedTimer timer;
- timer.start();
- float prev_pressure = 0;
- float current_pressure = 0;
- double current_speed = 0;
- unsigned char bvstatus;
- unsigned short bvposition;
- unsigned short bvoffset = 150;
- int keep_times = 60;
- int stable_count = 0; //稳压计数
- PressureSensor ps(&m_SerialUi4);
- BallValve bv(&m_SerialUi4);
- bool bv_ready = false;
- bv.SetPosition(bvoffset);
- PID* pPIDouter = NULL;
- PID* pPIDinner = NULL;
- double speed_target = 0.0;
- ParaItem pid_para;
- g_CalibrationPara->get_pidPara(expect.volume, pid_para);
- pPIDouter = new PID(0.5, pid_para.outermax, pid_para.outermin, pid_para.outerkp, 0, 0);
- //pPIDouter = new PID(0.5, pid_para.outermax, pid_para.outermin, pid_para.outerkp, pid_para.outerkd, pid_para.outerki);
- pPIDinner = new PID(0.5, pid_para.innermax, pid_para.innermin, pid_para.innerkp, pid_para.innerkd, pid_para.innerki,pid_para.innermaxI, pid_para.innerIstep, pid_para.innerDstep);
- //将稳压时间转换成计数
- keep_times = pid_para.keep_time *(1000/interval_time);
- prev_pressure = calculate_averagepressure();
- Valve in_v(&m_SerialUi3, VALVE_INTAKE);
- bool bOpen_intake = false;
- //bOpen_intake = in_v.Open();
- //
- QDateTime datetime = QDateTime::currentDateTime();
- QString timestr = datetime.toString("ddHHmmzzz");
- QString filepath = "D:/VaporRecoverySystemTest/";
- QFile datafile(filepath+timestr+"_PIDdata.csv");
- bool datafile_opened = false;
- if(true == bSavedata){
- datafile_opened = datafile.open(QFile::WriteOnly | QFile::Truncate);
- }
- //等待压力达到目标值附近
- while(m_bRunning){
- //等待球阀,到达指定位置 100
- if(false == bv_ready){
- if(false == bv.GetSP(bvstatus, bvposition)){
- qDebug(" PositivePressure_Add, bv.GetSP failed");
- }else{
- if(BALLVALVE_STATUS_FAULT == bvstatus){
- ret_v = Ret_Failed;
- break;
- }
- if((BALLVALVE_STATUS_OPENEND == bvstatus) || (BALLVALVE_STATUS_CLOSEEND == bvstatus) ){
- int ps_offset = bvoffset;
- int cu_position = bvposition;
- if(abs(cu_position-ps_offset) <= 10){
- bv_ready=true;
- }
- }else{
- bv.SetPosition(bvoffset);
- }
- }
- }else{
- current_pressure = calculate_averagepressure();
- current_speed = current_pressure - prev_pressure;
- prev_pressure = current_pressure;
- qDebug(" PositivePressure_Add, current_pressure : %f target: %f", current_pressure, expect.target);
- if(current_pressure >= expect.target+0.01){
- count = 0;
- stable_count++;
- if(bOpen_intake){
- qDebug(" PositivePressure_Add, in_v.Close ");
- if(in_v.Close()){
- bOpen_intake = false;
- exceed_times++;
- }
- //bOpen_intake = false;
- }
- #if 1
- if(exceed_times <= 2){
- delay_count = 15*(1000/interval_time);
- }else if(3 == exceed_times){
- delay_count =10*(1000/interval_time);
- }else{
- delay_count =5*(1000/interval_time);
- }
- #endif
- }else{
- // stable_count 需要从第一次超出目标压力时,开始增加
- if(stable_count > 0) stable_count++;
- if(current_pressure >= expect.target && current_pressure < expect.target + 0.01){
- count++;
- if(((false == bOpen_intake) && count >=10*(1000/interval_time))||((stable_count > keep_times)&&(false == bOpen_intake))){
- count = keep_times+10;
- }
- if(false == bOpen_intake){
- //在进气阀关闭,压力回落过程中,两种情况触发加压过程退出
- // 1. 压力值连续10秒都没有下降0.01Kpa, 说明压力基本稳定了
- // 2. 计数超出稳压所需计数
- if((count >=10*(1000/interval_time)) || (stable_count > keep_times) ){
- count = keep_times+10;
- }
- }
- // 进行阀门密闭性测试,加压过程中。 只要加压到目标压力就退出
- if(m_stage == Test_Stage_ValveTest){
- count = keep_times+10;
- }
- }else{
- count=0;
- if(delay_count > 0){
- delay_count--;
- }
- if(false == bOpen_intake && 0 == delay_count){
- bOpen_intake = in_v.Open();
- qDebug(" PositivePressure_Add, in_v.Open 222 ");
- pPIDinner->reset();
- if(bv.SetPosition(bvoffset))
- bvposition = bvoffset;
- }
- }
- if(NULL != pPIDouter && NULL != pPIDinner && 0 == delay_count){
- speed_target = pPIDouter->calculate(expect.target, current_pressure);
- qDebug(" PositivePressure_Add, pPIDinner speed_target:%f, current_speed:%f", speed_target, current_speed);
- double inc = pPIDinner->calculate(speed_target, current_speed);
- unsigned short position = bvoffset +inc;
- //qDebug(" PositivePressure_Add, position : %d", position);
- if(bvposition != position){
- qDebug(" PositivePressure_Add, position : %d", position);
- if(bv.SetPosition(position))
- bvposition = position;
- }
- }else{
- if(0 == delay_count){
- qDebug(" PositivePressure_Add, NULL = pPIDouter NULL == pPIDinner ");
- }
- //qDebug(" PositivePressure_Add, NULL = pPIDouter NULL == pPIDinner ");
- }
- }
- }
- if(count >= keep_times){ //about 60s
- break;
- }
- if(true == bSavedata && true == datafile_opened){
- QTextStream out(&datafile); // 输入流
- QString str1 = QString("%1").arg(expect.target, 8,'f',6,QLatin1Char('0'));
- QString str2 = QString("%1").arg(current_pressure, 8,'f',6,QLatin1Char('0'));
- //out << QString::number(expect.target) << "," << QString::number(current_pressure) << ",";
- out << str1 << "," << str2 << ",";
- str1 = QString("%1").arg(speed_target, 8,'f',6,QLatin1Char('0'));
- str2 = QString("%1").arg(current_speed, 8,'f',6,QLatin1Char('0'));
- //out << QString::number(speed_target) << "," << QString::number(current_speed) << ",";
- out << str1 << "," << str2 << ",";
- out << QString::number(bvposition) << "\n";
- }
- QThread::msleep(interval_time);
- int remainingtime = expect.timeout*1000 - timer.elapsed();
- if(remainingtime <= 0){
- qDebug(" add_pressure timeout, Rough valve will colse");
- ret_v = Ret_Timeout;
- break;
- }
- }
- if(!m_bRunning){
- // be stoped
- ret_v = Ret_Exit;
- }
- if(NULL != pPIDouter){
- delete pPIDouter;
- }
- if(NULL != pPIDinner){
- delete pPIDinner;
- }
- in_v.Close();
- bv.SetPosition(0);
- if(true == bSavedata && true == datafile_opened){
- datafile.close();
- }
- return ret_v;
- }
- Ret_Value TestService::PositivePressure_Add_V2(const TestExpect& expect)
- {
- Ret_Value ret_v = Ret_OK;
- int count = 0;
- QElapsedTimer timer;
- timer.start();
- float current_pressure = 0;
- unsigned char bvstatus;
- unsigned short bvposition;
- unsigned short bvoffset = 120;
- int holding_time = 60;
- PressureSensor ps(&m_SerialUi4);
- BallValve bv(&m_SerialUi4);
- bool bv_ready = false;
- bv.SetPosition(bvoffset);
- PID* pPID = NULL;
- if(expect.volume <= 200){
- pPID = new PID(1, 200, 0, 0, 2, 0.4);
- holding_time = 60;
- }else if(expect.volume <= 4000){
- pPID = new PID(1, 500, 0, 0, 5, 0.6);
- holding_time = 60;
- }else if(expect.volume <= 6000){
- pPID = new PID(1, 800, 0, 0, 6, 1.0);
- holding_time = 120;
- }else if(expect.volume <= 8000){
- pPID = new PID(1, 800, 0, 0, 7, 2);
- holding_time = 180;
- }else{
- pPID = new PID(1, 800, 0, 0, 8, 3);
- holding_time = 180;
- }
- Valve in_v(&m_SerialUi3, VALVE_INTAKE);
- bool bOpen_intake = false;
- //bOpen_intake = in_v.Open();
- //等待压力达到目标值附近
- while(m_bRunning){
- //等待球阀,到达指定位置 100
- if(false == bv_ready){
- if(false == bv.GetSP(bvstatus, bvposition)){
- qDebug(" PositivePressure_Add, bv.GetSP failed");
- }else{
- if(BALLVALVE_STATUS_FAULT == bvstatus){
- ret_v = Ret_Failed;
- break;
- }
- if((BALLVALVE_STATUS_OPENEND == bvstatus) || (BALLVALVE_STATUS_CLOSEEND == bvstatus) ){
- int ps_offset = bvoffset;
- int cu_position = bvposition;
- if(abs(cu_position-ps_offset) < 10){
- bv_ready=true;
- }
- }else{
- bv.SetPosition(bvoffset);
- }
- }
- }else{
- current_pressure = calculate_averagepressure();
- qDebug(" PositivePressure_Add, current_pressure : %f target: %f", current_pressure, expect.target);
- if(current_pressure >= expect.target+0.05){
- count++;
- if(bOpen_intake){
- qDebug(" PositivePressure_Add, in_v.Close ");
- if(in_v.Close())
- bOpen_intake = false;
- }
- //系统自测及容积较小时,球阀最好归零,否则因球阀不太紧漏气, 进气阀与球阀之间的气体会压向系统,导致压力升高
- //当容器过大时, 如果压力超出后又降下来或系统存在漏气,需要重新加压,设置 bvoffset,能让重新加压速度快起来。
- if(expect.volume < 100){
- if(bv.SetPosition(0))
- bvposition = 0;
- qDebug(" PositivePressure_Add, bv.SetPosition 0");
- }else {
- if(bvoffset != bvposition){
- if(bv.SetPosition(bvoffset))
- bvposition = bvoffset;
- qDebug(" PositivePressure_Add, bv.SetPosition bvoffset");
- }
- }
- }else if((current_pressure < expect.target+0.05) & (current_pressure >= expect.target) ){
- count++;
- }else{
- count = 0;
- if(false == bOpen_intake){
- bOpen_intake = in_v.Open();
- qDebug(" PositivePressure_Add, in_v.Open ");
- pPID->reset();
- }else{
- if(NULL != pPID){
- double inc = pPID->calculate_v2(expect.target+0.05, current_pressure);
- unsigned short position = bvoffset +inc;
- //qDebug(" PositivePressure_Add, position : %d", position);
- if(bvposition != position){
- qDebug(" PositivePressure_Add, position : %d", position);
- if(bv.SetPosition(position))
- bvposition = position;
- }
- }else{
- qDebug(" PositivePressure_Add, NULL = pPID ");
- }
- }
- }
- }
- if(count >= holding_time){ //about 60s
- break;
- }
- QThread::msleep(1000);
- int remainingtime = expect.timeout*1000 - timer.elapsed();
- if(remainingtime <= 0){
- qDebug(" add_pressure timeout, Rough valve will colse");
- ret_v = Ret_Timeout;
- break;
- }
- }
- if(!m_bRunning){
- // be stoped
- ret_v = Ret_Exit;
- }
- if(NULL != pPID){
- delete pPID;
- }
- in_v.Close();
- bv.SetPosition(0);
- return ret_v;
- }
- Ret_Value TestService::Pressure_Relief(const TestExpect& expect)
- {
- Ret_Value ret_v = Ret_OK;
- bool bOpen_ventv = false;
- Valve vent_v(&m_SerialUi3, VALVE_VENT);
- float current_pressure;
- float last_pressure = calculate_averagepressure();
- QElapsedTimer timer;
- timer.start();
- int count = 0;
- //打开泄压阀
- bOpen_ventv = vent_v.Open();
- //last_pressure = calculate_averagepressure();
- //等待压力清零
- while(m_bRunning){
- if(false == bOpen_ventv){
- bOpen_ventv = vent_v.Open();
- }
- current_pressure = calculate_averagepressure();
- if(fabs(current_pressure - last_pressure) <= 0.01){
- qDebug(" Pressure_Relief 111 finished");
- count++;
- }else{
- count=0;
- }
- if((count > 5) ||(current_pressure < 0.01)){
- //关闭泄压阀
- vent_v.Close();
- break;
- }
- QThread::msleep(1000);
- int remainingtime = expect.timeout*1000 - timer.elapsed();
- if(remainingtime < 0){
- ret_v = Ret_Timeout;
- qDebug("timeout, Pressure_Relief Timeout");
- break;
- }
- }
- if(!m_bRunning){
- ret_v = Ret_Exit;
- }
- vent_v.Close();
- return ret_v;
- }
- Ret_Value TestService::Pressure_Relief()
- {
- Ret_Value ret_v = Ret_OK;
- bool bOpen_ventv = false;
- Valve vent_v(&m_SerialUi3, VALVE_VENT);
- float current_pressure;
- QElapsedTimer timer;
- timer.start();
- int count = 0;
- //打开泄压阀
- bOpen_ventv = vent_v.Open();
- //等待压力清零
- while(1){
- if(false == bOpen_ventv){
- bOpen_ventv = vent_v.Open();
- }
- if(false == m_pTimer_1->isActive())
- OnTimer1();
- current_pressure = calculate_averagepressure();
- if(current_pressure < 0.1){
- qDebug(" Pressure_Relief finished 222");
- count++;
- }else{
- count=0;
- }
- if(count > 0){
- //关闭泄压阀
- vent_v.Close();
- break;
- }
- QThread::msleep(1000);
- int remainingtime = 60*1000 - timer.elapsed();
- if(remainingtime < 0){
- ret_v = Ret_Timeout;
- qDebug("timeout, Pressure_Relief Timeout");
- break;
- }
- }
- vent_v.Close();
- qDebug(" Pressure_Relief leave");
- return ret_v;
- }
- Ret_Value TestService::Pressure_Keep(int keeptime, float& start_value, float& end_value)
- {
- int count = 0;
- Ret_Value ret_v = Ret_OK;
- start_value = calculate_averagepressure();
- int _ipressure = start_value*100;
- start_value = _ipressure/100.0;
- while((count < keeptime) && m_bRunning){
- QThread::msleep(1000);
- count++;
- }
- end_value = calculate_averagepressure();
- _ipressure = end_value*100;
- end_value = _ipressure/100.0;
- if(!m_bRunning){
- // be stoped
- ret_v = Ret_Exit;
- }
- return ret_v;
- }
- bool TestService::self_checking()
- {
- //读继电器状态
- Valve all_v(&m_SerialUi3, ALL_VALVE);
- if(false == all_v.Close()){
- return false;
- }
- //读取球阀状态
- BallValve ball_v(&m_SerialUi4);
- unsigned char status;
- unsigned short value;
- if(false == ball_v.GetSP(status, value)){
- return false;
- }
- if(status == BALLVALVE_STATUS_FAULT){
- return false;
- }
- ball_v.SetPosition(0);
- PressureSensor ps(&m_SerialUi4);
- float pressure = 0.0;
- if(false == ps.Read(pressure)){
- return false;
- }
- return true;
- }
- bool TestService::test_init()
- {
- //bool ret_v=true;
- Valve all_v(&m_SerialUi3, ALL_VALVE);
- all_v.Close();
- BallValve ball_v(&m_SerialUi4);
- unsigned char status;
- unsigned short value;
- if(ball_v.GetSP(status, value)){
- if(value > 20){
- ball_v.SetPosition(0);
- int wait_time = (1+value/100);
- QThread::msleep(wait_time*1000);
- }
- }else{
- return false;
- }
- return true;
- }
- int TestService::make_messagebox(Test_Direction direction, Test_Step step, Ret_Value ret_v)
- {
- int ret_btn = QMessageBox::NoButton;
- QString notice_str;
- if(Test_Direction_Positive == direction){
- switch(step){
- case Test_Step_AddPressure:
- if(Ret_Timeout == ret_v){
- notice_str = "加压超时, 是否重试?";
- ret_btn = m_msgbox.information(NULL, "提示:", notice_str, QMessageBox::Retry|QMessageBox::Abort, QMessageBox::Retry);
- }else if(Ret_Failed == ret_v){
- notice_str = "继电器通信失败, 和序终止";
- ret_btn = m_msgbox.information(NULL, "提示:", notice_str, QMessageBox::Ok, QMessageBox::Ok);
- }
- break;
- case Test_Step_AdjustPressure:
- if( Ret_Timeout == ret_v ){
- notice_str = "比例阀调压精调超时, 是否重试?";
- ret_btn = m_msgbox.information(NULL, "提示:", notice_str, QMessageBox::Retry|QMessageBox::Abort, QMessageBox::Retry);
- //emit onNotice(notice_str);
- }else if(Ret_Failed == ret_v){
- notice_str = "继电器通信失败, 程序终止";
- ret_btn = m_msgbox.information(NULL, "提示:", notice_str, QMessageBox::Ok, QMessageBox::Ok);
- //emit onNotice(notice_str);
- }
- break;
- default:
- break;
- }
- }else {
- }
- return ret_btn;
- }
- void TestService::run()
- {
- qDebug("doTest >>>enter ");
- QString notice_str;
- //QElapsedTimer q_time;
- int ret_btn = QMessageBox::NoButton;
- TestExpect texpect;
- bool bQuit = false;
- //q_time.start();
- Ret_Value ret_v = Ret_OK;
- m_bRealEnd = false;
- if(m_compartmentid >= 0){
- if(m_direction == Test_Direction_Positive){
- while(m_bRunning && (bQuit == false)){
- switch(m_step){
- case Test_Step_Start:
- {
- m_tank.get_compartment(m_compartmentid).clear_result();
- if(false == self_checking()){
- ret_btn = m_msgbox.information(NULL, "提示:", "通信故障,请终止程序", QMessageBox::Abort, QMessageBox::Abort);
- }else{
- test_init();
- ret_btn = m_msgbox.information(NULL, "提示:", "请确认已经打开旋拧阀", QMessageBox::Ok, QMessageBox::Ok);
- }
- switch (ret_btn)
- {
- case QMessageBox::Ok:
- m_step = Test_Step_AddPressure;
- break;
- default:
- break;
- }
- }
- break;
- case Test_Step_AddPressure:
- {
- if(m_stage == Test_Stage_SysTest){
- emit sigState(m_compartmentid+1, "回收系统测试,开始加压", "");
- }else{
- emit sigState(m_compartmentid+1, "回收阀测试,开始加压", "");
- }
- texpect.target = m_standard.positive_target;
- texpect.volume = m_tank.m_comparts[m_compartmentid].m_volume;
- texpect.timeout = m_tank.m_comparts[m_compartmentid].get_addpressure_timeout();
- ret_v = PositivePressure_Add(texpect);
- if(Ret_OK == ret_v){
- if(m_stage == Test_Stage_SysTest){
- m_step = Test_Step_KeepPressure;
- }else if(m_stage == Test_Stage_ValveTest){
- m_msgbox.information(NULL, "提示:", "即将泄压, 请确认已经关闭油气回收阀。", QMessageBox::Ok, QMessageBox::Ok);
- m_step = Test_Step_reliefPressure;
- }
- }else if(Ret_Exit == ret_v){
- bQuit = true;
- }else{
- ret_btn = make_messagebox(m_direction, m_step, ret_v);
- switch (ret_btn)
- {
- case QMessageBox::Retry:
- qDebug()<<"Retry";
- break;
- case QMessageBox::Abort:
- qDebug()<<"Abort";
- bQuit = true;
- break;
- case QMessageBox::Ok:
- qDebug()<<"OK";
- bQuit = true;
- break;
- default:
- break;
- }
- }
- }
- break;
- case Test_Step_KeepPressure:
- {
- if(m_stage == Test_Stage_SysTest){
- emit sigState(m_compartmentid+1, "油气回收系统测试,开始保压", "");
- }else{
- emit sigState(m_compartmentid+1, "油气回收阀测试,开始保压", "");
- }
- // 检测 5分钟都没超限,就是通过了
- //float delta = 0;
- //float threshold = 0.0;
- //bool bPassed = true;
- // 检测 5分钟都没超限,就是通过了
- float delta = 0;
- float start_value = 0.0;
- float end_value = 0.0;
- bool bPassed = true;
- //ret_v = Pressure_Keep2(5*60, start_value, end_value);
- if(m_stage == Test_Stage_SysTest){
- ret_v = Pressure_Keep(5*60, start_value, end_value);
- m_tank.m_comparts[m_compartmentid].m_result.sysstart_pressure = start_value;
- m_tank.m_comparts[m_compartmentid].m_result.sysend_pressure = end_value;
- delta = start_value - end_value;
- m_tank.m_comparts[m_compartmentid].m_result.delta_sys_pressure = delta;
- if(Ret_Exit == ret_v){
- bQuit = true;
- } else {
- if(delta < m_tank.m_comparts[m_compartmentid].m_standarditem.system_threshold){
- bPassed = true;
- m_tank.m_comparts[m_compartmentid].m_result.pass_sys_pressure = true;
- }else{
- bPassed = false;
- m_tank.m_comparts[m_compartmentid].m_result.pass_sys_pressure = false;
- }
- m_tank.m_comparts[m_compartmentid].m_result.sys_test_finished = true;
- QString delta_str = QString("%1").arg(delta, 4,'f',2,QLatin1Char('0'));
- emit sigSystemResult(m_compartmentid+1, delta_str, bPassed);
- emit sigState(m_compartmentid+1, "油气回收系统检测,结束", "");
- ret_btn = QMessageBox::NoButton;
- notice_str = "系统密闭性已经检测完成,是否进行阀门密闭性检测?";
- ret_btn = m_msgbox.information(NULL, "提示:", notice_str, QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
- switch (ret_btn)
- {
- case QMessageBox::Yes:
- m_stage = Test_Stage_ValveTest;
- if(calculate_averagepressure() < m_standard.positive_target){
- m_step = Test_Step_AddPressure;
- }else{
- m_msgbox.information(NULL, "提示:", "即将泄压, 请确认已经关闭油气回收阀。", QMessageBox::Ok, QMessageBox::Ok);
- m_step = Test_Step_reliefPressure; //如果压力还在4.5以上, 可以不调压
- }
- break;
- case QMessageBox::No:
- m_step = Test_Step_End;
- break;
- default:
- break;
- }
- }
- }else{
- ret_v = Pressure_Keep(5*60, start_value, end_value);
- float offset = 0;
- //修正 强制初始压力为 0
- if(start_value != 0.0){
- offset = start_value;
- start_value = 0.0;
- end_value -= offset;
- }
- m_tank.m_comparts[m_compartmentid].m_result.valvestart_pressure = start_value;
- m_tank.m_comparts[m_compartmentid].m_result.valveend_pressure = end_value;
- delta = end_value - start_value;
- m_tank.m_comparts[m_compartmentid].m_result.delta_valve_pressure = delta;
- if(Ret_Exit == ret_v){
- bQuit = true;
- }else {
- if(delta <= m_tank.m_comparts[m_compartmentid].m_standarditem.valve_threshold){
- m_tank.m_comparts[m_compartmentid].m_result.pass_valve_pressure = true;
- bPassed = true;
- }else{
- m_tank.m_comparts[m_compartmentid].m_result.pass_valve_pressure = false;
- bPassed = false;
- }
- m_tank.m_comparts[m_compartmentid].m_result.valve_test_finished = true;
- QString delta_str = QString("%1").arg(delta, 4,'f',2,QLatin1Char('0'));
- emit sigValveResult(m_compartmentid+1, delta_str, bPassed);
- emit sigState(m_compartmentid+1, "油气回收阀测试,结束", "");
- m_step = Test_Step_End;
- }
- }
- }
- break;
- case Test_Step_reliefPressure:
- {
- if(m_stage == Test_Stage_SysTest){
- emit sigState(m_compartmentid+1, "油气回收系统测试结束,开始泄压", "");
- }else if(m_stage == Test_Stage_ValveTest){
- emit sigState(m_compartmentid+1, "油气回收阀测试,开始泄压", "");
- }
- texpect.volume = 0;
- texpect.target = 0.0;
- texpect.timeout = 60;//m_tank.m_comparts[m_compartmentid].get_adjust_timeout();
- ret_v = Pressure_Relief(texpect);
- if(Ret_Exit == ret_v){
- bQuit = true;
- }else if(Ret_OK == ret_v){
- m_step = Test_Step_KeepPressure;
- if(m_stage == Test_Stage_ValveTest){
- m_step = Test_Step_KeepPressure;
- }else{
- m_step = Test_Step_End;
- }
- }else{
- ret_btn = QMessageBox::NoButton;
- notice_str = "泄压超时, 是否重试?";
- ret_btn = m_msgbox.information(NULL, "提示:", notice_str, QMessageBox::Retry|QMessageBox::Abort, QMessageBox::Retry);
- switch (ret_btn)
- {
- case QMessageBox::Retry:
- break;
- case QMessageBox::Abort:
- bQuit = true;
- break;
- case QMessageBox::Ok:
- bQuit = true;
- break;
- default:
- break;
- }
- }
- }
- break;
- default:
- break;
- }
- if(Test_Step_End == m_step){
- break;
- }
- }
- }else{
- //负压测试, 暂不支持
- m_stage = Test_Stage_SysTest;
- qDebug(" negative test is not support now ");
- }
- }else{
- //self test
- if(m_direction == Test_Direction_Positive){
- while(m_bRunning && (bQuit == false)){
- switch(m_step){
- case Test_Step_Start:
- {
- emit sigState(m_compartmentid+1, "开始", "");
- if(false == self_checking()){
- ret_btn = m_msgbox.information(NULL, "提示:", "通信故障,请终止程序", QMessageBox::Abort, QMessageBox::Abort);
- }else{
- test_init();
- ret_btn = m_msgbox.information(NULL, "提示:", "请确认已经打开旋拧阀", QMessageBox::Ok, QMessageBox::Ok);
- }
- switch (ret_btn)
- {
- case QMessageBox::Ok:
- qDebug()<<"Yes";
- m_step = Test_Step_AddPressure;
- break;
- case QMessageBox::Abort:
- bQuit = true;
- break;
- }
- }
- break;
- case Test_Step_AddPressure:
- {
- emit sigState(m_compartmentid+1, "加压", "");
- QThread::msleep(2000);
- texpect.volume = 0;
- texpect.target = 4.50;
- texpect.timeout = 3*60; //3分钟
- ret_v = PositivePressure_Add(texpect);
- if(Ret_Exit == ret_v){
- bQuit = true;
- }else if(Ret_OK == ret_v){
- m_step = Test_Step_KeepPressure;
- }else{
- ret_btn = QMessageBox::NoButton;
- if(Ret_Timeout == ret_v){
- notice_str = "正压加压超时, 是否重试?";
- ret_btn = m_msgbox.information(NULL, "提示:", notice_str, QMessageBox::Retry|QMessageBox::Abort, QMessageBox::Retry);
- }else{
- notice_str = "继电器通信失败, 程序终止";
- ret_btn = m_msgbox.information(NULL, "提示:", notice_str, QMessageBox::Ok, QMessageBox::Ok);
- }
- switch (ret_btn)
- {
- case QMessageBox::Retry:
- break;
- case QMessageBox::Abort:
- bQuit = true;
- break;
- case QMessageBox::Ok:
- bQuit = true;
- break;
- default:
- break;
- }
- }
- }
- break;
- case Test_Step_KeepPressure:
- {
- emit sigState(m_compartmentid+1, "保压", "");
- // 检测 5分钟都没超限,就是通过了
- float delta = 0;
- float start_value = 0.0;
- float end_value = 0.0;
- bool bPassed = true;
- ret_v = Pressure_Keep(5*60, start_value, end_value);
- if(Ret_Exit == ret_v){
- bQuit = true;
- }else {
- delta = start_value - end_value;
- if(delta <= 0.5){
- bPassed = true;
- }else{
- bPassed = false;
- }
- //QString delta_str = QString("%1").arg(delta, 4,'f',2,QLatin1Char('0'));
- QString info_str = "初始压力:";
- info_str += QString("%1").arg(start_value, 4,'f',2,QLatin1Char('0'));
- info_str += ", 结束压力:";
- info_str += QString("%1").arg(end_value, 4,'f',2,QLatin1Char('0'));
- info_str += ", Deta:";
- info_str += QString("%1").arg(delta, 4,'f',2,QLatin1Char('0'));
- emit sigSelfTestResult(m_compartmentid+1, info_str, bPassed);
- emit sigState(m_compartmentid+1, "结束", "");
- m_step = Test_Step_reliefPressure;
- }
- }
- break;
- case Test_Step_reliefPressure:
- {
- ret_btn = m_msgbox.information(NULL, "提示:", "栓测任务结束,是否要泄压?", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
- m_step = Test_Step_End;
- switch (ret_btn)
- {
- case QMessageBox::Yes:
- qDebug()<<"Yes";
- {
- TestExpect expect;
- expect.target = 0.0;
- expect.volume = 0;
- expect.timeout = 30;
- ret_v = Pressure_Relief(expect);
- if(Ret_Exit == ret_v){
- bQuit = true;
- }
- }
- break;
- default:
- break;
- }
- }
- break;
- default:
- break;
- }
- if(Test_Step_End == m_step){
- break;
- }
- }
- }else{ //negtive
- }
- }
- if(Test_Step_End == m_step){
- ret_btn = QMessageBox::NoButton;
- }else{
- if(true == bQuit){
- if(Ret_Exit == ret_v){ // 主动退出
- ret_btn = m_msgbox.information(NULL, "提示:", "程序退出,是否要泄压?", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
- }else if(Ret_Timeout == ret_v){ // 超时退出
- ret_btn = m_msgbox.information(NULL, "提示:", "程序超时退出,是否要泄压?", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
- }else{//通信错误退出
- ret_btn = m_msgbox.information(NULL, "提示:", "程序通信错误退出,是否要泄压?", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
- }
- }
- }
- switch (ret_btn)
- {
- case QMessageBox::Yes:
- Pressure_Relief();
- break;
- default:
- break;
- }
- if(m_bRunning){
- m_bRunning = false;
- emit sigStop(m_compartmentid+1);
- }
- Valve all_v(&m_SerialUi3, ALL_VALVE);
- all_v.Close();
- //dump_comstatistic();
- m_bRealEnd = true;
- qDebug("doTest >>>leave ");
- }
|