test

Dependents:   robotic_fish_6

Committer:
juansal12
Date:
Fri Dec 03 23:00:34 2021 +0000
Revision:
0:c792b17d9f78
uploaded sofi code ;

Who changed what in which revision?

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