From 47567c5c2483aa014d40106c93101254e9a3f565 Mon Sep 17 00:00:00 2001 From: acfloria Date: Fri, 9 Mar 2018 10:49:40 +0100 Subject: [PATCH] Improve IridiumSBD TX buffer handling - Every time data is written to the iridium module all previous untransmitted data is overwritten - The buffer is reset only on the following conditions - A sbd session is successfully completed - An incoming mavlink message would result in less than SATCOM_MIN_TX_BUF_SPACE free bytes after it is written - Any other incomming data would result in less than SATCOM_MIN_TX_BUF_SPACE free bytes after it is written to the buffer. --- .../telemetry/iridiumsbd/IridiumSBD.cpp | 26 ++++++++++++++++--- src/drivers/telemetry/iridiumsbd/IridiumSBD.h | 11 ++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/drivers/telemetry/iridiumsbd/IridiumSBD.cpp b/src/drivers/telemetry/iridiumsbd/IridiumSBD.cpp index 2c8146c86d..9d03bfe8fa 100644 --- a/src/drivers/telemetry/iridiumsbd/IridiumSBD.cpp +++ b/src/drivers/telemetry/iridiumsbd/IridiumSBD.cpp @@ -78,7 +78,7 @@ int IridiumSBD::start(int argc, char *argv[]) IridiumSBD::instance = new IridiumSBD(); IridiumSBD::task_handle = px4_task_spawn_cmd("iridiumsbd", SCHED_DEFAULT, - SCHED_PRIORITY_SLOW_DRIVER, 1200, (main_t)&IridiumSBD::main_loop_helper, argv); + SCHED_PRIORITY_SLOW_DRIVER, 1300, (main_t)&IridiumSBD::main_loop_helper, argv); return OK; } @@ -463,6 +463,9 @@ void IridiumSBD::sbdsession_loop(void) rx_read_pending = true; } + // after a successful session reset the tx buffer + tx_buf_write_idx = 0; + publish_telemetry_status(); break; @@ -472,6 +475,9 @@ void IridiumSBD::sbdsession_loop(void) last_heartbeat = hrt_absolute_time(); publish_telemetry_status(); + // after a successful session reset the tx buffer + tx_buf_write_idx = 0; + tx_session_pending = false; break; @@ -579,6 +585,22 @@ void IridiumSBD::start_test(void) ssize_t IridiumSBD::write(struct file *filp, const char *buffer, size_t buflen) { + // check and reset the remaining buffer space for incoming MavLink messages + if (buflen == 6) { + if (*buffer == MAVLINK_PACKAGE_START) { + if (SATCOM_TX_BUF_LEN - tx_buf_write_idx - SATCOM_MIN_TX_BUF_SPACE - (*(buffer + 1) + 8) < 0) { + tx_buf_write_idx = 0; + PX4_INFO("Deleting full TX buffer before writing new message"); + } + } + } + + // check and reset the remaining buffer space for any non mavlink messages + if (SATCOM_TX_BUF_LEN - tx_buf_write_idx - SATCOM_MIN_TX_BUF_SPACE < 0) { + tx_buf_write_idx = 0; + PX4_INFO("Deleting full TX buffer"); + } + VERBOSE_INFO("WRITE: LEN %d, TX WRITTEN: %d", buflen, tx_buf_write_idx); if ((ssize_t)buflen > SATCOM_TX_BUF_LEN - tx_buf_write_idx) { @@ -672,8 +694,6 @@ void IridiumSBD::write_tx_buf() VERBOSE_INFO("WRITE SBD: DATA WRITTEN TO MODEM"); - tx_buf_write_idx = 0; - pthread_mutex_unlock(&tx_buf_mutex); tx_session_pending = true; diff --git a/src/drivers/telemetry/iridiumsbd/IridiumSBD.h b/src/drivers/telemetry/iridiumsbd/IridiumSBD.h index 6eacfce224..b26f49afa1 100644 --- a/src/drivers/telemetry/iridiumsbd/IridiumSBD.h +++ b/src/drivers/telemetry/iridiumsbd/IridiumSBD.h @@ -84,10 +84,21 @@ typedef enum { extern "C" __EXPORT int iridiumsbd_main(int argc, char *argv[]); #define SATCOM_TX_BUF_LEN 340 // TX buffer size - maximum for a SBD MO message is 340, but billed per 50 +#define SATCOM_MIN_TX_BUF_SPACE 50 // Minimum remaining buffer space required, should be equal to the largerst message intended to send #define SATCOM_RX_MSG_BUF_LEN 270 // RX buffer size for MT messages #define SATCOM_RX_COMMAND_BUF_LEN 50 // RX buffer size for other commands #define SATCOM_SIGNAL_REFRESH_DELAY 20000000 // update signal quality every 20s +#define MAVLINK_PACKAGE_START 254 // The value of the first byte of the mavlink header + +/** + * The driver for the Rockblock 9602 and 9603 RockBlock module for satellite communication over the Iridium satellite system + * + * TODO: + * - 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 + * - Keep CDev active even if the driver is stopped to avoid a hard fault caused by MavLink. + */ class IridiumSBD : public device::CDev { public: