mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 02:43: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:
+22
-17
@@ -99,9 +99,11 @@ using namespace time_literals;
|
||||
*
|
||||
* Encapsulates PX4FMU to PX4IO communications modeled as file operations.
|
||||
*/
|
||||
class PX4IO : public cdev::CDev, public ModuleBase<PX4IO>, public OutputModuleInterface
|
||||
class PX4IO : public cdev::CDev, public ModuleBase, public OutputModuleInterface
|
||||
{
|
||||
public:
|
||||
static Descriptor desc;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -339,6 +341,8 @@ private:
|
||||
)
|
||||
};
|
||||
|
||||
ModuleBase::Descriptor PX4IO::desc{task_spawn, custom_command, print_usage};
|
||||
|
||||
#define PX4IO_DEVICE_PATH "/dev/px4io"
|
||||
|
||||
PX4IO::PX4IO(device::Device *interface) :
|
||||
@@ -512,7 +516,7 @@ void PX4IO::Run()
|
||||
ScheduleClear();
|
||||
_mixing_output.unregister();
|
||||
|
||||
exit_and_cleanup();
|
||||
exit_and_cleanup(desc);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1513,7 +1517,8 @@ int PX4IO::bind(int argc, char *argv[])
|
||||
pulses = atoi(argv[1]);
|
||||
}
|
||||
|
||||
get_instance()->ioctl(nullptr, DSM_BIND_START, pulses);
|
||||
get_instance<PX4IO>(desc)->ioctl(nullptr, DSM_BIND_START, pulses);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1529,8 +1534,8 @@ int PX4IO::task_spawn(int argc, char *argv[])
|
||||
PX4IO *instance = new PX4IO(interface);
|
||||
|
||||
if (instance) {
|
||||
_object.store(instance);
|
||||
_task_id = task_id_is_work_queue;
|
||||
desc.object.store(instance);
|
||||
desc.task_id = task_id_is_work_queue;
|
||||
|
||||
if (instance->init() == PX4_OK) {
|
||||
return PX4_OK;
|
||||
@@ -1541,8 +1546,8 @@ int PX4IO::task_spawn(int argc, char *argv[])
|
||||
}
|
||||
|
||||
delete instance;
|
||||
_object.store(nullptr);
|
||||
_task_id = -1;
|
||||
desc.object.store(nullptr);
|
||||
desc.task_id = -1;
|
||||
|
||||
return PX4_ERROR;
|
||||
}
|
||||
@@ -1556,7 +1561,7 @@ int PX4IO::custom_command(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!strcmp(verb, "checkcrc")) {
|
||||
if (is_running()) {
|
||||
if (is_running(desc)) {
|
||||
PX4_ERR("io must be stopped");
|
||||
return 1;
|
||||
}
|
||||
@@ -1566,7 +1571,7 @@ int PX4IO::custom_command(int argc, char *argv[])
|
||||
|
||||
if (!strcmp(verb, "update")) {
|
||||
|
||||
if (is_running()) {
|
||||
if (is_running(desc)) {
|
||||
PX4_ERR("io must be stopped");
|
||||
return 1;
|
||||
}
|
||||
@@ -1656,7 +1661,7 @@ int PX4IO::custom_command(int argc, char *argv[])
|
||||
|
||||
|
||||
/* commands below here require a started driver */
|
||||
if (!is_running()) {
|
||||
if (!is_running(desc)) {
|
||||
PX4_ERR("not running");
|
||||
return 1;
|
||||
}
|
||||
@@ -1668,7 +1673,7 @@ int PX4IO::custom_command(int argc, char *argv[])
|
||||
}
|
||||
|
||||
uint8_t level = atoi(argv[1]);
|
||||
int ret = get_instance()->ioctl(nullptr, PX4IO_SET_DEBUG, level);
|
||||
int ret = get_instance<PX4IO>(desc)->ioctl(nullptr, PX4IO_SET_DEBUG, level);
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("SET_DEBUG failed: %d", ret);
|
||||
@@ -1680,7 +1685,7 @@ int PX4IO::custom_command(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!strcmp(verb, "bind")) {
|
||||
if (!is_running()) {
|
||||
if (!is_running(desc)) {
|
||||
PX4_ERR("io must be running");
|
||||
return 1;
|
||||
}
|
||||
@@ -1689,7 +1694,7 @@ int PX4IO::custom_command(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!strcmp(verb, "sbus1_out")) {
|
||||
int ret = get_instance()->ioctl(nullptr, SBUS_SET_PROTO_VERSION, 1);
|
||||
int ret = get_instance<PX4IO>(desc)->ioctl(nullptr, SBUS_SET_PROTO_VERSION, 1);
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("S.BUS v1 failed (%i)", ret);
|
||||
@@ -1700,7 +1705,7 @@ int PX4IO::custom_command(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!strcmp(verb, "sbus2_out")) {
|
||||
int ret = get_instance()->ioctl(nullptr, SBUS_SET_PROTO_VERSION, 2);
|
||||
int ret = get_instance<PX4IO>(desc)->ioctl(nullptr, SBUS_SET_PROTO_VERSION, 2);
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("S.BUS v2 failed (%i)", ret);
|
||||
@@ -1711,12 +1716,12 @@ int PX4IO::custom_command(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!strcmp(verb, "test_fmu_fail")) {
|
||||
get_instance()->test_fmu_fail(true);
|
||||
get_instance<PX4IO>(desc)->test_fmu_fail(true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(verb, "test_fmu_ok")) {
|
||||
get_instance()->test_fmu_fail(false);
|
||||
get_instance<PX4IO>(desc)->test_fmu_fail(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1764,5 +1769,5 @@ extern "C" __EXPORT int px4io_main(int argc, char *argv[])
|
||||
PX4_INFO("PX4IO Not Supported");
|
||||
return -1;
|
||||
}
|
||||
return PX4IO::main(argc, argv);
|
||||
return ModuleBase::main(PX4IO::desc, argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user