Xbee CountUp

Dependencies:   mbed

Fork of HeptaXbee_CountUp by 智也 大野

Committer:
tomoya123
Date:
Tue Dec 13 07:55:03 2016 +0000
Revision:
1:715b80d2a02b
Parent:
0:0a7fa0911e6c
Xbee CountUp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tomoya123 0:0a7fa0911e6c 1 /* mbed Microcontroller Library
tomoya123 0:0a7fa0911e6c 2 * Copyright (c) 2006-2012 ARM Limited
tomoya123 0:0a7fa0911e6c 3 *
tomoya123 0:0a7fa0911e6c 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
tomoya123 0:0a7fa0911e6c 5 * of this software and associated documentation files (the "Software"), to deal
tomoya123 0:0a7fa0911e6c 6 * in the Software without restriction, including without limitation the rights
tomoya123 0:0a7fa0911e6c 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
tomoya123 0:0a7fa0911e6c 8 * copies of the Software, and to permit persons to whom the Software is
tomoya123 0:0a7fa0911e6c 9 * furnished to do so, subject to the following conditions:
tomoya123 0:0a7fa0911e6c 10 *
tomoya123 0:0a7fa0911e6c 11 * The above copyright notice and this permission notice shall be included in
tomoya123 0:0a7fa0911e6c 12 * all copies or substantial portions of the Software.
tomoya123 0:0a7fa0911e6c 13 *
tomoya123 0:0a7fa0911e6c 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
tomoya123 0:0a7fa0911e6c 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
tomoya123 0:0a7fa0911e6c 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
tomoya123 0:0a7fa0911e6c 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
tomoya123 0:0a7fa0911e6c 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tomoya123 0:0a7fa0911e6c 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
tomoya123 0:0a7fa0911e6c 20 * SOFTWARE.
tomoya123 0:0a7fa0911e6c 21 */
tomoya123 0:0a7fa0911e6c 22 #include "ff.h"
tomoya123 0:0a7fa0911e6c 23 #include "ffconf.h"
tomoya123 0:0a7fa0911e6c 24 #include "mbed_debug.h"
tomoya123 0:0a7fa0911e6c 25
tomoya123 0:0a7fa0911e6c 26 #include "FATFileHandle.h"
tomoya123 0:0a7fa0911e6c 27
tomoya123 0:0a7fa0911e6c 28 FATFileHandle::FATFileHandle(FIL fh) {
tomoya123 0:0a7fa0911e6c 29 _fh = fh;
tomoya123 0:0a7fa0911e6c 30 }
tomoya123 0:0a7fa0911e6c 31
tomoya123 0:0a7fa0911e6c 32 int FATFileHandle::close() {
tomoya123 0:0a7fa0911e6c 33 int retval = f_close(&_fh);
tomoya123 0:0a7fa0911e6c 34 delete this;
tomoya123 0:0a7fa0911e6c 35 return retval;
tomoya123 0:0a7fa0911e6c 36 }
tomoya123 0:0a7fa0911e6c 37
tomoya123 0:0a7fa0911e6c 38 ssize_t FATFileHandle::write(const void* buffer, size_t length) {
tomoya123 0:0a7fa0911e6c 39 UINT n;
tomoya123 0:0a7fa0911e6c 40 FRESULT res = f_write(&_fh, buffer, length, &n);
tomoya123 0:0a7fa0911e6c 41 if (res) {
tomoya123 0:0a7fa0911e6c 42 debug_if(FFS_DBG, "f_write() failed: %d", res);
tomoya123 0:0a7fa0911e6c 43 return -1;
tomoya123 0:0a7fa0911e6c 44 }
tomoya123 0:0a7fa0911e6c 45 return n;
tomoya123 0:0a7fa0911e6c 46 }
tomoya123 0:0a7fa0911e6c 47
tomoya123 0:0a7fa0911e6c 48 ssize_t FATFileHandle::read(void* buffer, size_t length) {
tomoya123 0:0a7fa0911e6c 49 debug_if(FFS_DBG, "read(%d)\n", length);
tomoya123 0:0a7fa0911e6c 50 UINT n;
tomoya123 0:0a7fa0911e6c 51 FRESULT res = f_read(&_fh, buffer, length, &n);
tomoya123 0:0a7fa0911e6c 52 if (res) {
tomoya123 0:0a7fa0911e6c 53 debug_if(FFS_DBG, "f_read() failed: %d\n", res);
tomoya123 0:0a7fa0911e6c 54 return -1;
tomoya123 0:0a7fa0911e6c 55 }
tomoya123 0:0a7fa0911e6c 56 return n;
tomoya123 0:0a7fa0911e6c 57 }
tomoya123 0:0a7fa0911e6c 58
tomoya123 0:0a7fa0911e6c 59 int FATFileHandle::isatty() {
tomoya123 0:0a7fa0911e6c 60 return 0;
tomoya123 0:0a7fa0911e6c 61 }
tomoya123 0:0a7fa0911e6c 62
tomoya123 0:0a7fa0911e6c 63 off_t FATFileHandle::lseek(off_t position, int whence) {
tomoya123 0:0a7fa0911e6c 64 if (whence == SEEK_END) {
tomoya123 0:0a7fa0911e6c 65 position += _fh.fsize;
tomoya123 0:0a7fa0911e6c 66 } else if(whence==SEEK_CUR) {
tomoya123 0:0a7fa0911e6c 67 position += _fh.fptr;
tomoya123 0:0a7fa0911e6c 68 }
tomoya123 0:0a7fa0911e6c 69 FRESULT res = f_lseek(&_fh, position);
tomoya123 0:0a7fa0911e6c 70 if (res) {
tomoya123 0:0a7fa0911e6c 71 debug_if(FFS_DBG, "lseek failed: %d\n", res);
tomoya123 0:0a7fa0911e6c 72 return -1;
tomoya123 0:0a7fa0911e6c 73 } else {
tomoya123 0:0a7fa0911e6c 74 debug_if(FFS_DBG, "lseek OK, returning %i\n", _fh.fptr);
tomoya123 0:0a7fa0911e6c 75 return _fh.fptr;
tomoya123 0:0a7fa0911e6c 76 }
tomoya123 0:0a7fa0911e6c 77 }
tomoya123 0:0a7fa0911e6c 78
tomoya123 0:0a7fa0911e6c 79 int FATFileHandle::fsync() {
tomoya123 0:0a7fa0911e6c 80 FRESULT res = f_sync(&_fh);
tomoya123 0:0a7fa0911e6c 81 if (res) {
tomoya123 0:0a7fa0911e6c 82 debug_if(FFS_DBG, "f_sync() failed: %d\n", res);
tomoya123 0:0a7fa0911e6c 83 return -1;
tomoya123 0:0a7fa0911e6c 84 }
tomoya123 0:0a7fa0911e6c 85 return 0;
tomoya123 0:0a7fa0911e6c 86 }
tomoya123 0:0a7fa0911e6c 87
tomoya123 0:0a7fa0911e6c 88 off_t FATFileHandle::flen() {
tomoya123 0:0a7fa0911e6c 89 return _fh.fsize;
tomoya123 0:0a7fa0911e6c 90 }