BLE Temperature Service Mobile and Ubiquitous Computing Module Birkbeck College

Dependencies:   DS1820

Committer:
gkroussos
Date:
Sun Mar 08 19:42:20 2015 +0000
Revision:
0:dd0fea342ad2
BLE Temperature Service ; Mobile and Ubiquitous Computing Module; Birkbeck College

Who changed what in which revision?

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