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