37 #ifndef _TINY_PACKET_H_ 38 #define _TINY_PACKET_H_ 41 #include <HardwareSerial.h> 68 m_buf =
reinterpret_cast<uint8_t *
>(buf);
74 m_size = packet.m_size;
103 m_buf[m_len++] = byte;
113 put(static_cast<uint8_t>(chr));
122 m_buf[m_len++] = data & 0x00FF;
123 m_buf[m_len++] = data >> 8;
132 put((uint16_t)(data & 0x0000FFFF));
133 put((uint16_t)(data >> 16));
149 inline void put(
const char *str)
151 int room = m_size - m_len - 1;
153 int strSize =
static_cast<int>(strlen(str));
154 strncpy((
char *)&m_buf[m_len], str, room);
155 m_len += strSize < room ? strSize : room;
165 memcpy(&m_buf[m_len], pkt.m_buf, pkt.m_len);
193 uint16_t t = m_buf[m_p++];
194 return t | ((uint16_t)m_buf[m_p++] << 8);
221 char *p = (
char *)&m_buf[m_p];
222 m_p +=
static_cast<int>(strlen(p)) + 1;
250 return (
char *)m_buf;
259 return (
size_t)(m_len - m_p);
276 m_size = source.m_size;
277 m_buf = source.m_buf;
296 uint8_t *m_buf =
nullptr;
335 :
IPacket((char *)(new uint8_t[size]), size)
347 delete[](uint8_t *)
data();
HeapPacket(int size)
Creates packet with dynamically allocated buffer.
Definition: TinyPacket.h:334
ProtoLight class incapsulates Protocol functionality.
Definition: TinyLightProtocol.h:61
void put(char chr)
Puts next char to the packet.
Definition: TinyPacket.h:111
int16_t getInt16()
Reads next signed 16-bit integer from the packet.
Definition: TinyPacket.h:201
uint8_t getByte()
Reads next byte from the packet.
Definition: TinyPacket.h:173
void allocate(int bytes)
Allocates space inside the packet buffer, the next data will be written after allocated block...
Definition: TinyPacket.h:285
void put(const char *str)
Puts next null-terminated string to the packet.
Definition: TinyPacket.h:149
Describes packet entity and provides API methods to manipulate the packet.
Definition: TinyPacket.h:56
StaticPacket()
Creates IPacket instance with statically allocated buffer.
Definition: TinyPacket.h:314
void put(uint32_t data)
Puts next 32-bit unsigned integer to the packet.
Definition: TinyPacket.h:130
virtual ~IPacket()=default
Destroys the object.
void put(int16_t data)
Puts next 16-bit signed integer to the packet.
Definition: TinyPacket.h:140
uint16_t getUint16()
Reads next unsigned 16-bit integer from the packet.
Definition: TinyPacket.h:191
char getChar()
Reads next character from the packet.
Definition: TinyPacket.h:182
IPacket & operator=(const IPacket &source)
Assign operator doesn't copy the data from the source packet, but it copies only pointers.
Definition: TinyPacket.h:274
Class which allocated buffer for packet dynamically.
Definition: TinyPacket.h:327
IPacket(char *buf, int size)
Creates packet object.
Definition: TinyPacket.h:65
IFd class incapsulates Full Duplex Protocol functionality.
Definition: TinyProtocolFd.h:63
uint32_t getUint32()
Reads next unsigned 32-bit integer from the packet.
Definition: TinyPacket.h:210
int size() const
Returns size of payload data in the received packet.
Definition: TinyPacket.h:230
int maxSize() const
Returns maximum size of packet buffer.
Definition: TinyPacket.h:239
char * getString()
Reads zero-terminated string from the packet.
Definition: TinyPacket.h:219
Template class to create packet with static allocation of buffer Use this class for microcontrollers ...
Definition: TinyPacket.h:308
void clear()
Clears Packet state.
Definition: TinyPacket.h:90
uint8_t & operator[](int idx)
You may refer to Packet payload data directly by using operator [].
Definition: TinyPacket.h:265
void put(const IPacket &pkt)
Adds data from packet to the new packet being built.
Definition: TinyPacket.h:163
Definition: TinySerial.cpp:22
Hdlc class incapsulates hdlc Protocol functionality.
Definition: TinyProtocolHdlc.h:62
size_t availableBytes()
Returns size of remaining bytes (not yet accessed through get*()) in the received packet...
Definition: TinyPacket.h:257
Definition: TinyProtocol.h:59
void put(uint8_t byte)
Puts next byte to the packet.
Definition: TinyPacket.h:101
char * data() const
Returns pointer to payload data in the received packet.
Definition: TinyPacket.h:248
void put(uint16_t data)
Puts next 16-bit unsigned integer to the packet.
Definition: TinyPacket.h:120