Compare commits

...

3 Commits

Author SHA1 Message Date
cxh
b2ec530a4b auto 2025-05-26 11:04:17 +08:00
cxh
8654831d4c Auto commit on 2025-05-23 17:44:42 2025-05-23 17:44:42 +08:00
cxh
7688e9f3f5 Auto commit on 2025-05-23 17:43:56 2025-05-23 17:43:56 +08:00

View File

@ -108,24 +108,24 @@ void UartHandler::stop_reading()
void UartHandler::read_loop() void UartHandler::read_loop()
{ {
uint8_t buf[512]; uint8_t buf[512];
auto last_receive_time = std::chrono::steady_clock::now(); // auto last_receive_time = std::chrono::steady_clock::now();
while (reading) while (reading)
{ {
int n = read(fd, buf, sizeof(buf)); int n = read(fd, buf, sizeof(buf));
if (n > 0) if (n > 0)
{ {
last_receive_time = std::chrono::steady_clock::now(); // last_receive_time = std::chrono::steady_clock::now();
parse_data(buf, n); parse_data(buf, n);
} }
else if (n == 0 || (n < 0 && errno == EAGAIN)) else if (n == 0 || (n < 0 && errno == EAGAIN))
{ {
// 检查超时 // 检查超时
auto now = std::chrono::steady_clock::now(); // auto now = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::seconds>(now - last_receive_time).count() > 2) // 超过2秒没数据 // if (std::chrono::duration_cast<std::chrono::seconds>(now - last_receive_time).count() > 2) // 超过2秒没数据
{ // {
failsafe_status = SBUS_SIGNAL_LOST; // failsafe_status = SBUS_SIGNAL_LOST;
} // }
usleep(1000); usleep(1000);
} }
else else