• 如何去除switch case,实现不同任务的调用
  • 其它
    2.00元

嵌入式linux,应用
通过串口获得了 形如 命令+参数 的字符串
我是之前是通过switch case进行功能选择的?有没有什么更好的办法统一起来,有些约定的指令需要带参数,有些不需要。

           switch(location)
           {
               case 0:command_getServerIp(); break;
               case 1:command_setServerIp(); break;
               case 2:command_getIpcIP(); break;
               case 3:command_takephoto(); break;
               case 4:command_standby(); break;
               case 5:command_setStandbytime(); break;
               case 6:command_GPIOCTRL(); break;
               default:
                   rdlen = 0;
                   location = -1;
                   memset(recbuffer,0,sizeof(recbuffer));
                   sendmessage("BAD COMMAND!\n");
           }
           memset(recbuffer,0,sizeof(recbuffer));// cleanup


  • Caroline    2020-04-14 10:44:53
  • 阅读 1956    收藏 0    回答 1
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信