示例#1
0
void thr_fn(void *arg)
{
    tcp_client_stream_t *stream = NULL;
    stream = tcp_client_connect(client, "127.0.0.1", 5000); 
    tcp_client_add_stream(stream, rcv_cb); 
    tcp_client_send_data(stream, buffer);
}
示例#2
0
void tcp_client_start(tcp_client_data_t * client)
{
        tcp_client_connect(client);
        pthread_create(&client->send_thread, NULL, &tcp_client_send_loop, client);
        pthread_create(&client->recv_thread, NULL, &tcp_client_recv_loop, client);


}
示例#3
0
文件: cam_view.c 项目: EX311/moira
int main(void)
{

    pthread_t ts_thread;
    void* thread_result;
    int thread_res;

    int count ;
    int offset =0;
    unsigned short buf_pix ;
    struct color tmp_color;

    int i,j;
    int tmp = 0;

    signal(SIGSEGV, sig);
    signal(SIGINT, sig);
    signal(SIGTERM, sig);

    myfb = myfb_open();
    insert_ipaddr();

    for(i=0 ; i <10; i++)
        printf("\n");

    for(i =0 ; i<4 ; i++)
    {
        printf(" ipaddr set [%d] = ", i );
        for(j=0 ; j <16 ; j++)
        {
            printf("%c",ipaddr[i][j]);
        }
        printf("\n");
    }



    set_vfb_buf(VFB_MAX);
#if DEBUG
    printf(" set_ vfb buf () \n");
#endif

    register_icon(&icon[0], 40, 198,60,40, "Single", "" );
    register_icon(&icon[1], 130, 198,60,40, "Mult", "");
    register_icon(&icon[2], 220, 198,60,40, "Full Screen", "");
    register_icon(&icon[3], 298, 5,20,20, "x", "");

    thread_res = pthread_create(&ts_thread, NULL, ts_click,NULL);

    if (thread_res !=0)
    {
        perror (" thread create failed\n");
        exit(1);
    }

    clear_screen();

    for (i=0; i<myicon_count; i++)
        draw_icon(&icon[i]);

    while( event ==0)
    {
        sleep(1);  // input delay
    }

    while(1)
    {

        //	insert_ipaddr();

        if (event == 9)
        {
            put_string_center(140, 100, " exit cam app ", white);
            sleep(2);
            goto end;

        }
        cam_set(func);

        if(func == 2 || func == 3)
        {
            for(i =0 ; i <VFB_MAX ; i++)
            {
                if(i == get_MyLocation())
                    continue;
                if (strlen(ipaddr[i]) > 13) {
                    sock[i] = tcp_client_connect(ipaddr[i], ip2port(ipaddr[i],8000));
                    if (sock[i] < 0)
                    {
                        fprintf(stderr, "%s connect error\n", ipaddr[i]);
                    }
                }
            }
            tmp = 1 ;
        }
        event = 0;
        while(1)
        {
#if DEBUG
            printf(" main loop start func is %d \n",func);
#endif
            count = read(cam_fd, (unsigned char*)cam_data, image_size);
            if( count <0)
            {
                perror(" cam_data read err \n");
                exit(1);
            }

            offset = 0;
            for (i =0 ; i <camif_cfg.dst_y ; i++)
            {
                for(j = 0 ; j < camif_cfg.dst_x; j++)
                {
                    memcpy(&buf_pix,cam_data+offset, sizeof(unsigned short));
                    offset+= 2;
                    tmp_color = reveres_pixel(buf_pix);
                    buf_pixel(j,i,tmp_color);
                }
            }

            for (i=0; i<myicon_count; i++)
                draw_icon(&icon[i]);

            if(func == 1)
            {
                show_vfb(vfb_list[0]);//  demo ver need change 0 to  mylocation
            }
            else if (func == 2)
            {
                if (tmp ==0)
                    break;
                send_data(func);
                show_vfb(vfb_list[0]);//  demo ver need change 0 to  mylocation
            }

            else if (func == 3)
            {
                if (tmp ==0)
                    break;
                send_data(func);
                show_vfb(vfb_list[get_MyLocation()]);//  demo ver need change 0 to  mylocation

            }

            for (i=0; i<myicon_count; i++)
                draw_icon(&icon[i]);

            if (event == 9)
            {
                put_string_center(140, 100, " exit cam app ", white);
                sleep(2);
                goto end;

            }
            else if( event != 0 )
            {
                break;
            }

        }// end while "main lool"


        write(cam_fd,"X",2);	/* Stop Camera */
        if (cam_fd) close(cam_fd);


        for(i =0 ; i< VFB_MAX; i++)
        {
            if(sock[i])
                close(sock[i]);
        }


        //clear_all_screen();
    }

end:

    clear_screen();
    //	clear_all_screen();

    thread_res= pthread_join(ts_thread, &thread_result);
    for(i =0 ; i< VFB_MAX; i++)
    {
        if(sock[i])
            close(sock[i]);
    }

    if (cam_fd > 0)
    {
        write(cam_fd,"X",2);
        close(cam_fd);
    }

    if (cam_data >0)
        free(cam_data);

    myfb_close();
    free_vfb_buf(VFB_MAX);
    return 0;

}
示例#4
0
int main(void)
{
  int i_counter = 160;	
	
	SystemInit();
	
	SSD1963_Init();

	SSD1963_Clear(Red);
	Delay(100);
	SSD1963_Clear(Blue);
	Delay(100);
	SSD1963_Clear(Red);
	SSD1963_Fill(0, 0, 50, 50, Blue);
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);
	GUI_Init();
	GUI_SetColor(GUI_RED);
	GUI_Clear();
	
	BSP_KeyInit( BSP_KEY1, BSP_KEY1_GPIO_PORT );

	BSP_USART_Init( );
	
	BSP_SPI_Init( );
	BSP_SPI_CS_Init( );
	
	//Debug_ShowRegister( GPIOA_BASE, (DebugPeripheralTypedef *)&DeBugGPIO );
	//Debug_ShowRegister( BSP_USARTx_BASE, (DebugPeripheralTypedef *)&DeBugUART );
	//Debug_ShowRegister( RCC_BASE, (DebugPeripheralTypedef *)&DeBugRCC );
	//Debug_ShowSpecificRegister( RCC_BASE, (DebugPeripheralTypedef *)&DeBugRCC, "APB2ENR" );
	
  /* 初始化LWIP协议栈*/
	LwIP_Init(); 

	/* 初始化web server 显示网页程序 */
	//httpd_init();
  
  /* 初始化telnet 远程控制程序 */   
  //CMD_init();                                       

  /* 初始化web celient远程控制程序 */  
  //tcp_client_connect();
	tcp_client_connect();
	
  /* Infinite loop */
  while ( 1 )
	{	
		static int i = 0;
		/*轮询*/ 
		if(i >= 150)
		{
			i = 0;
			i_counter ++;
			if(Updateflag == 1)
			{
				tcp_client_connect();	
			}
			printf("*******************  tcp_client_connect *************************\r\n");
		}			
		
		LwIP_Periodic_Handle(LocalTime);

		if(i_counter> 1000)
			i_counter = 101;
		
		wendu[0] = i_counter/100%10 + 0x30;
		wendu[1] = i_counter/10%10 + 0x30;
		wendu[3] = i_counter%10 + 0x30;
	
		printf(wendu);
		
		printf("      i = %d\r\n",i);
		
		i++;
		
		Delay(10);
  }

}
示例#5
0
文件: my_test.c 项目: EX311/moira
int main(int argc , char**argv)
{


	struct color color;

	int i, j;
	//char* fb_list[ VFB_MAX];

	int x,y;

	int master;

	ip_list[0] = "192.168.77.30";
	ip_list[1] = "192.168.77.55";

	int debug_send_data_size =0;
#if DEBUG
	int test_count =0 ;
#endif


	master = atoi(argv[1]);
	myfb = myfb_open();
	

	// is master ? yse -> client , no ->server
	
	//if (master == mylocation)
	if (master == 1)
	{
			
		if(argc !=5)
		{
			perror("useing filename (int)arg [master is 1, slaver 2");
			exit(1);
		}	
	
		set_vfb_buf(4);
		bh = bmp_open(argv[2]);
		buf_bmp(bh,atoi(argv[3]),atoi(argv[4]));

		

		client_sock = tcp_client_connect( ip_list[1], "8000") ;
/*		
	// show my location data [pixel]
		x= 150;
		y= 30;
	
	//	for ( x = 150; x < 200; x++)
		{
			printf(" test for loop 1 x= %d\n",x);
			for( i =0 ; i<50; i++)
			{

				for(j=0; j <400 ; j++)
					buf_pixel(vfb_list[0],j+x,i+y,color);
			}

			//show_vfb(vfb_list[mylocation]);
*/
			show_vfb(vfb_list[0]);  // my fb data show
			debug_send_data_size = send_data(vfb_list[1]);
			#if DEBUG
				printf("send_data() call %d , send data size is %d\n",test_count,debug_send_data_size);
				test_count++;
			#endif

	}

	

	else
	{
			do_server();
	}
	
	
	
	
/*
	drow_rect(10,10,150,60,color);
	drow_line(150,150, 300,200,color);

	color.r = 255 ;
	color.g = 0;
	color.b = 0 ;

	//fb_list = set_vfb_buf(2);
	set_vfb_buf(2);

	x= 10;
	y= 30;
	
	for (; x<200; x++)
	{

		for( i =0 ; i<50; i++)
		{
			for(j=0; j <200 ; j++)
				buf_pixel(vfb_list[0],j+x,i+y,color);
		}

		show_vfb(vfb_list[0]);
	}


	
	printf("x-resolution : %d\n", myfb->fbvar.xres);
	printf("y-resolution : %d\n", myfb->fbvar.yres);
	printf("x-resolution(virtual) : %d\n", myfb->fbvar.xres_virtual);
	printf("y-resolution(virtual) : %d\n", myfb->fbvar.yres_virtual);
	printf("bpp : %d\n", myfb->fbvar.bits_per_pixel);
	printf("smem_len: %d\n", myfb->fbfix.smem_len);
*/
	return 0; 
}