Programme d'utilisation des AX12 avec rajout de l'MX12

Fork of test_carteAToutFaire_PR by CRAC Team

Committer:
ClementBreteau
Date:
Thu May 11 11:49:50 2017 +0000
Revision:
1:f3f702086a30
test de la carte ? tout faire du petit robot

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ClementBreteau 1:f3f702086a30 1 /* mbed Microcontroller Library - FileHandler
ClementBreteau 1:f3f702086a30 2 * Copyright (c) 2007-2009 ARM Limited. All rights reserved.
ClementBreteau 1:f3f702086a30 3 */
ClementBreteau 1:f3f702086a30 4
ClementBreteau 1:f3f702086a30 5 #ifndef MBED_FILEHANDLE_H
ClementBreteau 1:f3f702086a30 6 #define MBED_FILEHANDLE_H
ClementBreteau 1:f3f702086a30 7
ClementBreteau 1:f3f702086a30 8 typedef int FILEHANDLE;
ClementBreteau 1:f3f702086a30 9
ClementBreteau 1:f3f702086a30 10 #include <stdio.h>
ClementBreteau 1:f3f702086a30 11 #ifdef __ARMCC_VERSION
ClementBreteau 1:f3f702086a30 12 typedef int ssize_t;
ClementBreteau 1:f3f702086a30 13 typedef long off_t;
ClementBreteau 1:f3f702086a30 14 #else
ClementBreteau 1:f3f702086a30 15 #include <sys/types.h>
ClementBreteau 1:f3f702086a30 16 #endif
ClementBreteau 1:f3f702086a30 17
ClementBreteau 1:f3f702086a30 18 namespace mbed {
ClementBreteau 1:f3f702086a30 19
ClementBreteau 1:f3f702086a30 20 /* Class FileHandle
ClementBreteau 1:f3f702086a30 21 * An OO equivalent of the internal FILEHANDLE variable
ClementBreteau 1:f3f702086a30 22 * and associated _sys_* functions
ClementBreteau 1:f3f702086a30 23 *
ClementBreteau 1:f3f702086a30 24 * FileHandle is an abstract class, needing at least sys_write and
ClementBreteau 1:f3f702086a30 25 * sys_read to be implmented for a simple interactive device
ClementBreteau 1:f3f702086a30 26 *
ClementBreteau 1:f3f702086a30 27 * No one ever directly tals to/instanciates a FileHandle - it gets
ClementBreteau 1:f3f702086a30 28 * created by FileSystem, and wrapped up by stdio
ClementBreteau 1:f3f702086a30 29 */
ClementBreteau 1:f3f702086a30 30 class FileHandle {
ClementBreteau 1:f3f702086a30 31
ClementBreteau 1:f3f702086a30 32 public:
ClementBreteau 1:f3f702086a30 33
ClementBreteau 1:f3f702086a30 34 /* Function write
ClementBreteau 1:f3f702086a30 35 * Write the contents of a buffer to the file
ClementBreteau 1:f3f702086a30 36 *
ClementBreteau 1:f3f702086a30 37 * Parameters
ClementBreteau 1:f3f702086a30 38 * buffer - the buffer to write from
ClementBreteau 1:f3f702086a30 39 * length - the number of characters to write
ClementBreteau 1:f3f702086a30 40 *
ClementBreteau 1:f3f702086a30 41 * Returns
ClementBreteau 1:f3f702086a30 42 * The number of characters written (possibly 0) on success, -1 on error.
ClementBreteau 1:f3f702086a30 43 */
ClementBreteau 1:f3f702086a30 44 virtual ssize_t write(const void* buffer, size_t length) = 0;
ClementBreteau 1:f3f702086a30 45
ClementBreteau 1:f3f702086a30 46 /* Function close
ClementBreteau 1:f3f702086a30 47 * Close the file
ClementBreteau 1:f3f702086a30 48 *
ClementBreteau 1:f3f702086a30 49 * Returns
ClementBreteau 1:f3f702086a30 50 * Zero on success, -1 on error.
ClementBreteau 1:f3f702086a30 51 */
ClementBreteau 1:f3f702086a30 52 virtual int close() = 0;
ClementBreteau 1:f3f702086a30 53
ClementBreteau 1:f3f702086a30 54 /* Function read
ClementBreteau 1:f3f702086a30 55 * Reads the contents of the file into a buffer
ClementBreteau 1:f3f702086a30 56 *
ClementBreteau 1:f3f702086a30 57 * Parameters
ClementBreteau 1:f3f702086a30 58 * buffer - the buffer to read in to
ClementBreteau 1:f3f702086a30 59 * length - the number of characters to read
ClementBreteau 1:f3f702086a30 60 *
ClementBreteau 1:f3f702086a30 61 * Returns
ClementBreteau 1:f3f702086a30 62 * The number of characters read (zero at end of file) on success, -1 on error.
ClementBreteau 1:f3f702086a30 63 */
ClementBreteau 1:f3f702086a30 64 virtual ssize_t read(void* buffer, size_t length) = 0;
ClementBreteau 1:f3f702086a30 65
ClementBreteau 1:f3f702086a30 66 /* Function isatty
ClementBreteau 1:f3f702086a30 67 * Check if the handle is for a interactive terminal device
ClementBreteau 1:f3f702086a30 68 *
ClementBreteau 1:f3f702086a30 69 * If so, line buffered behaviour is used by default
ClementBreteau 1:f3f702086a30 70 *
ClementBreteau 1:f3f702086a30 71 * Returns
ClementBreteau 1:f3f702086a30 72 * 1 if it is a terminal, 0 otherwise
ClementBreteau 1:f3f702086a30 73 */
ClementBreteau 1:f3f702086a30 74 virtual int isatty() = 0 ;
ClementBreteau 1:f3f702086a30 75
ClementBreteau 1:f3f702086a30 76 /* Function lseek
ClementBreteau 1:f3f702086a30 77 * Move the file position to a given offset from a given location.
ClementBreteau 1:f3f702086a30 78 *
ClementBreteau 1:f3f702086a30 79 * Parameters
ClementBreteau 1:f3f702086a30 80 * offset - The offset from whence to move to
ClementBreteau 1:f3f702086a30 81 * whence - SEEK_SET for the start of the file, SEEK_CUR for the
ClementBreteau 1:f3f702086a30 82 * current file position, or SEEK_END for the end of the file.
ClementBreteau 1:f3f702086a30 83 *
ClementBreteau 1:f3f702086a30 84 * Returns
ClementBreteau 1:f3f702086a30 85 * New file position on success, -1 on failure or unsupported
ClementBreteau 1:f3f702086a30 86 */
ClementBreteau 1:f3f702086a30 87 virtual off_t lseek(off_t offset, int whence) = 0;
ClementBreteau 1:f3f702086a30 88
ClementBreteau 1:f3f702086a30 89 /* Function fsync
ClementBreteau 1:f3f702086a30 90 * Flush any buffers associated with the FileHandle, ensuring it
ClementBreteau 1:f3f702086a30 91 * is up to date on disk
ClementBreteau 1:f3f702086a30 92 *
ClementBreteau 1:f3f702086a30 93 * Returns
ClementBreteau 1:f3f702086a30 94 * 0 on success or un-needed, -1 on error
ClementBreteau 1:f3f702086a30 95 */
ClementBreteau 1:f3f702086a30 96 virtual int fsync() = 0;
ClementBreteau 1:f3f702086a30 97
ClementBreteau 1:f3f702086a30 98 virtual off_t flen() {
ClementBreteau 1:f3f702086a30 99 /* remember our current position */
ClementBreteau 1:f3f702086a30 100 off_t pos = lseek(0, SEEK_CUR);
ClementBreteau 1:f3f702086a30 101 if(pos == -1) return -1;
ClementBreteau 1:f3f702086a30 102 /* seek to the end to get the file length */
ClementBreteau 1:f3f702086a30 103 off_t res = lseek(0, SEEK_END);
ClementBreteau 1:f3f702086a30 104 /* return to our old position */
ClementBreteau 1:f3f702086a30 105 lseek(pos, SEEK_SET);
ClementBreteau 1:f3f702086a30 106 return res;
ClementBreteau 1:f3f702086a30 107 }
ClementBreteau 1:f3f702086a30 108
ClementBreteau 1:f3f702086a30 109 };
ClementBreteau 1:f3f702086a30 110
ClementBreteau 1:f3f702086a30 111 } // namespace mbed
ClementBreteau 1:f3f702086a30 112
ClementBreteau 1:f3f702086a30 113 #endif
ClementBreteau 1:f3f702086a30 114