Skip to content

Commit ac8b535

Browse files
committed
AP_RCProtocol: move RC Protocol announcements to AP_RCProtocol
1 parent 2c3f01b commit ac8b535

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

libraries/AP_RCProtocol/AP_RCProtocol.cpp

Lines changed: 38 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,34 @@ 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+
switch (_detected_protocol) {
472+
#if AP_RCPROTOCOL_IOMCU_ENABLED
473+
case AP_RCProtocol::IOMCU:
474+
src = "IOMCU";
475+
break;
476+
#endif
477+
default:
478+
src = using_uart() ? "Bytes" : "Pulses";
479+
}
480+
GCS_SEND_TEXT(MAV_SEVERITY_DEBUG, "RCInput: decoding %s (%s)", name, src);
481+
}
482+
453483
bool AP_RCProtocol::new_input()
454484
{
455485
// if we have an extra UART from a SERIALn_PROTOCOL then check it for data
@@ -503,6 +533,14 @@ bool AP_RCProtocol::new_input()
503533
}
504534
#endif
505535

536+
// announce protocol changes:
537+
if (_detected_protocol != _last_detected_protocol ||
538+
using_uart() != _last_detected_using_uart) {
539+
_last_detected_protocol = _detected_protocol;
540+
_last_detected_using_uart = using_uart();
541+
announce_detected();
542+
}
543+
506544
bool ret = _new_input;
507545
_new_input = false;
508546
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)