HeptaCamera&GPS Library

Dependents:   Lab9-01_All_transmit Lab9-03_Thermal_chamber Final_Magnetism_measurement_GPS_data_saving LaserCommProtocol_01 ... more

Fork of HeptaCamera_GPS by CLTP 8

Committer:
HEPTA
Date:
Tue Nov 05 07:08:17 2019 +0000
Revision:
27:bf29ef2b3c76
Parent:
0:5a6468b4164d
Compatible with south latitude and west longitude

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sunifu 0:5a6468b4164d 1 #ifndef _SERIAL_BUFFERED_H_
sunifu 0:5a6468b4164d 2 #define _SERIAL_BUFFERED_H_
sunifu 0:5a6468b4164d 3
sunifu 0:5a6468b4164d 4 /**
sunifu 0:5a6468b4164d 5 * Buffered serial class.
sunifu 0:5a6468b4164d 6 */
sunifu 0:5a6468b4164d 7 class SerialBuffered : public Serial {
sunifu 0:5a6468b4164d 8 public:
sunifu 0:5a6468b4164d 9 /**
sunifu 0:5a6468b4164d 10 * Create a buffered serial class.
sunifu 0:5a6468b4164d 11 *
sunifu 0:5a6468b4164d 12 * @param tx A pin for transmit.
sunifu 0:5a6468b4164d 13 * @param rx A pin for receive.
sunifu 0:5a6468b4164d 14 */
sunifu 0:5a6468b4164d 15 SerialBuffered(PinName tx, PinName rx);
sunifu 0:5a6468b4164d 16
sunifu 0:5a6468b4164d 17 /**
sunifu 0:5a6468b4164d 18 * Destroy.
sunifu 0:5a6468b4164d 19 */
sunifu 0:5a6468b4164d 20 virtual ~SerialBuffered();
sunifu 0:5a6468b4164d 21
sunifu 0:5a6468b4164d 22 /**
sunifu 0:5a6468b4164d 23 * Get a character.
sunifu 0:5a6468b4164d 24 *
sunifu 0:5a6468b4164d 25 * @return A character. (-1:timeout)
sunifu 0:5a6468b4164d 26 */
sunifu 0:5a6468b4164d 27 int getc();
sunifu 0:5a6468b4164d 28
sunifu 0:5a6468b4164d 29 /**
sunifu 0:5a6468b4164d 30 * Returns 1 if there is a character available to read, 0 otherwise.
sunifu 0:5a6468b4164d 31 */
sunifu 0:5a6468b4164d 32 int readable();
sunifu 0:5a6468b4164d 33
sunifu 0:5a6468b4164d 34 /**
sunifu 0:5a6468b4164d 35 * Set timeout for getc().
sunifu 0:5a6468b4164d 36 *
sunifu 0:5a6468b4164d 37 * @param ms milliseconds. (-1:Disable timeout)
sunifu 0:5a6468b4164d 38 */
sunifu 0:5a6468b4164d 39 void setTimeout(int ms);
sunifu 0:5a6468b4164d 40
sunifu 0:5a6468b4164d 41 /**
sunifu 0:5a6468b4164d 42 * Read requested bytes.
sunifu 0:5a6468b4164d 43 *
sunifu 0:5a6468b4164d 44 * @param bytes A pointer to a buffer.
sunifu 0:5a6468b4164d 45 * @param requested Length.
sunifu 0:5a6468b4164d 46 *
sunifu 0:5a6468b4164d 47 * @return Readed byte length.
sunifu 0:5a6468b4164d 48 */
sunifu 0:5a6468b4164d 49 size_t readBytes(uint8_t *bytes, size_t requested);
sunifu 0:5a6468b4164d 50
sunifu 0:5a6468b4164d 51 void _baud(int b);
sunifu 0:5a6468b4164d 52 private:
sunifu 0:5a6468b4164d 53 void handleInterrupt();
sunifu 0:5a6468b4164d 54 static const int BUFFERSIZE = 4096;
sunifu 0:5a6468b4164d 55 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
sunifu 0:5a6468b4164d 56 uint16_t indexContentStart; // index of first bytes of content
sunifu 0:5a6468b4164d 57 uint16_t indexContentEnd; // index of bytes after last byte of content
sunifu 0:5a6468b4164d 58 int timeout;
sunifu 0:5a6468b4164d 59 Timer timer;
sunifu 0:5a6468b4164d 60 };
sunifu 0:5a6468b4164d 61
sunifu 0:5a6468b4164d 62 #endif