mavlink ulog: advertise ulog_stream topic before subscribing to ulog_stream_ack

This reduces the maximum number of needed file descriptors by 1 when using
ulog streaming.
This commit is contained in:
Beat Küng
2017-08-16 16:46:56 +02:00
parent ba150566c6
commit 9e01842c6a
2 changed files with 33 additions and 24 deletions
@@ -69,6 +69,13 @@ LogWriterMavlink::~LogWriterMavlink()
void LogWriterMavlink::start_log()
{
if (_ulog_stream_pub == nullptr) {
memset(&_ulog_stream_data, 0, sizeof(_ulog_stream_data));
// advertise before we subscribe: this is a trick to reduce the number of needed file descriptors
// (the advertise temporarily opens a file descriptor)
_ulog_stream_pub = orb_advertise_queue(ORB_ID(ulog_stream), &_ulog_stream_data, _queue_size);
}
if (_ulog_stream_ack_sub == -1) {
_ulog_stream_ack_sub = orb_subscribe(ORB_ID(ulog_stream_ack));
}