Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ICE-Application/src/add-ons/ConfigFS/ConfigFs.cpp
- Revision:
- 0:61364762ee0e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ICE-Application/src/add-ons/ConfigFS/ConfigFs.cpp Tue Jan 24 19:05:33 2017 +0000 @@ -0,0 +1,55 @@ +#include "ConfigFs.h" +#include "mbed.h" +#include "mfs.h" + +bool ConfigFs::saveUserFile(const char *filename, void *file_buf, int file_size) +{ +// printf("Writing filename=%s, size=%d\r\n", filename, file_size); + mfs fs0(0xA0); + fs0.createFile((char *)filename); + file *fp = new file(&fs0, (char *)filename, AWRITE); + fp->write((char *)file_buf, file_size); + if( fp->flush() != 0 ) { + printf("Flush Failed\r\n"); + } + delete fp; + return true; +} + +bool ConfigFs::readUserFile(const char *filename, void *file_buf, int file_size) +{ + mfs fs0(0xA0); +// printf("%s, len=%d\r\n", filename, strlen(filename)); + file *fp = new file(&fs0, (char *)filename, AWRITE); + fp->read((char *)file_buf, file_size); + delete fp; +// printf("File Read: %s; bytes=%d, len=%d\n\r", (char *)file_buf, file_size, strlen((char *)file_buf)); + return true; +} + +bool ConfigFs::deleteUserFile(const char *filename) +{ + mfs fs0(0xA0); + fs0.removeFile((char *)filename); + return true; +} + +std::vector<std::string> ConfigFs::listUserFiles() +{ + mfs fs0(0xA0); + unsigned int n; + char found_file[FILENAME_LENGTH]; + std::vector<std::string> filelist; + + n=0; + while (1) { + if (fs0.findNextFile(n, found_file, &n) == 0 ) { + filelist.push_back(found_file); + } else { + break; // Reach end of fs + } + n++; + } + return filelist; + +} \ No newline at end of file