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