-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.h
62 lines (53 loc) · 1.54 KB
/
lib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef _LIB_H_
#define _LIB_H_
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#define MAX_TOPIC 50
#define MAX_PAYLOAD 1500
#define MAX_ID 10
#define DIE(assertion, call_description) \
do { \
if (assertion) { \
fprintf(stderr, "(%s, %d): ", __FILE__, __LINE__); \
perror(call_description); \
exit(EXIT_FAILURE); \
} \
} while (0)
/* Structure for the messages received from udp clients */
struct udp_packet {
char topic[MAX_TOPIC];
uint8_t type;
unsigned char payload[MAX_PAYLOAD];
};
/* Structure with data received by UDP client */
struct msg_udp {
char ip[16];
uint16_t port;
char topic[MAX_TOPIC];
uint8_t type;
unsigned char payload[MAX_PAYLOAD];
};
/* Structure for the messages for TCP */
/* Type:
1 -> subscribe to topic
2 -> unsubscribe from a topic
3 -> UDP message
4 -> exit
*/
struct tcp_packet {
uint16_t len;
uint8_t type;
char message[sizeof(struct msg_udp)];
};
/* Structure with data for subscribe */
struct msg_subscribe {
char topic[MAX_TOPIC];
int sf;
};
/* Structure with data for unsubscribe */
struct msg_unsubscribe {
char topic[MAX_TOPIC];
};
#endif /* _LIB_H_ */