Add modified Px4 Simple App for SLIP testing (couldn't compile)

This commit is contained in:
Junwoo Hwang 2022-10-05 15:47:34 +02:00
parent 5df558f1cb
commit baa0e8a46d

View File

@ -33,7 +33,9 @@
/**
* @file px4_simple_app.c
* Minimal application example for PX4 autopilot
*
* Simple app to test SLIP utility.
* Partial copy of platforms/nuttx/NuttX/apps/examples/thttpd/thttpd_main.c
*
* @author Example User <mail@example.com>
*/
@ -41,86 +43,61 @@
#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/tasks.h>
#include <px4_platform_common/posix.h>
#include <unistd.h>
#include <stdio.h>
#include <poll.h>
#include <string.h>
#include <math.h>
// #include <unistd.h>
// #include <stdio.h>
// #include <poll.h>
// #include <string.h>
// #include <math.h>
// #include "netutils/netlib.h"
/* Include SLIP related libraries / macro defs */
#ifdef CONFIG_NET_SLIP
/* TTY device to use */
#pragma message "NET_SLIP is enabled, adding the libraries!"
// # include <nuttx/net/net.h>
# include <nuttx/net/slip.h>
# ifndef CONFIG_NET_SLIPTTY
# define CONFIG_NET_SLIPTTY "/dev/ttyS4"
# endif
# define SLIP_DEVNO 0
# ifndef NET_DEVNAME
# define NET_DEVNAME "sl0"
# endif
#endif
#include <uORB/uORB.h>
#include <uORB/topics/vehicle_acceleration.h>
#include <uORB/topics/vehicle_attitude.h>
__EXPORT int px4_simple_app_main(int argc, char *argv[]);
int px4_simple_app_main(int argc, char *argv[])
{
PX4_INFO("Hello Sky!");
PX4_INFO("PX4 Simple SLIP Testing App!");
/* subscribe to vehicle_acceleration topic */
int sensor_sub_fd = orb_subscribe(ORB_ID(vehicle_acceleration));
/* limit the update rate to 5 Hz */
orb_set_interval(sensor_sub_fd, 200);
/* Sanity Checks */
// static_assert(CONFIG_NET_SLIPTTY == "/dev/ttyS4");
/* advertise attitude topic */
struct vehicle_attitude_s att;
memset(&att, 0, sizeof(att));
orb_advert_t att_pub = orb_advertise(ORB_ID(vehicle_attitude), &att);
/* Configure SLIP */
/* one could wait for multiple topics with this technique, just using one here */
px4_pollfd_struct_t fds[] = {
{ .fd = sensor_sub_fd, .events = POLLIN },
/* there could be more file descriptors here, in the form like:
* { .fd = other_sub_fd, .events = POLLIN },
*/
};
#ifdef CONFIG_NET_SLIP
int ret = slip_initialize(SLIP_DEVNO, CONFIG_NET_SLIPTTY);
int error_counter = 0;
if (ret < 0) {
printf("ERROR: SLIP initialization failed: %d\n", ret);
exit(1);
}
for (int i = 0; i < 5; i++) {
/* wait for sensor update of 1 file descriptor for 1000 ms (1 second) */
int poll_ret = px4_poll(fds, 1, 1000);
#endif
/* handle the poll result */
if (poll_ret == 0) {
/* this means none of our providers is giving us data */
PX4_ERR("Got no data within a second");
} else if (poll_ret < 0) {
/* this is seriously bad - should be an emergency */
if (error_counter < 10 || error_counter % 50 == 0) {
/* use a counter to prevent flooding (and slowing us down) */
PX4_ERR("ERROR return value from poll(): %d", poll_ret);
}
error_counter++;
} else {
if (fds[0].revents & POLLIN) {
/* obtained data for the first file descriptor */
struct vehicle_acceleration_s accel;
/* copy sensors raw data into local buffer */
orb_copy(ORB_ID(vehicle_acceleration), sensor_sub_fd, &accel);
PX4_INFO("Accelerometer:\t%8.4f\t%8.4f\t%8.4f",
(double)accel.xyz[0],
(double)accel.xyz[1],
(double)accel.xyz[2]);
/* set att and publish this information for other apps
the following does not have any meaning, it's just an example
*/
att.q[0] = accel.xyz[0];
att.q[1] = accel.xyz[1];
att.q[2] = accel.xyz[2];
orb_publish(ORB_ID(vehicle_attitude), att_pub, &att);
}
/* there could be more file descriptors here, in the form like:
* if (fds[1..n].revents & POLLIN) {}
*/
}
// Idle by just sleeping for 1 second continuously
while (true) {
px4_usleep(1E6);
}
PX4_INFO("exiting");