From a8e6a099033721843e9c256f367167717ea374e5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 5 Nov 2018 16:44:00 +1100 Subject: [PATCH] AP_RCProtocol: expose protocol name mapping --- libraries/AP_RCProtocol/AP_RCProtocol.cpp | 12 ++++++++++-- libraries/AP_RCProtocol/AP_RCProtocol.h | 9 +++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libraries/AP_RCProtocol/AP_RCProtocol.cpp b/libraries/AP_RCProtocol/AP_RCProtocol.cpp index 85f456ec9f..af312849c2 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol.cpp @@ -198,9 +198,9 @@ void AP_RCProtocol::start_bind(void) /* return protocol name */ -const char *AP_RCProtocol::protocol_name(void) const +const char *AP_RCProtocol::protocol_name_from_protocol(rcprotocol_t protocol) { - switch (_detected_protocol) { + switch (protocol) { case PPM: return "PPM"; case SBUS: @@ -219,3 +219,11 @@ const char *AP_RCProtocol::protocol_name(void) const } return nullptr; } + +/* + return protocol name + */ +const char *AP_RCProtocol::protocol_name(void) const +{ + return protocol_name_from_protocol(_detected_protocol); +} diff --git a/libraries/AP_RCProtocol/AP_RCProtocol.h b/libraries/AP_RCProtocol/AP_RCProtocol.h index 7e3032736b..326579b510 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol.h @@ -29,6 +29,7 @@ public: instance = this; } ~AP_RCProtocol(); + enum rcprotocol_t { PPM = 0, SBUS, @@ -66,9 +67,17 @@ public: bool new_input(); void start_bind(void); + // return protocol name as a string + static const char *protocol_name_from_protocol(rcprotocol_t protocol); + // return protocol name as a string const char *protocol_name(void) const; + // return protocol name as a string + enum rcprotocol_t protocol_detected(void) const { + return _detected_protocol; + } + // access to singleton static AP_RCProtocol *get_instance(void) { return instance;