Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2017-09-21 21:27:40 +0300
committerDavid Crocker <dcrocker@eschertech.com>2017-09-21 21:29:52 +0300
commit370060e84b9f30dd5d9edff817baaba154106c7c (patch)
treeaa399d680427189e6a8c62572c304b9b16118406 /src/Storage
parent77d6718860bd6ad383d29e0708c600fcba855116 (diff)
Version 1.20 alpha 2
Removed define of printf=iprintf in build settings Removed Platform::Time() function, use millis() or millis64() instead Added event logging to SD card. MessageType is now a bitmap. Implemented M929. Enable pullup resistors on endstops 10 and 11 SCARA printers can now use the manual bed levelling assistant When using the manual bed levelling assitant, don't give an error if the bed screw corrections were out of range, and always leave the first screw alone M552 now supports connection to a specified SSID M572 now allows multiple D values Thermocouple type letter in M305 command may now be in lower case Bug fix: G29 bed probing on a SCARA printer gave spurious "not reachable" warnings and skipped probe points Protect against a dud command line containing the letter M being interpreted as a M0 command Fix reference to towers in the error message when trying to move a SCARA printer before homing it When updating firmware, warn that USB will disconnect Fix duplicate error messatge when opening a gcode file fails
Diffstat (limited to 'src/Storage')
-rw-r--r--src/Storage/FileData.h5
-rw-r--r--src/Storage/FileStore.cpp56
-rw-r--r--src/Storage/FileStore.h9
-rw-r--r--src/Storage/MassStorage.cpp18
4 files changed, 54 insertions, 34 deletions
diff --git a/src/Storage/FileData.h b/src/Storage/FileData.h
index 2dea0214..683b4165 100644
--- a/src/Storage/FileData.h
+++ b/src/Storage/FileData.h
@@ -56,6 +56,11 @@ public:
return f->Write(b);
}
+ bool Write(const char *s)
+ {
+ return f->Write(s, strlen(s));
+ }
+
bool Write(const char *s, size_t len)
{
return f->Write(s, len);
diff --git a/src/Storage/FileStore.cpp b/src/Storage/FileStore.cpp
index c5642732..084fb873 100644
--- a/src/Storage/FileStore.cpp
+++ b/src/Storage/FileStore.cpp
@@ -38,12 +38,12 @@ bool FileStore::IsOpenOn(const FATFS *fs) const
// Open a local file (for example on an SD card).
// This is protected - only Platform can access it.
-bool FileStore::Open(const char* directory, const char* fileName, bool write)
+bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode)
{
const char* const location = (directory != nullptr)
? platform->GetMassStorage()->CombineName(directory, fileName)
: fileName;
- writing = write;
+ writing = (mode == OpenMode::write || mode == OpenMode::append);
if (writing)
{
@@ -53,7 +53,7 @@ bool FileStore::Open(const char* directory, const char* fileName, bool write)
filePath.copy(location);
bool isVolume = isdigit(filePath[0]);
- for(size_t i = 1; i < filePath.strlen(); i++)
+ for (size_t i = 1; i < filePath.strlen(); i++)
{
if (filePath[i] == '/')
{
@@ -66,7 +66,7 @@ bool FileStore::Open(const char* directory, const char* fileName, bool write)
filePath[i] = 0;
if (!platform->GetMassStorage()->DirectoryExists(filePath.Pointer()) && !platform->GetMassStorage()->MakeDirectory(filePath.Pointer()))
{
- platform->MessageF(GENERIC_MESSAGE, "Failed to create directory %s while trying to open file %s\n",
+ platform->MessageF(ErrorMessage, "Failed to create directory %s while trying to open file %s\n",
filePath.Pointer(), location);
return false;
}
@@ -78,14 +78,17 @@ bool FileStore::Open(const char* directory, const char* fileName, bool write)
writeBuffer = platform->GetMassStorage()->AllocateWriteBuffer();
}
- FRESULT openReturn = f_open(&file, location, (writing) ? FA_CREATE_ALWAYS | FA_WRITE : FA_OPEN_EXISTING | FA_READ);
+ const FRESULT openReturn = f_open(&file, location,
+ (mode == OpenMode::write) ? FA_CREATE_ALWAYS | FA_WRITE
+ : (mode == OpenMode::append) ? FA_WRITE | FA_OPEN_ALWAYS
+ : FA_OPEN_EXISTING | FA_READ);
if (openReturn != FR_OK)
{
// We no longer report an error if opening a file in read mode fails unless debugging is enabled, because sometimes that is quite normal.
// It is up to the caller to report an error if necessary.
if (reprap.Debug(modulePlatform))
{
- platform->MessageF(GENERIC_MESSAGE, "Can't open %s to %s, error code %d\n", location, (writing) ? "write" : "read", openReturn);
+ platform->MessageF(ErrorMessage, "Can't open %s to %s, error code %d\n", location, (writing) ? "write" : "read", openReturn);
}
return false;
}
@@ -99,7 +102,7 @@ void FileStore::Duplicate()
{
if (!inUse)
{
- platform->Message(GENERIC_MESSAGE, "Error: Attempt to dup a non-open file.\n");
+ platform->Message(ErrorMessage, "Attempt to dup a non-open file.\n");
return;
}
irqflags_t flags = cpu_irq_save();
@@ -132,7 +135,7 @@ bool FileStore::Close()
if (!inUse)
{
- platform->Message(GENERIC_MESSAGE, "Error: Attempt to close a non-open file.\n");
+ platform->Message(ErrorMessage, "Attempt to close a non-open file.\n");
return false;
}
@@ -169,7 +172,7 @@ bool FileStore::Seek(FilePosition pos)
{
if (!inUse)
{
- platform->Message(GENERIC_MESSAGE, "Error: Attempt to seek on a non-open file.\n");
+ platform->Message(ErrorMessage, "Attempt to seek on a non-open file.\n");
return false;
}
FRESULT fr = f_lseek(&file, pos);
@@ -192,7 +195,7 @@ FilePosition FileStore::Length() const
{
if (!inUse)
{
- platform->Message(GENERIC_MESSAGE, "Error: Attempt to size non-open file.\n");
+ platform->Message(ErrorMessage, "Attempt to size non-open file.\n");
return 0;
}
@@ -210,7 +213,7 @@ int FileStore::Read(char* extBuf, size_t nBytes)
{
if (!inUse)
{
- platform->Message(GENERIC_MESSAGE, "Error: Attempt to read from a non-open file.\n");
+ platform->Message(ErrorMessage, "Attempt to read from a non-open file.\n");
return -1;
}
@@ -218,7 +221,7 @@ int FileStore::Read(char* extBuf, size_t nBytes)
FRESULT readStatus = f_read(&file, extBuf, nBytes, &bytes_read);
if (readStatus != FR_OK)
{
- platform->Message(GENERIC_MESSAGE, "Error: Cannot read file.\n");
+ platform->Message(ErrorMessage, "Cannot read file.\n");
return -1;
}
return (int)bytes_read;
@@ -285,7 +288,7 @@ bool FileStore::Write(const char *s, size_t len)
{
if (!inUse)
{
- platform->Message(GENERIC_MESSAGE, "Error: Attempt to write block to a non-open file.\n");
+ platform->Message(ErrorMessage, "Attempt to write block to a non-open file.\n");
return false;
}
@@ -302,7 +305,8 @@ bool FileStore::Write(const char *s, size_t len)
size_t bytesStored = writeBuffer->Store(s + totalBytesWritten, len - totalBytesWritten);
if (writeBuffer->BytesLeft() == 0)
{
- size_t bytesToWrite = writeBuffer->BytesStored(), bytesWritten;
+ const size_t bytesToWrite = writeBuffer->BytesStored();
+ size_t bytesWritten;
writeStatus = Store(writeBuffer->Data(), bytesToWrite, &bytesWritten);
writeBuffer->DataTaken();
@@ -319,7 +323,7 @@ bool FileStore::Write(const char *s, size_t len)
if ((writeStatus != FR_OK) || (totalBytesWritten != len))
{
- platform->Message(GENERIC_MESSAGE, "Error: Cannot write to file. Drive may be full.\n");
+ platform->Message(ErrorMessage, "Failed to write to file. Drive may be full.\n");
return false;
}
return true;
@@ -329,20 +333,24 @@ bool FileStore::Flush()
{
if (!inUse)
{
- platform->Message(GENERIC_MESSAGE, "Error: Attempt to flush a non-open file.\n");
+ platform->Message(ErrorMessage, "Attempt to flush a non-open file.\n");
return false;
}
if (writeBuffer != nullptr)
{
- size_t bytesToWrite = writeBuffer->BytesStored(), bytesWritten;
- FRESULT writeStatus = Store(writeBuffer->Data(), bytesToWrite, &bytesWritten);
- writeBuffer->DataTaken();
-
- if ((writeStatus != FR_OK) || (bytesToWrite != bytesWritten))
+ const size_t bytesToWrite = writeBuffer->BytesStored();
+ if (bytesToWrite != 0)
{
- platform->Message(GENERIC_MESSAGE, "Error: Cannot write to file. Drive may be full.\n");
- return false;
+ size_t bytesWritten;
+ const FRESULT writeStatus = Store(writeBuffer->Data(), bytesToWrite, &bytesWritten);
+ writeBuffer->DataTaken();
+
+ if ((writeStatus != FR_OK) || (bytesToWrite != bytesWritten))
+ {
+ platform->Message(ErrorMessage, "Failed to write to file. Drive may be full.\n");
+ return false;
+ }
}
}
@@ -364,7 +372,7 @@ bool FileStore::SetClusterMap(uint32_t tbl[])
{
if (!inUse)
{
- platform->Message(GENERIC_MESSAGE, "Error: Attempt to set cluster map for a non-open file.\n");
+ platform->Message(ErrorMessage, "attempt to set cluster map for a non-open file.\n");
return false;
}
diff --git a/src/Storage/FileStore.h b/src/Storage/FileStore.h
index dfc8cd16..0bf65af3 100644
--- a/src/Storage/FileStore.h
+++ b/src/Storage/FileStore.h
@@ -10,6 +10,13 @@
class Platform;
class FileWriteBuffer;
+enum class OpenMode : uint8_t
+{
+ read, // open an existing file for reading
+ write, // write a file, replacing any existing file of the same name
+ append // append to an existing file, or create a new file if it is not found
+};
+
class FileStore
{
public:
@@ -44,7 +51,7 @@ protected:
FileStore(Platform* p);
void Init();
- bool Open(const char* directory, const char* fileName, bool write);
+ bool Open(const char* directory, const char* fileName, OpenMode mode);
FRESULT Store(const char *s, size_t len, size_t *bytesWritten); // Write data to the non-volatile storage
private:
diff --git a/src/Storage/MassStorage.cpp b/src/Storage/MassStorage.cpp
index 17741acd..5a601d7b 100644
--- a/src/Storage/MassStorage.cpp
+++ b/src/Storage/MassStorage.cpp
@@ -75,7 +75,7 @@ void MassStorage::Init()
if (reply.strlen() != 0)
{
delay(3000); // Wait a few seconds so users have a chance to see this
- platform->Message(HOST_MESSAGE, reply.Pointer());
+ platform->Message(UsbMessage, reply.Pointer());
}
}
@@ -113,7 +113,7 @@ const char* MassStorage::CombineName(const char* directory, const char* fileName
outIndex++;
if (outIndex >= ARRAY_SIZE(combinedName))
{
- platform->MessageF(GENERIC_MESSAGE, "CombineName() buffer overflow.");
+ platform->MessageF(ErrorMessage, "CombineName() buffer overflow");
outIndex = 0;
}
}
@@ -133,7 +133,7 @@ const char* MassStorage::CombineName(const char* directory, const char* fileName
outIndex++;
if (outIndex >= ARRAY_SIZE(combinedName))
{
- platform->Message(GENERIC_MESSAGE, "CombineName() buffer overflow.");
+ platform->Message(ErrorMessage, "CombineName() buffer overflow");
outIndex = 0;
}
}
@@ -231,7 +231,7 @@ bool MassStorage::Delete(const char* directory, const char* fileName, bool silen
{
if (!silent)
{
- platform->MessageF(GENERIC_MESSAGE, "Can't delete file %s\n", location);
+ platform->MessageF(ErrorMessage, "Failed to delete file %s\n", location);
}
return false;
}
@@ -244,7 +244,7 @@ bool MassStorage::MakeDirectory(const char *parentDir, const char *dirName)
const char* location = platform->GetMassStorage()->CombineName(parentDir, dirName);
if (f_mkdir(location) != FR_OK)
{
- platform->MessageF(GENERIC_MESSAGE, "Can't create directory %s\n", location);
+ platform->MessageF(ErrorMessage, "Failed to create directory %s\n", location);
return false;
}
return true;
@@ -254,7 +254,7 @@ bool MassStorage::MakeDirectory(const char *directory)
{
if (f_mkdir(directory) != FR_OK)
{
- platform->MessageF(GENERIC_MESSAGE, "Can't create directory %s\n", directory);
+ platform->MessageF(ErrorMessage, "Failed to create directory %s\n", directory);
return false;
}
return true;
@@ -272,7 +272,7 @@ bool MassStorage::Rename(const char *oldFilename, const char *newFilename)
}
if (f_rename(oldFilename, newFilename) != FR_OK)
{
- platform->MessageF(GENERIC_MESSAGE, "Can't rename file or directory %s to %s\n", oldFilename, newFilename);
+ platform->MessageF(ErrorMessage, "Failed to rename file or directory %s to %s\n", oldFilename, newFilename);
return false;
}
return true;
@@ -334,7 +334,7 @@ bool MassStorage::SetLastModifiedTime(const char* directory, const char *fileNam
const bool ok = (f_utime(location, &fno) == FR_OK);
if (!ok)
{
- reprap.GetPlatform().MessageF(HTTP_MESSAGE, "SetLastModifiedTime didn't work for file '%s'\n", location);
+ reprap.GetPlatform().MessageF(ErrorMessage, "Failed to set last modified time for file '%s'\n", location);
}
return ok;
}
@@ -389,7 +389,7 @@ bool MassStorage::Mount(size_t card, StringRef& reply, bool reportSuccess)
FRESULT mounted = f_mount(card, &fileSystems[card]);
if (mounted != FR_OK)
{
- reply.printf("Can't mount SD card %u: code %d", card, mounted);
+ reply.printf("Cannot mount SD card %u: code %d", card, mounted);
}
else
{