Browse Source

GCS_MAVLink: mavlink_channel from SerialManager

master
Randy Mackay 10 years ago committed by Andrew Tridgell
parent
commit
febda988af
  1. 2
      libraries/GCS_MAVLink/GCS.h
  2. 43
      libraries/GCS_MAVLink/GCS_Common.cpp

2
libraries/GCS_MAVLink/GCS.h

@ -67,7 +67,7 @@ class GCS_MAVLINK
public: public:
GCS_MAVLINK(); GCS_MAVLINK();
void update(void (*run_cli)(AP_HAL::UARTDriver *)); void update(void (*run_cli)(AP_HAL::UARTDriver *));
void init(AP_HAL::UARTDriver *port); void init(AP_HAL::UARTDriver *port, mavlink_channel_t mav_chan);
void setup_uart(const AP_SerialManager& serial_manager, AP_SerialManager::SerialProtocol protocol); void setup_uart(const AP_SerialManager& serial_manager, AP_SerialManager::SerialProtocol protocol);
void send_message(enum ap_message id); void send_message(enum ap_message id);
void send_text(gcs_severity severity, const char *str); void send_text(gcs_severity severity, const char *str);

43
libraries/GCS_MAVLink/GCS_Common.cpp

@ -32,23 +32,29 @@ GCS_MAVLINK::GCS_MAVLINK() :
} }
void void
GCS_MAVLINK::init(AP_HAL::UARTDriver *port) GCS_MAVLINK::init(AP_HAL::UARTDriver *port, mavlink_channel_t mav_chan)
{ {
_port = port; _port = port;
if (port == (AP_HAL::BetterStream*)hal.uartA) { chan = mav_chan;
mavlink_comm_0_port = port;
chan = MAVLINK_COMM_0; switch (chan) {
initialised = true; case MAVLINK_COMM_0:
} else if (port == (AP_HAL::BetterStream*)hal.uartC) { mavlink_comm_0_port = _port;
mavlink_comm_1_port = port; initialised = true;
chan = MAVLINK_COMM_1; break;
initialised = true; case MAVLINK_COMM_1:
mavlink_comm_1_port = _port;
initialised = true;
break;
#if MAVLINK_COMM_NUM_BUFFERS > 2 #if MAVLINK_COMM_NUM_BUFFERS > 2
} else if (port == (AP_HAL::BetterStream*)hal.uartD) { case MAVLINK_COMM_2:
mavlink_comm_2_port = port; mavlink_comm_2_port = _port;
chan = MAVLINK_COMM_2; initialised = true;
initialised = true; break;
#endif #endif
default:
// do nothing for unsupport mavlink channels
break;
} }
_queued_parameter = NULL; _queued_parameter = NULL;
reset_cli_timeout(); reset_cli_timeout();
@ -61,13 +67,20 @@ GCS_MAVLINK::init(AP_HAL::UARTDriver *port)
void void
GCS_MAVLINK::setup_uart(const AP_SerialManager& serial_manager, AP_SerialManager::SerialProtocol protocol) GCS_MAVLINK::setup_uart(const AP_SerialManager& serial_manager, AP_SerialManager::SerialProtocol protocol)
{ {
// serach find serial port // search for serial port
AP_SerialManager::serial_state gcs_serial; AP_SerialManager::serial_state gcs_serial;
if (!serial_manager.find_serial(protocol, gcs_serial)) { if (!serial_manager.find_serial(protocol, gcs_serial)) {
// return immediately if not found // return immediately if not found
return; return;
} }
// get associated mavlink channel
mavlink_channel_t mav_chan;
if (!serial_manager.get_mavlink_channel(protocol, mav_chan)) {
// return immediately in unlikely case mavlink channel cannot be found
return;
}
/* /*
Now try to cope with SiK radios that may be stuck in bootloader Now try to cope with SiK radios that may be stuck in bootloader
mode because CTS was held while powering on. This tells the mode because CTS was held while powering on. This tells the
@ -90,7 +103,7 @@ GCS_MAVLINK::setup_uart(const AP_SerialManager& serial_manager, AP_SerialManager
gcs_serial.uart->begin(map_baudrate(gcs_serial.baud)); gcs_serial.uart->begin(map_baudrate(gcs_serial.baud));
// and init the gcs instance // and init the gcs instance
init(gcs_serial.uart); init(gcs_serial.uart, mav_chan);
} }
uint16_t uint16_t

Loading…
Cancel
Save