| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#if HAVE_CONFIG_H |
| 22 |
# include <config.h> |
| 23 |
#endif |
| 24 |
|
| 25 |
#ifndef WIN32 |
| 26 |
#include <sys/socket.h> |
| 27 |
#include <netinet/in.h> |
| 28 |
#include <arpa/inet.h> |
| 29 |
#endif |
| 30 |
|
| 31 |
#include <string.h> |
| 32 |
#include <stdlib.h> |
| 33 |
#include <time.h> |
| 34 |
#include <stdio.h> |
| 35 |
|
| 36 |
#include "artnet.h" |
| 37 |
#include "artnet/packets.h" |
| 38 |
#include "misc.h" |
| 39 |
#include "tod.h" |
| 40 |
|
| 41 |
#ifndef ARTNET_PRIVATE_H |
| 42 |
#define ARTNET_PRIVATE_H |
| 43 |
|
| 44 |
|
| 45 |
extern int ARTNET_PORT; |
| 46 |
extern char ARTNET_STRING[]; |
| 47 |
extern int ARTNET_STRING_SIZE; |
| 48 |
extern uint8_t ARTNET_VERSION; |
| 49 |
extern uint8_t OEM_HI; |
| 50 |
extern uint8_t OEM_LO; |
| 51 |
extern char ESTA_HI; |
| 52 |
extern char ESTA_LO; |
| 53 |
extern uint8_t TTM_BEHAVIOUR_MASK; |
| 54 |
extern uint8_t TTM_REPLY_MASK; |
| 55 |
extern uint8_t PROGRAM_NO_CHANGE; |
| 56 |
extern uint8_t PROGRAM_DEFAULTS; |
| 57 |
extern uint8_t PROGRAM_CHANGE_MASK; |
| 58 |
extern uint8_t HIGH_NIBBLE; |
| 59 |
extern uint8_t LOW_NIBBLE; |
| 60 |
extern uint8_t STATUS_PROG_AUTH_MASK; |
| 61 |
extern uint8_t PORT_STATUS_LPT_MODE; |
| 62 |
extern uint8_t PORT_STATUS_SHORT; |
| 63 |
extern uint8_t PORT_STATUS_ERROR; |
| 64 |
extern uint8_t PORT_STATUS_DISABLED_MASK; |
| 65 |
extern uint8_t ORT_STATUS_MERGE; |
| 66 |
extern uint8_t PORT_STATUS_DMX_TEXT; |
| 67 |
extern uint8_t PORT_STATUS_DMX_SIP; |
| 68 |
extern uint8_t PORT_STATUS_DMX_TEST; |
| 69 |
extern uint8_t PORT_STATUS_ACT_MASK; |
| 70 |
extern uint8_t PORT_DISABLE_MASK; |
| 71 |
extern uint8_t TOD_RESPONSE_FULL; |
| 72 |
extern uint8_t TOD_RESPONSE_NAK; |
| 73 |
extern uint8_t MIN_PACKET_SIZE; |
| 74 |
extern uint8_t MERGE_TIMEOUT_SECONDS; |
| 75 |
extern uint8_t FIRMWARE_TIMEOUT_SECONDS; |
| 76 |
extern uint8_t RECV_NO_DATA; |
| 77 |
|
| 78 |
#ifndef TRUE |
| 79 |
extern int TRUE; |
| 80 |
extern int FALSE; |
| 81 |
#endif |
| 82 |
|
| 83 |
extern uint16_t LOW_BYTE; |
| 84 |
extern uint16_t HIGH_BYTE; |
| 85 |
|
| 86 |
|
| 87 |
#define SA struct sockaddr |
| 88 |
#define SI struct in_addr |
| 89 |
|
| 90 |
#ifndef min |
| 91 |
#define min(a, b) ((a) < (b) ? (a) : (b)) |
| 92 |
#endif |
| 93 |
|
| 94 |
#ifndef max |
| 95 |
#define max(a, b) ((a) > (b) ? (a) : (b)) |
| 96 |
#endif |
| 97 |
|
| 98 |
#ifndef INVALID_SOCKET |
| 99 |
#define INVALID_SOCKET -1 |
| 100 |
#endif |
| 101 |
|
| 102 |
|
| 103 |
#ifndef bswap_16 |
| 104 |
#define bswap_16(x) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) |
| 105 |
#endif |
| 106 |
|
| 107 |
|
| 108 |
#ifdef WIN32 |
| 109 |
# define htols(x) (x) |
| 110 |
#else |
| 111 |
# ifdef HAVE_ENDIAN_H |
| 112 |
# if BYTE_ORDER == __BIG_ENDIAN |
| 113 |
# define htols(x) bswap_16 (x) |
| 114 |
# else |
| 115 |
# define htols(x) (x) |
| 116 |
# endif |
| 117 |
# else |
| 118 |
# if BYTE_ORDER == BIG_ENDIAN |
| 119 |
# define htols(x) bswap_16 (x) |
| 120 |
# else |
| 121 |
# define htols(x) (x) |
| 122 |
# endif |
| 123 |
# endif |
| 124 |
#endif |
| 125 |
|
| 126 |
|
| 127 |
#define short_get_high_byte(x) ((HIGH_BYTE & x) >> 8) |
| 128 |
#define short_get_low_byte(x) (LOW_BYTE & x) |
| 129 |
|
| 130 |
#define bytes_to_short(h,l) ( ((h << 8) & 0xff00) | (l & 0x00FF) ); |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
typedef enum { |
| 146 |
ARTNET_RCDEBUG, |
| 147 |
ARTNET_RCPOWEROK, |
| 148 |
ARTNET_RCPOWERFAIL, |
| 149 |
ARTNET_RCSOCKETWR1, |
| 150 |
ARTNET_RCPARSEFAIL, |
| 151 |
ARTNET_RCUDPFAIL, |
| 152 |
ARTNET_RCSHNAMEOK, |
| 153 |
ARTNET_RCLONAMEOK, |
| 154 |
ARTNET_RCDMXERROR, |
| 155 |
ARTNET_RCDMXUDPFULL, |
| 156 |
ARTNET_RCDMXRXFULL, |
| 157 |
ARTNET_RCSWITCHERR, |
| 158 |
ARTNET_RCCONFIGERR, |
| 159 |
ARTNET_RCDMXSHORT, |
| 160 |
ARTNET_RCFIRMWAREFAIL, |
| 161 |
ARTNET_RCUSERFAIL |
| 162 |
} artnet_node_report_code; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
typedef enum { |
| 167 |
STNODE = 0x00, |
| 168 |
STSERVER = 0x01, |
| 169 |
STMEDIA = 0x02, |
| 170 |
STROUTE = 0x03, |
| 171 |
STBACKUP = 0x04, |
| 172 |
STCONFIG = 0x05 |
| 173 |
} artnet_node_style_code; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
typedef enum { |
| 187 |
ARTNET_FIRMWARE_FIRMFIRST = 0x00, |
| 188 |
ARTNET_FIRMWARE_FIRMCONT = 0x01, |
| 189 |
ARTNET_FIRMWARE_FIRMLAST = 0x02, |
| 190 |
ARTNET_FIRMWARE_UBEAFIRST = 0x03, |
| 191 |
ARTNET_FIRMWARE_UBEACONT = 0x04, |
| 192 |
ARTNET_FIRMWARE_UBEALAST = 0x05, |
| 193 |
} artnet_firmware_type_code; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
typedef struct { |
| 212 |
int (*fh)(artnet_node n, void *p, void *data); |
| 213 |
void *data; |
| 214 |
} callback_t; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
typedef struct { |
| 220 |
int (*fh)(artnet_node n, int portid, void *data); |
| 221 |
void *data; |
| 222 |
} dmx_callback_t; |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
typedef struct { |
| 228 |
int (*fh)(artnet_node n, int ubea, uint16_t *data, int length, void *d); |
| 229 |
void *data; |
| 230 |
} firmware_callback_t; |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
typedef struct { |
| 236 |
int (*fh)(artnet_node n, void *d); |
| 237 |
void *data; |
| 238 |
} program_callback_t; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
typedef struct { |
| 244 |
int (*fh)(artnet_node n, int address, uint8_t *rdm, int length, void *d); |
| 245 |
void *data; |
| 246 |
} rdm_callback_t; |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
typedef struct { |
| 251 |
callback_t recv; |
| 252 |
callback_t send; |
| 253 |
callback_t poll; |
| 254 |
callback_t reply; |
| 255 |
callback_t dmx; |
| 256 |
callback_t address; |
| 257 |
callback_t input; |
| 258 |
callback_t todrequest; |
| 259 |
callback_t toddata; |
| 260 |
callback_t todcontrol; |
| 261 |
callback_t rdm; |
| 262 |
callback_t ipprog; |
| 263 |
callback_t firmware; |
| 264 |
callback_t firmware_reply; |
| 265 |
dmx_callback_t dmx_c; |
| 266 |
firmware_callback_t firmware_c; |
| 267 |
program_callback_t program_c; |
| 268 |
rdm_callback_t rdm_c; |
| 269 |
dmx_callback_t rdm_init_c; |
| 270 |
dmx_callback_t rdm_tod_c; |
| 271 |
} node_callbacks_t; |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
typedef struct { |
| 285 |
uint8_t addr; |
| 286 |
uint8_t default_addr; |
| 287 |
uint8_t net_ctl; |
| 288 |
uint8_t status; |
| 289 |
uint8_t enabled; |
| 290 |
|
| 291 |
|
| 292 |
tod_t tod; |
| 293 |
} g_port_t; |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
typedef struct { |
| 301 |
g_port_t port; |
| 302 |
uint8_t seq; |
| 303 |
} input_port_t; |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
typedef enum { |
| 310 |
ARTNET_MERGE_HTP, |
| 311 |
ARTNET_MERGE_LTP |
| 312 |
} merge_t; |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
typedef struct { |
| 327 |
g_port_t port; |
| 328 |
int length; |
| 329 |
uint8_t enabled; |
| 330 |
|
| 331 |
|
| 332 |
uint8_t data[ARTNET_DMX_LENGTH]; |
| 333 |
merge_t merge_mode; |
| 334 |
uint8_t dataA[ARTNET_DMX_LENGTH]; |
| 335 |
uint8_t dataB[ARTNET_DMX_LENGTH]; |
| 336 |
time_t timeA; |
| 337 |
time_t timeB; |
| 338 |
SI ipA; |
| 339 |
SI ipB; |
| 340 |
} output_port_t; |
| 341 |
|
| 342 |
|
| 343 |
#define port_addr port.addr |
| 344 |
#define port_default_addr port.default_addr |
| 345 |
#define port_net_ctl port.net_ctl |
| 346 |
#define port_status port.status |
| 347 |
#define port_enabled port.enabled |
| 348 |
#define port_tod port.tod |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
typedef struct { |
| 364 |
uint16_t *data; |
| 365 |
int bytes_current; |
| 366 |
int bytes_total; |
| 367 |
struct in_addr peer; |
| 368 |
int ubea; |
| 369 |
time_t last_time; |
| 370 |
int expected_block; |
| 371 |
int (*callback)(artnet_node n, artnet_firmware_status_code code, void *d); |
| 372 |
void *user_data; |
| 373 |
} firmware_transfer_t; |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
typedef struct node_entry_private_s { |
| 380 |
artnet_node_entry_t pub; |
| 381 |
struct node_entry_private_s *next; |
| 382 |
firmware_transfer_t firmware; |
| 383 |
SI ip; |
| 384 |
|
| 385 |
|
| 386 |
} node_entry_private_t; |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
typedef struct { |
| 393 |
node_entry_private_t *first; |
| 394 |
node_entry_private_t *current; |
| 395 |
node_entry_private_t *last; |
| 396 |
int length; |
| 397 |
} node_list_t; |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
typedef enum { |
| 406 |
ARTNET_OFF, |
| 407 |
ARTNET_STANDBY, |
| 408 |
ARTNET_ON |
| 409 |
} node_status_t; |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
typedef struct { |
| 414 |
artnet_node_type node_type; |
| 415 |
node_status_t mode; |
| 416 |
SI reply_addr; |
| 417 |
SI ip_addr; |
| 418 |
SI bcast_addr; |
| 419 |
uint8_t hw_addr[ARTNET_MAC_SIZE]; |
| 420 |
uint8_t default_subnet; |
| 421 |
uint8_t subnet_net_ctl; |
| 422 |
int send_apr_on_change; |
| 423 |
int ar_count; |
| 424 |
int verbose; |
| 425 |
char short_name[ARTNET_SHORT_NAME_LENGTH]; |
| 426 |
char long_name[ARTNET_LONG_NAME_LENGTH]; |
| 427 |
char report[ARTNET_REPORT_LENGTH]; |
| 428 |
uint8_t subnet; |
| 429 |
uint8_t oem_hi; |
| 430 |
uint8_t oem_lo; |
| 431 |
uint8_t esta_hi; |
| 432 |
uint8_t esta_lo; |
| 433 |
int bcast_limit; |
| 434 |
artnet_node_report_code report_code; |
| 435 |
} node_state_t; |
| 436 |
|
| 437 |
|
| 438 |
typedef struct { |
| 439 |
struct artnet_node_s *peer; |
| 440 |
int master; |
| 441 |
} node_peering_t; |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
typedef struct artnet_node_s{ |
| 448 |
int sd; |
| 449 |
node_state_t state; |
| 450 |
node_callbacks_t callbacks; |
| 451 |
struct ports_s { |
| 452 |
uint8_t types[ARTNET_MAX_PORTS]; |
| 453 |
input_port_t in[ARTNET_MAX_PORTS]; |
| 454 |
output_port_t out[ARTNET_MAX_PORTS]; |
| 455 |
} ports; |
| 456 |
artnet_reply_t ar_temp; |
| 457 |
node_list_t node_list; |
| 458 |
firmware_transfer_t firmware; |
| 459 |
node_peering_t peering; |
| 460 |
} artnet_node_t; |
| 461 |
|
| 462 |
|
| 463 |
typedef artnet_node_t *node; |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
node_entry_private_t *find_private_entry( node n, artnet_node_entry e); |
| 471 |
void check_timeouts(node n); |
| 472 |
node_entry_private_t *find_entry_from_ip(node_list_t *nl, SI ip); |
| 473 |
int artnet_nl_update(node_list_t *nl, artnet_packet reply); |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
int handle(node n, artnet_packet p); |
| 478 |
int16_t get_type(artnet_packet p); |
| 479 |
void reset_firmware_upload(node n); |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
int artnet_tx_poll(node n, const char *ip, artnet_ttm_value_t ttm); |
| 484 |
int artnet_tx_poll_reply(node n, int reply); |
| 485 |
int artnet_tx_tod_data(node n, int id); |
| 486 |
int artnet_tx_firmware_reply(node n, in_addr_t ip, artnet_firmware_status_code code); |
| 487 |
int artnet_tx_firmware_packet(node n, firmware_transfer_t *firm ); |
| 488 |
int artnet_tx_tod_request(node n); |
| 489 |
int artnet_tx_tod_control(node n, uint8_t address, artnet_tod_command_code action); |
| 490 |
int artnet_tx_rdm(node n, uint8_t address, uint8_t *data, int length); |
| 491 |
int artnet_tx_build_art_poll_reply(node n); |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
int artnet_net_recv(node n, artnet_packet p, int block); |
| 496 |
int artnet_net_send(node n, artnet_packet p); |
| 497 |
int artnet_net_set_non_block(node n); |
| 498 |
int artnet_net_init(node n, const char *ip); |
| 499 |
int artnet_net_start(node n); |
| 500 |
int artnet_net_close(int sock); |
| 501 |
int artnet_net_join(node n1, node n2); |
| 502 |
int artnet_net_set_fdset(node n, fd_set *fdset); |
| 503 |
int artnet_net_inet_aton(const char *ip_address, struct in_addr *address); |
| 504 |
const char *artnet_net_last_error(); |
| 505 |
|
| 506 |
#endif |