Skip to content

Commit

Permalink
Fixing tests in linux
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldn committed Mar 24, 2024
1 parent 9977127 commit 921283b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions tools/hon_simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_compile_options(-DHAIER_LOG_LEVEL=5)
if (UNIX)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
add_compile_options(-DUSE_CURSES)
endif (UNIX)

include_directories("${LIB_ROOT}/include")
Expand Down
1 change: 1 addition & 0 deletions tools/smartair2_simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_compile_options(-DHAIER_LOG_LEVEL=5)
if (UNIX)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
add_compile_options(-DUSE_CURSES)
endif (UNIX)

include_directories("${LIB_ROOT}/include")
Expand Down
13 changes: 8 additions & 5 deletions tools/utils/console_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <cstdarg>
#if _WIN32
#include <windows.h>
#else
#endif
#ifdef USE_CURSES
#include <curses.h>
#endif
#include "console_log.h"
Expand Down Expand Up @@ -53,7 +54,10 @@ void console_logger(haier_protocol::HaierLogLevel level, const char* tag, const
va_start(args, format);
vsnprintf(msg_buffer + len, BUFFER_SIZE - len - 1, format, args);
va_end(args);
#if _WIN32
#ifdef USE_CURSES
attron(COLOR_PAIR((short)level));
printw("%s\n", msg_buffer);
#else
const char* ll2color[] =
{
"\033[0m", // llNone
Expand All @@ -65,6 +69,8 @@ void console_logger(haier_protocol::HaierLogLevel level, const char* tag, const
"\033[90m", // llVerbose
};
std::cout << ll2color[(uint8_t)level] << msg_buffer << "\033[0m" << std::endl;
#endif
#if _WIN32
// DebugView++ message sending
HWND debugviewpp_window = FindWindowA(NULL, "[Capture Win32 & Global Win32 Messages] - DebugView++");
if (debugviewpp_window == NULL)
Expand All @@ -73,8 +79,5 @@ void console_logger(haier_protocol::HaierLogLevel level, const char* tag, const
static unsigned long process_id = GetCurrentProcessId();
SendMessageA(debugviewpp_window, EM_REPLACESEL, process_id, (LPARAM)msg_buffer);
}
#else
attron(COLOR_PAIR((short) level));
printw("%s\n", msg_buffer);
#endif
}
18 changes: 9 additions & 9 deletions tools/utils/serial_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ size_t SerialStream::available() noexcept {
#if _WIN32
status = ReadFile(handle_, tmp_buf, SERIAL_BUFFER_SIZE, &size, nullptr);
#else
status = read(handle_, tmp_buf, SERIAL_BUFFER_SIZE);
if (status >= 0) {
size = status;
status = 1;
}
else {
status = 0;
size = 0;
}
status = read(handle_, tmp_buf, SERIAL_BUFFER_SIZE);
if (status >= 0) {
size = status;
status = 1;
}
else {
status = 0;
size = 0;
}
#endif
if ((status != 0) && (size > 0))
buffer_.push(tmp_buf, size);
Expand Down
7 changes: 4 additions & 3 deletions tools/utils/simulator_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include <iostream>
#if _WIN32
#include <conio.h>
#else
#endif
#ifdef USE_CURSES
#include <curses.h>
#endif

Expand Down Expand Up @@ -62,7 +63,7 @@ void simulator_main(const char* app_name, const char* port_name, message_handler
#if _WIN32
SetConsoleTitle(std::string(app_name).append(", port=").append(port_name).append(". Press ESC to exit").c_str());
#endif
#if __linux__
#ifdef USE_CURSES
initscr();
start_color();
cbreak();
Expand All @@ -89,7 +90,7 @@ void simulator_main(const char* app_name, const char* port_name, message_handler
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
protocol_thread.join();
#if __linux__
#ifdef USE_CURSES
echo();
endwin();
#endif
Expand Down

0 comments on commit 921283b

Please sign in to comment.