Lab3_Surveillance

Dependencies:   GPS mbed

Committer:
gtg846r
Date:
Thu Oct 13 05:48:32 2011 +0000
Revision:
0:2af1e48a285d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gtg846r 0:2af1e48a285d 1 /**
gtg846r 0:2af1e48a285d 2 * =============================================================================
gtg846r 0:2af1e48a285d 3 * LS-Y201 device driver class (Version 0.0.1)
gtg846r 0:2af1e48a285d 4 * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
gtg846r 0:2af1e48a285d 5 * January 2010
gtg846r 0:2af1e48a285d 6 * =============================================================================
gtg846r 0:2af1e48a285d 7 * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
gtg846r 0:2af1e48a285d 8 *
gtg846r 0:2af1e48a285d 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
gtg846r 0:2af1e48a285d 10 * of this software and associated documentation files (the "Software"), to deal
gtg846r 0:2af1e48a285d 11 * in the Software without restriction, including without limitation the rights
gtg846r 0:2af1e48a285d 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
gtg846r 0:2af1e48a285d 13 * copies of the Software, and to permit persons to whom the Software is
gtg846r 0:2af1e48a285d 14 * furnished to do so, subject to the following conditions:
gtg846r 0:2af1e48a285d 15 *
gtg846r 0:2af1e48a285d 16 * The above copyright notice and this permission notice shall be included in
gtg846r 0:2af1e48a285d 17 * all copies or substantial portions of the Software.
gtg846r 0:2af1e48a285d 18 *
gtg846r 0:2af1e48a285d 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
gtg846r 0:2af1e48a285d 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
gtg846r 0:2af1e48a285d 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
gtg846r 0:2af1e48a285d 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
gtg846r 0:2af1e48a285d 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gtg846r 0:2af1e48a285d 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
gtg846r 0:2af1e48a285d 25 * THE SOFTWARE.
gtg846r 0:2af1e48a285d 26 * =============================================================================
gtg846r 0:2af1e48a285d 27 */
gtg846r 0:2af1e48a285d 28
gtg846r 0:2af1e48a285d 29 #ifndef _SERIAL_BUFFERED_H_
gtg846r 0:2af1e48a285d 30 #define _SERIAL_BUFFERED_H_
gtg846r 0:2af1e48a285d 31
gtg846r 0:2af1e48a285d 32 /**
gtg846r 0:2af1e48a285d 33 * Buffered serial class.
gtg846r 0:2af1e48a285d 34 */
gtg846r 0:2af1e48a285d 35 class SerialBuffered : public Serial {
gtg846r 0:2af1e48a285d 36 public:
gtg846r 0:2af1e48a285d 37 /**
gtg846r 0:2af1e48a285d 38 * Create a buffered serial class.
gtg846r 0:2af1e48a285d 39 *
gtg846r 0:2af1e48a285d 40 * @param tx A pin for transmit.
gtg846r 0:2af1e48a285d 41 * @param rx A pin for receive.
gtg846r 0:2af1e48a285d 42 */
gtg846r 0:2af1e48a285d 43 SerialBuffered(PinName tx, PinName rx);
gtg846r 0:2af1e48a285d 44
gtg846r 0:2af1e48a285d 45 /**
gtg846r 0:2af1e48a285d 46 * Destroy.
gtg846r 0:2af1e48a285d 47 */
gtg846r 0:2af1e48a285d 48 virtual ~SerialBuffered();
gtg846r 0:2af1e48a285d 49
gtg846r 0:2af1e48a285d 50 /**
gtg846r 0:2af1e48a285d 51 * Get a character.
gtg846r 0:2af1e48a285d 52 *
gtg846r 0:2af1e48a285d 53 * @return A character. (-1:timeout)
gtg846r 0:2af1e48a285d 54 */
gtg846r 0:2af1e48a285d 55 int getc();
gtg846r 0:2af1e48a285d 56
gtg846r 0:2af1e48a285d 57 /**
gtg846r 0:2af1e48a285d 58 * Returns 1 if there is a character available to read, 0 otherwise.
gtg846r 0:2af1e48a285d 59 */
gtg846r 0:2af1e48a285d 60 int readable();
gtg846r 0:2af1e48a285d 61
gtg846r 0:2af1e48a285d 62 /**
gtg846r 0:2af1e48a285d 63 * Set timeout for getc().
gtg846r 0:2af1e48a285d 64 *
gtg846r 0:2af1e48a285d 65 * @param ms milliseconds. (-1:Disable timeout)
gtg846r 0:2af1e48a285d 66 */
gtg846r 0:2af1e48a285d 67 void setTimeout(int ms);
gtg846r 0:2af1e48a285d 68
gtg846r 0:2af1e48a285d 69 /**
gtg846r 0:2af1e48a285d 70 * Read requested bytes.
gtg846r 0:2af1e48a285d 71 *
gtg846r 0:2af1e48a285d 72 * @param bytes A pointer to a buffer.
gtg846r 0:2af1e48a285d 73 * @param requested Length.
gtg846r 0:2af1e48a285d 74 *
gtg846r 0:2af1e48a285d 75 * @return Readed byte length.
gtg846r 0:2af1e48a285d 76 */
gtg846r 0:2af1e48a285d 77 size_t readBytes(uint8_t *bytes, size_t requested);
gtg846r 0:2af1e48a285d 78
gtg846r 0:2af1e48a285d 79 private:
gtg846r 0:2af1e48a285d 80 void handleInterrupt();
gtg846r 0:2af1e48a285d 81 static const int BUFFERSIZE = 4096;
gtg846r 0:2af1e48a285d 82 uint8_t buffer[BUFFERSIZE]; // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end
gtg846r 0:2af1e48a285d 83 uint16_t indexContentStart; // index of first bytes of content
gtg846r 0:2af1e48a285d 84 uint16_t indexContentEnd; // index of bytes after last byte of content
gtg846r 0:2af1e48a285d 85 int timeout;
gtg846r 0:2af1e48a285d 86 Timer timer;
gtg846r 0:2af1e48a285d 87 };
gtg846r 0:2af1e48a285d 88
gtg846r 0:2af1e48a285d 89 #endif