⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thread.~cp

📁 数据采集
💻 ~CP
📖 第 1 页 / 共 5 页
字号:
    */


  // HQ_CPZ24

  for(int i=0;i<8;i++){
    ofst_up[i]=ofst_down[i]=0;  //init from_ofst 两个剪力一上一下
  }
  if(flag_test==0) offset_buf=0;
  collect_zero();
  don_flag=false;

  int ab_cnt;
  const int MK_ZERO=700; // check zero        // 400  -->  700

  init_kg();    // init

   // 等车上
  if(flag_test==0){
      long ad_tmp;
      for(ab_cnt=0;ab_cnt<5;){
        if(don_susp==TRUE){return EXIT_ESC;}
        if(get_ad_don(&ad_tmp)<0){
          WaitForSingleObject(g_hEvent,100);
        }else{
          if(ad_tmp<zero+MK_ZERO) ab_cnt=0;
          else ab_cnt++;
        }
      }
  }

  start_wb(); // 开微波

  form_main->timer_chsb->Enabled=false;

  start_tm=GetCurrentTime();
  if(flag_test==0) don_flag=TRUE;
  Sleep(200);   //  立刻让getdatathread运行

  Synchronize(show_being);
  form_main->sound();
  Synchronize(repaint);

  get_direct();
  DeleteFile("c:\\tran\\chreport.rep");
  //direct=L_R;


  //ofstream out_tmp("c:\\cb4\\wingdh\\out_tmp.txt");

  int pp=0;   // 当前处理的数据
  int _kg[8]={0,0,0,0,0,0,0,0}; // 已处理的开关数
  const int CNT_EXIT=3500;
  for(cnt_exit=0,ce_cnt=0;cnt_exit<CNT_EXIT;){
    int ofst_buf=offset_buf-1;
    if(pp+10<ofst_buf){
      for(;pp<ofst_buf;pp+=10){
        if(don_susp==true){return EXIT_ESC;}
        for(int j=0;j<8;j++){
          if( deal_kg_cpz24(pp,j) ){     // HQ_CPZ24
            cnt_exit=0;
            //if( !(  (direct==L_R&&j==7) || (direct==R_L&&j==0) ) ){continue;}
            if( !(  (direct==L_R&&(j==7||j==6)) || (direct==R_L&&(j==0||j==1)) ) ){continue;}

            int k14=kk1[j]+kk4[j];
            if(k14>=_kg[j]+4){               // !!! +4
              int i;
              for(i=_kg[j];i<=k14-4;i++){    // !!! -4
                if( kkg[j][i].k1  == kkg[j][i].k4  &&
                    kkg[j][i].k1 % 2==0  &&
                    kkg[j][i].k1  >= 2 ){
                   //float x1,x2,x3;

                   if(kkg[j][i].ofst+kkg[j][i].k3>kkg[j][i-1].ofst){
                     kx1=((float)(kkg[j][i+1].ofst-kkg[j][i].k3-kkg[j][i].ofst))/
                                (kkg[j][i].ofst+kkg[j][i].k3-kkg[j][i-1].ofst);
                     if(kx1<2.3) continue; // 六轴机车与车皮间回零<2.0  车皮内回零>2.6,取2.3
                   }else{kx1=0.0;}

                   if(  i>4 &&
                        kkg[j][i+1].ofst-kkg[j][i].ofst < kkg[j][i-3].ofst-kkg[j][i-4].ofst ){
                     continue; // 车皮间回零  因为车皮间回零<车皮内回零
                   }

                   if(kkg[j][i].k1>5){
                     if(kkg[j][i-2].ofst+kkg[j][i-2].k3>kkg[j][i-3].ofst){
                       kx2=((float)(kkg[j][i-3].ofst- kkg[j][i-4].k3-kkg[j][i-4].ofst))/
                                  (kkg[j][i-2].ofst+kkg[j][i-2].k3- kkg[j][i-3].ofst);
                       if(kx2<0.4){  // 六轴机车:0.20   车皮:0.75 取0.4
                         continue; // 六轴机车
                       }
                     }else{kx2=0.0;}
                   }else{kx2=0.0;}

                   if( i>2 &&
                       kkg[j][i].ofst+kkg[j][i].k3>kkg[j][i-1].ofst){
                     kx3=((float)(kkg[j][i-1].ofst- kkg[j][i-2].k3-kkg[j][i-2].ofst))/
                                (kkg[j][i].ofst+kkg[j][i].k3- kkg[j][i-1].ofst);
                     if(kx3>0.36&&kx1<3.2) continue;  // ez\0330_5x8四轴机车0.54,车皮:0.18,取0.77
                   }else{kx3=0.0;}                  // 掉车\四轴机车:kx3=0.93,kx1=2.55 车皮:kx3=0.61,kx1>7.0


                   bool ok=true;
                   for(int n=0;n<8;n++){
                     if(kkg[n][i-3].ofst>=kkg[n][i-2].ofst){ ok=false; break; }
                     if(kkg[n][i-2].ofst>=kkg[n][i-1].ofst){ ok=false; break; }
                     if(kkg[n][i-1].ofst>=kkg[n][i-0].ofst){ ok=false; break; }
                     if(kkg[n][i-0].ofst>=kkg[n][i+1].ofst){ ok=false; break; }
                     if(kkg[n][i+1].ofst>=kkg[n][i+2].ofst){ ok=false; break; }
                     if(kkg[n][i+2].ofst>=kkg[n][i+3].ofst){ ok=false; break; }
                     if(kkg[n][i+3].ofst>=kkg[n][i+4].ofst){ ok=false; break; }
                   }
                   if(!ok) continue;


                   //  !!j6,j7 要同步    j0,j1要同步
                   if(  ( direct==L_R && ((j==7&&kkg[6][i+4].ofst!=0)||(j==6&&kkg[7][i+4].ofst!=0)) ) ||
                        ( direct==R_L && ((j==0&&kkg[1][i+4].ofst!=0)||(j==1&&kkg[0][i+4].ofst!=0)) )  ){
                     int m;
                     for(ad_n1[ce_cnt]=ad_n2[ce_cnt]=ad_n3[ce_cnt]=ad_n4[ce_cnt]=0,
                          ad_w1[ce_cnt]=ad_w2[ce_cnt]=ad_w3[ce_cnt]=ad_w4[ce_cnt]=0,m=0;m<4;m++){
                       if(direct==L_R ){ // --->
                         ad_n4[ce_cnt]+=js_ad(2*m+1,kkg[2*m][i-3].ofst,kkg[2*m][i-2].ofst)-zero_tm[2*m];
                         ad_n3[ce_cnt]+=js_ad(2*m+1,kkg[2*m][i-1].ofst,kkg[2*m][i-0].ofst)-zero_tm[2*m];
                         ad_n2[ce_cnt]+=js_ad(2*m+1,kkg[2*m][i+1].ofst,kkg[2*m][i+2].ofst)-zero_tm[2*m];
                         ad_n1[ce_cnt]+=js_ad(2*m+1,kkg[2*m][i+3].ofst,kkg[2*m][i+4].ofst)-zero_tm[2*m];
                         ad_w4[ce_cnt]+=js_ad(2*m+2,kkg[2*m+1][i-3].ofst,kkg[2*m+1][i-2].ofst)-zero_tm[2*m+1];
                         ad_w3[ce_cnt]+=js_ad(2*m+2,kkg[2*m+1][i-1].ofst,kkg[2*m+1][i-0].ofst)-zero_tm[2*m+1];
                         ad_w2[ce_cnt]+=js_ad(2*m+2,kkg[2*m+1][i+1].ofst,kkg[2*m+1][i+2].ofst)-zero_tm[2*m+1];
                         ad_w1[ce_cnt]+=js_ad(2*m+2,kkg[2*m+1][i+3].ofst,kkg[2*m+1][i+4].ofst)-zero_tm[2*m+1];
                       }else{ // <---
                         ad_n1[ce_cnt]+=js_ad(2*m+1,kkg[2*m][i-3].ofst,kkg[2*m][i-2].ofst)-zero_tm[2*m];
                         ad_n2[ce_cnt]+=js_ad(2*m+1,kkg[2*m][i-1].ofst,kkg[2*m][i-0].ofst)-zero_tm[2*m];
                         ad_n3[ce_cnt]+=js_ad(2*m+1,kkg[2*m][i+1].ofst,kkg[2*m][i+2].ofst)-zero_tm[2*m];
                         ad_n4[ce_cnt]+=js_ad(2*m+1,kkg[2*m][i+3].ofst,kkg[2*m][i+4].ofst)-zero_tm[2*m];
                         ad_w1[ce_cnt]+=js_ad(2*m+2,kkg[2*m+1][i-3].ofst,kkg[2*m+1][i-2].ofst)-zero_tm[2*m+1];
                         ad_w2[ce_cnt]+=js_ad(2*m+2,kkg[2*m+1][i-1].ofst,kkg[2*m+1][i-0].ofst)-zero_tm[2*m+1];
                         ad_w3[ce_cnt]+=js_ad(2*m+2,kkg[2*m+1][i+1].ofst,kkg[2*m+1][i+2].ofst)-zero_tm[2*m+1];
                         ad_w4[ce_cnt]+=js_ad(2*m+2,kkg[2*m+1][i+3].ofst,kkg[2*m+1][i+4].ofst)-zero_tm[2*m+1];
                       }
                       /*out_tmp<<ce_cnt<<" "<<kkg[2*m][i-3].ofst<<" "<<kkg[2*m][i-2].ofst<<" "<<
                                             kkg[2*m][i-1].ofst<<" "<<kkg[2*m][i-0].ofst<<" "<<
                                             kkg[2*m][i+1].ofst<<" "<<kkg[2*m][i+2].ofst<<" "<<
                                             kkg[2*m][i+3].ofst<<" "<<kkg[2*m][i+4].ofst<<" "<<
                                             kkg[2*m+1][i-3].ofst<<" "<<kkg[2*m+1][i-2].ofst<<" "<<
                                             kkg[2*m+1][i-1].ofst<<" "<<kkg[2*m+1][i-0].ofst<<" "<<
                                             kkg[2*m+1][i+1].ofst<<" "<<kkg[2*m+1][i+2].ofst<<" "<<
                                             kkg[2*m+1][i+3].ofst<<" "<<kkg[2*m+1][i+4].ofst<<" "<<endl;*/
                     }


                     ad_n1[ce_cnt]/=16;    ad_w1[ce_cnt]/=16;       //  /32 == /4/4
                     ad_n2[ce_cnt]/=16;    ad_w2[ce_cnt]/=16;
                     ad_n3[ce_cnt]/=16;    ad_w3[ce_cnt]/=16;
                     ad_n4[ce_cnt]/=16;    ad_w4[ce_cnt]/=16;

                     ad[ce_cnt]=qin_hou[ce_cnt]=
                           ad_n1[ce_cnt]+ad_n2[ce_cnt]+ad_n3[ce_cnt]+ad_n4[ce_cnt]+
                           ad_w1[ce_cnt]+ad_w2[ce_cnt]+ad_w3[ce_cnt]+ad_w4[ce_cnt];

                     wei[ce_cnt]=ad_to_wei(ad[ce_cnt],direct);
                     if(kkg[j][i].ofst>kkg[j][i-1].ofst){
                       spd[ce_cnt]=(long)(3.6*bd.len*700/
                       (double)(kkg[j][i].ofst+kkg[j][i].k3-kkg[j][i-1].ofst)+0.5);
                     }
                     else spd[ce_cnt]=100;
                     if(spd[ce_cnt]>100) spd[ce_cnt]=100;

                     if(ce_cnt==0){
                       copyfile(CPZDATA,CPZDATABAK);  // copyfile(from,to)
                     }
                     const int SPEED=60;

                     int nono;
                     bool is_hc=check_is_hc(nono);
                     //if(is_hc)  ShowMessage(String("is_hc:  ")+nono);
                     //else       ShowMessage(String("not_hc:  "));

                     if( spd[ce_cnt]<=SPEED && is_hc){
                       lock_weight(nono);
                     }

                     c_newcpz(); //计算超偏载


                     if(is_debug){
                       if(bd.use_status==USE_CPZJH){
                         if(lock_flag && spd[ce_cnt]<=SPEED && is_hc ){
                           lock_cpz24(false,nono); // add_cnt not used
                           refresh_cpz_data(false,nono); // add_cnt not used
                         }
                       }else{
                         if(spd[ce_cnt]<=SPEED && is_hc ){
                           if(lock_flag) lock_cpz24(false,nono);
                           refresh_cpz_data(false,nono); // add_cnt not used
                         }
                       }
                     }else{
                       if(lock_flag && spd[ce_cnt]<=SPEED && is_hc ){
                         lock_cpz24(false,nono); // add_cnt not used
                         refresh_cpz_data(false,nono); // add_cnt not used
                       }
                     }

                     Synchronize(show);
                     for(int n=0;n<8;n++){
                       // *( p_buf_z[n]+(kkg[n][i].ofst+kkg[n][i+1].ofst)/2 )|=0x8000;
                       *(p_buf_z[n]+kkg[n][i].ofst)|=0x8000;
                       *(p_buf_z[n]+kkg[n][i-1].ofst)|=0x8000;
                       *(p_buf_z[n]+kkg[n][i-2].ofst)|=0x8000;
                       *(p_buf_z[n]+kkg[n][i-3].ofst)|=0x8000;
                       *(p_buf_z[n]+kkg[n][i+1].ofst)|=0x8000;
                       *(p_buf_z[n]+kkg[n][i+2].ofst)|=0x8000;
                       *(p_buf_z[n]+kkg[n][i+3].ofst)|=0x8000;
                       *(p_buf_z[n]+kkg[n][i+4].ofst)|=0x8000;
                     }

                     /*
                     {
                       fstream out("c:\\cb4\\wingdh\\out.txt",ios::out|ios::app);
                       if(out){
                         out<<(ce_cnt+1)<<" "<<"3:"<<kkg[0][i-3].ofst
                                        <<" "<<"2:"<<kkg[0][i-2].ofst
                                        <<" "<<"1:"<<kkg[0][i-1].ofst
                                        <<" "<<"0:"<<kkg[0][i-0].ofst
                                        <<" "<<"4:"<<kkg[0][i+1].ofst
                                        <<" "<<"5:"<<kkg[0][i+2].ofst
                                        <<" "<<"6:"<<kkg[0][i+3].ofst
                                        <<" "<<"7:"<<kkg[0][i+4].ofst<<endl;
                         out.close();
                       }
                     }*/

                     get_ch(_ch[ce_cnt],_cx[ce_cnt]); // for test 简配车号

                     ce_cnt++;
                   }


                   i++;
                   break;
                } // if
              } // for(i=_kg[j];i<=k14-4;i++)
              _kg[j]=i;

            }//  if(k14>=_kg[j]+8)  YH_CPZ24
          }else{ cnt_exit++;}
        }// for(j=0;j<8;j++)
      }// for
    }else{
      Sleep(1);
    }

    if(don_susp==true){return EXIT_ESC;}
  }

  //有问题就不生成文件
  for(int i=0;i<8;i++){
    if(kk1[i]!=kk4[i]){
      ce_cnt=0;
      return EXIT_YC;
    }
  }
  for(int i=0;i<ce_cnt;i++){
    if(wei[i]<0){
      ce_cnt=0;
      return EXIT_YC;
    }
  }

  //检查是否进入动态称重时台面压车
  if(!zero_is_ok()){
    ce_cnt=0;
    return EXIT_YC;
  }

  if(cnt_exit>=CNT_EXIT){
    if(kk1[0]!=kk4[7]) EXIT_YC;
  }

  return EXIT_OK;


  }catch(...){Sleep(10000);return EXIT_YC; }
  //return EXIT_OK;
}

bool __fastcall TDonThread::zero_is_ok()  //检查是否进入动态称重时台面压车
{
  int cnt[8];
  for(int i=0;i<8;i++){
    cnt[i]=0;
  }
  for(int ofst=0;ofst<JIN_SIZE-50;ofst++){
    for(int i=0;i<8;i++){
      if(abs(zero_tm[i]-data_jz(i+1,ofst))>1500) cnt[i]++;
    }
  }

  char s[100];
  sprintf(s,"%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d ",zero_tm[0],zero_tm[1],zero_tm[2],zero_tm[3],
               zero_tm[4],zero_tm[5],zero_tm[6],zero_tm[7],
               cnt[0],cnt[1],cnt[2],cnt[3],cnt[4],cnt[5],cnt[6],cnt[7]);
  err(s);               

  for(int i=0;i<8;i++){
    if(cnt[i]>50) return false;
  }
  return true;
}

void __fastcall TDonThread::get_direct()
{
  /* 2001-8-7重写,因为静态buf的数据加到了动态buf的首部
  */

  if(bd.hq_mode==HQ_2J1Z||bd.hq_mode==HQ_CPZGZ){
      for(int i=0,ab_cnt1=0,ab_cnt2=0;i<offset_buf;i++){
        if(data_j1(i)>zero_j1+1000 )  ab_cnt1++;
        else ab_cnt1=0;
        if(ab_cnt1>5){  direct=L_R;return;}

        if(data_j2(i)>zero_j2+1000)  ab_cnt2++;
        else ab_cnt2=0;
        if(ab_cnt2>5){  direct=R_L;return;}
      }
      err("direct: not dound");
  }else if(bd.hq_mode==HQ_CPZ24){

    bool b1,b2;
    long ofst= offset_buf>2000 ? 2000 : offset_buf;
    short dlt1,dlt2;
    long retp1=0,retp2=0;
    b1=find_kg_up_new(1, 0,ofst,dlt1,retp1);
    b2=find_kg_up_new(15,0,ofst,dlt2,retp2);
    if(b1 && b2){
      //err("direct b1 && b2");
      if(retp1<retp2) direct=L_R;
      else direct=R_L;
    }
    else if(b1==true ){direct=L_R;}
    else if(b2==true ){direct=R_L;}
    else{err("direct not found");}

    //char str[30];
    //sprintf(str,"%d %d ",retp1,retp2);
    //err(str);

  }else if(bd.hq_mode==HQ_NEWBDG){
    bool found=false;
    for(int i=0,ab_cnt1=0,ab_cnt2=0;i<offset_buf;i++){
      if(data_jz(1,i)-zero_tm[0]>
         data_jz(2,i)-zero_tm[1]+500)  ab_cnt1++;
      else ab_cnt1=0;
      if(ab_cnt1>20){  direct=L_R;found=true;break;}

      if(data_jz(2,i)-zero_tm[1]>
         data_jz(1,i)-zero_tm[0]+500)  ab_cnt2++;
      else ab_cnt2=0;
      if(ab_cnt2>20){  direct=R_L;found=true;break;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -