![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Gets messages form the pc and translates it to I2C and back.
Dependencies: DevInterfaces I2Cinterfaces MCP4725 mbed
Diff: Reader.h
- Revision:
- 0:b40341017545
- Child:
- 2:2330ad8b1baa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Reader.h Wed May 18 11:22:41 2016 +0000 @@ -0,0 +1,42 @@ +#pragma once + +#include <string> +#include "mbed.h" +#include "Translator.h" + +// Reads the input buffer and notifies when a new message is ready +class Reader { + +private: + // PC interaction object + Serial pc; + + static const int _maxSize = 255+2; + bool _isNewMessageReceived; // set to true if a complete message was read + Translator::MessageInfo _lastMessageInfo; + int8_t _lastMessage[_maxSize]; // last complete message received + int _lastMessageSize; // size of last complete message received + int8_t _buffer[_maxSize]; // temporary storage while reading a message + int _bufferSize; // size of the buffer + + int8_t _lastChar; // last byte read + bool _isMessageStarted; // starting character was received + int _charsToRead; // number of characters to read + int _index; // current number of characters read + +public: + // Default constructor, attaches a callback to pc + Reader(); + + // Returns true once if a complete message was read + bool IsNewMessageReceived(); + Translator::MessageInfo GetLastMessageInfo() const; + // Returns the last message (without header) + const int8_t* GetLastMessage() const; + // Returns the size of the last message + int GetLastMessageSize() const; + +private: + // Function to be attached to pc + void pcCallback(); +}; \ No newline at end of file