Пример #1
0
void		client_talking(t_server *server, int *actual, char *buff)
{
	int			i;
	t_client	client;
	char		*tmp;

	i = 0;
	while (i < *actual)
	{
		if (FD_ISSET(server->clients[i].sock, &(server->rdfs)))
		{
			client = server->clients[i];
			if (read_client(server->clients[i].sock, buff) == 0)
			{
				if_read(server, actual, buff, i);
			}
			else if (buff[0] == '/')
			{
				if ((tmp = cmd(buff, &(server->clients[i]), server)))
					write_client(server->clients[i].sock, tmp);
			}
			else
				send_to_all(server->clients, client, *actual, buff);
			break ;
		}
		i++;
	}
}
Пример #2
0
void cmd_lcd_drawimage(uint_least16_t fgcolor, uint_least16_t bgcolor)
{
  uint_least8_t b, c, e, n;
  uint_least16_t a, x0, y0, x1, y1, w, h;
  uint_least32_t i, ms;

  x0 = if_read(); //x0
  y0 = if_read(); //y0
  w  = if_read(); //w
  h  = if_read(); //h
  x1 = x0+w-1;
  y1 = y0+h-1;
  c  = if_read8(); //color mode + encoding
  e  = c & COLOR_RLE;
  c  = c & ~COLOR_RLE;

  lcd_enable();
  lcd_setarea(x0, y0, x1, y1);
  lcd_drawstart();

  switch(c)
  {
    case COLOR_BW: //black/white
      fgcolor = RGB(0,0,0);
      bgcolor = RGB(255,255,255);
      break;
    case COLOR_WB: //white/black
      fgcolor = RGB(255,255,255);
      bgcolor = RGB(0,0,0);
      break;
    case COLOR_FG: //fg/bg
      fgcolor = fgcolor;
      bgcolor = bgcolor;
      break;
    case COLOR_BG: //bg/fg
      fgcolor ^= bgcolor;
      bgcolor ^= fgcolor;
      fgcolor ^= bgcolor;
      break;
  }

  ms = get_ms();
  if(e == 0) //no encoding
  {
    switch(c)
    {
      case COLOR_BW: //black/white
      case COLOR_WB: //white/black
      case COLOR_FG: //fg/bg
      case COLOR_BG: //bg/fg
        for(i=w*h; i!=0;)
        {
          if(if_available())
          {
            a = if_read8();
            for(b=0x80; (b!=0) && (i!=0); b>>=1)
            {
              if(a & b) { lcd_draw(fgcolor); }
              else      { lcd_draw(bgcolor); }
              i--;
            }
          }
          else if((get_ms()-ms) > 2000) //2s
          {
            break;
          }
        }
        break;
      case COLOR_RGB323:
      case COLOR_RGB332:
      case COLOR_RGB233:
      case COLOR_GRAY:
        for(i=w*h; i!=0;)
        {
          if(if_available())
          {
            a = if_read8();
                 if(c == COLOR_RGB323){ a = RGB323toRGB565(a); }
            else if(c == COLOR_RGB332){ a = RGB332toRGB565(a); }
            else if(c == COLOR_RGB233){ a = RGB233toRGB565(a); }
            else                      { a = GRAYtoRGB565(a);   }
            lcd_draw(a);
            i--;
          }
          else if((get_ms()-ms) > 2000) //2s
          {
            break;
          }
        }
        break;
      default:
      case COLOR_RGB565:
        for(i=w*h; i!=0;)
        {
          if(if_available())
          {
            a = if_read16();
            lcd_draw(a);
            i--;
          }
          else if((get_ms()-ms) > 2000) //2s
          {
            break;
          }
        }
        break;
      case COLOR_RGB888:
        for(i=w*h; i!=0;)
        {
          if(if_available())
          {
            a  = (if_read8()&0xF8)<<8; //R (5 bits)
            a |= (if_read8()&0xFC)<<3; //G (6 bits)
            a |= (if_read8()&0xF8)>>3; //B (5 bits)
            lcd_draw(a);
            i--;
          }
          else if((get_ms()-ms) > 2000) //2s
          {
            break;
          }
        }
        break;
    }
Пример #3
0
void use_download(int conn_fd)
{
	char pathname[SIZE];
	char name[SIZE];
	char tmp[SIZE];
	char choose[SIZE];
	char lenght[SIZE];
	char u_lenght[SIZE];
	long size;
	long d_size;
	double percent;
	struct stat file;
	int fd;
	int dir;
	int ret;
	long len = 0;
	int flag;
	int i = 0;


	printf("\n\n\t请输入要保存的本地路径:");

	scanf("%s", pathname);

	dir = chdir(pathname);

	printf("\t\t请输入保存名称:");
	scanf("%s", name);

	flag = if_read(pathname, name);
	send_data(conn_fd, "y\n");
	i = recv(conn_fd, lenght, sizeof(lenght), 0);
	size = atol(lenght);

	if (flag == 1)
	{
		fd = open(name, O_WRONLY | O_APPEND );
	}
	else
	{
		fd = open(name, O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0600);
//需要修改
	}
	fstat(fd, &file);
	d_size = (long)file.st_size;
	getchar();
	getch();
	sprintf(u_lenght, "%ld", d_size);
	send(conn_fd, u_lenght, sizeof(lenght), 0);
	
		while((size - len) > SIZE)
	{
		stat(name, &file);
		d_size = (long)file.st_size;
		percent = (double)d_size*100.0/(double)size;
		printf("\n\n\t已下载%.1lf%%\n", percent);
		memset(tmp, '\0', sizeof(tmp));
		flag = recv(conn_fd, tmp, SIZE, MSG_WAITALL);
		len += write(fd, tmp, SIZE);
		system("clear");
	}
	memset(tmp, '\0', sizeof(tmp));
	flag = recv(conn_fd, tmp, SIZE, 0);
	len += write(fd, tmp, flag);
	d_size = (long)file.st_size;
	percent = (double)d_size*100.0/(double)size;
	printf("\n\n\t已下载%.1lf%%\n", percent);
	sleep(1);
	system("clear");
	printf("\n\n\t已下载100%%,接收完毕\n");
	ftruncate(fd, size);
	close(fd);
    printf("\n\n\t请按任意健返回\n");
	getch();
	send_data(conn_fd, "y\n");
	user_choose(conn_fd);
}