P2P Transmitter
Loading...
Searching...
No Matches
packet.h
Go to the documentation of this file.
1#ifndef P2P_TRANSMITTER_PACKET_H
2#define P2P_TRANSMITTER_PACKET_H
3
4#include <stdint.h>
5#include <stdlib.h>
6#include <stdbool.h>
7
11
12// Byte struct representing a single byte in the linked list
13typedef struct Byte {
14 uint8_t value;
15 struct Byte* next;
16 struct Byte* previous;
17} Byte;
18
19// Packet struct representing a sequence of bytes
20typedef struct Packet {
22 int length;
23
26 uint8_t header;
27
32
34 bool parity;
35} Packet;
36
40Byte* toByte(char c);
41
45
48Packet* createRetransmitPacket(uint8_t identifier);
49
53Packet* toPacket(char* s);
54
59
63uint8_t getPacketID(Packet* p);
64
68bool getPacketRT(Packet* p);
69
73void setPacketID(Packet* p, uint8_t id);
74
78// Packet* createCachedPacket(uint8_t* data, int length);
79
83void packetAppendByte(Packet* p, Byte* b);
84
85// Conversion functions
86// uint8_t* packetToArray(Packet* p);
87// Packet* arrayToPacket(uint8_t* data, int length);
88
91// void sendPacket(uint8_t* data, int length);
94// void retransmit(uint8_t id);
95
98void printByte(Byte* b);
99
102void printPacket(Packet* p);
103
104// Memory Handling
107void freePacket(Packet* p);
108
109#endif // P2P_TRANSMITTER_PACKET_H
void freePacket(Packet *p)
Free the memory reserved for the packet and all contained bytes.
Definition packet.c:140
Packet * createRetransmitPacket(uint8_t identifier)
Creates a Packet requesting that the peer retransmit the cached Packet with the specified identifier.
Definition packet.c:36
Packet * byteToPacket(Byte *b)
Creates a Packet structure containing the provided Byte.
Definition packet.c:67
Packet * toPacket(char *s)
Converts a char* string to a Packet containing one Byte per char.
Definition packet.c:42
void printByte(Byte *b)
Sending and retransmitting.
Definition packet.c:108
bool getPacketRT(Packet *p)
Checks the header field to determine if the specified Packet ID should be retransmitted.
Definition packet.c:82
void packetAppendByte(Packet *p, Byte *b)
Creates a Packet to be stored within the PacketCache.
Definition packet.c:91
void setPacketID(Packet *p, uint8_t id)
Sets the Packet Identifier within the header field.
Definition packet.c:86
Byte * toByte(char c)
Converts a character to a Byte struct (linked list node)
Definition packet.c:8
void printPacket(Packet *p)
Display the bytes contained within the packet and their ASCII representation.
Definition packet.c:116
uint8_t getPacketID(Packet *p)
Extracts the Packet Identifier from the header field.
Definition packet.c:77
Packet * createPacket()
Creates a reserved, empty Packet struct instance.
Definition packet.c:21
Definition packet.h:13
Definition packet.h:20
bool parity
Boolean used for even parity implementation.
Definition packet.h:34
Byte * lastByte
The last Byte contained within the Linked List, used for reverse traversal.
Definition packet.h:31
int length
Number of contained Bytes within the Packet. This value is not reliable and must be updated in any cu...
Definition packet.h:22
uint8_t header
4-bit Packet header
Definition packet.h:26
Byte * firstByte
The first Byte contained within the Linked List, used for forward traversal.
Definition packet.h:29