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.
This commit is contained in:
acfloria
2018-03-09 10:49:40 +01:00
committed by Beat Küng
parent 6c3857a147
commit 47567c5c24
2 changed files with 34 additions and 3 deletions

View File

@@ -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;

View File

@@ -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: