Skip to content

Commit ab279d5

Browse files
acfloriadagar
authored andcommitted
IridiumSBD: Fixes for receiving data
- Catch the case where the case where the driver gets stuck because nothing is received by +SBDRB - Add a mutex for the rx buffer - Stop the standby loop if a mode change is already scheduled
1 parent 57162ff commit ab279d5

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/drivers/telemetry/iridiumsbd/IridiumSBD.cpp

+22-3
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ void IridiumSBD::main_loop(int argc, char *argv[])
211211
CDev::init();
212212

213213
pthread_mutex_init(&_tx_buf_mutex, NULL);
214+
pthread_mutex_init(&_rx_buf_mutex, NULL);
214215

215216
int arg_i = 3;
216217
int arg_uart_name = 0;
@@ -350,26 +351,31 @@ void IridiumSBD::standby_loop(void)
350351
if (_rx_session_pending && !_tx_session_pending) {
351352
if (clear_mo_buffer()) {
352353
start_sbd_session();
354+
return;
353355
}
354356

355357
} else {
356358
start_sbd_session();
359+
return;
357360
}
358361

359362
} else {
360363
start_csq();
364+
return;
361365
}
362366
}
363367

364368
// start a signal check if requested and not a switch to another mode is scheduled
365369
if (((hrt_absolute_time() - _last_signal_check) > SATCOM_SIGNAL_REFRESH_DELAY)
366370
&& (_new_state == SATCOM_STATE_STANDBY)) {
367371
start_csq();
372+
return;
368373
}
369374

370375
// only read the MT buffer if the higher layer (mavlink app) read the previous message
371-
if (_rx_read_pending && (_rx_msg_read_idx == _rx_msg_end_idx)) {
376+
if (_rx_read_pending && (_rx_msg_read_idx == _rx_msg_end_idx) && (_new_state == SATCOM_STATE_STANDBY)) {
372377
read_rx_buf();
378+
return;
373379
}
374380
}
375381

@@ -679,6 +685,7 @@ ssize_t IridiumSBD::write(struct file *filp, const char *buffer, size_t buflen)
679685

680686
ssize_t IridiumSBD::read(struct file *filp, char *buffer, size_t buflen)
681687
{
688+
pthread_mutex_lock(&_rx_buf_mutex);
682689
VERBOSE_INFO("READ: LEN %d, RX: %d RX END: %d", buflen, _rx_msg_read_idx, _rx_msg_end_idx);
683690

684691
if (_rx_msg_read_idx < _rx_msg_end_idx) {
@@ -692,9 +699,11 @@ ssize_t IridiumSBD::read(struct file *filp, char *buffer, size_t buflen)
692699

693700
_rx_msg_read_idx += bytes_to_copy;
694701

702+
pthread_mutex_unlock(&_rx_buf_mutex);
695703
return bytes_to_copy;
696704

697705
} else {
706+
pthread_mutex_unlock(&_rx_buf_mutex);
698707
return -EAGAIN;
699708
}
700709
}
@@ -767,18 +776,25 @@ void IridiumSBD::read_rx_buf(void)
767776
return;
768777
}
769778

779+
pthread_mutex_lock(&_rx_buf_mutex);
780+
781+
770782
write_at("AT+SBDRB");
771783

772784
if (read_at_msg() != SATCOM_RESULT_OK) {
773785
VERBOSE_INFO("READ SBD: MODEM NOT RESPONDING!");
786+
_rx_msg_read_idx = _rx_msg_end_idx;
787+
pthread_mutex_unlock(&_rx_buf_mutex);
774788
return;
775789
}
776790

777791
int data_len = (_rx_msg_buf[0] << 8) + _rx_msg_buf[1];
778792

779793
// rx_buf contains 2 byte length, data, 2 byte checksum and /r/n delimiter
780794
if (data_len != _rx_msg_end_idx - 6) {
781-
VERBOSE_INFO("READ SBD: WRONG DATA LENGTH");
795+
PX4_ERR("READ SBD: WRONG DATA LENGTH");
796+
_rx_msg_read_idx = _rx_msg_end_idx;
797+
pthread_mutex_unlock(&_rx_buf_mutex);
782798
return;
783799
}
784800

@@ -789,14 +805,17 @@ void IridiumSBD::read_rx_buf(void)
789805
}
790806

791807
if ((checksum / 256 != _rx_msg_buf[_rx_msg_end_idx - 4]) || ((checksum & 255) != _rx_msg_buf[_rx_msg_end_idx - 3])) {
792-
VERBOSE_INFO("READ SBD: WRONG DATA CHECKSUM");
808+
PX4_ERR("READ SBD: WRONG DATA CHECKSUM");
809+
_rx_msg_read_idx = _rx_msg_end_idx;
810+
pthread_mutex_unlock(&_rx_buf_mutex);
793811
return;
794812
}
795813

796814
_rx_msg_read_idx = 2; // ignore the length
797815
_rx_msg_end_idx -= 4; // ignore the checksum and delimiter
798816
_rx_read_pending = false;
799817

818+
pthread_mutex_unlock(&_rx_buf_mutex);
800819
VERBOSE_INFO("READ SBD: SUCCESS, LEN: %d", data_len);
801820
}
802821

src/drivers/telemetry/iridiumsbd/IridiumSBD.h

+2
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ class IridiumSBD : public device::CDev
333333
satcom_state _new_state = SATCOM_STATE_STANDBY;
334334

335335
pthread_mutex_t _tx_buf_mutex = pthread_mutex_t();
336+
pthread_mutex_t _rx_buf_mutex = pthread_mutex_t();
337+
336338
bool _verbose = false;
337339

338340
iridiumsbd_status_s _status = {};

0 commit comments

Comments
 (0)