Example #1
0
int do_simple_list(char* directory, int sockfd)
{
	DIR* dirp;
	struct dirent* entry;
	char line_buffer[256], line_length;

	dirp = opendir(directory);
	if (dirp == NULL)
	{
		line_length = rt_sprintf(line_buffer, "500 Internal Error\r\n");
		send(sockfd, line_buffer, line_length, 0);
		return -1;
	}

	while (1)
	{
		entry = readdir(dirp);
		if (entry == NULL) break;

		line_length = rt_sprintf(line_buffer, "%s\r\n", entry->d_name);
		send(sockfd, line_buffer, line_length, 0);
	}

	closedir(dirp);
	return 0;
}
Example #2
0
void dfs_get_fullpath(char *fullpath, const char *path, const char *file)
{
	if(path[strlen(path) - 1] != '/')
		rt_sprintf(fullpath, "%s%c%s", path, '/', file);
	else
		rt_sprintf(fullpath, "%s%s", path, file);
}
Example #3
0
void tetris_refreshmap(struct rtgui_dc *dc)                               //刷新地图
{
    rt_uint8_t i, j;
    rt_uint8_t buf[5];
    rtgui_rect_t rect = {XOFFSET, YOFFSET, XOFFSET + 240, YOFFSET + 400};
    RTGUI_DC_FC(dc) = RTGUI_RGB(0x55, 0x55, 0x55);
    rtgui_dc_fill_rect_forecolor(dc, &rect);
    rect.x1 -= 10;
    rect.x2 += 150;
    rect.y1 -= 10;
    rect.y2 += 10;
    RTGUI_DC_FC(dc) = RTGUI_RGB(0x00, 0x00, 0xff);
    rtgui_dc_draw_rect(dc, &rect);
    rect.x1 += 290;
    rect.x2 -= 30;
    rect.y1 += 40;
    rect.y2 -= 360;
    RTGUI_DC_FC(dc) = RTGUI_RGB(0x00, 0x00, 0x00);
    rtgui_dc_draw_text(dc, "下一个", &rect);
    rect.y1 += 130;
    rect.y2 += 130;
    rtgui_dc_draw_text(dc, "总得分", &rect);
    rect.y1 += 80;
    rect.y2 += 80;
    rtgui_dc_draw_text(dc, "LEVEL", &rect);
    RTGUI_DC_FC(dc) = RTGUI_RGB(0xff, 0x00, 0x00);
    rect.x1 += 20;
    rect.x2 += 20;
    rect.y1 -= 60;
    rect.y2 -= 60;
    rt_sprintf(buf, "%d", score);
    rtgui_dc_fill_rect(dc, &rect);
    rtgui_dc_draw_text(dc, buf, &rect);
    rect.y1 += 80;
    rect.y2 += 80;
    rt_sprintf(buf, "%d", level);
    rtgui_dc_fill_rect(dc, &rect);
    rtgui_dc_draw_text(dc, buf, &rect);


    for (i = 0; i < 25; i++)
    {
        for (j = 0; j < 15; j++)
        {
            if (tetris_map[j][i] != 0)
            {
                tetris_drawbox(dc, j, i, tetris_colors[tetris_map[j][i]]);
            }
        }
    }
}
Example #4
0
int do_list(char* directory, int sockfd)
{
	DIR* dirp;
	struct dirent* entry;
	char line_buffer[256], line_length;
#ifdef _WIN32
	struct _stat s;
#else
	struct stat s;
#endif

	dirp = opendir(directory);
	if (dirp == NULL)
	{
		line_length = rt_sprintf(line_buffer, "500 Internal Error\r\n");
		send(sockfd, line_buffer, line_length, 0);
		return -1;
	}

	while (1)
	{
		entry = readdir(dirp);
		if (entry == NULL) break;

		rt_sprintf(line_buffer, "%s/%s", directory, entry->d_name);
#ifdef _WIN32
		if (_stat(line_buffer, &s) ==0)
#else
		if (stat(line_buffer, &s) == 0)
#endif
		{
			if (s.st_mode & S_IFDIR)
				line_length = rt_sprintf(line_buffer, "drw-r--r-- 1 admin admin %d Jan 1 2000 %s\r\n", 0, entry->d_name);
			else
				line_length = rt_sprintf(line_buffer, "-rw-r--r-- 1 admin admin %d Jan 1 2000 %s\r\n", s.st_size, entry->d_name);

			send(sockfd, line_buffer, line_length, 0);
		}
		else
		{
			rt_kprintf("Get directory entry error\n");
			break;
		}
	}

	closedir(dirp);
	return 0;
}
Example #5
0
/* 触发自动窗口显示 */
static void demo_autowin_onbutton(struct rtgui_object *object, rtgui_event_t *event)
{
    struct rtgui_rect rect = {50, 50, 200, 200};

    /* don't create the window twice */
    if (autowin)
        return;

    autowin = rtgui_win_create(main_win, "Information",
                              &rect, RTGUI_WIN_STYLE_DEFAULT | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
    if (autowin == RT_NULL)
        return;

    cnt = 5;
    rt_sprintf(label_text, "closed then %d second!", cnt);
    label = rtgui_label_create(label_text);
    rect.x1 += 5;
    rect.x2 -= 5;
    rect.y1 += 5;
    rect.y2 = rect.y1 + 20;
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    rtgui_container_add_child(RTGUI_CONTAINER(autowin),
                              RTGUI_WIDGET(label));

    /* 设置关闭窗口时的动作 */
    rtgui_win_set_onclose(autowin, auto_window_close);

    rtgui_win_show(autowin, RT_FALSE);
    /* 创建一个定时器 */
    timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
    rtgui_timer_start(timer);
}
Example #6
0
void list_dir(const char* path)
{
	DIR *dir;

	dir = opendir(path);
	if (dir != RT_NULL)
	{
		struct dirent* dirent;
		struct stat s;

		do
		{
			dirent = readdir(dir);
			if (dirent == RT_NULL) break;
			rt_memset(&s, 0, sizeof(struct stat));

			/* build full path for each file */
			rt_sprintf(fullpath, "/%s", dirent->d_name);

			stat(fullpath, &s);
			if ( s.st_mode & DFS_S_IFDIR )
			{
				rt_kprintf("%s\t\t<DIR>\n", dirent->d_name);
			}
			else
			{
				rt_kprintf("%s\t\t%lu\n", dirent->d_name, s.st_size);
			}
		} while (dirent != RT_NULL);

		closedir(dir);
	}
	else rt_kprintf("open %s directory failed\n", path);
}
Example #7
0
/* 触发自动窗口显示 */
static void demo_autowin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
{
	rtgui_toplevel_t *parent;
	struct rtgui_rect rect ={50, 50, 200, 200};

	parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));
	msgbox = rtgui_win_create(parent, "Information", &rect, RTGUI_WIN_STYLE_DEFAULT);
	if (msgbox != RT_NULL)
	{
		cnt = 5;
		rt_sprintf(label_text, "closed then %d second!", cnt);
		label = rtgui_label_create(label_text);
		rect.x1 += 5;
		rect.x2 -= 5;
		rect.y1 += 5;
		rect.y2 = rect.y1 + 20;
		rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
		rtgui_container_add_child(RTGUI_CONTAINER(msgbox), RTGUI_WIDGET(label));

		rtgui_win_show(msgbox, RT_FALSE);
	}

	/* 创建一个定时器 */
	timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
	rtgui_timer_start(timer);
}
Example #8
0
static void scan_app_dir(const char* path)
{
    DIR* dir;
    struct dirent* entry;
    char fn[32];

    dir = opendir(path);
    if (dir == RT_NULL)
    {
        rt_kprintf("open directory %s failed\n", path);
        return;
    }

    do
    {
        entry = readdir(dir);
        if (entry != RT_NULL)
        {
            if(entry->d_type == DFS_DT_REG) break;
            rt_sprintf(fn, "%s/%s/%s.xml", path, entry->d_name, entry->d_name);
            xml_load_items(fn);
        }
    } while(entry != RT_NULL);

    /* close directory */
    closedir(dir);
}
Example #9
0
/* 列表项的动作函数 */
static void listitem_action(rtgui_widget_t *widget, void *parameter)
{
    char label_text[32];
    rtgui_win_t *win;
    rtgui_label_t *label;
    rtgui_rect_t rect = {0, 0, 150, 80};
    int no = (int)parameter;

    rtgui_rect_moveto(&rect, 20, 50);

    /* 显示消息窗口 */
    win = rtgui_win_create(main_win,
                           "窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);

    rect.x1 += 20;
    rect.x2 -= 5;
    rect.y1 += 5;
    rect.y2 = rect.y1 + 20;

    /* 添加相应的标签 */
    rt_sprintf(label_text, "动作 %d", no);
    label = rtgui_label_create(label_text);

    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    rtgui_container_add_child(win, RTGUI_WIDGET(label));

    /* 非模态显示窗口 */
    rtgui_win_show(win, RT_FALSE);
}
Example #10
0
long version(void)
{
	struct m3_sys_info_st sys_info;
	//char datestr[12];
	char datestr_1[12];
	int i;
	
	//rt_show_version();
	read_syscfgdata_tbl(SYSCFGDATA_TBL_SYS_INFO, 0, &sys_info);
	
	printf_syn("HW ver:%d.%d.%d\n", M3_HW_VERSION, M3_HW_SUBVERSION, M3_HW_REVISION);
	printf_syn("OS ver:%d.%d.%d\n", RT_VERSION, RT_SUBVERSION, RT_REVISION);
	printf_syn("DB ver:%d.%d.%d\n", (sys_info.db_ver>>16)&0xff, (sys_info.db_ver>>8)&0xff, (sys_info.db_ver)&0xff);
	printf_syn("App ver:%d.%d.%d build %s %s\n", RT_APP_VERSION, RT_APP_SUBVERSION, RT_APP_REVISION,
			__DATE__, __TIME__);

	/* Aug 22 2012 */
	rt_strncpy(datestr_1, __DATE__, sizeof(datestr_1));
	datestr_1[3] = '\0';
	if (' '==datestr_1[4])
		datestr_1[4] = '0';
	datestr_1[6] = '\0';
	//datestr_1[11] = '\0';
	
	for (i=0; i<12; ++i)
		if (0==rt_strncmp(months_str[i], datestr_1, 3))
			break;

	rt_sprintf(datestr_1, "%02d", i+1);
	printf_syn("Standard ver:SCC_%d.%d.%d.%s%s%s_%s_%d\n", (sys_info.sw_ver>>16)&0xff, (sys_info.sw_ver>>8)&0xff, (sys_info.sw_ver)&0xff,
			&datestr_1[7], &datestr_1[0], &datestr_1[4], RT_APP_VER_TYPE, RT_APP_MODIFY_VERSION);

	return 0;
}
Example #11
0
/* 获取一个递增的窗口标题 */
static char *get_win_title()
{
    static rt_uint8_t win_no = 0;
    static char win_title[16];

    rt_sprintf(win_title, "窗口 %d", ++win_no);
    return win_title;
}
Example #12
0
void do_modules(const char *path)
{
	char *fn;
	DIR  *dir;

	fn = rt_malloc(FILENAME_MAX);
	if (fn == RT_NULL)
	{
		rt_kprintf("out of memory\n");
		return;
	}

	dir = opendir(path);
	if (dir != RT_NULL)
	{
		struct dirent* dirent;
		struct stat s;

		do
		{
			dirent = readdir(dir);
			if (dirent == RT_NULL) break;
			rt_memset(&s, 0, sizeof(struct stat));

			/* build full path for each file */
			if (path[strlen(path) - 1] != '/')
				rt_sprintf(fn, "%s/%s", path, dirent->d_name);
			else
				rt_sprintf(fn, "%s%s", path, dirent->d_name);

			if (strstr(fn, ".mo") != RT_NULL)
			{
				/* execute this module */
				rt_module_open(fn);
			}
		} while (dirent != RT_NULL);

		closedir(dir);
	}
	else rt_kprintf("open %s directory failed\n", path);

	rt_free(fn);
}
Example #13
0
int build_full_path(struct ftp_session* session, char* path, char* new_path, size_t size)
{
	if (is_absolute_path(path) == RT_TRUE)
		strcpy(new_path, path);
	else {
		rt_sprintf(new_path, "%s/%s", session->currentdir, path);
	}

	return 0;
}
/* send files */
static rt_err_t zsend_files(struct zfile *zf)
{
	char *p,*q;
	char *str = "/";
	struct stat finfo;
	rt_err_t res = -RT_ERROR;

	if (zf->fname == RT_NULL)
	{
	    rt_kprintf("\r\nerror: no file to be send.\r\n");
		return res;
	}
	if ((zf->fd=open(zf->fname, DFS_O_RDONLY,0)) <0)
	{
	    rt_kprintf("\r\ncan not open file:%s\r\n",zf->fname+1);
	    return res;
	}

	zf->file_end = 0;
	++file_cnt;	 
	/* extract file name */
	p = zf->fname;
	for (;;)
	{
		q = strstr(p,str);
		if (q == RT_NULL)  break;
		p = q+1;
	}	
	q = (char*)TX_BUFFER;	  
	for (;;)
	{
	    *q++ = *p++;
		if (*p == 0) break;
	}
	*q++ = 0;
	p=q;
	while (q < (char*)(TX_BUFFER + 1024))
		*q++ = 0;
	/* get file attributes */
	fstat(zf->fd,&finfo);
	Left_sizes += finfo.st_size;			                
	rt_sprintf(p, "%lu %lo %o 3 %d %ld", (long)finfo.st_size, finfo.st_mtime,
			  finfo.st_mode, file_cnt, Left_sizes);
	Left_sizes -= finfo.st_size;
	TX_BUFFER[127] = (finfo.st_size + 127) >>7;
	TX_BUFFER[126] = (finfo.st_size + 127) >>15;

	zsend_init();
	/* start sending files */							
	res = zsend_file(zf,TX_BUFFER, (p-(char*)TX_BUFFER)+strlen(p)+1);
	zsay_bibi();
	close(zf->fd);
 
	return res;
}
Example #15
0
/* 触发正常窗口显示 */
static void demo_normal_window_onbutton(struct rtgui_object *object, rtgui_event_t *event)
{
    rt_sprintf(normal_window_label_text,
               "第 %d 次显示", normal_window_show_count);
    rtgui_label_set_text(normal_window_label,
                         normal_window_label_text);
    if (RTGUI_WIDGET_IS_HIDE(normal_window))
        rtgui_win_show(normal_window, RT_FALSE);
    else
        rtgui_win_activate(normal_window);
}
Example #16
0
int get_sys_time4label(char *timestr)
{
	time_t time;
	struct tm *ptime;

	if (NULL == rtc_dev)
		return FAIL;

	rt_device_control(rtc_dev, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
	ptime = localtime(&time);
	rt_sprintf(timestr, "%4d-%02d-%02d %02d:%02d:%02d", (ptime->tm_year+1900), (ptime->tm_mon+1),
			   ptime->tm_mday,	ptime->tm_hour, ptime->tm_min, ptime->tm_sec);

	return SUCC;
}
Example #17
0
/* 关闭对话框时的回调函数 */
void diag_close(struct rtgui_timer *timer, void *parameter)
{
    cnt --;
    rt_sprintf(label_text, "closed then %d second!", cnt);

    /* 设置标签文本并更新控件 */
    rtgui_label_set_text(label, label_text);
    rtgui_widget_update(RTGUI_WIDGET(label));

    if (cnt == 0)
    {
        /* 超时,关闭对话框 */
        rtgui_win_destroy(autowin);
    }
}
Example #18
0
/*
 * yyyymmdd.hhmm
 *
 * !!NOTE:len(str) >= 14
 */
int get_timestr(rt_uint32_t time, char *str, int len)
{
	struct tm *ptime;

	if (len < 14)
		return FAIL;

	if (0 != time) {
		ptime = localtime(&time);
		rt_sprintf(str, "%4d%02d%02d.%02d%02d", (ptime->tm_year+1900), (ptime->tm_mon+1),
				   ptime->tm_mday,	ptime->tm_hour, ptime->tm_min);
	} else {
		rt_strncpy(str, NO_POWEROFF_TIME, len);
	}

	return SUCC;
}
Example #19
0
static void json_rpc_handle(const char* json, size_t length)
{
	int status = 0;
	struct json_tree* tree = RT_NULL;

	tree = json_tree_parse(json, length);
	if (tree != RT_NULL)
	{
		const char *version;
		const char *method;
		struct json_node *params;
		int id, index, position;

		char cmd[64];

		/* check parameter */
		version = json_tree_get_string(tree, "jsonrpc", RT_NULL);
		method  = json_tree_get_string(tree, "method", RT_NULL);
		id      = json_tree_get_integer(tree, "id", RT_NULL);
		params  = json_tree_get_node(tree, "params", RT_NULL);

		/* parameter check */
		if (strcmp(version, "2.0") != 0) goto __exit;

		position = 0;
		position += rt_sprintf(&cmd[position], "%s(", method);
		for (index = 0; index < params->count; index ++)
		{
			struct json_node *node;

			node = params->vu.array[index];
			
			if (index != 0) 
				position += rt_sprintf(&cmd[position], ",");

			if (node->type == JSON_NODE_TYPE_STR)
				position += rt_sprintf(&cmd[position], "\"%s\"", node->vu.str_value);
			if (node->type == JSON_NODE_TYPE_INT)
				position += rt_sprintf(&cmd[position], "%d", node->vu.int_value);
			if (node->type == JSON_NODE_TYPE_FLOAT)
				position += rt_sprintf(&cmd[position], "%f", node->vu.float_value);
		}
		position += rt_sprintf(&cmd[position], ")");

		rt_kprintf("cmd: %s\n", cmd);
	}

__exit:
	if (tree != RT_NULL) json_tree_destroy(tree);
	return;
}
Example #20
0
/*GPRS发送数据流程*/
rt_bool_t gprssend(char* str)
{
  char strtemp[50] = {0x00};  
  int len;
  
  rt_kprintf("\r\n Send data! Display information from module:\r\n");
  len = rt_strlen(str);
  rt_sprintf(strtemp,"AT^SISW=0,%d\x00D\x00A",len);
  if(gprs_send_data_package(strtemp,"SISW",2,1))
  {
  }
  else
    return RT_FALSE; 

  if(gprs_send_data_package(str,"OK",2,1))
  {
    rt_kprintf("\r\n Send data OK !\r\n");
  }
  else
    return RT_FALSE; 
  
  return RT_TRUE;
}
Example #21
0
static void create_normal_win(void)
{
    rtgui_rect_t rect = {30, 40, 150, 80};

    normal_window = rtgui_win_create(RT_NULL, "普通窗口",
                                     &rect, RTGUI_WIN_STYLE_DEFAULT);

    rect.x1 += 20;
    rect.x2 -= 5;
    rect.y1 += 5;
    rect.y2 = rect.y1 + 20;

    /* 添加一个文本标签 */
    rt_sprintf(normal_window_label_text,
               "第 %d 次显示", normal_window_show_count);
    normal_window_label = rtgui_label_create(normal_window_label_text);
    rtgui_widget_set_rect(RTGUI_WIDGET(normal_window_label), &rect);
    rtgui_container_add_child(RTGUI_CONTAINER(normal_window),
                              RTGUI_WIDGET(normal_window_label));

    rtgui_win_set_onclose(normal_window,
                          normal_window_onclose);
}
Example #22
0
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) 
            return RT_FALSE;
		rtgui_widget_get_rect(widget, &rect);

		rtgui_dc_fill_rect(dc, &rect);
		rect.x2 -= 1; rect.y2 -= 1;
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
		rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);

		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2);
		rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2 + 1);
        
        /* shrink border */
		rtgui_rect_inflate(&rect, -1);
        
		/* draw text */
        rtgui_widget_get_rect(widget, &rect);
        rect.y1 += 25;        
        rtgui_dc_draw_text(dc, "  FM3 Easy Kit Demo", &rect);
        rect.y1 += 10;
        rtgui_dc_draw_text(dc, "  rt-thread / RTGUI", &rect);
		rtgui_dc_end_drawing(dc);

		return RT_FALSE;
	}
    else if (event->type == RTGUI_EVENT_KBD)
    {
        struct rtgui_dc* dc;
        struct rtgui_rect rect;
        struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
        if (ekbd->type == RTGUI_KEYDOWN)
        {
            char key_str[16];
            switch (ekbd->key)
            {
                case RTGUIK_LEFT:
                rt_sprintf(key_str, "%s", "L");
                break;
                case RTGUIK_RIGHT:
                rt_sprintf(key_str, "%s", "R");
                break;
                case RTGUIK_DOWN:
                rt_sprintf(key_str, "%s", "D");
                break;
                case RTGUIK_UP:
                rt_sprintf(key_str, "%s", "U");
                break;                
                default:
                rt_sprintf(key_str, "%s", "S");
                break;
            }
            dc = rtgui_dc_begin_drawing(widget);
            if (dc == RT_NULL) 
                return RT_FALSE;
            rect.x1 = 118;
            rect.y1 = 1;  
            rect.x2 = 127;
            rect.y2 = 10;       
            rtgui_dc_fill_rect(dc, &rect);
            rtgui_dc_draw_text(dc, key_str, &rect);
            rtgui_dc_end_drawing(dc);
        }
        else if (ekbd->type == RTGUI_KEYUP)
        {
            dc = rtgui_dc_begin_drawing(widget);
            if (dc == RT_NULL) 
                return RT_FALSE;
            rect.x1 = 118;
            rect.y1 = 1;  
            rect.x2 = 127;
            rect.y2 = 10;       
            rtgui_dc_fill_rect(dc, &rect);
            //rtgui_dc_draw_text(dc, key_str, &rect);
            rtgui_dc_end_drawing(dc);
        }
    }
    else if (event->type == RTGUI_EVENT_COMMAND)
    {
        char str[16];
        struct rtgui_dc* dc;
        struct rtgui_rect rect;
        struct rtgui_event_command* ecmd;
        rt_uint8_t major,minor;
        dc = rtgui_dc_begin_drawing(widget);
        if (dc == RT_NULL) 
            return RT_FALSE;
            
        ecmd = (struct rtgui_event_command*)event;
        switch (ecmd->command_id)
        {   
            case ADC_UPDATE:
                rect.x1 = 1;
                rect.y1 = 1;  
                rect.x2 = 117;
                rect.y2 = 10;       
                rtgui_dc_fill_rect(dc, &rect);     
			    rt_sprintf(str, "ADC = %d mv", adc_value);
			    rtgui_dc_draw_text(dc, str, &rect);	
            break;
            case CPU_UPDATE:
                cpu_usage_get(&major, &minor);
                rect.x1 = 1;
                rect.y1 = 12;  
                rect.x2 = 127;
                rect.y2 = 22;       
                rtgui_dc_fill_rect(dc, &rect);     
			    rt_sprintf(str, "CPU : %d.%d%", major, minor);
			    rtgui_dc_draw_text(dc, str, &rect);

                rect.y1 = 23;  
                rect.y2 = 63;                 
                index++;
                if (index == 127)
                {    
                    index = 1;
                    rtgui_dc_fill_rect(dc, &rect);     
                }
                if (major>40)
                    rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
                else
                    rtgui_dc_draw_vline(dc, index, rect.y2-major, rect.y2);
                break;
        }
        rtgui_dc_end_drawing(dc); 
    }

	return rtgui_view_event_handler(widget, event);
}
Example #23
0
void tcpserver6(void)
{
	int sockfd, clientfd;
	struct sockaddr_in6 server_addr6, client_addr6;
	int bytes_received;
	char *recv_data;
	UInt32 sin_size;
	rt_bool_t stop = RT_FALSE;

	recv_data = malloc(BUF_SIZE);
	if(recv_data == NULL)
	{
		printf("No memory\n");
		return ;
	}

	if((sockfd = socket(PF_INET6, SOCK_STREAM, 0)) == -1)
	{
		printf("Socket error\n");
		rt_free(recv_data);
		return ;
	}

	server_addr6.sin6_family = AF_INET6;
	memcpy(server_addr6.sin6_addr.s6_addr, IP6_ADDR_ANY, 16);
	server_addr6.sin6_port = htons(SERV_PORT);

	if(bind(sockfd, (struct sockaddr *)&server_addr6, sizeof(struct sockaddr)) == -1)
	{
		printf("Bind error\n");
		rt_free(recv_data);
		return ;
	}
	if(listen(sockfd, BACKLOG) == -1)
	{
		printf("Listen error\n");
		rt_free(recv_data);
		return ;
	}

	rt_sprintf(recv_data, "%4d", SERV_PORT);
	printf("\nTCPServer Waiting for client on port %s...\n", recv_data);

	while(stop != RT_TRUE)
	{
		sin_size = sizeof(struct sockaddr_in6);
		clientfd = accept(sockfd, (struct sockaddr *)&client_addr6, &sin_size);
		printf("I got a connection from (IP:%s, PORT:%d\n)", inet6_ntoa(client_addr6.sin6_addr), ntohs(client_addr6.sin6_port));
		while(1)
		{
			send(clientfd, send_data, strlen(send_data), 0);

			bytes_received = recv(clientfd, recv_data, BUF_SIZE, 0);
			if(bytes_received <= 0)
			{
				closesocket(clientfd);
				break;
			}
			recv_data[bytes_received] = '\0';
			if(strcmp(recv_data, "q") == 0 || strcmp(recv_data, "Q") == 0)
			{
				closesocket(clientfd);
				break;
			}
			else if(strcmp(recv_data, "exit") == 0)
			{
				closesocket(clientfd);
				stop = RT_TRUE;
				break;
			}
			else
			{
				printf("RECEIVED DATA = %s\n", recv_data);
			}
		}
	}

	closesocket(sockfd);
	rt_free(recv_data);

	return ;
}
Example #24
0
int ftp_process_request(struct ftp_session* session, char *buf)
{
	int  fd;
	struct timeval tv;
	fd_set readfds;
	char filename[256];
	int  numbytes;
	char *sbuf;
	char *parameter_ptr, *ptr;
	rt_uint32_t addr_len = sizeof(struct sockaddr_in);
	struct sockaddr_in local, pasvremote;

	sbuf =(char *)rt_malloc(FTP_BUFFER_SIZE);

	tv.tv_sec=3, tv.tv_usec=0;
	local.sin_family=PF_INET;
	local.sin_addr.s_addr=INADDR_ANY;

	/* remove \r\n */
	ptr = buf;
	while (*ptr) {
		if (*ptr == '\r' || *ptr == '\n') *ptr = 0;
		ptr ++;
	}

	/* get request parameter */
	parameter_ptr = strchr(buf, ' ');
	if (parameter_ptr != NULL) parameter_ptr ++;

	// debug:
	rt_kprintf("%s requested: \"%s\"\n", inet_ntoa(session->remote.sin_addr), buf);

	//
	//-----------------------
	if(str_begin_with(buf, "USER")==0) {
		rt_kprintf("%s sent login \"%s\"\n", inet_ntoa(session->remote.sin_addr), parameter_ptr);
		// login correct
		if(strcmp(parameter_ptr, "anonymous") == 0) {
			session->is_anonymous = RT_TRUE;
			rt_sprintf(sbuf, "331 Anonymous login OK send e-mail address for password.\r\n", parameter_ptr);
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		} else if (strcmp(parameter_ptr, FTP_USER) == 0) {
			session->is_anonymous = RT_FALSE;
			rt_sprintf(sbuf, "331 Password required for %s\r\n", parameter_ptr);
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		} else {
			// incorrect login
			rt_sprintf(sbuf, "530 Login incorrect. Bye.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			rt_free(sbuf);
			return -1;
		}
		return 0;
	} else if(str_begin_with(buf, "PASS")==0) {
		rt_kprintf("%s sent password \"%s\"\n", inet_ntoa(session->remote.sin_addr), parameter_ptr);
		if (strcmp(parameter_ptr, FTP_PASSWORD)==0 ||
			session->is_anonymous == RT_TRUE) {
			// password correct
			rt_sprintf(sbuf, "230 User logged in\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			rt_free(sbuf);
			return 0;
		}

		// incorrect password
		rt_sprintf(sbuf, "530 Login or Password incorrect. Bye!\r\n");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
		rt_free(sbuf);
		return -1;
	} else if(str_begin_with(buf, "LIST")==0  ) {
		memset(sbuf,0,FTP_BUFFER_SIZE);
		rt_sprintf(sbuf, "150 Opening Binary mode connection for file list.\r\n");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
		do_list(session->currentdir, session->pasv_sockfd);
		closesocket(session->pasv_sockfd);
		session->pasv_active = 0;
		rt_sprintf(sbuf, "226 Transfert Complete.\r\n");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
	} else if(str_begin_with(buf, "NLST")==0 ) {
		memset(sbuf, 0, FTP_BUFFER_SIZE);
		rt_sprintf(sbuf, "150 Opening Binary mode connection for file list.\r\n");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
		do_simple_list(session->currentdir, session->pasv_sockfd);
		closesocket(session->pasv_sockfd);
		session->pasv_active = 0;
		rt_sprintf(sbuf, "226 Transfert Complete.\r\n");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
	} else if(str_begin_with(buf, "PWD")==0 || str_begin_with(buf, "XPWD")==0) {
		rt_sprintf(sbuf, "257 \"%s\" is current directory.\r\n", session->currentdir);
		send(session->sockfd, sbuf, strlen(sbuf), 0);
	} else if(str_begin_with(buf, "TYPE")==0) {
		// Ignore it
		if(strcmp(parameter_ptr, "I")==0) {
			rt_sprintf(sbuf, "200 Type set to binary.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		} else {
			rt_sprintf(sbuf, "200 Type set to ascii.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		}
	} else if(str_begin_with(buf, "PASV")==0) {
		int dig1, dig2;
		int sockfd;
		char optval='1';

		session->pasv_port = 10000;
		session->pasv_active = 1;
		local.sin_port=htons(session->pasv_port);
		local.sin_addr.s_addr=INADDR_ANY;

		dig1 = (int)(session->pasv_port/256);
		dig2 = session->pasv_port % 256;

		FD_ZERO(&readfds);
		if((sockfd=socket(PF_INET, SOCK_STREAM, 0))==-1) {
			rt_sprintf(sbuf, "425 Can't open data connection.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			goto err1;
		}
		if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))==-1) {
			rt_sprintf(sbuf, "425 Can't open data connection.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			goto err1;
		}
		if(bind(sockfd, (struct sockaddr *)&local, addr_len)==-1) {
			rt_sprintf(sbuf, "425 Can't open data connection.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			goto err1;
		}
		if(listen(sockfd, 1)==-1) {
			rt_sprintf(sbuf, "425 Can't open data connection.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			goto err1;
		}
		rt_kprintf("Listening %d seconds @ port %d\n", tv.tv_sec, session->pasv_port);
		rt_sprintf(sbuf, "227 Entering passive mode (%d,%d,%d,%d,%d,%d)\r\n", 127, 0, 0, 1, dig1, dig2);
		send(session->sockfd, sbuf, strlen(sbuf), 0);
		FD_SET(sockfd, &readfds);
		select(0, &readfds, 0, 0, &tv);
		if(FD_ISSET(sockfd, &readfds)) {
			if((session->pasv_sockfd = accept(sockfd, (struct sockaddr*)&pasvremote, &addr_len))==-1) {
				rt_sprintf(sbuf, "425 Can't open data connection.\r\n");
				send(session->sockfd, sbuf, strlen(sbuf), 0);
				goto err1;
			} else {
				rt_kprintf("Got Data(PASV) connection from %s\n", inet_ntoa(pasvremote.sin_addr));
				session->pasv_active = 1;
				closesocket(sockfd);
			}
		} else {
err1:
			closesocket(session->pasv_sockfd);
			session->pasv_active = 0;
			rt_free(sbuf);
			return 0;
		}
	} else if (str_begin_with(buf, "RETR")==0) {
		int file_size;

		strcpy(filename, buf + 5);

		build_full_path(session, parameter_ptr, filename, 256);
		file_size = ftp_get_filesize(filename);
		if (file_size == -1) {
			rt_sprintf(sbuf, "550 \"%s\" : not a regular file\r\n", filename);
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			session->offset=0;
			rt_free(sbuf);
			return 0;
		}

		fd = open(filename, O_RDONLY, 0);
		if (fd < 0) {
			rt_free(sbuf);
			return 0;
		}

		if(session->offset>0 && session->offset < file_size) {
			lseek(fd, session->offset, SEEK_SET);
			rt_sprintf(sbuf, "150 Opening binary mode data connection for partial \"%s\" (%d/%d bytes).\r\n",
					   filename, file_size - session->offset, file_size);
		} else {
			rt_sprintf(sbuf, "150 Opening binary mode data connection for \"%s\" (%d bytes).\r\n", filename, file_size);
		}
		send(session->sockfd, sbuf, strlen(sbuf), 0);
		while((numbytes = read(fd, sbuf, FTP_BUFFER_SIZE))>0) {
			send(session->pasv_sockfd, sbuf, numbytes, 0);
		}
		rt_sprintf(sbuf, "226 Finished.\r\n");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
		close(fd);
		closesocket(session->pasv_sockfd);
	} else if (str_begin_with(buf, "STOR")==0) {
		if(session->is_anonymous == RT_TRUE) {
			rt_sprintf(sbuf, "550 Permission denied.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			rt_free(sbuf);
			return 0;
		}

		build_full_path(session, parameter_ptr, filename, 256);

		fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0);
		if(fd < 0) {
			rt_sprintf(sbuf, "550 Cannot open \"%s\" for writing.\r\n", filename);
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			rt_free(sbuf);
			return 0;
		}
		rt_sprintf(sbuf, "150 Opening binary mode data connection for \"%s\".\r\n", filename);
		send(session->sockfd, sbuf, strlen(sbuf), 0);
		FD_ZERO(&readfds);
		FD_SET(session->pasv_sockfd, &readfds);
		rt_kprintf("Waiting %d seconds for data...\n", tv.tv_sec);
		while(select(session->pasv_sockfd+1, &readfds, 0, 0, &tv)>0 ) {
			if((numbytes=recv(session->pasv_sockfd, sbuf, FTP_BUFFER_SIZE, 0))>0) {
				write(fd, sbuf, numbytes);
			} else if(numbytes==0) {
				close(fd);
				closesocket(session->pasv_sockfd);
				rt_sprintf(sbuf, "226 Finished.\r\n");
				send(session->sockfd, sbuf, strlen(sbuf), 0);
				break;
			} else if(numbytes==-1) {
				close(fd);
				closesocket(session->pasv_sockfd);
				rt_free(sbuf);
				return -1;
			}
		}
		closesocket(session->pasv_sockfd);
	} else if(str_begin_with(buf, "SIZE")==0) {
		int file_size;

		build_full_path(session, parameter_ptr, filename, 256);

		file_size = ftp_get_filesize(filename);
		if( file_size == -1) {
			rt_sprintf(sbuf, "550 \"%s\" : not a regular file\r\n", filename);
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		} else {
			rt_sprintf(sbuf, "213 %d\r\n", file_size);
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		}
	} else if(str_begin_with(buf, "MDTM")==0) {
		rt_sprintf(sbuf, "550 \"/\" : not a regular file\r\n");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
	} else if(str_begin_with(buf, "SYST")==0) {
		rt_sprintf(sbuf, "215 %s\r\n", "RT-Thread RTOS");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
	} else if(str_begin_with(buf, "CWD")==0) {
		build_full_path(session, parameter_ptr, filename, 256);

		rt_sprintf(sbuf, "250 Changed to directory \"%s\"\r\n", filename);
		send(session->sockfd, sbuf, strlen(sbuf), 0);
		strcpy(session->currentdir, filename);
		rt_kprintf("Changed to directory %s", filename);
	} else if(str_begin_with(buf, "CDUP")==0) {
		rt_sprintf(filename, "%s/%s", session->currentdir, "..");

		rt_sprintf(sbuf, "250 Changed to directory \"%s\"\r\n", filename);
		send(session->sockfd, sbuf, strlen(sbuf), 0);
		strcpy(session->currentdir, filename);
		rt_kprintf("Changed to directory %s", filename);
	} else if(str_begin_with(buf, "PORT")==0) {
		int i;
		int portcom[6];
		char tmpip[100];

		i=0;
		portcom[i++]=atoi(strtok(parameter_ptr, ".,;()"));
		for(; i<6; i++)
			portcom[i]=atoi(strtok(0, ".,;()"));
		rt_sprintf(tmpip, "%d.%d.%d.%d", portcom[0], portcom[1], portcom[2], portcom[3]);

		FD_ZERO(&readfds);
		if((session->pasv_sockfd=socket(AF_INET, SOCK_STREAM, 0))==-1) {
			rt_sprintf(sbuf, "425 Can't open data connection.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			closesocket(session->pasv_sockfd);
			session->pasv_active = 0;
			rt_free(sbuf);
			return 0;
		}
		pasvremote.sin_addr.s_addr=inet_addr(tmpip);
		pasvremote.sin_port=htons(portcom[4] * 256 + portcom[5]);
		pasvremote.sin_family=PF_INET;
		if(connect(session->pasv_sockfd, (struct sockaddr *)&pasvremote, addr_len)==-1) {
			// is it only local address?try using gloal ip addr
			pasvremote.sin_addr=session->remote.sin_addr;
			if(connect(session->pasv_sockfd, (struct sockaddr *)&pasvremote, addr_len)==-1) {
				rt_sprintf(sbuf, "425 Can't open data connection.\r\n");
				send(session->sockfd, sbuf, strlen(sbuf), 0);
				closesocket(session->pasv_sockfd);
				rt_free(sbuf);
				return 0;
			}
		}
		session->pasv_active=1;
		session->pasv_port = portcom[4] * 256 + portcom[5];
		rt_kprintf("Connected to Data(PORT) %s @ %d\n", tmpip, portcom[4] * 256 + portcom[5]);
		rt_sprintf(sbuf, "200 Port Command Successful.\r\n");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
	} else if(str_begin_with(buf, "REST")==0) {
		if(atoi(parameter_ptr)>=0) {
			session->offset=atoi(parameter_ptr);
			rt_sprintf(sbuf, "350 Send RETR or STOR to start transfert.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		}
	} else if(str_begin_with(buf, "MKD")==0) {
		if (session->is_anonymous == RT_TRUE) {
			rt_sprintf(sbuf, "550 Permission denied.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			rt_free(sbuf);
			return 0;
		}

		build_full_path(session, parameter_ptr, filename, 256);

		if(mkdir(filename, 0) == -1) {
			rt_sprintf(sbuf, "550 File \"%s\" exists.\r\n", filename);
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		} else {
			rt_sprintf(sbuf, "257 directory \"%s\" successfully created.\r\n", filename);
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		}
	} else if(str_begin_with(buf, "DELE")==0) {
		if (session->is_anonymous == RT_TRUE) {
			rt_sprintf(sbuf, "550 Permission denied.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			rt_free(sbuf);
			return 0;
		}

		build_full_path(session, parameter_ptr, filename, 256);

		if(unlink(filename)==0)
			rt_sprintf(sbuf, "250 Successfully deleted file \"%s\".\r\n", filename);
		else {
			rt_sprintf(sbuf, "550 Not such file or directory: %s.\r\n", filename);
		}
		send(session->sockfd, sbuf, strlen(sbuf), 0);
	} else if(str_begin_with(buf, "RMD")==0) {
		if (session->is_anonymous == RT_TRUE) {
			rt_sprintf(sbuf, "550 Permission denied.\r\n");
			send(session->sockfd, sbuf, strlen(sbuf), 0);
			rt_free(sbuf);
			return 0;
		}
		build_full_path(session, parameter_ptr, filename, 256);

		if(unlink(filename) == -1) {
			rt_sprintf(sbuf, "550 Directory \"%s\" doesn't exist.\r\n", filename);
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		} else {
			rt_sprintf(sbuf, "257 directory \"%s\" successfully deleted.\r\n", filename);
			send(session->sockfd, sbuf, strlen(sbuf), 0);
		}
	}

	else if(str_begin_with(buf, "QUIT")==0) {
		rt_sprintf(sbuf, "221 Bye!\r\n");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
		rt_free(sbuf);
		return -1;
	} else {
		rt_sprintf(sbuf, "502 Not Implemented.\r\n");
		send(session->sockfd, sbuf, strlen(sbuf), 0);
	}
	rt_free(sbuf);
	return 0;
}
Example #25
0
/***************************************************************************//**
 * @brief
 *  Initialize the specified IIC unit
 *
 * @details
 *
 * @note
 *
 * @param[in] unitNumber
 *  Unit number
 *
 * @param[in] location
 *  Pin location number
 ******************************************************************************/
static struct efm32_iic_device_t *rt_hw_iic_unit_init(
    struct efm32_iic_block  *block,
    rt_uint8_t              unitNumber,
    rt_uint8_t              location)
{
    struct efm32_iic_device_t   *iic;
    CMU_Clock_TypeDef           iicClock;
    GPIO_Port_TypeDef           port_scl, port_sda;
    rt_uint32_t                 pin_scl, pin_sda;
    I2C_Init_TypeDef            init = I2C_INIT_DEFAULT;
    efm32_irq_hook_init_t       hook;
    rt_uint8_t                  name[RT_NAME_MAX];

    do
    {
        /* Allocate device */
        iic = rt_malloc(sizeof(struct efm32_iic_device_t));
        if (iic == RT_NULL)
        {
            iic_debug("IIC err: no MEM for IIC%d driver\n", unitNumber);
            break;
        }
        iic->counter        = 0;
        iic->timer          = &block->timer;
        iic->timeout        = false;
        iic->state          |= IIC_STATE_MASTER;
        iic->address        = 0x0000;
        iic->rx_buffer      = RT_NULL;

        /* Initialization */
        if (unitNumber >= I2C_COUNT)
        {
            break;
        }
        switch (unitNumber)
        {
        case 0:
            iic->iic_device = I2C0;
            iicClock        = (CMU_Clock_TypeDef)cmuClock_I2C0;
            port_scl            = AF_I2C0_SCL_PORT(location);
            pin_scl             = AF_I2C0_SCL_PIN(location);
            port_sda            = AF_I2C0_SDA_PORT(location);
            pin_sda             = AF_I2C0_SDA_PIN(location);
            break;
#if (I2C_COUNT > 1)
        case 1:
            iic->iic_device = I2C1;
            iicClock        = (CMU_Clock_TypeDef)cmuClock_I2C1;
            port_scl            = AF_I2C1_SCL_PORT(location);
            pin_scl             = AF_I2C1_SCL_PIN(location);
            port_sda            = AF_I2C1_SDA_PORT(location);
            pin_sda             = AF_I2C1_SDA_PIN(location);
            break;
#endif
        default:
            break;
        }
        rt_sprintf(name, "iic%d", unitNumber);

        /* Enabling clock */
        CMU_ClockEnable(iicClock, true);

        /* Reset */
        I2C_Reset(iic->iic_device);

        /* Config GPIO */
        GPIO_PinModeSet(
            port_scl,
            pin_scl,
            gpioModeWiredAndPullUpFilter,
            1);
        GPIO_PinModeSet(
            port_sda,
            pin_sda,
            gpioModeWiredAndPullUpFilter,
            1);

        hook.type       = efm32_irq_type_iic;
        hook.unit       = unitNumber;
        hook.cbFunc     = rt_hw_iic_slave_isr;
        hook.userPtr    = (void *)&block->device;
        efm32_irq_hook_register(&hook);

        /* Enable SDZ and SCL pins and set location */
        iic->iic_device->ROUTE = I2C_ROUTE_SDAPEN | I2C_ROUTE_SCLPEN | \
                    (location << _I2C_ROUTE_LOCATION_SHIFT);

        /* Initializing IIC */
        init.enable = false;
        I2C_Init(iic->iic_device, &init);

        /* Abort current TX data and clear TX buffers */
        iic->iic_device->CMD = I2C_CMD_ABORT | I2C_CMD_CLEARPC | I2C_CMD_CLEARTX;

        /* Initialize lock */
        iic->lock = &block->lock;
        if (rt_sem_init(iic->lock, name, 1, RT_IPC_FLAG_FIFO) != RT_EOK)
        {
            break;
        }

        /* Initialize timer */
        rt_timer_init(iic->timer, name, rt_iic_timer, &iic->timeout,
            IIC_TIMEOUT_PERIOD, RT_TIMER_FLAG_ONE_SHOT);

        return iic;
    } while(0);

    if (iic)
    {
        rt_free(iic);
    }

    iic_debug("IIC err: Unit %d init failed!\n", unitNumber);
    return RT_NULL;
}
/*
 * container的事件处理函数
 */
rt_bool_t instrument_panel_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
    struct rtgui_widget *widget = RTGUI_WIDGET(object);
    char ac[4];
    int i;
    int x0 = 120;
    int y0 = 170;
    int x, y;
    int default_color;

    /* 仅对PAINT事件进行处理 */
    if (event->type == RTGUI_EVENT_PAINT)
    {
        struct rtgui_dc *dc;
        rtgui_rect_t rect;
        const int arrowx[] = {120 + 75, 120 + 75, 120 + 85};
        const int arrowy[] = {170 - 5,  170 + 5,  170};

        /*
         * 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container
         * 先绘图
         */
        rtgui_container_event_handler(RTGUI_OBJECT(widget), event);

        /************************************************************************/
        /* 下面的是DC的操作                                                     */
        /************************************************************************/

        /* 获得控件所属的DC */
        dc = rtgui_dc_begin_drawing(widget);
        /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
        if (dc == RT_NULL)
            return RT_FALSE;

        /* 获得demo container允许绘图的区域 */
        demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);

        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
        /* 显示GUI的版本信息 */
#ifdef RTGUI_USING_SMALL_SIZE
        rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect);
#else
        rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect);
#endif


        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_CENTER_HORIZONTAL;
        RTGUI_DC_FC(dc) = blue;
        rect.y2 = 270;
        rtgui_dc_draw_text(dc, "rtgui-panel", &rect);

        for (i = 0; i < 6; i++)
        {
            rtgui_dc_draw_arc(dc, x0, y0, 117 - i, 150, 30);
        }

        RTGUI_DC_FC(dc) = black;

        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_LEFT;
        for (i = 0; i <= 23; i++)
        {
            if (i < 12)
            {
                x = x0 + 105 * cos((150 + i * 10) * 3.1415926 / 180);
                y = y0 + 105 * sin((150 + i * 10) * 3.1415926 / 180);
                rect.x1 = x;
                rect.y1 = y;
                rect.x2 = rect.x1 + 12 * 3;
                rect.y2 = rect.y1 + 12;
                rt_sprintf(ac, "%d", 10 * i);
                rtgui_dc_draw_text(dc, ac, &rect);
            }
            else
            {
                RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_RIGHT;

                x = x0 + 105 * cos((160 + i * 10) * 3.1415926 / 180);
                y = y0 + 105 * sin((160 + i * 10) * 3.1415926 / 180);

                rect.x1 = x  - 12 * 3;
                rect.y1 = y;
                rect.x2 = rect.x1 + 12 * 3;
                rect.y2 = rect.y1 + 12;
                rt_sprintf(ac, "%d", 10 * i);
                rtgui_dc_draw_text(dc, ac, &rect);
            }

            x = x0 + 107 * cos((150 + i * 10) * 3.1415926 / 180);
            y = y0 + 107 * sin((150 + i * 10) * 3.1415926 / 180);
            rtgui_dc_fill_circle(dc, x, y, 3);
        }
        RTGUI_DC_FC(dc) = RTGUI_RGB(166, 0, 166);
        rtgui_dc_fill_circle(dc, x0, y0, 3);
        RTGUI_DC_FC(dc) = RTGUI_RGB(120, 141, 30);
        rtgui_dc_draw_circle(dc, x0, y0, 5);

        default_color = RTGUI_DC_BC(dc);
        RTGUI_DC_BC(dc) = red;
        rect.x1 = x0 + 7;
        rect.y1 = y0 - 1;
        rect.x2 = x0 + 75;
        rect.y2 = y0 + 1;
        rtgui_dc_fill_rect(dc, &rect);

        RTGUI_DC_BC(dc) = default_color;

        rtgui_dc_fill_polygon(dc, arrowx, arrowy, 3);

        /* 绘图完成 */
        rtgui_dc_end_drawing(dc);
    }
    else
    {
        /* 其他事件,调用默认的事件处理函数 */
        return rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
    }

    return RT_FALSE;
}
Example #27
0
/* return the size of  struct dirent*/
static int dfs_jffs2_getdents(struct dfs_fd* file, 
                       struct dirent* dirp, 
					   rt_uint32_t count)
{
	cyg_file * jffs2_file;
	struct CYG_UIO_TAG uio_s;
	struct CYG_IOVEC_TAG iovec;
	struct jffs2_dirent jffs2_d;
	struct dirent * d;
	rt_uint32_t index;
#if !defined (CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE)
	struct jffs2_stat s;
	cyg_mtab_entry * mte;
	char * fullname;
#endif
	int result;
	
	RT_ASSERT(file->data != RT_NULL);	
	jffs2_file = (cyg_file*)(file->data);
	
	//set jffs2_d
	memset(&jffs2_d, 0, sizeof(struct jffs2_dirent));
	//set CYG_UIO_TAG uio_s
	uio_s.uio_iov = &iovec;
	uio_s.uio_iov->iov_base = &jffs2_d;
	uio_s.uio_iov->iov_len = sizeof(struct jffs2_dirent);;
	uio_s.uio_iovcnt = 1; //must be 1
	uio_s.uio_offset = 0;//not used...
	uio_s.uio_resid = uio_s.uio_iov->iov_len; //seem no use in jffs2;	

#if !defined (CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE)

	result = _find_fs(&mte, file->fs->dev_id);
	if (result)
		return -DFS_STATUS_ENOENT;
#endif

	/* make integer count, usually count is 1 */
	count = (count / sizeof(struct dirent)) * sizeof(struct dirent);
	if (count == 0) 
		return -DFS_STATUS_EINVAL;

	index = 0;
	/* usually, the while loop should only be looped only once! */
	while (1)
	{
		d = dirp + index;
		rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER);
		result = jffs2_dir_read(jffs2_file, &uio_s); 
		rt_mutex_release(&jffs2_lock);
		/* if met a error or all entry are read over, break while*/
		if (result || jffs2_d.d_name[0] == 0)
			break;

#if defined (CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE)
		switch(jffs2_d.d_type & JFFS2_S_IFMT) 
		{ 
		case JFFS2_S_IFREG: d->d_type = DFS_DT_REG; break; 		
		case JFFS2_S_IFDIR: d->d_type = DFS_DT_DIR; break; 
		default: d->d_type = DFS_DT_UNKNOWN; break; 
		} 	
#else
		fullname = rt_malloc(FILE_PATH_MAX);
		if(fullname == RT_NULL)
				return -DFS_STATUS_ENOMEM;

		/* make a right entry */
		if ((file->path[0] == '/') )
		{
			if (file->path[1] == 0)
				strcpy(fullname, jffs2_d.d_name);
			else
				rt_sprintf(fullname, "%s/%s", file->path+1, jffs2_d.d_name);
		}
		else
			rt_sprintf(fullname, "%s/%s", file->path, jffs2_d.d_name);
		rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER);
		result = jffs2_porting_stat(mte, mte->root, fullname, (void *)&s);
		rt_mutex_release(&jffs2_lock);
		if (result)
			return jffs2_result_to_dfs(result);

		rt_free(fullname);
		/* convert to dfs stat structure */
		switch(s.st_mode & JFFS2_S_IFMT)
		{
		case JFFS2_S_IFREG: d->d_type = DFS_DT_REG; break;
		case JFFS2_S_IFDIR: d->d_type = DFS_DT_DIR; break;
		default: d->d_type = DFS_DT_UNKNOWN; break;
		}
#endif
		/* write the rest fields of struct dirent* dirp  */
		d->d_namlen = rt_strlen(jffs2_d.d_name);
		d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
		rt_strncpy(d->d_name, jffs2_d.d_name, d->d_namlen + 1);
		
		index ++;
		if (index * sizeof(struct dirent) >= count)
			break;
	}
	if (result)
		return jffs2_result_to_dfs(result);
	return index * sizeof(struct dirent);
}
Example #28
0
void rt_init_thread_entry(void *parameter)
{
    rt_device_t lcd;  
    
    rt_hw_led_init();
	rt_hw_key_init();
	rt_hw_adc_init();
	rt_hw_lcd_init();      
	rt_hw_cpu_init();

#ifdef RT_USING_RTGUI
	extern void rtgui_system_server_init(void);

	/* find lcd device */
	lcd = rt_device_find("lcd");    
    
	/* set lcd device as rtgui graphic driver */		
	rtgui_graphic_set_device(lcd);

	/* init rtgui system server */
	rtgui_system_server_init();
   
	/* startup rtgui */
	rtgui_startup();
#else
	{
	char buf[20] = {'\0'};
    struct lcd_msg msg;
    rt_device_t device;   
    device = rt_device_find("lcd");
	rt_device_control(device, RT_DEVICE_CTRL_LCD_CLEAR_SCR, RT_NULL);
	x = 1;
	y = 1;
	rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "ADC"); 
	x = 1;
	y = 20;
	rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "CPU");
	x = 1;
	y = 40;
	rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "KEY");
    
    while(1)
    {
        if (rt_mq_recv(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER) == RT_EOK)
        {
        	switch(msg.type)
    		{
    			case ADC_MSG:
					x = 40;
					y = 1;
					rt_memset(buf, 0, sizeof(buf));
					rt_sprintf(buf, "%04d", msg.adc_value);
					rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf); 
					break;
				case CPU_MSG:
					x = 40;
					y = 20;
					rt_memset(buf, 0, sizeof(buf));
					rt_sprintf(buf, "%03d %03d", msg.major, msg.minor);
					rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf); 
					break;
				case KEY_MSG:
					x = 40;
					y = 40;
					rt_memset(buf, 0, sizeof(buf));
                    switch(msg.key)
                	{
                		case KEY_DOWN:
							rt_sprintf(buf, "DOWN KEY ");
							break;
						case KEY_UP:
							rt_sprintf(buf, "UP KEY   ");
							break;	
                		case KEY_RIGHT:
							rt_sprintf(buf, "RIGHT KEY");
							break;
						case KEY_LEFT:
							rt_sprintf(buf, "LEFT KEY ");
							break;	
                		case KEY_ENTER:
							rt_sprintf(buf, "ENTER KEY");
							break;
						default:
							rt_sprintf(buf, "NO KEY   ");
							break;								
                	}
					rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf); 
                    break;                    
    		}
        }
    }
	}
#endif
}
Example #29
0
/*
 * 构建应用视图
 */
int app_view_structure(struct rtgui_workbench *workbench, struct rtgui_view *view)
{
	int ret = SUCC;
	rtgui_rect_t rect, body_rect;
	rtgui_label_t* label;
	char str[48];
	//rtgui_radiobox_t *radiobox;
	//rtgui_button_t* button;
	struct tm *ptime;
#if 1==DISPLAY_OVERLOAD_INFO
	rtgui_label_t *rx_overload_label;
#endif

	app_view_get_can_use_rect(view, &rect);
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   rect.x1, rect.y1, rect.x2, rect.y2));

	body_rect.x1 = 0;
	body_rect.y1 = 0;
	body_rect.x2 = rect.x2;
	body_rect.y2 = TITLE_PANEL_HEIGHT;
	label = rtgui_label_create(DEVICE_NAME);
	if (NULL != label) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = blue;
		rtgui_widget_set_rect(RTGUI_WIDGET(label), &body_rect);
		/* view是一个container控件,调用add_child方法添加这个label控件 */
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
	} else {
		printf_syn("creat title label fail\n");
	}

	body_rect.x1 = 0;
	body_rect.y1 = TITLE_PANEL_HEIGHT;
	body_rect.x2 = rect.x2;
	body_rect.y2 = rect.y2;
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2));

	zvd_notebook = rtgui_notebook_create(&body_rect, RTGUI_NOTEBOOK_TOP);
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(zvd_notebook));

	re_form = rtgui_form_create(re_form_head, RE_FORM_ROWS, RE_FORM_COLS, &body_rect);
	rtgui_notebook_add(zvd_notebook, "接收端", RTGUI_WIDGET(re_form));
#if 1
	set_form_px_col(re_form);
	i2str(str, avg_val[AVI_RE_PA]);
	rtgui_form_set_item(re_form, str, RE_PA_AVG_VALUE_ROW, RE_PA_AVG_VALUE_COL, 0);
	rtgui_form_set_item(re_form, print_info_str[PIS_ID_ZHENGCHANG], RE_PA_OVER_RANGE_ROW, RE_PA_OVER_RANGE_COL, 0);

	i2str(str, avg_val[AVI_RE_PB]);
	rtgui_form_set_item(re_form, str, RE_PB_AVG_VALUE_ROW, RE_PB_AVG_VALUE_COL, 0);
	rtgui_form_set_item(re_form, print_info_str[PIS_ID_ZHENGCHANG], RE_PB_OVER_RANGE_ROW, RE_PB_OVER_RANGE_COL, 0);

	i2str(str, avg_val[AVI_RE_PC]);
	rtgui_form_set_item(re_form, str, RE_PC_AVG_VALUE_ROW, RE_PC_AVG_VALUE_COL, 0);
	rtgui_form_set_item(re_form, print_info_str[PIS_ID_ZHENGCHANG], RE_PC_OVER_RANGE_ROW, RE_PC_OVER_RANGE_COL, 0);
#endif

	se_form = rtgui_form_create(se_form_head, SE_FORM_ROWS, SE_FORM_COLS, &body_rect);
	rtgui_notebook_add(zvd_notebook, "发射端", RTGUI_WIDGET(se_form));
#if 1
	set_form_px_col(se_form);
	rtgui_form_set_item(se_form, print_info_str[PIS_ID_ZHENGCHANG], SE_PA_OVER_RANGE_ROW, SE_PA_OVER_RANGE_COL, 0);
	rtgui_form_set_item(se_form, print_info_str[PIS_ID_FOU], SE_PA_POWER_DOWN_ROW, SE_PA_POWER_DOWN_COL, 0);

	rtgui_form_set_item(se_form, print_info_str[PIS_ID_ZHENGCHANG], SE_PB_OVER_RANGE_ROW, SE_PB_OVER_RANGE_COL, 0);
	rtgui_form_set_item(se_form, print_info_str[PIS_ID_FOU], SE_PB_POWER_DOWN_ROW, SE_PB_POWER_DOWN_COL, 0);

	rtgui_form_set_item(se_form, print_info_str[PIS_ID_ZHENGCHANG], SE_PC_OVER_RANGE_ROW, SE_PC_OVER_RANGE_COL, 0);
	rtgui_form_set_item(se_form, print_info_str[PIS_ID_FOU], SE_PC_POWER_DOWN_ROW, SE_PC_POWER_DOWN_COL, 0);
#endif

	sys_form = rtgui_form_create(sys_form_head, SYS_FORM_ROWS, SYS_FORM_COLS, &body_rect);
	rtgui_notebook_add(zvd_notebook, "系统", RTGUI_WIDGET(sys_form));
#if 1
	rtgui_form_set_item(sys_form, "接收端", 1, 0, 0);
	i2str(str, sys_temper[STI_RE_CPU_T]);
	rtgui_form_set_item(sys_form, str, 		RE_RE_CPU_TEMP_ROW, RE_RE_CPU_TEMP_COL, 0);
	i2str(str, sys_temper[STI_RE_CTB_T]);
	rtgui_form_set_item(sys_form, str, 		RE_RE_BOX_TEMP_ROW, RE_RE_BOX_TEMP_COL, 0);
	convert_ver2str(re_version, str);
	rtgui_form_set_item(sys_form, str, 	RE_RE_SOFT_VER_ROW, RE_RE_SOFT_VER_COL, 0);

	rtgui_form_set_item(sys_form, "发射端", 2, 0, 0);
	i2str(str, sys_temper[STI_SE_CPU_T]);
	rtgui_form_set_item(sys_form, str, 		RE_SE_CPU_TEMP_ROW, RE_SE_CPU_TEMP_COL, 0);
	i2str(str, sys_temper[STI_SE_CTB_T]);
	rtgui_form_set_item(sys_form, str, 		RE_SE_BOX_TEMP_ROW, RE_SE_BOX_TEMP_COL, 0);
	convert_ver2str(se_version, str);
	rtgui_form_set_item(sys_form, str, 	RE_SE_SOFT_VER_ROW, RE_SE_SOFT_VER_COL, 0);

	creat_devsn(str, sizeof(str), 0);
	rtgui_form_set_row(sys_form, str, TE_SN_ROW);

	creat_devsn(str, sizeof(str), 1);
	rtgui_form_set_row(sys_form, str, RE_SN_ROW);
#endif


	other_form = rtgui_form_create(other_form_head, OTHER_FORM_ROWS, OTHER_FORM_COLS, &body_rect);
	rtgui_notebook_add(zvd_notebook, "掉电", RTGUI_WIDGET(other_form));
#if 1
	rtgui_form_set_item(other_form, "次数", 1, 0, 0);
	rtgui_form_set_item(other_form, "n", 2, 0, 0);
	rtgui_form_set_item(other_form, "n-1", 3, 0, 0);
	rtgui_form_set_item(other_form, "n-2", 4, 0, 0);
	update_tx_poweroff_info_of_otherform();
	update_rx_poweroff_info_of_otherform();
#endif

	body_rect.x1 = FRAME_GAP;
	body_rect.y1 = body_rect.y2 + WIDGET_ROW_GAP;
	body_rect.x2 = FRAME_GAP + 8 * rt_strlen(RE_IF_SWITCH2CABLE_STR);
	body_rect.y2 = body_rect.y1 + 16;
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2));

	switch_cable_label = rtgui_label_create(RE_IF_SWITCH2CABLE_STR);
	if (NULL != switch_cable_label) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(switch_cable_label)) =  RTGUI_ALIGN_CENTER_VERTICAL;
		//RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(switch_cable_label)) = blue;
		rtgui_widget_set_rect(RTGUI_WIDGET(switch_cable_label), &body_rect);
		/* view是一个container控件,调用add_child方法添加这个label控件 */
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(switch_cable_label));
	} else {
		printf_syn("creat cable label fail\n");
	}

#if 1
	body_rect.x1 = body_rect.x2 + 2;
	body_rect.x2 = body_rect.x1 + 16 + 8;
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2));

	switch_cable_yn_textview = rtgui_textview_create(print_info_str[PIS_ID_FOU], &body_rect);
	if (NULL != switch_cable_yn_textview) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(switch_cable_yn_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL
				| RTGUI_ALIGN_CENTER_VERTICAL;
		//RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(switch_cable_yn_textview)) = red;
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(switch_cable_yn_textview));
	} else {
		printf_syn("creat cable yn textview fail\n");
	}
#endif

#if 1
	body_rect.x1 = body_rect.x2 + 2 + 2*8;
	body_rect.x2 = body_rect.x1 + 8*rt_strlen(TE_HAD_POWEROFF_STR);
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2));

	tx_poweroff_label = rtgui_label_create(TE_HAD_POWEROFF_STR);
	if (NULL != tx_poweroff_label) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(tx_poweroff_label)) =  RTGUI_ALIGN_CENTER_VERTICAL;
		rtgui_widget_set_rect(RTGUI_WIDGET(tx_poweroff_label), &body_rect);
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(tx_poweroff_label));
	} else {
		printf_syn("tx poweroff label fail\n");
	}

	body_rect.x1 = body_rect.x2 + 2;
	body_rect.x2 = body_rect.x1 + 16 + 8;
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2));

	tx_poweroff_yn_textview = rtgui_textview_create(print_info_str[PIS_ID_FOU], &body_rect);
	if (NULL != tx_poweroff_yn_textview) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(tx_poweroff_yn_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL
				| RTGUI_ALIGN_CENTER_VERTICAL;
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(tx_poweroff_yn_textview));
	} else {
		printf_syn("creat cable yn textview fail\n");
	}
#endif


#if 1
	body_rect.x1 = FRAME_GAP;
	body_rect.y1 = body_rect.y2 + WIDGET_ROW_GAP;
	body_rect.x2 = FRAME_GAP + (8+1) * rt_strlen(RE_BUZZER_DISABLE_STR);
	body_rect.y2 = body_rect.y1 + 16 + 2*WIDGET_ROW_GAP;
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2));

	buzzer_button = rtgui_pushbutton_create(RE_BUZZER_DISABLE_STR);
	if (NULL != buzzer_button) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(buzzer_button)) = RTGUI_ALIGN_CENTER_HORIZONTAL
				| RTGUI_ALIGN_CENTER_VERTICAL;
		//RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(buzzer_button)) = blue;
		rtgui_widget_set_rect(RTGUI_WIDGET(buzzer_button), &body_rect);
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(buzzer_button));

		rtgui_button_set_onbutton(buzzer_button, buzzer_btn_onbutton);
	} else {
		printf_syn("creat buzzer pushbutton fail\n");
	}

	body_rect.x1 = body_rect.x2 + FRAME_GAP;
	/* body_rect.y1 = body_rect.y1; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */
	body_rect.x2 = body_rect.x1 + (8+1) * rt_strlen(SWITCH_TO_PT_STR);;
	/* body_rect.y2 = body_rect.y2; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */
	
	switch2pt_button = rtgui_pushbutton_create(SWITCH_TO_PT_STR);
	if (NULL != switch2pt_button) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(switch2pt_button)) = RTGUI_ALIGN_CENTER_HORIZONTAL
				| RTGUI_ALIGN_CENTER_VERTICAL;
		//RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(switch2pt_button)) = blue;
		rtgui_widget_set_rect(RTGUI_WIDGET(switch2pt_button), &body_rect);
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(switch2pt_button));
		rtgui_button_set_onbutton(switch2pt_button, switch2pt_btn_onbutton);
	} else {
		printf_syn("creat switch button fail\n");
	}

#if USE_OPTICX_200S_VERSION
	body_rect.x1 = body_rect.x2 + FRAME_GAP;
	/* body_rect.y1 = body_rect.y1; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */
	body_rect.x2 = body_rect.x1 + (8) * rt_strlen(RE_CUR_CHANNEL_NO_STR) + 2;
	/* body_rect.y2 = body_rect.y2; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2));
	rxe_cur_channel_label = rtgui_label_create(RE_CUR_CHANNEL_NO_STR);
	if (NULL != rxe_cur_channel_label) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rxe_cur_channel_label)) =  RTGUI_ALIGN_CENTER_VERTICAL;
		rtgui_widget_set_rect(RTGUI_WIDGET(rxe_cur_channel_label), &body_rect);
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rxe_cur_channel_label));
	} else {
		printf_syn("rxe cru channel label fail\n");
	}

	body_rect.x1 = body_rect.x2 + 2;
	body_rect.x2 = body_rect.x1 + 8 + 8;
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2));
	str[0] = convert_cur_channel_to_char();
	str[1] = '\0';
	rxe_cur_channel_no_textview = rtgui_textview_create(str, &body_rect);
	if (NULL != rxe_cur_channel_no_textview) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rxe_cur_channel_no_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL
				| RTGUI_ALIGN_CENTER_VERTICAL;
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rxe_cur_channel_no_textview));
	} else {
		printf_syn("creat cable yn textview fail\n");
	}
#endif
#endif

#if 1==DISPLAY_OVERLOAD_INFO
	body_rect.x1 = body_rect.x2 + 2 + 7*8;
	body_rect.x2 = body_rect.x1 + 8*rt_strlen(RE_OVERLOAD_CNT_STR);
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2));

	rx_overload_label = rtgui_label_create(RE_OVERLOAD_CNT_STR);
	if (NULL != rx_overload_label) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rx_overload_label)) =  RTGUI_ALIGN_CENTER_VERTICAL;
		rtgui_widget_set_rect(RTGUI_WIDGET(rx_overload_label), &body_rect);
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rx_overload_label));
	} else {
		printf_syn("tx poweroff label fail\n");
	}

	body_rect.x1 = body_rect.x2 + 2;
	body_rect.x2 = body_rect.x1 + 16 + 8;
	zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__,
				   body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2));

	rx_overload_cnt_textview = rtgui_textview_create("0", &body_rect);
	if (NULL != rx_overload_cnt_textview) {
		RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rx_overload_cnt_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rx_overload_cnt_textview));
	} else {
		printf_syn("creat cable yn textview fail\n");
	}
#endif



#if 1
	/* 创建时间标签, 2013-03-18 09:20 */
	rtc_dev = rt_device_find("rtc");
	if (NULL != rtc_dev) {
		time_t time;
		rt_device_control(rtc_dev, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
		ptime = localtime(&time);
		rt_sprintf(sys_time_str, "%4d-%02d-%02d %02d:%02d:%02d", (ptime->tm_year+1900), (ptime->tm_mon+1),
				   ptime->tm_mday,	ptime->tm_hour, ptime->tm_min, ptime->tm_sec);

		body_rect.x2 = rtgui_graphic_driver_get_default()->width;
		body_rect.y2 = rtgui_graphic_driver_get_default()->height;
		body_rect.x1 = body_rect.x2 - (8+1) * 19;
		body_rect.y1 = body_rect.y2 - 20;
#if SYS_TIME_USE_TEXTBOX
		sys_time_textbox = rtgui_textbox_create(sys_time_str, RTGUI_TEXTBOX_SINGLE | RTGUI_TEXTBOX_CARET_HIDE);
		if (NULL != sys_time_textbox) {
			RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(sys_time_textbox)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
			//RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(sys_time_textbox)) = blue;
			RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(sys_time_textbox)) = blue; //default_background;
			//RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view));
			rtgui_widget_set_rect(RTGUI_WIDGET(sys_time_textbox), &body_rect);
			rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(sys_time_textbox));

		} else {
			printf_syn("creat sys time textbox fail\n");
		}
#else
		sys_time_textview = rtgui_textview_create(sys_time_str, &body_rect);
		if (NULL != sys_time_textview) {
			RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(sys_time_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
			//RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(sys_time_textbox)) = blue;
			rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(sys_time_textview));
		} else {
			printf_syn("creat sys time textview fail\n");
		}
#endif

	} else {
		printf_syn("find rtc device fail\n");
	}

#endif
	rtgui_view_show(view, RT_FALSE); /* 显示视图 */

	return ret;
}