#include <arpa/inet.h>
#include "workthread.h"
#include <math.h>
#include "fftw3.h"
#include <pthread.h>
#include <semaphore.h>
#include <string.h>
#include "tool.h"
#include "V_Dip_Swell_Interrupt.h"
#include "main.h"
#include "pq_linux.h"
#include "data.h"
#include <unistd.h>
//修正系数
double a_channel_index=1.01278;
short test;
int test2;
int A_packet_number;
volatile short an_buffer[AN_BUFFER_880kLEN];
static short an_buffer_cur[AN_BUFFER_880kLEN];
unsigned long an_buffer_idx_A = 0;
static unsigned long an_buffer_8800flag_A = 0;
static int index_8800_A = 0;
u_int A_err_flag;
u_short A_err_current;
unsigned long A_err_sum;
static char A_fre_flag = 0;
static u_short A_temp, A_temp_last;
u_short A_flag;
static u_char error_flag = 0;
static u_char A_flag1 = 0, A_flag2 = 0;
static u_short stand_flag;
short output1,output2;
char output_flag=0;
#if(AD_SAMPLE_ACCURACY==16)
static int packet_offset=42;
#else
static int packet_offset=16;
#endif
//第一个参数是pcap_loop的最后一个参数,当收到足够数量的包后pcap_loop会调用callback回调函数,同时将pcap_loop()的user参数传递给它
//第二个参数是收到的数据包的pcap_pkthdr类型的指针
//第三个参数是收到的数据包数据
void ethernet_protocol_packet_callback_A(u_char * arg, const struct pcap_pkthdr * pkthdr, const u_char * packet)
{
an_point *sample;
(void)(arg);
sample = (an_point *)(packet + packet_offset);
if (!A_flag1) //ִֻ
{
A_flag = ntohs(sample->stand_flag);
stand_flag = (A_flag - 1) % mod_value;
A_flag1 = 1;
}
A_temp = ntohs(sample->stand_flag);
if (A_temp != ((A_temp_last + 1) % mod_value))
{
error_flag = 1;
A_err_current = (((short)(A_temp - A_temp_last - 1)) % mod_value);
A_err_sum += A_err_current;
A_err_flag++;
}
A_temp_last = A_temp;
if (A_temp == stand_flag)
{
A_flag2 = 1;
}
//if (A_flag2)
{
if (an_buffer_idx_A < AN_BUFFER_880kLEN)
{
#if(AD_SAMPLE_ACCURACY==16)
{
an_buffer[an_buffer_idx_A] = ntohs(sample->an_ch0)*a_channel_index;//
an_buffer_cur[an_buffer_idx_A] = ntohs(sample->an_ch1)*a_channel_index;//
}
#else
{
an_buffer[an_buffer_idx_A] = ntohl(sample->an_ch0)/4;//
an_buffer_cur[an_buffer_idx_A] = ntohl(sample->an_ch0)/4;//
an_buffer[an_buffer_idx_A]=an_buffer[an_buffer_idx_A]*a_channel_index;
}
#endif
an_buffer_idx_A++;
if(output_flag==0)
{
output1=an_buffer[an_buffer_idx_A-1];
//output1=an_buffer[0];
//printf("**********%d %d\n",output1,an_buffer[0]);
//output2=ntohs(sample->stand_flag);
output2=A_temp;
output_flag=1;
}
if (an_buffer_idx_A % 400 == 0) //400
sem_post(&A_halfcalc_semaphore);
if (an_buffer_idx_A % 8 == 0) //
sem_post(&data_send_sem);
if (an_buffer_idx_A % Plus_8000 == 0)//
{
index_8800_A = an_buffer_idx_A / Plus_8000;
an_buffer_8800flag_A = 1;
sem_post(&FFT_A_semaphore);
}
}
else
{
an_buffer_idx_A = 0;
#if(AD_SAMPLE_ACCURACY==16)
{
an_buffer[an_buffer_idx_A] = ntohs(sample->an_ch0)*a_channel_index;//
an_buffer_cur[an_buffer_idx_A] = ntohs(sample->an_ch1)*a_channel_index;//
}
#else
{
an_buffer[an_buffer_idx_A] = ntohl(sample->an_ch0)/4;//
an_buffer_cur[an_buffer_idx_A] = ntohl(sample->an_ch0)/4;//
}
#endif
an_buffer_idx_A++;
}
}
A_packet_number = 1;
}
int B_packet_number;
static char B_fre_flag = 0;
static int index_8800_B = 0;
unsigned long an_buffer_idx_B = 0;
static short an_buffer_b[AN_BUFFER_880kLEN];
static short an_buffer_b_cur[AN_BUFFER_880kLEN];
static unsigned long an_buffer_8800flag_B = 0;
u_int B_err_flag;
u_short B_err_current;
unsigned long B_err_sum;
static u_short B_temp,B_temp_last;
u_short B_flag;
static u_char B_flag1 = 0, B_flag2 = 0;
void ethernet_protocol_packet_callback_B(u_char *user_data,
const struct pcap_pkthdr *packet_header,
const u_char *packet_content)
{
an_point *sample;
(void)(user_data);
sample = (an_point *)(packet_content + packet_offset);
if (!B_flag1) //ִֻ
{
B_flag = ntohs(sample->stand_flag);
B_flag1 = 1;
}
B_temp = ntohs(sample->stand_flag);
if (B_temp != ((B_temp_last + 1) % mod_value))
{
error_flag = 1;
B_err_current = (((short)(B_temp - B_temp_last - 1)) % mod_value);
B_err_sum += B_err_current;
B_err_flag++;
}
B_temp_last = B_temp;
if (B_temp == stand_flag)
{
B_flag2 = 1;
}
//if (B_flag2)
{
if (an_buffer_idx_B < AN_BUFFER_880kLEN) // 880000 1000 20s
{
//ntohs
#if (AD_SAMPLE_ACCURACY == 16)
{
an_buffer_b[an_buffer_idx_B] = ntohs(sample->an_ch2);//B
an_buffer_b_cur[an_buffer_idx_B] = ntohs(sample->an_ch3);//B
}
#else
{
an_buffer_b[an_buffer_idx_B] = ntohl(sample->an_ch0) / 4;//
an_buffer_b_cur[an_buffer_idx_B] = ntohl(sample->an_ch0) / 4;//
}
#endif
an_buffer_idx_B++;
/********************************************�����ڼ���**********************************************************************************/
if (an_buffer_idx_B % 400 == 0) //400
sem_post(&FFT_B_semaphore);
if (an_buffer_idx_B % Plus_8000 == 0)//
{
index_8800_B = an_buffer_idx_B / Plus_8000;
an_buffer_8800flag_B = 1;
sem_post(&FFT_B_semaphore);
}
}
else
{
an_buffer_idx_B = 0;
#if (AD_SAMPLE_ACCURACY == 16)
{
an_buffer_b[an_buffer_idx_B] = ntohs(sample->an_ch2);//B��ѹ
an_buffer_b_cur[an_buffer_idx_B] = ntohs(sample->an_ch3);//B��ѹ
}
#else
{
an_buffer_b[an_buffer_idx_B] = ntohl(sample->an_ch0) / 4;//B��ѹ
an_buffer_b_cur[an_buffer_idx_B] = ntohl(sample->an_ch0) / 4;//B��ѹ
}
#endif
an_buffer_idx_B++;
}
}
B_packet_number = 1;
}
int C_packet_number;
static char C_fre_flag = 0;
static int index_8800_C = 0;
unsigned long an_buffer_idx_C = 0;
static short an_buffer_c[AN_BUFFER_880kLEN];
static short an_buffer_c_cur[AN_BUFFER_880kLEN];
static unsigned long an_buffer_8800flag_C = 0;
u_int C_err_flag;
u_short C_err_current;
unsigned long C_err_sum;
static u_short C_temp, C_temp_last;
u_short C_flag;
static u_char C_flag1 = 0, C_flag2 = 0;
void ethernet_protocol_packet_callback_C(u_char *user_data,
const struct pcap_pkthdr *packet_header,
const u_char *packet_content)
{
an_point *sample;
(void)(user_data);
sample = (an_point *)(packet_content + packet_offset);
if (!C_flag1) //ִֻ��һ�εõ���ʼֵ
{
C_flag = ntohs(sample->stand_flag) - 1;
C_flag1 = 1;
}
C_temp = ntohs(sample->stand_flag);
if (C_temp != ((C_temp_last + 1) % mod_value))
{
error_flag = 1;
C_err_current = (((short)(C_temp - C_temp_last - 1)) % mod_value);
C_err_sum += C_err_current;
C_err_flag++;
}
C_temp_last = C_temp;
if (C_temp == stand_flag)
{
C_flag2 = 1;
}
//if (C_flag2)
{