test seeking in a file on mDot
Dependencies: libmDot mbed-rtos mbed
main.cpp
- Committer:
- mfiore
- Date:
- 2016-08-24
- Revision:
- 0:c5ab0dc979fc
- Child:
- 1:4d3a502a7e58
File content as of revision 0:c5ab0dc979fc:
#include "mbed.h" #include "mDot.h" #include "MTSLog.h" #include <vector> int main() { mDot* dot; std::vector<mDot::mdot_file> files; mDot::mdot_file file; const char filename[] = "test_file.txt"; // get a mDot handle dot = mDot::getInstance(); // print library version information logInfo("version: %s", dot->getId().c_str()); files = dot->listUserFiles(); if (files.size() == 0) { logInfo("no user files"); } else { logInfo("user files:"); for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { printf("\t%s [%d]\r\n", it->name, it->size); } } logInfo("deleting user files"); for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { dot->deleteUserFile(it->name); } while (true) { uint8_t buf[2048]; memset(buf, 0x3B, sizeof(buf)); file = dot->openUserFile(filename, mDot::FM_RDWR | mDot::FM_CREAT | mDot::FM_APPEND); if (file.fd < 0) { logError("failed to open file"); break; } else { if (dot->writeUserFile(file, (void*)buf, sizeof(buf)) != sizeof(buf)) { logError("didn't write entire buffer"); break; } dot->closeUserFile(file); } files = dot->listUserFiles(); if (files.size() == 0) { logInfo("no user files"); } else { logInfo("user files:"); for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { printf("\t%s [%d]\r\n", it->name, it->size); } } } files = dot->listUserFiles(); if (files.size() == 0) { logInfo("no user files"); } else { logInfo("user files:"); for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { printf("\t%s [%d]\r\n", it->name, it->size); } } return 0; }