免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 556 | 回复: 0
打印 上一主题 下一主题

[2008.12.3]函数问题: [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-03 14:55 |只看该作者 |倒序浏览
/*==================================================================================================
FUNCTION: getGpio()
DESCRIPTION: This function is responsible for handling get GPIO status.
ARGUMENTS PASSED:
  TC_GPIO_DATA *gpio_data- Pointer to TC_GPIO_DATA data structure               
                     
RETURN VALUE:
  void
IMPORTANT NOTES:
  None
==================================================================================================*/
int getGpio(TC_GPIO_DATA *gpio_data)
{
    char *pos=NULL;
    char gpio_str[8], buf[1024];
    int ret=-1;
    int i;
    memset(buf, 0, 1024);
    memset(gpio_str, 0, 8);
   
    if( gpio_fp != NULL )
        fclose(gpio_fp);
    gpio_fp = fopen("/sys/kernel/debug/gp
io","r");
    if( !gpio_fp )
    {
        TCMD_TRACE("Error: can not open debugfs gpio control file\n");
        return ret;
    }
    TCMD_TRACE("Open the file success \n");
    TCMD_TRACE("the gpio number is %d :\n",gpio_data->gpio_number);
    sprintf(gpio_str,"gpio-%d",gpio_data->gpio_number);
    for(i=0;i8;i++)
      TCMD_TRACE("%c",gpio_str);
    while( fgets(buf, 1024, gpio_fp) )
    {
        TCMD_TRACE("Begin to parse data information \n");
        if( (pos=strstr(buf,gpio_str)) != NULL )
        {/* Found */
            TCMD_TRACE("Found the current gpio address \n");
            pos += strlen(gpio_str);
            while( *pos && *pos!=')' )
                pos++;
            TCMD_TRACE("Begin to parse the detaillll info \n");
            if(*pos == ')' )   
            {
                pos+=2; /* bypass ") " */
                if( strncmp(pos,"in  ",4)==0 )
                {
                    gpio_data->in_out=0;
                    pos +=4;
                }else if(strncmp(pos,"out ",4)==0)
                {
                    gpio_data->in_out=1;
                    pos +=4;
                }else
                {
                    ret = -2;
                    TCMD_TRACE("can't find the inout flag \n ");
                    break;
                }
                if( strncmp(pos, "lo",2)==0 )
                {
                    gpio_data->level=0;
                }else if( strncmp(pos,"hi",2)==0 )
                {
                    gpio_data->level=1;
                }else
                {
                    ret = -3;
                    TCMD_TRACE("can't find the hilow flag \n");
                    break;
                }
                /* Successful parsed */
                ret=0;
                TCMD_TRACE("parse success \n");
            }
            else
            {
                ret=-4;
                TCMD_TRACE("some unexpected error \n");
                break;
            }
        }else
        {/* Not found in this line */
            TCMD_TRACE("can't find the address in this line \n");
            continue;
        }
    }
    fclose(gpio_fp);
    gpio_fp = NULL;
    TCMD_TRACE("get gpio over \n");
    return ret;
}
座在我旁的同事找到了毛病:
1:在寻找文件中时,可能分析找到了对应的gpio,但是不会break退出,而是接着向下寻找:如下中绿线下的部分:
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] Found the current gpio address [14:41:36] Begin to parse the detaillll info [14:41:36] parse success
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] get gpio over
2另外,在sprintf(gpio_str,"gpio-%d",gpio_data->gpio_number);
如找gpio-2 因为用 if( (pos=strstr(buf,gpio_str)) != NULL )
会找gpio-20中一样,从而可能产生错误,如果第一个问题解决就不会有这个问题。
下面带色就是这个问题:这是因为gpio-20 gpio-21 gpio-22 gpio-23gpio-24 ...29

[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [[14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] Found the current gpio address
[14:47:26] Begin to parse the detaillll info
[14:47:26] some unexpected error
[14:47:26] get gpio over


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/63775/showart_1677737.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP