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

(uart) fix port change handling, add packet stats resetting

This commit is contained in:
Marcin Nowak
2021-10-17 00:13:33 +02:00
parent 0138aa2f41
commit 20a369974a
2 changed files with 14 additions and 7 deletions

View File

@@ -9,6 +9,11 @@
#include "simulationtime.h" #include "simulationtime.h"
#include "application.h" #include "application.h"
void UartStatus::reset_stats() {
packets_sent = 0;
packets_received = 0;
}
uart_input::uart_input() uart_input::uart_input()
{ {
conf = Global.uart_conf; conf = Global.uart_conf;
@@ -21,6 +26,8 @@ uart_input::uart_input()
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();
enumerate_ports();
} }
void uart_input::enumerate_ports() { void uart_input::enumerate_ports() {
@@ -64,11 +71,6 @@ bool uart_input::setup_port()
last_setup = std::chrono::high_resolution_clock::now(); last_setup = std::chrono::high_resolution_clock::now();
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->active_port_index = status->selected_port_index;
}
if (sp_get_port_by_name(status->port_name.c_str(), &port) != SP_OK) { if (sp_get_port_by_name(status->port_name.c_str(), &port) != SP_OK) {
if(!error_notified) { if(!error_notified) {
status->is_connected = false; status->is_connected = false;
@@ -125,6 +127,7 @@ bool uart_input::setup_port()
if(error_notified || ! status->is_connected) { if(error_notified || ! status->is_connected) {
error_notified = false; error_notified = false;
ErrorLog("uart: connected to '"+status->port_name+"'"); ErrorLog("uart: connected to '"+status->port_name+"'");
status->reset_stats();
status->is_connected = true; status->is_connected = true;
} }
@@ -229,9 +232,11 @@ 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();
if(status->available_ports.size() > 0 && status->selected_port_index >= 0 && status->active_port_index != status->selected_port_index) {
if(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->reset_stats();
status->is_connected = false;
setup_port(); setup_port();
} }

2
uart.h
View File

@@ -15,6 +15,8 @@ class UartStatus {
bool is_synced = false; bool is_synced = false;
unsigned long packets_sent = 0; unsigned long packets_sent = 0;
unsigned long packets_received = 0; unsigned long packets_received = 0;
void reset_stats();
}; };
class uart_input class uart_input