Skip to content

Commit

Permalink
AP_RCProtocol: move RC Protocol announcements to AP_RCProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed May 5, 2024
1 parent f672d03 commit 1b77877
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
43 changes: 43 additions & 0 deletions libraries/AP_RCProtocol/AP_RCProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

#include <AP_Vehicle/AP_Vehicle_Type.h>

#include <GCS_MAVLink/GCS.h>

extern const AP_HAL::HAL& hal;

void AP_RCProtocol::init()
Expand Down Expand Up @@ -450,6 +452,39 @@ bool AP_RCProtocol::detect_async_protocol(rcprotocol_t protocol)
return true;
}

const char *AP_RCProtocol::detected_protocol_name() const
{
switch (_detected_protocol) {
#if AP_RCPROTOCOL_IOMCU_ENABLED
case AP_RCProtocol::IOMCU:
return ((AP_RCProtocol_IOMCU*)(backend[AP_RCProtocol::IOMCU]))->get_rc_protocol();
#endif
default:
return protocol_name();
}
}

void AP_RCProtocol::announce_detected()
{
const char *src;
const char *name = detected_protocol_name();
if (name == nullptr) {
return;
}
switch (_detected_protocol) {
#if AP_RCPROTOCOL_IOMCU_ENABLED
case AP_RCProtocol::IOMCU:
src = "IOMCU";
break;
#endif
default:
src = using_uart() ? "Bytes" : "Pulses";
}
(void)src; // iofirmware doesn't use this
(void)name; // iofirmware doesn't use this
GCS_SEND_TEXT(MAV_SEVERITY_DEBUG, "RCInput: decoding %s (%s)", name, src);
}

bool AP_RCProtocol::new_input()
{
// if we have an extra UART from a SERIALn_PROTOCOL then check it for data
Expand Down Expand Up @@ -503,6 +538,14 @@ bool AP_RCProtocol::new_input()
}
#endif

// announce protocol changes:
if (_detected_protocol != _last_detected_protocol ||
using_uart() != _last_detected_using_uart) {
_last_detected_protocol = _detected_protocol;
_last_detected_using_uart = using_uart();
announce_detected();
}

bool ret = _new_input;
_new_input = false;
return ret;
Expand Down
10 changes: 10 additions & 0 deletions libraries/AP_RCProtocol/AP_RCProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ class AP_RCProtocol {
// return protocol name as a string
const char *protocol_name(void) const;

// return detected protocol. In the case that backend can provide
// information on what *it* is decoding that will be returned by
// this method. As opposed to "protocol_name" which will be the
// backend name e.g. "IOMCU".
const char *detected_protocol_name() const;

// return detected protocol
enum rcprotocol_t protocol_detected(void) const {
return _detected_protocol;
Expand Down Expand Up @@ -287,6 +293,10 @@ class AP_RCProtocol {
// allowed RC protocols mask (first bit means "all")
uint32_t rc_protocols_mask;

rcprotocol_t _last_detected_protocol;
bool _last_detected_using_uart;
void announce_detected();

#endif // AP_RCPROTCOL_ENABLED

};
Expand Down
6 changes: 6 additions & 0 deletions libraries/AP_RCProtocol/AP_RCProtocol_IOMCU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

#include <AP_BoardConfig/AP_BoardConfig.h>
#include <AP_IOMCU/AP_IOMCU.h>

extern AP_IOMCU iomcu;

const char *AP_RCProtocol_IOMCU::get_rc_protocol() const
{
return iomcu.get_rc_protocol();
}

void AP_RCProtocol_IOMCU::update()
{
if (!AP_BoardConfig::io_enabled()) {
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_RCProtocol/AP_RCProtocol_IOMCU.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class AP_RCProtocol_IOMCU : public AP_RCProtocol_Backend {
return ever_seen_input && AP_HAL::micros() - last_iomcu_us < 400000;
}

const char *get_rc_protocol() const;

private:

uint32_t last_iomcu_us;
Expand Down

0 comments on commit 1b77877

Please sign in to comment.