Beispiel #1
0
void	flag(t_env *e)
{
	zero_padding(e);
	if (e->f_alternate_form)
		alternate_form(e);
	if (e->sign || e->blank_positiv_number)
		positive_number(e);
}
Beispiel #2
0
/* Writes SIZE bytes from BUFFER into INODE, starting at OFFSET.
   Returns the number of bytes actually written, which may be
   less than SIZE if end of file is reached or an error occurs.
   (Normally a write at end of file would extend the inode, but
   growth is not yet implemented.) */
off_t
inode_write_at (struct inode *inode, const void *buffer_, off_t size_,
                off_t offset_)
{
  const uint8_t *buffer = buffer_;
  int bytes_written = 0;
  int size=(int) size_;
  int offset=(int)offset_;

  if (inode->deny_write_cnt)
    return 0;

  struct inode_disk id;
  lock_acquire(&inode->inode_lock);
  cache_read(inode->sector, INVALID_SECTOR_ID, &id, 0, BLOCK_SECTOR_SIZE);
  int phy_length = (int)id.length;
  if (offset + size > phy_length) {
	  if(!zero_padding(inode, &id, phy_length, offset+size)){
		  lock_release(&inode->inode_lock);
		  return 0;
	  }
  }


  while (size > 0)
    {
      /* Sector to write, starting byte offset within sector. */
      block_sector_t sector_idx = byte_to_sector_no_check (inode, offset);
      int sector_ofs = offset % BLOCK_SECTOR_SIZE;

      /* Bytes left in inode, bytes left in sector, lesser of the two. */
      off_t inode_left = id.length - offset;
      int sector_left = BLOCK_SECTOR_SIZE - sector_ofs;
      int min_left = inode_left < sector_left ? inode_left : sector_left;

      /* Number of bytes to actually write into this sector. */
      int chunk_size = size < min_left ? size : min_left;
      if (chunk_size <= 0)
        break;

      cache_write(sector_idx, (void *)(buffer+bytes_written),
    		  sector_ofs, chunk_size);

      /* Advance. */
      size -= chunk_size;
      offset += chunk_size;
      bytes_written += chunk_size;
    }

  inode->readable_length=id.length;
  lock_release(&inode->inode_lock);
  return bytes_written;
}
Beispiel #3
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;
}
Beispiel #4
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;
}