Skip to content

Commit 28d9073

Browse files
committed
AP_RCProtocol: move navio2 RC input into AP_RCProtocol
1 parent caefa03 commit 28d9073

File tree

5 files changed

+124
-1
lines changed

5 files changed

+124
-1
lines changed

libraries/AP_RCProtocol/AP_RCProtocol.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "AP_RCProtocol_PPMSum.h"
2525
#include "AP_RCProtocol_DSM.h"
26+
#include "AP_RCProtocol_Emlid_RCIO.h"
2627
#include "AP_RCProtocol_IBUS.h"
2728
#include "AP_RCProtocol_SBUS.h"
2829
#include "AP_RCProtocol_SUMD.h"
@@ -114,6 +115,9 @@ void AP_RCProtocol::init()
114115
#if AP_RCPROTOCOL_RADIO_ENABLED
115116
backend[AP_RCProtocol::RADIO] = new AP_RCProtocol_Radio(*this);
116117
#endif
118+
#if AP_RCPROTOCOL_EMLID_RCIO_ENABLED
119+
backend[AP_RCProtocol::EMLID_RCIO] = new AP_RCProtocol_Emlid_RCIO(*this);
120+
#endif
117121
}
118122

119123
AP_RCProtocol::~AP_RCProtocol()
@@ -478,6 +482,9 @@ bool AP_RCProtocol::new_input()
478482
#endif
479483
#if AP_RCPROTOCOL_RADIO_ENABLED
480484
AP_RCProtocol::RADIO,
485+
#endif
486+
#if AP_RCPROTOCOL_EMLID_RCIO_ENABLED
487+
AP_RCProtocol::EMLID_RCIO,
481488
#endif
482489
};
483490
for (const auto protocol : pollable) {
@@ -630,6 +637,10 @@ const char *AP_RCProtocol::protocol_name_from_protocol(rcprotocol_t protocol)
630637
#if AP_RCPROTOCOL_RADIO_ENABLED
631638
case RADIO:
632639
return "Radio";
640+
#endif
641+
#if AP_RCPROTOCOL_EMLID_RCIO_ENABLED
642+
case EMLID_RCIO:
643+
return "Emlid RCIO";
633644
#endif
634645
case NONE:
635646
break;

libraries/AP_RCProtocol/AP_RCProtocol.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class AP_RCProtocol {
9292
#endif
9393
#if AP_RCPROTOCOL_RADIO_ENABLED
9494
RADIO = 19,
95+
#endif
96+
#if AP_RCPROTOCOL_EMLID_RCIO_ENABLED
97+
EMLID_RCIO = 21,
9598
#endif
9699
NONE //last enum always is None
97100
};
@@ -197,6 +200,9 @@ class AP_RCProtocol {
197200
#endif
198201
#if AP_RCPROTOCOL_RADIO_ENABLED
199202
case RADIO:
203+
#endif
204+
#if AP_RCPROTOCOL_EMLID_RCIO_ENABLED
205+
case EMLID_RCIO:
200206
#endif
201207
case NONE:
202208
return false;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include "AP_RCProtocol_config.h"
2+
3+
#if AP_RCPROTOCOL_EMLID_RCIO_ENABLED
4+
5+
#include "AP_RCProtocol_Emlid_RCIO.h"
6+
7+
#include <cstdio>
8+
#include <unistd.h>
9+
#include <fcntl.h>
10+
#include <cstdlib>
11+
12+
#include <AP_Common/AP_Common.h>
13+
14+
#include <GCS_MAVLink/GCS.h>
15+
16+
#define RCIN_SYSFS_PATH "/sys/kernel/rcio/rcin"
17+
18+
int AP_RCProtocol_Emlid_RCIO::open_channel(int channel)
19+
{
20+
char *channel_path;
21+
if (asprintf(&channel_path, "%s/ch%d", RCIN_SYSFS_PATH, channel) == -1) {
22+
AP_HAL::panic("[AP_RCProtocol_Emlid_RCIO]: not enough memory\n");
23+
}
24+
25+
int fd = ::open(channel_path, O_RDONLY|O_CLOEXEC);
26+
27+
free(channel_path);
28+
29+
return fd;
30+
}
31+
32+
void AP_RCProtocol_Emlid_RCIO::init()
33+
{
34+
for (size_t i = 0; i < ARRAY_SIZE(channels); i++) {
35+
channels[i] = open_channel(i);
36+
if (channels[i] < 0) {
37+
AP_HAL::panic("[AP_RCProtocol_Emlid_RCIO]: failed to open channels\n");
38+
}
39+
}
40+
}
41+
42+
void AP_RCProtocol_Emlid_RCIO::update(void)
43+
{
44+
if (!init_done) {
45+
init();
46+
init_done = true;
47+
}
48+
49+
if (AP_HAL::micros() - _last_timestamp < 10000) {
50+
return;
51+
}
52+
_last_timestamp = AP_HAL::micros();
53+
54+
uint16_t periods[16];
55+
56+
char buffer[12] {};
57+
for (size_t i = 0; i < ARRAY_SIZE(channels); i++) {
58+
if (::pread(channels[i], buffer, sizeof(buffer) - 1, 0) <= 0) {
59+
/* We ignore error in order not to spam the console */
60+
continue;
61+
}
62+
periods[i] = atoi(buffer);
63+
}
64+
65+
add_input(
66+
ARRAY_SIZE(periods),
67+
periods,
68+
false,
69+
-1,
70+
0
71+
);
72+
73+
}
74+
75+
#endif // AP_RCPROTOCOL_EMLID_RCIO_ENABLED
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include "AP_RCProtocol_config.h"
4+
5+
#if AP_RCPROTOCOL_EMLID_RCIO_ENABLED
6+
7+
#include "AP_RCProtocol_Backend.h"
8+
9+
class AP_RCProtocol_Emlid_RCIO : public AP_RCProtocol_Backend {
10+
public:
11+
12+
using AP_RCProtocol_Backend::AP_RCProtocol_Backend;
13+
14+
void update() override;
15+
16+
private:
17+
bool init_done;
18+
void init();
19+
20+
uint32_t _last_timestamp;
21+
22+
int channels[16];
23+
24+
int open_channel(int channel);
25+
};
26+
27+
#endif // AP_RCPROTOCOL_EMLID_RCIO_ENABLED

libraries/AP_RCProtocol/AP_RCProtocol_config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#define AP_RCPROTOCOL_DSM_ENABLED AP_RCPROTOCOL_BACKEND_DEFAULT_ENABLED
2626
#endif
2727

28+
#ifndef AP_RCPROTOCOL_EMLID_RCIO_ENABLED
29+
#define AP_RCPROTOCOL_EMLID_RCIO_ENABLED 0
30+
#endif
31+
2832
#ifndef AP_RCPROTOCOL_FPORT_ENABLED
2933
#define AP_RCPROTOCOL_FPORT_ENABLED AP_RCPROTOCOL_BACKEND_DEFAULT_ENABLED
3034
#endif
@@ -90,4 +94,4 @@
9094

9195
#ifndef AP_RCPROTOCOL_FDM_ENABLED
9296
#define AP_RCPROTOCOL_FDM_ENABLED AP_RCPROTOCOL_BACKEND_DEFAULT_ENABLED && (CONFIG_HAL_BOARD == HAL_BOARD_SITL)
93-
#endif
97+
#endif

0 commit comments

Comments
 (0)