mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-21 04:33:10 +08:00
3e37a74173
Make PX4 startup, daemon command handling, shell I/O, shutdown, logging, getopt, and instance state work across POSIX and native Windows runtime boundaries. Keep command-client behavior explicit by routing shell output through shared logger paths and preserving socket protocol return markers during shutdown.
88 lines
2.0 KiB
Plaintext
88 lines
2.0 KiB
Plaintext
/* definitions of builtin command list - automatically generated, do not edit */
|
|
#include <px4_platform_common/time.h>
|
|
#include <px4_platform_common/posix.h>
|
|
#include <px4_platform_common/log.h>
|
|
#include <px4_platform_common/exit.h>
|
|
#include <uORB/uORB.h>
|
|
|
|
#include "apps.h"
|
|
|
|
#include <cstdio>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#include <cstdlib>
|
|
|
|
#define MODULE_NAME "px4"
|
|
|
|
extern "C" {
|
|
|
|
${builtin_apps_decl_string}
|
|
int shutdown_main(int argc, char *argv[]);
|
|
int list_tasks_main(int argc, char *argv[]);
|
|
int list_files_main(int argc, char *argv[]);
|
|
int sleep_main(int argc, char *argv[]);
|
|
|
|
}
|
|
|
|
void init_app_map(apps_map_type &apps)
|
|
{
|
|
${builtin_apps_string}
|
|
apps["shutdown"] = shutdown_main;
|
|
apps["list_tasks"] = list_tasks_main;
|
|
apps["list_files"] = list_files_main;
|
|
apps["sleep"] = sleep_main;
|
|
}
|
|
|
|
void list_builtins(apps_map_type &apps)
|
|
{
|
|
printf("Builtin Commands:\n");
|
|
for (apps_map_type::iterator it = apps.begin(); it != apps.end(); ++it) {
|
|
printf(" %s\n", it->first.c_str());
|
|
}
|
|
}
|
|
|
|
int shutdown_main(int argc, char *argv[])
|
|
{
|
|
// Reject any leftover positional arguments (e.g. "status", "start", "stop").
|
|
// shutdown takes no flags or subcommands -- it always tears the daemon
|
|
// down -- so silently ignoring extra args would terminate the daemon when
|
|
// the user almost certainly meant a different module (e.g.
|
|
// "<module> status"). Print usage and exit non-zero instead.
|
|
if (argc > 1) {
|
|
PX4_ERR("unrecognized argument: %s", argv[1]);
|
|
printf("Usage:\n shutdown\n");
|
|
return 1;
|
|
}
|
|
|
|
printf("Exiting NOW.\n");
|
|
uorb_shutdown();
|
|
px4_platform_exit(0);
|
|
return 0;
|
|
}
|
|
|
|
int list_tasks_main(int argc, char *argv[])
|
|
{
|
|
px4_show_tasks();
|
|
return 0;
|
|
}
|
|
|
|
int list_files_main(int argc, char *argv[])
|
|
{
|
|
px4_show_files();
|
|
return 0;
|
|
}
|
|
|
|
int sleep_main(int argc, char *argv[])
|
|
{
|
|
if (argc != 2) {
|
|
PX4_WARN( "Usage: sleep <seconds>" );
|
|
return 1;
|
|
}
|
|
|
|
unsigned long usecs = 1000000UL * atol(argv[1]);
|
|
printf("Sleeping for %s s; (%lu us).\n", argv[1], usecs);
|
|
px4_usleep(usecs);
|
|
return 0;
|
|
}
|