16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 15:09:19 +02:00

(uart, debug) add UART debug panel with connection information

This commit is contained in:
Marcin Nowak
2021-10-16 02:16:17 +02:00
parent 0c1bcdcadf
commit a0153b1d7b
7 changed files with 93 additions and 10 deletions

View File

@@ -13,6 +13,9 @@ http://mozilla.org/MPL/2.0/.
#include "PyInt.h" #include "PyInt.h"
#include "network/manager.h" #include "network/manager.h"
#include "headtrack.h" #include "headtrack.h"
#ifdef WITH_UART
#include "uart.h"
#endif
class eu07_application { class eu07_application {
const int MAX_NETWORK_PER_FRAME = 1000; const int MAX_NETWORK_PER_FRAME = 1000;
@@ -91,6 +94,9 @@ public:
is_server() const; is_server() const;
bool bool
is_client() const; is_client() const;
#ifdef WITH_UART
UartStatus uart_status;
#endif
private: private:
// types // types

View File

@@ -40,6 +40,9 @@ driver_ui::driver_ui() {
m_aidpanel.title = STR("Driving Aid"); m_aidpanel.title = STR("Driving Aid");
m_scenariopanel.size_min = { 435, 50 };
m_scenariopanel.size_max = { Global.fb_size.x * 0.95f, Global.fb_size.y * 0.95 };
m_scenariopanel.title = STR("Scenario"); m_scenariopanel.title = STR("Scenario");
m_scenariopanel.size_min = { 435, 85 }; m_scenariopanel.size_min = { 435, 85 };
m_scenariopanel.size_max = { Global.fb_size.x * 0.95f, Global.fb_size.y * 0.95 }; m_scenariopanel.size_max = { Global.fb_size.x * 0.95f, Global.fb_size.y * 0.95 };

View File

@@ -548,6 +548,7 @@ debug_panel::update() {
m_powergridlines.clear(); m_powergridlines.clear();
m_cameralines.clear(); m_cameralines.clear();
m_rendererlines.clear(); m_rendererlines.clear();
m_uartlines.clear();
update_section_vehicle( m_vehiclelines ); update_section_vehicle( m_vehiclelines );
update_section_engine( m_enginelines ); update_section_engine( m_enginelines );
@@ -558,6 +559,7 @@ debug_panel::update() {
update_section_powergrid( m_powergridlines ); update_section_powergrid( m_powergridlines );
update_section_camera( m_cameralines ); update_section_camera( m_cameralines );
update_section_renderer( m_rendererlines ); update_section_renderer( m_rendererlines );
update_section_uart(m_uartlines);
} }
void void
@@ -610,6 +612,11 @@ debug_panel::render() {
render_section( "Camera", m_cameralines ); render_section( "Camera", m_cameralines );
render_section( "Gfx Renderer", m_rendererlines ); render_section( "Gfx Renderer", m_rendererlines );
render_section_settings(); render_section_settings();
#ifdef WITH_UART
if(true == render_section( "UART", m_uartlines)) {
//ImGui::Checkbox("Enabled", &Global.uart_conf.enable);
}
#endif
// toggles // toggles
ImGui::Separator(); ImGui::Separator();
ImGui::Checkbox( "Debug Mode", &DebugModeFlag ); ImGui::Checkbox( "Debug Mode", &DebugModeFlag );
@@ -619,6 +626,13 @@ debug_panel::render() {
ImGui::PopFont(); ImGui::PopFont();
} }
#ifdef WITH_UART
bool
debug_panel::render_section_uart() {
return true;
};
#endif
bool bool
debug_panel::render_section_scenario() { debug_panel::render_section_scenario() {
@@ -1213,6 +1227,27 @@ debug_panel::update_section_scantable( std::vector<text_line> &Output ) {
} }
} }
#ifdef WITH_UART
void
debug_panel::update_section_uart( std::vector<text_line> &Output ) {
Output.emplace_back(("Port: " + Global.uart_conf.port).c_str(), Global.UITextColor);
Output.emplace_back(("Baud: " + std::to_string(Global.uart_conf.baud)).c_str(), Global.UITextColor);
if(Application.uart_status.is_connected) {
std::string synctext = Application.uart_status.is_synced ? "SYNCED" : "NOT SYNCED";
Output.emplace_back(("CONNECTED, " + synctext).c_str(), Global.UITextColor);
} else {
Output.emplace_back("* NOT CONNECTED *", Global.UITextColor);
}
Output.emplace_back(
(
"Packets sent: "+std::to_string(Application.uart_status.packets_sent)
+" Packets received: "+std::to_string(Application.uart_status.packets_received)
).c_str(),
Global.UITextColor
);
}
#endif
void void
debug_panel::update_section_scenario( std::vector<text_line> &Output ) { debug_panel::update_section_scenario( std::vector<text_line> &Output ) {

View File

@@ -89,6 +89,9 @@ private:
void update_section_powergrid( std::vector<text_line> &Output ); void update_section_powergrid( std::vector<text_line> &Output );
void update_section_camera( std::vector<text_line> &Output ); void update_section_camera( std::vector<text_line> &Output );
void update_section_renderer( std::vector<text_line> &Output ); void update_section_renderer( std::vector<text_line> &Output );
#ifdef WITH_UART
void update_section_uart( std::vector<text_line> &Output );
#endif
// section update helpers // section update helpers
std::string update_vehicle_coupler( int const Side ); std::string update_vehicle_coupler( int const Side );
std::string update_vehicle_brake() const; std::string update_vehicle_brake() const;
@@ -97,6 +100,9 @@ private:
bool render_section( std::vector<text_line> const &Lines ); bool render_section( std::vector<text_line> const &Lines );
bool render_section_scenario(); bool render_section_scenario();
bool render_section_eventqueue(); bool render_section_eventqueue();
#ifdef WITH_UART
bool render_section_uart();
#endif
bool render_section_settings(); bool render_section_settings();
// members // members
std::array<char, 1024> m_buffer; std::array<char, 1024> m_buffer;
@@ -111,7 +117,13 @@ private:
m_scenariolines, m_scenariolines,
m_eventqueuelines, m_eventqueuelines,
m_powergridlines, m_powergridlines,
#ifdef WITH_UART
m_rendererlines,
m_uartlines;
#else
m_rendererlines; m_rendererlines;
#endif
double last_time = std::numeric_limits<double>::quiet_NaN(); double last_time = std::numeric_limits<double>::quiet_NaN();

View File

@@ -7,6 +7,7 @@
#include "parser.h" #include "parser.h"
#include "Logs.h" #include "Logs.h"
#include "simulationtime.h" #include "simulationtime.h"
#include "application.h"
uart_input::uart_input() uart_input::uart_input()
{ {
@@ -29,6 +30,7 @@ bool uart_input::setup_port()
if (sp_get_port_by_name(conf.port.c_str(), &port) != SP_OK) { if (sp_get_port_by_name(conf.port.c_str(), &port) != SP_OK) {
if(!error_notified) { if(!error_notified) {
Application.uart_status.is_connected = false;
ErrorLog("uart: cannot find specified port '"+conf.port+"'"); ErrorLog("uart: cannot find specified port '"+conf.port+"'");
} }
error_notified = true; error_notified = true;
@@ -37,6 +39,7 @@ bool uart_input::setup_port()
if (sp_open(port, (sp_mode)(SP_MODE_READ | SP_MODE_WRITE)) != SP_OK) { if (sp_open(port, (sp_mode)(SP_MODE_READ | SP_MODE_WRITE)) != SP_OK) {
if(!error_notified) { if(!error_notified) {
Application.uart_status.is_connected = false;
ErrorLog("uart: cannot open port '"+conf.port+"'"); ErrorLog("uart: cannot open port '"+conf.port+"'");
} }
error_notified = true; error_notified = true;
@@ -54,6 +57,7 @@ bool uart_input::setup_port()
sp_set_config_parity(config, SP_PARITY_NONE) != SP_OK || sp_set_config_parity(config, SP_PARITY_NONE) != SP_OK ||
sp_set_config(port, config) != SP_OK) { sp_set_config(port, config) != SP_OK) {
if(!error_notified) { if(!error_notified) {
Application.uart_status.is_connected = false;
ErrorLog("uart: cannot set config"); ErrorLog("uart: cannot set config");
} }
error_notified = true; error_notified = true;
@@ -65,6 +69,7 @@ bool uart_input::setup_port()
if (sp_flush(port, SP_BUF_BOTH) != SP_OK) { if (sp_flush(port, SP_BUF_BOTH) != SP_OK) {
if(!error_notified) { if(!error_notified) {
Application.uart_status.is_connected = false;
ErrorLog("uart: cannot flush"); ErrorLog("uart: cannot flush");
} }
error_notified = true; error_notified = true;
@@ -72,7 +77,11 @@ bool uart_input::setup_port()
return false; return false;
} }
if(error_notified || !Application.uart_status.is_connected) {
error_notified = false; error_notified = false;
ErrorLog("uart: connected to '"+conf.port+"'");
Application.uart_status.is_connected = true;
}
return true; return true;
} }
@@ -205,11 +214,13 @@ void uart_input::poll()
bool sync; bool sync;
if (tmp_buffer[0] != 0xEF || tmp_buffer[1] != 0xEF || tmp_buffer[2] != 0xEF || tmp_buffer[3] != 0xEF) { if (tmp_buffer[0] != 0xEF || tmp_buffer[1] != 0xEF || tmp_buffer[2] != 0xEF || tmp_buffer[3] != 0xEF) {
Application.uart_status.is_synced = false;
if (conf.debug) if (conf.debug)
WriteLog("uart: bad sync"); WriteLog("uart: bad sync");
sync = false; sync = false;
} }
else { else {
Application.uart_status.is_synced = true;
if (conf.debug) if (conf.debug)
WriteLog("uart: sync ok"); WriteLog("uart: sync ok");
sync = true; sync = true;
@@ -253,6 +264,7 @@ void uart_input::poll()
std::array<uint8_t, 16> buffer; std::array<uint8_t, 16> buffer;
memmove(&buffer[0], &tmp_buffer[4], 16); memmove(&buffer[0], &tmp_buffer[4], 16);
Application.uart_status.packets_received++;
if (conf.debug) if (conf.debug)
{ {
@@ -475,7 +487,12 @@ void uart_input::poll()
setup_port(); setup_port();
return; return;
} }
Application.uart_status.packets_sent++;
data_pending = true; data_pending = true;
} }
} }
bool uart_input::is_connected() {
return (port != nullptr);
}

10
uart.h
View File

@@ -3,6 +3,14 @@
#include <libserialport.h> #include <libserialport.h>
#include "command.h" #include "command.h"
class UartStatus {
public:
bool is_connected = false;
bool is_synced = false;
unsigned long packets_sent = 0;
unsigned long packets_received = 0;
};
class uart_input class uart_input
{ {
public: public:
@@ -52,6 +60,8 @@ public:
recall_bindings(); recall_bindings();
void void
poll(); poll();
bool
is_connected();
private: private:
// types // types