Skip to content

Commit 1edca3a

Browse files
committed
Getrt command
1 parent 888cb94 commit 1edca3a

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/hal/utils/halcmd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ struct halcmd_command halcmd_commands[] = {
140140
{"delf", FUNCT(do_delf_cmd, cp_cp), A_TWO | A_OPTIONAL },
141141
{"delsig", FUNCT(do_delsig_cmd, cp), A_ONE },
142142
{"debug", FUNCT(do_set_debug_cmd, cp), A_ONE },
143+
{"getrt", FUNCT(do_getrt_cmd, v), A_ZERO },
143144
{"echo", FUNCT(do_echo_cmd, v), A_ZERO },
144145
{"getp", FUNCT(do_getp_cmd, cp), A_ONE },
145146
{"gets", FUNCT(do_gets_cmd, cp), A_ONE },

src/hal/utils/halcmd_commands.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,26 @@ int do_set_debug_cmd(char* level){
255255
return retval;
256256
}
257257

258+
int do_getrt_cmd(void){
259+
int m=0,retval=-EINVAL;
260+
const char *argv[4];
261+
#if defined(RTAPI_USPACE)
262+
argv[m++] = EMC2_BIN_DIR "/rtapi_app";
263+
argv[m++] = "getrt";
264+
argv[m++] = NULL;
265+
retval = hal_systemv(argv);
266+
if(retval){
267+
halcmd_error("No realtime available\n");
268+
}else{
269+
halcmd_output("Realtime available\n");
270+
}
271+
#else
272+
halcmd_output("Realtime available, running in kernel\n");
273+
retval = 0;
274+
#endif
275+
return retval;
276+
}
277+
258278
int do_source_cmd(char *hal_filename) {
259279
FILE *f = fopen(hal_filename, "r");
260280
char buf[MAX_CMD_LEN+1];

src/hal/utils/halcmd_commands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ extern int do_list_cmd(char *type, char **patterns);
7777
extern int do_source_cmd(char *type);
7878
extern int do_status_cmd(char *type);
7979
extern int do_set_debug_cmd(char *level);
80+
extern int do_getrt_cmd(void);
8081
extern int do_delsig_cmd(char *mod_name);
8182
extern int do_loadrt_cmd(char *mod_name, char *args[]);
8283
extern int do_unlinkp_cmd(char *mod_name);

src/rtapi/uspace_rtapi_main.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@ static int do_debug_cmd(const std::string &value) {
307307
}
308308
}
309309

310+
static int do_getrt_cmd(void) {
311+
try {
312+
return rtapi_is_realtime() == 0;
313+
} catch (std::invalid_argument &e) {
314+
//stoi will throw an exception if parsing is not possible
315+
rtapi_print_msg(RTAPI_MSG_ERR, "Debug level is not a number\n");
316+
return -EINVAL;
317+
}
318+
}
319+
310320
/*
311321
* Fully checked send/recv
312322
* Will retry on EINTR, so to abort a send_data/recv_data on a
@@ -557,6 +567,8 @@ static int handle_command(const std::vector<std::string> &args) {
557567
return do_newinst_cmd(args[1], args[2], args[3]);
558568
} else if (args.size() == 2 && args[0] == "debug") {
559569
return do_debug_cmd(args[1]);
570+
} else if (args.size() == 1 && args[0] == "getrt") {
571+
return do_getrt_cmd();
560572
} else {
561573
rtapi_print_msg(RTAPI_MSG_ERR, "Unrecognized command starting with %s\n", args[0].c_str());
562574
return -1;

0 commit comments

Comments
 (0)