|
|
|
@ -76,55 +76,29 @@ uint8_t GCS_MAVLINK::mavlink_private = 0;
@@ -76,55 +76,29 @@ uint8_t GCS_MAVLINK::mavlink_private = 0;
|
|
|
|
|
|
|
|
|
|
GCS *GCS::_singleton = nullptr; |
|
|
|
|
|
|
|
|
|
GCS_MAVLINK::GCS_MAVLINK() |
|
|
|
|
GCS_MAVLINK::GCS_MAVLINK(GCS_MAVLINK_Parameters ¶meters, |
|
|
|
|
AP_HAL::UARTDriver &uart) |
|
|
|
|
{ |
|
|
|
|
AP_Param::setup_object_defaults(this, var_info); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
GCS_MAVLINK::init(AP_HAL::UARTDriver *port, mavlink_channel_t mav_chan) |
|
|
|
|
{ |
|
|
|
|
if (!valid_channel(mav_chan)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_port = port; |
|
|
|
|
chan = mav_chan; |
|
|
|
|
|
|
|
|
|
mavlink_comm_port[chan] = _port; |
|
|
|
|
_queued_parameter = nullptr; |
|
|
|
|
_port = &uart; |
|
|
|
|
|
|
|
|
|
snprintf(_perf_packet_name, sizeof(_perf_packet_name), "GCS_Packet_%u", chan); |
|
|
|
|
_perf_packet = hal.util->perf_alloc(AP_HAL::Util::PC_ELAPSED, _perf_packet_name); |
|
|
|
|
|
|
|
|
|
snprintf(_perf_update_name, sizeof(_perf_update_name), "GCS_Update_%u", chan); |
|
|
|
|
_perf_update = hal.util->perf_alloc(AP_HAL::Util::PC_ELAPSED, _perf_update_name); |
|
|
|
|
|
|
|
|
|
initialised = true; |
|
|
|
|
streamRates = parameters.streamRates; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
setup a UART, handling begin() and init() |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
GCS_MAVLINK::setup_uart(uint8_t instance) |
|
|
|
|
bool GCS_MAVLINK::init(uint8_t instance) |
|
|
|
|
{ |
|
|
|
|
// search for serial port
|
|
|
|
|
const AP_SerialManager& serial_manager = AP::serialmanager(); |
|
|
|
|
const AP_SerialManager::SerialProtocol protocol = AP_SerialManager::SerialProtocol_MAVLink; |
|
|
|
|
|
|
|
|
|
AP_HAL::UARTDriver *uart = serial_manager.find_serial(protocol, instance); |
|
|
|
|
if (uart == nullptr) { |
|
|
|
|
// return immediately if not found
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const AP_SerialManager::SerialProtocol protocol = AP_SerialManager::SerialProtocol_MAVLink; |
|
|
|
|
|
|
|
|
|
// get associated mavlink channel
|
|
|
|
|
mavlink_channel_t mav_chan; |
|
|
|
|
if (!serial_manager.get_mavlink_channel(protocol, instance, mav_chan)) { |
|
|
|
|
if (!serial_manager.get_mavlink_channel(protocol, instance, chan)) { |
|
|
|
|
// return immediately in unlikely case mavlink channel cannot be found
|
|
|
|
|
return; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
// and init the gcs instance
|
|
|
|
|
if (!valid_channel(chan)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -135,29 +109,35 @@ GCS_MAVLINK::setup_uart(uint8_t instance)
@@ -135,29 +109,35 @@ GCS_MAVLINK::setup_uart(uint8_t instance)
|
|
|
|
|
0x20 at 115200 on startup, which tells the bootloader to reset |
|
|
|
|
and boot normally |
|
|
|
|
*/ |
|
|
|
|
uart->begin(115200); |
|
|
|
|
AP_HAL::UARTDriver::flow_control old_flow_control = uart->get_flow_control(); |
|
|
|
|
uart->set_flow_control(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE); |
|
|
|
|
_port->begin(115200); |
|
|
|
|
AP_HAL::UARTDriver::flow_control old_flow_control = _port->get_flow_control(); |
|
|
|
|
_port->set_flow_control(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE); |
|
|
|
|
for (uint8_t i=0; i<3; i++) { |
|
|
|
|
hal.scheduler->delay(1); |
|
|
|
|
uart->write(0x30); |
|
|
|
|
uart->write(0x20); |
|
|
|
|
_port->write(0x30); |
|
|
|
|
_port->write(0x20); |
|
|
|
|
} |
|
|
|
|
// since tcdrain() and TCSADRAIN may not be implemented...
|
|
|
|
|
hal.scheduler->delay(1); |
|
|
|
|
|
|
|
|
|
uart->set_flow_control(old_flow_control); |
|
|
|
|
_port->set_flow_control(old_flow_control); |
|
|
|
|
|
|
|
|
|
// now change back to desired baudrate
|
|
|
|
|
uart->begin(serial_manager.find_baudrate(protocol, instance)); |
|
|
|
|
_port->begin(serial_manager.find_baudrate(protocol, instance)); |
|
|
|
|
|
|
|
|
|
// and init the gcs instance
|
|
|
|
|
init(uart, mav_chan); |
|
|
|
|
mavlink_comm_port[chan] = _port; |
|
|
|
|
|
|
|
|
|
// create performance counters
|
|
|
|
|
snprintf(_perf_packet_name, sizeof(_perf_packet_name), "GCS_Packet_%u", chan); |
|
|
|
|
_perf_packet = hal.util->perf_alloc(AP_HAL::Util::PC_ELAPSED, _perf_packet_name); |
|
|
|
|
|
|
|
|
|
snprintf(_perf_update_name, sizeof(_perf_update_name), "GCS_Update_%u", chan); |
|
|
|
|
_perf_update = hal.util->perf_alloc(AP_HAL::Util::PC_ELAPSED, _perf_update_name); |
|
|
|
|
|
|
|
|
|
AP_SerialManager::SerialProtocol mavlink_protocol = AP::serialmanager().get_mavlink_protocol(mav_chan); |
|
|
|
|
AP_SerialManager::SerialProtocol mavlink_protocol = serial_manager.get_mavlink_protocol(chan); |
|
|
|
|
mavlink_status_t *status = mavlink_get_channel_status(chan); |
|
|
|
|
if (status == nullptr) { |
|
|
|
|
return; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mavlink_protocol == AP_SerialManager::SerialProtocol_MAVLink2) { |
|
|
|
@ -178,6 +158,8 @@ GCS_MAVLINK::setup_uart(uint8_t instance)
@@ -178,6 +158,8 @@ GCS_MAVLINK::setup_uart(uint8_t instance)
|
|
|
|
|
// after experiments with MAVLink2
|
|
|
|
|
status->flags |= MAVLINK_STATUS_FLAG_OUT_MAVLINK1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GCS_MAVLINK::send_meminfo(void) |
|
|
|
@ -1845,9 +1827,7 @@ void GCS::service_statustext(void)
@@ -1845,9 +1827,7 @@ void GCS::service_statustext(void)
|
|
|
|
|
void GCS::send_message(enum ap_message id) |
|
|
|
|
{ |
|
|
|
|
for (uint8_t i=0; i<num_gcs(); i++) { |
|
|
|
|
if (chan(i).initialised) { |
|
|
|
|
chan(i).send_message(id); |
|
|
|
|
} |
|
|
|
|
chan(i)->send_message(id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1872,9 +1852,7 @@ void GCS::update_send()
@@ -1872,9 +1852,7 @@ void GCS::update_send()
|
|
|
|
|
_missionitemprotocol_rally->update(); |
|
|
|
|
} |
|
|
|
|
for (uint8_t i=0; i<num_gcs(); i++) { |
|
|
|
|
if (chan(i).initialised) { |
|
|
|
|
chan(i).update_send(); |
|
|
|
|
} |
|
|
|
|
chan(i)->update_send(); |
|
|
|
|
} |
|
|
|
|
WITH_SEMAPHORE(_statustext_sem); |
|
|
|
|
service_statustext(); |
|
|
|
@ -1883,9 +1861,7 @@ void GCS::update_send()
@@ -1883,9 +1861,7 @@ void GCS::update_send()
|
|
|
|
|
void GCS::update_receive(void) |
|
|
|
|
{ |
|
|
|
|
for (uint8_t i=0; i<num_gcs(); i++) { |
|
|
|
|
if (chan(i).initialised) { |
|
|
|
|
chan(i).update_receive(); |
|
|
|
|
} |
|
|
|
|
chan(i)->update_receive(); |
|
|
|
|
} |
|
|
|
|
// also update UART pass-thru, if enabled
|
|
|
|
|
update_passthru(); |
|
|
|
@ -1894,17 +1870,62 @@ void GCS::update_receive(void)
@@ -1894,17 +1870,62 @@ void GCS::update_receive(void)
|
|
|
|
|
void GCS::send_mission_item_reached_message(uint16_t mission_index) |
|
|
|
|
{ |
|
|
|
|
for (uint8_t i=0; i<num_gcs(); i++) { |
|
|
|
|
if (chan(i).initialised) { |
|
|
|
|
chan(i).mission_item_reached_index = mission_index; |
|
|
|
|
chan(i).send_message(MSG_MISSION_ITEM_REACHED); |
|
|
|
|
chan(i)->mission_item_reached_index = mission_index; |
|
|
|
|
chan(i)->send_message(MSG_MISSION_ITEM_REACHED); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GCS::setup_console() |
|
|
|
|
{ |
|
|
|
|
AP_HAL::UARTDriver *uart = AP::serialmanager().find_serial(AP_SerialManager::SerialProtocol_MAVLink, 0); |
|
|
|
|
if (uart == nullptr) { |
|
|
|
|
// this is probably not going to end well.
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (ARRAY_SIZE(chan_parameters) == 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
create_gcs_mavlink_backend(chan_parameters[0], *uart); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GCS_MAVLINK_Parameters::GCS_MAVLINK_Parameters() |
|
|
|
|
{ |
|
|
|
|
AP_Param::setup_object_defaults(this, var_info); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GCS::create_gcs_mavlink_backend(GCS_MAVLINK_Parameters ¶ms, AP_HAL::UARTDriver &uart) |
|
|
|
|
{ |
|
|
|
|
if (_num_gcs >= ARRAY_SIZE(chan_parameters)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
_chan[_num_gcs] = new_gcs_mavlink_backend(params, uart); |
|
|
|
|
if (_chan[_num_gcs] == nullptr) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!_chan[_num_gcs]->init(_num_gcs)) { |
|
|
|
|
delete _chan[_num_gcs]; |
|
|
|
|
_chan[_num_gcs] = nullptr; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_num_gcs++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GCS::setup_uarts() |
|
|
|
|
{ |
|
|
|
|
for (uint8_t i = 1; i < MAVLINK_COMM_NUM_BUFFERS; i++) { |
|
|
|
|
chan(i).setup_uart(i); |
|
|
|
|
if (i >= ARRAY_SIZE(chan_parameters)) { |
|
|
|
|
// should not happen
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
AP_HAL::UARTDriver *uart = AP::serialmanager().find_serial(AP_SerialManager::SerialProtocol_MAVLink, i); |
|
|
|
|
if (uart == nullptr) { |
|
|
|
|
// no more mavlink uarts
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
create_gcs_mavlink_backend(chan_parameters[i], *uart); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (frsky == nullptr) { |
|
|
|
|