Exemplo n.º 1
0
int main(int argc, char ** argv)
{
	const char *IP="192.168.1.74";
	SOCKET client;

	printf("waiting for connection\n");
	init_TCP_client(&client, IP, PORT);

	//usleep(60000000);
	int i=0,Nbuff=12;
	int *buff_int=NULL;
	int16_t *buff=NULL;
	buff_int=(int *)malloc(Nbuff*sizeof(int));
	buff=(int16_t *)malloc(Nbuff*sizeof(uint16_t));

	receive_int16_TCP_client(&client,buff,Nbuff);
	for (i=0 ; i<Nbuff ; i++)
	{
		printf("buff[%i] = %i\n",i,buff[i]);
	}

	close_TCP_client(&client);

	return 0;
}
Exemplo n.º 2
0
int main(int arg, char *argv[])
{
	int Npoint, dec, line, Nline, sector;
	double x0, xf;

	//socket variable
	SOCKET sock;
	const char *IP="192.168.128.3";
	init_TCP_client(&sock, IP, Port);

	int Nset=5;
	char settings[Nset];
	receive_TCP_client(&sock, settings, Nset);
	x0=(double)int_converter(settings[0]);
	xf=(double)int_converter(settings[1]);
	dec=int_converter(settings[2]);
	line=int_converter(settings[3]);
	Nline=line/2;
	sector=int_converter(settings[4]);
	Npoint=(int)(2.0*(xf-x0)*125.0/1.48/((double)dec));
	char *buff=(char *)malloc((Npoint+1)*sizeof(char));

	//gnuplot variable
	gnuplot_ctrl * h;
	double *y= (double *)malloc(Npoint*sizeof(double));
	int i,j;

	//gnuplot object
	h=gnuplot_init();
	gnuplot_setstyle(h,"lines");
	gnuplot_set_xlabel(h,"time (us)");
	gnuplot_set_ylabel(h,"signal");
	gnuplot_cmd(h,"set yrange [1:%d]",Ymax);
	gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1);

	while(1)
	{
		if (receive_TCP_client(&sock, buff, Npoint+1)==1)
		{
			break;
		}	
			
		if ((int)(buff[0])==Nline)
		{
			for (i=1; i<Npoint+1 ; i++)
			{
				y[i-1]=(double)(buff[i]);
			}
			gnuplot_resetplot(h);
			gnuplot_plot_x(h, y, Npoint, "RP");
		}
	}

	usleep(30);
	close(sock);
	free(y);
	return 0;
}
Exemplo n.º 3
0
void Com_Init (int direction, int I_media_type, short SenderId, short ReceiverId)
{
/*
	HANDLE hMutex;
	
	if(direction == MEDIUM_SEND){
		hMutex = createComMutex(comSendMutName);
	}
	else{
		hMutex = createComMutex(comRcvMutName);
	}
	WaitForSingleObject(hMutex, INFINITE);
*/
	switch(direction){
		case MEDIUM_SEND:
			if(Media[SenderId][ReceiverId][TCP_SND].medium == NULL){
				Media_TCP *medium = (Media_TCP *) malloc(sizeof(Media_TCP));
				
				medium->port = TCP_BASE_ADDRESS + ((SenderId<<4) + (ReceiverId));
				medium->socket =  init_TCP_server (*medium);

				Media[SenderId][ReceiverId][TCP_SND].medium = medium;
			}
			break;

		case MEDIUM_RCV: 	
			if(Media[ReceiverId][SenderId][TCP_RCV].medium == NULL){		
				Media_TCP *medium = (Media_TCP *) malloc(sizeof(Media_TCP));

				medium->port = TCP_BASE_ADDRESS + ((SenderId<<4) + (ReceiverId));
				medium->socket =  init_TCP_client (*medium,"localhost");//"192.168.1.2"

				Media[ReceiverId][SenderId][TCP_RCV].medium = medium;
			}
			break;
	}

	//ReleaseMutex(hMutex);
}
Exemplo n.º 4
0
int main(int arg, char *argv[])
{
	int Npoint;

	//socket variable
	SOCKET sock;
	const char *IP="192.168.128.3";
	init_TCP_client(&sock, IP, Port);
	get_RP_settings(&sock);
	printf("r0=%f\n",r0);
        printf("rf=%f\n",rf);
        printf("dec=%i\n",dec);
        printf("Nline=%i\n",Nline);
        printf("sector=%f\n",sector);
	printf("mode_RP=%i\n",mode_RP);

	int l=0;

	Npoint=(int)(2.0*(rf-r0)*125.0/1.48/((double)dec));
        if (Npoint>16384) {Npoint=16384;}
	printf("Npoint = %i\n",Npoint);

	int powd, pad_len;
        if (power_two(Npoint,&powd)){powd++;}
        pad_len=int_pow(2,powd);
	init_table(pad_len);
	float fech=125000000.0/((float)dec);

	//gnuplot variable
	gnuplot_ctrl * h;
	double *y= (double *)malloc(Npoint*sizeof(double));
	int i;

	int Ymax=1.5;

	//gnuplot object
	h=gnuplot_init();
	gnuplot_setstyle(h,"lines");
	gnuplot_set_xlabel(h,"time (us)");
	gnuplot_set_ylabel(h,"signal");
	//gnuplot_cmd(h,"set yrange [0:%d]", 2*Ymax);
	gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1);

	char name[30];

	if (mode_RP==0)
	{

		int powd, pad_len;
		if (power_two(Npoint,&powd)){powd++;}
        	pad_len=int_pow(2,powd);
		double *pad=NULL;
		pad=(double *)malloc(pad_len*sizeof(double));
		double *env=NULL;
		env=(double *)malloc(pad_len*sizeof(double));
	
		gnuplot_cmd(h,"set yrange [-0.01:1.5]");
		gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1);
		int16_t *buff=(int16_t *)malloc((Npoint+1)*sizeof(int16_t));
		while(1)
		{
			if(receive_int16_TCP_client(&sock, buff, Npoint+1)==1){break;}
			for (i=1 ; i<Npoint+1 ; i++){y[i-1]=(double)(buff[i])/409.6;} //divide by 409.6 to have voltage value
			zero_padding(y, pad, Npoint, pad_len, 1);
			envelope(pad, env, pad_len, fech, fmin, fmax, 0);
			gnuplot_resetplot(h);
			//gnuplot_plot_x(h, y, Npoint, "Oscillo int16_t");
			gnuplot_plot_x(h, env, pad_len, "Oscillo int16_t");			
                        //sprintf(name, "int%i.txt", l);
                        //writefile(y, Npoint, name);
                        l++;

		}
		free(buff);
		free(pad);
		free(env);
	}

	else if (mode_RP==1)
	{
		char *buff=(char *)malloc((Npoint+1)*sizeof(char));
		while(1)
		{
			if(receive_TCP_client(&sock, buff, Npoint+1)==1){break;}
			for (i=1 ; i<Npoint+1 ; i++){y[i-1]=(double)(int_converter(buff[i]));} 
			gnuplot_resetplot(h);
			gnuplot_plot_x(h, y, Npoint, "Oscillo 256 gray");
			sprintf(name, "char%i.txt", l);
			//writefile(y, Npoint, name);
			l++;
		}
		free(buff);
	}

	else {printf("Problem of settings\n");}

	usleep(30);
	close(sock);
	free(y);

	return 0;
}
Exemplo n.º 5
0
int main(int arg, char *argv[])
{
	//socket variable
	SOCKET sock;
	const char *IP="192.168.128.3";
	init_TCP_client(&sock, IP, Port);
        get_RP_settings(&sock);
        printf("x0=%f\n",x0);
        printf("xf=%f\n",xf);
        printf("dec=%i\n",dec);
        printf("Nline=%i\n",Nline);
        printf("sector=%f\n",sector);
	printf("mode_RP=%i\n",mode_RP);

	char name[50];

	Npoint=(int)(2.0*(xf-x0)*125.0/1.48/((double)dec));
	if (Npoint>16384){Npoint=16384;}
	printf("Npoint = %i\n",Npoint);

	int powd, pad_len;
        if (power_two(Npoint,&powd)){powd++;}
        pad_len=int_pow(2,powd);
	init_table(pad_len);

	//gnuplot variable
	gnuplot_ctrl * h;
	int i, j;

	double **x = NULL;
        double **y = NULL;
        int **z = (int **)malloc(Nline*sizeof(int *));
	double *tmp = (double *)malloc(Npoint*sizeof(int));
	double *tmp2 = (double *)malloc(pad_len*sizeof(double));
	double **env = (double **)malloc(Nline*sizeof(double *));
	double *pad = (double *)malloc(pad_len*sizeof(double));
        x = malloc(Nline*sizeof(double *));
        y = malloc(Nline*sizeof(double *));

        for (i=0 ; i<Nline ; i++)
        {
                x[i]=malloc((Npoint)*sizeof(double));
                y[i]=malloc((Npoint)*sizeof(double));
                z[i]=malloc((Npoint)*sizeof(int));
		env[i]=(double *)malloc(pad_len*sizeof(double));
		if (env[i]==NULL) {printf("boulet!");}
		for (j=0 ; j<pad_len ; j++) {env[i][j]=0.0;}
        }

        init_xy(x,y);

	//gnuplot object
	h=gnuplot_init();
	gnuplot_cmd(h, "set pm3d map");
	gnuplot_cmd(h, "set palette gray");

	int k=1, line=0, l=0, temp;

	if (mode_RP==0)
	{
		int16_t *buff=(int16_t *)malloc((Npoint+1)*sizeof(int16_t));
		float fech, f0, fm;
		fech=125000000.0/dec;
		f0=3500000.0;
		fm=6500000.0;

	        i=0;
	        j=0;
	        while (1)
	        {
	                receive_int16_TCP_client(&sock, buff, Npoint+1);
	                j=i;
	                i=(int)buff[0];
	                if (j==63 && i==64) {break;}
	                if (j==2 && i==1) {break;}
	        }


		while(k)
		{
			temp=l/10;
			for (i=0 ; i<Nline ; i++)
			{
				if (receive_int16_TCP_client(&sock, buff, Npoint+1)==1)
				{
					i=Nline+2;
					k=0;
					break;
				}
	
				if(i<Nline+2)
				{
					line=(int)buff[0]-1;
					for (j=0 ; j<Npoint ; j++) {tmp[j]=(double)buff[j+1];}
					zero_padding(tmp, pad, Npoint, pad_len, 1); 
					tmp2=env[line];
                        		envelope(pad, tmp2, pad_len, fech, f0, fm, 0);
					if (temp*10==l) {z[line]=tmp[j];}
					//for (j=0 ; j<Npoint ; j++) {z[line][j]=(int)env[j];}
				}
			}
			gnuplot_matrix_double(h, env, Npoint, Nline);
			if (temp*10==l)
			{
				sprintf(name, "int%i.txt", l);
				writefile_double(env, Nline, Npoint, name);
			}
			l++;
		}
		free(buff);
	}

	else if (mode_RP==1)
	{
		char *buff=(char *)malloc((Npoint+1)*sizeof(char));
		while(k)
		{
			for (i=0 ; i<Nline ; i++)
			{
				if (receive_TCP_client(&sock, buff, Npoint+1)==1)
				{
					i=Nline+2;
					k=0;
					break;
				}
	
				if(i<Nline+2)
				{
					line=int_converter(buff[0])-1;
					for (j=0 ; j<Npoint ; j++) {z[line][j]=int_converter(buff[j+1]);}
				}
			}
			gnuplot_matrix(h, z, Npoint, Nline);
			temp=l/10;
			if (temp*10==l)
			{
				sprintf(name, "char%i.txt", l);
				writefile(z, Nline, Npoint, name);
			}
			l++;
		}
		free(buff);
	}

	else {printf("problem with RP settings\n");}


	/*int k=1, line=0, l=0;
	while(k)
	{
		for (i=0 ; i<Nline ; i++)
		{
			if (receive_TCP_client(&sock, buff, Npoint+1)==1)
			{
				i=Nline+2;
				k=0;
				break;
			}
			
			if (i<Nline+2)
			{
				line=int_converter(buff[0])-1;
				for (j=0 ; j<Npoint-1 ; j++)
				{
					//z[line][j]=(int)buff[j+1];
					z[line][j]=int_converter(buff[j+1]);
				}
			}
		}
		gnuplot_matrix(h, z, Npoint, Nline);	
		//sprintf(name, "main%i.txt",l);
		//writefile(z, Nline, Npoint, name);
		l++;
	}*/

	usleep(30);
	close(sock);
	free(x);
	free(y);
	free(z);
	free(env);
	free(pad);
	return 0;
}