• Linux测试程序交互实现


    void sig_handler(int signo) 
    {
        std::cout << "oops! stop!!!" << std::endl;
        _exit(0);
    }
    
    int main(int argc, char **argv)
    {
    
        PadSim pad_sim ;
        pad_sim.init(node);
    
        signal( SIGINT, sig_handler); /*注册ctrl+c 退出函数*/
        int value = system("stty erase ^H");/* 退格键不回显 */
    
        char cmd[256];
        std::cout <<"***************************************************************" << std::endl;
        std::cout <<"The command list:" << std::endl;
        std::cout << std::left << std::setw(20) << "h"
                            << " This help text
    "
    
                            << std::setw(20) << "auto"
                            << " Start: switch control mode to auto 
    "
                            << std::setw(20) << "manual"
                            << " Stop:  switch control mode to manual
    "
    
                            << std::setw(20) << "start"
                            << " Start: switch task mode start 
    "
                            << std::setw(20) << "stop"
                            << " Stop:  switch task mode to stop
    "
                            << std::setw(20) << "pause"
                            << " Pause: switch task mode to pause
    "
                            << std::setw(20) << "continue"
                            << " Pause: switch task mode to continue
    "
                            << std::setw(20) << "shutdown"
                            << " Shut down the program
    "
                            << std::flush;
        std::cout <<"***************************************************************" << std::endl;
        std::cout << "> ";
        while (std::cin.getline(cmd, sizeof(cmd))) 
        {
            std::string strCmd(cmd);
            if (strCmd == "shutdown") 
            {
                break;
            } 
            else if (strCmd == "h")
            {
                std::cout << std::left << std::setw(20) << "h"
                            << " This help text
    "
    
                            << std::setw(20) << "auto"
                            << " Start: switch control mode to auto 
    "
                            << std::setw(20) << "manual"
                            << " Stop:  switch control mode to manual
    "
    
                            << std::setw(20) << "start"
                            << " Start: switch task mode to start 
    "
                            << std::setw(20) << "stop"
                            << " Stop:  switch task mode to stop
    "
                            << std::setw(20) << "pause"
                            << " Pause: switch task mode to pause
    "
                            << std::setw(20) << "continue"
                            << " Pause: switch task mode to continue
    "
                            << std::setw(20) << "shutdown"
                            << " Shut down the program
    "
                            << std::flush;
            } 
            else if (strCmd == "auto") 
            {
                pad_sim.pad_send_message(1008);
            } 
            else if (strCmd == "manual") 
            {
                pad_sim.pad_send_message(1009);
            } 
            else if (strCmd == "start") 
            {
                pad_sim.pad_send_message(1007);
            } 
            else if (strCmd == "stop") 
            {
                pad_sim.pad_send_message(1006);
            } 
            else if (strCmd == "pause") 
            {
                pad_sim.pad_send_message(1004);
            } 
            else if (strCmd == "continue") 
            {
                pad_sim.pad_send_message(1005);
            } 
            else 
            {
                std::cerr << "Error: unknown commamd" << std::endl;
            }           
            std::cout << "> ";
        }
        std::cout << "exit " << std::endl;
        return 0;
    }
    

      

  • 相关阅读:
    node express 返回json object
    CodeIgniter 安装指导
    nodejs 使用express开发获取其他网站引用本站点js文件的参数
    nodejs express 学习
    microsoft webMatrix 使用 IISnode 进行node express 开发
    模板引擎jade学习
    模板引擎之jade 学习
    smarty学习——高级知识
    smarty学习——缓存
    smarty学习——编程知识
  • 原文地址:https://www.cnblogs.com/sshbit/p/13225656.html
Copyright © 2020-2023  润新知