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

📄 global.~cp

📁 数据采集
💻 ~CP
📖 第 1 页 / 共 5 页
字号:
#include <vcl.h>
#include <math.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>

#define IS_GLOBAL_CPP
#include "main.h"
#include "thread.h"
#include "global.h"
#include <limits.h>
#include <values.h>
#include <math.h>

extern TDonThread  *donThread;

struct str_port {
        USHORT port_w1;
        USHORT port_w2;
        USHORT port_w3;
        USHORT port_w4;
        USHORT port_w5;
        USHORT port_w6;
        USHORT port_w7;
        USHORT port_w8;

        USHORT port_s1;
        USHORT port_s2;
        USHORT port_s3;
        USHORT port_s4;
        USHORT port_s5;
        USHORT port_s6;
        USHORT port_s7;
        USHORT port_s8;
        USHORT port_s9;
        USHORT port_s10;

        USHORT port_st;
        USHORT port_st2;
        USHORT port_st3;
        USHORT port_st4;
        USHORT port_kg;
}struct_port;


int  get_kk(int which_tm,int ofst)
{
  int step=1;

  if(ofst<=step) return 0;

  if(bd.hq_mode==HQ_2J1Z){
    if(which_tm==1) return  (data_j1(ofst)-data_j1(ofst-step))/10;
    else            return  (data_j2(ofst)-data_j2(ofst-step))/10;
  }else if(bd.hq_mode==HQ_BDG){
    return  (data_j1(ofst)-data_j1(ofst-step))/10;
  }else if(bd.hq_mode==HQ_STMBDG||bd.hq_mode==HQ_BDG3){
    if(which_tm==1) return  (data_j1(ofst)-data_j1(ofst-step))/10;
    else            return  (data_j2(ofst)-data_j2(ofst-step))/10;
  }else if(bd.hq_mode==HQ_CPZ){
    return ( (data_j1(ofst)-data_j1(ofst-step))/10+
             (data_j2(ofst)-data_j2(ofst-step))/10 )/2 ;
  }else if(bd.hq_mode==HQ_NEWCPZ||bd.hq_mode==HQ_CPZ24||bd.hq_mode==HQ_NEWBDG
           ||bd.hq_mode==HQ_CPZGZ){
    return (data_j(which_tm-1,ofst)-data_j(which_tm-1,ofst-step))/10;

    /*
    if(which_tm==1)        return (data_j1(ofst)-data_j1(ofst-step))/10;
    else if(which_tm==2)   return (data_j2(ofst)-data_j2(ofst-step))/10;
    else if(which_tm==3)   return (data_j3(ofst)-data_j3(ofst-step))/10;
    else if(which_tm==4)   return (data_j4(ofst)-data_j4(ofst-step))/10;
    else if(which_tm==5)   return (data_j5(ofst)-data_j5(ofst-step))/10;
    else if(which_tm==6)   return (data_j6(ofst)-data_j6(ofst-step))/10;
    else if(which_tm==7)   return (data_j7(ofst)-data_j7(ofst-step))/10;
    else if(which_tm==8)   return (data_j8(ofst)-data_j8(ofst-step))/10;
    else return 0;
    */
  }else{err("get_kk()"); return 0;}
}


long __fastcall get_rr(long offset)
{
  double a1,a2,b1,b2,c1,c2,dlt1,dlt2;
  double dx1,dy1,x,y,rr1;
  double x1,x2,x3,y1,y2,y3;
  int step=5;

  if(offset<step) offset=step; //makesure offset-step>0
  x1=0;x2=step;x3=2*step;
  y1=(data_jz(which_tm,offset-step)+data_jz(which_tm,offset-step+1)+data_jz(which_tm,offset-step+2))/3;
  y2=(data_jz(which_tm,offset)     +data_jz(which_tm,offset+1)     +data_jz(which_tm,offset+2))/3;
  y3=(data_jz(which_tm,offset+step)+data_jz(which_tm,offset+step+1)+data_jz(which_tm,offset+step+2))/3;

  if( (y2>y1&&y2>y3) || (y2<y1&&y2<y3) ) return 0; // 防止y2最大or最小

  a1=2*(x2-x1); b1=2*(y2-y1); c1=x2*x2-x1*x1+y2*y2-y1*y1;
  a2=2*(x3-x2); b2=2*(y3-y2); c2=x3*x3-x2*x2+y3*y3-y2*y2;

  dlt1=(a1*b2-a2*b1);
  dlt2=(b1*a2-b2*a1);
  if(dlt1==0||dlt2==0) return 300;
  x=((double)(c1*b2-c2*b1))/(double)dlt1;
  y=((double)(c1*a2-c2*a1))/(double)dlt2;
  dx1=x-x1;dy1=y-y1;
  rr1=dx1*dx1+dy1*dy1;
  rr1=sqrt(sqrt(rr1));

  if(rr1>bd.rr) return 300; // 便于draw
  else return 0;
}

//该函数可取代 find_don_qin().....
long __fastcall findp(int qh,int which_tm,long offset,
                    long dlt,float kk,long ref,int& dx,int high_bt,int zhou_jv,bool show_err)
/*
   qh: DOWN_QIN,UP_QIN,UP_HOU,DOWN_HOU
   which_tm:
   offset : start point的偏移
   dlt: 找目标拐点允许相对offset的最大变化
   kk: 拐点两端的比值最大值
   ref: 目标拐点的最小值
   dx: 找到目标拐点实际offset变化
*/
{
  long i,ret_offset=offset;
  long below_zero_cnt=0;
  bool found_flag=false;
  int  bl_cnt=0,ab_cnt=0;
  int  tmp;

  if( bd.hq_mode==HQ_NEWBDG){

    if(qh==DOWN_QIN){
      for(i=0;i<dlt;i++){
        int which_j=get_which_j_down(which_tm);
        if(get_kk(which_j,offset-i)<0) bl_cnt++;
        else{
          tmp=get_high_bt(which_j,offset-i,offset-i+bl_cnt);

          if( bl_cnt>KK_XX && data_jz(which_tm,offset-i)>ref && tmp>high_bt ){
              ret_offset=offset-i;
              found_flag=true;
              break;
          }
          bl_cnt=0;
        }//else
      }//for
      if(found_flag==true) dx=bl_cnt;
      else{ dx=0; char msg[50]; sprintf(msg,"%d DOWN_QIN:not found",which_tm); if(show_err){ err(msg);} }
      return ret_offset;
    }else if(qh==UP_QIN){
      for(i=0;i<dlt;i++){
        int which_j=get_which_j_up(which_tm);
        if(get_kk(which_j,offset-i)>0) {ab_cnt++;}
        else{
          tmp=get_high_bt(which_j,offset-i+ab_cnt,offset-i);

          if(ab_cnt>KK_XX && data_jz(which_tm,offset-i+ab_cnt)>ref &&
                 tmp>high_bt &&  i-ab_cnt>zhou_jv ){
            ret_offset=offset-i+ab_cnt;
            found_flag=true;
            break;
          }
          ab_cnt=0;
        }
      }
      if(found_flag==true) dx=ab_cnt;
      else{ dx=0; char msg[50]; sprintf(msg,"%d UP_QIN:not found",which_tm); if(show_err)err(msg);}
      return ret_offset;

    }else if(qh==UP_HOU){
      for(i=0;(below_zero_cnt<1000)&&(i<dlt);){ // 如果回零则退出,不影响其他车
        if(don_susp==TRUE) break; // Esc
        if(offset+i<offset_buf-10){ // 后架可能要等数据

          int which_j=get_which_j_up(which_tm);
          if(get_kk(which_j,offset+i)>0) {ab_cnt++;}
          else{
            tmp=get_high_bt(which_j,offset+i,offset+i-ab_cnt);
            if(ab_cnt>KK_XX && tmp>high_bt && data_jz(which_tm,offset+i)>ref){
              ret_offset=offset+i;
              found_flag=TRUE;
              break;
            }
            ab_cnt=0;
          }
          if(data_jz(which_tm,offset+i)<zero+500) below_zero_cnt++; //如果回零,返回
          else below_zero_cnt=0;
          i++;
        }else WaitForSingleObject(g_hEvent,10);
      }
      if(found_flag==TRUE) dx=ab_cnt;
      else{ dx=0; char msg[50]; sprintf(msg,"%d UP_HOU:not found",which_tm); if(show_err)err(msg);}
      return ret_offset;
    }else if(qh==DOWN_HOU){
      for(i=0;(below_zero_cnt<1000)&&(i<dlt);){// !! below_zero_cnt<80,如果回零则退出,不影响其他车
        if(don_susp==TRUE) break;   // Esc
        if(offset+i<offset_buf-10){ /*后架可能要等数据*/
          int which_j=get_which_j_down(which_tm);
          if(get_kk(which_j,offset+i)<0) {bl_cnt++;}
          else{
            tmp=get_high_bt(which_j,offset+i-bl_cnt,offset+i);
            if(bl_cnt>KK_XX && data_jz(which_tm,offset+i-bl_cnt)>ref &&
                  tmp>high_bt && i-bl_cnt>zhou_jv){
              ret_offset=offset+i-bl_cnt;
              found_flag=TRUE;
              break;
            }
            bl_cnt=0;
          }
          if(data_jz(which_tm,offset+i)<zero+500) below_zero_cnt++;  //如果回零,返回
          else below_zero_cnt=0;
          i++;
        }else WaitForSingleObject(g_hEvent,10);
      }
      if(found_flag==TRUE) dx=bl_cnt;
      else{ dx=0; char msg[50]; sprintf(msg,"%d DOWN_HOU:not found",which_tm); if(show_err)err(msg);}
      return ret_offset;
    }else{ err("findp(): not defined qh ");return 0;}


  }else if( bd.hq_mode==HQ_CPZ24){
    if(qh==DOWN_QIN){
      for(i=0;i<dlt;i++){
        int which_j=get_which_j_down(which_tm);
        if(get_kk(which_j,offset-i)<0) bl_cnt++;
        else{
          tmp=get_high_bt(which_j,offset-i,offset-i+bl_cnt);

          if( bl_cnt>KK_XX && data_jz(which_tm,offset-i)>ref && tmp>high_bt ){
              ret_offset=offset-i;
              found_flag=true;
              break;
          }
          bl_cnt=0;
        }//else
      }//for
      if(found_flag==true) dx=bl_cnt;
      else{ dx=0; char msg[50]; sprintf(msg,"%d DOWN_QIN:not found",which_tm); if(show_err){ err(msg);} }
      return ret_offset;
    }else if(qh==UP_QIN){
      for(i=0;i<dlt;i++){
        int which_j=get_which_j_up(which_tm);
        if(get_kk(which_j,offset-i)>0) {ab_cnt++;}
        else{
          tmp=get_high_bt(which_j,offset-i+ab_cnt,offset-i);

          if(ab_cnt>KK_XX && data_jz(which_tm,offset-i+ab_cnt)>ref &&
                 tmp>high_bt &&  i-ab_cnt>zhou_jv ){
            ret_offset=offset-i+ab_cnt;
            found_flag=true;
            break;
          }
          ab_cnt=0;
        }
      }
      if(found_flag==true) dx=ab_cnt;
      else{ dx=0; char msg[50]; sprintf(msg,"%d UP_QIN:not found",which_tm); if(show_err)err(msg);}
      return ret_offset;

    }else if(qh==UP_HOU){
      for(i=0;(below_zero_cnt<1000)&&(i<dlt);){ // 如果回零则退出,不影响其他车
        if(don_susp==TRUE) break; // Esc
        if(offset+i<offset_buf-10){ // 后架可能要等数据

          int which_j=get_which_j_up(which_tm);
          if(get_kk(which_j,offset+i)>0) {ab_cnt++;}
          else{
            tmp=get_high_bt(which_j,offset+i,offset+i-ab_cnt);
            if(ab_cnt>KK_XX && tmp>high_bt && data_jz(which_tm,offset+i)>ref){
              ret_offset=offset+i;
              found_flag=TRUE;
              break;
            }
            ab_cnt=0;
          }
          if(data_jz(which_tm,offset+i)<zero+500) below_zero_cnt++; //如果回零,返回
          else below_zero_cnt=0;
          i++;
        }else WaitForSingleObject(g_hEvent,10);
      }
      if(found_flag==TRUE) dx=ab_cnt;
      else{ dx=0; char msg[50]; sprintf(msg,"%d UP_HOU:not found",which_tm); if(show_err)err(msg);}
      return ret_offset;
    }else if(qh==DOWN_HOU){
      for(i=0;(below_zero_cnt<1000)&&(i<dlt);){// !! below_zero_cnt<80,如果回零则退出,不影响其他车
        if(don_susp==TRUE) break;   // Esc
        if(offset+i<offset_buf-10){ /*后架可能要等数据*/
          int which_j=get_which_j_down(which_tm);
          if(get_kk(which_j,offset+i)<0) {bl_cnt++;}
          else{
            tmp=get_high_bt(which_j,offset+i-bl_cnt,offset+i);
            if(bl_cnt>KK_XX && data_jz(which_tm,offset+i-bl_cnt)>ref &&
                  tmp>high_bt && i-bl_cnt>zhou_jv){
              ret_offset=offset+i-bl_cnt;
              found_flag=TRUE;
              break;
            }
            bl_cnt=0;
          }
          if(data_jz(which_tm,offset+i)<zero+500) below_zero_cnt++;  //如果回零,返回
          else below_zero_cnt=0;
          i++;
        }else WaitForSingleObject(g_hEvent,10);
      }
      if(found_flag==TRUE) dx=bl_cnt;
      else{ dx=0; char msg[50]; sprintf(msg,"%d DOWN_HOU:not found",which_tm); if(show_err)err(msg);}
      return ret_offset;
    }else{ err("findp(): not defined qh ");return 0;}
  }else{ err("findp():not difined hq_model");return 0;}
}

long __fastcall find_down_qin(long offset,long dlt,float kk,long ref,int *dx)
/*
   offset : start point的偏移
   dlt: 找目标拐点允许相对offset的最大变化
   kk: 拐点两端的比值最大值
   ref: 目标拐点的最小值
   *dx: 找到目标拐点实际offset变化
*/
{
  if(bd.hq_mode==HQ_STMBDG || bd.hq_mode==HQ_BDG|| bd.hq_mode==HQ_CPZ||bd.hq_mode==HQ_BDG3){
    long i,ret_offset=offset;
    bool found_flag=false;
    int  bl_cnt=0;
    int tmp;

    for(i=0;i<dlt;i++){
      if(get_kk(which_tm,offset-i)<0) bl_cnt++;
      else{
        if(bd.hq_mode==HQ_BDG) tmp=data_j1(offset-i)-data_j1(offset-i+bl_cnt);
        else if(bd.hq_mode==HQ_STMBDG||bd.hq_mode==HQ_BDG3){
          if(which_tm==1) tmp=data_j1(offset-i)-data_j1(offset-i+bl_cnt);
          else            tmp=data_j2(offset-i)-data_j2(offset-i+bl_cnt);
        }else tmp= ( data_j1(offset-i)-data_j1(offset-i+bl_cnt) +
                     data_j2(offset-i)-data_j2(offset-i+bl_cnt) )/2 ;

        if( bl_cnt>KK_XX && data_jz(which_tm,offset-i)>ref && tmp>high_bt ){
            ret_offset=offset-i;
            found_flag=true;
            break;
        }
        bl_cnt=0;
      }
    }
    if(found_flag==true) *dx=bl_cnt;
    else *dx=0;
    return ret_offset;
  }

  else if( bd.hq_mode==HQ_NEWCPZ){
    long i,ret_offset=offset;
    bool found_flag=false;
    int  bl_cnt=0;
    int tmp;

    for(i=0;i<dlt;i++){
      int which_j=get_which_j_down(which_tm_newcpz);
      if(get_kk(which_j,offset-i)<0) bl_cnt++;
      else{
        tmp=get_high_bt(which_j,offset-i,offset-i+bl_cnt);

        if( bl_cnt>KK_XX && data_jz(which_tm_newcpz,offset-i)>ref && tmp>high_bt ){
            ret_offset=offset-i;
            found_flag=true;
            break;
        }
        bl_cnt=0;
      }//else
    }//for
    if(found_flag==true) *dx=bl_cnt;
    else *dx=0;
    return ret_offset;
  }

  else{
    long i,ret_offset=offset,line_count=0;
    int found_flag=FALSE;

    for(i=0;i<dlt;i++){
      if(get_rr(offset-i)) {line_count++;}
      else{
        if( line_count>RR_XX && data_jz(which_tm,offset-i)>ref ){
          if( (float)(data_jz(which_tm,offset-i+line_count)-zero)/(float)(data_jz(which_tm,offset-i)-zero)<kk ){
            ret_offset=offset-i;
            found_flag=TRUE;
            break;
          }
        }
        line_count=0;
      }
    }
    if(found_flag==TRUE) *dx=line_count;
    else *dx=0;
    return ret_offset;
  }
}

long __fastcall find_up_qin(long offset,long dlt,float kk,long ref,int *dx)
{
  try{

  if(bd.hq_mode==HQ_STMBDG || bd.hq_mode==HQ_BDG|| bd.hq_mode==HQ_CPZ||bd.hq_mode==HQ_BDG3){
    long i,ret_offset=offset,ab_cnt=0;
    bool found_flag=false;
    int tmp;

    for(i=0;i<dlt;i++){
      if(get_kk(which_tm,offset-i)>0) {ab_cnt++;}
      else{

        if(bd.hq_mode==HQ_BDG) tmp=data_j1(offset-i+ab_cnt)-data_j1(offset-i);
        else if(bd.hq_mode==HQ_STMBDG||bd.hq_mode==HQ_BDG3){

⌨️ 快捷键说明

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