test

Dependents:   robotic_fish_7

Committer:
juansal12
Date:
Tue Jan 14 19:14:29 2020 +0000
Revision:
0:44931ff4a3ed
Sofi 7 code;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
juansal12 0:44931ff4a3ed 1 /* mbed Microcontroller Library
juansal12 0:44931ff4a3ed 2 * Copyright (c) 2006-2013 ARM Limited
juansal12 0:44931ff4a3ed 3 *
juansal12 0:44931ff4a3ed 4 * Licensed under the Apache License, Version 2.0 (the "License");
juansal12 0:44931ff4a3ed 5 * you may not use this file except in compliance with the License.
juansal12 0:44931ff4a3ed 6 * You may obtain a copy of the License at
juansal12 0:44931ff4a3ed 7 *
juansal12 0:44931ff4a3ed 8 * http://www.apache.org/licenses/LICENSE-2.0
juansal12 0:44931ff4a3ed 9 *
juansal12 0:44931ff4a3ed 10 * Unless required by applicable law or agreed to in writing, software
juansal12 0:44931ff4a3ed 11 * distributed under the License is distributed on an "AS IS" BASIS,
juansal12 0:44931ff4a3ed 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
juansal12 0:44931ff4a3ed 13 * See the License for the specific language governing permissions and
juansal12 0:44931ff4a3ed 14 * limitations under the License.
juansal12 0:44931ff4a3ed 15 */
juansal12 0:44931ff4a3ed 16 #ifndef MBED_LOCALFILESYSTEM_H
juansal12 0:44931ff4a3ed 17 #define MBED_LOCALFILESYSTEM_H
juansal12 0:44931ff4a3ed 18
juansal12 0:44931ff4a3ed 19 #include "platform.h"
juansal12 0:44931ff4a3ed 20
juansal12 0:44931ff4a3ed 21 #if DEVICE_LOCALFILESYSTEM
juansal12 0:44931ff4a3ed 22
juansal12 0:44931ff4a3ed 23 #include "FileSystemLike.h"
juansal12 0:44931ff4a3ed 24
juansal12 0:44931ff4a3ed 25 namespace mbed {
juansal12 0:44931ff4a3ed 26
juansal12 0:44931ff4a3ed 27 FILEHANDLE local_file_open(const char* name, int flags);
juansal12 0:44931ff4a3ed 28
juansal12 0:44931ff4a3ed 29 class LocalFileHandle : public FileHandle {
juansal12 0:44931ff4a3ed 30
juansal12 0:44931ff4a3ed 31 public:
juansal12 0:44931ff4a3ed 32 LocalFileHandle(FILEHANDLE fh);
juansal12 0:44931ff4a3ed 33
juansal12 0:44931ff4a3ed 34 virtual int close();
juansal12 0:44931ff4a3ed 35
juansal12 0:44931ff4a3ed 36 virtual ssize_t write(const void *buffer, size_t length);
juansal12 0:44931ff4a3ed 37
juansal12 0:44931ff4a3ed 38 virtual ssize_t read(void *buffer, size_t length);
juansal12 0:44931ff4a3ed 39
juansal12 0:44931ff4a3ed 40 virtual int isatty();
juansal12 0:44931ff4a3ed 41
juansal12 0:44931ff4a3ed 42 virtual off_t lseek(off_t position, int whence);
juansal12 0:44931ff4a3ed 43
juansal12 0:44931ff4a3ed 44 virtual int fsync();
juansal12 0:44931ff4a3ed 45
juansal12 0:44931ff4a3ed 46 virtual off_t flen();
juansal12 0:44931ff4a3ed 47
juansal12 0:44931ff4a3ed 48 protected:
juansal12 0:44931ff4a3ed 49 FILEHANDLE _fh;
juansal12 0:44931ff4a3ed 50 int pos;
juansal12 0:44931ff4a3ed 51 };
juansal12 0:44931ff4a3ed 52
juansal12 0:44931ff4a3ed 53 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
juansal12 0:44931ff4a3ed 54 *
juansal12 0:44931ff4a3ed 55 * This allows programs to read and write files on the same disk drive that is used to program the
juansal12 0:44931ff4a3ed 56 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
juansal12 0:44931ff4a3ed 57 * read and write files.
juansal12 0:44931ff4a3ed 58 *
juansal12 0:44931ff4a3ed 59 * Example:
juansal12 0:44931ff4a3ed 60 * @code
juansal12 0:44931ff4a3ed 61 * #include "mbed.h"
juansal12 0:44931ff4a3ed 62 *
juansal12 0:44931ff4a3ed 63 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
juansal12 0:44931ff4a3ed 64 *
juansal12 0:44931ff4a3ed 65 * int main() {
juansal12 0:44931ff4a3ed 66 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
juansal12 0:44931ff4a3ed 67 * fprintf(fp, "Hello World!");
juansal12 0:44931ff4a3ed 68 * fclose(fp);
juansal12 0:44931ff4a3ed 69 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
juansal12 0:44931ff4a3ed 70 *
juansal12 0:44931ff4a3ed 71 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
juansal12 0:44931ff4a3ed 72 * struct dirent *p;
juansal12 0:44931ff4a3ed 73 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
juansal12 0:44931ff4a3ed 74 * printf("%s\n", p->d_name); // to stdout.
juansal12 0:44931ff4a3ed 75 * }
juansal12 0:44931ff4a3ed 76 * closedir(d);
juansal12 0:44931ff4a3ed 77 * }
juansal12 0:44931ff4a3ed 78 * @endcode
juansal12 0:44931ff4a3ed 79 *
juansal12 0:44931ff4a3ed 80 * @note
juansal12 0:44931ff4a3ed 81 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
juansal12 0:44931ff4a3ed 82 * on the Host computer. This means it is no longer accessible from the Host Computer.
juansal12 0:44931ff4a3ed 83 *
juansal12 0:44931ff4a3ed 84 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
juansal12 0:44931ff4a3ed 85 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
juansal12 0:44931ff4a3ed 86 */
juansal12 0:44931ff4a3ed 87 class LocalFileSystem : public FileSystemLike {
juansal12 0:44931ff4a3ed 88
juansal12 0:44931ff4a3ed 89 public:
juansal12 0:44931ff4a3ed 90 LocalFileSystem(const char* n) : FileSystemLike(n) {
juansal12 0:44931ff4a3ed 91
juansal12 0:44931ff4a3ed 92 }
juansal12 0:44931ff4a3ed 93
juansal12 0:44931ff4a3ed 94 virtual FileHandle *open(const char* name, int flags);
juansal12 0:44931ff4a3ed 95 virtual int remove(const char *filename);
juansal12 0:44931ff4a3ed 96 virtual DirHandle *opendir(const char *name);
juansal12 0:44931ff4a3ed 97 };
juansal12 0:44931ff4a3ed 98
juansal12 0:44931ff4a3ed 99 } // namespace mbed
juansal12 0:44931ff4a3ed 100
juansal12 0:44931ff4a3ed 101 #endif
juansal12 0:44931ff4a3ed 102
juansal12 0:44931ff4a3ed 103 #endif