aboutsummaryrefslogtreecommitdiff
path: root/src/modules/mavlink/mavlink_stream.cpp
blob: 16407366e4be9780ac3aa71b6cdae45085468b1f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * mavlink_stream.cpp
 *
 *  Created on: 24.02.2014
 *      Author: ton
 */

#include <stdlib.h>

#include "mavlink_stream.h"
#include "mavlink_main.h"

MavlinkStream::MavlinkStream() : _interval(1000), _last_sent(0), _channel(MAVLINK_COMM_0), next(nullptr)
{
}

MavlinkStream::~MavlinkStream()
{
}

/**
 * Set messages interval in ms
 */
void
MavlinkStream::set_interval(const unsigned int interval)
{
	_interval = interval * 1000;
}

/**
 * Set mavlink channel
 */
void
MavlinkStream::set_channel(mavlink_channel_t channel)
{
	_channel = channel;
}

/**
 * Update subscriptions and send message if necessary
 */
int
MavlinkStream::update(const hrt_abstime t)
{
	uint64_t dt = t - _last_sent;
	if (dt > 0 && dt >= _interval) {
		/* interval expired, send message */
		send(t);
		_last_sent = (t / _interval) * _interval;
	}
}