mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 14:49:19 +02:00
(uart, driveruipanels) add possibility to change uart baud rate in debug panel
This commit is contained in:
@@ -34,6 +34,10 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#define DRIVER_HINT_CONTENT
|
#define DRIVER_HINT_CONTENT
|
||||||
#include "driverhints.h"
|
#include "driverhints.h"
|
||||||
|
|
||||||
|
#ifdef WITH_UART
|
||||||
|
#include "uart.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
drivingaid_panel::update() {
|
drivingaid_panel::update() {
|
||||||
|
|
||||||
@@ -548,7 +552,9 @@ debug_panel::update() {
|
|||||||
m_powergridlines.clear();
|
m_powergridlines.clear();
|
||||||
m_cameralines.clear();
|
m_cameralines.clear();
|
||||||
m_rendererlines.clear();
|
m_rendererlines.clear();
|
||||||
|
#ifdef WITH_UART
|
||||||
m_uartlines.clear();
|
m_uartlines.clear();
|
||||||
|
#endif
|
||||||
|
|
||||||
update_section_vehicle( m_vehiclelines );
|
update_section_vehicle( m_vehiclelines );
|
||||||
update_section_engine( m_enginelines );
|
update_section_engine( m_enginelines );
|
||||||
@@ -559,7 +565,9 @@ 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 );
|
||||||
|
#ifdef WITH_UART
|
||||||
update_section_uart(m_uartlines);
|
update_section_uart(m_uartlines);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -621,6 +629,7 @@ debug_panel::render() {
|
|||||||
avlports[i] = (char *) Application.uart_status.available_ports[i].c_str();
|
avlports[i] = (char *) Application.uart_status.available_ports[i].c_str();
|
||||||
}
|
}
|
||||||
ImGui::Combo("Port", &Application.uart_status.selected_port_index, avlports, ports_num);
|
ImGui::Combo("Port", &Application.uart_status.selected_port_index, avlports, ports_num);
|
||||||
|
ImGui::Combo("Baud", &Application.uart_status.selected_baud_index, uart_baudrates_list, uart_baudrates_list_num);
|
||||||
}
|
}
|
||||||
ImGui::Checkbox("Enabled", &Application.uart_status.enabled);
|
ImGui::Checkbox("Enabled", &Application.uart_status.enabled);
|
||||||
}
|
}
|
||||||
|
|||||||
43
uart.cpp
43
uart.cpp
@@ -9,6 +9,29 @@
|
|||||||
#include "simulationtime.h"
|
#include "simulationtime.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
|
||||||
|
|
||||||
|
const char* uart_baudrates_list[] = {
|
||||||
|
"300",
|
||||||
|
"1200",
|
||||||
|
"2400",
|
||||||
|
"4800",
|
||||||
|
"9600",
|
||||||
|
"19200",
|
||||||
|
"38400",
|
||||||
|
"57600",
|
||||||
|
"74880",
|
||||||
|
"115200",
|
||||||
|
"230400",
|
||||||
|
"250000",
|
||||||
|
"500000",
|
||||||
|
"1000000",
|
||||||
|
"2000000"
|
||||||
|
};
|
||||||
|
|
||||||
|
const size_t uart_baudrates_list_num = (
|
||||||
|
sizeof(uart_baudrates_list)/sizeof(uart_baudrates_list[0])
|
||||||
|
);
|
||||||
|
|
||||||
void UartStatus::reset_stats() {
|
void UartStatus::reset_stats() {
|
||||||
packets_sent = 0;
|
packets_sent = 0;
|
||||||
packets_received = 0;
|
packets_received = 0;
|
||||||
@@ -23,6 +46,16 @@ uart_input::uart_input()
|
|||||||
status->port_name = conf.port;
|
status->port_name = conf.port;
|
||||||
status->baud = conf.baud;
|
status->baud = conf.baud;
|
||||||
|
|
||||||
|
const std::string baudStr = std::to_string(status->baud);
|
||||||
|
|
||||||
|
for(int i=0;i<uart_baudrates_list_num;i++) {
|
||||||
|
if(baudStr == uart_baudrates_list[i]) {
|
||||||
|
status->selected_baud_index = i;
|
||||||
|
status->active_port_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
old_packet.fill(0);
|
old_packet.fill(0);
|
||||||
last_update = std::chrono::high_resolution_clock::now();
|
last_update = std::chrono::high_resolution_clock::now();
|
||||||
last_setup = std::chrono::high_resolution_clock::now();
|
last_setup = std::chrono::high_resolution_clock::now();
|
||||||
@@ -232,6 +265,16 @@ void uart_input::poll()
|
|||||||
UartStatus *status = &Application.uart_status;
|
UartStatus *status = &Application.uart_status;
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto now = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
/* handle baud change */
|
||||||
|
if(status->active_baud_index != status->selected_baud_index) {
|
||||||
|
status->baud = std::stoul(uart_baudrates_list[status->selected_baud_index]);
|
||||||
|
status->active_baud_index = status->selected_baud_index;
|
||||||
|
status->reset_stats();
|
||||||
|
status->is_connected = false;
|
||||||
|
setup_port();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* handle port change */
|
||||||
if(status->available_ports.size() > 0 && status->selected_port_index >= 0 && status->active_port_index != status->selected_port_index) {
|
if(status->available_ports.size() > 0 && status->selected_port_index >= 0 && status->active_port_index != status->selected_port_index) {
|
||||||
status->port_name = status->available_ports[status->selected_port_index];
|
status->port_name = status->available_ports[status->selected_port_index];
|
||||||
status->active_port_index = status->selected_port_index;
|
status->active_port_index = status->selected_port_index;
|
||||||
|
|||||||
5
uart.h
5
uart.h
@@ -3,12 +3,17 @@
|
|||||||
#include <libserialport.h>
|
#include <libserialport.h>
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
|
extern const char* uart_baudrates_list[];
|
||||||
|
extern const size_t uart_baudrates_list_num;
|
||||||
|
|
||||||
class UartStatus {
|
class UartStatus {
|
||||||
public:
|
public:
|
||||||
std::string port_name = "";
|
std::string port_name = "";
|
||||||
std::vector<std::string> available_ports = {};
|
std::vector<std::string> available_ports = {};
|
||||||
int selected_port_index = -1;
|
int selected_port_index = -1;
|
||||||
|
int selected_baud_index = -1;
|
||||||
int active_port_index = -1;
|
int active_port_index = -1;
|
||||||
|
int active_baud_index = -1;
|
||||||
int baud = 0;
|
int baud = 0;
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
bool is_connected = false;
|
bool is_connected = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user