JEK changes enabling proper recording of IMU/GPS datastrams - 02-APR-2013
Fork of GPS_Incremental by
FatFileSystem/FATFileHandle.cpp@9:b45feb91ba38, 2013-04-19 (annotated)
- Committer:
- jekain314
- Date:
- Fri Apr 19 16:21:27 2013 +0000
- Revision:
- 9:b45feb91ba38
- Parent:
- 0:c746ee34feae
update to allow better imu gps data collection
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dannyman939 | 0:c746ee34feae | 1 | /* mbed Microcontroller Library - FATFileHandle |
dannyman939 | 0:c746ee34feae | 2 | * Copyright (c) 2008, sford |
dannyman939 | 0:c746ee34feae | 3 | */ |
dannyman939 | 0:c746ee34feae | 4 | |
dannyman939 | 0:c746ee34feae | 5 | #include "FATFileHandle.h" |
dannyman939 | 0:c746ee34feae | 6 | |
dannyman939 | 0:c746ee34feae | 7 | #include <stdio.h> |
dannyman939 | 0:c746ee34feae | 8 | #include <stdlib.h> |
dannyman939 | 0:c746ee34feae | 9 | #include "ff.h" |
dannyman939 | 0:c746ee34feae | 10 | #include "FATFileSystem.h" |
dannyman939 | 0:c746ee34feae | 11 | |
dannyman939 | 0:c746ee34feae | 12 | namespace mbed { |
dannyman939 | 0:c746ee34feae | 13 | |
dannyman939 | 0:c746ee34feae | 14 | #if FFSDEBUG_ENABLED |
dannyman939 | 0:c746ee34feae | 15 | static const char *FR_ERRORS[] = { |
dannyman939 | 0:c746ee34feae | 16 | "FR_OK = 0", |
dannyman939 | 0:c746ee34feae | 17 | "FR_NOT_READY", |
dannyman939 | 0:c746ee34feae | 18 | "FR_NO_FILE", |
dannyman939 | 0:c746ee34feae | 19 | "FR_NO_PATH", |
dannyman939 | 0:c746ee34feae | 20 | "FR_INVALID_NAME", |
dannyman939 | 0:c746ee34feae | 21 | "FR_INVALID_DRIVE", |
dannyman939 | 0:c746ee34feae | 22 | "FR_DENIED", |
dannyman939 | 0:c746ee34feae | 23 | "FR_EXIST", |
dannyman939 | 0:c746ee34feae | 24 | "FR_RW_ERROR", |
dannyman939 | 0:c746ee34feae | 25 | "FR_WRITE_PROTECTED", |
dannyman939 | 0:c746ee34feae | 26 | "FR_NOT_ENABLED", |
dannyman939 | 0:c746ee34feae | 27 | "FR_NO_FILESYSTEM", |
dannyman939 | 0:c746ee34feae | 28 | "FR_INVALID_OBJECT", |
dannyman939 | 0:c746ee34feae | 29 | "FR_MKFS_ABORTED" |
dannyman939 | 0:c746ee34feae | 30 | }; |
dannyman939 | 0:c746ee34feae | 31 | #endif |
dannyman939 | 0:c746ee34feae | 32 | |
dannyman939 | 0:c746ee34feae | 33 | FATFileHandle::FATFileHandle(FIL fh) { |
dannyman939 | 0:c746ee34feae | 34 | _fh = fh; |
dannyman939 | 0:c746ee34feae | 35 | } |
dannyman939 | 0:c746ee34feae | 36 | |
dannyman939 | 0:c746ee34feae | 37 | int FATFileHandle::close() { |
dannyman939 | 0:c746ee34feae | 38 | FFSDEBUG("close\n"); |
dannyman939 | 0:c746ee34feae | 39 | int retval = f_close(&_fh); |
dannyman939 | 0:c746ee34feae | 40 | delete this; |
dannyman939 | 0:c746ee34feae | 41 | return retval; |
dannyman939 | 0:c746ee34feae | 42 | } |
dannyman939 | 0:c746ee34feae | 43 | |
dannyman939 | 0:c746ee34feae | 44 | ssize_t FATFileHandle::write(const void* buffer, size_t length) { |
dannyman939 | 0:c746ee34feae | 45 | FFSDEBUG("write(%d)\n", length); |
dannyman939 | 0:c746ee34feae | 46 | UINT n; |
dannyman939 | 0:c746ee34feae | 47 | FRESULT res = f_write(&_fh, buffer, length, &n); |
dannyman939 | 0:c746ee34feae | 48 | if(res) { |
dannyman939 | 0:c746ee34feae | 49 | FFSDEBUG("f_write() failed (%d, %s)", res, FR_ERRORS[res]); |
dannyman939 | 0:c746ee34feae | 50 | return -1; |
dannyman939 | 0:c746ee34feae | 51 | } |
dannyman939 | 0:c746ee34feae | 52 | return n; |
dannyman939 | 0:c746ee34feae | 53 | } |
dannyman939 | 0:c746ee34feae | 54 | |
dannyman939 | 0:c746ee34feae | 55 | ssize_t FATFileHandle::read(void* buffer, size_t length) { |
dannyman939 | 0:c746ee34feae | 56 | FFSDEBUG("read(%d)\n", length); |
dannyman939 | 0:c746ee34feae | 57 | UINT n; |
dannyman939 | 0:c746ee34feae | 58 | FRESULT res = f_read(&_fh, buffer, length, &n); |
dannyman939 | 0:c746ee34feae | 59 | if(res) { |
dannyman939 | 0:c746ee34feae | 60 | FFSDEBUG("f_read() failed (%d, %s)\n", res, FR_ERRORS[res]); |
dannyman939 | 0:c746ee34feae | 61 | return -1; |
dannyman939 | 0:c746ee34feae | 62 | } |
dannyman939 | 0:c746ee34feae | 63 | return n; |
dannyman939 | 0:c746ee34feae | 64 | } |
dannyman939 | 0:c746ee34feae | 65 | |
dannyman939 | 0:c746ee34feae | 66 | int FATFileHandle::isatty() { |
dannyman939 | 0:c746ee34feae | 67 | return 0; |
dannyman939 | 0:c746ee34feae | 68 | } |
dannyman939 | 0:c746ee34feae | 69 | |
dannyman939 | 0:c746ee34feae | 70 | off_t FATFileHandle::lseek(off_t position, int whence) { |
dannyman939 | 0:c746ee34feae | 71 | FFSDEBUG("lseek(%i,%i)\n",position,whence); |
dannyman939 | 0:c746ee34feae | 72 | if(whence == SEEK_END) { |
dannyman939 | 0:c746ee34feae | 73 | position += _fh.fsize; |
dannyman939 | 0:c746ee34feae | 74 | } else if(whence==SEEK_CUR) { |
dannyman939 | 0:c746ee34feae | 75 | position += _fh.fptr; |
dannyman939 | 0:c746ee34feae | 76 | } |
dannyman939 | 0:c746ee34feae | 77 | FRESULT res = f_lseek(&_fh, position); |
dannyman939 | 0:c746ee34feae | 78 | if(res) { |
dannyman939 | 0:c746ee34feae | 79 | FFSDEBUG("lseek failed (%d, %s)\n", res, FR_ERRORS[res]); |
dannyman939 | 0:c746ee34feae | 80 | return -1; |
dannyman939 | 0:c746ee34feae | 81 | } else { |
dannyman939 | 0:c746ee34feae | 82 | FFSDEBUG("lseek OK, returning %i\n", _fh.fptr); |
dannyman939 | 0:c746ee34feae | 83 | return _fh.fptr; |
dannyman939 | 0:c746ee34feae | 84 | } |
dannyman939 | 0:c746ee34feae | 85 | } |
dannyman939 | 0:c746ee34feae | 86 | |
dannyman939 | 0:c746ee34feae | 87 | int FATFileHandle::fsync() { |
dannyman939 | 0:c746ee34feae | 88 | FFSDEBUG("fsync()\n"); |
dannyman939 | 0:c746ee34feae | 89 | FRESULT res = f_sync(&_fh); |
dannyman939 | 0:c746ee34feae | 90 | if (res) { |
dannyman939 | 0:c746ee34feae | 91 | FFSDEBUG("f_sync() failed (%d, %s)\n", res, FR_ERRORS[res]); |
dannyman939 | 0:c746ee34feae | 92 | return -1; |
dannyman939 | 0:c746ee34feae | 93 | } |
dannyman939 | 0:c746ee34feae | 94 | return 0; |
dannyman939 | 0:c746ee34feae | 95 | } |
dannyman939 | 0:c746ee34feae | 96 | |
dannyman939 | 0:c746ee34feae | 97 | off_t FATFileHandle::flen() { |
dannyman939 | 0:c746ee34feae | 98 | FFSDEBUG("flen\n"); |
dannyman939 | 0:c746ee34feae | 99 | return _fh.fsize; |
dannyman939 | 0:c746ee34feae | 100 | } |
dannyman939 | 0:c746ee34feae | 101 | |
dannyman939 | 0:c746ee34feae | 102 | } // namespace mbed |