mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 10:29:19 +02:00
(uart, debug) first part of fixes after code review
- remove `uart_status` from eu7_application class - remove copy&pasted `m_scenariopanel` size settings - remove unnecessary code `debug_panel::render_section_uart()` - remove #ifdef from `driveruipanels.h` textlines - set `data_pending` to false when establishing a new connection
This commit is contained in:
@@ -94,9 +94,6 @@ 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
|
||||||
|
|||||||
@@ -40,9 +40,6 @@ 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 };
|
||||||
|
|||||||
@@ -622,14 +622,14 @@ debug_panel::render() {
|
|||||||
render_section_settings();
|
render_section_settings();
|
||||||
#ifdef WITH_UART
|
#ifdef WITH_UART
|
||||||
if(true == render_section( "UART", m_uartlines)) {
|
if(true == render_section( "UART", m_uartlines)) {
|
||||||
int ports_num = Application.uart_status.available_ports.size();
|
int ports_num = UartStatus.available_ports.size();
|
||||||
char **avlports = new char*[ports_num];
|
char **avlports = new char*[ports_num];
|
||||||
for (int i=0; i < ports_num; i++) {
|
for (int i=0; i < ports_num; i++) {
|
||||||
avlports[i] = (char *) Application.uart_status.available_ports[i].c_str();
|
avlports[i] = (char *) UartStatus.available_ports[i].c_str();
|
||||||
}
|
}
|
||||||
ImGui::Combo("Port", &Application.uart_status.selected_port_index, avlports, ports_num);
|
ImGui::Combo("Port", &UartStatus.selected_port_index, avlports, ports_num);
|
||||||
ImGui::Combo("Baud", &Application.uart_status.selected_baud_index, uart_baudrates_list, uart_baudrates_list_num);
|
ImGui::Combo("Baud", &UartStatus.selected_baud_index, uart_baudrates_list, uart_baudrates_list_num);
|
||||||
ImGui::Checkbox("Enabled", &Application.uart_status.enabled);
|
ImGui::Checkbox("Enabled", &UartStatus.enabled);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// toggles
|
// toggles
|
||||||
@@ -641,13 +641,6 @@ 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() {
|
||||||
|
|
||||||
@@ -1245,7 +1238,7 @@ debug_panel::update_section_scantable( std::vector<text_line> &Output ) {
|
|||||||
#ifdef WITH_UART
|
#ifdef WITH_UART
|
||||||
void
|
void
|
||||||
debug_panel::update_section_uart( std::vector<text_line> &Output ) {
|
debug_panel::update_section_uart( std::vector<text_line> &Output ) {
|
||||||
UartStatus *status = &Application.uart_status;
|
uart_status *status = &UartStatus;
|
||||||
|
|
||||||
Output.emplace_back(
|
Output.emplace_back(
|
||||||
("Port: " + status->port_name).c_str(),
|
("Port: " + status->port_name).c_str(),
|
||||||
|
|||||||
@@ -117,13 +117,8 @@ private:
|
|||||||
m_scenariolines,
|
m_scenariolines,
|
||||||
m_eventqueuelines,
|
m_eventqueuelines,
|
||||||
m_powergridlines,
|
m_powergridlines,
|
||||||
#ifdef WITH_UART
|
|
||||||
m_rendererlines,
|
m_rendererlines,
|
||||||
m_uartlines;
|
m_uartlines;
|
||||||
#else
|
|
||||||
m_rendererlines;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
double last_time = std::numeric_limits<double>::quiet_NaN();
|
double last_time = std::numeric_limits<double>::quiet_NaN();
|
||||||
|
|
||||||
|
|||||||
22
uart.cpp
22
uart.cpp
@@ -9,7 +9,6 @@
|
|||||||
#include "simulationtime.h"
|
#include "simulationtime.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
|
||||||
|
|
||||||
const char* uart_baudrates_list[] = {
|
const char* uart_baudrates_list[] = {
|
||||||
"300",
|
"300",
|
||||||
"1200",
|
"1200",
|
||||||
@@ -32,15 +31,17 @@ const size_t uart_baudrates_list_num = (
|
|||||||
sizeof(uart_baudrates_list)/sizeof(uart_baudrates_list[0])
|
sizeof(uart_baudrates_list)/sizeof(uart_baudrates_list[0])
|
||||||
);
|
);
|
||||||
|
|
||||||
void UartStatus::reset_stats() {
|
void uart_status::reset_stats() {
|
||||||
packets_sent = 0;
|
packets_sent = 0;
|
||||||
packets_received = 0;
|
packets_received = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uart_status UartStatus;
|
||||||
|
|
||||||
uart_input::uart_input()
|
uart_input::uart_input()
|
||||||
{
|
{
|
||||||
conf = Global.uart_conf;
|
conf = Global.uart_conf;
|
||||||
UartStatus *status = &Application.uart_status;
|
uart_status *status = &UartStatus;
|
||||||
|
|
||||||
status->enabled = conf.enable;
|
status->enabled = conf.enable;
|
||||||
status->port_name = conf.port;
|
status->port_name = conf.port;
|
||||||
@@ -64,7 +65,7 @@ uart_input::uart_input()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void uart_input::find_ports() {
|
void uart_input::find_ports() {
|
||||||
UartStatus *status = &Application.uart_status;
|
uart_status *status = &UartStatus;
|
||||||
|
|
||||||
struct sp_port **ports;
|
struct sp_port **ports;
|
||||||
if (sp_list_ports(&ports) == SP_OK) {
|
if (sp_list_ports(&ports) == SP_OK) {
|
||||||
@@ -91,7 +92,7 @@ void uart_input::find_ports() {
|
|||||||
|
|
||||||
bool uart_input::setup_port()
|
bool uart_input::setup_port()
|
||||||
{
|
{
|
||||||
UartStatus *status = &Application.uart_status;
|
uart_status *status = &UartStatus;
|
||||||
|
|
||||||
if(!port) {
|
if(!port) {
|
||||||
find_ports();
|
find_ports();
|
||||||
@@ -162,6 +163,7 @@ bool uart_input::setup_port()
|
|||||||
ErrorLog("uart: connected to '"+status->port_name+"'");
|
ErrorLog("uart: connected to '"+status->port_name+"'");
|
||||||
status->reset_stats();
|
status->reset_stats();
|
||||||
status->is_connected = true;
|
status->is_connected = true;
|
||||||
|
data_pending = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -262,7 +264,7 @@ uart_input::recall_bindings() {
|
|||||||
|
|
||||||
void uart_input::poll()
|
void uart_input::poll()
|
||||||
{
|
{
|
||||||
UartStatus *status = &Application.uart_status;
|
uart_status *status = &UartStatus;
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto now = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
/* handle baud change */
|
/* handle baud change */
|
||||||
@@ -334,13 +336,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;
|
UartStatus.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;
|
UartStatus.is_synced = true;
|
||||||
if (conf.debug)
|
if (conf.debug)
|
||||||
WriteLog("uart: sync ok");
|
WriteLog("uart: sync ok");
|
||||||
sync = true;
|
sync = true;
|
||||||
@@ -384,7 +386,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++;
|
UartStatus.packets_received++;
|
||||||
|
|
||||||
if (conf.debug)
|
if (conf.debug)
|
||||||
{
|
{
|
||||||
@@ -607,7 +609,7 @@ void uart_input::poll()
|
|||||||
setup_port();
|
setup_port();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Application.uart_status.packets_sent++;
|
UartStatus.packets_sent++;
|
||||||
|
|
||||||
data_pending = true;
|
data_pending = true;
|
||||||
}
|
}
|
||||||
|
|||||||
4
uart.h
4
uart.h
@@ -6,7 +6,7 @@
|
|||||||
extern const char* uart_baudrates_list[];
|
extern const char* uart_baudrates_list[];
|
||||||
extern const size_t uart_baudrates_list_num;
|
extern const size_t uart_baudrates_list_num;
|
||||||
|
|
||||||
class UartStatus {
|
class uart_status {
|
||||||
public:
|
public:
|
||||||
std::string port_name = "";
|
std::string port_name = "";
|
||||||
std::vector<std::string> available_ports = {};
|
std::vector<std::string> available_ports = {};
|
||||||
@@ -104,3 +104,5 @@ private:
|
|||||||
bool error_notified = false;
|
bool error_notified = false;
|
||||||
std::uint8_t m_trainstatecab { 0 }; // helper, keeps track of last active cab. 0: front cab, 1: rear cab
|
std::uint8_t m_trainstatecab { 0 }; // helper, keeps track of last active cab. 0: front cab, 1: rear cab
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern uart_status UartStatus;
|
||||||
|
|||||||
Reference in New Issue
Block a user