Christian Weiß / Mbed 2 deprecated Diplomarbeit_MW_CW

Dependencies:   mbed

Committer:
martwerl
Date:
Wed Oct 17 17:19:45 2018 +0000
Revision:
0:afeca64a6543
Diplomarbeit_MW_CW

Who changed what in which revision?

UserRevisionLine numberNew contents of line
martwerl 0:afeca64a6543 1 /* mbed Microcontroller Library
martwerl 0:afeca64a6543 2 * Copyright (c) 2006-2013 ARM Limited
martwerl 0:afeca64a6543 3 *
martwerl 0:afeca64a6543 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
martwerl 0:afeca64a6543 5 * of this software and associated documentation files (the "Software"), to deal
martwerl 0:afeca64a6543 6 * in the Software without restriction, including without limitation the rights
martwerl 0:afeca64a6543 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
martwerl 0:afeca64a6543 8 * copies of the Software, and to permit persons to whom the Software is
martwerl 0:afeca64a6543 9 * furnished to do so, subject to the following conditions:
martwerl 0:afeca64a6543 10 *
martwerl 0:afeca64a6543 11 * The above copyright notice and this permission notice shall be included in
martwerl 0:afeca64a6543 12 * all copies or substantial portions of the Software.
martwerl 0:afeca64a6543 13 *
martwerl 0:afeca64a6543 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
martwerl 0:afeca64a6543 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
martwerl 0:afeca64a6543 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
martwerl 0:afeca64a6543 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
martwerl 0:afeca64a6543 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
martwerl 0:afeca64a6543 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
martwerl 0:afeca64a6543 20 * SOFTWARE.
martwerl 0:afeca64a6543 21 */
martwerl 0:afeca64a6543 22 #ifndef MBED_LOCALFILESYSTEM_H
martwerl 0:afeca64a6543 23 #define MBED_LOCALFILESYSTEM_H
martwerl 0:afeca64a6543 24
martwerl 0:afeca64a6543 25 #include "platform.h"
martwerl 0:afeca64a6543 26
martwerl 0:afeca64a6543 27 #if DEVICE_LOCALFILESYSTEM
martwerl 0:afeca64a6543 28
martwerl 0:afeca64a6543 29 #include "FileSystemLike.h"
martwerl 0:afeca64a6543 30
martwerl 0:afeca64a6543 31 namespace mbed {
martwerl 0:afeca64a6543 32
martwerl 0:afeca64a6543 33 FILEHANDLE local_file_open(const char* name, int flags);
martwerl 0:afeca64a6543 34
martwerl 0:afeca64a6543 35 class LocalFileHandle : public FileHandle {
martwerl 0:afeca64a6543 36
martwerl 0:afeca64a6543 37 public:
martwerl 0:afeca64a6543 38 LocalFileHandle(FILEHANDLE fh);
martwerl 0:afeca64a6543 39
martwerl 0:afeca64a6543 40 virtual int close();
martwerl 0:afeca64a6543 41
martwerl 0:afeca64a6543 42 virtual ssize_t write(const void *buffer, size_t length);
martwerl 0:afeca64a6543 43
martwerl 0:afeca64a6543 44 virtual ssize_t read(void *buffer, size_t length);
martwerl 0:afeca64a6543 45
martwerl 0:afeca64a6543 46 virtual int isatty();
martwerl 0:afeca64a6543 47
martwerl 0:afeca64a6543 48 virtual off_t lseek(off_t position, int whence);
martwerl 0:afeca64a6543 49
martwerl 0:afeca64a6543 50 virtual int fsync();
martwerl 0:afeca64a6543 51
martwerl 0:afeca64a6543 52 virtual off_t flen();
martwerl 0:afeca64a6543 53
martwerl 0:afeca64a6543 54 protected:
martwerl 0:afeca64a6543 55 FILEHANDLE _fh;
martwerl 0:afeca64a6543 56 int pos;
martwerl 0:afeca64a6543 57 };
martwerl 0:afeca64a6543 58
martwerl 0:afeca64a6543 59 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
martwerl 0:afeca64a6543 60 *
martwerl 0:afeca64a6543 61 * This allows programs to read and write files on the same disk drive that is used to program the
martwerl 0:afeca64a6543 62 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
martwerl 0:afeca64a6543 63 * read and write files.
martwerl 0:afeca64a6543 64 *
martwerl 0:afeca64a6543 65 * Example:
martwerl 0:afeca64a6543 66 * @code
martwerl 0:afeca64a6543 67 * #include "mbed.h"
martwerl 0:afeca64a6543 68 *
martwerl 0:afeca64a6543 69 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
martwerl 0:afeca64a6543 70 *
martwerl 0:afeca64a6543 71 * int main() {
martwerl 0:afeca64a6543 72 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
martwerl 0:afeca64a6543 73 * fprintf(fp, "Hello World!");
martwerl 0:afeca64a6543 74 * fclose(fp);
martwerl 0:afeca64a6543 75 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
martwerl 0:afeca64a6543 76 *
martwerl 0:afeca64a6543 77 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
martwerl 0:afeca64a6543 78 * struct dirent *p;
martwerl 0:afeca64a6543 79 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
martwerl 0:afeca64a6543 80 * printf("%s\n", p->d_name); // to stdout.
martwerl 0:afeca64a6543 81 * }
martwerl 0:afeca64a6543 82 * closedir(d);
martwerl 0:afeca64a6543 83 * }
martwerl 0:afeca64a6543 84 * @endcode
martwerl 0:afeca64a6543 85 *
martwerl 0:afeca64a6543 86 * @note
martwerl 0:afeca64a6543 87 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
martwerl 0:afeca64a6543 88 * on the Host computer. This means it is no longer accessible from the Host Computer.
martwerl 0:afeca64a6543 89 *
martwerl 0:afeca64a6543 90 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
martwerl 0:afeca64a6543 91 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
martwerl 0:afeca64a6543 92 */
martwerl 0:afeca64a6543 93 class LocalFileSystem : public FileSystemLike {
martwerl 0:afeca64a6543 94
martwerl 0:afeca64a6543 95 public:
martwerl 0:afeca64a6543 96 LocalFileSystem(const char* n) : FileSystemLike(n) {
martwerl 0:afeca64a6543 97
martwerl 0:afeca64a6543 98 }
martwerl 0:afeca64a6543 99
martwerl 0:afeca64a6543 100 virtual FileHandle *open(const char* name, int flags);
martwerl 0:afeca64a6543 101 virtual int remove(const char *filename);
martwerl 0:afeca64a6543 102 virtual DirHandle *opendir(const char *name);
martwerl 0:afeca64a6543 103 };
martwerl 0:afeca64a6543 104
martwerl 0:afeca64a6543 105 } // namespace mbed
martwerl 0:afeca64a6543 106
martwerl 0:afeca64a6543 107 #endif
martwerl 0:afeca64a6543 108
martwerl 0:afeca64a6543 109 #endif
martwerl 0:afeca64a6543 110