diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-01-09 10:42:14 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-01-09 10:42:14 +0200 |
| commit | d50d729a2b7d45ca4b22df7ff0d8823825c479b6 (patch) | |
| tree | b6ac5a0813c4b76d43ad3af1d56ac8a44361dd7f /Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c | |
| parent | aeebb8d47e1d78b50d9ae5afd9df6eaf9765ed87 (diff) | |
| download | Tango-d50d729a2b7d45ca4b22df7ff0d8823825c479b6.tar.gz Tango-d50d729a2b7d45ca4b22df7ff0d8823825c479b6.zip | |
Version 1.3.1.1 changes
Communication tx traces (reports, diagnostics, alarms, job reports)
File system file download support – not tested!
Communication tx with pre-allocated memory (improve and add areas)
Winder Screw – send messages in regular mode
Preparation for motor actions timeouts
Preparations for control debug
Heaters: bug fix, enlarge PID start region
IDS:
• Dispenser time out between motor operation and valve operation (start->open. Close->stop).
• Dispenser homing backlash – to pressure above limit (currently 0.1 for machines without mixer) or timeout (10 seconds).
State machine – Suspend Large Messages cancelled.
Diffstat (limited to 'Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c')
| -rw-r--r-- | Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c index c1f673745..51c30782c 100644 --- a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c +++ b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c @@ -12,6 +12,10 @@ #include <Communication/PMR/IO/FileUploadResponse.pb-c.h> #include <Communication/PMR/IO/FileChunkUploadRequest.pb-c.h> #include <Communication/PMR/IO/FileChunkUploadResponse.pb-c.h> +#include <Communication/PMR/IO/FileDownloadRequest.pb-c.h> +#include <Communication/PMR/IO/FileDownloadResponse.pb-c.h> +#include <Communication/PMR/IO/FileChunkDownloadRequest.pb-c.h> +#include <Communication/PMR/IO/FileChunkDownloadResponse.pb-c.h> #include <Communication/PMR/IO/ExecuteProcessRequest.pb-c.h> #include <Communication/PMR/IO/ExecuteProcessResponse.pb-c.h> #include <Communication/PMR/IO/KillProcessRequest.pb-c.h> @@ -499,3 +503,104 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer) } return Fresult; } +uint32_t FileDownloadRequestFunc(MessageContainer* requestContainer) +{ + uint32_t status = OK; + + FRESULT Fresult = FR_OK; + + MessageContainer responseContainer; + + FileDownloadRequest* request = file_download_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); + + FileDownloadResponse response = FILE_DOWNLOAD_RESPONSE__INIT; + + WrittenBytes=0; + FileHandle = malloc(sizeof(FIL)); + if (FileHandle == 0) + Fresult = FR_DENIED; + else + { + Fresult = f_open(FileHandle,request->filename,FA_READ ); + if (Fresult == FR_OK) + { + response.has_maxchunklength = true; + response.maxchunklength = MAX_CHUNK_LENGTH; + strcpy(FileHandleChar, "1234"); + response.downloadid = FileHandleChar; //supporting only single file at each time. + } + + } + + + responseContainer = createContainer(MESSAGE_TYPE__FileDownloadResponse, requestContainer->token, false, &response, &file_download_response__pack, &file_download_response__get_packed_size); + if (Fresult!= FR_OK) + { + responseContainer.error = getErrorCode(Fresult); + responseContainer.errormessage = "File operation error"; + } + responseContainer.continuous = false; + uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + my_free(responseContainer.data.data); + file_download_request__free_unpacked(request,NULL); + SendChars(container_buffer, container_size); + + return OK; +} +uint32_t FileChunkDownloadRequestFunc(MessageContainer* requestContainer) +{ + MessageContainer responseContainer; + FileChunkDownloadRequest* request = file_chunk_download_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); + FileChunkDownloadResponse response = FILE_CHUNK_DOWNLOAD_RESPONSE__INIT; + FRESULT Fresult = FR_OK; + FIL *ReceivedFileHandle; //the system supports a single active file + + ReceivedFileHandle = FileHandle; + char *Buffer = 0; + Buffer = malloc (2000); + if (Buffer != NULL) + { + Fresult = f_read(ReceivedFileHandle,response.buffer.data,2000,&WrittenBytes ); + if(Fresult != FR_OK) + { + LOG_ERROR (Fresult,"f_write error"); + } + else + { + response.buffer.len = WrittenBytes; + FileReceivedLength += WrittenBytes; + if (FileReceivedLength == FileLength) + { + REPORT_MSG (FileReceivedLength,"file download ended successfully"); + f_close(ReceivedFileHandle); + free (FileHandle); + } + else + { + if (FileReceivedLength > FileLength) + { + REPORT_MSG (FileReceivedLength,"file download too much data!"); + f_close(ReceivedFileHandle); + free (FileHandle); + } + } + } + } + + responseContainer = createContainer(MESSAGE_TYPE__FileChunkDownloadResponse, requestContainer->token, false, &response, &file_chunk_download_response__pack, &file_chunk_download_response__get_packed_size); + if (Fresult!= OK) + { + responseContainer.error = getErrorCode(Fresult); + responseContainer.errormessage = "File operation error"; + } + responseContainer.continuous = false; + uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + file_chunk_download_request__free_unpacked(request,NULL); + my_free(responseContainer.data.data); + my_free(Buffer); + SendChars(container_buffer, container_size); + + return OK; +} |
