mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 02:13:33 +08:00
module_base: remove CRTP template pattern to reduce flash bloat (#26476)
* module_base: claude rewrite to remove CRTP bloat * module_base: apply to all drivers/modules * format * fix build errors * fix missing syntax * remove reference to module.h in files that need module_base.h * remove old ModuleBase<T> * add module_base.cpp to px4_protected_layers.cmake * fix IridiumSBD can_stop() * fix IridiumSBD.cpp * clang-tidy: downcast static cast * get_instance() template accessor, revert clang-tidy global * rename module_base.h to module.h * revert changes in zenoh/Kconfig.topics
This commit is contained in:
@@ -47,6 +47,8 @@
|
||||
#include <systemlib/err.h>
|
||||
#include <parameters/param.h>
|
||||
|
||||
ModuleBase::Descriptor IridiumSBD::desc{task_spawn, custom_command, print_usage};
|
||||
|
||||
static constexpr const char *satcom_state_string[4] = {"STANDBY", "SIGNAL CHECK", "SBD SESSION", "TEST"};
|
||||
|
||||
#define VERBOSE_INFO(...) if (_verbose) { PX4_INFO(__VA_ARGS__); }
|
||||
@@ -63,23 +65,30 @@ IridiumSBD::~IridiumSBD()
|
||||
deinit();
|
||||
}
|
||||
|
||||
int IridiumSBD::run_trampoline(int argc, char *argv[])
|
||||
{
|
||||
return ModuleBase::run_trampoline_impl(desc, [](int ac, char *av[]) -> ModuleBase * {
|
||||
return IridiumSBD::instantiate(ac, av);
|
||||
}, argc, argv);
|
||||
}
|
||||
|
||||
int IridiumSBD::task_spawn(int argc, char *argv[])
|
||||
{
|
||||
_task_id = px4_task_spawn_cmd("iridiumsbd",
|
||||
SCHED_DEFAULT,
|
||||
SCHED_PRIORITY_SLOW_DRIVER,
|
||||
1350,
|
||||
(px4_main_t)&run_trampoline,
|
||||
(char *const *)argv);
|
||||
desc.task_id = px4_task_spawn_cmd("iridiumsbd",
|
||||
SCHED_DEFAULT,
|
||||
SCHED_PRIORITY_SLOW_DRIVER,
|
||||
1350,
|
||||
(px4_main_t)&run_trampoline,
|
||||
(char *const *)argv);
|
||||
|
||||
if (_task_id < 0) {
|
||||
_task_id = -1;
|
||||
if (desc.task_id < 0) {
|
||||
desc.task_id = -1;
|
||||
return -errno;
|
||||
}
|
||||
|
||||
// wait until task is up & running (max 6 seconds)
|
||||
if (wait_until_running(6000) < 0) {
|
||||
_task_id = -1;
|
||||
if (wait_until_running(desc, 6000) < 0) {
|
||||
desc.task_id = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1080,13 +1089,13 @@ Creates a virtual serial port that another module can use for communication (e.g
|
||||
|
||||
int IridiumSBD::custom_command(int argc, char *argv[])
|
||||
{
|
||||
if (!is_running()) {
|
||||
if (!is_running(desc)) {
|
||||
print_usage("not running");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[0], "test")) {
|
||||
get_instance()->test(argc, argv);
|
||||
get_instance<IridiumSBD>(desc)->test(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1095,12 +1104,12 @@ int IridiumSBD::custom_command(int argc, char *argv[])
|
||||
|
||||
extern "C" __EXPORT int iridiumsbd_main(int argc, char *argv[])
|
||||
{
|
||||
if (argc >= 2 && !strcmp(argv[1], "stop") && IridiumSBD::is_running()) {
|
||||
if (argc >= 2 && !strcmp(argv[1], "stop") && IridiumSBD::is_running(IridiumSBD::desc)) {
|
||||
if (!IridiumSBD::can_stop()) {
|
||||
PX4_ERR("Device is used. Stop all users first (mavlink stop-all)");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return IridiumSBD::main(argc, argv);
|
||||
return ModuleBase::main(IridiumSBD::desc, argc, argv);
|
||||
}
|
||||
|
||||
@@ -99,15 +99,20 @@ typedef enum {
|
||||
* - Improve TX buffer handling:
|
||||
* - Do not reset the full TX buffer but delete the oldest HIGH_LATENCY2 message if one is in the buffer or delete the oldest message in general
|
||||
*/
|
||||
class IridiumSBD : public cdev::CDev, public ModuleBase<IridiumSBD>
|
||||
class IridiumSBD : public cdev::CDev, public ModuleBase
|
||||
{
|
||||
public:
|
||||
static Descriptor desc;
|
||||
|
||||
IridiumSBD();
|
||||
~IridiumSBD();
|
||||
|
||||
/** @see ModuleBase */
|
||||
static int task_spawn(int argc, char *argv[]);
|
||||
|
||||
/** @see ModuleBase */
|
||||
static int run_trampoline(int argc, char *argv[]);
|
||||
|
||||
/** @see ModuleBase */
|
||||
static IridiumSBD *instantiate(int argc, char *argv[]);
|
||||
|
||||
@@ -136,7 +141,7 @@ public:
|
||||
*/
|
||||
int ioctl(struct file *filp, int cmd, unsigned long arg);
|
||||
|
||||
static bool can_stop() { return !get_instance()->_cdev_used.load(); }
|
||||
static bool can_stop() { return !get_instance<IridiumSBD>(desc)->_cdev_used.load(); }
|
||||
|
||||
private:
|
||||
int init(int argc, char *argv[]);
|
||||
|
||||
Reference in New Issue
Block a user