Add libserialport + another improvements

This commit is contained in:
Marek Kraus 2022-09-12 13:14:55 +02:00
parent 019c7dd845
commit fb70d7eea4
5 changed files with 36 additions and 7 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "vendor/argtable3"] [submodule "vendor/argtable3"]
path = vendor/argtable3 path = vendor/argtable3
url = https://github.com/argtable/argtable3 url = https://github.com/argtable/argtable3
[submodule "vendor/libserialport"]
path = vendor/libserialport
url = https://github.com/sigrokproject/libserialport/

View File

@ -9,3 +9,24 @@ add_executable(blisp src/main.c src/cmd/write.c)
target_include_directories(blisp PRIVATE vendor/argtable3/src) target_include_directories(blisp PRIVATE vendor/argtable3/src)
target_link_libraries(blisp PRIVATE argtable3) target_link_libraries(blisp PRIVATE argtable3)
target_sources(blisp PRIVATE
${CMAKE_SOURCE_DIR}/vendor/libserialport/serialport.c
${CMAKE_SOURCE_DIR}/vendor/libserialport/timing.c)
if(WIN32)
target_link_libraries(blisp PRIVATE Setupapi.lib)
target_compile_definitions(blisp PRIVATE LIBSERIALPORT_MSBUILD)
target_sources(blisp PRIVATE
${CMAKE_SOURCE_DIR}/vendor/libserialport/windows.c)
elseif(UNIX AND NOT APPLE)
target_sources(blisp PRIVATE
${CMAKE_SOURCE_DIR}/vendor/libserialport/linux.c
${CMAKE_SOURCE_DIR}/vendor/libserialport/linux_termios.c)
target_compile_definitions(blisp PRIVATE
LIBSERIALPORT_ATBUILD
"SP_API=__attribute__((visibility(\"default\")))"
"SP_PRIV=__attribute__((visibility(\"hidden\")))")
target_include_directories(blisp PRIVATE ${CMAKE_SOURCE_DIR}/vendor/libserialport)
write_file(${CMAKE_SOURCE_DIR}/vendor/libserialport/config.h "// bypass errors.")
endif()

View File

@ -21,6 +21,7 @@ cmd_write_args_init() {
fprintf(stderr, "insufficient memory\n"); fprintf(stderr, "insufficient memory\n");
return -1; return -1;
} }
return 0;
} }
uint8_t uint8_t

View File

@ -5,9 +5,11 @@
#include <stdbool.h> #include <stdbool.h>
struct cmd* cmds[] = { struct cmd* cmds[] = {
&cmd_write, &cmd_write
}; };
static uint8_t cmds_count = sizeof(cmds) / sizeof(cmds[0]);
static struct arg_lit* help; static struct arg_lit* help;
static struct arg_lit* version; static struct arg_lit* version;
static struct arg_end* end; static struct arg_end* end;
@ -22,11 +24,12 @@ int8_t args_init() {
fprintf(stderr, "insufficient memory\n"); fprintf(stderr, "insufficient memory\n");
return -1; return -1;
} }
return 0;
} }
void print_help() { void print_help() {
puts("Usage:"); puts("Usage:");
for (uint8_t i = 0; cmds[i] != NULL; i++) { for (uint8_t i = 0; i < cmds_count; i++) {
fputs("\tblisp", stdout); fputs("\tblisp", stdout);
cmds[i]->args_print_syntax(); cmds[i]->args_print_syntax();
} }
@ -62,7 +65,7 @@ main(int argc, char** argv) {
goto exit; goto exit;
} }
for (uint8_t i = 0; cmds[i] != NULL; i++) { for (uint8_t i = 0; i < cmds_count; i++) {
if (cmds[i]->args_init() != 0) { if (cmds[i]->args_init() != 0) {
exit_code = -1; exit_code = -1;
goto exit; goto exit;
@ -74,7 +77,7 @@ main(int argc, char** argv) {
} }
uint8_t command_found = false; uint8_t command_found = false;
for (uint8_t i = 0; cmds[i] != NULL; i++) { for (uint8_t i = 0; i < cmds_count; i++) {
if (cmds[i]->args_parse_exec(argc, argv)) { if (cmds[i]->args_parse_exec(argc, argv)) {
command_found = true; command_found = true;
break; break;
@ -82,11 +85,11 @@ main(int argc, char** argv) {
} }
if (!command_found) { if (!command_found) {
print_help();
} }
exit: exit:
for (uint8_t i = 0; cmds[i] != NULL; i++) { for (uint8_t i = 0; i < cmds_count; i++) {
cmds[i]->args_free(); cmds[i]->args_free();
} }
args_free(); args_free();

1
vendor/libserialport vendored Submodule

@ -0,0 +1 @@
Subproject commit 6f9b03e597ea7200eb616a4e410add3dd1690cb1