Debian Codegraph @

interfaces/artnet/artnet.h

raw symbols SCIP
1 /*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * artnet.h
17 * Interface to libartnet
18 * Copyright (C) 2004-2007 Simon Newton
19 */
20
21 #ifndef ARTNET_HEADER_H
22 #define ARTNET_HEADER_H
23
24 #include <stdint.h>
25 // order is important here for osx
26 #include <sys/types.h>
27
28 #ifndef WIN32
29 #include <sys/select.h>
30 #else
31 #include <Winsock2.h>
32 typedef unsigned long in_addr_t;
33 #endif
34
35 #include <artnet/common.h>
36
37 /* the external storage class is "extern" in UNIX; in MSW it's ugly. */
38 #ifndef EXTERN
39 #ifdef MSW
40 #define EXTERN __declspec(dllexport) extern
41 #else
42 #define EXTERN extern
43 #endif /* MSW */
44 #endif
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 EXTERN int ARTNET_ADDRESS_NO_CHANGE;
51
52 /**
53 * An enum for setting the behaviour of a port.
54 * Ports can either input data (DMX -> ArtNet) or
55 * output (ArtNet -> DMX) data.
56 */
57 typedef enum {
58 ARTNET_ENABLE_INPUT = 0x40, /**< Enables the input for this port */
59 ARTNET_ENABLE_OUTPUT = 0x80 /**< Enables the output for this port */
60 } artnet_port_settings_t;
61
62
63 typedef enum {
64 ARTNET_PC_NONE = 0x00,
65 ARTNET_PC_CANCEL = 0x01,
66 ARTNET_PC_LED_NORMAL = 0x02,
67 ARTNET_PC_LED_MUTE = 0x03,
68 ARTNET_PC_LED_LOCATE = 0x04,
69 ARTNET_PC_RESET = 0x05,
70 ARTNET_PC_MERGE_LTP_O = 0x10,
71 ARTNET_PC_MERGE_LTP_1 = 0x11,
72 ARTNET_PC_MERGE_LTP_2 = 0x12,
73 ARTNET_PC_MERGE_LTP_3 = 0x13,
74 ARTNET_PC_MERGE_HTP_0 = 0x50,
75 ARTNET_PC_MERGE_HTP_1 = 0x51,
76 ARTNET_PC_MERGE_HTP_2 = 0x52,
77 ARTNET_PC_MERGE_HTP_3 = 0x53,
78 ARTNET_PC_CLR_0 = 0x93,
79 ARTNET_PC_CLR_1 = 0x93,
80 ARTNET_PC_CLR_2 = 0x93,
81 ARTNET_PC_CLR_3 = 0x93,
82 } artnet_port_command_t;
83
84
85 /*
86 * An enum for the type of data transmitted on a port.
87 * As far as I know, only DMX-512 is supported
88 */
89 typedef enum {
90 ARTNET_PORT_DMX = 0x00, /**< Data is DMX-512 */
91 ARTNET_PORT_MIDI = 0x01, /**< Data is MIDI */
92 ARTNET_PORT_AVAB = 0x02, /**< Data is Avab */
93 ARTNET_PORT_CMX = 0x03, /**< Data is Colortran CMX */
94 ARTNET_PORT_ADB = 0x04, /**< Data is ABD 62.5 */
95 ARTNET_PORT_ARTNET = 0x05 /**< Data is ArtNet */
96 } artnet_port_data_code;
97
98
99 // defines the status of the firmware transfer
100 typedef enum {
101 ARTNET_FIRMWARE_BLOCKGOOD = 0x00,
102 ARTNET_FIRMWARE_ALLGOOD = 0x01,
103 ARTNET_FIRMWARE_FAIL = 0xff,
104 } artnet_firmware_status_code;
105
106 // tod actions
107 typedef enum {
108 ARTNET_TOD_FULL = 0x00,
109 ARTNET_TOD_FLUSH = 0x01,
110 } artnet_tod_command_code;
111
112
113 /**
114 * An enum for refering to a particular input or output port.
115 */
116 typedef enum {
117 ARTNET_INPUT_PORT = 1, /**< The input port */
118 ARTNET_OUTPUT_PORT, /**< The output port */
119 } artnet_port_dir_t;
120
121
122 /*
123 * Enum describing the type of node
124 */
125 typedef enum {
126 ARTNET_SRV, /**< An ArtNet server (transmitts DMX data) */
127 ARTNET_NODE, /**< An ArtNet node (dmx reciever) */
128 ARTNET_MSRV, /**< A Media Server */
129 ARTNET_ROUTE, /**< No Effect currently */
130 ARTNET_BACKUP, /**< No Effect currently */
131 ARTNET_RAW /**< Raw Node - used for diagnostics */
132 } artnet_node_type;
133
134
135 /*
136 * Enum for the talk-to-me value
137 * These values can be &'ed togeather, so for example to set private replies
138 * and auto replying use :
139 * (ARTNET_TTM_PRIVATE & ARTNET_TTM_AUTO)
140 */
141 typedef enum {
142 ARTNET_TTM_DEFAULT = 0xFF, /**< default, ArtPollReplies are broadcast, and nodes won't send a ArtPollReply when conditions change */
143 ARTNET_TTM_PRIVATE = 0xFE, /**< ArtPollReplies aren't broadcast */
144 ARTNET_TTM_AUTO = 0xFD /**< ArtPollReplies are send when node conditions chang */
145 } artnet_ttm_value_t;
146
147 /**
148 * Enums for the application defined handlers
149 */
150 typedef enum {
151 ARTNET_RECV_HANDLER, /**< Called on reciept of any ArtNet packet */
152 ARTNET_SEND_HANDLER, /**< Called on transmission of any ArtNet packet */
153 ARTNET_POLL_HANDLER, /**< Called on reciept of an ArtPoll packet */
154 ARTNET_REPLY_HANDLER, /**< Called on reciept of an ArtPollReply packet */
155 ARTNET_DMX_HANDLER, /**< Called on reciept of an ArtDMX packet */
156 ARTNET_ADDRESS_HANDLER, /**< Called on reciept of an ArtAddress packet */
157 ARTNET_INPUT_HANDLER, /**< Called on reciept of an ArtInput packet */
158 ARTNET_TOD_REQUEST_HANDLER, /**< Called on reciept of an ArtTodRequest packet */
159 ARTNET_TOD_DATA_HANDLER, /**< Called on reciept of an ArtTodData packet */
160 ARTNET_TOD_CONTROL_HANDLER, /**< Called on reciept of an ArtTodControl packet */
161 ARTNET_RDM_HANDLER, /**< Called on reciept of an ArtRdm packet */
162 ARTNET_IPPROG_HANDLER, /**< Called on reciept of an ArtIPProg packet */
163 ARTNET_FIRMWARE_HANDLER, /**< Called on reciept of an ArtFirmware packet */
164 ARTNET_FIRMWARE_REPLY_HANDLER, /**< Called on reciept of an ArtFirmwareReply packet */
165 } artnet_handler_name_t;
166
167
168 /*
169 * Describes a remote ArtNet node that has been discovered
170 */
171 typedef struct artnet_node_entry_s {
172 uint8_t ip[ARTNET_IP_SIZE]; /**< The IP address, Network byte ordered*/
173 int16_t ver; /**< The firmware version */
174 int16_t sub; /**< The subnet address */
175 int16_t oem; /**< The OEM value */
176 uint8_t ubea; /**< The UBEA version */
177 uint8_t status;
178 uint8_t etsaman[ARTNET_ESTA_SIZE]; /**< The ESTA Manufacturer code */
179 uint8_t shortname[ARTNET_SHORT_NAME_LENGTH]; /**< The short node name */
180 uint8_t longname[ARTNET_LONG_NAME_LENGTH]; /**< The long node name */
181 uint8_t nodereport[ARTNET_REPORT_LENGTH]; /**< The node report */
182 int16_t numbports; /**< The number of ports */
183 uint8_t porttypes[ARTNET_MAX_PORTS]; /**< The type of ports */
184 uint8_t goodinput[ARTNET_MAX_PORTS];
185 uint8_t goodoutput[ARTNET_MAX_PORTS];
186 uint8_t swin[ARTNET_MAX_PORTS];
187 uint8_t swout[ARTNET_MAX_PORTS];
188 uint8_t swvideo;
189 uint8_t swmacro;
190 uint8_t swremote;
191 uint8_t style;
192 uint8_t mac[ARTNET_MAC_SIZE]; /**< The MAC address of the node */
193 } artnet_node_entry_t;
194
195 /** A pointer to an artnet_node_entry_t */
196 typedef artnet_node_entry_t *artnet_node_entry;
197
198 typedef struct {
199 char short_name[ARTNET_SHORT_NAME_LENGTH];
200 char long_name[ARTNET_LONG_NAME_LENGTH];
201 uint8_t subnet;
202 uint8_t in_ports[ARTNET_MAX_PORTS];
203 uint8_t out_ports[ARTNET_MAX_PORTS];
204 } artnet_node_config_t;
205
206
207 /** The local ArtNet node */
208 typedef void *artnet_node;
209
210 /** A list of remote ArtNet nodes */
211 typedef void *artnet_node_list;
212
213 // node control functions
214 EXTERN artnet_node artnet_new(const char *ip, int verbose);
215 EXTERN int artnet_setoem(artnet_node vn, uint8_t hi, uint8_t lo);
216 EXTERN int artnet_setesta(artnet_node vn, char hi, char lo);
217 EXTERN int artnet_set_bcast_limit(artnet_node vn, int limit);
218 EXTERN int artnet_start(artnet_node n);
219 EXTERN int artnet_read(artnet_node n, int timeout);
220 EXTERN int artnet_stop(artnet_node n);
221 EXTERN int artnet_destroy(artnet_node n);
222
223 int artnet_join(artnet_node vn1, artnet_node vn2);
224
225 // handler functions
226 // these need to be cleaned up into a generic interface
227 EXTERN int artnet_set_handler(artnet_node vn,
228 artnet_handler_name_t handler,
229 int (*fh)(artnet_node n, void *pp, void *d),
230 void* data);
231 EXTERN int artnet_set_dmx_handler(artnet_node vn,
232 int (*fh)(artnet_node n, int port, void *d),
233 void *data);
234 EXTERN int artnet_set_program_handler(artnet_node vn,
235 int (*fh)(artnet_node n, void *d),
236 void *data);
237 EXTERN int artnet_set_firmware_handler(artnet_node vn,
238 int (*fh)(artnet_node n, int ubea, uint16_t *data, int length, void *d),
239 void *data);
240 EXTERN int artnet_set_rdm_handler(artnet_node vn,
241 int (*fh)(artnet_node n, int address, uint8_t *rdm, int length, void *d),
242 void *data);
243 EXTERN int artnet_set_rdm_initiate_handler(artnet_node vn,
244 int (*fh)(artnet_node n, int port, void *d),
245 void *data);
246 EXTERN int artnet_set_rdm_tod_handler(artnet_node vn,
247 int (*fh)(artnet_node n, int port, void *d),
248 void *data);
249
250 // send functions
251 EXTERN int artnet_send_poll(artnet_node n,
252 const char *ip,
253 artnet_ttm_value_t talk_to_me);
254 EXTERN int artnet_send_poll_reply(artnet_node n);
255 EXTERN int artnet_send_dmx(artnet_node n,
256 int port_id,
257 int16_t length,
258 const uint8_t *data);
259 EXTERN int artnet_raw_send_dmx(artnet_node vn,
260 uint8_t uni,
261 int16_t length,
262 const uint8_t *data);
263 EXTERN int artnet_send_address(artnet_node n,
264 artnet_node_entry e,
265 const char *shortName,
266 const char *longName,
267 uint8_t inAddr[ARTNET_MAX_PORTS],
268 uint8_t outAddr[ARTNET_MAX_PORTS],
269 uint8_t subAddr,
270 artnet_port_command_t cmd);
271 EXTERN int artnet_send_input(artnet_node n,
272 artnet_node_entry e,
273 uint8_t settings[ARTNET_MAX_PORTS]);
274 EXTERN int artnet_send_firmware(artnet_node vn,
275 artnet_node_entry e,
276 int ubea,
277 uint16_t *data,
278 int length,
279 int (*fh)(artnet_node n, artnet_firmware_status_code code, void *d),
280 void *user_data);
281 EXTERN int artnet_send_firmware_reply(artnet_node vn,
282 artnet_node_entry e,
283 artnet_firmware_status_code code);
284
285 // rdm functions
286 EXTERN int artnet_send_tod_request(artnet_node vn);
287 EXTERN int artnet_send_tod_control(artnet_node vn,
288 uint8_t address,
289 artnet_tod_command_code action);
290 EXTERN int artnet_send_tod_data(artnet_node vn, int port);
291 EXTERN int artnet_send_rdm(artnet_node vn,
292 uint8_t address,
293 uint8_t *data,
294 int length);
295 EXTERN int artnet_add_rdm_device(artnet_node vn,
296 int port,
297 uint8_t uid[ARTNET_RDM_UID_WIDTH]);
298 EXTERN int artnet_add_rdm_devices(artnet_node vn,
299 int port,
300 uint8_t *uid,
301 int count);
302 EXTERN int artnet_remove_rdm_device(artnet_node vn,
303 int port,
304 uint8_t uid[ARTNET_RDM_UID_WIDTH]);
305
306 // recv functions
307 EXTERN uint8_t *artnet_read_dmx(artnet_node n, int port_id, int *length);
308
309 // state changing functions
310 EXTERN int artnet_set_node_type(artnet_node n, artnet_node_type type);
311 EXTERN int artnet_set_short_name(artnet_node vn, const char *name);
312 EXTERN int artnet_set_long_name(artnet_node n, const char *name);
313
314 //port manipulation functions
315 EXTERN int artnet_set_port_type(artnet_node n,
316 int id,
317 artnet_port_settings_t settings,
318 artnet_port_data_code data);
319 EXTERN int artnet_set_port_addr(artnet_node n,
320 int id,
321 artnet_port_dir_t dir,
322 uint8_t addr);
323 EXTERN int artnet_set_subnet_addr(artnet_node n, uint8_t subnet);
324 EXTERN int artnet_get_universe_addr(artnet_node n,
325 int id,
326 artnet_port_dir_t dir);
327
328 //node list functions
329 EXTERN artnet_node_list artnet_get_nl(artnet_node n);
330 EXTERN artnet_node_entry artnet_nl_first(artnet_node_list nl);
331 EXTERN artnet_node_entry artnet_nl_next(artnet_node_list nl);
332 EXTERN int artnet_nl_get_length(artnet_node_list nl);
333
334 // misc
335 EXTERN int artnet_dump_config(artnet_node n);
336 EXTERN int artnet_get_config(artnet_node n, artnet_node_config_t *config);
337 EXTERN int artnet_get_sd(artnet_node n);
338 EXTERN int artnet_set_fdset(artnet_node vn, fd_set *fdset);
339
340 char *artnet_strerror();
341
342 #ifdef __cplusplus
343 }
344 #endif
345
346 #endif