Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions frontend/dronebridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ function get_stats() {
} else if (!isNaN(tcp_clients)) {
document.getElementById("tcp_connected").innerHTML = tcp_clients + " clients"
}

if (json_data["fc_connected"]) {
document.getElementById("fc_sys_id_div").innerHTML = "MAVLink System ID: " + json_data["fc_sys_id"];
} else {
document.getElementById("fc_sys_id_div").innerHTML = "No Flight Controller connected.";
}

// UDP clients for tooltip
let udp_clients_string = ""
if (json_data.hasOwnProperty("udp_clients")) {
Expand Down
12 changes: 9 additions & 3 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ <h2>Statistics</h2>
</div>
</div>
<div class="row">
<div class="four columns">
<label>received bytes serial port</label>
<div id="read_bytes">-</div>
<div id="fc_sys_id_div" class="twelve columns small_text">
</div>
</div>
<div class="row">
<div class="four columns">
<label>Connected TCP clients</label>
<div id="tcp_connected">-</div>
Expand All @@ -55,6 +55,12 @@ <h2>Statistics</h2>
</div>
</div>
</div>
<div class="row">
<div class="four columns">
<label>received bytes serial port</label>
<div id="read_bytes">-</div>
</div>
</div>
</div>
<div>
<h2>Settings</h2>
Expand Down
18 changes: 18 additions & 0 deletions main/db_mavlink_msgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
#include <string.h>
#include <esp_log.h>
#include <esp_timer.h>

#include "db_mavlink_msgs.h"
#include "db_parameters.h"
Expand All @@ -36,6 +37,22 @@
#define FASTMAVLINK_ROUTER_COMPONENTS_MAX 5

#define TAG "DB_MAV_MSGS"
uint8_t DB_MAV_SYS_ID = 1;
uint32_t last_fc_heartbeat_ms = 0;

/**
* Returns true if we recently saw a heartbeat from a flight controller on the serial link
*/
bool fc_connected() {
return (esp_timer_get_time() / 1000 - last_fc_heartbeat_ms) < 2500;
}

/**
* Returns the current flight controller system ID (last seen)
*/
uint8_t db_get_fc_sys_id() {
return DB_MAV_SYS_ID;
}

/**
* Based on the system architecture and configured wifi mode the ESP32 may have a different role and system id.
Expand Down Expand Up @@ -334,6 +351,7 @@ void handle_mavlink_message(fmav_message_t *new_msg, int *tcp_clients, udp_conn_
// This means we are connected to the FC since we only parse mavlink on UART and thus only see the
// device we are connected to via UART
DB_MAV_SYS_ID = new_msg->sysid;
last_fc_heartbeat_ms = esp_timer_get_time() / 1000;
// Check if FC is armed and the Wi-Fi switch based on armed status is configured by the user
if (DB_PARAM_DIS_RADIO_ON_ARM &&
(payload.base_mode & MAV_MODE_FLAG_SAFETY_ARMED ||
Expand Down
2 changes: 2 additions & 0 deletions main/db_mavlink_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

uint8_t db_get_mav_comp_id();
uint8_t db_get_mav_sys_id();
bool fc_connected();
uint8_t db_get_fc_sys_id();
int8_t db_format_rssi(int8_t signal_strength, int8_t noise_floor);
uint16_t db_mav_create_heartbeat(uint8_t *buff, fmav_status_t *fmav_status);
uint16_t db_get_mavmsg_param_value(uint8_t *buff, fmav_status_t *fmav_status, uint16_t param_index, float_int_union *value, uint8_t type, char *param_id);
Expand Down
1 change: 0 additions & 1 deletion main/db_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

#define TAG "DB_SERIAL"

uint8_t DB_MAV_SYS_ID = 1;
uint32_t serial_total_byte_count = 0;
uint32_t serial_total_decoded_mav_msgs = 0;
uint16_t DB_SERIAL_READ_TIMEOUT_MS = DB_SERIAL_READ_TIMEOUT_MS_DEFAULT;
Expand Down
3 changes: 3 additions & 0 deletions main/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "globals.h"
#include "main.h"
#include "db_serial.h"
#include "db_mavlink_msgs.h"

#define TAG "DB_HTTP_REST"
#define REST_CHECK(a, str, goto_tag, ...) \
Expand Down Expand Up @@ -332,6 +333,8 @@ static esp_err_t system_stats_get_handler(httpd_req_t *req) {
cJSON_AddNumberToObject(root, "serial_dec_mav_msgs", serial_total_decoded_mav_msgs);
cJSON_AddNumberToObject(root, "tcp_connected", num_connected_tcp_clients);
cJSON_AddNumberToObject(root, "udp_connected", udp_conn_list->size);
cJSON_AddBoolToObject(root, "fc_connected", fc_connected());
cJSON_AddNumberToObject(root, "fc_sys_id", db_get_fc_sys_id());
// add IP:PORT info on connected UDP clients
cJSON *udp_clients = cJSON_CreateArray();
for (int i = 0; i < udp_conn_list->size; i++) {
Expand Down
Loading