📄 thread.~cp
字号:
if( ce_cnt>=MAX_CE-1 ){ return EXIT_OK;}
ce_cnt++;
} //for
return ret;
}// 开普
else if(bd.pb_mode==PB_TG){ // 泰钢
int head_is_before;
if(flag_test==0) init_kg(); // init
for(cnt_exit=0;;){
if(don_flag==FALSE){ // 等车
while(don_flag==FALSE){
Sleep(100); // 提高性能
if(don_susp==TRUE){return EXIT_ESC;}
if(kg_now>0){
if(kg[1].who==1) direct=L_R;
else direct=R_L;
don_flag=TRUE;
Synchronize(show_being);
form_main->sound();
Synchronize(repaint);
start_tm=GetCurrentTime();
Sleep(300);
}
}
}
Sleep(100); // 提高性能
if( (ret=check_exit()) != NOT_EXIT ) break; // 等车过完
}
if(kg[kg_now].k1!=kg[kg_now].k4){ce_cnt=0;return EXIT_OK ;}
head_is_before=pb_head();
int go_ce; // 过了多少车
if(direct==L_R) go_ce=(kg[kg_now].k1-2)/4;
else go_ce=(kg[kg_now].k4-2)/4;
for(ce_cnt=0,kg_used=0;kg_used<=kg_now && ce_cnt<go_ce;kg_used++){
if(direct==L_R){
if( kg[kg_used].k1>head_is_before*2 &&
kg[kg_used].k1<=(head_is_before==0?kg[kg_now].k1-2:kg[kg_now].k1) &&
(kg[kg_used].k1-head_is_before*2) %4 ==0 &&
kg[kg_used].k1==kg[kg_used].k4+4 ) start_kg=kg_used;
else continue;
}else{
if ( kg[kg_used].k4>head_is_before*2 &&
kg[kg_used].k4<=(head_is_before==0?kg[kg_now].k4-2:kg[kg_now].k4) &&
(kg[kg_used].k4-head_is_before*2) %4 ==0 &&
kg[kg_used].k4==kg[kg_used].k1+4 ) start_kg=kg_used;
else continue;
}
if(kg[start_kg].ofst==0 || kg[start_kg+1].ofst==0 ) break;
int dlt_ofst=(kg[start_kg+1].ofst-kg[start_kg].ofst)/5;
c_wei(kg[start_kg].ofst+dlt_ofst,
kg[start_kg+1].ofst-dlt_ofst/2); //计算重量
c_spd(start_kg); //计算速度
*(p_buf_z1+kg[start_kg].ofst+dlt_ofst)|=0x8000;
*(p_buf_z1+kg[start_kg+1].ofst-dlt_ofst/2)|=0x8000;
lock_weight();
Synchronize(show); //(ce_cnt);
if( ce_cnt>=MAX_CE-1 ){ return EXIT_OK;}
ce_cnt++;
} //for
return ret;
}// 泰钢
else if(bd.pb_mode==PB_JG){ // 济钢
int len[MAX_CE];
//for(int i=0;i<MAX_CE;i++) len[i]=0;
int head_is_before;
if(flag_test==0) init_kg(); // init
for(cnt_exit=0;;){
if(don_flag==FALSE){ // 等车
while(don_flag==FALSE){
Sleep(100); // 提高性能
if(don_susp==TRUE){return EXIT_ESC;}
if(kg_now>0){
if(kg[1].who==1) direct=L_R;
else direct=R_L;
don_flag=TRUE;
Synchronize(show_being);
form_main->sound();
Synchronize(repaint);
start_tm=GetCurrentTime();
Sleep(300);
}
}
}
Sleep(100); // 提高性能
if( (ret=check_exit()) != NOT_EXIT ) break; // 等车过完
}
if(kg[kg_now].k1!=kg[kg_now].k4){ce_cnt=0;return EXIT_OK ;} //漏开关
int what_head;// 机车类型
if(kg[kg_now].k1%4==0) what_head=1; //内燃机车
else{
what_head=0; //蒸气机车
head_is_before=pb_head();
}
for(ce_cnt=0,kg_used=0;kg_used<=kg_now ;kg_used++){
if(direct==L_R){
if(what_head==1){//内燃机车
if( kg[kg_used].k1%4 ==0 && kg[kg_used].k1==kg[kg_used].k4+4 ){
start_kg=kg_used;
}else continue;
}else{ //蒸气机车
if( kg[kg_used].k1>head_is_before*10 &&
kg[kg_used].k1<=(head_is_before==0?kg[kg_now].k1-10:kg[kg_now].k1) &&
(kg[kg_used].k1-head_is_before*10) %4 ==0 &&
kg[kg_used].k1==kg[kg_used].k4+4 ) start_kg=kg_used;
else continue;
}
}else{
if(what_head==1){//内燃机车
if( kg[kg_used].k4%4 ==0 && kg[kg_used].k4==kg[kg_used].k1+4 ){
start_kg=kg_used;
}else continue;
}else{ //蒸气机车
if( kg[kg_used].k4>head_is_before*10 &&
kg[kg_used].k4<=(head_is_before==0?kg[kg_now].k4-10:kg[kg_now].k4) &&
(kg[kg_used].k4-head_is_before*10) %4 ==0 &&
kg[kg_used].k4==kg[kg_used].k1+4 ) start_kg=kg_used;
else continue;
}
}
if(kg[start_kg].ofst==0 || kg[start_kg+1].ofst==0 ) break;
len[ce_cnt]=kg[start_kg+1].ofst-kg[start_kg].ofst;
if(len[ce_cnt]<130) continue;
int dlt_ofst=len[ce_cnt]/8;
//if(len[ce_cnt]>max_len) max_len=len[ce_cnt];
c_wei(kg[start_kg].ofst+dlt_ofst+dlt_ofst/2, //计算重量
kg[start_kg+1].ofst);//+dlt_ofst-dlt_ofst*3/4); 开关位子变化了
if(wei[ce_cnt]<29000) continue; //隔离车
if(kg[start_kg+1].ofst<kg[start_kg].ofst+50) continue; //隔离车
c_spd(start_kg); //计算速度
*(p_buf_z1+kg[start_kg].ofst+dlt_ofst+dlt_ofst/2)|=0x8000;
*(p_buf_z1+kg[start_kg+1].ofst)|=0x8000;
lock_weight();
Synchronize(show); //(ce_cnt);隔离车变化了
if( ce_cnt>=MAX_CE-1 ){ return EXIT_OK;}
ce_cnt++;
} //for
return ret;
}
else if(bd.pb_mode==PB_DY){ // 用剪力模拟开关判别,单羊
//int len[MAX_CE];
int ab_cnt;
const int MK_ZERO=700; // check zero // 400 --> 700
short i,j;
int head_is_before;
if(flag_test==0) 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++;
}
}
}
if(flag_test==0) don_flag=TRUE;
Synchronize(show_being);
form_main->sound();
Synchronize(repaint);
start_tm=GetCurrentTime();
// 等车过完
for(int offset_tmp=0,bl_cnt=0;bl_cnt<2000;){
if(don_susp==TRUE){return EXIT_ESC;}
if(offset_buf>BUF_SIZE/2){ return EXIT_YC;}
if(flag_test==1){if(offset_tmp>=offset_buf-10) break;}
if(offset_tmp<offset_buf-10){ //may need to wait for getdataThread
if(data_jz(0,offset_tmp)<zero+MK_ZERO){ bl_cnt++;}
else{ bl_cnt=0;}
offset_tmp++;
}else WaitForSingleObject(g_hEvent,100);
}
get_direct();
int kg1_cnt,kg4_cnt,kg1_ofst[KG_SIZE/4],kg4_ofst[KG_SIZE/4];
if(direct==L_R){
kg1_cnt=find_kg_up(1,kg1_ofst,HIGH_BT);
kg4_cnt=find_kg_down(2,kg4_ofst,HIGH_BT);
}else{
kg4_cnt=find_kg_up(2,kg4_ofst,HIGH_BT);
kg1_cnt=find_kg_down(1,kg1_ofst,HIGH_BT);
}
// 填充kg[]
for(i=1,j=1,kg_now=0;;){
if( (kg4_ofst[j]<=kg1_ofst[i] && j<=kg4_cnt) || (i>kg1_cnt&&j<=kg4_cnt) ){
kg[kg_now].ofst=kg4_ofst[j];
kg[kg_now].who=4;
j++;
kg[kg_now].k1=short(i-1);
kg[kg_now].k4=short(j-1);
kg_now++;
}
else if((kg1_ofst[i]<=kg4_ofst[j] && i<=kg1_cnt) || (j>kg4_cnt&&i<=kg1_cnt)){
kg[kg_now].ofst=kg1_ofst[i];
kg[kg_now].who=1;
i++;
kg[kg_now].k1=short(i-1);
kg[kg_now].k4=short(j-1);
kg_now++;
}
if(i>kg1_cnt && j>kg4_cnt) break;
}
kg_now-=1;
int what_head;// 机车类型
if(kg[kg_now].k1%4==0){
what_head=1; //四轴机车
if(abs(kg[3].k1-kg[3].k4)==2){ head_is_before=1;}
else{ head_is_before=0;}
}else{
what_head=0; //六轴机车
double d=1.0*(kg[2].ofst-kg[1].ofst)/(kg[1].ofst-kg[0].ofst);
//char s[100];
//sprintf(s,"%5.2f",d);
//err(s);
if(d<1.8) head_is_before=1;
else head_is_before=0;
//head_is_before=pb_head();
}
struct{
int ce_cnt;
int kg_index;
}start[MAX_CE];
start[0].kg_index=0;
start[0].ce_cnt=0;
int index=1;
for(ce_cnt=0,kg_used=0;kg_used<=kg_now ;kg_used++){
if(direct==L_R){
if(what_head==1){//四轴内燃机车
if( kg[kg_used].k1%4 ==0 && kg[kg_used].k1==kg[kg_used].k4+4 ){
start_kg=kg_used;
ce_cnt=(kg[kg_used].k4-head_is_before*4)/4;
start[index].kg_index=start_kg;
start[index].ce_cnt=ce_cnt+1;
index++;
}else continue;
}else{ //六轴机车
if( kg[kg_used].k1>head_is_before*6 &&
kg[kg_used].k1<=(head_is_before==0?kg[kg_now].k1-6:kg[kg_now].k1) &&
(kg[kg_used].k1-head_is_before*6) %4 ==0 &&
kg[kg_used].k1==kg[kg_used].k4+4 ){
start_kg=kg_used;
ce_cnt=(kg[kg_used].k4-head_is_before*6)/4;
start[index].kg_index=start_kg;
start[index].ce_cnt=ce_cnt+1;
index++;
}else continue;
}
}else{ //R_L
if(what_head==1){//四轴内燃机车
if( kg[kg_used].k4%4 ==0 && kg[kg_used].k4==kg[kg_used].k1+4 ){
start_kg=kg_used;
ce_cnt=(kg[kg_used].k1-head_is_before*4)/4;
start[index].kg_index=start_kg;
start[index].ce_cnt=ce_cnt+1;
index++;
}else continue;
}else{ //六轴机车
if( kg[kg_used].k4>head_is_before*6 &&
kg[kg_used].k4<=(head_is_before==0?kg[kg_now].k4-6:kg[kg_now].k4) &&
(kg[kg_used].k4-head_is_before*6) %4 ==0 &&
kg[kg_used].k4==kg[kg_used].k1+4 ){
start_kg=kg_used;
ce_cnt=(kg[kg_used].k1-head_is_before*6)/4;
start[index].kg_index=start_kg;
start[index].ce_cnt=ce_cnt+1;
index++;
}else continue;
}
}
if(kg[start_kg].ofst==0 || kg[start_kg+1].ofst==0 ) break;
int dlt_ofst=(kg[start_kg+1].ofst-kg[start_kg].ofst)/8;
//if(len[ce_cnt]>max_len) max_len=len[ce_cnt];
c_wei(kg[start_kg].ofst+dlt_ofst, //计算重量
kg[start_kg+1].ofst-dlt_ofst);
c_spd(start_kg); //计算速度
*(p_buf_z1+kg[start_kg].ofst+dlt_ofst)|=0x8000;
*(p_buf_z1+kg[start_kg+1].ofst-dlt_ofst)|=0x8000;
lock_weight();
Synchronize(show); //(ce_cnt);隔离车变化了
//ce_cnt++;
} //for
int ct_ls;
if(what_head==1) ct_ls=4;
else ct_ls=6;
int total_ce_cnt=(kg[kg_now].k1-ct_ls)/4;
start[index].kg_index=kg_now;
start[index].ce_cnt=total_ce_cnt+1;
for(int i=0;i<index;i++){
if(start[i+1].ce_cnt>start[i].ce_cnt+1 ){ //判长车
int last;
int x=0;
int start_zxj[MAX_CE*2];
last=head_is_before*ct_ls+start[i].ce_cnt*4;
if(direct==L_R){
for(int j=start[i].kg_index;j<start[i+1].kg_index;j++){
if( kg[j].k1==kg[j].k4+2 && kg[j].k4==last){ start_zxj[x++]=j;last+=2;}
}
}else{ // R_L
for(int j=start[i].kg_index;j<start[i+1].kg_index;j++){
if( kg[j].k4==kg[j].k1+2 && kg[j].k1==last){ start_zxj[x++]=j;last+=2;}
}
}
for(int i=0;i<x;i+=2){
int j=start_zxj[i];
int k=start_zxj[i+1];
int ad1,ad2;
int dlt1,dlt2;
dlt1=(kg[j+1].ofst-kg[j].ofst)/8;
dlt2=(kg[k+1].ofst-kg[k].ofst)/8;
if(direct==L_R) ce_cnt=(kg[j].k4-head_is_before*ct_ls)/4;
else ce_cnt=(kg[j].k1-head_is_before*ct_ls)/4;
if(ce_cnt>=total_ce_cnt) break;
ad1=js_ad(0,kg[j].ofst+dlt1,kg[j+1].ofst-dlt1)-zero;
ad2=js_ad(0,kg[k].ofst+dlt2,kg[k+1].ofst-dlt2)-zero;
qin_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -