Skip to content

Commit 82f5b93

Browse files
committed
AP_RCProtocol: move RC Protocol announcements to AP_RCProtocol
1 parent 2d4e248 commit 82f5b93

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

libraries/AP_RCProtocol/AP_RCProtocol.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
#include <AP_Vehicle/AP_Vehicle_Type.h>
4747

48+
#include <GCS_MAVLink/GCS.h>
49+
4850
extern const AP_HAL::HAL& hal;
4951

5052
void AP_RCProtocol::init()
@@ -450,6 +452,39 @@ bool AP_RCProtocol::detect_async_protocol(rcprotocol_t protocol)
450452
return true;
451453
}
452454

455+
const char *AP_RCProtocol::detected_protocol_name() const
456+
{
457+
switch (_detected_protocol) {
458+
#if AP_RCPROTOCOL_IOMCU_ENABLED
459+
case AP_RCProtocol::IOMCU:
460+
return ((AP_RCProtocol_IOMCU*)(backend[AP_RCProtocol::IOMCU]))->get_rc_protocol();
461+
#endif
462+
default:
463+
return protocol_name();
464+
}
465+
}
466+
467+
void AP_RCProtocol::announce_detected()
468+
{
469+
const char *src;
470+
const char *name = detected_protocol_name();
471+
if (name == nullptr) {
472+
return;
473+
}
474+
switch (_detected_protocol) {
475+
#if AP_RCPROTOCOL_IOMCU_ENABLED
476+
case AP_RCProtocol::IOMCU:
477+
src = "IOMCU";
478+
break;
479+
#endif
480+
default:
481+
src = using_uart() ? "Bytes" : "Pulses";
482+
}
483+
(void)src; // iofirmware doesn't use this
484+
(void)name; // iofirmware doesn't use this
485+
GCS_SEND_TEXT(MAV_SEVERITY_DEBUG, "RCInput: decoding %s (%s)", name, src);
486+
}
487+
453488
bool AP_RCProtocol::new_input()
454489
{
455490
// if we have an extra UART from a SERIALn_PROTOCOL then check it for data
@@ -503,6 +538,14 @@ bool AP_RCProtocol::new_input()
503538
}
504539
#endif
505540

541+
// announce protocol changes:
542+
if (_detected_protocol != _last_detected_protocol ||
543+
using_uart() != _last_detected_using_uart) {
544+
_last_detected_protocol = _detected_protocol;
545+
_last_detected_using_uart = using_uart();
546+
announce_detected();
547+
}
548+
506549
bool ret = _new_input;
507550
_new_input = false;
508551
return ret;

libraries/AP_RCProtocol/AP_RCProtocol.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ class AP_RCProtocol {
222222
// return protocol name as a string
223223
const char *protocol_name(void) const;
224224

225+
// return detected protocol. In the case that backend can provide
226+
// information on what *it* is decoding that will be returned by
227+
// this method. As opposed to "protocol_name" which will be the
228+
// backend name e.g. "IOMCU".
229+
const char *detected_protocol_name() const;
230+
225231
// return detected protocol
226232
enum rcprotocol_t protocol_detected(void) const {
227233
return _detected_protocol;
@@ -287,6 +293,10 @@ class AP_RCProtocol {
287293
// allowed RC protocols mask (first bit means "all")
288294
uint32_t rc_protocols_mask;
289295

296+
rcprotocol_t _last_detected_protocol;
297+
bool _last_detected_using_uart;
298+
void announce_detected();
299+
290300
#endif // AP_RCPROTCOL_ENABLED
291301

292302
};

libraries/AP_RCProtocol/AP_RCProtocol_IOMCU.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66

77
#include <AP_BoardConfig/AP_BoardConfig.h>
88
#include <AP_IOMCU/AP_IOMCU.h>
9+
910
extern AP_IOMCU iomcu;
1011

12+
const char *AP_RCProtocol_IOMCU::get_rc_protocol() const
13+
{
14+
return iomcu.get_rc_protocol();
15+
}
16+
1117
void AP_RCProtocol_IOMCU::update()
1218
{
1319
if (!AP_BoardConfig::io_enabled()) {

libraries/AP_RCProtocol/AP_RCProtocol_IOMCU.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class AP_RCProtocol_IOMCU : public AP_RCProtocol_Backend {
1919
return ever_seen_input && AP_HAL::micros() - last_iomcu_us < 400000;
2020
}
2121

22+
const char *get_rc_protocol() const;
23+
2224
private:
2325

2426
uint32_t last_iomcu_us;

0 commit comments

Comments
 (0)