mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 18:39:18 +02:00
(uart) fix uart synchronization routine
This commit is contained in:
12
uart.cpp
12
uart.cpp
@@ -59,7 +59,7 @@ bool uart_input::setup_port()
|
|||||||
port = nullptr;
|
port = nullptr;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,17 +173,17 @@ void uart_input::poll()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
sp_return ret;
|
sp_return ret;
|
||||||
|
|
||||||
if ((ret = sp_input_waiting(port)) >= 20)
|
if ((ret = sp_input_waiting(port)) >= 20)
|
||||||
{
|
{
|
||||||
std::array<uint8_t, 20> tmp_buffer; // TBD, TODO: replace with vector of configurable size?
|
std::array<uint8_t, 20> tmp_buffer; // TBD, TODO: replace with vector of configurable size?
|
||||||
ret = sp_blocking_read(port, (void*)tmp_buffer.data(), tmp_buffer.size(), 0);
|
ret = sp_blocking_read(port, (void*)tmp_buffer.data(), tmp_buffer.size(), 0);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
setup_port();
|
setup_port();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
if (conf.debug)
|
if (conf.debug)
|
||||||
@@ -195,7 +195,7 @@ void uart_input::poll()
|
|||||||
WriteLog("uart: sync ok");
|
WriteLog("uart: sync ok");
|
||||||
sync = true;
|
sync = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
int sync_cnt = 0;
|
int sync_cnt = 0;
|
||||||
int sync_fail = 0;
|
int sync_fail = 0;
|
||||||
@@ -231,7 +231,7 @@ void uart_input::poll()
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user