Add tftp_custom_write and test functions
This commit is contained in:
2023-11-13 16:03:14 +01:00
parent c97d24e578
commit 623cf3749c
7 changed files with 54 additions and 3 deletions

View File

@@ -91,7 +91,7 @@ size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) {
* @param handle The handle to the file to write to
* @return The number of bytes written
*/
size_t tftp_custom_fwrite(void* buf, size_t bytes, tftp_custom_file_t* handle) {
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;
}
@@ -145,6 +145,11 @@ void tftp_close(void* handle) {
return;
}
if (handle == &virt_file[2]) {
// TODO: Clear display
lcd_display_text((uint8_t*)virt_file[2].data, 0, 0, LCD_COLOR_BLACK, LCD_COLOR_WHITE, LCD_FONT16);
}
if (handle == &virt_file[0] || handle == &virt_file[1] || handle == &virt_file[2]) {
((tftp_custom_file_t*)handle)->ofset = 0;
return;
@@ -202,6 +207,11 @@ 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;
if (file == &virt_file[1] || file == &virt_file[2]) {
return tftp_custom_fwrite(p->payload, p->len, file);
}
return -1;
}
/**