diff --git a/project/Core/Inc/tftp.h b/project/Core/Inc/tftp.h index 57ae68d..e33e855 100644 --- a/project/Core/Inc/tftp.h +++ b/project/Core/Inc/tftp.h @@ -6,8 +6,11 @@ #ifndef PROJECT_TFTP_H #define PROJECT_TFTP_H -#define LOGGER_LEVEL_ALL #include +#ifdef __cplusplus +extern "C" { +#endif +#define LOGGER_LEVEL_ALL #include "log.h" #include "llfs.h" #include @@ -25,4 +28,11 @@ typedef struct tftp_custom_file_s { void tftp_server_init(void); void tftp_server_deinit(void); +void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence); +size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle); + +#ifdef __cplusplus +} +#endif + #endif // PROJECT_TFTP_H diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3b36bc7..1b931ee 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,8 +6,14 @@ include_directories(${GTEST_INCLUDE_DIR}) link_directories(${GTEST_LIB_DIR}) # tests -file(GLOB_RECURSE TEST_SOURCES "*.cpp") -add_executable(tests ${TEST_SOURCES}) +file(GLOB_RECURSE TEST_SOURCES "*.cpp" "*.c") +add_executable(tests) + +target_sources(tests + PRIVATE + ${TEST_SOURCES} + ../project/Core/Src/tftp.c +) target_compile_options(tests PRIVATE $<$: -Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion @@ -22,6 +28,7 @@ target_include_directories(tests PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${PROJECT_BINARY_DIR} + ../project/Core/Inc/ ) include(GoogleTest) diff --git a/tests/mocs.c b/tests/mocs.c new file mode 100644 index 0000000..26fff82 --- /dev/null +++ b/tests/mocs.c @@ -0,0 +1,19 @@ +#include "tftp.h" + +struct llfs_data_file llfs_root = { + .data = NULL, + .len = 0, + .name = "root", + .next = NULL, +}; + +void tftp_cleanup(void) { + +} +uint32_t logger_get_timestamp(void) { + return 0; +} + +int tftp_init(struct tftp_context* context) { + return 0; +} diff --git a/tests/tfpt_tests.cpp b/tests/tfpt_tests.cpp index 96d0e11..4fd19f2 100644 --- a/tests/tfpt_tests.cpp +++ b/tests/tfpt_tests.cpp @@ -4,7 +4,7 @@ #include #include -#include "tftp.hpp" +#include "tftp.h" tftp_custom_file_t file = { .data = (char*)"1234567890", diff --git a/tests/tftp.cpp b/tests/tftp.cpp deleted file mode 100644 index 4def0eb..0000000 --- a/tests/tftp.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "tftp.hpp" - -/** - * @brief tftp custom file functions to set the offset and read the data - * @param[in,out] handle Custom file handles - * @param[in] offset The offset to set - * @param[in] whence The origin of the offset - */ -void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence) { - switch (whence) { - case SEEK_SET: - handle->ofset = offset; - break; - case SEEK_CUR: - handle->ofset += offset; - break; - case SEEK_END: - break; - } - if (handle->ofset > handle->len) { - handle->ofset = handle->len; - } -} - -/** - * @brief tftp custom file functions to read the data - * auto rolling over the offset - * if the bytes to read is bigger than the remaining bytes - * it will read the remaining bytes and set the bytes to 0 - * @param[out] buf The buffer to write the data to - * @param[in] bytes The number of bytes to read - * @param[in,out] handle Custom file handles - */ -size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) { - if (handle->ofset + bytes > handle->len) { - bytes = handle->len - handle->ofset; - } - memcpy(buf, handle->data + handle->ofset, bytes); - handle->ofset += bytes; - ((char*)buf)[bytes] = '\0'; - if (handle->ofset > handle->len) { - bytes = 0; - } - return bytes; -} \ No newline at end of file diff --git a/tests/tftp.hpp b/tests/tftp.hpp deleted file mode 100644 index 868b1da..0000000 --- a/tests/tftp.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -typedef struct tftp_custom_file_s { - const char* data; - size_t len; - char*name; - size_t ofset; -}tftp_custom_file_t; - -void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence); -size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle); \ No newline at end of file diff --git a/tests/tftp_server.h b/tests/tftp_server.h new file mode 100644 index 0000000..f5d45d9 --- /dev/null +++ b/tests/tftp_server.h @@ -0,0 +1,37 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +struct pbuf { + struct pbuf *next; + void *payload; + uint16_t tot_len; + uint16_t len; + uint8_t type_internal; + uint8_t flags; + //LWIP_PBUF_REF_T ref; + + uint8_t if_idx; +}; + +#define ERR_OK 0 + +struct tftp_context { + void* (*open)(const char* fname, const char* mode, uint8_t write); + void (*close)(void* handle); + int (*read)(void* handle, void* buf, int bytes); + int (*write)(void* handle, struct pbuf* p); +}; + +void tftp_cleanup(void); +uint32_t logger_get_timestamp(void); +int tftp_init(struct tftp_context* context); + +#ifdef __cplusplus +} +#endif \ No newline at end of file