⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cli_cmdpro.c

📁 可以作为路由器交换机设备的远端shell控制接口
💻 C
📖 第 1 页 / 共 5 页
字号:

    /*error msg*/
    if ( argc < 2)
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (0, "\n\r error msg" ) ;
        return ;
    }

    /*get user index*/
    aos_atol(argv[0], (S32*)&ulIndex);

    /*get curent interface mode*/
    aos_strcpy(szIfName, argv[1]);

    if ( argc == 2 )
    {
        /*----------------------------------------------------------------*/
        /* change to config mode                                          */
        /*----------------------------------------------------------------*/
        cli_change_level (ulIndex, PRIVILEGE_LEVEL ) ;
        pstFrame = aos_msg_alloc( MPE_CLI, sizeof( struct dbg_frame_s));
        if( NULL == pstFrame )
        {
            return;
        }

        aos_memzero( pstFrame, sizeof( struct dbg_frame_s));


        /*填充DEBUG消息帧*/
        pstFrame->debuger_ip_addr = AOS_HTONL(ulIndex);
        pstFrame->cmd = DEBUG_GOODBYE;
        aos_sscanf(argv[1], "%d", &ulDstProcessorID);
        pstFrame->dstProcessorId = ulDstProcessorID;
        pstFrame->is_to_borad = TRANS_TO_BOARD;



        /*填充AOS消息头*/
        stMsg.dstMpe = MPE_DEBUG;
        stMsg.dstProcessorId = ulDstProcessorID;
        stMsg.msgPrio = MSG_PRIO_NORMAL;
        stMsg.srcMpe = MPE_CLI;
        stMsg.srcProcessorId = dev_get_local_processorid();
        stMsg.pvMsgBuf = pstFrame;
        stMsg.ulSize = sizeof( struct dbg_frame_s );

        /*发送AOS消息*/
        aos_msg_send( &stMsg );
        return ;
    }
    else
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (ulIndex, pTooManyParam ) ;
        return ;
    }

}

VOID cli_ada_cmd_proc ( U32 argc, S8 * argv[ ] )
{
   struct dbg_frame_s*   pstFrame;
   U32   ulDstProcessorID;

   USER_DATA_S *pstUserData = NULL;
   U32 ulIndex = 0;
   MSG_S    stMsg;
   U32 ulMpe, ulParams;
   U32 i;

    /*error msg*/
    if ( argc < 2)
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (0, "\n\r error msg" ) ;
        return ;
    }

    /*get user index*/
    aos_atol(argv[0], (S32*)&ulIndex);



     if ( argc == 2 )
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (ulIndex, pIncompleteCmd ) ;
        return ;
    }

    pstUserData = cli_get_userdata_by_index( ulIndex);
    if(NULL == pstUserData)
    {
          //AOS_ASSERT(0);

       return;
    }


    if (( argc >= 3 )&&( argc <= 8 ))
    {
        pstFrame = aos_msg_alloc( MPE_CLI, sizeof( struct dbg_frame_s));
        if( NULL == pstFrame )
        {
            return;
        }

        aos_memzero( pstFrame, sizeof( struct dbg_frame_s));
        aos_atoul( argv[2], &ulMpe );


        /*填充DEBUG消息帧*/
        pstFrame->debuger_ip_addr = AOS_HTONL(ulIndex);
        pstFrame->cmd = DEBUG_CMD;
        pstFrame->u.cmdmsg.subcmd = DEBUG_SUB_CMD;
        pstFrame->u.cmdmsg.mpe = (U8)ulMpe;
        aos_sscanf(argv[1], "%d", &ulDstProcessorID);
        pstFrame->dstProcessorId = ulDstProcessorID;
        pstFrame->is_to_borad = TRANS_TO_BOARD;
        pstFrame->u.cmdmsg.para[0] = U32_BUTT;
        pstFrame->u.cmdmsg.para[1] = U32_BUTT;
        pstFrame->u.cmdmsg.para[2] = U32_BUTT;
        pstFrame->u.cmdmsg.para[3] = U32_BUTT;


        for( i = 3; i < argc; i++ )
        {
            if(aos_memcmp(argv[i],"0x",2)==0)
            {
                aos_memset(argv[i],0x20,2);
                aos_atolx(argv[i],&ulParams);

            }
            else
            {
                aos_atoul( argv[i], &ulParams );
            }
            pstFrame->u.cmdmsg.para[i-3] = AOS_HTONL( ulParams );
        }


        /*填充AOS消息头*/
        stMsg.dstMpe = MPE_DEBUG;
        stMsg.dstProcessorId = ulDstProcessorID;
        stMsg.msgPrio = MSG_PRIO_NORMAL;
        stMsg.srcMpe = MPE_CLI;
        stMsg.srcProcessorId = dev_get_local_processorid();
        stMsg.pvMsgBuf = pstFrame;
        stMsg.ulSize = sizeof( struct dbg_frame_s );

        /*发送AOS消息*/
        aos_msg_send( &stMsg );
        return;
    }
    else
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (ulIndex, pTooManyParam ) ;
        return ;
    }


}

VOID cli_ada_memshow ( U32 argc, S8 * argv[ ] )
{
   struct dbg_frame_s*   pstFrame;
   U32   ulDstProcessorID;

   USER_DATA_S *pstUserData = NULL;
   U32 ulIndex = 0;
   MSG_S    stMsg;
   U32 ulParams;

    /*error msg*/
    if ( argc < 2)
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (0, "\n\r error msg" ) ;
        return ;
    }

    /*get user index*/
    aos_atol(argv[0], (S32*)&ulIndex);



     if ( argc != 4 )
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (ulIndex, pIncorrectCmd ) ;
        return ;
    }

    pstUserData = cli_get_userdata_by_index( ulIndex);
    if(NULL == pstUserData)
    {
          //AOS_ASSERT(0);

       return;
    }


    pstFrame = aos_msg_alloc( MPE_CLI, sizeof( struct dbg_frame_s));
    if( NULL == pstFrame )
    {
        return;
    }

    aos_memzero( pstFrame, sizeof( struct dbg_frame_s));


    /*填充DEBUG消息帧*/
    pstFrame->debuger_ip_addr = AOS_HTONL(ulIndex);
    pstFrame->cmd = DEBUG_CMD;
    pstFrame->u.cmdmsg.subcmd = DEBUG_MEM_SHOW;
    pstFrame->u.cmdmsg.mpe = 0;
    aos_sscanf(argv[1], "%d", &ulDstProcessorID);
    pstFrame->dstProcessorId = ulDstProcessorID;
    pstFrame->is_to_borad = TRANS_TO_BOARD;
    pstFrame->u.cmdmsg.para[0] = U32_BUTT;
    pstFrame->u.cmdmsg.para[1] = U32_BUTT;
    pstFrame->u.cmdmsg.para[2] = U32_BUTT;
    pstFrame->u.cmdmsg.para[3] = U32_BUTT;


    if(( 0 == aos_strncmp( "0x", argv[2], 2)) ||
       ( 0 == aos_strncmp( "0X", argv[2], 2)))
    {
        aos_atoulx( argv[2]+2, &ulParams );
    }
    else
    {
        aos_atoul( argv[2], &ulParams );
    }
    pstFrame->u.cmdmsg.para[0] = AOS_HTONL( ulParams );

    aos_atoul( argv[3], &ulParams );
    pstFrame->u.cmdmsg.para[1] = AOS_HTONL( ulParams );

    /*填充AOS消息头*/
    stMsg.dstMpe = MPE_DEBUG;
    stMsg.dstProcessorId = ulDstProcessorID;
    stMsg.msgPrio = MSG_PRIO_NORMAL;
    stMsg.srcMpe = MPE_CLI;
    stMsg.srcProcessorId = dev_get_local_processorid();
    stMsg.pvMsgBuf = pstFrame;
    stMsg.ulSize = sizeof( struct dbg_frame_s );

    /*发送AOS消息*/
    aos_msg_send( &stMsg );
    return;

}



VOID cli_ada_memmod ( U32 argc, S8 * argv[ ] )
{
   struct dbg_frame_s*   pstFrame;
   U32   ulDstProcessorID;

   USER_DATA_S *pstUserData = NULL;
   U32 ulIndex = 0;
   MSG_S    stMsg;
   U32 ulMpe, ulParams;

    /*error msg*/
    if ( argc < 2)
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (0, "\n\r error msg" ) ;
        return ;
    }

    /*get user index*/
    aos_atol(argv[0], (S32*)&ulIndex);



    if ( argc != 5 )
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (ulIndex, pIncorrectCmd ) ;
        return ;
    }

    pstUserData = cli_get_userdata_by_index( ulIndex);
    if(NULL == pstUserData)
    {
          //AOS_ASSERT(0);

       return;
    }


    pstFrame = aos_msg_alloc( MPE_CLI, sizeof( struct dbg_frame_s));
    if( NULL == pstFrame )
    {
        return;
    }

    aos_memzero( pstFrame, sizeof( struct dbg_frame_s));
    aos_atoul( argv[2], &ulMpe );


    /*填充DEBUG消息帧*/
    pstFrame->debuger_ip_addr = AOS_HTONL(ulIndex);
    pstFrame->cmd = DEBUG_CMD;
    pstFrame->u.cmdmsg.subcmd = DEBUG_MEM_MOD;
    pstFrame->u.cmdmsg.mpe = 0;
    aos_sscanf(argv[1], "%d", &ulDstProcessorID);
    pstFrame->dstProcessorId = ulDstProcessorID;
    pstFrame->is_to_borad = TRANS_TO_BOARD;


    pstFrame->u.cmdmsg.para[0] = U32_BUTT;
    pstFrame->u.cmdmsg.para[1] = U32_BUTT;
    pstFrame->u.cmdmsg.para[2] = U32_BUTT;
    pstFrame->u.cmdmsg.para[3] = U32_BUTT;

    if(( 0 == aos_strncmp( "0x", argv[2], 2)) ||
       ( 0 == aos_strncmp( "0X", argv[2], 2)))
    {
        aos_atoulx( argv[2]+2, &ulParams );
    }
    else
    {
        aos_atoul( argv[2], &ulParams );
    }
    pstFrame->u.cmdmsg.para[0] = AOS_HTONL( ulParams );

    aos_atoul( argv[3], &ulParams );
    pstFrame->u.cmdmsg.para[1] = AOS_HTONL( ulParams );

    if(( 0 == aos_strncmp( "0x", argv[4], 2)) ||
       ( 0 == aos_strncmp( "0X", argv[4], 2)))
    {
        aos_atoulx( argv[4]+2, &ulParams );
    }
    else
    {
        aos_atoul( argv[4], &ulParams );
    }

    pstFrame->u.cmdmsg.para[2] = AOS_HTONL( ulParams );

    /*填充AOS消息头*/
    stMsg.dstMpe = MPE_DEBUG;
    stMsg.dstProcessorId = ulDstProcessorID;
    stMsg.msgPrio = MSG_PRIO_NORMAL;
    stMsg.srcMpe = MPE_CLI;
    stMsg.srcProcessorId = dev_get_local_processorid();
    stMsg.pvMsgBuf = pstFrame;
    stMsg.ulSize = sizeof( struct dbg_frame_s );

    /*发送AOS消息*/
    aos_msg_send( &stMsg );
    return;

}




VOID cli_ada_turnon ( U32 argc, S8 * argv[ ] )
{
   struct dbg_frame_s*   pstFrame;
   U32   ulDstProcessorID;

   USER_DATA_S *pstUserData = NULL;
   U32 ulIndex = 0;
   MSG_S    stMsg;
   U32 ulMpe, ulParams;
   U32 i;

    /*error msg*/
    if ( argc < 2)
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (0, "\n\r error msg" ) ;
        return ;
    }

    /*get user index*/
    aos_atol(argv[0], (S32*)&ulIndex);



    if ( argc != 3 )
    {
        /*----------------------------------------------------------------*/
        /* error message                                                  */
        /*----------------------------------------------------------------*/
        cli_out_string (ulIndex, pIncorrectCmd ) ;
        return ;
    }

    pstUserData = cli_get_userdata_by_index( ulIndex);
    if(NULL == pstUserData)
    {
          //AOS_ASSERT(0);

       return;
    }


    pstFrame = aos_msg_alloc( MPE_CLI, sizeof( struct dbg_frame_s));
    if( NULL == pstFrame )
    {
        return;
    }

    aos_memzero( pstFrame, sizeof( struct dbg_frame_s));
    aos_atoul( argv[2], &ulMpe );


    /*填充DEBUG消息帧*/
    pstFrame->debuger_ip_addr = AOS_HTONL(ulIndex);
    pstFrame->cmd = DEBUG_CMD;
    pstFrame->u.cmdmsg.mpe = (U8)ulMpe;
    pstFrame->u.cmdmsg.subcmd = DEBUG_TURNON;
    aos_sscanf(argv[1], "%d", &ulDstProcessorID);
    pstFrame->dstProcessorId = ulDstProcessorID;
    pstFrame->is_to_borad = TRANS_TO_BOARD;

    pstFrame->u.cmdmsg.para[0] = U32_BUTT;
    pstFrame->u.cmdmsg.para[1] = U32_BUTT;
    pstFrame->u.cmdmsg.para[2] = U32_BUTT;
    pstFrame->u.cmdmsg.para[3] = U32_BUTT;



    for( i = 3; i < argc; i++ )
    {
        aos_atoul( argv[i], &ulParams );
        pstFrame->u.cmdmsg.para[i-3] = AOS_HTONL( ulParams );
    }


    /*填充AOS消息头*/
    stMsg.dstMpe = MPE_DEBUG;
    stMsg.dstProcessorId = ulDstProcessorID;
    stMsg.msgPrio = MSG_PRIO_NORMAL;
    stMsg.srcMpe = MPE_CLI;
    stMsg.srcProcessorId = dev_get_local_processorid();
    stMsg.pvMsgBuf = pstFrame;
    stMsg.ulSize = sizeof( struct dbg_frame_s );

    /*发送AOS消息*/
    aos_msg_send( &stMsg );
    return;

}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -