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;
}