int main(int UNUSED(argc), char *argv[]) { // int i; const int num_threads = 2; pthread_t tid[num_threads]; // void *status; struct listen_param lis_para; struct send_param send_para; char *line; //mtrace(); que_msg = CreateQueue(100); sem_init(&sem_msg, 0, 0); memset(&dev_map, 0, sizeof(dev_map)); lis_para.port = SERVER_PORT; lis_para.receive_thread = receive_thread; pthread_create(&tid[0], NULL, listen_thread, &lis_para); send_para.que_msg = que_msg; send_para.mutex_msg = &mutex_msg; send_para.sem_msg = &sem_msg; pthread_create(&tid[1], NULL, send_thread, &send_para); linenoiseHistoryLoad("hist-srv.txt"); /* Load the history at startup */ while((line = linenoise("srv> ")) != NULL) { /* Do something with the string. */ if (line[0] != '\0' && line[0] != '/') { //printf("echo: '%s'\n", line); linenoiseHistoryAdd(line); /* Add to the history. */ linenoiseHistorySave("hist-srv.txt"); /* Save the history on disk. */ cmd_handle(0, line); } else if (!strncmp(line,"/q",2)) { free(line); break; } else if (!strncmp(line,"/historylen",11)) { /* The "/historylen" command will change the history len. */ int len = atoi(line+11); linenoiseHistorySetMaxLen(len); } else if (line[0] == '/') { printf("Unreconized command: %s\n", line); } else { printf("\n"); } free(line); } // for (i = 0; i < num_threads; i++) // pthread_join(tid[i],&status); return 0; }
void cmd_handle(const char *line, int argc, char **argv, struct command *parent) { struct command *cmd; static char cmdbuf[32]; if(argc < 1) { error("No %scommand given", parent ? "sub" : ""); return; } cmd = cmd_find(argv[0], parent ? parent->subcommands : command_list); if(!cmd) { if(parent) error("%s %s: command not found", parent->name, argv[0]); else error("%s: command not found", argv[0]); return; } if(cmd->subcommands) cmd_handle(line, argc - 1, argv + 1, cmd); else if(!cmd->func) { if(parent) { snprintf(cmdbuf, sizeof(cmdbuf), "%s %s", parent->name, cmd->name); argv[0] = cmdbuf; } error("%s: command not implemented", argv[0]); } else { if(parent) { snprintf(cmdbuf, sizeof(cmdbuf), "%s %s", parent->name, cmd->name); argv[0] = cmdbuf; } cmd->func(line, argc, argv); } }
int main(void){ sys_init(); //配置系统时钟72M(包括clock, PLL and Flash configuration) delay_init();//初始化延时 uart1_init(72,9600); uart2_init(36,9600);//时钟为最高时钟的一半 // uart3_init(36,9600);//时钟为最高时钟的一半 led_init(); car_init(); jtag_set(2);//禁止JTAG,释放PB3,PA15 Steering_Init(); uart_printf("ok\r\n"); hwbz_init(); power_init(); while(1){ cmd_handle(); }; return 0; }
int main(int argc, char *argv[]) { int status = 0; struct rc_config rc; struct cli_state *state; bool exit_immediately = false; /* If no actions are specified, just show the usage text and exit */ if (argc == 1) { usage(argv[0]); return 0; } init_rc_config(&rc); if (get_rc_config(argc, argv, &rc)) { return 1; } state = cli_state_create(); if (!state) { fprintf(stderr, "Failed to create state object\n"); return 1; } bladerf_log_set_verbosity(rc.verbosity); if (rc.show_help) { usage(argv[0]); exit_immediately = true; } else if (rc.show_version) { printf(BLADERF_CLI_VERSION "\n"); exit_immediately = true; } else if (rc.show_lib_version) { struct bladerf_version version; bladerf_version(&version); printf("%s\n", version.describe); exit_immediately = true; } else if (rc.probe) { status = cmd_handle(state, "probe"); exit_immediately = true; } if (!exit_immediately) { /* Conditionally performed items, depending on runtime config */ status = open_device(&rc, state, status); if (status) { fprintf(stderr, "Could not open device\n"); goto main__issues ; } status = flash_fw(&rc, state, status); if (status) { fprintf(stderr, "Could not flash firmware\n"); goto main__issues ; } status = flash_fpga(&rc, state, status); if (status) { fprintf(stderr, "Could not flash fpga\n"); goto main__issues ; } status = load_fpga(&rc, state, status); if (status) { fprintf(stderr, "Could not load fpga\n"); goto main__issues ; } status = open_script(&rc, state, status); if (status) { fprintf(stderr, "Could not load scripts\n"); goto main__issues ; } main__issues: /* These items are no longer needed */ free(rc.device); rc.device = NULL; free(rc.fw_file); rc.fw_file = NULL; free(rc.fpga_file); rc.fpga_file = NULL; free(rc.script_file); rc.script_file = NULL; /* Drop into interactive mode or begin executing commands * from a script. If we're not requested to do either, exit cleanly */ if (rc.interactive_mode || state->script != NULL) { status = interactive(state, !rc.interactive_mode); } } cli_state_destroy(state); return status; }
int main(int argc, char *argv[]) { int status = 0; struct rc_config rc; struct cli_state *state; bool exit_immediately = false; struct str_queue exec_list; /* If no actions are specified, just show the usage text and exit */ if (argc == 1) { usage(argv[0]); return 0; } str_queue_init(&exec_list); init_rc_config(&rc); if (get_rc_config(argc, argv, &rc, &exec_list)) { return 1; } state = cli_state_create(); if (!state) { fprintf(stderr, "Failed to create state object\n"); return 1; } state->exec_list = &exec_list; bladerf_log_set_verbosity(rc.verbosity); if (rc.show_help) { usage(argv[0]); exit_immediately = true; } else if (rc.show_help_interactive) { printf("Interactive Commands:\n\n"); cmd_show_help_all(); exit_immediately = true; } else if (rc.show_version) { printf(BLADERF_CLI_VERSION "\n"); exit_immediately = true; } else if (rc.show_lib_version) { struct bladerf_version version; bladerf_version(&version); printf("%s\n", version.describe); exit_immediately = true; } else if (rc.probe) { status = cmd_handle(state, "probe strict"); exit_immediately = true; } if (!exit_immediately) { check_for_bootloader_devs(); /* Conditionally performed items, depending on runtime config */ status = open_device(&rc, state, status); if (status) { goto main_issues; } status = flash_fw(&rc, state, status); if (status) { goto main_issues; } status = flash_fpga(&rc, state, status); if (status) { goto main_issues; } status = load_fpga(&rc, state, status); if (status) { goto main_issues; } if (rc.script_file) { status = cli_open_script(&state->scripts, rc.script_file); if (status != 0) { fprintf(stderr, "Failed to open script file \"%s\": %s\n", rc.script_file, strerror(-status)); goto main_issues; } } /* Drop into interactive mode or begin executing commands from a a * command-line list or a script. If we're not requested to do either, * exit cleanly */ if (!str_queue_empty(&exec_list) || rc.interactive_mode || cli_script_loaded(state->scripts)) { status = cli_start_tasks(state); if (status == 0) { status = input_loop(state, rc.interactive_mode); } } } main_issues: cli_state_destroy(state); str_queue_deinit(&exec_list); deinit_rc_config(&rc); return status; }
static void run() { cmd_t* cmd = cmd_create(".history", "~>"); cmd_register(cmd, "base conhash", test_base_conhash); cmd_register(cmd, "base bitset", test_base_bitset); cmd_register(cmd, "base heap", test_base_heap); cmd_register(cmd, "base rbtree", test_base_rbtree); cmd_register(cmd, "base rbuffer", test_base_rbuffer); cmd_register(cmd, "base slist", test_base_slist); cmd_register(cmd, "base skiplist", test_base_skiplist); cmd_register(cmd, "base skiplist find", test_base_skiplist_find); cmd_register(cmd, "base skiplist duplicate", test_base_skiplist_duplicate); cmd_register(cmd, "base timer", test_base_timer); cmd_register(cmd, "core atomic", test_core_atomic); #ifdef OS_LINUX // seems some memory error ... // cmd_register(cmd, "core coroutine", test_core_coroutine); #endif cmd_register(cmd, "core fsm", test_core_fsm); cmd_register(cmd, "core lock", test_core_lock); cmd_register(cmd, "core spin", test_core_spin); cmd_register(cmd, "core thread", test_core_thread); cmd_register(cmd, "logic dirty", test_logic_dirty); cmd_register(cmd, "logic task", test_logic_task); cmd_register(cmd, "mm slab", test_mm_slab); cmd_register(cmd, "mm shm", test_mm_shm); cmd_register(cmd, "net curl", test_net_curl); cmd_register(cmd, "net echo", test_net_echo); cmd_register(cmd, "util base64", test_util_base64); cmd_register(cmd, "util cjson text", test_util_cjson_text); cmd_register(cmd, "util cjson file", test_util_cjson_file); cmd_register(cmd, "util cjson create", test_util_cjson_create); cmd_register(cmd, "util dh", test_util_dh); cmd_register(cmd, "util dh perf", test_util_dh_perf); cmd_register(cmd, "util random", test_util_random); cmd_register(cmd, "util shuffle", test_util_shuffle); cmd_register(cmd, "util unicode", test_util_unicode); cmd_register(cmd, "util wscode", test_util_wscode); // unit test mode if (mode_all) { int res = cmd_traverse(cmd, NULL, traverse_callback); if (res < 0) { fprintf(stderr, "\033[%dm--> [RUN ALL TEST CASES FAILURE] <--\033[0m\n\n", COLOR_RED); cmd_release(cmd); exit(res); } } // interact mode if (mode_interact) { while (1) { char* line = cmd_readline(cmd); if (!line) { break; } int ret = cmd_handle(cmd, line); traverse_callback(line, ret); free(line); if (cmd_eof(cmd)) { if (cmd_closed(cmd)) { break; } } } } cmd_release(cmd); }