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