test seeking in a file on mDot
Dependencies: libmDot mbed-rtos mbed
main.cpp@0:c5ab0dc979fc, 2016-08-24 (annotated)
- Committer:
- mfiore
- Date:
- Wed Aug 24 14:29:47 2016 +0000
- Revision:
- 0:c5ab0dc979fc
- Child:
- 1:4d3a502a7e58
initial commit - keep appending to a single file to test maximum file size in the filesystem
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:c5ab0dc979fc | 1 | #include "mbed.h" |
mfiore | 0:c5ab0dc979fc | 2 | #include "mDot.h" |
mfiore | 0:c5ab0dc979fc | 3 | #include "MTSLog.h" |
mfiore | 0:c5ab0dc979fc | 4 | #include <vector> |
mfiore | 0:c5ab0dc979fc | 5 | |
mfiore | 0:c5ab0dc979fc | 6 | int main() |
mfiore | 0:c5ab0dc979fc | 7 | { |
mfiore | 0:c5ab0dc979fc | 8 | mDot* dot; |
mfiore | 0:c5ab0dc979fc | 9 | std::vector<mDot::mdot_file> files; |
mfiore | 0:c5ab0dc979fc | 10 | mDot::mdot_file file; |
mfiore | 0:c5ab0dc979fc | 11 | const char filename[] = "test_file.txt"; |
mfiore | 0:c5ab0dc979fc | 12 | |
mfiore | 0:c5ab0dc979fc | 13 | // get a mDot handle |
mfiore | 0:c5ab0dc979fc | 14 | dot = mDot::getInstance(); |
mfiore | 0:c5ab0dc979fc | 15 | |
mfiore | 0:c5ab0dc979fc | 16 | // print library version information |
mfiore | 0:c5ab0dc979fc | 17 | logInfo("version: %s", dot->getId().c_str()); |
mfiore | 0:c5ab0dc979fc | 18 | |
mfiore | 0:c5ab0dc979fc | 19 | files = dot->listUserFiles(); |
mfiore | 0:c5ab0dc979fc | 20 | if (files.size() == 0) { |
mfiore | 0:c5ab0dc979fc | 21 | logInfo("no user files"); |
mfiore | 0:c5ab0dc979fc | 22 | } else { |
mfiore | 0:c5ab0dc979fc | 23 | logInfo("user files:"); |
mfiore | 0:c5ab0dc979fc | 24 | for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { |
mfiore | 0:c5ab0dc979fc | 25 | printf("\t%s [%d]\r\n", it->name, it->size); |
mfiore | 0:c5ab0dc979fc | 26 | } |
mfiore | 0:c5ab0dc979fc | 27 | } |
mfiore | 0:c5ab0dc979fc | 28 | |
mfiore | 0:c5ab0dc979fc | 29 | logInfo("deleting user files"); |
mfiore | 0:c5ab0dc979fc | 30 | for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { |
mfiore | 0:c5ab0dc979fc | 31 | dot->deleteUserFile(it->name); |
mfiore | 0:c5ab0dc979fc | 32 | } |
mfiore | 0:c5ab0dc979fc | 33 | |
mfiore | 0:c5ab0dc979fc | 34 | while (true) { |
mfiore | 0:c5ab0dc979fc | 35 | uint8_t buf[2048]; |
mfiore | 0:c5ab0dc979fc | 36 | |
mfiore | 0:c5ab0dc979fc | 37 | memset(buf, 0x3B, sizeof(buf)); |
mfiore | 0:c5ab0dc979fc | 38 | |
mfiore | 0:c5ab0dc979fc | 39 | file = dot->openUserFile(filename, mDot::FM_RDWR | mDot::FM_CREAT | mDot::FM_APPEND); |
mfiore | 0:c5ab0dc979fc | 40 | if (file.fd < 0) { |
mfiore | 0:c5ab0dc979fc | 41 | logError("failed to open file"); |
mfiore | 0:c5ab0dc979fc | 42 | break; |
mfiore | 0:c5ab0dc979fc | 43 | } else { |
mfiore | 0:c5ab0dc979fc | 44 | if (dot->writeUserFile(file, (void*)buf, sizeof(buf)) != sizeof(buf)) { |
mfiore | 0:c5ab0dc979fc | 45 | logError("didn't write entire buffer"); |
mfiore | 0:c5ab0dc979fc | 46 | break; |
mfiore | 0:c5ab0dc979fc | 47 | } |
mfiore | 0:c5ab0dc979fc | 48 | |
mfiore | 0:c5ab0dc979fc | 49 | dot->closeUserFile(file); |
mfiore | 0:c5ab0dc979fc | 50 | } |
mfiore | 0:c5ab0dc979fc | 51 | |
mfiore | 0:c5ab0dc979fc | 52 | |
mfiore | 0:c5ab0dc979fc | 53 | files = dot->listUserFiles(); |
mfiore | 0:c5ab0dc979fc | 54 | if (files.size() == 0) { |
mfiore | 0:c5ab0dc979fc | 55 | logInfo("no user files"); |
mfiore | 0:c5ab0dc979fc | 56 | } else { |
mfiore | 0:c5ab0dc979fc | 57 | logInfo("user files:"); |
mfiore | 0:c5ab0dc979fc | 58 | for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { |
mfiore | 0:c5ab0dc979fc | 59 | printf("\t%s [%d]\r\n", it->name, it->size); |
mfiore | 0:c5ab0dc979fc | 60 | } |
mfiore | 0:c5ab0dc979fc | 61 | } |
mfiore | 0:c5ab0dc979fc | 62 | } |
mfiore | 0:c5ab0dc979fc | 63 | |
mfiore | 0:c5ab0dc979fc | 64 | files = dot->listUserFiles(); |
mfiore | 0:c5ab0dc979fc | 65 | if (files.size() == 0) { |
mfiore | 0:c5ab0dc979fc | 66 | logInfo("no user files"); |
mfiore | 0:c5ab0dc979fc | 67 | } else { |
mfiore | 0:c5ab0dc979fc | 68 | logInfo("user files:"); |
mfiore | 0:c5ab0dc979fc | 69 | for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { |
mfiore | 0:c5ab0dc979fc | 70 | printf("\t%s [%d]\r\n", it->name, it->size); |
mfiore | 0:c5ab0dc979fc | 71 | } |
mfiore | 0:c5ab0dc979fc | 72 | } |
mfiore | 0:c5ab0dc979fc | 73 | |
mfiore | 0:c5ab0dc979fc | 74 | return 0; |
mfiore | 0:c5ab0dc979fc | 75 | } |