blob: 182407a5ebaf2c40cec1fc16bb287ca7547ddf14 (
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
|
/*
* mavlink_orb_subscription.cpp
*
* Created on: 23.02.2014
* Author: ton
*/
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <uORB/uORB.h>
#include "mavlink_orb_subscription.h"
MavlinkOrbSubscription::MavlinkOrbSubscription(const struct orb_metadata *meta, size_t size)
{
this->meta = meta;
this->data = malloc(size);
memset(this->data, 0, size);
this->fd = orb_subscribe(meta);
this->last_update = 0;
this->interval = 0;
}
MavlinkOrbSubscription::~MavlinkOrbSubscription()
{
close(fd);
free(data);
}
int MavlinkOrbSubscription::set_interval(const unsigned int interval)
{
this->interval = interval;
return orb_set_interval(fd, interval);
}
int MavlinkOrbSubscription::update(const hrt_abstime t)
{
if (last_update != t) {
bool updated;
orb_check(fd, &updated);
if (updated)
return orb_copy(meta, fd, &data);
}
return OK;
}
|