Skip to content

Commit f955a9a

Browse files
committed
Fix halcmd debug (uspace only)
1 parent 4950963 commit f955a9a

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/hal/utils/halcmd_commands.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,18 @@ int do_unlinkp_cmd(char *pin)
241241
}
242242

243243
int do_set_debug_cmd(char* level){
244-
int new_level = atoi(level);
245-
if (new_level < 0 || new_level > 5){
246-
halcmd_error("Debug level must be >=0 and <= 5\n");
247-
return -EINVAL;
248-
}
249-
return rtapi_set_msg_level(atoi(level));
244+
int m=0,retval=-EINVAL;
245+
const char *argv[4];
246+
#if defined(RTAPI_USPACE)
247+
argv[m++] = EMC2_BIN_DIR "/rtapi_app";
248+
argv[m++] = "debug";
249+
argv[m++] = level;
250+
argv[m++] = NULL;
251+
retval = hal_systemv(argv);
252+
#else
253+
halcmd_error("debug: not implemented for anything else than uspace\n");
254+
#endif
255+
return retval;
250256
}
251257

252258
int do_source_cmd(char *hal_filename) {

src/rtapi/uspace_rtapi_app.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,21 @@ static int do_unload_cmd(const string& name) {
329329
return 0;
330330
}
331331

332+
static int do_debug_cmd(const string& value) {
333+
try{
334+
int new_level = stoi(value);
335+
if (new_level < 0 || new_level > 5){
336+
rtapi_print_msg(RTAPI_MSG_ERR, "Debug level must be >=0 and <= 5\n");
337+
return -EINVAL;
338+
}
339+
return rtapi_set_msg_level(new_level);
340+
}catch(invalid_argument &e){
341+
//stoi will throw an exception if parsing is not possible
342+
rtapi_print_msg(RTAPI_MSG_ERR, "Debug level is not a number\n");
343+
return -EINVAL;
344+
}
345+
}
346+
332347
struct ReadError : std::exception {};
333348
struct WriteError : std::exception {};
334349

@@ -403,6 +418,8 @@ static int handle_command(vector<string> args) {
403418
return do_newinst_cmd(args[1], args[2], "");
404419
} else if(args.size() == 4 && args[0] == "newinst") {
405420
return do_newinst_cmd(args[1], args[2], args[3]);
421+
} else if(args.size() == 2 && args[0] == "debug") {
422+
return do_debug_cmd(args[1]);
406423
} else {
407424
rtapi_print_msg(RTAPI_MSG_ERR,
408425
"Unrecognized command starting with %s\n",

0 commit comments

Comments
 (0)