mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 00:43:35 +08:00
introduce uORB::PublicationQueued and transition most orb_advertise_queue usage
This commit is contained in:
@@ -45,9 +45,10 @@
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <drivers/drv_led.h>
|
||||
|
||||
static void usage();
|
||||
#include <uORB/PublicationQueued.hpp>
|
||||
#include <uORB/topics/led_control.h>
|
||||
|
||||
static orb_advert_t led_control_pub = nullptr;
|
||||
static void usage();
|
||||
|
||||
extern "C" {
|
||||
__EXPORT int led_control_main(int argc, char *argv[]);
|
||||
@@ -57,12 +58,8 @@ static void publish_led_control(led_control_s &led_control)
|
||||
{
|
||||
led_control.timestamp = hrt_absolute_time();
|
||||
|
||||
if (led_control_pub == nullptr) {
|
||||
led_control_pub = orb_advertise_queue(ORB_ID(led_control), &led_control, LED_UORB_QUEUE_LENGTH);
|
||||
|
||||
} else {
|
||||
orb_publish(ORB_ID(led_control), led_control_pub, &led_control);
|
||||
}
|
||||
uORB::PublicationQueued<led_control_s> led_control_pub{ORB_ID(led_control)};
|
||||
led_control_pub.publish(led_control);
|
||||
}
|
||||
|
||||
static void run_led_test1()
|
||||
|
||||
@@ -36,7 +36,7 @@ px4_add_module(
|
||||
STACK_MAIN 4096
|
||||
COMPILE_FLAGS
|
||||
SRCS
|
||||
motor_test.c
|
||||
motor_test.cpp
|
||||
DEPENDS
|
||||
)
|
||||
|
||||
|
||||
@@ -38,48 +38,30 @@
|
||||
* Tool for drive testing
|
||||
*/
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <px4_config.h>
|
||||
#include <px4_getopt.h>
|
||||
#include <px4_log.h>
|
||||
#include <px4_module.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <arch/board/board.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <uORB/PublicationQueued.hpp>
|
||||
#include <uORB/topics/test_motor.h>
|
||||
|
||||
|
||||
|
||||
|
||||
__EXPORT int motor_test_main(int argc, char *argv[]);
|
||||
extern "C" __EXPORT int motor_test_main(int argc, char *argv[]);
|
||||
|
||||
static void motor_test(unsigned channel, float value);
|
||||
static void usage(const char *reason);
|
||||
|
||||
static orb_advert_t _test_motor_pub = NULL;
|
||||
|
||||
void motor_test(unsigned channel, float value)
|
||||
{
|
||||
struct test_motor_s _test_motor;
|
||||
test_motor_s test_motor{};
|
||||
test_motor.timestamp = hrt_absolute_time();
|
||||
test_motor.motor_number = channel;
|
||||
test_motor.value = value;
|
||||
|
||||
_test_motor.motor_number = channel;
|
||||
_test_motor.timestamp = hrt_absolute_time();
|
||||
_test_motor.value = value;
|
||||
uORB::PublicationQueued<test_motor_s> test_motor_pub{ORB_ID(test_motor)};
|
||||
test_motor_pub.publish(test_motor);
|
||||
|
||||
if (_test_motor_pub != NULL) {
|
||||
/* publish test state */
|
||||
orb_publish(ORB_ID(test_motor), _test_motor_pub, &_test_motor);
|
||||
|
||||
} else {
|
||||
/* advertise and publish */
|
||||
_test_motor_pub = orb_advertise_queue(ORB_ID(test_motor), &_test_motor, 4);
|
||||
}
|
||||
|
||||
printf("motor %d set to %.2f\n", channel, (double)value);
|
||||
PX4_INFO("motor %d set to %.2f", channel, (double)value);
|
||||
}
|
||||
|
||||
static void usage(const char *reason)
|
||||
Reference in New Issue
Block a user