mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 22:33:34 +08:00
QuRT and POSIX changes - part 5
Last part of the main QuRT related changes Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
@@ -42,11 +42,12 @@
|
|||||||
#include "commander_helper.h"
|
#include "commander_helper.h"
|
||||||
|
|
||||||
#include <px4_posix.h>
|
#include <px4_posix.h>
|
||||||
|
#include <px4_time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <drivers/drv_hrt.h>
|
#include <drivers/drv_hrt.h>
|
||||||
#include <uORB/topics/sensor_combined.h>
|
#include <uORB/topics/sensor_combined.h>
|
||||||
@@ -193,9 +194,9 @@ int do_gyro_calibration(int mavlink_fd)
|
|||||||
/* maximum allowable calibration error in radians */
|
/* maximum allowable calibration error in radians */
|
||||||
const float maxoff = 0.0055f;
|
const float maxoff = 0.0055f;
|
||||||
|
|
||||||
if (!isfinite(gyro_scale[0].x_offset) ||
|
if (!PX4_ISFINITE(gyro_scale[0].x_offset) ||
|
||||||
!isfinite(gyro_scale[0].y_offset) ||
|
!PX4_ISFINITE(gyro_scale[0].y_offset) ||
|
||||||
!isfinite(gyro_scale[0].z_offset) ||
|
!PX4_ISFINITE(gyro_scale[0].z_offset) ||
|
||||||
fabsf(xdiff) > maxoff ||
|
fabsf(xdiff) > maxoff ||
|
||||||
fabsf(ydiff) > maxoff ||
|
fabsf(ydiff) > maxoff ||
|
||||||
fabsf(zdiff) > maxoff) {
|
fabsf(zdiff) > maxoff) {
|
||||||
|
|||||||
@@ -43,12 +43,13 @@
|
|||||||
#include "calibration_messages.h"
|
#include "calibration_messages.h"
|
||||||
|
|
||||||
#include <px4_posix.h>
|
#include <px4_posix.h>
|
||||||
|
#include <px4_time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <drivers/drv_hrt.h>
|
#include <drivers/drv_hrt.h>
|
||||||
#include <drivers/drv_accel.h>
|
#include <drivers/drv_accel.h>
|
||||||
@@ -376,7 +377,7 @@ int mag_calibrate_all(int mavlink_fd, int32_t (&device_ids)[max_mags])
|
|||||||
&sphere_x[cur_mag], &sphere_y[cur_mag], &sphere_z[cur_mag],
|
&sphere_x[cur_mag], &sphere_y[cur_mag], &sphere_z[cur_mag],
|
||||||
&sphere_radius[cur_mag]);
|
&sphere_radius[cur_mag]);
|
||||||
|
|
||||||
if (!isfinite(sphere_x[cur_mag]) || !isfinite(sphere_y[cur_mag]) || !isfinite(sphere_z[cur_mag])) {
|
if (!PX4_ISFINITE(sphere_x[cur_mag]) || !PX4_ISFINITE(sphere_y[cur_mag]) || !PX4_ISFINITE(sphere_z[cur_mag])) {
|
||||||
mavlink_and_console_log_info(mavlink_fd, "ERROR: NaN in sphere fit for mag #%u", cur_mag);
|
mavlink_and_console_log_info(mavlink_fd, "ERROR: NaN in sphere fit for mag #%u", cur_mag);
|
||||||
result = ERROR;
|
result = ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,9 @@
|
|||||||
* Remote Control calibration routine
|
* Remote Control calibration routine
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <px4_posix.h>
|
||||||
|
#include <px4_time.h>
|
||||||
|
|
||||||
#include "rc_calibration.h"
|
#include "rc_calibration.h"
|
||||||
#include "commander_helper.h"
|
#include "commander_helper.h"
|
||||||
|
|
||||||
@@ -82,11 +85,11 @@ int do_trim_calibration(int mavlink_fd)
|
|||||||
|
|
||||||
if (save_ret != 0) {
|
if (save_ret != 0) {
|
||||||
mavlink_log_critical(mavlink_fd, "TRIM: SAVE FAIL");
|
mavlink_log_critical(mavlink_fd, "TRIM: SAVE FAIL");
|
||||||
close(sub_man);
|
px4_close(sub_man);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
mavlink_log_info(mavlink_fd, "trim cal done");
|
mavlink_log_info(mavlink_fd, "trim cal done");
|
||||||
close(sub_man);
|
px4_close(sub_man);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,9 +112,11 @@ public:
|
|||||||
|
|
||||||
static void forward_message(const mavlink_message_t *msg, Mavlink *self);
|
static void forward_message(const mavlink_message_t *msg, Mavlink *self);
|
||||||
|
|
||||||
|
#ifndef __PX4_QURT
|
||||||
static int get_uart_fd(unsigned index);
|
static int get_uart_fd(unsigned index);
|
||||||
|
|
||||||
int get_uart_fd();
|
int get_uart_fd();
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the MAVLink system id.
|
* Get the MAVLink system id.
|
||||||
@@ -190,12 +192,14 @@ public:
|
|||||||
|
|
||||||
int get_instance_id();
|
int get_instance_id();
|
||||||
|
|
||||||
|
#ifndef __PX4_QURT
|
||||||
/**
|
/**
|
||||||
* Enable / disable hardware flow control.
|
* Enable / disable hardware flow control.
|
||||||
*
|
*
|
||||||
* @param enabled True if hardware flow control should be enabled
|
* @param enabled True if hardware flow control should be enabled
|
||||||
*/
|
*/
|
||||||
int enable_flow_control(bool enabled);
|
int enable_flow_control(bool enabled);
|
||||||
|
#endif
|
||||||
|
|
||||||
mavlink_channel_t get_channel();
|
mavlink_channel_t get_channel();
|
||||||
|
|
||||||
@@ -320,7 +324,9 @@ private:
|
|||||||
bool _forwarding_on;
|
bool _forwarding_on;
|
||||||
bool _passing_on;
|
bool _passing_on;
|
||||||
bool _ftp_on;
|
bool _ftp_on;
|
||||||
|
#ifndef __PX4_QURT
|
||||||
int _uart_fd;
|
int _uart_fd;
|
||||||
|
#endif
|
||||||
int _baudrate;
|
int _baudrate;
|
||||||
int _datarate; ///< data rate for normal streams (attitude, position, etc.)
|
int _datarate; ///< data rate for normal streams (attitude, position, etc.)
|
||||||
int _datarate_events; ///< data rate for params, waypoints, text messages
|
int _datarate_events; ///< data rate for params, waypoints, text messages
|
||||||
@@ -378,7 +384,9 @@ private:
|
|||||||
|
|
||||||
void mavlink_update_system();
|
void mavlink_update_system();
|
||||||
|
|
||||||
|
#ifndef __PX4_QURT
|
||||||
int mavlink_open_uart(int baudrate, const char *uart_name, struct termios *uart_config_original, bool *is_usb);
|
int mavlink_open_uart(int baudrate, const char *uart_name, struct termios *uart_config_original, bool *is_usb);
|
||||||
|
#endif
|
||||||
|
|
||||||
static unsigned int interval_from_rate(float rate);
|
static unsigned int interval_from_rate(float rate);
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
* @author Anton Babushkin <anton.babushkin@me.com>
|
* @author Anton Babushkin <anton.babushkin@me.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <px4_time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <commander/px4_custom_mode.h>
|
#include <commander/px4_custom_mode.h>
|
||||||
@@ -354,6 +355,7 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __PX4_QURT
|
||||||
void send(const hrt_abstime t)
|
void send(const hrt_abstime t)
|
||||||
{
|
{
|
||||||
if (!mavlink_logbuffer_is_empty(_mavlink->get_logbuffer())) {
|
if (!mavlink_logbuffer_is_empty(_mavlink->get_logbuffer())) {
|
||||||
@@ -391,7 +393,7 @@ protected:
|
|||||||
char log_file_path[64] = "";
|
char log_file_path[64] = "";
|
||||||
|
|
||||||
timespec ts;
|
timespec ts;
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
px4_clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
/* use GPS time for log file naming, e.g. /fs/microsd/2014-01-19/19_37_52.bin */
|
/* use GPS time for log file naming, e.g. /fs/microsd/2014-01-19/19_37_52.bin */
|
||||||
time_t gps_time_sec = ts.tv_sec + (ts.tv_nsec / 1e9);
|
time_t gps_time_sec = ts.tv_sec + (ts.tv_nsec / 1e9);
|
||||||
struct tm tt;
|
struct tm tt;
|
||||||
@@ -410,6 +412,7 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
class MavlinkStreamCommandLong : public MavlinkStream
|
class MavlinkStreamCommandLong : public MavlinkStream
|
||||||
@@ -975,7 +978,7 @@ protected:
|
|||||||
mavlink_system_time_t msg;
|
mavlink_system_time_t msg;
|
||||||
timespec tv;
|
timespec tv;
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &tv);
|
px4_clock_gettime(CLOCK_REALTIME, &tv);
|
||||||
|
|
||||||
msg.time_boot_ms = hrt_absolute_time() / 1000;
|
msg.time_boot_ms = hrt_absolute_time() / 1000;
|
||||||
msg.time_unix_usec = (uint64_t)tv.tv_sec * 1000000 + tv.tv_nsec / 1000;
|
msg.time_unix_usec = (uint64_t)tv.tv_sec * 1000000 + tv.tv_nsec / 1000;
|
||||||
|
|||||||
@@ -41,12 +41,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* XXX trim includes */
|
/* XXX trim includes */
|
||||||
#ifdef __PX4_NUTTX
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
#include <nuttx/sched.h>
|
|
||||||
#else
|
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
#endif
|
#include <px4_time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -64,8 +60,10 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#ifndef __PX4_QURT
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
@@ -993,7 +991,7 @@ MavlinkReceiver::handle_message_system_time(mavlink_message_t *msg)
|
|||||||
mavlink_msg_system_time_decode(msg, &time);
|
mavlink_msg_system_time_decode(msg, &time);
|
||||||
|
|
||||||
timespec tv;
|
timespec tv;
|
||||||
clock_gettime(CLOCK_REALTIME, &tv);
|
px4_clock_gettime(CLOCK_REALTIME, &tv);
|
||||||
|
|
||||||
// date -d @1234567890: Sat Feb 14 02:31:30 MSK 2009
|
// date -d @1234567890: Sat Feb 14 02:31:30 MSK 2009
|
||||||
bool onb_unix_valid = (unsigned long long)tv.tv_sec > PX4_EPOCH_SECS;
|
bool onb_unix_valid = (unsigned long long)tv.tv_sec > PX4_EPOCH_SECS;
|
||||||
@@ -1002,7 +1000,7 @@ MavlinkReceiver::handle_message_system_time(mavlink_message_t *msg)
|
|||||||
if (!onb_unix_valid && ofb_unix_valid) {
|
if (!onb_unix_valid && ofb_unix_valid) {
|
||||||
tv.tv_sec = time.time_unix_usec / 1000000ULL;
|
tv.tv_sec = time.time_unix_usec / 1000000ULL;
|
||||||
tv.tv_nsec = (time.time_unix_usec % 1000000ULL) * 1000ULL;
|
tv.tv_nsec = (time.time_unix_usec % 1000000ULL) * 1000ULL;
|
||||||
if(clock_settime(CLOCK_REALTIME, &tv)) {
|
if(px4_clock_settime(CLOCK_REALTIME, &tv)) {
|
||||||
warn("failed setting clock");
|
warn("failed setting clock");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1488,6 +1486,7 @@ MavlinkReceiver::handle_message_hil_state_quaternion(mavlink_message_t *msg)
|
|||||||
void *
|
void *
|
||||||
MavlinkReceiver::receive_thread(void *arg)
|
MavlinkReceiver::receive_thread(void *arg)
|
||||||
{
|
{
|
||||||
|
#ifndef __PX4_QURT
|
||||||
int uart_fd = _mavlink->get_uart_fd();
|
int uart_fd = _mavlink->get_uart_fd();
|
||||||
|
|
||||||
const int timeout = 500;
|
const int timeout = 500;
|
||||||
@@ -1530,6 +1529,7 @@ MavlinkReceiver::receive_thread(void *arg)
|
|||||||
_mavlink->count_rxbytes(nread);
|
_mavlink->count_rxbytes(nread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1576,9 +1576,11 @@ MavlinkReceiver::receive_start(Mavlink *parent)
|
|||||||
pthread_attr_t receiveloop_attr;
|
pthread_attr_t receiveloop_attr;
|
||||||
pthread_attr_init(&receiveloop_attr);
|
pthread_attr_init(&receiveloop_attr);
|
||||||
|
|
||||||
|
#ifndef __PX4_QURT
|
||||||
// set to non-blocking read
|
// set to non-blocking read
|
||||||
int flags = fcntl(parent->get_uart_fd(), F_GETFL, 0);
|
int flags = fcntl(parent->get_uart_fd(), F_GETFL, 0);
|
||||||
fcntl(parent->get_uart_fd(), F_SETFL, flags | O_NONBLOCK);
|
fcntl(parent->get_uart_fd(), F_SETFL, flags | O_NONBLOCK);
|
||||||
|
#endif
|
||||||
|
|
||||||
struct sched_param param;
|
struct sched_param param;
|
||||||
(void)pthread_attr_getschedparam(&receiveloop_attr, ¶m);
|
(void)pthread_attr_getschedparam(&receiveloop_attr, ¶m);
|
||||||
|
|||||||
@@ -79,7 +79,9 @@ MavlinkStream::update(const hrt_abstime t)
|
|||||||
|
|
||||||
if (dt > 0 && dt >= interval) {
|
if (dt > 0 && dt >= interval) {
|
||||||
/* interval expired, send message */
|
/* interval expired, send message */
|
||||||
|
#ifndef __PX4_QURT
|
||||||
send(t);
|
send(t);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (const_rate()) {
|
if (const_rate()) {
|
||||||
_last_sent = (t / _interval) * _interval;
|
_last_sent = (t / _interval) * _interval;
|
||||||
|
|||||||
@@ -92,7 +92,9 @@ protected:
|
|||||||
Mavlink *_mavlink;
|
Mavlink *_mavlink;
|
||||||
unsigned int _interval;
|
unsigned int _interval;
|
||||||
|
|
||||||
|
#ifndef __PX4_QURT
|
||||||
virtual void send(const hrt_abstime t) = 0;
|
virtual void send(const hrt_abstime t) = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
hrt_abstime _last_sent;
|
hrt_abstime _last_sent;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
* @author Lorenz Meier <lm@inf.ethz.ch>
|
* @author Lorenz Meier <lm@inf.ethz.ch>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <px4_posix.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -124,5 +125,5 @@ __EXPORT void mavlink_vasprintf(int _fd, int severity, const char *fmt, ...)
|
|||||||
char text[MAVLINK_LOG_MAXLEN + 1];
|
char text[MAVLINK_LOG_MAXLEN + 1];
|
||||||
vsnprintf(text, sizeof(text), fmt, ap);
|
vsnprintf(text, sizeof(text), fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
ioctl(_fd, severity, (unsigned long)&text[0]);
|
px4_ioctl(_fd, severity, (unsigned long)&text[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#ifdef __PX4_LINUX
|
#if defined(__PX4_LINUX) || defined(__PX4_NUTTX)
|
||||||
|
|
||||||
#define px4_clock_gettime clock_gettime
|
#define px4_clock_gettime clock_gettime
|
||||||
#define px4_clock_settime clock_settime
|
#define px4_clock_settime clock_settime
|
||||||
|
|||||||
Reference in New Issue
Block a user