Skip to content

Commit

Permalink
Enable compilation on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Apr 5, 2024
1 parent 37f5333 commit 07a30c4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
9 changes: 8 additions & 1 deletion native/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ lib_deps =
https://github.com/Theldus/wsServer#476a67448c05ba2057bae43eaa6e704f8b2d6625
https://github.com/DaveGamble/cJSON#v1.7.17
https://github.com/gpakosz/uuid4
kuba2k2/libserialport@^2021.7.1
kuba2k2/libserialport@^2023.11.2
extra_scripts = pre:extra_script.py

[env:windows_x86]
Expand All @@ -15,3 +15,10 @@ build_flags =
-static
-D_WIN32_WINNT=0x0601
-Wl,-wrap,__mingw_vprintf

[env:linux_x86_64]
platform = linux_x86_64
build_flags =
-lpthread
-static
-Dprintf=__wrap_printf
15 changes: 15 additions & 0 deletions native/src/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ int __wrap___mingw_vprintf(const char *format, va_list argv) {

return ret;
}

int __wrap_printf(const char *format, ...) {
va_list argv;
va_start(argv, format);
uint32_t len = vsnprintf(NULL, 0, format, argv);
va_end(argv);

char *buf = malloc(len + 1);
int ret = vsprintf(buf, format, argv);

stdmsg_send_log(buf);
free(buf);

return ret;
}
2 changes: 1 addition & 1 deletion native/src/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const char *serial_auth_grant(const char *port_name);
void serial_auth_revoke(const char *port_name);

char *serial_port_get_id(struct sp_port *port);
void serial_port_fix_details(struct sp_port *port, const char *id);
__attribute__((weak)) void serial_port_fix_details(struct sp_port *port, const char *id);

serial_port_t *serial_get_by_auth(const char *auth_key);
serial_port_t *serial_get_by_conn(ws_cli_conn_t *conn);
Expand Down
15 changes: 15 additions & 0 deletions native/src/serial_linux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Copyright (c) Kuba Szczodrzyński 2024-04-05. */

#ifdef __linux__

#define LIBSERIALPORT_ATBUILD
#include "libserialport_internal.h"
#undef DEBUG

#include "serial.h"

char *serial_port_get_id(struct sp_port *port) {
return port->name;
}

#endif

0 comments on commit 07a30c4

Please sign in to comment.