blob: 84ac11483f87e96cf522b08a20496531fc5badb5 (
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
|
/*
* 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 *topic, size_t size)
{
this->topic = topic;
this->data = malloc(size);
memset(this->data, 0, size);
this->fd = orb_subscribe(topic);
this->last_update = 0;
}
MavlinkOrbSubscription::~MavlinkOrbSubscription()
{
close(fd);
free(data);
}
bool MavlinkOrbSubscription::update(const hrt_abstime t)
{
if (last_update != t) {
bool updated;
orb_check(fd, &updated);
if (updated) {
orb_copy(topic, fd, data);
return true;
}
}
return false;
}
|