|
|
|
@ -154,6 +154,7 @@ mavlink_send_uart_bytes(mavlink_channel_t channel, const uint8_t *ch, int length
@@ -154,6 +154,7 @@ mavlink_send_uart_bytes(mavlink_channel_t channel, const uint8_t *ch, int length
|
|
|
|
|
instance = Mavlink::get_instance(6); |
|
|
|
|
break; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -178,8 +179,7 @@ mavlink_send_uart_bytes(mavlink_channel_t channel, const uint8_t *ch, int length
@@ -178,8 +179,7 @@ mavlink_send_uart_bytes(mavlink_channel_t channel, const uint8_t *ch, int length
|
|
|
|
|
if (last_write_try_times[(unsigned)channel] != 0 && |
|
|
|
|
hrt_elapsed_time(&last_write_success_times[(unsigned)channel]) > 500 * 1000UL && |
|
|
|
|
last_write_success_times[(unsigned)channel] != |
|
|
|
|
last_write_try_times[(unsigned)channel]) |
|
|
|
|
{ |
|
|
|
|
last_write_try_times[(unsigned)channel]) { |
|
|
|
|
warnx("DISABLING HARDWARE FLOW CONTROL"); |
|
|
|
|
instance->enable_flow_control(false); |
|
|
|
|
} |
|
|
|
@ -197,15 +197,20 @@ mavlink_send_uart_bytes(mavlink_channel_t channel, const uint8_t *ch, int length
@@ -197,15 +197,20 @@ mavlink_send_uart_bytes(mavlink_channel_t channel, const uint8_t *ch, int length
|
|
|
|
|
if (buf_free < desired) { |
|
|
|
|
/* we don't want to send anything just in half, so return */ |
|
|
|
|
instance->count_txerr(); |
|
|
|
|
instance->count_txerrbytes(desired); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ssize_t ret = write(uart, ch, desired); |
|
|
|
|
|
|
|
|
|
if (ret != desired) { |
|
|
|
|
instance->count_txerr(); |
|
|
|
|
instance->count_txerrbytes(desired); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
last_write_success_times[(unsigned)channel] = last_write_try_times[(unsigned)channel]; |
|
|
|
|
instance->count_txbytes(desired); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -247,6 +252,14 @@ Mavlink::Mavlink() :
@@ -247,6 +252,14 @@ Mavlink::Mavlink() :
|
|
|
|
|
_subscribe_to_stream(nullptr), |
|
|
|
|
_subscribe_to_stream_rate(0.0f), |
|
|
|
|
_flow_control_enabled(true), |
|
|
|
|
_bytes_tx(0), |
|
|
|
|
_bytes_txerr(0), |
|
|
|
|
_bytes_rx(0), |
|
|
|
|
_bytes_timestamp(0), |
|
|
|
|
_rate_tx(0.0f), |
|
|
|
|
_rate_txerr(0.0f), |
|
|
|
|
_rate_rx(0.0f), |
|
|
|
|
_rstatus {}, |
|
|
|
|
_message_buffer {}, |
|
|
|
|
_message_buffer_mutex {}, |
|
|
|
|
_param_initialized(false), |
|
|
|
@ -424,6 +437,27 @@ Mavlink::destroy_all_instances()
@@ -424,6 +437,27 @@ Mavlink::destroy_all_instances()
|
|
|
|
|
return OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
Mavlink::get_status_all_instances() |
|
|
|
|
{ |
|
|
|
|
Mavlink *inst = ::_mavlink_instances; |
|
|
|
|
|
|
|
|
|
unsigned iterations = 0; |
|
|
|
|
|
|
|
|
|
while (inst != nullptr) { |
|
|
|
|
|
|
|
|
|
printf("\ninstance #%u:\n", iterations); |
|
|
|
|
inst->display_status(); |
|
|
|
|
|
|
|
|
|
/* move on */ |
|
|
|
|
inst = inst->next; |
|
|
|
|
iterations++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* return an error if there are no instances */ |
|
|
|
|
return (iterations == 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
Mavlink::instance_exists(const char *device_name, Mavlink *self) |
|
|
|
|
{ |
|
|
|
@ -615,7 +649,8 @@ int Mavlink::mavlink_open_uart(int baud, const char *uart_name, struct termios *
@@ -615,7 +649,8 @@ int Mavlink::mavlink_open_uart(int baud, const char *uart_name, struct termios *
|
|
|
|
|
case 921600: speed = B921600; break; |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
warnx("ERROR: Unsupported baudrate: %d\n\tsupported examples:\n\t9600, 19200, 38400, 57600\t\n115200\n230400\n460800\n921600\n", baud); |
|
|
|
|
warnx("ERROR: Unsupported baudrate: %d\n\tsupported examples:\n\t9600, 19200, 38400, 57600\t\n115200\n230400\n460800\n921600\n", |
|
|
|
|
baud); |
|
|
|
|
return -EINVAL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -845,6 +880,7 @@ void Mavlink::mavlink_pm_message_handler(const mavlink_channel_t chan, const mav
@@ -845,6 +880,7 @@ void Mavlink::mavlink_pm_message_handler(const mavlink_channel_t chan, const mav
|
|
|
|
|
case MAVLINK_MSG_ID_PARAM_REQUEST_LIST: { |
|
|
|
|
mavlink_param_request_list_t req; |
|
|
|
|
mavlink_msg_param_request_list_decode(msg, &req); |
|
|
|
|
|
|
|
|
|
if (req.target_system == mavlink_system.sysid && |
|
|
|
|
(req.target_component == mavlink_system.compid || req.target_component == MAV_COMP_ID_ALL)) { |
|
|
|
|
/* Start sending parameters */ |
|
|
|
@ -861,7 +897,9 @@ void Mavlink::mavlink_pm_message_handler(const mavlink_channel_t chan, const mav
@@ -861,7 +897,9 @@ void Mavlink::mavlink_pm_message_handler(const mavlink_channel_t chan, const mav
|
|
|
|
|
mavlink_param_set_t mavlink_param_set; |
|
|
|
|
mavlink_msg_param_set_decode(msg, &mavlink_param_set); |
|
|
|
|
|
|
|
|
|
if (mavlink_param_set.target_system == mavlink_system.sysid && ((mavlink_param_set.target_component == mavlink_system.compid) || (mavlink_param_set.target_component == MAV_COMP_ID_ALL))) { |
|
|
|
|
if (mavlink_param_set.target_system == mavlink_system.sysid |
|
|
|
|
&& ((mavlink_param_set.target_component == mavlink_system.compid) |
|
|
|
|
|| (mavlink_param_set.target_component == MAV_COMP_ID_ALL))) { |
|
|
|
|
/* local name buffer to enforce null-terminated string */ |
|
|
|
|
char name[MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN + 1]; |
|
|
|
|
strncpy(name, mavlink_param_set.param_id, MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN); |
|
|
|
@ -888,7 +926,9 @@ void Mavlink::mavlink_pm_message_handler(const mavlink_channel_t chan, const mav
@@ -888,7 +926,9 @@ void Mavlink::mavlink_pm_message_handler(const mavlink_channel_t chan, const mav
|
|
|
|
|
mavlink_param_request_read_t mavlink_param_request_read; |
|
|
|
|
mavlink_msg_param_request_read_decode(msg, &mavlink_param_request_read); |
|
|
|
|
|
|
|
|
|
if (mavlink_param_request_read.target_system == mavlink_system.sysid && ((mavlink_param_request_read.target_component == mavlink_system.compid) || (mavlink_param_request_read.target_component == MAV_COMP_ID_ALL))) { |
|
|
|
|
if (mavlink_param_request_read.target_system == mavlink_system.sysid |
|
|
|
|
&& ((mavlink_param_request_read.target_component == mavlink_system.compid) |
|
|
|
|
|| (mavlink_param_request_read.target_component == MAV_COMP_ID_ALL))) { |
|
|
|
|
/* when no index is given, loop through string ids and compare them */ |
|
|
|
|
if (mavlink_param_request_read.param_index == -1) { |
|
|
|
|
/* local name buffer to enforce null-terminated string */ |
|
|
|
@ -954,9 +994,11 @@ Mavlink::send_statustext(unsigned severity, const char *string)
@@ -954,9 +994,11 @@ Mavlink::send_statustext(unsigned severity, const char *string)
|
|
|
|
|
case MAVLINK_IOC_SEND_TEXT_INFO: |
|
|
|
|
statustext.severity = MAV_SEVERITY_INFO; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case MAVLINK_IOC_SEND_TEXT_CRITICAL: |
|
|
|
|
statustext.severity = MAV_SEVERITY_CRITICAL; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case MAVLINK_IOC_SEND_TEXT_EMERGENCY: |
|
|
|
|
statustext.severity = MAV_SEVERITY_EMERGENCY; |
|
|
|
|
break; |
|
|
|
@ -1079,9 +1121,11 @@ Mavlink::message_buffer_init(int size)
@@ -1079,9 +1121,11 @@ Mavlink::message_buffer_init(int size)
|
|
|
|
|
_message_buffer.data = (char *)malloc(_message_buffer.size); |
|
|
|
|
|
|
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
if (_message_buffer.data == 0) { |
|
|
|
|
ret = ERROR; |
|
|
|
|
_message_buffer.size = 0; |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
ret = OK; |
|
|
|
|
} |
|
|
|
@ -1395,7 +1439,7 @@ Mavlink::task_main(int argc, char *argv[])
@@ -1395,7 +1439,7 @@ Mavlink::task_main(int argc, char *argv[])
|
|
|
|
|
configure_stream("GPS_GLOBAL_ORIGIN", 0.5f); |
|
|
|
|
configure_stream("HIGHRES_IMU", 1.0f * rate_mult); |
|
|
|
|
configure_stream("ATTITUDE", 10.0f * rate_mult); |
|
|
|
|
configure_stream("VFR_HUD", 10.0f * rate_mult); |
|
|
|
|
configure_stream("VFR_HUD", 8.0f * rate_mult); |
|
|
|
|
configure_stream("GPS_RAW_INT", 1.0f * rate_mult); |
|
|
|
|
configure_stream("GLOBAL_POSITION_INT", 3.0f * rate_mult); |
|
|
|
|
configure_stream("LOCAL_POSITION_NED", 3.0f * rate_mult); |
|
|
|
@ -1453,7 +1497,8 @@ Mavlink::task_main(int argc, char *argv[])
@@ -1453,7 +1497,8 @@ Mavlink::task_main(int argc, char *argv[])
|
|
|
|
|
if (_subscribe_to_stream != nullptr) { |
|
|
|
|
if (OK == configure_stream(_subscribe_to_stream, _subscribe_to_stream_rate)) { |
|
|
|
|
if (_subscribe_to_stream_rate > 0.0f) { |
|
|
|
|
warnx("stream %s on device %s enabled with rate %.1f Hz", _subscribe_to_stream, _device_name, (double)_subscribe_to_stream_rate); |
|
|
|
|
warnx("stream %s on device %s enabled with rate %.1f Hz", _subscribe_to_stream, _device_name, |
|
|
|
|
(double)_subscribe_to_stream_rate); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
warnx("stream %s on device %s disabled", _subscribe_to_stream, _device_name); |
|
|
|
@ -1506,6 +1551,7 @@ Mavlink::task_main(int argc, char *argv[])
@@ -1506,6 +1551,7 @@ Mavlink::task_main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
|
// Pull a single message from the buffer
|
|
|
|
|
size_t read_count = available; |
|
|
|
|
|
|
|
|
|
if (read_count > sizeof(mavlink_message_t)) { |
|
|
|
|
read_count = sizeof(mavlink_message_t); |
|
|
|
|
} |
|
|
|
@ -1534,6 +1580,20 @@ Mavlink::task_main(int argc, char *argv[])
@@ -1534,6 +1580,20 @@ Mavlink::task_main(int argc, char *argv[])
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* update TX/RX rates*/ |
|
|
|
|
if (t > _bytes_timestamp + 1000000) { |
|
|
|
|
if (_bytes_timestamp != 0) { |
|
|
|
|
float dt = (t - _bytes_timestamp) / 1000.0f; |
|
|
|
|
_rate_tx = _bytes_tx / dt; |
|
|
|
|
_rate_txerr = _bytes_txerr / dt; |
|
|
|
|
_rate_rx = _bytes_rx / dt; |
|
|
|
|
_bytes_tx = 0; |
|
|
|
|
_bytes_txerr = 0; |
|
|
|
|
_bytes_rx = 0; |
|
|
|
|
} |
|
|
|
|
_bytes_timestamp = t; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
perf_end(_loop_perf); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1584,6 +1644,7 @@ Mavlink::task_main(int argc, char *argv[])
@@ -1584,6 +1644,7 @@ Mavlink::task_main(int argc, char *argv[])
|
|
|
|
|
message_buffer_destroy(); |
|
|
|
|
pthread_mutex_destroy(&_message_buffer_mutex); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* destroy log buffer */ |
|
|
|
|
mavlink_logbuffer_destroy(&_logbuffer); |
|
|
|
|
|
|
|
|
@ -1605,6 +1666,7 @@ int Mavlink::start_helper(int argc, char *argv[])
@@ -1605,6 +1666,7 @@ int Mavlink::start_helper(int argc, char *argv[])
|
|
|
|
|
/* out of memory */ |
|
|
|
|
res = -ENOMEM; |
|
|
|
|
warnx("OUT OF MEM"); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
/* this will actually only return once MAVLink exits */ |
|
|
|
|
res = instance->task_main(argc, argv); |
|
|
|
@ -1664,7 +1726,40 @@ Mavlink::start(int argc, char *argv[])
@@ -1664,7 +1726,40 @@ Mavlink::start(int argc, char *argv[])
|
|
|
|
|
void |
|
|
|
|
Mavlink::display_status() |
|
|
|
|
{ |
|
|
|
|
warnx("running"); |
|
|
|
|
|
|
|
|
|
if (_rstatus.heartbeat_time > 0) { |
|
|
|
|
printf("\tGCS heartbeat:\t%llu us ago\n", hrt_elapsed_time(&_rstatus.heartbeat_time)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (_rstatus.timestamp > 0) { |
|
|
|
|
|
|
|
|
|
printf("\ttype:\t\t"); |
|
|
|
|
|
|
|
|
|
switch (_rstatus.type) { |
|
|
|
|
case TELEMETRY_STATUS_RADIO_TYPE_3DR_RADIO: |
|
|
|
|
printf("3DR RADIO\n"); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
printf("UNKNOWN RADIO\n"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("\trssi:\t\t%d\n", _rstatus.rssi); |
|
|
|
|
printf("\tremote rssi:\t%u\n", _rstatus.remote_rssi); |
|
|
|
|
printf("\ttxbuf:\t\t%u\n", _rstatus.txbuf); |
|
|
|
|
printf("\tnoise:\t\t%d\n", _rstatus.noise); |
|
|
|
|
printf("\tremote noise:\t%u\n", _rstatus.remote_noise); |
|
|
|
|
printf("\trx errors:\t%u\n", _rstatus.rxerrors); |
|
|
|
|
printf("\tfixed:\t\t%u\n", _rstatus.fixed); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
printf("\tno telem status.\n"); |
|
|
|
|
} |
|
|
|
|
printf("\trates:\n"); |
|
|
|
|
printf("\ttx: %.3f kB/s\n", (double)_rate_tx); |
|
|
|
|
printf("\ttxerr: %.3f kB/s\n", (double)_rate_txerr); |
|
|
|
|
printf("\trx: %.3f kB/s\n", (double)_rate_rx); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
@ -1752,8 +1847,8 @@ int mavlink_main(int argc, char *argv[])
@@ -1752,8 +1847,8 @@ int mavlink_main(int argc, char *argv[])
|
|
|
|
|
} else if (!strcmp(argv[1], "stop-all")) { |
|
|
|
|
return Mavlink::destroy_all_instances(); |
|
|
|
|
|
|
|
|
|
// } else if (!strcmp(argv[1], "status")) {
|
|
|
|
|
// mavlink::g_mavlink->status();
|
|
|
|
|
} else if (!strcmp(argv[1], "status")) { |
|
|
|
|
return Mavlink::get_status_all_instances(); |
|
|
|
|
|
|
|
|
|
} else if (!strcmp(argv[1], "stream")) { |
|
|
|
|
return Mavlink::stream_command(argc, argv); |
|
|
|
|