Merge branch 'main' into MQTT_Robin

This commit is contained in:
RobinVdB8
2023-12-10 15:58:57 +01:00
158 changed files with 16086 additions and 56 deletions

View File

@@ -1,7 +1,7 @@
#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
cmake_minimum_required(VERSION 3.26)
cmake_minimum_required(VERSION 3.27)
# specify cross-compilers and tools
set(CMAKE_C_COMPILER arm-none-eabi-gcc)

View File

@@ -86,8 +86,8 @@ size_t llfs_file_count(void);
/**
* @brief This function returns the extension of a file
* @param[in] filename The filename to get the extension from
* @return char* The extension of the file
* @return const char* The extension of the file
*/
char* llfs_get_filename_ext(char* filename);
const char* llfs_get_filename_ext(const char* filename);
#endif // LLFS_H

View File

@@ -19,7 +19,7 @@
#define POSIX_MAX_FILES 10
extern struct llfs_data_file* llfs_root;
const char* TAG = "llfs";
static const char* TAG = "llfs";
static size_t file_count = 0; // Cache for the number of files in the filesystem
static FILE* file_table[POSIX_MAX_FILES];
@@ -141,7 +141,7 @@ size_t llfs_file_count(void) {
return file_count;
}
char* llfs_get_filename_ext(char* filename) {
const char* llfs_get_filename_ext(const char* filename) {
char* dot = strrchr(filename, '.');
if (dot == NULL || dot == filename)
return NULL;

View File

@@ -49,7 +49,8 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
char text[TEXT_LENGTH];
uint32_t result_background = 0xff000000;
uint32_t text_foreground_color = 0xff000000;
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(arg); // This is used to prevent a warning
// Putting underscores in the whole array
memset(text, '_', TEXT_LENGTH);
@@ -148,7 +149,7 @@ static err_t modbus_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
* @brief Initializes the modbus tcp
*/
void modbus_init(void) {
LOG_INFO(TAG, "Initializing\n");
LOG_INFO(TAG, "Initializing");
// Creating a new tcp pcb
modbus_pcb = tcp_new();
@@ -158,5 +159,5 @@ void modbus_init(void) {
modbus_pcb = tcp_listen(modbus_pcb);
// Set callback function for incoming connections
tcp_accept(modbus_pcb, modbus_accept);
LOG_INFO(TAG, "initialized\n");
LOG_INFO(TAG, "initialized");
}

View File

@@ -24,27 +24,11 @@ static tftp_custom_file_t virt_file[] = {{.name = "index.txt", .data = NULL, .le
{.name = "virtImage.bmp", .data = NULL, .len = 0, .offset = 0},
{.name = "virtImage.gif", .data = NULL, .len = 0, .offset = 0},
{.name = "virtText.txt", .data = NULL, .len = 0, .offset = 0}};
static int str_cat_str(char* dest, size_t dest_size, const char* src) {
size_t dest_len = strlen(dest);
size_t src_len = strlen(src);
if (dest_len + src_len > dest_size) {
return -1;
}
memcpy(dest + dest_len, src, src_len);
return 0;
}
static int str_cat(char* dest, size_t dest_size, char c) {
size_t dest_len = strlen(dest);
if (dest_len + 1 > dest_size) {
return -1;
}
dest[dest_len] = c;
dest[dest_len + 1] = '\0';
return 0;
}
static void* tftp_open(const char* fname, const char* mode, uint8_t write);
static void tftp_close(void* handle);
static int tftp_read(void* handle, void* buf, int bytes);
static int tftp_write(void* handle, struct pbuf* p);
static struct tftp_context tftpContext_s = {.open = tftp_open, .close = tftp_close, .read = tftp_read, .write = tftp_write};
/**
* @brief tftp custom file functions to set the offset and read the data
* @param[in,out] handle Custom file handles
@@ -72,6 +56,7 @@ void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence) {
* 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
* this function does not handle null termination
* @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
@@ -82,7 +67,6 @@ size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) {
}
memcpy(buf, handle->data + handle->offset, bytes);
handle->offset += bytes;
((char*)buf)[bytes] = '\0';
if (handle->offset > handle->len) {
bytes = 0;
}
@@ -91,7 +75,12 @@ size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) {
/**
* @brief tftp custom file functions to write the data
* auto rolling over the offset
* auto rolling over the offset
* if the bytes to write is bigger than the remaining bytes
* it will write the remaining bytes and set the bytes to 0
* this function does not handle null termination
* if you want to write a null termination you have to add it to the data
* and set the len to the new length before calling this function
*
* @param buf The buffer to write the data to
* @param bytes The number of bytes to write
@@ -104,7 +93,7 @@ size_t tftp_custom_fwrite(const void* buf, size_t bytes, tftp_custom_file_t* han
}
memcpy(handle->data + handle->offset, buf, bytes);
handle->offset += bytes;
if (handle->offset > handle->len) {
if (handle->offset >= handle->len) {
bytes = 0;
}
return bytes;
@@ -124,7 +113,7 @@ size_t tftp_custom_fwrite(const void* buf, size_t bytes, tftp_custom_file_t* han
* @param write Flag indicating read (0) or write (!= 0) access
* @return void* File handle supplied to other functions
*/
void* tftp_open(const char* fname, const char* mode, uint8_t write) {
static void* tftp_open(const char* fname, const char* mode, uint8_t write) {
LOG_INFO(TAG, "Opening %s", fname);
UNUSED(mode);
@@ -148,7 +137,7 @@ void* tftp_open(const char* fname, const char* mode, uint8_t write) {
*
* @param handle The handle to the file to close
*/
void tftp_close(void* handle) {
static void tftp_close(void* handle) {
LOG_INFO(TAG, "closing file");
if (handle == NULL) {
LOG_CRIT(TAG, "handle is null");
@@ -170,7 +159,7 @@ void tftp_close(void* handle) {
if (handle == &virt_file[VIRT_TEXT_TXT]) {
lcd_clear_images();
lcd_clear_text();
lcd_display_text((const char*)virt_file[VIRT_TEXT_TXT].data, 0, 0, LCD_COLOR_WHITE, LCD_TRANSPARENT, LCD_FONT16);
lcd_display_text((char*)virt_file[VIRT_TEXT_TXT].data, 0, 0, LCD_COLOR_WHITE, LCD_TRANSPARENT, LCD_FONT16);
}
if (handle == &virt_file[VIRT_INDEX_TXT] || handle == &virt_file[VIRT_IMAGE_BMP]
@@ -192,7 +181,7 @@ void tftp_close(void* handle) {
* @param bytes Number of bytes to copy to buf
* @return int >= 0: Success; < 0: Error
*/
int tftp_read(void* handle, void* buf, int bytes) {
static int tftp_read(void* handle, void* buf, int bytes) {
int ret = 0;
LOG_INFO(TAG, "reading file");
if (handle == NULL) {
@@ -230,7 +219,7 @@ int tftp_read(void* handle, void* buf, int bytes) {
* In other words, TFTP headers are stripped off.
* @return int >= 0: Success; < 0: Error
*/
int tftp_write(void* handle, struct pbuf* p) {
static int tftp_write(void* handle, struct pbuf* p) {
LOG_INFO(TAG, "Writing file");
tftp_custom_file_t* file = (tftp_custom_file_t*)handle;
if (file == &virt_file[VIRT_IMAGE_BMP] || file == &virt_file[VIRT_IMAGE_GIF] || file == &virt_file[VIRT_TEXT_TXT]) {
@@ -262,20 +251,22 @@ void init_index(void) {
virt_file[VIRT_INDEX_TXT].len = len;
for (int i = 0; i < MAX_VIRT_FILES; i++) {
str_cat_str(virt_file[VIRT_INDEX_TXT].data, len, virt_file[i].name);
str_cat(virt_file[VIRT_INDEX_TXT].data, len, '\n');
strncat(virt_file[VIRT_INDEX_TXT].data, virt_file[i].name, len);
strncat(virt_file[VIRT_INDEX_TXT].data, "\n", len);
}
mem = NULL;
file = NULL;
while ((file = llfs_next_file(&mem, NULL)) != NULL) {
str_cat_str(virt_file[VIRT_INDEX_TXT].data, len, file->name);
str_cat(virt_file[VIRT_INDEX_TXT].data, len, '\n');
strncat(virt_file[VIRT_INDEX_TXT].data, file->name, len);
strncat(virt_file[VIRT_INDEX_TXT].data, "\n", len);
}
}
struct tftp_context tftpContext_s = {.open = tftp_open, .close = tftp_close, .read = tftp_read, .write = tftp_write};
LOG_DEBUG(TAG, "index.txt:\n%s", virt_file[VIRT_INDEX_TXT].data);
LOG_DEBUG(TAG, "index.txt: %u strlen: %u", virt_file[VIRT_INDEX_TXT].len, strlen(virt_file[VIRT_INDEX_TXT].data));
LOG_INFO(TAG, "index.txt created");
}
/**
* @brief Initialize tftp server
@@ -284,8 +275,6 @@ void tftp_server_init(void) {
LOG_INFO(TAG, "Initializing tftp server");
init_index();
LOG_DEBUG(TAG, "index.txt: %s", virt_file[VIRT_INDEX_TXT].data);
// init the virtImage virt_file with 80kb of ram
virt_file[VIRT_IMAGE_BMP].data = calloc(IMAGE_BUFFER_SIZE, sizeof(char));
if (virt_file[VIRT_IMAGE_BMP].data == NULL) {