|
|
|
|
#include "common.h"
|
|
|
|
|
#include "ysp_debug.h"
|
|
|
|
|
#include "msq.h"
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#include "thread.h"
|
|
|
|
|
#include "analysis.h"
|
|
|
|
|
|
|
|
|
|
#define DEBUG_ANALYSIS
|
|
|
|
|
|
|
|
|
|
#define REDUCE_BIT 3 //
|
|
|
|
|
#define SUM_NUM 8 //ÿ<><C3BF><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>
|
|
|
|
|
#define MOVE_NUM 8 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6>ĵ<EFBFBD><C4B5><EFBFBD>
|
|
|
|
|
#define JUDGE_NUM 8 //ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϵĵ<CFB5><C4B5><EFBFBD>
|
|
|
|
|
|
|
|
|
|
#define MAX_JUDGE_NUM 32 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϵ<D0B6><CFB5><EFBFBD>
|
|
|
|
|
#define MIN_JUDGE_NUM 7 //<2F><>С<EFBFBD>жϵ<D0B6><CFB5><EFBFBD>
|
|
|
|
|
|
|
|
|
|
#define MIN_AMP 4 //<2F><>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
#define MIN_LEN 12 //<2F><>Сʱ<D0A1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
#define BACK_SUM_NUM 20
|
|
|
|
|
/*
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>:
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪH2,CO,CH4,C2H4,C2H6,C2H2
|
|
|
|
|
ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㹫ʽΪ:
|
|
|
|
|
S=A*K=K*h*tr
|
|
|
|
|
A=<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
h=<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ߵ<EFBFBD>ֵ-<EFBFBD><EFBFBD>ֵ)
|
|
|
|
|
tr=<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)
|
|
|
|
|
K=<EFBFBD>궨ϵ<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㹫ʽΪ:
|
|
|
|
|
S=A*K=K*1.064*h*(y/2)=1.064*K*h*h/4
|
|
|
|
|
A=1.064*h*(y/2)=1.064*h*h/4
|
|
|
|
|
y/2=<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
h=<EFBFBD><EFBFBD><EFBFBD><EFBFBD>=<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>-<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
y/2=h/2
|
|
|
|
|
<EFBFBD>߶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
H'=Kx(H-<EFBFBD><EFBFBD>С<EFBFBD>߶<EFBFBD>)*tr+<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ũ<EFBFBD><EFBFBD>ֵ
|
|
|
|
|
HΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ߶<EFBFBD>
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ:
|
|
|
|
|
S'=Kx(S-<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)+<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ũ<EFBFBD><EFBFBD>ֵ
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>KxΪK1-K12<EFBFBD>е<EFBFBD>һ<EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD>,SΪԭʼ<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Kxͨ<EFBFBD><EFBFBD>S<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>Kx<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊkx_fac4,KxΪkx_fac1,<EFBFBD><EFBFBD>Ũ<EFBFBD><EFBFBD>ֵΪkx_fac2
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define MIN_SLOPE 1
|
|
|
|
|
#define ANALYSIS_MESSAGE_SIZE 1024
|
|
|
|
|
#define ANALYSIS_MAX_MESSAGE 8
|
|
|
|
|
#define ANALYSIS_MQ_PRIO 30
|
|
|
|
|
#define ANALYSIS_MQ "/analysis_mq"
|
|
|
|
|
|
|
|
|
|
#define MAX_DATA_LEN 5000
|
|
|
|
|
|
|
|
|
|
mqd_t analysis_mq;//
|
|
|
|
|
char analysis_buf[ANALYSIS_MESSAGE_SIZE];
|
|
|
|
|
|
|
|
|
|
int slope_data[MAX_DATA_LEN];
|
|
|
|
|
|
|
|
|
|
int filter_data[MAX_DATA_LEN];
|
|
|
|
|
|
|
|
|
|
int raw_data_buf[MAX_DATA_LEN];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
1.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>ʼ<EFBFBD><EFBFBD>㶥<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
2.<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>δ<EFBFBD>ҵ<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
3.ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>ҳ<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>趨<EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5>ۼӺ<DBBC>
|
|
|
|
|
int cal_int_sum(int *buf,int len)
|
|
|
|
|
{
|
|
|
|
|
int sum=0;
|
|
|
|
|
int i;
|
|
|
|
|
if(buf==NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
|
sum+=(*buf++);
|
|
|
|
|
return sum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>ֵ
|
|
|
|
|
int cal_int_avr(int *buf,int len)
|
|
|
|
|
{
|
|
|
|
|
int sum=0;
|
|
|
|
|
if(len<=0)
|
|
|
|
|
return 0;
|
|
|
|
|
sum=cal_int_sum(buf,len);
|
|
|
|
|
return sum/len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><>С<EFBFBD><D0A1><EFBFBD>̱<EFBFBD><CCB1>ڷ<EFBFBD><DAB7><EFBFBD>
|
|
|
|
|
void reduce_data(int *buf,int len,int *out,int fac)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
|
{
|
|
|
|
|
out[i]=(buf[i]>>fac);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>λ<EFBFBD><CEBB>
|
|
|
|
|
int find_max_val(int *buf,int len,int *val)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int max_val,max_pos;
|
|
|
|
|
max_val=buf[0];
|
|
|
|
|
max_pos=0;
|
|
|
|
|
|
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
|
{
|
|
|
|
|
if(buf[i]>max_val)
|
|
|
|
|
{
|
|
|
|
|
max_val=buf[i];
|
|
|
|
|
max_pos=i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(val!=NULL)
|
|
|
|
|
*val=max_val;
|
|
|
|
|
return max_pos;
|
|
|
|
|
}
|
|
|
|
|
//time():974943297
|
|
|
|
|
//time()->localtime()->mktime():974943297
|
|
|
|
|
int find_max_val_ex(int *buf,int len,int *val)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int max_val,max_pos;
|
|
|
|
|
|
|
|
|
|
max_val=buf[0];
|
|
|
|
|
max_pos=0;
|
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
|
{
|
|
|
|
|
if(buf[i]>=max_val)
|
|
|
|
|
{
|
|
|
|
|
max_val=buf[i];
|
|
|
|
|
max_pos=i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(val!=NULL)
|
|
|
|
|
*val=max_val;
|
|
|
|
|
return max_pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//ref_val<61>᷵<EFBFBD><E1B7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
void process_data(int *raw_data,int len,int *ref_val)
|
|
|
|
|
{
|
|
|
|
|
static float proc_data[MAX_DATA_LEN];
|
|
|
|
|
float start_val,end_val,delt_y;
|
|
|
|
|
float offs;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
|
{
|
|
|
|
|
proc_data[i]=(float)raw_data[i];
|
|
|
|
|
}
|
|
|
|
|
//start_val=(float)cal_int_avr(&raw_data[0],4);//ȡ<><C8A1><EFBFBD>㿪ʼ8<CABC><38>ƽ<EFBFBD><C6BD>
|
|
|
|
|
//end_val=(float)cal_int_avr(&raw_data[len-9],4);//ȡ<>յ<EFBFBD>ǰ8<C7B0><38>ƽ<EFBFBD><C6BD>
|
|
|
|
|
start_val=(float)raw_data[0];
|
|
|
|
|
end_val=(float)raw_data[len-1];
|
|
|
|
|
delt_y=(end_val-start_val)/len;//<2F><><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>
|
|
|
|
|
|
|
|
|
|
offs=(float)(start_val-((float)(*ref_val)));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ȥ<EFBFBD>ο<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>
|
|
|
|
|
//printf("start=%f ref_val=%d offs=%f\n",start_val,*ref_val,offs);
|
|
|
|
|
//if(delt_y>0)
|
|
|
|
|
//{
|
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
|
{
|
|
|
|
|
proc_data[i]=proc_data[i]-delt_y*i;//<2F><>ƽ
|
|
|
|
|
raw_data[i]=(int)(proc_data[i]-offs);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
*ref_val=raw_data[i-1];
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>λ<EFBFBD><CEBB>
|
|
|
|
|
int find_max_val_ex(int *buf,int len,int *val)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int max_val,max_pos,top_end_pos,top_end_val;
|
|
|
|
|
int curr;
|
|
|
|
|
|
|
|
|
|
top_end_val=cal_int_sum(&buf[len-1-BACK_SUM_NUM],BACK_SUM_NUM);
|
|
|
|
|
top_end_pos=len-1-BACK_SUM_NUM;
|
|
|
|
|
|
|
|
|
|
for(i=(len-1-BACK_SUM_NUM);i>=0;i-=(BACK_SUM_NUM/2))
|
|
|
|
|
{
|
|
|
|
|
curr=cal_int_sum(&buf[i],BACK_SUM_NUM);
|
|
|
|
|
if(curr<=(top_end_val+2))
|
|
|
|
|
{
|
|
|
|
|
top_end_val=curr;
|
|
|
|
|
top_end_pos=i+(BACK_SUM_NUM/2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//printf("i=%d top_end_pos=%d\n",i,top_end_pos);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
max_pos=find_max_val(buf,top_end_pos,NULL);
|
|
|
|
|
//printf("max_pos=%d\n",max_pos);
|
|
|
|
|
return max_pos;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼӺ<DBBC>,<2C><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>,sum_numΪ<6D>ۼӵĵ<D3B5><C4B5><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int find_max_sum(int *buf,int len,int sum_num,int delt)
|
|
|
|
|
{
|
|
|
|
|
int i,result;
|
|
|
|
|
int curr_sum,max_sum;
|
|
|
|
|
|
|
|
|
|
max_sum=cal_int_sum(buf,sum_num);
|
|
|
|
|
result=0;
|
|
|
|
|
for(i=sum_num;i<len;i+=sum_num)
|
|
|
|
|
{
|
|
|
|
|
curr_sum=cal_int_sum(&buf[i],sum_num);
|
|
|
|
|
if(curr_sum>max_sum)
|
|
|
|
|
{
|
|
|
|
|
max_sum=curr_sum;
|
|
|
|
|
result=i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result+=find_max_val(&buf[result],sum_num,NULL);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
int find_min_sum(int *buf,int len,int sum_num,int delt)
|
|
|
|
|
{
|
|
|
|
|
int i,result;
|
|
|
|
|
int curr_sum,min_sum;
|
|
|
|
|
|
|
|
|
|
min_sum=cal_int_sum(&buf[len-1],sum_num);
|
|
|
|
|
result=len-1;
|
|
|
|
|
for(i=len-sum_num-1;i>0;i-=sum_num)
|
|
|
|
|
{
|
|
|
|
|
curr_sum=cal_int_sum(&buf[i-sum_num],sum_num);
|
|
|
|
|
if(curr_sum<min_sum)
|
|
|
|
|
{
|
|
|
|
|
min_sum=curr_sum;
|
|
|
|
|
result=i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result+=find_max_val(&buf[result],sum_num,NULL);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int find_left_pos(int *buf,int len,int sum_num,int delt,int *ret)
|
|
|
|
|
{
|
|
|
|
|
int i,result;
|
|
|
|
|
int pre_sum,curr_sum;
|
|
|
|
|
int pos2=0,pos3=0;
|
|
|
|
|
|
|
|
|
|
result=0;
|
|
|
|
|
pre_sum=cal_int_sum(buf,sum_num);
|
|
|
|
|
for(i=0;i<len;i+=sum_num)
|
|
|
|
|
{
|
|
|
|
|
curr_sum=cal_int_sum(&buf[i],sum_num); //<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
if(curr_sum>(pre_sum+delt))
|
|
|
|
|
{
|
|
|
|
|
//printf("arrived 1\n");
|
|
|
|
|
if((cal_int_sum(&buf[i+sum_num],sum_num)+delt)<cal_int_sum(&buf[i+2*sum_num],sum_num))
|
|
|
|
|
{
|
|
|
|
|
// printf("arrived 2 %d %d\n",cal_int_sum(&buf[i+sum_num],sum_num),cal_int_sum(&buf[i+2*sum_num],sum_num));
|
|
|
|
|
pos2=i;
|
|
|
|
|
if((cal_int_sum(&buf[i+2*sum_num],sum_num)+delt)<cal_int_sum(&buf[i+3*sum_num],sum_num))
|
|
|
|
|
{
|
|
|
|
|
pos3=i;
|
|
|
|
|
//printf("arrived 3 %d %d\n",cal_int_sum(&buf[i+sum_num],sum_num),cal_int_sum(&buf[i+2*sum_num],sum_num));
|
|
|
|
|
if((cal_int_sum(&buf[i+3*sum_num],sum_num)+delt)<cal_int_sum(&buf[i+4*sum_num],sum_num))
|
|
|
|
|
{
|
|
|
|
|
//printf("arrived 4 %d %d\n",cal_int_sum(&buf[i+3*sum_num],sum_num),cal_int_sum(&buf[i+4*sum_num],sum_num));
|
|
|
|
|
if(ret!=NULL)
|
|
|
|
|
*ret=i;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pre_sum=curr_sum;
|
|
|
|
|
}
|
|
|
|
|
if(ret!=NULL)
|
|
|
|
|
{
|
|
|
|
|
if(pos3!=0)
|
|
|
|
|
{
|
|
|
|
|
*ret=pos3;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
*ret=0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>i<EFBFBD><69><EFBFBD>͵<EFBFBD>i+forward_cnt<6E><74><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>Ƚ<EFBFBD>contine_cnt<6E><74>,<2C><>Сб<D0A1><D0B1>delt
|
|
|
|
|
int FindLeftPos(int *buf,int len,int contine_cnt,int forward_cnt,int delt,int *ret)
|
|
|
|
|
{//contine_cnt=5,forward_cnt=8
|
|
|
|
|
int i,result;
|
|
|
|
|
int n=0;
|
|
|
|
|
|
|
|
|
|
if(len<(forward_cnt+contine_cnt))
|
|
|
|
|
return -1;
|
|
|
|
|
for(i=0;i<(len-forward_cnt-contine_cnt);i++)
|
|
|
|
|
{
|
|
|
|
|
result=0;
|
|
|
|
|
for(n=0;n<contine_cnt;n++)
|
|
|
|
|
{
|
|
|
|
|
if((buf[i+n]+delt)<buf[i+n+forward_cnt])
|
|
|
|
|
{
|
|
|
|
|
result++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(result>=contine_cnt)
|
|
|
|
|
{
|
|
|
|
|
*ret=(i+(forward_cnt/2));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>(i<>㵽<EFBFBD><E3B5BD>i+per_width<74><68>ƽ<EFBFBD><C6BD>ֵ)<29><>
|
|
|
|
|
//<2F><>(i+tot_width<74><68><EFBFBD><EFBFBD>i+tot_width+per_width<74><68>ƽ<EFBFBD><C6BD>ֵ)
|
|
|
|
|
//<2F>Ƚ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>Ƚ<EFBFBD>3<EFBFBD><33>,ÿ<>Ƚ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>mov_width<74><68>
|
|
|
|
|
int FindLeftPosEx(int *buf,int len,int tot_width,int per_width,int mov_width,int min_slope)
|
|
|
|
|
{
|
|
|
|
|
int i,n,result;
|
|
|
|
|
int avr_val1[3],avr_val2[3];
|
|
|
|
|
result=-1;
|
|
|
|
|
if(len<=(tot_width+4*mov_width+per_width))
|
|
|
|
|
return -1;
|
|
|
|
|
for(n=0;n<(len-tot_width-4*mov_width-per_width);n++)
|
|
|
|
|
{
|
|
|
|
|
for(i=0;i<(sizeof(avr_val1)/sizeof(int));i++)
|
|
|
|
|
{
|
|
|
|
|
avr_val1[i]=cal_int_avr(&buf[n+i*mov_width],per_width);
|
|
|
|
|
avr_val2[i]=cal_int_avr(&buf[n+i*mov_width+tot_width],per_width);
|
|
|
|
|
}
|
|
|
|
|
if(avr_val1[2]<avr_val2[0])
|
|
|
|
|
{
|
|
|
|
|
if((avr_val2[0]<avr_val2[1])&&(avr_val2[1]<avr_val2[2]))
|
|
|
|
|
{
|
|
|
|
|
if((avr_val1[0]+min_slope)<avr_val2[0])
|
|
|
|
|
{
|
|
|
|
|
if((avr_val1[1]+min_slope)<avr_val2[1])
|
|
|
|
|
{
|
|
|
|
|
if((avr_val1[2]+min_slope)<avr_val2[2])
|
|
|
|
|
{
|
|
|
|
|
result=n+(2*mov_width)+(tot_width/2);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result; //
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FindMaxPos(int *buf,int len,GRADIENT_TYPE_DEF *para_ptr,int *str,int *peak)
|
|
|
|
|
{
|
|
|
|
|
int max_pos;
|
|
|
|
|
int tmp_len;
|
|
|
|
|
int i,n=0;
|
|
|
|
|
int max_val;
|
|
|
|
|
|
|
|
|
|
max_pos=find_max_val(buf,len,&max_val);
|
|
|
|
|
|
|
|
|
|
if(max_pos<len)
|
|
|
|
|
{
|
|
|
|
|
if((max_pos+16)<len)
|
|
|
|
|
tmp_len=16;
|
|
|
|
|
else
|
|
|
|
|
tmp_len=len-max_pos;
|
|
|
|
|
|
|
|
|
|
n=0;
|
|
|
|
|
for(i=max_pos+1;i<tmp_len;i++)
|
|
|
|
|
{
|
|
|
|
|
if(buf[i]!=max_val)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
max_pos+=(n/2);
|
|
|
|
|
if(peak!=NULL)
|
|
|
|
|
*peak=max_pos;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int find_key_pos1(int *buf,int len,YSP_PARA *para_ptr,FIND_POS_DATA *pos_data)
|
|
|
|
|
{
|
|
|
|
|
int i,n,*data_stream;
|
|
|
|
|
int start_pos,end_pos;
|
|
|
|
|
int left_pos,top_pos,right_pos;
|
|
|
|
|
int ret=0;
|
|
|
|
|
int top_val,left_val;
|
|
|
|
|
int top_flg=0,left_flg=0;
|
|
|
|
|
int str_pos,peak_pos;
|
|
|
|
|
int min_slope;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>ݶ<EFBFBD>
|
|
|
|
|
int mov_tick;
|
|
|
|
|
for(i=INDEX_H2;i<=INDEX_C2H2;i++)
|
|
|
|
|
{
|
|
|
|
|
//1.<2E><><EFBFBD>Ҷ<EFBFBD><D2B6><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD>㶥<EFBFBD><E3B6A5><EFBFBD><EFBFBD>ʼλ<CABC><CEBB>
|
|
|
|
|
start_pos=para_ptr->gas_cal_fac[i].position.start;
|
|
|
|
|
//<2F><><EFBFBD>㶥<EFBFBD><E3B6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
//end_pos=para_ptr->gas_cal_fac[i].position.peak+para_ptr->gas_cal_fac[i].position.width;
|
|
|
|
|
end_pos=para_ptr->gas_cal_fac[i].position.end;
|
|
|
|
|
|
|
|
|
|
//printf("start_pos=%d\n",start_pos);
|
|
|
|
|
|
|
|
|
|
while(start_pos<end_pos)
|
|
|
|
|
{
|
|
|
|
|
if(cal_int_sum(&buf[start_pos],SUM_NUM)>cal_int_sum(&buf[start_pos+SUM_NUM],SUM_NUM))
|
|
|
|
|
{
|
|
|
|
|
start_pos+=2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if((start_pos+5+8)<end_pos)
|
|
|
|
|
{
|
|
|
|
|
data_stream=buf+start_pos;//
|
|
|
|
|
min_slope=(int)para_ptr->gas_cal_fac[i].gradient.lYmin;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><35>,<2C><>1<EFBFBD><31><EFBFBD>͵<EFBFBD>8<EFBFBD><38><EFBFBD><EFBFBD>
|
|
|
|
|
if(FindLeftPos(data_stream,end_pos-start_pos,5,8,min_slope,&str_pos)==0)
|
|
|
|
|
{
|
|
|
|
|
FindMaxPos(data_stream+str_pos,end_pos-start_pos-str_pos,NULL,NULL,&peak_pos);
|
|
|
|
|
left_pos=start_pos+str_pos;
|
|
|
|
|
top_pos=left_pos+peak_pos;
|
|
|
|
|
//if(top_pos>(left_pos+MIN_LEN))
|
|
|
|
|
//{
|
|
|
|
|
left_val=*(buf+left_pos);
|
|
|
|
|
top_val=*(buf+top_pos);
|
|
|
|
|
// if((left_val+MIN_AMP)<top_val)
|
|
|
|
|
// {
|
|
|
|
|
ret|=(1<<i);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"find pos%d in 1st\n",i);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ //<2F><><EFBFBD><EFBFBD>δ<EFBFBD>ҵ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FindMaxPos(data_stream,end_pos-start_pos,NULL,NULL,&peak_pos);
|
|
|
|
|
left_pos=start_pos;//<2F><><EFBFBD>趨<EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
top_pos=start_pos+peak_pos;//<2F><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ<D6B5><CEAA><EFBFBD><EFBFBD>
|
|
|
|
|
//if(i==INDEX_CO||i==INDEX_CH4)
|
|
|
|
|
if(i==INDEX_CO)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"find pos%d in 2st\n",i);
|
|
|
|
|
ret|=(1<<i);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ //<2F>ж<EFBFBD><D0B6><EFBFBD><EEB6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>ֵ?
|
|
|
|
|
mov_tick=0;
|
|
|
|
|
end_pos=start_pos+peak_pos;
|
|
|
|
|
while(end_pos>(start_pos+MIN_LEN))
|
|
|
|
|
{
|
|
|
|
|
if(cal_int_sum(&buf[end_pos-(SUM_NUM/2)],SUM_NUM)>cal_int_sum(&buf[end_pos-SUM_NUM],SUM_NUM))
|
|
|
|
|
{
|
|
|
|
|
end_pos-=2;
|
|
|
|
|
mov_tick++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"find pos%d in 2st\n",i);
|
|
|
|
|
if(mov_tick>10)
|
|
|
|
|
{
|
|
|
|
|
left_pos=end_pos;
|
|
|
|
|
ret|=(1<<i);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//left_pos=top_pos;
|
|
|
|
|
top_pos=left_pos;
|
|
|
|
|
ret&=(~(1<<i));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if((ret&(1<<i))==0)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"find pos%d in 2st failed\n",i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>̫խ,<2C><><EFBFBD><EFBFBD>CO<43><4F>ֱ<EFBFBD>Ӹ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"find pos%d failed for data error\n",i);
|
|
|
|
|
if(i==INDEX_CO)
|
|
|
|
|
{
|
|
|
|
|
left_pos=para_ptr->gas_cal_fac[i].position.start;
|
|
|
|
|
top_pos=para_ptr->gas_cal_fac[i].position.peak;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
left_pos=start_pos;
|
|
|
|
|
top_pos=left_pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(pos_data!=NULL)
|
|
|
|
|
{
|
|
|
|
|
pos_data->position[i].start=left_pos;
|
|
|
|
|
pos_data->position[i].peak=top_pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int find_key_pos2(int *buf,int len,YSP_PARA *para_ptr,FIND_POS_DATA *pos_data)
|
|
|
|
|
{
|
|
|
|
|
int ret=0;
|
|
|
|
|
int i;
|
|
|
|
|
int *curr_ptr;
|
|
|
|
|
int min_slope;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>ݶ<EFBFBD>
|
|
|
|
|
int start_pos,end_pos;//<2F>趨<EFBFBD><E8B6A8><EFBFBD><EFBFBD>ʼλ<CABC>úͽ<C3BA><CDBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
int pos_start,pos_peak;//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
int start_val,peak_val;//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>ֵ
|
|
|
|
|
for(i=INDEX_H2;i<=INDEX_C2H2;i++)
|
|
|
|
|
{
|
|
|
|
|
start_pos=para_ptr->gas_cal_fac[i].position.start;
|
|
|
|
|
end_pos=para_ptr->gas_cal_fac[i].position.end;
|
|
|
|
|
min_slope=(int)para_ptr->gas_cal_fac[i].gradient.lYmin;
|
|
|
|
|
while(start_pos<end_pos)
|
|
|
|
|
{
|
|
|
|
|
if(cal_int_sum(&buf[start_pos],SUM_NUM)>cal_int_sum(&buf[start_pos+(SUM_NUM/2)],SUM_NUM))
|
|
|
|
|
{
|
|
|
|
|
start_pos+=2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(start_pos<end_pos)
|
|
|
|
|
{
|
|
|
|
|
curr_ptr=buf+start_pos;
|
|
|
|
|
if((pos_start=FindLeftPosEx(curr_ptr,end_pos-start_pos,16,SUM_NUM,MOVE_NUM,min_slope))>0)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҷ<EFBFBD><D2B6><EFBFBD>
|
|
|
|
|
FindMaxPos(curr_ptr+pos_start,end_pos-start_pos-pos_start,¶_ptr->gas_cal_fac[i].gradient,NULL,&pos_peak);
|
|
|
|
|
pos_start+=start_pos;
|
|
|
|
|
pos_peak+=pos_start;
|
|
|
|
|
if(pos_peak>(pos_start+MIN_LEN))//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
start_val=*(buf+pos_start);
|
|
|
|
|
peak_val=*(buf+pos_peak);
|
|
|
|
|
if((start_val+MIN_AMP)<peak_val)//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD><EFBFBD>ĸ߶Ȳ<DFB6>
|
|
|
|
|
{
|
|
|
|
|
ret|=(1<<i);//<2F>ҵ<EFBFBD><D2B5>˺ϸ<CBBA><CFB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//<2F><>(<28><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>ֵ)<29><>
|
|
|
|
|
//<2F><>(<28><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>ֵ)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ //<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
pos_start=start_pos;
|
|
|
|
|
pos_peak=pos_start;
|
|
|
|
|
}
|
|
|
|
|
if(pos_data!=NULL)
|
|
|
|
|
{
|
|
|
|
|
pos_data->position[i].start=pos_start;
|
|
|
|
|
pos_data->position[i].peak=pos_peak;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int find_left_pos_ex(int *buf,int len,int sum_num,int delt)
|
|
|
|
|
{
|
|
|
|
|
int i,result;
|
|
|
|
|
int start_sum,curr_sum;
|
|
|
|
|
|
|
|
|
|
start_sum=cal_int_sum(&buf[len-sum_num-1],sum_num);//<2F><><EFBFBD>ұߵĵ<DFB5>
|
|
|
|
|
|
|
|
|
|
result=len-sum_num-1;
|
|
|
|
|
|
|
|
|
|
for(i=len-sum_num-1;i>0;i-=sum_num)
|
|
|
|
|
{
|
|
|
|
|
curr_sum=cal_int_sum(&buf[i-sum_num],sum_num); //<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
if((curr_sum+delt)>start_sum)
|
|
|
|
|
{
|
|
|
|
|
if((cal_int_sum(&buf[i-2*sum_num],sum_num)+delt)>=cal_int_sum(&buf[i-sum_num],sum_num))
|
|
|
|
|
{
|
|
|
|
|
if((cal_int_sum(&buf[i-3*sum_num],sum_num)+delt)>=cal_int_sum(&buf[i-2*sum_num],sum_num))
|
|
|
|
|
{
|
|
|
|
|
if((cal_int_sum(&buf[i-4*sum_num],sum_num)+delt)>=cal_int_sum(&buf[i-3*sum_num],sum_num))
|
|
|
|
|
{
|
|
|
|
|
//if((cal_int_sum(&buf[i-5*sum_num],sum_num)+delt)>cal_int_sum(&buf[i-4*sum_num],sum_num))
|
|
|
|
|
// {
|
|
|
|
|
result=len-i;
|
|
|
|
|
break;
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
start_sum=curr_sum;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int find_key_pos(int *buf,int len,YSP_PARA *para_ptr,FIND_POS_DATA *pos_data)
|
|
|
|
|
{
|
|
|
|
|
int i,n,*data_stream;
|
|
|
|
|
int start_pos,end_pos;
|
|
|
|
|
int left_pos,top_pos,right_pos;
|
|
|
|
|
int ret=0;
|
|
|
|
|
int top_val,left_val;
|
|
|
|
|
int top_flg=0,left_flg=0;
|
|
|
|
|
|
|
|
|
|
// #ifdef DEBUG_ANALYSIS
|
|
|
|
|
int str_pos,peak_pos;
|
|
|
|
|
//#endif
|
|
|
|
|
for(i=INDEX_H2;i<=INDEX_C2H2;i++)
|
|
|
|
|
{
|
|
|
|
|
//1.<2E><><EFBFBD>Ҷ<EFBFBD><D2B6><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD>㶥<EFBFBD><E3B6A5><EFBFBD><EFBFBD>ʼλ<CABC><CEBB>
|
|
|
|
|
start_pos=para_ptr->gas_cal_fac[i].position.start;
|
|
|
|
|
//<2F><><EFBFBD>㶥<EFBFBD><E3B6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
//end_pos=para_ptr->gas_cal_fac[i].position.peak+para_ptr->gas_cal_fac[i].position.width;
|
|
|
|
|
end_pos=para_ptr->gas_cal_fac[i].position.end;
|
|
|
|
|
|
|
|
|
|
//printf("start_pos=%d\n",start_pos);
|
|
|
|
|
|
|
|
|
|
while(start_pos<end_pos)
|
|
|
|
|
{
|
|
|
|
|
if(cal_int_sum(&buf[start_pos],SUM_NUM)>cal_int_sum(&buf[start_pos+SUM_NUM],SUM_NUM))
|
|
|
|
|
{
|
|
|
|
|
start_pos+=2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data_stream=buf+start_pos;//
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
//if(i==INDEX_C2H4)
|
|
|
|
|
if(find_top_pos(data_stream,end_pos-start_pos,&(para_ptr->gas_cal_fac[i].gradient),&str_pos,&peak_pos)>0)
|
|
|
|
|
{
|
|
|
|
|
//top_val=data_stream[peak_pos];
|
|
|
|
|
top_pos=peak_pos+start_pos;//
|
|
|
|
|
|
|
|
|
|
top_val=top_pos-para_ptr->gas_cal_fac[i].position.width;
|
|
|
|
|
|
|
|
|
|
data_stream=buf+top_val;
|
|
|
|
|
|
|
|
|
|
top_pos=top_val+find_max_val(data_stream,para_ptr->gas_cal_fac[i].position.width+8,NULL);
|
|
|
|
|
top_val=buf[top_pos];
|
|
|
|
|
top_flg|=(1<<i);
|
|
|
|
|
|
|
|
|
|
//CO<43><4F>CH4ֻ<34><D6BB>Ҫ<EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(i==INDEX_CO||i==INDEX_CH4)
|
|
|
|
|
{
|
|
|
|
|
ret|=(1<<i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
start_pos=para_ptr->gas_cal_fac[i].position.peak-(para_ptr->gas_cal_fac[i].position.width/2);
|
|
|
|
|
end_pos=start_pos+para_ptr->gas_cal_fac[i].position.width;
|
|
|
|
|
|
|
|
|
|
data_stream=buf+start_pos;//
|
|
|
|
|
top_pos=find_max_val(data_stream,end_pos-start_pos,NULL);//<2F><><EFBFBD>Ҷ<EFBFBD><D2B6><EFBFBD>
|
|
|
|
|
top_val=data_stream[top_pos];
|
|
|
|
|
if(top_pos!=0)
|
|
|
|
|
{
|
|
|
|
|
if((top_val-data_stream[0])>MIN_AMP)//<2F>˴<EFBFBD><CBB4><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
top_pos+=start_pos;
|
|
|
|
|
top_flg|=(1<<i);
|
|
|
|
|
if(i==INDEX_CO||i==INDEX_CH4)
|
|
|
|
|
{
|
|
|
|
|
ret|=(1<<i);
|
|
|
|
|
}
|
|
|
|
|
//printf("top=%d sta=%d\n",top_val,data_stream[0]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
top_pos=para_ptr->gas_cal_fac[i].position.start;
|
|
|
|
|
//printf("top=%d sta=%d 2\n",top_val,data_stream[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//δȷ<CEB4><C8B7><EFBFBD>Ƿ<EFBFBD><C7B7>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(cal_int_avr(data_stream,4)>cal_int_avr(&data_stream[4],4))
|
|
|
|
|
{
|
|
|
|
|
if(cal_int_avr(&data_stream[4],4)>cal_int_avr(&data_stream[8],4))
|
|
|
|
|
{
|
|
|
|
|
if(cal_int_avr(&data_stream[8],4)>cal_int_avr(&data_stream[12],4))
|
|
|
|
|
{
|
|
|
|
|
//<2F>ҵ<EFBFBD><D2B5>˶<EFBFBD><CBB6><EFBFBD>
|
|
|
|
|
top_pos+=start_pos;
|
|
|
|
|
top_flg|=(1<<i);
|
|
|
|
|
if(i==INDEX_CO||i==INDEX_CH4)
|
|
|
|
|
{
|
|
|
|
|
ret|=(1<<i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ //δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
top_pos=para_ptr->gas_cal_fac[i].position.start;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
top_pos=para_ptr->gas_cal_fac[i].position.start;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ //δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
top_pos=para_ptr->gas_cal_fac[i].position.start;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(i==INDEX_CO||i==INDEX_CH4)
|
|
|
|
|
{
|
|
|
|
|
if((top_flg&(1<<i))==0)
|
|
|
|
|
{
|
|
|
|
|
ret|=(1<<i);
|
|
|
|
|
top_pos=para_ptr->gas_cal_fac[i].position.peak;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"warning:can not find top pos,use default peak_pos=%d index=%d\n",top_pos,i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if((top_flg&(1<<i))!=0)
|
|
|
|
|
{
|
|
|
|
|
start_pos=para_ptr->gas_cal_fac[i].position.start;//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>±<EFBFBD>
|
|
|
|
|
data_stream=buf+start_pos;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD>Ƶ<EFBFBD>ַ
|
|
|
|
|
end_pos=top_pos;//<2F><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
|
|
|
|
if(find_left_pos(data_stream,end_pos-start_pos,SUM_NUM,(int)para_ptr->gas_cal_fac[i].gradient.lYmin,&left_pos)==0)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
left_val=data_stream[left_pos];
|
|
|
|
|
left_pos+=start_pos;
|
|
|
|
|
left_flg|=(1<<i);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{//δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
left_pos=top_pos;
|
|
|
|
|
left_val=top_val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
left_pos=top_pos;
|
|
|
|
|
left_val=top_val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(i!=INDEX_CO&&i!=INDEX_CH4)
|
|
|
|
|
{
|
|
|
|
|
if((top_val<=(left_val+MIN_AMP))||((left_pos+MIN_LEN)>=top_pos))
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ANALYSIS_EEROR_DEBUG,"error:left_val=%d top_val=%d index=%d\n",left_val,top_val,i);
|
|
|
|
|
ret&=(~(1<<i));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ret|=(1<<i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pos_data->position[i].start=left_pos;
|
|
|
|
|
pos_data->position[i].peak=top_pos;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
int find_left_start(int *buf,int len,GRADIENT_TYPE_DEF *para_ptr,int *str,int *peak)
|
|
|
|
|
{
|
|
|
|
|
int i,n;
|
|
|
|
|
int area[JUDGE_NUM];
|
|
|
|
|
int k[JUDGE_NUM];
|
|
|
|
|
int avr[JUDGE_NUM];
|
|
|
|
|
int str_pos=0;
|
|
|
|
|
int peak_pos=0;
|
|
|
|
|
int tmp;
|
|
|
|
|
int find_flg=0;
|
|
|
|
|
|
|
|
|
|
for(n=0;n<JUDGE_NUM;n++)
|
|
|
|
|
{
|
|
|
|
|
area[n]=cal_int_sum(&buf[n*MOVE_NUM],SUM_NUM);
|
|
|
|
|
avr[n]=area[n]/SUM_NUM;
|
|
|
|
|
}
|
|
|
|
|
tmp=area[0];
|
|
|
|
|
for(n=0;n<JUDGE_NUM;n++)
|
|
|
|
|
{
|
|
|
|
|
k[n]=area[n]-tmp;
|
|
|
|
|
tmp=area[n];
|
|
|
|
|
printf("k%d=%d ",n,k[n]);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
for(i=(JUDGE_NUM*MOVE_NUM);i<len;i+=MOVE_NUM)
|
|
|
|
|
{
|
|
|
|
|
printf("k0=%d k1=%d k2=%d k3=%d k4=%d\n",k[0],k[1],k[2],k[3],k[4]);
|
|
|
|
|
for(n=0;n<(JUDGE_NUM-1);n++)
|
|
|
|
|
{
|
|
|
|
|
if(k[n]>=k[n+1])
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//printf("\n");
|
|
|
|
|
//Ҳ<><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>para_ptr->lYmin;
|
|
|
|
|
if(n>=(JUDGE_NUM-2))
|
|
|
|
|
{
|
|
|
|
|
if((k[0]>=0)&&k[1]>0&&k[2]>0&&k[3]>0&&k[4]>0)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(find_flg==0)
|
|
|
|
|
{
|
|
|
|
|
str_pos=i-JUDGE_NUM*MOVE_NUM;
|
|
|
|
|
//printf("str_pos=%d ",str_pos);
|
|
|
|
|
find_flg=1;
|
|
|
|
|
if(str!=NULL)
|
|
|
|
|
*str=str_pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F>Ҷ<EFBFBD><D2B6><EFBFBD>
|
|
|
|
|
if(find_flg!=0)
|
|
|
|
|
{
|
|
|
|
|
for(n=(JUDGE_NUM-1);n>=0;n--)
|
|
|
|
|
{
|
|
|
|
|
if(k[n]>=0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(n<1)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
tmp=i-((JUDGE_NUM-n)*MOVE_NUM);
|
|
|
|
|
if(peak_pos==0)
|
|
|
|
|
{
|
|
|
|
|
peak_pos=tmp;
|
|
|
|
|
if(peak!=NULL)
|
|
|
|
|
*peak=peak_pos;
|
|
|
|
|
//printf("top_pos=%d\n",peak_pos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
for(n=0;n<(JUDGE_NUM-1);n++)
|
|
|
|
|
{
|
|
|
|
|
area[n]=area[n+1];
|
|
|
|
|
k[n]=k[n+1];
|
|
|
|
|
avr[n]=avr[n+1];
|
|
|
|
|
}
|
|
|
|
|
area[n]=cal_int_sum(&buf[i],SUM_NUM);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
avr[n]=area[n]/SUM_NUM;//ƽ<><C6BD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
//k[n]=avr[n]-avr[n-1];//ƽ<><C6BD>ֵ<EFBFBD><D6B5>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
k[n]=area[n]-area[n-1];//ƽ<><C6BD>ֵ<EFBFBD><D6B5>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
int find_top_pos(int *buf,int len,GRADIENT_TYPE_DEF *para_ptr,int *str,int *peak)
|
|
|
|
|
{
|
|
|
|
|
int i,n;
|
|
|
|
|
int area[JUDGE_NUM];
|
|
|
|
|
int k[JUDGE_NUM];
|
|
|
|
|
int avr[JUDGE_NUM];
|
|
|
|
|
int find_pos[JUDGE_NUM];
|
|
|
|
|
//int find_val[JUDGE_NUM];
|
|
|
|
|
int str_pos=0;
|
|
|
|
|
int peak_pos=0;
|
|
|
|
|
int left_flg,right_flg;
|
|
|
|
|
int tmp;
|
|
|
|
|
int find_num=0;
|
|
|
|
|
int pre_k=0,curr_k=0;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>JUDGE_NUM<55><4D><EFBFBD><EFBFBD>,ÿ<><C3BF><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>SUM_NUM<55><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>
|
|
|
|
|
for(n=0;n<JUDGE_NUM;n++)
|
|
|
|
|
{
|
|
|
|
|
area[n]=cal_int_sum(&buf[n*MOVE_NUM],SUM_NUM);
|
|
|
|
|
avr[n]=area[n]/SUM_NUM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmp=avr[0];
|
|
|
|
|
for(n=0;n<JUDGE_NUM;n++)
|
|
|
|
|
{
|
|
|
|
|
k[n]=avr[n]-tmp;
|
|
|
|
|
tmp=avr[n];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>JUDGE_NUM*MOVE_NUM<55><4D>ʼ<EFBFBD><CABC>
|
|
|
|
|
for(i=(JUDGE_NUM*MOVE_NUM);i<len;i+=MOVE_NUM)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if((k[JUDGE_NUM/2]<=0)&&(k[JUDGE_NUM/2+1]<=0))
|
|
|
|
|
{ //<2F>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>ݶ<EFBFBD>С<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
right_flg=2;//<2F>Ұ<EFBFBD><D2B0><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
for(n=((JUDGE_NUM/2)+1);n<JUDGE_NUM;n++)
|
|
|
|
|
{
|
|
|
|
|
if(k[n]<=0)//<2F>ϸ<EFBFBD><CFB8><EFBFBD>˵Ҫk[n]<0
|
|
|
|
|
right_flg++; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>ݶ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(right_flg>=(JUDGE_NUM/2))
|
|
|
|
|
{ //<2F>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>ݶ<EFBFBD>ȫ<EFBFBD><C8AB>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>
|
|
|
|
|
left_flg=0;
|
|
|
|
|
for(n=0;n<(JUDGE_NUM/2);n++)
|
|
|
|
|
{
|
|
|
|
|
if(k[n]>0)
|
|
|
|
|
left_flg++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(left_flg>=(JUDGE_NUM/2))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
find_pos[find_num]=i-((JUDGE_NUM+1)*MOVE_NUM/2);
|
|
|
|
|
curr_k=0;
|
|
|
|
|
for(tmp=0;tmp<(JUDGE_NUM/2);tmp++)
|
|
|
|
|
{
|
|
|
|
|
curr_k+=k[tmp];//<2F><><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>k
|
|
|
|
|
//printf("k%d=%d ",tmp,k[tmp]);
|
|
|
|
|
}
|
|
|
|
|
//printf("\n");
|
|
|
|
|
find_num++;
|
|
|
|
|
if(curr_k>pre_k)//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if(peak!=NULL)
|
|
|
|
|
{
|
|
|
|
|
*peak=i-((JUDGE_NUM+1)*MOVE_NUM/2);
|
|
|
|
|
}
|
|
|
|
|
pre_k=curr_k;
|
|
|
|
|
}
|
|
|
|
|
if(find_num>=JUDGE_NUM)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
for(n=0;n<(JUDGE_NUM-1);n++)
|
|
|
|
|
{
|
|
|
|
|
area[n]=area[n+1];
|
|
|
|
|
k[n]=k[n+1];
|
|
|
|
|
avr[n]=avr[n+1];
|
|
|
|
|
}
|
|
|
|
|
area[n]=cal_int_sum(&buf[i],SUM_NUM);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
avr[n]=area[n]/SUM_NUM;//ƽ<><C6BD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
k[n]=avr[n]-avr[n-1];//ƽ<><C6BD>ֵ<EFBFBD><D6B5>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
}
|
|
|
|
|
return find_num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int find_top_pos_ex(int *buf,int len,GRADIENT_TYPE_DEF *para_ptr,int *str,int *peak,int tot_width,int per_width,int mov_width)
|
|
|
|
|
{
|
|
|
|
|
int i,n;
|
|
|
|
|
int area[MAX_JUDGE_NUM];
|
|
|
|
|
int k[MAX_JUDGE_NUM];
|
|
|
|
|
int avr[MAX_JUDGE_NUM];
|
|
|
|
|
int find_pos[MAX_JUDGE_NUM];
|
|
|
|
|
//int find_val[JUDGE_NUM];
|
|
|
|
|
int str_pos=0;
|
|
|
|
|
int peak_pos=0;
|
|
|
|
|
int left_flg,right_flg;
|
|
|
|
|
int tmp;
|
|
|
|
|
int find_num=0;
|
|
|
|
|
int pre_k=0,curr_k=0;
|
|
|
|
|
|
|
|
|
|
int tot_judge_num;
|
|
|
|
|
|
|
|
|
|
tot_judge_num=(tot_width-((per_width+1)/2))/mov_width;
|
|
|
|
|
if(tot_judge_num<MIN_JUDGE_NUM)
|
|
|
|
|
{
|
|
|
|
|
//per_width<74><68>mov_width<74><68><EFBFBD><EFBFBD><EFBFBD>ټ<EFBFBD><D9BC><EFBFBD>tot_judge_num<75><6D>
|
|
|
|
|
tot_judge_num=MIN_JUDGE_NUM;
|
|
|
|
|
}
|
|
|
|
|
if(tot_judge_num>MAX_JUDGE_NUM)
|
|
|
|
|
{
|
|
|
|
|
tot_judge_num=MAX_JUDGE_NUM;
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>JUDGE_NUM<55><4D><EFBFBD><EFBFBD>,ÿ<><C3BF><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>SUM_NUM<55><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>
|
|
|
|
|
for(n=0;n<tot_judge_num;n++)
|
|
|
|
|
{
|
|
|
|
|
area[n]=cal_int_sum(&buf[n*mov_width],per_width);
|
|
|
|
|
avr[n]=area[n]/per_width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmp=avr[0];
|
|
|
|
|
for(n=0;n<tot_judge_num;n++)
|
|
|
|
|
{
|
|
|
|
|
k[n]=avr[n]-tmp;
|
|
|
|
|
tmp=avr[n];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>JUDGE_NUM*MOVE_NUM<55><4D>ʼ<EFBFBD><CABC>
|
|
|
|
|
for(i=(tot_judge_num*mov_width);i<len;i+=mov_width)
|
|
|
|
|
{
|
|
|
|
|
if((k[tot_judge_num/2]<=0)&&(k[tot_judge_num/2+1]<=0))
|
|
|
|
|
{ //<2F>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>ݶ<EFBFBD>С<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
right_flg=2;//<2F>Ұ<EFBFBD><D2B0><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
for(n=((tot_judge_num/2)+2);n<tot_judge_num;n++)
|
|
|
|
|
{
|
|
|
|
|
if(k[n]<=0)//<2F>ϸ<EFBFBD><CFB8><EFBFBD>˵Ҫk[n]<0
|
|
|
|
|
right_flg++; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>ݶ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(right_flg>=(tot_judge_num/2))
|
|
|
|
|
{ //<2F>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>ݶ<EFBFBD>ȫ<EFBFBD><C8AB>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>
|
|
|
|
|
left_flg=0;
|
|
|
|
|
for(n=0;n<(tot_judge_num/2);n++)
|
|
|
|
|
{
|
|
|
|
|
if(k[n]>0)
|
|
|
|
|
left_flg++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(left_flg>=(tot_judge_num/2))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
find_pos[find_num]=i-((tot_judge_num+1)*mov_width/2);
|
|
|
|
|
curr_k=0;
|
|
|
|
|
for(tmp=0;tmp<(tot_judge_num/2);tmp++)
|
|
|
|
|
{
|
|
|
|
|
curr_k+=k[tmp];//<2F><><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>k
|
|
|
|
|
//printf("k%d=%d ",tmp,k[tmp]);
|
|
|
|
|
}
|
|
|
|
|
//printf("\n");
|
|
|
|
|
find_num++;
|
|
|
|
|
if(curr_k>pre_k)//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if(peak!=NULL)
|
|
|
|
|
{
|
|
|
|
|
*peak=i-((tot_judge_num+1)*mov_width/2);
|
|
|
|
|
}
|
|
|
|
|
pre_k=curr_k;
|
|
|
|
|
}
|
|
|
|
|
if(find_num>=tot_judge_num)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
for(n=0;n<(tot_judge_num-1);n++)
|
|
|
|
|
{
|
|
|
|
|
area[n]=area[n+1];
|
|
|
|
|
k[n]=k[n+1];
|
|
|
|
|
avr[n]=avr[n+1];
|
|
|
|
|
}
|
|
|
|
|
area[n]=cal_int_sum(&buf[i],per_width);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
avr[n]=area[n]/per_width;//ƽ<><C6BD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
k[n]=avr[n]-avr[n-1];//ƽ<><C6BD>ֵ<EFBFBD><D6B5>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
}
|
|
|
|
|
return find_num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
int find_key_pos_ex(int *buf,int len,YSP_PARA *para_ptr,FIND_POS_DATA *pos_data)
|
|
|
|
|
{
|
|
|
|
|
int i,n,*data_stream;
|
|
|
|
|
int start_pos,end_pos;
|
|
|
|
|
int left_pos,top_pos,right_pos;
|
|
|
|
|
int ret=0;
|
|
|
|
|
int top_val,left_val;
|
|
|
|
|
|
|
|
|
|
for(i=INDEX_H2;i<=INDEX_C2H2;i++)
|
|
|
|
|
{
|
|
|
|
|
//1.<2E><><EFBFBD>Ҷ<EFBFBD><D2B6><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD>㶥<EFBFBD><E3B6A5><EFBFBD><EFBFBD>ʼλ<CABC><CEBB>
|
|
|
|
|
start_pos=para_ptr->gas_cal_fac[i].position.start;
|
|
|
|
|
//<2F><><EFBFBD>㶥<EFBFBD><E3B6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
end_pos=para_ptr->gas_cal_fac[i].position.end;
|
|
|
|
|
|
|
|
|
|
while(start_pos<end_pos)
|
|
|
|
|
{
|
|
|
|
|
if(cal_int_sum(&buf[start_pos],SUM_NUM)>cal_int_sum(&buf[start_pos+SUM_NUM],SUM_NUM))
|
|
|
|
|
{
|
|
|
|
|
start_pos+=4;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
data_stream=buf+start_pos;//
|
|
|
|
|
top_pos=find_max_val(data_stream,end_pos-start_pos,NULL);//<2F><><EFBFBD>Ҷ<EFBFBD><D2B6><EFBFBD>
|
|
|
|
|
top_val=data_stream[top_pos];
|
|
|
|
|
if(top_pos!=0)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
top_pos+=start_pos;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//δȷ<CEB4><C8B7><EFBFBD>Ƿ<EFBFBD><C7B7>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
top_pos+=start_pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
start_pos=para_ptr->gas_cal_fac[i].position.start;//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>±<EFBFBD>
|
|
|
|
|
data_stream=buf+start_pos;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD>Ƶ<EFBFBD>ַ
|
|
|
|
|
end_pos=top_pos-(para_ptr->gas_cal_fac[i].position.width);//<2F><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
left_pos=find_left_pos(data_stream,end_pos-start_pos,SUM_NUM,(int)para_ptr->gas_cal_fac[i].gradient.lYmin);
|
|
|
|
|
//left_pos=find_left_pos_ex(data_stream,end_pos-start_pos,SUM_NUM,(int)para_ptr->gas_cal_fac[i].gradient.lYmin);
|
|
|
|
|
left_val=data_stream[left_pos];
|
|
|
|
|
left_pos+=start_pos;
|
|
|
|
|
|
|
|
|
|
if(top_val<=left_val)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ANALYSIS_EEROR_DEBUG,"error:left_val=%d top_val=%d index=%d\n",left_val,top_val,i);
|
|
|
|
|
}
|
|
|
|
|
pos_data->position[i].start=left_pos;
|
|
|
|
|
pos_data->position[i].peak=top_pos;
|
|
|
|
|
ret|=(1<<i);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int send_analysis_req(char *file_name,int len)
|
|
|
|
|
{
|
|
|
|
|
static mqd_t analysis_req_mq=(mqd_t)-1;
|
|
|
|
|
if(analysis_req_mq==(mqd_t)-1)
|
|
|
|
|
{
|
|
|
|
|
if((analysis_req_mq= open_mq(ANALYSIS_MQ))==((mqd_t)-1))
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ANALYSIS_EEROR_DEBUG,"open analysis mq failed\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(mq_send(analysis_req_mq,(const char *)file_name,len,ANALYSIS_MQ_PRIO)==-1)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ANALYSIS_EEROR_DEBUG,"send msg to analysis mq failed\n");
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>б<EFBFBD><D0B1>
|
|
|
|
|
void cal_slope(int *raw_data,int *out_data,unsigned int len,int num)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
int curr_val,pre_val;
|
|
|
|
|
curr_val=cal_int_avr(raw_data,num);
|
|
|
|
|
pre_val=curr_val;
|
|
|
|
|
for(i=0;i<(len/num);i++)
|
|
|
|
|
{
|
|
|
|
|
//out_data[i]=raw_data[i]-raw_data[i-1];
|
|
|
|
|
out_data[i]=curr_val-pre_val;
|
|
|
|
|
pre_val=curr_val;
|
|
|
|
|
curr_val=cal_int_avr(raw_data+i*num,num);
|
|
|
|
|
}
|
|
|
|
|
//out_data[0]=out_data[1];//<2F><>һ<EFBFBD><D2BB>б<EFBFBD><D0B1>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//ȥ<><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊԭʼ<D4AD><CABC><EFBFBD><EFBFBD>
|
|
|
|
|
void smooth_data(int *data,unsigned int len,unsigned int smooth_num)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
if(smooth_num==1)
|
|
|
|
|
{
|
|
|
|
|
for(i=1;i<len-1;i++)
|
|
|
|
|
{
|
|
|
|
|
if(data[i]<data[i-1]&&data[i]<data[i+1])
|
|
|
|
|
{
|
|
|
|
|
data[i]=(data[i-1]+data[i+1])/2;
|
|
|
|
|
}
|
|
|
|
|
else if(data[i]>data[i-1]&&data[i]>data[i+1])
|
|
|
|
|
{
|
|
|
|
|
data[i]=(data[i-1]+data[i+1])/2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void avr_filter(int *data,unsigned int len,unsigned int smooth_num,int *out)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i,n;
|
|
|
|
|
int num;
|
|
|
|
|
num=smooth_num/2;
|
|
|
|
|
for(i=0;i<(len-smooth_num);i++)
|
|
|
|
|
{
|
|
|
|
|
out[i+num]=cal_int_avr(&data[i],smooth_num);
|
|
|
|
|
}
|
|
|
|
|
for(n=0;n<num;n++)
|
|
|
|
|
{
|
|
|
|
|
out[n]=out[num];
|
|
|
|
|
out[len-num-1+n]=out[len-num-1];
|
|
|
|
|
}
|
|
|
|
|
out[len-1]=out[len-2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FACTOR_TYPE *find_right_fac(float *raw_data,GAS_CAL_PARA *gas_cal_fac,int *index_out)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
float min,max;
|
|
|
|
|
if(raw_data==NULL||gas_cal_fac==NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
for(i=0;i<12;i++)
|
|
|
|
|
{
|
|
|
|
|
min=gas_cal_fac->correct_fac.k[i].fac[3];//<2F><>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
max=gas_cal_fac->correct_fac.k[i].fac[4];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(((*raw_data)<=max)&&((*raw_data)>min))
|
|
|
|
|
{
|
|
|
|
|
if(index_out!=NULL)
|
|
|
|
|
{
|
|
|
|
|
*index_out=i;
|
|
|
|
|
}
|
|
|
|
|
return &(gas_cal_fac->correct_fac.k[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
int cal_h(int *raw_data,int str_pos,int peak_pos,float *out_data,int *base_data)
|
|
|
|
|
{
|
|
|
|
|
int h,base_val;
|
|
|
|
|
if(raw_data==NULL||out_data==NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if(base_data!=NULL)
|
|
|
|
|
{
|
|
|
|
|
base_val=(*base_data);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
base_val=raw_data[str_pos-1];
|
|
|
|
|
}
|
|
|
|
|
h=raw_data[peak_pos]-base_val;
|
|
|
|
|
if(h<0)
|
|
|
|
|
h=0;
|
|
|
|
|
//printf("max=%d base=%d h=%d peak_pos=%d\n",raw_data[peak_pos],base_val,h,peak_pos);
|
|
|
|
|
//out=h*tr
|
|
|
|
|
//*out_data=((float)h*(peak_pos-str_pos+1)*(my_para_data.mach_run_para.sample_rate))/1000;
|
|
|
|
|
*out_data=(float)h;//((float)h*(peak_pos)*(my_para_data.mach_run_para.sample_rate))/100000;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int correct_h(float *raw_h,float *out_h,GAS_CAL_PARA *gas_cal_fac)
|
|
|
|
|
{
|
|
|
|
|
float h=0;
|
|
|
|
|
int k_index=0;
|
|
|
|
|
FACTOR_TYPE *fac_ptr;
|
|
|
|
|
|
|
|
|
|
if(gas_cal_fac==NULL||raw_h==NULL||out_h==NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>raw_h<5F><68><EFBFBD>Ҵ<EFBFBD><D2B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Kֵ,Ȼ<><C8BB>ʹ<EFBFBD>ø<EFBFBD>Kֵ<4B><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if((fac_ptr=find_right_fac(raw_h,gas_cal_fac,&k_index))!=NULL)
|
|
|
|
|
{
|
|
|
|
|
//fac[0]=Kx
|
|
|
|
|
//fac[1]=<3D><>Ũ<EFBFBD><C5A8>ֵ
|
|
|
|
|
//fac[3]=<3D><>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
h=(fac_ptr->fac[0])*((*raw_h)-(fac_ptr->fac[3]))+(fac_ptr->fac[1]);
|
|
|
|
|
if(out_h!=NULL)
|
|
|
|
|
{
|
|
|
|
|
*out_h=h;
|
|
|
|
|
}
|
|
|
|
|
return k_index;
|
|
|
|
|
}
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int cal_area(int *raw_data,int str_pos,int peak_pos,float *out_area)
|
|
|
|
|
{
|
|
|
|
|
float area=0;
|
|
|
|
|
int tmp=0;
|
|
|
|
|
int i;
|
|
|
|
|
int base_data;
|
|
|
|
|
if(raw_data==NULL||out_area==NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
base_data=raw_data[str_pos];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
for(i=str_pos;i<peak_pos;i++)
|
|
|
|
|
{
|
|
|
|
|
tmp+=(raw_data[i]-base_data);//<2F>ۼ<EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
area=((float)tmp*((float)(my_para_data.mach_run_para.sample_rate)*0.001));
|
|
|
|
|
*out_area=area*2;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int correct_area(float *raw_area,float *out_area,GAS_CAL_PARA *gas_cal_fac)
|
|
|
|
|
{
|
|
|
|
|
float area=0;
|
|
|
|
|
int k_index=0;
|
|
|
|
|
FACTOR_TYPE *fac_ptr;
|
|
|
|
|
|
|
|
|
|
if(gas_cal_fac==NULL||raw_area==NULL||out_area==NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>raw_area<65><61><EFBFBD>Ҵ<EFBFBD><D2B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Kֵ,Ȼ<><C8BB>ʹ<EFBFBD>ø<EFBFBD>Kֵ<4B><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if((fac_ptr=find_right_fac(raw_area,gas_cal_fac,&k_index))!=NULL)
|
|
|
|
|
{
|
|
|
|
|
//fac[0]=Kx
|
|
|
|
|
//fac[1]=<3D><>Ũ<EFBFBD><C5A8>ֵ
|
|
|
|
|
//fac[3]=<3D><>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
area=(fac_ptr->fac[0])*((*raw_area)-(fac_ptr->fac[3]))+(fac_ptr->fac[1]);
|
|
|
|
|
if(out_area!=NULL)
|
|
|
|
|
{
|
|
|
|
|
*out_area=area;
|
|
|
|
|
}
|
|
|
|
|
return k_index;
|
|
|
|
|
}
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int save_dumy_file(const char *file,long offs,int *ptr,unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
fp=fopen(file,"w");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"Creat file %s failed when savefile\r\n",file);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if(offs!=0)
|
|
|
|
|
{
|
|
|
|
|
fseek(fp,offs,SEEK_SET);
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
|
{
|
|
|
|
|
fprintf(fp,"%d\n",*ptr++);
|
|
|
|
|
}
|
|
|
|
|
fprintf(fp,"\n");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,len<65><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>,
|
|
|
|
|
int analysis_data(int *raw_data,int len,YSP_PARA *para_ptr,ANALY_RESULT *ana_rlt)
|
|
|
|
|
{
|
|
|
|
|
int str_pos[10]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int peak_pos[10]; //<2F><><EFBFBD>嶥<EFBFBD><E5B6A5>
|
|
|
|
|
int find_mask;
|
|
|
|
|
int base_val;
|
|
|
|
|
int ret=0;
|
|
|
|
|
int i,n;
|
|
|
|
|
int k_index;
|
|
|
|
|
int segment_len;
|
|
|
|
|
float tmp;
|
|
|
|
|
int ref_val;
|
|
|
|
|
FIND_POS_DATA position_data;
|
|
|
|
|
FIND_POS_DATA *pos_data=&position_data;
|
|
|
|
|
if(len>MAX_DATA_LEN)
|
|
|
|
|
len=MAX_DATA_LEN;
|
|
|
|
|
smooth_data(raw_data,len,1); //<2F>˲<EFBFBD>ȥ<EFBFBD><C8A5>
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
avr_filter(raw_data,len,SUM_NUM,filter_data);
|
|
|
|
|
|
|
|
|
|
ref_val=cal_int_avr(&filter_data[para_ptr->gas_cal_fac[INDEX_CH4].position.end],16);
|
|
|
|
|
for(i=para_ptr->gas_cal_fac[INDEX_CH4].position.end;i<para_ptr->gas_cal_fac[INDEX_C2H4].position.start;i++)
|
|
|
|
|
{
|
|
|
|
|
filter_data[i]=ref_val;
|
|
|
|
|
}
|
|
|
|
|
for(i=INDEX_C2H4;i<=INDEX_C2H2;i++)
|
|
|
|
|
{
|
|
|
|
|
printf("ref_val=%d start=%d start1=%d\n",ref_val,filter_data[para_ptr->gas_cal_fac[i].position.start],filter_data[para_ptr->gas_cal_fac[i].position.start-1]);
|
|
|
|
|
process_data(&filter_data[para_ptr->gas_cal_fac[i].position.start],(para_ptr->gas_cal_fac[i].position.end)-(para_ptr->gas_cal_fac[i].position.start)+1,&ref_val);
|
|
|
|
|
if(i!=INDEX_C2H2)
|
|
|
|
|
{
|
|
|
|
|
for(n=para_ptr->gas_cal_fac[i].position.end;n<para_ptr->gas_cal_fac[i+1].position.start;n++)
|
|
|
|
|
{
|
|
|
|
|
filter_data[n]=filter_data[n-1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(n=para_ptr->gas_cal_fac[i].position.end;n<len;n++)
|
|
|
|
|
{
|
|
|
|
|
filter_data[n]=filter_data[n-1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//ref_val=filter_data[para_ptr->gas_cal_fac[i].position.end-1];
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//ref_val=cal_int_avr(&raw_data[para_ptr->gas_cal_fac[INDEX_CH4].position.end],16);
|
|
|
|
|
//ref_val=&raw_data[para_ptr->gas_cal_fac[INDEX_C2H4].position.start];
|
|
|
|
|
//for(i=para_ptr->gas_cal_fac[INDEX_CH4].position.end;i<para_ptr->gas_cal_fac[INDEX_C2H4].position.start;i++)
|
|
|
|
|
//{
|
|
|
|
|
// raw_data[i]=ref_val;
|
|
|
|
|
// }
|
|
|
|
|
ref_val=raw_data[para_ptr->gas_cal_fac[INDEX_C2H4].position.start];
|
|
|
|
|
for(i=INDEX_C2H4;i<=INDEX_C2H2;i++)
|
|
|
|
|
{
|
|
|
|
|
segment_len=(para_ptr->gas_cal_fac[i].position.end)-(para_ptr->gas_cal_fac[i].position.start)+1;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>(<28><><EFBFBD><EFBFBD>ֵ-ref_val)
|
|
|
|
|
process_data(&raw_data[para_ptr->gas_cal_fac[i].position.start],segment_len,&ref_val);
|
|
|
|
|
//ref_val<61>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
if(i!=INDEX_C2H2)
|
|
|
|
|
{
|
|
|
|
|
for(n=para_ptr->gas_cal_fac[i].position.end;n<para_ptr->gas_cal_fac[i+1].position.start;n++)
|
|
|
|
|
{
|
|
|
|
|
raw_data[n]=raw_data[n-1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{//<2F><>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for(n=para_ptr->gas_cal_fac[i].position.end;n<len;n++)
|
|
|
|
|
{
|
|
|
|
|
raw_data[n]=raw_data[n-1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
avr_filter(raw_data,len,SUM_NUM,filter_data);
|
|
|
|
|
//save_dumy_file("filter.csv",0,filter_data,len);
|
|
|
|
|
memcpy(raw_data,filter_data,len*sizeof(int));
|
|
|
|
|
reduce_data(raw_data,len,filter_data,REDUCE_BIT);//<2F><>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
//save_dumy_file("reduce.csv",0,filter_data,len);
|
|
|
|
|
|
|
|
|
|
//cal_slope(filter_data,slope_data,len,SUM_NUM);//<2F><><EFBFBD><EFBFBD>б<EFBFBD><D0B1>
|
|
|
|
|
//save_dumy_file("slope.csv",0,slope_data,len/SUM_NUM);
|
|
|
|
|
//<2F>ҵ<EFBFBD>
|
|
|
|
|
//find_mask=find_key_pos(filter_data,len,para_ptr,pos_data);
|
|
|
|
|
find_mask=find_key_pos1(filter_data,len,para_ptr,pos_data);
|
|
|
|
|
ana_rlt->find_mask=find_mask;
|
|
|
|
|
for(i=INDEX_H2;i<=INDEX_C2H2;i++)
|
|
|
|
|
{
|
|
|
|
|
str_pos[i]=pos_data->position[i].start;
|
|
|
|
|
peak_pos[i]=pos_data->position[i].peak;
|
|
|
|
|
ana_rlt->pos_info[i].start=str_pos[i];
|
|
|
|
|
ana_rlt->pos_info[i].peak=peak_pos[i];
|
|
|
|
|
}
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"find_mask=%d,now start cal ysp data\n",find_mask);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
if((find_mask&(1<<INDEX_H2))!=0)
|
|
|
|
|
{
|
|
|
|
|
cal_h(raw_data,str_pos[INDEX_H2],peak_pos[INDEX_H2],&tmp,NULL);
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"H2_start=%d H2_peak=%d H2_amp=%f\n",str_pos[INDEX_H2],peak_pos[INDEX_H2],tmp);
|
|
|
|
|
ana_rlt->area[INDEX_H2]=tmp;
|
|
|
|
|
k_index=correct_h(&tmp,&ana_rlt->result.H2ppm,¶_ptr->gas_cal_fac[INDEX_H2]);
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"H2_corect=%f k_index=%d kx=%f min_area=%f min_ppm=%f\n",ana_rlt->result.H2ppm,k_index,para_ptr->gas_cal_fac[INDEX_H2].correct_fac.k[k_index].fac[0],para_ptr->gas_cal_fac[INDEX_H2].correct_fac.k[k_index].fac[3],para_ptr->gas_cal_fac[INDEX_H2].correct_fac.k[k_index].fac[1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//cal_h(raw_data,str_pos[INDEX_H2],peak_pos[INDEX_H2],&tmp,NULL);
|
|
|
|
|
tmp=0;
|
|
|
|
|
ana_rlt->area[INDEX_H2]=tmp;
|
|
|
|
|
ana_rlt->result.H2ppm=0;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"H2_start=%d H2_peak=%d H2_amp=%f\n",str_pos[INDEX_H2],peak_pos[INDEX_H2],tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>̼ʹ<CCBC><CAB9>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if((find_mask&(1<<INDEX_CO))!=0)
|
|
|
|
|
{
|
|
|
|
|
base_val=raw_data[str_pos[INDEX_H2]-1];
|
|
|
|
|
cal_h(raw_data,str_pos[INDEX_CO],peak_pos[INDEX_CO],&tmp,&base_val);
|
|
|
|
|
ana_rlt->area[INDEX_CO]=tmp;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"CO_start=%d CO_peak=%d CO_amp=%f\n",str_pos[INDEX_CO],peak_pos[INDEX_CO],tmp);
|
|
|
|
|
k_index=correct_h(&tmp,&ana_rlt->result.COppm,¶_ptr->gas_cal_fac[INDEX_CO]);
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"CO_corect=%f k_index=%d kx=%f min_area=%f min_ppm=%f\n",ana_rlt->result.COppm,k_index,para_ptr->gas_cal_fac[INDEX_CO].correct_fac.k[k_index].fac[0],para_ptr->gas_cal_fac[INDEX_CO].correct_fac.k[k_index].fac[3],para_ptr->gas_cal_fac[INDEX_CO].correct_fac.k[k_index].fac[1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
tmp=0;
|
|
|
|
|
ana_rlt->area[INDEX_CO]=tmp;
|
|
|
|
|
ana_rlt->result.COppm=0;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"CO_start=%d CO_peak=%d CO_amp=%f\n",str_pos[INDEX_CO],peak_pos[INDEX_CO],tmp);
|
|
|
|
|
*/
|
|
|
|
|
base_val=raw_data[str_pos[INDEX_H2]-1];
|
|
|
|
|
cal_h(raw_data,para_ptr->gas_cal_fac[INDEX_CO].position.start,para_ptr->gas_cal_fac[INDEX_CO].position.peak,&tmp,&base_val);
|
|
|
|
|
ana_rlt->area[INDEX_CO]=tmp;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"use dfault postion para:CO_start=%d CO_peak=%d CO_amp=%f\n",para_ptr->gas_cal_fac[INDEX_CO].position.start,para_ptr->gas_cal_fac[INDEX_CO].position.peak,tmp);
|
|
|
|
|
k_index=correct_h(&tmp,&ana_rlt->result.COppm,¶_ptr->gas_cal_fac[INDEX_CO]);
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"CO_corect=%f k_index=%d kx=%f min_area=%f min_ppm=%f\n",ana_rlt->result.COppm,k_index,para_ptr->gas_cal_fac[INDEX_CO].correct_fac.k[k_index].fac[0],para_ptr->gas_cal_fac[INDEX_CO].correct_fac.k[k_index].fac[3],para_ptr->gas_cal_fac[INDEX_CO].correct_fac.k[k_index].fac[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((find_mask&(1<<INDEX_CH4))!=0)
|
|
|
|
|
{
|
|
|
|
|
//base_val=raw_data[str_pos[INDEX_H2]-1];
|
|
|
|
|
base_val=raw_data[str_pos[INDEX_CH4]-1];
|
|
|
|
|
cal_h(raw_data,str_pos[INDEX_CH4],peak_pos[INDEX_CH4],&tmp,&base_val);
|
|
|
|
|
ana_rlt->area[INDEX_CH4]=tmp;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"CH4_start=%d CH4_peak=%d CH4_amp=%f\n",str_pos[INDEX_CH4],peak_pos[INDEX_CH4],tmp);
|
|
|
|
|
k_index=correct_h(&tmp,&ana_rlt->result.CH4ppm,¶_ptr->gas_cal_fac[INDEX_CH4]);
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"CH4_corect=%f k_index=%d kx=%f min_area=%f min_ppm=%f\n",ana_rlt->result.CH4ppm,k_index,para_ptr->gas_cal_fac[INDEX_CO].correct_fac.k[k_index].fac[0],para_ptr->gas_cal_fac[INDEX_CO].correct_fac.k[k_index].fac[3],para_ptr->gas_cal_fac[INDEX_CO].correct_fac.k[k_index].fac[1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tmp=0;
|
|
|
|
|
ana_rlt->area[INDEX_CH4]=tmp;
|
|
|
|
|
ana_rlt->result.CH4ppm=0;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"CH4_start=%d CH4_peak=%d CH4_amp=%f\n",str_pos[INDEX_CH4],peak_pos[INDEX_CH4],tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((find_mask&(1<<INDEX_C2H4))!=0)
|
|
|
|
|
{
|
|
|
|
|
cal_area(raw_data,str_pos[INDEX_C2H4],peak_pos[INDEX_C2H4],&tmp);
|
|
|
|
|
ana_rlt->area[INDEX_C2H4]=tmp;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"C2H4_start=%d C2H4_peak=%d C2H4_amp=%f\n",str_pos[INDEX_C2H4],peak_pos[INDEX_C2H4],tmp);
|
|
|
|
|
k_index=correct_area(&tmp,&ana_rlt->result.C2H4ppm,¶_ptr->gas_cal_fac[INDEX_C2H4]);
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"C2H4_corect=%f k_index=%d kx=%f min_area=%f min_ppm=%f\n",ana_rlt->result.C2H4ppm,k_index,para_ptr->gas_cal_fac[INDEX_C2H4].correct_fac.k[k_index].fac[0],para_ptr->gas_cal_fac[INDEX_C2H4].correct_fac.k[k_index].fac[3],para_ptr->gas_cal_fac[INDEX_C2H4].correct_fac.k[k_index].fac[1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tmp=0;
|
|
|
|
|
ana_rlt->area[INDEX_C2H4]=tmp;
|
|
|
|
|
ana_rlt->result.C2H4ppm=0;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"C2H4_start=%d C2H4_peak=%d C2H4_amp=%f\n",str_pos[INDEX_C2H4],peak_pos[INDEX_C2H4],tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((find_mask&(1<<INDEX_C2H6))!=0)
|
|
|
|
|
{
|
|
|
|
|
cal_area(raw_data,str_pos[INDEX_C2H6],peak_pos[INDEX_C2H6],&tmp);
|
|
|
|
|
ana_rlt->area[INDEX_C2H6]=tmp;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"C2H6_start=%d C2H6_peak=%d C2H6_amp=%f\n",str_pos[INDEX_C2H6],peak_pos[INDEX_C2H6],tmp);
|
|
|
|
|
k_index=correct_area(&tmp,&ana_rlt->result.C2H6ppm,¶_ptr->gas_cal_fac[INDEX_C2H6]);
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"C2H6_corect=%f k_index=%d kx=%f min_area=%f min_ppm=%f\n",ana_rlt->result.C2H6ppm,k_index,para_ptr->gas_cal_fac[INDEX_C2H6].correct_fac.k[k_index].fac[0],para_ptr->gas_cal_fac[INDEX_C2H6].correct_fac.k[k_index].fac[3],para_ptr->gas_cal_fac[INDEX_C2H6].correct_fac.k[k_index].fac[1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tmp=0;
|
|
|
|
|
ana_rlt->area[INDEX_C2H6]=tmp;
|
|
|
|
|
ana_rlt->result.C2H6ppm=0;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"C2H6_start=%d C2H6_peak=%d C2H6_amp=%f\n",str_pos[INDEX_C2H6],peak_pos[INDEX_C2H6],tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>tmp
|
|
|
|
|
if((find_mask&(1<<INDEX_C2H2))!=0)
|
|
|
|
|
{
|
|
|
|
|
cal_area(raw_data,str_pos[INDEX_C2H2],peak_pos[INDEX_C2H2],&tmp);
|
|
|
|
|
ana_rlt->area[INDEX_C2H2]=tmp;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"C2H2_start=%d C2H2_peak=%d C2H2_amp=%f\n",str_pos[INDEX_C2H2],peak_pos[INDEX_C2H2],tmp);
|
|
|
|
|
//<2F><>tmp<6D><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>&out_data->C2H2ppm
|
|
|
|
|
k_index=correct_area(&tmp,&ana_rlt->result.C2H2ppm,¶_ptr->gas_cal_fac[INDEX_C2H2]);
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"C2H2_corect=%f k_index=%d kx=%f min_area=%f min_ppm=%f\n",ana_rlt->result.C2H2ppm,k_index,para_ptr->gas_cal_fac[INDEX_C2H2].correct_fac.k[k_index].fac[0],para_ptr->gas_cal_fac[INDEX_C2H2].correct_fac.k[k_index].fac[3],para_ptr->gas_cal_fac[INDEX_C2H2].correct_fac.k[k_index].fac[1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tmp=0;
|
|
|
|
|
ana_rlt->area[INDEX_C2H2]=tmp;
|
|
|
|
|
ana_rlt->result.C2H2ppm=0;
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"C2H2_start=%d C2H2_peak=%d C2H2_amp=%f\n",str_pos[INDEX_C2H2],peak_pos[INDEX_C2H2],tmp);
|
|
|
|
|
}
|
|
|
|
|
ana_rlt->result.TotHyd=(ana_rlt->result.CH4ppm)+(ana_rlt->result.C2H4ppm)+(ana_rlt->result.C2H6ppm)+(ana_rlt->result.C2H2ppm);
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"h2=%fppm co=%fppm ch4=%fppm\n",ana_rlt->result.H2ppm,ana_rlt->result.COppm,ana_rlt->result.CH4ppm);
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"c2h4=%fppm c2h6=%fppm c2h2=%fppm\n",ana_rlt->result.C2H4ppm,ana_rlt->result.C2H6ppm,ana_rlt->result.C2H2ppm);
|
|
|
|
|
//if(co2_is_ok)
|
|
|
|
|
// {
|
|
|
|
|
ana_rlt->result.CO2ppm=last_co2_ppm;
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// ana_rlt->result.CO2ppm=0;
|
|
|
|
|
// }
|
|
|
|
|
ret=0;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
int analysis_co2(unsigned short *buf,unsigned int buf_len,float *result)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int max_pos=0;
|
|
|
|
|
int start_pos=0;
|
|
|
|
|
unsigned short max=0;
|
|
|
|
|
unsigned int sum=0;
|
|
|
|
|
int find_flg=0;
|
|
|
|
|
int large_cnt=0;
|
|
|
|
|
int less_cnt=0;
|
|
|
|
|
float ppm;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for(i=0;i<(buf_len-5);i++)
|
|
|
|
|
{
|
|
|
|
|
if(buf[i]<buf[i+1])
|
|
|
|
|
{
|
|
|
|
|
if(buf[i+1]<buf[i+2])
|
|
|
|
|
{
|
|
|
|
|
if(buf[i+2]<buf[i+3])
|
|
|
|
|
{
|
|
|
|
|
if(buf[i+3]<buf[i+4])
|
|
|
|
|
{
|
|
|
|
|
start_pos=i;
|
|
|
|
|
find_flg=1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(find_flg)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>
|
|
|
|
|
max=buf[start_pos];
|
|
|
|
|
for(i=(start_pos+1);i<buf_len;i++)
|
|
|
|
|
{
|
|
|
|
|
if(buf[i]>max)
|
|
|
|
|
{ //<2F><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>
|
|
|
|
|
max=buf[i];
|
|
|
|
|
max_pos=i;
|
|
|
|
|
large_cnt++;
|
|
|
|
|
less_cnt=0;
|
|
|
|
|
}
|
|
|
|
|
if(buf[i]<max)
|
|
|
|
|
{
|
|
|
|
|
less_cnt++;
|
|
|
|
|
if(less_cnt>=4)
|
|
|
|
|
{
|
|
|
|
|
if(large_cnt>=4)
|
|
|
|
|
{
|
|
|
|
|
find_flg=2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(find_flg==2)
|
|
|
|
|
{
|
|
|
|
|
sum=0;
|
|
|
|
|
for(i=start_pos;i<=max_pos;i++)
|
|
|
|
|
{
|
|
|
|
|
sum+=(buf[i]-buf[start_pos]);
|
|
|
|
|
}
|
|
|
|
|
ppm=(float)2*sum;
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"co2_start_pos=%d co2_peak_pos=%d co2_area=%f\n",start_pos,max_pos,ppm);
|
|
|
|
|
if(correct_area(&ppm,&ppm,&my_para_data.co2_cal_fac)==0)
|
|
|
|
|
{
|
|
|
|
|
if(result!=NULL)
|
|
|
|
|
*result=ppm;
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"co2_ppm=%f\n",ppm);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"can't find co2 cal fac\n");
|
|
|
|
|
if(result!=NULL)
|
|
|
|
|
*result=0;
|
|
|
|
|
return -3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"can't find co2 peak pos\n");
|
|
|
|
|
if(result!=NULL)
|
|
|
|
|
*result=0;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"can't find co2 start pos\n");
|
|
|
|
|
if(result!=NULL)
|
|
|
|
|
*result=0;
|
|
|
|
|
}
|
|
|
|
|
return -2;
|
|
|
|
|
}*/
|
|
|
|
|
int analysis_co2(unsigned short *buf,unsigned int buf_len,float *result)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int max_pos=0;
|
|
|
|
|
int start_pos=0;
|
|
|
|
|
unsigned short max=0;
|
|
|
|
|
unsigned int sum=0;
|
|
|
|
|
int find_flg=0;
|
|
|
|
|
int large_cnt=0;
|
|
|
|
|
int less_cnt=0;
|
|
|
|
|
float ppm;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for(i=0;i<(buf_len-5);i++)
|
|
|
|
|
{
|
|
|
|
|
if(buf[i]<buf[i+2])
|
|
|
|
|
{
|
|
|
|
|
if(buf[i+1]<buf[i+3])
|
|
|
|
|
{
|
|
|
|
|
if(buf[i+2]<buf[i+4])
|
|
|
|
|
{
|
|
|
|
|
if((buf[i+4]-buf[i+1])>(buf[i+2]-buf[i]))
|
|
|
|
|
{
|
|
|
|
|
start_pos=i;
|
|
|
|
|
find_flg=1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(find_flg)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>
|
|
|
|
|
max=buf[start_pos];
|
|
|
|
|
large_cnt=0;
|
|
|
|
|
for(i=(start_pos+1);i<buf_len;i++)
|
|
|
|
|
{
|
|
|
|
|
if(buf[i]>max)
|
|
|
|
|
{ //<2F><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>
|
|
|
|
|
max=buf[i];
|
|
|
|
|
max_pos=i;
|
|
|
|
|
large_cnt++;
|
|
|
|
|
less_cnt=0;
|
|
|
|
|
}
|
|
|
|
|
else if(buf[i]<=max)
|
|
|
|
|
{
|
|
|
|
|
less_cnt++;
|
|
|
|
|
if(less_cnt>=2)
|
|
|
|
|
{
|
|
|
|
|
if(large_cnt>=2)
|
|
|
|
|
{
|
|
|
|
|
find_flg=2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(find_flg==2)
|
|
|
|
|
{
|
|
|
|
|
sum=0;
|
|
|
|
|
for(i=start_pos;i<=max_pos;i++)
|
|
|
|
|
{
|
|
|
|
|
sum+=(buf[i]-buf[start_pos]);
|
|
|
|
|
}
|
|
|
|
|
ppm=(float)2*sum;
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"co2_start_pos=%d co2_peak_pos=%d co2_area=%f\n",start_pos,max_pos,ppm);
|
|
|
|
|
if(correct_area(&ppm,&ppm,&my_para_data.co2_cal_fac)==0)
|
|
|
|
|
{
|
|
|
|
|
if(result!=NULL)
|
|
|
|
|
*result=ppm;
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"co2_ppm=%f\n",ppm);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"can't find co2 cal fac\n");
|
|
|
|
|
if(result!=NULL)
|
|
|
|
|
*result=0;
|
|
|
|
|
return -3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"can't find co2 peak pos\n");
|
|
|
|
|
if(result!=NULL)
|
|
|
|
|
{
|
|
|
|
|
ppm=(float)buf[buf_len/2];
|
|
|
|
|
if(correct_area(&ppm,&ppm,&my_para_data.co2_cal_fac)==0)
|
|
|
|
|
{
|
|
|
|
|
*result=ppm;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*result=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"can't find co2 start pos\n");
|
|
|
|
|
if(result!=NULL)
|
|
|
|
|
{
|
|
|
|
|
ppm=(float)buf[buf_len/2];
|
|
|
|
|
if(correct_area(&ppm,&ppm,&my_para_data.co2_cal_fac)==0)
|
|
|
|
|
{
|
|
|
|
|
*result=ppm;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*result=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//<2F><>csv<73>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
|
|
int read_float_csv(const char *fname,float *buf,int len)
|
|
|
|
|
{
|
|
|
|
|
FILE *stream;
|
|
|
|
|
int i;
|
|
|
|
|
stream=fopen(fname,"r");
|
|
|
|
|
if(stream==NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
|
{
|
|
|
|
|
if(fscanf(stream,"%f",buf++)<=0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(stream);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int read_float_raw(const char *fname,float *buf,int len)
|
|
|
|
|
{
|
|
|
|
|
FILE *stream;
|
|
|
|
|
int i;
|
|
|
|
|
stream=fopen(fname,"r");
|
|
|
|
|
if(stream==NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
if((i=fread((void *)buf,sizeof(float),len,stream))!=len)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"read_float_raw failed when fread len=%d\n",len);
|
|
|
|
|
}
|
|
|
|
|
fclose(stream);
|
|
|
|
|
return i;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
//lenָ<6E><D6B8><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>,<2C><><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
|
|
|
|
int read_int_raw(const char *fname,int *buf,int len)
|
|
|
|
|
{
|
|
|
|
|
FILE *stream;
|
|
|
|
|
int i;
|
|
|
|
|
stream=fopen(fname,"r");
|
|
|
|
|
if(stream==NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
if((i=fread((void *)buf,sizeof(int),len,stream))!=len)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"read_float_raw failed when fread len=%d\n",len);
|
|
|
|
|
}
|
|
|
|
|
fclose(stream);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>,len<65><6E><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĵ<DDB5><C4B5><EFBFBD>
|
|
|
|
|
int analysis_file(char *file_name,int len,YSP_PARA *para_ptr,ANALY_RESULT *ana_rlt)
|
|
|
|
|
{
|
|
|
|
|
int act_len;//ʵ<>ʳ<EFBFBD><CAB3><EFBFBD>
|
|
|
|
|
int tmp_len;
|
|
|
|
|
if(len>0)
|
|
|
|
|
tmp_len=len;
|
|
|
|
|
else
|
|
|
|
|
tmp_len=para_ptr->mach_run_para.sample_len;
|
|
|
|
|
if((act_len=read_int_raw(file_name,raw_data_buf,tmp_len))<=0)//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"read_int_raw failed\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
ana_rlt->result.SmpTm=time(NULL);
|
|
|
|
|
//out_data->SmpTm=time(NULL);
|
|
|
|
|
return analysis_data(raw_data_buf,act_len,para_ptr,ana_rlt);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>k=0,<2C>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD>k>0,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ճһ<D5B3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>k<0,<2C>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD>k>0
|
|
|
|
|
//<2F>ۺ<EFBFBD><DBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>k<=0,<2C>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD>k>0,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊб<CEAA><D0B1>
|
|
|
|
|
int lfind_slope_trough(float *data,unsigned int len,unsigned int *pos,unsigned int pos_num)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
unsigned int find_pos;
|
|
|
|
|
unsigned int find_index=0;
|
|
|
|
|
for(i=0;i<(len-6);i++)
|
|
|
|
|
{
|
|
|
|
|
if(data[i]<=0&&data[i+1]<=0&&data[i+2]<=0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><=0
|
|
|
|
|
{
|
|
|
|
|
if(data[i+3]>0&&data[i+4]>0&&data[i+5]>=0)//<2F>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
|
|
|
|
{
|
|
|
|
|
find_pos=i+2;
|
|
|
|
|
pos[find_index++]=find_pos;
|
|
|
|
|
if(find_index>=pos_num)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return find_index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
|
|
|
|
|
int find_increase_start(float *data,int len,int judge_num,int *str_pos,int *endpos)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int meet_lcnt=0,meet_rcnt=0;
|
|
|
|
|
int start_pos=-1,end_pos=-1;
|
|
|
|
|
for(i=0;i<len-judge_num;i++)
|
|
|
|
|
{
|
|
|
|
|
if(data[i]>MIN_SLOPE)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
meet_rcnt=0;
|
|
|
|
|
meet_lcnt++;
|
|
|
|
|
if(meet_lcnt>=judge_num)
|
|
|
|
|
{
|
|
|
|
|
if((-1)==start_pos)
|
|
|
|
|
{
|
|
|
|
|
start_pos=i-judge_num;//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
*str_pos=start_pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
meet_lcnt=0;
|
|
|
|
|
if(data[i]<=0)//
|
|
|
|
|
meet_rcnt++;
|
|
|
|
|
if((-1)!=start_pos)
|
|
|
|
|
{
|
|
|
|
|
if(meet_rcnt>=judge_num)
|
|
|
|
|
{
|
|
|
|
|
if((-1)==end_pos)
|
|
|
|
|
{
|
|
|
|
|
end_pos=i-judge_num;//<2F><><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD>,<2C>ж<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
|
|
|
|
*endpos=end_pos;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD>ҹȵ<D2B9>,<2C>Ӷ<EFBFBD><D3B6>㿪ʼ<E3BFAA><CABC><EFBFBD><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,k<><6B><EFBFBD><EFBFBD>С<EFBFBD><D0A1>0,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;<3B><>ճ<EFBFBD><D5B3><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>k<EFBFBD><6B><EFBFBD><EFBFBD><0,<2C><>ͻȻ<CDBB><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>k<-MIN_SLOPE,<2C>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD>k>=0;
|
|
|
|
|
int find_decrease_start(float *data,int len,int judge_num,int *str_pos,int *endpos)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int meet_lcnt=0,meet_rcnt=0;
|
|
|
|
|
int start_pos=-1,end_pos=-1;
|
|
|
|
|
for(i=0;i<len-judge_num;i++)
|
|
|
|
|
{
|
|
|
|
|
if(data[i]<0)//б<>ʳ<EFBFBD><CAB3><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
meet_rcnt=0;
|
|
|
|
|
meet_lcnt++;
|
|
|
|
|
if(meet_lcnt>=judge_num)
|
|
|
|
|
{
|
|
|
|
|
if((-1)==start_pos)
|
|
|
|
|
{
|
|
|
|
|
start_pos=i-judge_num;//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
*str_pos=start_pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
meet_lcnt=0;
|
|
|
|
|
if(data[i]<=0)
|
|
|
|
|
meet_rcnt++;
|
|
|
|
|
if((-1)!=start_pos)
|
|
|
|
|
{
|
|
|
|
|
if(meet_rcnt>=judge_num)
|
|
|
|
|
{
|
|
|
|
|
if((-1)==end_pos)
|
|
|
|
|
{
|
|
|
|
|
end_pos=i-judge_num;//<2F>յ<EFBFBD>
|
|
|
|
|
*endpos=end_pos;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//<2F>жϲ<D0B6><CFB2><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>,ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>岨<EFBFBD><E5B2A8><EFBFBD>Ƿ<EFBFBD>ճ<EFBFBD><D5B3><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊб<CEAA><D0B1>
|
|
|
|
|
int data_distinguish_type(float *data,unsigned int len,unsigned int judge_num)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int last_slope=0,curr_slope=0;
|
|
|
|
|
for(i=0;i<len-4;i++)
|
|
|
|
|
{
|
|
|
|
|
if(data[i]>MIN_SLOPE&&data[i+1]>MIN_SLOPE)
|
|
|
|
|
{
|
|
|
|
|
if(data[i+2]>MIN_SLOPE&&data[i+3]>MIN_SLOPE)
|
|
|
|
|
{
|
|
|
|
|
curr_slope=1;
|
|
|
|
|
if(curr_slope!=last_slope)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߽<EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>>0,<2C>ұ<EFBFBD>С<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>0,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊб<CEAA><D0B1>
|
|
|
|
|
int find_peak_lboundary(float *data,unsigned int len,unsigned int *pos)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for(i=3;i<(len-1);i++)
|
|
|
|
|
{
|
|
|
|
|
if((data[i]<=0)&&data[i-1]>0&&data[i-2]>0&&data[i-3]>0)
|
|
|
|
|
{
|
|
|
|
|
if(data[i+1]<=0)
|
|
|
|
|
{
|
|
|
|
|
if(pos!=NULL)
|
|
|
|
|
*pos=i;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD>ұ߽<D2B1>
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>>=0,<2C>ұ<EFBFBD><0,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊб<CEAA><D0B1>
|
|
|
|
|
int find_peak_rboundary(float *data,unsigned int len,unsigned int *pos)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for(i=3;i<(len-1);i++)
|
|
|
|
|
{
|
|
|
|
|
if((data[i]<0)&&data[i-1]>=0&&data[i-2]>=0&&data[i-3]>=0)
|
|
|
|
|
{
|
|
|
|
|
if(data[i+1]<0)
|
|
|
|
|
{
|
|
|
|
|
if(pos!=NULL)
|
|
|
|
|
*pos=i;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>k<0,<2C>ұ<EFBFBD>k=0,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ճһ<D5B3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>k<0,<2C>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD>k>0
|
|
|
|
|
//<2F>ۺ<EFBFBD><DBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>k<0,<2C>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD>k>=0
|
|
|
|
|
int rfind_slope_trough(float *data,unsigned int len,unsigned int *pos,unsigned int pos_num,unsigned int *lpos)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
unsigned int find_pos;
|
|
|
|
|
unsigned int find_index=0;
|
|
|
|
|
for(i=0;i<(len-6);i++)
|
|
|
|
|
{
|
|
|
|
|
if(data[i]<0&&data[i+1]<0&&data[i+2]<0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><=0
|
|
|
|
|
{
|
|
|
|
|
if(data[i+3]>=0&&data[i+4]>=0&&data[i+5]>=0)//<2F>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
|
|
|
|
{
|
|
|
|
|
find_pos=i+2;
|
|
|
|
|
if(lpos!=NULL)
|
|
|
|
|
{
|
|
|
|
|
if(find_pos<=lpos[find_index])
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
pos[find_index++]=find_pos;
|
|
|
|
|
if(find_index>=pos_num)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return find_index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
int find_key_points(float *raw_data,unsigned int len,void *key_points)
|
|
|
|
|
{
|
|
|
|
|
unsigned int lrough_pos[6]; //<2F><EFBFBD>
|
|
|
|
|
unsigned int rrough_pos[6]; //<2F>Ҳ<EFBFBD><D2B2><EFBFBD>
|
|
|
|
|
unsigned int peak_pos[6]; //<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
smooth_data(raw_data,len,1); //<2F>˲<EFBFBD>ȥ<EFBFBD><C8A5>
|
|
|
|
|
cal_slope(raw_data,slope_data,len);//<2F><><EFBFBD><EFBFBD>б<EFBFBD><D0B1>
|
|
|
|
|
//lfind_slope_trough(slope_data,len,lrough_pos,6);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//rfind_slope_trough(slope_data,len,rrough_pos,6);//<2F><><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>λ<EFBFBD>ú<EFBFBD><C3BA>趨<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD>Ƚ<EFBFBD>,
|
|
|
|
|
//<2F>ڲ<EFBFBD><DAB2>ҵ<EFBFBD><D2B5><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>
|
|
|
|
|
return 0;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
int save_last_result(ANALY_RESULT *pri_data)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
if(pri_data==NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
fp=fopen("last.dat","w");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
return -2;
|
|
|
|
|
if(fwrite((const void *)pri_data,sizeof(ANALY_RESULT),1,fp)!=1)
|
|
|
|
|
{
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return -3;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int load_last_result(ANALY_RESULT *pri_data)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
if(pri_data==NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
fp=fopen("last.dat","r");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
return -2;
|
|
|
|
|
if(fread((void *)pri_data,sizeof(ANALY_RESULT),1,fp)!=1)
|
|
|
|
|
{
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return -3;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*<2A><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>*/
|
|
|
|
|
int save_analysis_file(char *file_name,int len,YSP_PARA *para_ptr,FIND_POS_DATA *pos_data,YSP_PRI_DATA *out_data)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
char *p;
|
|
|
|
|
char file[64];
|
|
|
|
|
|
|
|
|
|
if(file_name==NULL||para_ptr==NULL||pos_data==NULL||out_data==NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
sprintf(file,"%s",file_name);
|
|
|
|
|
i=strlen(file);
|
|
|
|
|
if(i<3)
|
|
|
|
|
return -2;
|
|
|
|
|
//<2F>滻β
|
|
|
|
|
sprintf(&file[i-3],"dat");
|
|
|
|
|
fp=fopen(file,"w");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"Creat file %s failed when save_analysis_file\n",file);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if(fwrite((const void *)para_ptr->mach_run_para.version,16,1,fp)!=1)
|
|
|
|
|
{//<2F>汾<EFBFBD><E6B1BE>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save version failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
if(fwrite((const void *)para_ptr->mach_run_para.station,64,1,fp)!=1)
|
|
|
|
|
{
|
|
|
|
|
//վ<><D5BE>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save station failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -3;
|
|
|
|
|
}
|
|
|
|
|
if(fwrite((const void *)para_ptr->mach_run_para.device,64,1,fp)!=1)
|
|
|
|
|
{
|
|
|
|
|
//<2F>豸<EFBFBD><E8B1B8>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save device failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -4;
|
|
|
|
|
}
|
|
|
|
|
if(fwrite((const void *)&last_sample_time,4,1,fp)!=1)
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save sample date failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -5;
|
|
|
|
|
}
|
|
|
|
|
if(fwrite((const void *)¶_ptr->mach_run_para.sample_len,4,1,fp)!=1)
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save sample_len failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -6;
|
|
|
|
|
}
|
|
|
|
|
if(fwrite((const void *)¶_ptr->mach_run_para.sample_rate,4,1,fp)!=1)
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save sample_rate failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -7;
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<6;i++)
|
|
|
|
|
{
|
|
|
|
|
if(fwrite((const void *)¶_ptr->gas_cal_fac[i],sizeof(GAS_CAL_PARA),1,fp)!=1)
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save cal fac failed when save_analysis_file %s\n",file);
|
|
|
|
|
return (-8-i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(fwrite((const void *)pos_data,sizeof(FIND_POS_DATA),1,fp)!=1)
|
|
|
|
|
{//<2F><><EFBFBD>ҵ<EFBFBD><D2B5>Ĺؼ<C4B9><D8BC><EFBFBD>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save pos data failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -14;
|
|
|
|
|
}
|
|
|
|
|
if(fwrite((const void *)out_data,sizeof(YSP_PRI_DATA),1,fp)!=1)
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save result data failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -14;
|
|
|
|
|
}
|
|
|
|
|
/* if(fwrite((const void *)out_data,sizeof(YSP_PRI_DATA),1,fp)!=1)
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save result data failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -14;
|
|
|
|
|
}*/
|
|
|
|
|
if(fseek(fp,RSV_SPACE_SIZE,SEEK_CUR)!=0)
|
|
|
|
|
{ //<2F><><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"fseek failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -15;
|
|
|
|
|
}
|
|
|
|
|
if(fwrite((const void *)raw_data_buf,(para_ptr->mach_run_para.sample_len)*4,1,fp)!=1)
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
fclose(fp);
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save sample data failed when save_analysis_file %s\n",file);
|
|
|
|
|
return -16;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>,<2C>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
|
|
|
|
void *analysis_routine(void *arg)
|
|
|
|
|
{
|
|
|
|
|
YSP_PRI_DATA ysp_pri_data;
|
|
|
|
|
FIND_POS_DATA ysp_ana_pos;
|
|
|
|
|
ANALY_RESULT latest_ana_rlt;
|
|
|
|
|
float delt;
|
|
|
|
|
int i;
|
|
|
|
|
if((analysis_mq=create_mq(ANALYSIS_MQ,ANALYSIS_MAX_MESSAGE,ANALYSIS_MESSAGE_SIZE))<0)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"create analysis message queue failed\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
if(load_last_result(&ana_result)==0)
|
|
|
|
|
{
|
|
|
|
|
send_ysp_msg(&ana_result.result);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"load last history data failed\n");
|
|
|
|
|
}
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
if(recv_mq_wait(analysis_mq,(void *)analysis_buf,sizeof(analysis_buf),60000000)>0)
|
|
|
|
|
{
|
|
|
|
|
if(analysis_file(analysis_buf,my_para_data.mach_run_para.sample_len,&my_para_data,&ana_result)==0)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"analysis %s sucessful\n",analysis_buf);
|
|
|
|
|
if((my_para_data.mach_run_para.run_mode)==0)
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3>²<EFBFBD><C2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ģʽ<C4A3>²<EFBFBD><C2B2><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(read_his_entry(&latest_ana_rlt)==0)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(ana_result.result.H2ppm<latest_ana_rlt.result.H2ppm)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴ<EFBFBD>С
|
|
|
|
|
delt=(latest_ana_rlt.result.H2ppm-ana_result.result.H2ppm)/latest_ana_rlt.result.H2ppm;
|
|
|
|
|
if(delt>0.2)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>-20%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastH2=%f currH2=%f delt=%f correc to %f\n",latest_ana_rlt.result.H2ppm,ana_result.result.H2ppm,delt,latest_ana_rlt.result.H2ppm*0.9);
|
|
|
|
|
ana_result.result.H2ppm=latest_ana_rlt.result.H2ppm*0.9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(latest_ana_rlt.result.H2ppm>=(1.0))//<2F>ϴβ<CFB4><CEB2><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>1ppm
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴδ<CFB4>
|
|
|
|
|
delt=(ana_result.result.H2ppm-latest_ana_rlt.result.H2ppm)/latest_ana_rlt.result.H2ppm;
|
|
|
|
|
if(delt>0.4)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>40%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastH2=%f currH2=%f delt=%f correc to %f\n",latest_ana_rlt.result.H2ppm,ana_result.result.H2ppm,delt,latest_ana_rlt.result.H2ppm*1.2);
|
|
|
|
|
ana_result.result.H2ppm=latest_ana_rlt.result.H2ppm*1.2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(ana_result.result.COppm<latest_ana_rlt.result.COppm)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴ<EFBFBD>С
|
|
|
|
|
delt=(latest_ana_rlt.result.COppm-ana_result.result.COppm)/latest_ana_rlt.result.COppm;
|
|
|
|
|
if(delt>0.2)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>-20%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastCO=%f currCO=%f delt=%f correc to %f\n",latest_ana_rlt.result.COppm,ana_result.result.COppm,delt,latest_ana_rlt.result.COppm*0.9);
|
|
|
|
|
ana_result.result.COppm=latest_ana_rlt.result.COppm*0.9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(latest_ana_rlt.result.COppm>=(1.0))//<2F>ϴβ<CFB4><CEB2><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>1ppm
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴδ<CFB4>
|
|
|
|
|
delt=(ana_result.result.COppm-latest_ana_rlt.result.COppm)/latest_ana_rlt.result.COppm;
|
|
|
|
|
if(delt>0.4)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>40%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastCO=%f currCO=%f delt=%f correc to %f\n",latest_ana_rlt.result.COppm,ana_result.result.COppm,delt,latest_ana_rlt.result.COppm*1.2);
|
|
|
|
|
ana_result.result.COppm=latest_ana_rlt.result.COppm*1.2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(ana_result.result.CH4ppm<latest_ana_rlt.result.CH4ppm)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴ<EFBFBD>С
|
|
|
|
|
delt=(latest_ana_rlt.result.CH4ppm-ana_result.result.CH4ppm)/latest_ana_rlt.result.CH4ppm;
|
|
|
|
|
if(delt>0.2)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>-20%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastCH4=%f currCH4=%f delt=%f correc to %f\n",latest_ana_rlt.result.CH4ppm,ana_result.result.CH4ppm,delt,latest_ana_rlt.result.CH4ppm*0.9);
|
|
|
|
|
ana_result.result.CH4ppm=latest_ana_rlt.result.CH4ppm*0.9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(latest_ana_rlt.result.CH4ppm>=(1.0))//<2F>ϴβ<CFB4><CEB2><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>1ppm
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴδ<CFB4>
|
|
|
|
|
delt=(ana_result.result.CH4ppm-latest_ana_rlt.result.CH4ppm)/latest_ana_rlt.result.CH4ppm;
|
|
|
|
|
if(delt>0.4)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>40%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastCH4=%f currCH4=%f delt=%f correc to %f\n",latest_ana_rlt.result.CH4ppm,ana_result.result.CH4ppm,delt,latest_ana_rlt.result.CH4ppm*1.2);
|
|
|
|
|
ana_result.result.CH4ppm=latest_ana_rlt.result.CH4ppm*1.2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(ana_result.result.C2H4ppm<latest_ana_rlt.result.C2H4ppm)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴ<EFBFBD>С
|
|
|
|
|
delt=(latest_ana_rlt.result.C2H4ppm-ana_result.result.C2H4ppm)/latest_ana_rlt.result.C2H4ppm;
|
|
|
|
|
if(delt>0.2)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>-20%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastC2H4=%f currC2H4=%f delt=%f correc to %f\n",latest_ana_rlt.result.C2H4ppm,ana_result.result.C2H4ppm,delt,latest_ana_rlt.result.C2H4ppm*0.9);
|
|
|
|
|
ana_result.result.C2H4ppm=latest_ana_rlt.result.C2H4ppm*0.9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(latest_ana_rlt.result.C2H4ppm>=(1.0))//<2F>ϴβ<CFB4><CEB2><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>1ppm
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴδ<CFB4>
|
|
|
|
|
delt=(ana_result.result.C2H4ppm-latest_ana_rlt.result.C2H4ppm)/latest_ana_rlt.result.C2H4ppm;
|
|
|
|
|
if(delt>0.4)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>40%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastC2H4=%f currC2H4=%f delt=%f correc to %f\n",latest_ana_rlt.result.C2H4ppm,ana_result.result.C2H4ppm,delt,latest_ana_rlt.result.C2H4ppm*1.2);
|
|
|
|
|
ana_result.result.C2H4ppm=latest_ana_rlt.result.C2H4ppm*1.2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(ana_result.result.C2H6ppm<latest_ana_rlt.result.C2H6ppm)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴ<EFBFBD>С
|
|
|
|
|
delt=(latest_ana_rlt.result.C2H6ppm-ana_result.result.C2H6ppm)/latest_ana_rlt.result.C2H6ppm;
|
|
|
|
|
if(delt>0.2)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>-20%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastC2H6=%f currC2H6=%f delt=%f correc to %f\n",latest_ana_rlt.result.C2H6ppm,ana_result.result.C2H6ppm,delt,latest_ana_rlt.result.C2H6ppm*0.9);
|
|
|
|
|
ana_result.result.C2H6ppm=latest_ana_rlt.result.C2H6ppm*0.9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(latest_ana_rlt.result.C2H6ppm>=(1.0))//<2F>ϴβ<CFB4><CEB2><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>1ppm
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴδ<CFB4>
|
|
|
|
|
delt=(ana_result.result.C2H6ppm-latest_ana_rlt.result.C2H6ppm)/latest_ana_rlt.result.C2H6ppm;
|
|
|
|
|
if(delt>0.4)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>40%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastC2H6=%f currC2H6=%f delt=%f correc to %f\n",latest_ana_rlt.result.C2H6ppm,ana_result.result.C2H6ppm,delt,latest_ana_rlt.result.C2H6ppm*1.2);
|
|
|
|
|
ana_result.result.C2H6ppm=latest_ana_rlt.result.C2H6ppm*1.2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(ana_result.result.C2H2ppm<latest_ana_rlt.result.C2H2ppm)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴ<EFBFBD>С
|
|
|
|
|
delt=(latest_ana_rlt.result.C2H2ppm-ana_result.result.C2H2ppm)/latest_ana_rlt.result.C2H2ppm;
|
|
|
|
|
if(delt>0.2)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>-20%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastC2H2=%f currC2H2=%f delt=%f correc to %f\n",latest_ana_rlt.result.C2H2ppm,ana_result.result.C2H2ppm,delt,latest_ana_rlt.result.C2H2ppm*0.9);
|
|
|
|
|
ana_result.result.C2H2ppm=latest_ana_rlt.result.C2H2ppm*0.9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(latest_ana_rlt.result.C2H2ppm>=(1.0))//<2F>ϴβ<CFB4><CEB2><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>1ppm
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴδ<CFB4>
|
|
|
|
|
delt=(ana_result.result.C2H2ppm-latest_ana_rlt.result.C2H2ppm)/latest_ana_rlt.result.C2H2ppm;
|
|
|
|
|
if(delt>0.4)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>40%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastC2H2=%f currC2H2=%f delt=%f correc to %f\n",latest_ana_rlt.result.C2H2ppm,ana_result.result.C2H2ppm,delt,latest_ana_rlt.result.C2H2ppm*1.2);
|
|
|
|
|
ana_result.result.C2H2ppm=latest_ana_rlt.result.C2H2ppm*1.2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(my_para_data.mach_run_para.co2_pos!=0)
|
|
|
|
|
{
|
|
|
|
|
if(ana_result.result.CO2ppm<latest_ana_rlt.result.CO2ppm)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴ<EFBFBD>С
|
|
|
|
|
delt=(latest_ana_rlt.result.CO2ppm-ana_result.result.CO2ppm)/latest_ana_rlt.result.CO2ppm;
|
|
|
|
|
if(delt>0.2)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>-20%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastCO2=%f currCO2=%f delt=%f correc to %f\n",latest_ana_rlt.result.CO2ppm,ana_result.result.CO2ppm,delt,latest_ana_rlt.result.CO2ppm*0.9);
|
|
|
|
|
ana_result.result.CO2ppm=latest_ana_rlt.result.CO2ppm*0.9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(latest_ana_rlt.result.CO2ppm>=(1.0))//<2F>ϴβ<CFB4><CEB2><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>1ppm
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>α<EFBFBD><CEB1>ϴδ<CFB4>
|
|
|
|
|
delt=(ana_result.result.CO2ppm-latest_ana_rlt.result.CO2ppm)/latest_ana_rlt.result.CO2ppm;
|
|
|
|
|
if(delt>0.4)//<2F><><EFBFBD><EFBFBD><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD>40%
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(TRACE_DEBUG,"lastCO2=%f currCO2=%f delt=%f correc to %f\n",latest_ana_rlt.result.CO2ppm,ana_result.result.CO2ppm,delt,latest_ana_rlt.result.CO2ppm*1.2);
|
|
|
|
|
ana_result.result.CO2ppm=latest_ana_rlt.result.CO2ppm*1.2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ana_result.result.CO2ppm=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
memcpy(&ysp_pri_data,&ana_result.result,sizeof(YSP_PRI_DATA));
|
|
|
|
|
ysp_pri_data.TotHyd=ysp_pri_data.CH4ppm+ysp_pri_data.C2H2ppm+ysp_pri_data.C2H4ppm+ysp_pri_data.C2H6ppm;
|
|
|
|
|
ana_result.result.TotHyd=ysp_pri_data.TotHyd;
|
|
|
|
|
add_his_entry(&ana_result);//<2F><><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|
|
|
|
if(save_last_result(&ana_result)!=0)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save last data failed\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
send_ysp_msg(&ysp_pri_data);
|
|
|
|
|
for(i=0;i<6;i++)
|
|
|
|
|
{
|
|
|
|
|
ysp_ana_pos.position[i].start=ana_result.pos_info[i].start;
|
|
|
|
|
ysp_ana_pos.position[i].peak=ana_result.pos_info[i].peak;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(save_analysis_file(analysis_buf,MAX_DATA_LEN,&my_para_data,&ysp_ana_pos,&ysp_pri_data)==0)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"save analysis file %s sucessful\n",analysis_buf);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"save_analysis_file %s failed\n",analysis_buf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"analysis %s failed\n",analysis_buf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//LOG_DEBUG(ANALYSIS_TRACE_DEBUG,"analysis is running\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ((void *)0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int analysis_init(void)
|
|
|
|
|
{
|
|
|
|
|
pthread_t analysis_thread;
|
|
|
|
|
if((analysis_thread=task_create(analysis_routine,NULL,0,0))==-1)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(ERROR_DEBUG,"create analysis_routine failed\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|