* Change typo
* Format
* Add doxygen
This commit is contained in:
2023-11-20 15:44:38 +01:00
parent ff72c9a5eb
commit 46f2fcacd2
2 changed files with 65 additions and 32 deletions

View File

@@ -9,7 +9,7 @@
#define VIRT_INDEX_TXT 0
#define VIRT_IMAGE_BMP 1
#define VIRT_IMAGE_GIF 2
#define VIRT_TEXT_TXT 3
#define VIRT_TEXT_TXT 3
#define IMAGE_BUFFER_SIZE 81920
@@ -17,10 +17,10 @@ static const char* TAG = "tftp_server";
extern struct llfs_data_file* llfs_root;
static tftp_custom_file_t virt_file[] = {{.name = "index.txt", .data = NULL, .len = 0, .ofset = 0},
{.name = "virtImage.bmp", .data = NULL, .len = 0, .ofset = 0},
{.name = "virtImage.gif", .data = NULL, .len = 0, .ofset = 0},
{.name = "virtText.txt", .data = NULL, .len = 0, .ofset = 0}};
static tftp_custom_file_t virt_file[] = {{.name = "index.txt", .data = NULL, .len = 0, .offset = 0},
{.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}};
int str_cat_str(char* dest, size_t dest_size, const char* src) {
size_t dest_len = strlen(dest);
@@ -32,7 +32,6 @@ int str_cat_str(char* dest, size_t dest_size, const char* src) {
return 0;
}
int str_cat(char* dest, size_t dest_size, char c) {
size_t dest_len = strlen(dest);
if (dest_len + 1 > dest_size) {
@@ -52,16 +51,16 @@ int str_cat(char* dest, size_t dest_size, char c) {
void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence) {
switch (whence) {
case SEEK_SET:
handle->ofset = offset;
handle->offset = offset;
break;
case SEEK_CUR:
handle->ofset += offset;
handle->offset += offset;
break;
case SEEK_END:
break;
}
if (handle->ofset > handle->len) {
handle->ofset = handle->len;
if (handle->offset > handle->len) {
handle->offset = handle->len;
}
}
@@ -75,13 +74,13 @@ void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence) {
* @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;
if (handle->offset + bytes > handle->len) {
bytes = handle->len - handle->offset;
}
memcpy(buf, handle->data + handle->ofset, bytes);
handle->ofset += bytes;
memcpy(buf, handle->data + handle->offset, bytes);
handle->offset += bytes;
((char*)buf)[bytes] = '\0';
if (handle->ofset > handle->len) {
if (handle->offset > handle->len) {
bytes = 0;
}
return bytes;
@@ -97,12 +96,12 @@ size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) {
* @return The number of bytes written
*/
size_t tftp_custom_fwrite(const void* buf, size_t bytes, tftp_custom_file_t* handle) {
if (handle->ofset + bytes > handle->len) {
bytes = handle->len - handle->ofset;
if (handle->offset + bytes > handle->len) {
bytes = handle->len - handle->offset;
}
memcpy(handle->data + handle->ofset, buf, bytes);
handle->ofset += bytes;
if (handle->ofset > handle->len) {
memcpy(handle->data + handle->offset, buf, bytes);
handle->offset += bytes;
if (handle->offset > handle->len) {
bytes = 0;
}
return bytes;
@@ -160,16 +159,17 @@ void tftp_close(void* handle) {
if (handle == &virt_file[VIRT_IMAGE_GIF]) {
lcd_clear(LCD_COLOR_BLACK);
lcd_draw_gif((uint8_t*)virt_file[VIRT_IMAGE_GIF].data, virt_file[VIRT_IMAGE_GIF].ofset,0, 0);
lcd_draw_gif((uint8_t*)virt_file[VIRT_IMAGE_GIF].data, virt_file[VIRT_IMAGE_GIF].offset, 0, 0);
}
if (handle == &virt_file[VIRT_TEXT_TXT]) {
lcd_clear(LCD_COLOR_BLACK);
lcd_display_text((uint8_t*)virt_file[VIRT_TEXT_TXT].data, 0, 0,LCD_COLOR_WHITE, LCD_COLOR_BLACK, LCD_FONT16);
lcd_display_text((uint8_t*)virt_file[VIRT_TEXT_TXT].data, 0, 0, LCD_COLOR_WHITE, LCD_COLOR_BLACK, LCD_FONT16);
}
if (handle == &virt_file[VIRT_INDEX_TXT] || handle == &virt_file[VIRT_IMAGE_BMP] || handle == &virt_file[VIRT_IMAGE_GIF] || handle == &virt_file[VIRT_TEXT_TXT]) {
((tftp_custom_file_t*)handle)->ofset = 0;
if (handle == &virt_file[VIRT_INDEX_TXT] || handle == &virt_file[VIRT_IMAGE_BMP]
|| handle == &virt_file[VIRT_IMAGE_GIF] || handle == &virt_file[VIRT_TEXT_TXT]) {
((tftp_custom_file_t*)handle)->offset = 0;
return;
}
@@ -208,7 +208,7 @@ int tftp_read(void* handle, void* buf, int bytes) {
LOG_CRIT(TAG, "Exception: Trying to read a write only file");
return -1;
}
ret = (int)fread(buf, sizeof(uint8_t), (size_t)bytes, file);
if (ret <= 0) {
return -1;
@@ -301,7 +301,7 @@ void tftp_server_deinit(void) {
free(virt_file[VIRT_INDEX_TXT].data);
virt_file[VIRT_INDEX_TXT].data = NULL;
virt_file[VIRT_INDEX_TXT].len = 0;
virt_file[VIRT_INDEX_TXT].ofset = 0;
virt_file[VIRT_INDEX_TXT].offset = 0;
free(virt_file[VIRT_IMAGE_BMP].data);
virt_file[VIRT_IMAGE_BMP].data = NULL;
virt_file[VIRT_IMAGE_BMP].len = 0;