diff options
author | Can Geliş <geliscan@gmail.com> | 2017-08-01 12:04:34 +0300 |
---|---|---|
committer | dc42 <dcrocker@eschertech.com> | 2017-08-01 12:04:34 +0300 |
commit | 3247390f323c07d5c834b206103397f295a95378 (patch) | |
tree | 1a0a2e81a6d59287a377450abf0917af04422bad /src/Storage/FileStore.cpp | |
parent | 74890fbe742c1e4a96f862174260767d0b7daad2 (diff) |
Support for binary write for M559 and M560 (#125)
* Support for binary write
M560 and M559 now supports binary uploads.
Size in bytes of the file can be supplied to the GCode with S parameter to indicate end of file otherwise upload will continue until the EOF is encountered.
M560 writes www folder by default
M559 writes sys folder by default
Default folders can be changed by supplying the absolute path of the file. For example: M560 P/sys/firmware.bin
* code refactoring
* CRC32 checksum verification for binary uploads
In this implementation CRC32 checksum should be supplied with "C" parameter with 0x prefix. Example: M559 C0xabcdef Ptest.bin S123
* code refactoring
Diffstat (limited to 'src/Storage/FileStore.cpp')
-rw-r--r-- | src/Storage/FileStore.cpp | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/src/Storage/FileStore.cpp b/src/Storage/FileStore.cpp index d73a6f5f..4087787b 100644 --- a/src/Storage/FileStore.cpp +++ b/src/Storage/FileStore.cpp @@ -89,7 +89,7 @@ bool FileStore::Open(const char* directory, const char* fileName, bool write) } return false; } - + crc.Reset(); inUse = true; openCount = 1; return true; @@ -268,6 +268,19 @@ int FileStore::ReadLine(char* buf, size_t nBytes) return i; } +FRESULT FileStore::Store(const char *s, size_t len, size_t *bytesWritten) +{ + uint32_t time = micros(); + crc.Update(s, len); + FRESULT writeStatus = f_write(&file, s, len, bytesWritten); + time = micros() - time; + if (time > longestWriteTime) + { + longestWriteTime = time; + } + return writeStatus; +} + bool FileStore::Write(char b) { return Write(&b, sizeof(char)); @@ -290,13 +303,7 @@ bool FileStore::Write(const char *s, size_t len) FRESULT writeStatus = FR_OK; if (writeBuffer == nullptr) { - uint32_t time = micros(); - writeStatus = f_write(&file, s, len, &totalBytesWritten); - time = micros() - time; - if (time > longestWriteTime) - { - longestWriteTime = time; - } + writeStatus = Store(s, len, &totalBytesWritten); } else { @@ -306,13 +313,7 @@ bool FileStore::Write(const char *s, size_t len) if (writeBuffer->BytesLeft() == 0) { size_t bytesToWrite = writeBuffer->BytesStored(), bytesWritten; - uint32_t time = micros(); - writeStatus = f_write(&file, writeBuffer->Data(), bytesToWrite, &bytesWritten); - time = micros() - time; - if (time > longestWriteTime) - { - longestWriteTime = time; - } + writeStatus = Store(writeBuffer->Data(), bytesToWrite, &bytesWritten); writeBuffer->DataTaken(); if (bytesToWrite != bytesWritten) @@ -345,13 +346,7 @@ bool FileStore::Flush() if (writeBuffer != nullptr) { size_t bytesToWrite = writeBuffer->BytesStored(), bytesWritten; - uint32_t time = micros(); - FRESULT writeStatus = f_write(&file, writeBuffer->Data(), bytesToWrite, &bytesWritten); - time = micros() - time; - if (time > longestWriteTime) - { - longestWriteTime = time; - } + FRESULT writeStatus = Store(writeBuffer->Data(), bytesToWrite, &bytesWritten); writeBuffer->DataTaken(); if ((writeStatus != FR_OK) || (bytesToWrite != bytesWritten)) |