(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 "network/manager.h"
#include "headtrack.h"
#ifdef WITH_UART
#include "uart.h"
#endif
class eu07_application {
const int MAX_NETWORK_PER_FRAME = 1000;
@@ -91,6 +94,9 @@ public:
is_server() const;
bool
is_client() const;
#ifdef WITH_UART
UartStatus uart_status;
#endif
private:
// types

View File

@@ -140,7 +140,7 @@ driver_mode::drivermode_input::command_fallback( user_command const Command ) co
if( lookup == commandfallbacks.end() ) {
return { user_command::none, user_command::none };
}
return lookup->second;
}
@@ -600,7 +600,7 @@ driver_mode::update_camera( double const Deltatime ) {
// debug camera
DebugCamera.Update();
}
// reset window state, it'll be set again if applicable in a check below
Global.CabWindowOpen = false;
@@ -801,7 +801,7 @@ driver_mode::OnKeyDown(int cKey) {
switch (cKey) {
case GLFW_KEY_F4: {
if( Global.shiftState ) { ExternalView(); } // with Shift, cycle through external views
if( Global.shiftState ) { ExternalView(); } // with Shift, cycle through external views
else { InOutKey(); } // without, step out of the cab or return to it
break;
}
@@ -826,7 +826,7 @@ driver_mode::OnKeyDown(int cKey) {
}
case GLFW_KEY_F6: {
// przyspieszenie symulacji do testowania scenerii... uwaga na FPS!
if( DebugModeFlag ) {
if( DebugModeFlag ) {
if( Global.ctrlState ) { Global.fTimeSpeed = ( Global.shiftState ? 60.0 : 20.0 ); }
else { Global.fTimeSpeed = ( Global.shiftState ? 5.0 : Global.default_timespeed ); }
@@ -883,7 +883,7 @@ driver_mode::DistantView( bool const Near ) {
( simulation::Train != nullptr ) ?
simulation::Train->Dynamic() :
pDynamicNearest ) };
if( vehicle == nullptr ) { return; }
auto const cab =
@@ -1049,7 +1049,7 @@ driver_mode::CabView() {
m_externalview = false;
// likwidacja obrotów - patrzy horyzontalnie na południe
Camera.Reset();
Camera.Reset();
// bind camera with the vehicle
Camera.m_owner = train->Dynamic();

View File

@@ -40,6 +40,9 @@ driver_ui::driver_ui() {
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.size_min = { 435, 85 };
m_scenariopanel.size_max = { Global.fb_size.x * 0.95f, Global.fb_size.y * 0.95 };
@@ -116,7 +119,7 @@ driver_ui::on_key( int const Key, int const Action ) {
}
switch (Key) {
case GLFW_KEY_TAB: {
m_mappanel.is_open = !m_mappanel.is_open;
@@ -130,7 +133,7 @@ driver_ui::on_key( int const Key, int const Action ) {
( m_aidpanel.is_expanded == false ) ? 1 :
2 );
state = clamp_circular( ++state, 3 );
m_aidpanel.is_open = ( state > 0 );
m_aidpanel.is_expanded = ( state > 1 );
@@ -144,7 +147,7 @@ driver_ui::on_key( int const Key, int const Action ) {
( m_timetablepanel.is_expanded == false ) ? 1 :
2 );
state = clamp_circular( ++state, 3 );
m_timetablepanel.is_open = ( state > 0 );
m_timetablepanel.is_expanded = ( state > 1 );

View File

@@ -548,6 +548,7 @@ debug_panel::update() {
m_powergridlines.clear();
m_cameralines.clear();
m_rendererlines.clear();
m_uartlines.clear();
update_section_vehicle( m_vehiclelines );
update_section_engine( m_enginelines );
@@ -558,6 +559,7 @@ debug_panel::update() {
update_section_powergrid( m_powergridlines );
update_section_camera( m_cameralines );
update_section_renderer( m_rendererlines );
update_section_uart(m_uartlines);
}
void
@@ -610,6 +612,11 @@ debug_panel::render() {
render_section( "Camera", m_cameralines );
render_section( "Gfx Renderer", m_rendererlines );
render_section_settings();
#ifdef WITH_UART
if(true == render_section( "UART", m_uartlines)) {
//ImGui::Checkbox("Enabled", &Global.uart_conf.enable);
}
#endif
// toggles
ImGui::Separator();
ImGui::Checkbox( "Debug Mode", &DebugModeFlag );
@@ -619,6 +626,13 @@ debug_panel::render() {
ImGui::PopFont();
}
#ifdef WITH_UART
bool
debug_panel::render_section_uart() {
return true;
};
#endif
bool
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
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_camera( 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
std::string update_vehicle_coupler( int const Side );
std::string update_vehicle_brake() const;
@@ -97,6 +100,9 @@ private:
bool render_section( std::vector<text_line> const &Lines );
bool render_section_scenario();
bool render_section_eventqueue();
#ifdef WITH_UART
bool render_section_uart();
#endif
bool render_section_settings();
// members
std::array<char, 1024> m_buffer;
@@ -111,7 +117,13 @@ private:
m_scenariolines,
m_eventqueuelines,
m_powergridlines,
#ifdef WITH_UART
m_rendererlines,
m_uartlines;
#else
m_rendererlines;
#endif
double last_time = std::numeric_limits<double>::quiet_NaN();

View File

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

10
uart.h
View File

@@ -3,6 +3,14 @@
#include <libserialport.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
{
public:
@@ -52,6 +60,8 @@ public:
recall_bindings();
void
poll();
bool
is_connected();
private:
// types