Programme d'utilisation des AX12 avec rajout de l'MX12
Fork of test_carteAToutFaire_PR by
mbed/LocalFileSystem.h@1:f3f702086a30, 2017-05-11 (annotated)
- Committer:
- ClementBreteau
- Date:
- Thu May 11 11:49:50 2017 +0000
- Revision:
- 1:f3f702086a30
test de la carte ? tout faire du petit robot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ClementBreteau | 1:f3f702086a30 | 1 | /* mbed Microcontroller Library - LocalFileSystem |
ClementBreteau | 1:f3f702086a30 | 2 | * Copyright (c) 2008-2009 ARM Limited. All rights reserved. |
ClementBreteau | 1:f3f702086a30 | 3 | */ |
ClementBreteau | 1:f3f702086a30 | 4 | |
ClementBreteau | 1:f3f702086a30 | 5 | #ifndef MBED_LOCALFILESYSTEM_H |
ClementBreteau | 1:f3f702086a30 | 6 | #define MBED_LOCALFILESYSTEM_H |
ClementBreteau | 1:f3f702086a30 | 7 | |
ClementBreteau | 1:f3f702086a30 | 8 | #include "FileSystemLike.h" |
ClementBreteau | 1:f3f702086a30 | 9 | |
ClementBreteau | 1:f3f702086a30 | 10 | namespace mbed { |
ClementBreteau | 1:f3f702086a30 | 11 | |
ClementBreteau | 1:f3f702086a30 | 12 | FILEHANDLE local_file_open(const char* name, int flags); |
ClementBreteau | 1:f3f702086a30 | 13 | |
ClementBreteau | 1:f3f702086a30 | 14 | class LocalFileHandle : public FileHandle { |
ClementBreteau | 1:f3f702086a30 | 15 | |
ClementBreteau | 1:f3f702086a30 | 16 | public: |
ClementBreteau | 1:f3f702086a30 | 17 | LocalFileHandle(FILEHANDLE fh); |
ClementBreteau | 1:f3f702086a30 | 18 | |
ClementBreteau | 1:f3f702086a30 | 19 | virtual int close(); |
ClementBreteau | 1:f3f702086a30 | 20 | |
ClementBreteau | 1:f3f702086a30 | 21 | virtual ssize_t write(const void *buffer, size_t length); |
ClementBreteau | 1:f3f702086a30 | 22 | |
ClementBreteau | 1:f3f702086a30 | 23 | virtual ssize_t read(void *buffer, size_t length); |
ClementBreteau | 1:f3f702086a30 | 24 | |
ClementBreteau | 1:f3f702086a30 | 25 | virtual int isatty(); |
ClementBreteau | 1:f3f702086a30 | 26 | |
ClementBreteau | 1:f3f702086a30 | 27 | virtual off_t lseek(off_t position, int whence); |
ClementBreteau | 1:f3f702086a30 | 28 | |
ClementBreteau | 1:f3f702086a30 | 29 | virtual int fsync(); |
ClementBreteau | 1:f3f702086a30 | 30 | |
ClementBreteau | 1:f3f702086a30 | 31 | virtual off_t flen(); |
ClementBreteau | 1:f3f702086a30 | 32 | |
ClementBreteau | 1:f3f702086a30 | 33 | protected: |
ClementBreteau | 1:f3f702086a30 | 34 | FILEHANDLE _fh; |
ClementBreteau | 1:f3f702086a30 | 35 | int pos; |
ClementBreteau | 1:f3f702086a30 | 36 | }; |
ClementBreteau | 1:f3f702086a30 | 37 | |
ClementBreteau | 1:f3f702086a30 | 38 | /* Class: LocalFileSystem |
ClementBreteau | 1:f3f702086a30 | 39 | * A filesystem for accessing the local mbed Microcontroller USB disk drive |
ClementBreteau | 1:f3f702086a30 | 40 | * |
ClementBreteau | 1:f3f702086a30 | 41 | * This allows programs to read and write files on the same disk drive that is used to program the |
ClementBreteau | 1:f3f702086a30 | 42 | * mbed Microcontroller. Once created, the standard C file access functions are used to open, |
ClementBreteau | 1:f3f702086a30 | 43 | * read and write files. |
ClementBreteau | 1:f3f702086a30 | 44 | * |
ClementBreteau | 1:f3f702086a30 | 45 | * Example: |
ClementBreteau | 1:f3f702086a30 | 46 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 47 | * > |
ClementBreteau | 1:f3f702086a30 | 48 | * > LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
ClementBreteau | 1:f3f702086a30 | 49 | * > |
ClementBreteau | 1:f3f702086a30 | 50 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 51 | * > FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing |
ClementBreteau | 1:f3f702086a30 | 52 | * > fprintf(fp, "Hello World!"); |
ClementBreteau | 1:f3f702086a30 | 53 | * > fclose(fp); |
ClementBreteau | 1:f3f702086a30 | 54 | * > remove("/local/out.txt"); // Removes the file "out.txt" from the local file system |
ClementBreteau | 1:f3f702086a30 | 55 | * > |
ClementBreteau | 1:f3f702086a30 | 56 | * > DIR *d = opendir("/local"); // Opens the root directory of the local file system |
ClementBreteau | 1:f3f702086a30 | 57 | * > struct dirent *p; |
ClementBreteau | 1:f3f702086a30 | 58 | * > while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system |
ClementBreteau | 1:f3f702086a30 | 59 | * > printf("%s\n", p->d_name); // to stdout. |
ClementBreteau | 1:f3f702086a30 | 60 | * > } |
ClementBreteau | 1:f3f702086a30 | 61 | * > closedir(d); |
ClementBreteau | 1:f3f702086a30 | 62 | * > } |
ClementBreteau | 1:f3f702086a30 | 63 | * |
ClementBreteau | 1:f3f702086a30 | 64 | * Implementation Notes: |
ClementBreteau | 1:f3f702086a30 | 65 | * If the microcontroller program makes an access to the local drive, it will be marked as "removed" |
ClementBreteau | 1:f3f702086a30 | 66 | * on the Host computer. This means it is no longer accessible from the Host Computer. |
ClementBreteau | 1:f3f702086a30 | 67 | * |
ClementBreteau | 1:f3f702086a30 | 68 | * The drive will only re-appear when the microcontroller program exists. Note that if the program does |
ClementBreteau | 1:f3f702086a30 | 69 | * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again! |
ClementBreteau | 1:f3f702086a30 | 70 | */ |
ClementBreteau | 1:f3f702086a30 | 71 | class LocalFileSystem : public FileSystemLike { |
ClementBreteau | 1:f3f702086a30 | 72 | |
ClementBreteau | 1:f3f702086a30 | 73 | public: |
ClementBreteau | 1:f3f702086a30 | 74 | |
ClementBreteau | 1:f3f702086a30 | 75 | LocalFileSystem(const char* n) : FileSystemLike(n) { |
ClementBreteau | 1:f3f702086a30 | 76 | |
ClementBreteau | 1:f3f702086a30 | 77 | } |
ClementBreteau | 1:f3f702086a30 | 78 | |
ClementBreteau | 1:f3f702086a30 | 79 | virtual FileHandle *open(const char* name, int flags); |
ClementBreteau | 1:f3f702086a30 | 80 | virtual int remove(const char *filename); |
ClementBreteau | 1:f3f702086a30 | 81 | virtual DirHandle *opendir(const char *name); |
ClementBreteau | 1:f3f702086a30 | 82 | }; |
ClementBreteau | 1:f3f702086a30 | 83 | |
ClementBreteau | 1:f3f702086a30 | 84 | } // namespace mbed |
ClementBreteau | 1:f3f702086a30 | 85 | |
ClementBreteau | 1:f3f702086a30 | 86 | #endif |