This is my quadcopter prototype software, still in development!

Committer:
Anaesthetix
Date:
Wed Jan 30 13:14:44 2013 +0000
Revision:
0:978110f7f027
My quadcopter prototype software, still in development.

Who changed what in which revision?

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