![](/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
Translator.h
- Committer:
- katrijnverhasselt
- Date:
- 2016-05-18
- Revision:
- 0:b40341017545
- Child:
- 2:2330ad8b1baa
File content as of revision 0:b40341017545:
#pragma once #include <string> #include "mbed.h" #include "Utility.h" // Implements the Data-Link layer, translating a raw message to MessageInfo and back class Translator { public: // Contains easy retreivable message info struct MessageInfo { enum ECommandType { NONE, READ, WRITE, OPTION, ERROR } CommandType; int Channel; //Not used int DacValue; MessageInfo(); // Function to more easily check CommandType bool IsNone(); bool IsRead(); bool IsWrite(); bool IsOption(); }; private: // Contains the raw message in bytes const int8_t* _rawMessage; // Size of the raw message int _size; // Message info, is populated in SetRawMessage MessageInfo _message; public: // Contains rules about how the raw message is formatted struct Rules { static int StartCharIndex; static int8_t StartChar; static int CharsToReadIndex; static int CharsToReadOffset; static int rwoIndex; static int8_t ReadChar; static int8_t WriteChar; static int8_t OptionChar; static int8_t ErrorChar; //static int ChannelIndex; static int DataIndex; static int DataLength; static int ReadCmdSize; static int WriteCmdSize; static int ErrorCmdSize; }; private: // Private constructor: no class instance allowed Translator(); public: // <Handig om weten: dit is een NULL ('\0') terminated character array dat terug wordt gegeven. // Dit is nodig omdat printf("%s", cmd) niet kan weten hoe lang de array is en zal simpelweg // blijven lezen tot het toevallig een NULL karakter tegenkomt. // cmdSize geeft de grootte van de pointer ZONDER het null karakter zodat het zowel veilig // kan gebruikt worden in printf en andere functies die geen null karakter vereisen (en waarbij // dus het NULL karakter niet zal ingelezen worden> // Translate MessageInfo to raw int8_t* (NULL terminated) static bool Translate(MessageInfo info, int8_t** const cmd, int* const cmdSize); // <Hier bijvoorbeeld is het NULL karakter niet vereist omdat de grootte wordt opgevraagt // Indien de int8_t* van vorige functie hier terug wordt in gezet volstaat het om ook zijn // cmdSize te gebruiken: het NULL karakter valt hier buiten en wordt daarom dus niet gelezen // Dit zal ik toevoegen aan de ondervonden problemen.> // Translate raw int8_t* message to MessageInfo static bool Translate(const int8_t* const cmd, int cmdSize, MessageInfo* const info); private: void SetMessageInfo(); void ResetMessageInfo(); void InvalidateMessage(); };