TFTP
format + remove todo
This commit is contained in:
@@ -10,12 +10,9 @@ 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.raw",.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, .ofset = 0},
|
||||
{.name = "virtImage.raw", .data = NULL, .len = 0, .ofset = 0},
|
||||
{.name = "virtText.txt", .data = NULL, .len = 0, .ofset = 0}};
|
||||
|
||||
int str_cat_str(char* dest, size_t dest_size, const char* src) {
|
||||
size_t dest_len = strlen(dest);
|
||||
@@ -27,8 +24,7 @@ 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)
|
||||
{
|
||||
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;
|
||||
@@ -146,12 +142,12 @@ void tftp_close(void* handle) {
|
||||
}
|
||||
|
||||
if (handle == &virt_file[1]) {
|
||||
// TODO: waiting on pr of tim to merge so we can use the bmp lcd function
|
||||
lcd_clear(LCD_COLOR_BLACK);
|
||||
lcd_display_text("show me what you got virtImage.raw", 0, 0, LCD_COLOR_BLACK, LCD_COLOR_WHITE, LCD_FONT16);
|
||||
}
|
||||
|
||||
if (handle == &virt_file[2]) {
|
||||
// TODO: Clear display
|
||||
lcd_clear(LCD_COLOR_BLACK);
|
||||
lcd_display_text((uint8_t*)virt_file[2].data, 0, 0, LCD_COLOR_BLACK, LCD_COLOR_WHITE, LCD_FONT16);
|
||||
}
|
||||
@@ -213,7 +209,7 @@ int tftp_read(void* handle, void* buf, int bytes) {
|
||||
int tftp_write(void* handle, struct pbuf* p) {
|
||||
LOG_INFO(TAG, "Writing file");
|
||||
LOG_DEBUG(TAG, "Not implemented yet");
|
||||
tftp_custom_file_t *file = (tftp_custom_file_t*)handle;
|
||||
tftp_custom_file_t* file = (tftp_custom_file_t*)handle;
|
||||
if (file == &virt_file[1] || file == &virt_file[2]) {
|
||||
return tftp_custom_fwrite(p->payload, p->len, file);
|
||||
}
|
||||
@@ -223,16 +219,14 @@ int tftp_write(void* handle, struct pbuf* p) {
|
||||
/**
|
||||
* @brief This function creates the file list for index.txt
|
||||
*/
|
||||
void init_index(void)
|
||||
{
|
||||
void init_index(void) {
|
||||
size_t len = 0;
|
||||
// Add len of the virt files to the size
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
len += strlen(virt_file[i].name) + 1;
|
||||
}
|
||||
const struct llfs_data_file* root = llfs_root;
|
||||
while(root != NULL) {
|
||||
while (root != NULL) {
|
||||
len += strlen(root->name) + 1;
|
||||
root = root->next;
|
||||
}
|
||||
@@ -240,13 +234,12 @@ void init_index(void)
|
||||
virt_file[0].data = malloc(len);
|
||||
virt_file[0].len = len;
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
str_cat_str(virt_file[0].data, len, virt_file[i].name);
|
||||
str_cat(virt_file[0].data, len, '\n');
|
||||
}
|
||||
root = llfs_root;
|
||||
while(root != NULL) {
|
||||
while (root != NULL) {
|
||||
str_cat_str(virt_file[0].data, len, root->name);
|
||||
str_cat(virt_file[0].data, len, '\n');
|
||||
root = root->next;
|
||||
@@ -256,12 +249,7 @@ void init_index(void)
|
||||
virt_file[2].len = 100;
|
||||
}
|
||||
|
||||
struct tftp_context tftpContext_s = {
|
||||
.open = tftp_open,
|
||||
.close = tftp_close,
|
||||
.read = tftp_read,
|
||||
.write = tftp_write
|
||||
};
|
||||
struct tftp_context tftpContext_s = {.open = tftp_open, .close = tftp_close, .read = tftp_read, .write = tftp_write};
|
||||
|
||||
/**
|
||||
* @brief Initialize tftp server
|
||||
|
||||
Reference in New Issue
Block a user