aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends/sacn.h
blob: 7af2a36af6d815c2a1237e1a23d9eccb8b3605a9 (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "midimonster.h"

int init();
static int sacn_configure(char* option, char* value);
static int sacn_configure_instance(instance* instance, char* option, char* value);
static instance* sacn_instance();
static channel* sacn_channel(instance* instance, char* spec);
static int sacn_set(instance* inst, size_t num, channel** c, channel_value* v);
static int sacn_handle(size_t num, managed_fd* fds);
static int sacn_start();
static int sacn_shutdown();

#define SACN_PORT "5568"
#define SACN_RECV_BUF 8192
#define SACN_KEEPALIVE_INTERVAL 2000
#define SACN_DISCOVERY_TIMEOUT 9000
#define SACN_PDU_MAGIC "ASC-E1.17\0\0\0"

#define MAP_COARSE 0x0200
#define MAP_FINE 0x0400
#define MAP_SINGLE 0x0800
#define MAP_MARK 0x1000
#define MAPPED_CHANNEL(a) ((a) & 0x01FF)
#define IS_ACTIVE(a) ((a) & 0xFE00)
#define IS_WIDE(a) ((a) & (MAP_FINE | MAP_COARSE))
#define IS_SINGLE(a) ((a) & MAP_SINGLE)

typedef struct /*_sacn_universe_model*/ {
	uint8_t last_priority;
	uint8_t last_seq;
	uint8_t in[512];
	uint8_t out[512];
	uint16_t map[512];
} sacn_universe;

typedef struct /*_sacn_instance_model*/ {
	uint16_t uni;
	uint8_t xmit_prio;
	uint8_t cid_filter[16];
	uint8_t filter_enabled;
	uint8_t unicast_input;
	struct sockaddr_storage dest_addr;
	socklen_t dest_len;
	sacn_universe data;
	size_t fd_index;
} sacn_instance_data;

typedef union /*_sacn_instance_id*/ {
	struct {
		uint16_t fd_index;
		uint16_t uni;
		uint8_t pad[4];
	} fields;
	uint64_t label;
} sacn_instance_id;

typedef struct /*_sacn_socket*/ {
	int fd;
	uint8_t flags;
	size_t universes;
	uint16_t* universe;
	uint64_t* last_frame;
} sacn_fd;

#pragma pack(push, 1)
typedef struct /*_sacn_frame_root*/ {
	uint16_t preamble_size;
	uint16_t postamble_size;
	uint8_t magic[12];
	uint16_t flags;
	uint32_t vector;
	uint8_t sender_cid[16];
	//framing
	uint16_t frame_flags;
	uint32_t frame_vector;
} sacn_frame_root;

typedef struct /*_sacn_frame_data*/ {
	//framing
	uint8_t source_name[64];
	uint8_t priority;
	uint16_t sync_addr;
	uint8_t sequence;
	uint8_t options;
	uint16_t universe;
	//dmp
	uint16_t flags;
	uint8_t vector;
	uint8_t format;
	uint16_t startcode_offset;
	uint16_t address_increment;
	uint16_t channels;
	uint8_t data[513];
} sacn_frame_data;

typedef struct /*_sacn_frame_discovery*/ {
	//framing
	uint8_t source_name[64];
	uint32_t reserved;
	//universe discovery
	uint16_t flags;
	uint32_t vector;
	uint8_t page;
	uint8_t max_page;
	uint16_t data[512];
} sacn_frame_discovery;

typedef struct /*_sacn_xmit_data*/ {
	sacn_frame_root root;
	sacn_frame_data data;
} sacn_data_pdu;

typedef struct /*_sacn_xmit_discovery*/ {
	sacn_frame_root root;
	sacn_frame_discovery data;
} sacn_discovery_pdu;
#pragma pack(pop)

#define ROOT_E131_DATA 0x4
#define FRAME_E131_DATA 0x2
#define DMP_SET_PROPERTY 0x2

#define ROOT_E131_EXTENDED 0x8
#define FRAME_E131_DISCOVERY 0x2
#define DISCOVERY_UNIVERSE_LIST 0x1