-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.h
94 lines (79 loc) · 1.89 KB
/
config.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef MSB_CONFIG
#define MSB_CONFIG
#include <stdbool.h>
#include <arpa/inet.h>
#include <cyaml/cyaml.h>
// Serial device file name size limit
#define SERIAL_FILE_NAME_LIMIT 100
// Minimum IP address string length
#define IP_MIN_LEN 6
enum serial_flow_control
{
// No flow control
SFC_NONE,
// Hardware flow control
SFC_HARDWARE
};
// Serial configuration
struct config_serial
{
// Device file
const char device[SERIAL_FILE_NAME_LIMIT + 1];
// Baudrate
unsigned int *baudrate;
// Flow control
enum serial_flow_control *flow;
// TX ring buffer capacity
unsigned int *tx_buffer_capacity;
};
// UDP remote host settings
struct config_udp_remote
{
// Remote host IP
char ip[INET_ADDRSTRLEN + 1];
// Remote host port
uint16_t port;
// Lock remote host (not change on the incoming packet) (optional, false by default)
bool *lock;
// Allow brodcast (optional, false by default)
bool *broadcast;
};
// UDP local settings
struct config_udp_local
{
// Local IP (optional, all interfaces by default)
char *ip;
// Local port (optional, 0 by default)
uint16_t *port;
};
// UDP settings
struct config_udp
{
// Remote host settings (optional, listen mode by default)
struct config_udp_remote *remote;
// Local settings (optional, 0 port by default)
struct config_udp_local *local;
};
// Configuration
struct config
{
// Serial configuration
struct config_serial serial;
// UDP configuration
struct config_udp udp;
};
/*
Load the user configuration.
Arguments:
config_file_path - a configuration file name.
Returns:
Pointer to the configuration structure, NULL if failed.
*/
struct config *config_load(const char *config_file_path);
/*
Free the configuration structure.
Arguments:
config_ptr - a pointer to the configuration structure.
*/
void config_free(const struct config *config_ptr);
#endif