| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /*
- * @file dataframe.h
- * @brief DataFrame interface
- *
- * @date: 31. 12. 2022
- * @author: juraj
- */
- #ifndef __DATAFRAME_H__
- #define __DATAFRAME_H__
- #include "stdint.h"
- #define HEADER_CHAR 0xCC
- /**
- * @brief Class for representing data frame.
- */
- class DataFrame{
- private:
- uint8_t *_frame;
- uint8_t _length;
- uint8_t _capacity;
- public:
- /**
- * Constructor.
- * @param frame pointer to existing byte array
- * @param size size of buffer `frame`
- */
- DataFrame(uint8_t *frame, uint8_t size);
- /**
- * @brief Initialize packet
- * - set the header of packet
- * - reserver 1st byte to length of frame
- */
- void Init(void);
- /**
- * @brief Add one byte to data frame.
- * @return true, if it is success
- */
- bool AddUint8(uint8_t d);
- /**
- * @brief add 2 Bytes length variable to dataframe
- * @param d variable added to data frame
- * @return true, if it is success
- */
- bool AddUint16(uint16_t d);
- /**
- * @brief add 4 Bytes long variable to dataframe
- * @param d variable added to data frame
- * @return true, if it is success
- */
- bool AddUint32(uint32_t);
- /**
- * @brief add one byte signed variable to data frame
- * @param d variable added to data frame
- * @return true, if it is success
- */
- bool AddInt8(int8_t d);
- /**
- * @brief add 2 bytes length signed variable to data frame
- * @param d variable added to data frame
- * @return true, if it is success
- */
- bool AddInt16(int16_t);
- /**
- * @brief add 4 bytes length signed variable to data frame
- * @param d variable added to data frame
- * @return true, if it is success
- */
- bool AddInt32(int32_t);
- /**
- * @brief add float value to data frame.
- * Float value is encoded to 4 bytes according IEEE 754
- * @param d variable added to data frame
- * @return true, if it is success
- */
- bool AddFloat(float);
- /**
- * @brief Commit the creation of the packet.
- * - add to second position (frame[1]) length of packet
- * - compute CRC of packet
- * @return real length of packet (including CRC byte)
- */
- uint8_t Commit(void);
- /**
- * @brief Return pointer to data frame.
- * @return resulting packet
- */
- uint8_t* GetFrame(void);
- };
- #ifdef __cplusplus
- extern "C" {
- #endif
- uint8_t crc8(uint8_t crc, uint8_t Size, uint8_t *Buffer);
- #ifdef __cplusplus
- }
- #endif
- #endif /* DATAFRAME_H_ */
|