NevermindZZT / letter-shell

letter shell
MIT License
1.2k stars 438 forks source link

大小端导致shellSeekCommand中遍历命令属性异常 #184

Open wumingxu10 opened 6 months ago

wumingxu10 commented 6 months ago

我的板子是powerpc架构的,是大端模式,所以在shellSeekCommand的时候读取命令的属性有问题,修改了以下的定义


typedef struct shell_command
{
    union
    {
        struct
        {
#if 0
            //小端
            unsigned char permission : 8;                       /**< command权限 */
            ShellCommandType type : 4;                          /**< command类型 */
            unsigned char enableUnchecked : 1;                  /**< 在未校验密码的情况下可用 */
            unsigned char disableReturn : 1;                    /**< 禁用返回值输出 */
            unsigned char readOnly : 1;                         /**< 只读 */
            unsigned char reserve : 1;                          /**< 保留 */
            unsigned char paramNum : 4;                         /**< 参数数量 */
#else
            //大端
            unsigned int   : 12;
        unsigned char paramNum : 4;                         /**< 参数数量 */
        unsigned char reserve : 1;                          /**< 保留 */
        unsigned char readOnly : 1;                         /**< 只读 */
        unsigned char disableReturn : 1;                    /**< 禁用返回值输出 */
        unsigned char enableUnchecked : 1;                  /**< 在未校验密码的情况下可用 */
        ShellCommandType type : 4;                          /**< command类型 */
        unsigned char permission : 8;                       /**< command权限 */
#endif
        } attrs;
        int value;
    } attr;                                                     /**< 属性 */
    union
    {
        struct
        {
            const char *name;                                   /**< 命令名 */
            int (*function)();                                  /**< 命令执行函数 */
            const char *desc;                                   /**< 命令描述 */
        #if SHELL_USING_FUNC_SIGNATURE == 1
            const char *signature;                              /**< 函数签名 */
        #endif
        } cmd;                                                  /**< 命令定义 */
        struct
        {
            const char *name;                                   /**< 变量名 */
            void *value;                                        /**< 变量值 */
            const char *desc;                                   /**< 变量描述 */
        } var;                                                  /**< 变量定义 */
        struct
        {
            const char *name;                                   /**< 用户名 */
            const char *password;                               /**< 用户密码 */
            const char *desc;                                   /**< 用户描述 */
        } user;                                                 /**< 用户定义 */
        struct
        {
            int value;                                          /**< 按键键值 */
            void (*function)(Shell *);                          /**< 按键执行函数 */
            const char *desc;                                   /**< 按键描述 */
        } key;                                                  /**< 按键定义 */
#if SHELL_USING_FUNC_SIGNATURE == 1
        struct
        {
            const char *type;                                   /**< 参数类型 */
            int (*parser)(char *, void **);                     /**< 解析函数 */
            int (*cleaner)(void *);                             /**< 清理器 */
        } paramParser;                                          /**< 参数解析器 */
#endif
    } data;
} ShellCommand;