| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include "private.h" |
| 21 |
|
| 22 |
|
| 23 |
int ARTNET_ADDRESS_NO_CHANGE = 0x7f; |
| 24 |
int ARTNET_PORT = 6454; |
| 25 |
int ARTNET_STRING_SIZE = 8; |
| 26 |
char ARTNET_STRING[] = "Art-Net"; |
| 27 |
uint8_t ARTNET_VERSION = 14; |
| 28 |
uint8_t OEM_HI = 0x04; |
| 29 |
uint8_t OEM_LO = 0x30; |
| 30 |
char ESTA_HI = 'z'; |
| 31 |
char ESTA_LO = 'p'; |
| 32 |
uint8_t TTM_BEHAVIOUR_MASK = 0x02; |
| 33 |
uint8_t TTM_REPLY_MASK = 0x01; |
| 34 |
uint8_t PROGRAM_NO_CHANGE = 0x7f; |
| 35 |
uint8_t PROGRAM_DEFAULTS = 0x00; |
| 36 |
uint8_t PROGRAM_CHANGE_MASK = 0x80; |
| 37 |
uint8_t HIGH_NIBBLE = 0xF0; |
| 38 |
uint8_t LOW_NIBBLE = 0x0F; |
| 39 |
uint8_t STATUS_PROG_AUTH_MASK = 0x30; |
| 40 |
uint8_t PORT_STATUS_LPT_MODE = 0x02; |
| 41 |
uint8_t PORT_STATUS_SHORT = 0x04; |
| 42 |
uint8_t PORT_STATUS_ERROR = 0x04; |
| 43 |
uint8_t PORT_STATUS_DISABLED_MASK = 0x08; |
| 44 |
uint8_t PORT_STATUS_MERGE = 0x08; |
| 45 |
uint8_t PORT_STATUS_DMX_TEXT = 0x10; |
| 46 |
uint8_t PORT_STATUS_DMX_SIP = 0x20; |
| 47 |
uint8_t PORT_STATUS_DMX_TEST = 0x40; |
| 48 |
uint8_t PORT_STATUS_ACT_MASK = 0x80; |
| 49 |
uint8_t PORT_DISABLE_MASK = 0x01; |
| 50 |
uint8_t TOD_RESPONSE_FULL = 0x00; |
| 51 |
uint8_t TOD_RESPONSE_NAK = 0x00; |
| 52 |
uint8_t MIN_PACKET_SIZE = 10; |
| 53 |
uint8_t MERGE_TIMEOUT_SECONDS = 10; |
| 54 |
uint8_t FIRMWARE_TIMEOUT_SECONDS = 20; |
| 55 |
uint8_t RECV_NO_DATA = 1; |
| 56 |
uint8_t MAX_NODE_BCAST_LIMIT = 30; |
| 57 |
|
| 58 |
#ifndef TRUE |
| 59 |
int TRUE = 1; |
| 60 |
int FALSE = 0; |
| 61 |
#endif |
| 62 |
|
| 63 |
uint16_t LOW_BYTE = 0x00FF; |
| 64 |
uint16_t HIGH_BYTE = 0xFF00; |
| 65 |
|
| 66 |
void copy_apr_to_node_entry(artnet_node_entry e, artnet_reply_t *reply); |
| 67 |
int find_nodes_from_uni(node_list_t *nl, uint8_t uni, SI *ips, int size); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
artnet_node artnet_new(const char *ip, int verbose) { |
| 79 |
node n; |
| 80 |
int i; |
| 81 |
|
| 82 |
n = malloc(sizeof(artnet_node_t)); |
| 83 |
|
| 84 |
if (!n) { |
| 85 |
artnet_error("malloc failure"); |
| 86 |
return NULL; |
| 87 |
} |
| 88 |
|
| 89 |
memset(n, 0x0, sizeof(artnet_node_t)); |
| 90 |
|
| 91 |
|
| 92 |
n->node_list.first = NULL; |
| 93 |
n->node_list.current = NULL; |
| 94 |
n->node_list.last = NULL; |
| 95 |
n->node_list.length = 0; |
| 96 |
n->state.verbose = verbose; |
| 97 |
n->state.oem_hi = OEM_HI; |
| 98 |
n->state.oem_lo = OEM_LO; |
| 99 |
n->state.esta_hi = ESTA_HI; |
| 100 |
n->state.esta_lo = ESTA_LO; |
| 101 |
n->state.bcast_limit = 0; |
| 102 |
|
| 103 |
n->peering.peer = NULL; |
| 104 |
n->peering.master = TRUE; |
| 105 |
|
| 106 |
n->sd = INVALID_SOCKET; |
| 107 |
|
| 108 |
if (artnet_net_init(n, ip)) { |
| 109 |
free(n); |
| 110 |
return NULL; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
n->state.send_apr_on_change = FALSE; |
| 115 |
n->state.ar_count = 0; |
| 116 |
n->state.report_code = ARTNET_RCPOWEROK; |
| 117 |
n->state.reply_addr.s_addr = 0; |
| 118 |
n->state.mode = ARTNET_STANDBY; |
| 119 |
|
| 120 |
|
| 121 |
for (i=0; i < ARTNET_MAX_PORTS; i++) { |
| 122 |
n->ports.out[i].merge_mode = ARTNET_MERGE_HTP; |
| 123 |
n->ports.out[i].port_enabled = FALSE; |
| 124 |
n->ports.in[i].port_enabled = FALSE; |
| 125 |
|
| 126 |
|
| 127 |
reset_tod(&n->ports.in[i].port_tod); |
| 128 |
reset_tod(&n->ports.out[i].port_tod); |
| 129 |
} |
| 130 |
return n; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
int artnet_start(artnet_node vn) { |
| 142 |
node n = (node) vn; |
| 143 |
int ret; |
| 144 |
check_nullnode(vn); |
| 145 |
|
| 146 |
if (n->state.mode != ARTNET_STANDBY) |
| 147 |
return ARTNET_ESTATE; |
| 148 |
|
| 149 |
if ((ret = artnet_net_start(n))) |
| 150 |
return ret; |
| 151 |
|
| 152 |
n->state.mode = ARTNET_ON; |
| 153 |
|
| 154 |
if (n->state.reply_addr.s_addr == 0) { |
| 155 |
n->state.reply_addr = n->state.bcast_addr; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
if ((ret = artnet_tx_build_art_poll_reply(n))) |
| 160 |
return ret; |
| 161 |
|
| 162 |
if (n->state.node_type == ARTNET_SRV) { |
| 163 |
|
| 164 |
if ((ret = artnet_tx_poll(n,NULL, ARTNET_TTM_AUTO))) |
| 165 |
return ret; |
| 166 |
|
| 167 |
if ((ret = artnet_tx_tod_request(n))) |
| 168 |
return ret; |
| 169 |
} else { |
| 170 |
|
| 171 |
if ((ret = artnet_tx_poll_reply(n, FALSE))) |
| 172 |
return ret; |
| 173 |
} |
| 174 |
return ret; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
int artnet_stop(artnet_node vn) { |
| 184 |
node n = (node) vn; |
| 185 |
check_nullnode(vn); |
| 186 |
|
| 187 |
if (n->state.mode != ARTNET_ON) |
| 188 |
return ARTNET_EACTION; |
| 189 |
|
| 190 |
artnet_net_close(n->sd); |
| 191 |
n->state.mode = ARTNET_STANDBY; |
| 192 |
return ARTNET_EOK; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
int artnet_destroy(artnet_node vn) { |
| 200 |
node n = (node) vn; |
| 201 |
node_entry_private_t *ent, *tmp; |
| 202 |
int i; |
| 203 |
|
| 204 |
check_nullnode(vn); |
| 205 |
|
| 206 |
|
| 207 |
for (ent = n->node_list.first; ent != NULL; ent = tmp) { |
| 208 |
if (ent->firmware.data != NULL) |
| 209 |
free(ent->firmware.data); |
| 210 |
tmp = ent->next; |
| 211 |
free(ent); |
| 212 |
} |
| 213 |
|
| 214 |
for (i =0; i < ARTNET_MAX_PORTS; i++) { |
| 215 |
flush_tod(&n->ports.in[i].port_tod); |
| 216 |
flush_tod(&n->ports.out[i].port_tod); |
| 217 |
} |
| 218 |
|
| 219 |
free(vn); |
| 220 |
return ARTNET_EOK; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
int artnet_setoem(artnet_node vn, uint8_t hi, uint8_t lo) { |
| 229 |
node n = (node) vn; |
| 230 |
check_nullnode(vn); |
| 231 |
|
| 232 |
if (n->state.mode != ARTNET_STANDBY) |
| 233 |
return ARTNET_ESTATE; |
| 234 |
|
| 235 |
n->state.oem_hi = hi; |
| 236 |
n->state.oem_lo = lo; |
| 237 |
return ARTNET_EOK; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
int artnet_setesta(artnet_node vn, char hi, char lo) { |
| 246 |
node n = (node) vn; |
| 247 |
check_nullnode(vn); |
| 248 |
|
| 249 |
if (n->state.mode != ARTNET_STANDBY) |
| 250 |
return ARTNET_ESTATE; |
| 251 |
|
| 252 |
n->state.esta_hi = hi; |
| 253 |
n->state.esta_lo = lo; |
| 254 |
return ARTNET_EOK; |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
int artnet_set_bcast_limit(artnet_node vn, int limit) { |
| 264 |
node n = (node) vn; |
| 265 |
check_nullnode(vn); |
| 266 |
|
| 267 |
if (limit > MAX_NODE_BCAST_LIMIT) { |
| 268 |
artnet_error("attempt to set bcast limit > %d", MAX_NODE_BCAST_LIMIT); |
| 269 |
return ARTNET_EARG; |
| 270 |
} |
| 271 |
|
| 272 |
n->state.bcast_limit = limit; |
| 273 |
return ARTNET_EOK; |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
int artnet_read(artnet_node vn, int timeout) { |
| 290 |
node n = (node) vn; |
| 291 |
node tmp; |
| 292 |
artnet_packet_t p; |
| 293 |
int ret; |
| 294 |
|
| 295 |
check_nullnode(vn); |
| 296 |
|
| 297 |
if (n->state.mode != ARTNET_ON) |
| 298 |
return ARTNET_EACTION; |
| 299 |
|
| 300 |
while (1) { |
| 301 |
memset(&p.data, 0x0, sizeof(p.data)); |
| 302 |
|
| 303 |
|
| 304 |
check_timeouts(n); |
| 305 |
|
| 306 |
if ((ret = artnet_net_recv(n, &p, timeout)) < 0) |
| 307 |
return ret; |
| 308 |
|
| 309 |
|
| 310 |
if (ret == RECV_NO_DATA) |
| 311 |
break; |
| 312 |
|
| 313 |
|
| 314 |
if (p.length == 0) |
| 315 |
continue; |
| 316 |
|
| 317 |
for (tmp = n->peering.peer; tmp != NULL && tmp != n; tmp = tmp->peering.peer) |
| 318 |
check_timeouts(tmp); |
| 319 |
|
| 320 |
if (p.length > MIN_PACKET_SIZE && get_type(&p)) { |
| 321 |
handle(n, &p); |
| 322 |
for (tmp = n->peering.peer; tmp != NULL && tmp != n; tmp = tmp->peering.peer) { |
| 323 |
handle(tmp, &p); |
| 324 |
} |
| 325 |
} |
| 326 |
} |
| 327 |
return ARTNET_EOK; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
int artnet_join(artnet_node vn1, artnet_node vn2) { |
| 348 |
|
| 349 |
check_nullnode(vn1); |
| 350 |
check_nullnode(vn2); |
| 351 |
|
| 352 |
node n1 = (node) vn1; |
| 353 |
node n2 = (node) vn2; |
| 354 |
node tmp, n; |
| 355 |
|
| 356 |
if (n1->state.mode == ARTNET_ON || n2->state.mode == ARTNET_ON) { |
| 357 |
artnet_error("%s called after artnet_start", __FUNCTION__); |
| 358 |
return ARTNET_EACTION; |
| 359 |
} |
| 360 |
|
| 361 |
tmp = n1->peering.peer == NULL ? n1 : n1->peering.peer; |
| 362 |
n1->peering.peer = n2; |
| 363 |
for (n = n2; n->peering.peer != NULL && n->peering.peer != n2; n = n->peering.peer) ; |
| 364 |
n->peering.peer = tmp; |
| 365 |
|
| 366 |
|
| 367 |
for (n = n1->peering.peer; n != n1; n = n->peering.peer) |
| 368 |
n->peering.master = FALSE; |
| 369 |
|
| 370 |
n1->peering.master = TRUE; |
| 371 |
|
| 372 |
return ARTNET_ESTATE; |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
int artnet_set_handler(artnet_node vn, |
| 391 |
artnet_handler_name_t handler, |
| 392 |
int (*fh)(artnet_node n, void *pp, void * d), |
| 393 |
void *data) { |
| 394 |
node n = (node) vn; |
| 395 |
callback_t *callback; |
| 396 |
check_nullnode(vn); |
| 397 |
|
| 398 |
switch(handler) { |
| 399 |
case ARTNET_RECV_HANDLER: |
| 400 |
callback = &n->callbacks.recv; |
| 401 |
break; |
| 402 |
case ARTNET_SEND_HANDLER: |
| 403 |
callback = &n->callbacks.send; |
| 404 |
break; |
| 405 |
case ARTNET_POLL_HANDLER: |
| 406 |
callback = &n->callbacks.poll; |
| 407 |
break; |
| 408 |
case ARTNET_REPLY_HANDLER: |
| 409 |
callback = &n->callbacks.reply; |
| 410 |
break; |
| 411 |
case ARTNET_ADDRESS_HANDLER: |
| 412 |
callback = &n->callbacks.address; |
| 413 |
break; |
| 414 |
case ARTNET_INPUT_HANDLER: |
| 415 |
callback = &n->callbacks.input; |
| 416 |
break; |
| 417 |
case ARTNET_DMX_HANDLER: |
| 418 |
callback = &n->callbacks.dmx; |
| 419 |
break; |
| 420 |
case ARTNET_TOD_REQUEST_HANDLER: |
| 421 |
callback = &n->callbacks.todrequest; |
| 422 |
break; |
| 423 |
case ARTNET_TOD_DATA_HANDLER: |
| 424 |
callback = &n->callbacks.toddata; |
| 425 |
break; |
| 426 |
case ARTNET_TOD_CONTROL_HANDLER: |
| 427 |
callback = &n->callbacks.todcontrol; |
| 428 |
break; |
| 429 |
case ARTNET_RDM_HANDLER: |
| 430 |
callback = &n->callbacks.rdm; |
| 431 |
break; |
| 432 |
default: |
| 433 |
artnet_error("%s : Invalid handler defined", __FUNCTION__); |
| 434 |
return ARTNET_EARG; |
| 435 |
} |
| 436 |
callback->fh = fh; |
| 437 |
callback->data = data; |
| 438 |
return ARTNET_EOK; |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
int artnet_set_dmx_handler(artnet_node vn, |
| 451 |
int (*fh)(artnet_node n, int port, void *d), |
| 452 |
void *data) { |
| 453 |
node n = (node) vn; |
| 454 |
check_nullnode(vn); |
| 455 |
|
| 456 |
n->callbacks.dmx_c.fh = fh; |
| 457 |
n->callbacks.dmx_c.data = data; |
| 458 |
return ARTNET_EOK; |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
int artnet_set_firmware_handler( |
| 471 |
artnet_node vn, |
| 472 |
int (*fh)(artnet_node n, int ubea, uint16_t *data, int length, void *d), |
| 473 |
void *data) { |
| 474 |
node n = (node) vn; |
| 475 |
check_nullnode(vn); |
| 476 |
n->callbacks.firmware_c.fh = fh; |
| 477 |
n->callbacks.firmware_c.data = data; |
| 478 |
return ARTNET_EOK; |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
int artnet_set_program_handler(artnet_node vn, |
| 489 |
int (*fh)(artnet_node n, void *d), |
| 490 |
void *data) { |
| 491 |
node n = (node) vn; |
| 492 |
check_nullnode(vn); |
| 493 |
n->callbacks.program_c.fh = fh; |
| 494 |
n->callbacks.program_c.data = data; |
| 495 |
return ARTNET_EOK; |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
int artnet_set_rdm_handler( |
| 508 |
artnet_node vn, |
| 509 |
int (*fh)(artnet_node n, int address, uint8_t *rdm, int length, void *d), |
| 510 |
void *data) { |
| 511 |
node n = (node) vn; |
| 512 |
check_nullnode(vn); |
| 513 |
n->callbacks.rdm_c.fh = fh; |
| 514 |
n->callbacks.rdm_c.data = data; |
| 515 |
return ARTNET_EOK; |
| 516 |
} |
| 517 |
|
| 518 |
|
| 519 |
int artnet_set_rdm_initiate_handler( |
| 520 |
artnet_node vn, |
| 521 |
int (*fh)(artnet_node n, int port, void *d), |
| 522 |
void *data) { |
| 523 |
node n = (node) vn; |
| 524 |
check_nullnode(vn); |
| 525 |
|
| 526 |
n->callbacks.rdm_init_c.fh = fh; |
| 527 |
n->callbacks.rdm_init_c.data = data; |
| 528 |
return ARTNET_EOK; |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
int artnet_set_rdm_tod_handler( |
| 533 |
artnet_node vn, |
| 534 |
int (*fh)(artnet_node n, int port, void *d), |
| 535 |
void *data) { |
| 536 |
node n = (node) vn; |
| 537 |
check_nullnode(vn); |
| 538 |
|
| 539 |
n->callbacks.rdm_tod_c.fh = fh; |
| 540 |
n->callbacks.rdm_tod_c.data = data; |
| 541 |
return ARTNET_EOK; |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
int artnet_send_poll(artnet_node vn, |
| 557 |
const char *ip, |
| 558 |
artnet_ttm_value_t talk_to_me) { |
| 559 |
node n = (node) vn; |
| 560 |
check_nullnode(vn); |
| 561 |
|
| 562 |
if (n->state.mode != ARTNET_ON) |
| 563 |
return ARTNET_EACTION; |
| 564 |
|
| 565 |
if (n->state.node_type == ARTNET_SRV || n->state.node_type == ARTNET_RAW) { |
| 566 |
return artnet_tx_poll(n, ip, talk_to_me); |
| 567 |
} |
| 568 |
|
| 569 |
artnet_error("%s : Not sending poll, not a server or raw device", __FUNCTION__); |
| 570 |
return ARTNET_ESTATE; |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
int artnet_send_poll_reply(artnet_node vn) { |
| 580 |
node n = (node) vn; |
| 581 |
check_nullnode(vn); |
| 582 |
|
| 583 |
if (n->state.mode != ARTNET_ON) |
| 584 |
return ARTNET_EACTION; |
| 585 |
|
| 586 |
return artnet_tx_poll_reply(n, FALSE); |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
int artnet_send_dmx(artnet_node vn, |
| 596 |
int port_id, |
| 597 |
int16_t length, |
| 598 |
const uint8_t *data) { |
| 599 |
node n = (node) vn; |
| 600 |
artnet_packet_t p; |
| 601 |
int ret; |
| 602 |
input_port_t *port; |
| 603 |
|
| 604 |
check_nullnode(vn); |
| 605 |
|
| 606 |
if (n->state.mode != ARTNET_ON) |
| 607 |
return ARTNET_EACTION; |
| 608 |
|
| 609 |
if (port_id < 0 || port_id >= ARTNET_MAX_PORTS) { |
| 610 |
artnet_error("%s : port index out of bounds (%i < 0 || %i > ARTNET_MAX_PORTS)", __FUNCTION__, port_id); |
| 611 |
return ARTNET_EARG; |
| 612 |
} |
| 613 |
port = &n->ports.in[port_id]; |
| 614 |
|
| 615 |
if (length < 1 || length > ARTNET_DMX_LENGTH) { |
| 616 |
artnet_error("%s : Length of dmx data out of bounds (%i < 1 || %i > ARTNET_MAX_DMX)", __FUNCTION__, length); |
| 617 |
return ARTNET_EARG; |
| 618 |
} |
| 619 |
|
| 620 |
if (port->port_status & PORT_STATUS_DISABLED_MASK) { |
| 621 |
artnet_error("%s : attempt to send on a disabled port (id:%i)", __FUNCTION__, port_id); |
| 622 |
return ARTNET_EARG; |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
port->port_status = port->port_status | PORT_STATUS_ACT_MASK; |
| 627 |
|
| 628 |
p.length = sizeof(artnet_dmx_t) - (ARTNET_DMX_LENGTH - length); |
| 629 |
|
| 630 |
|
| 631 |
memcpy(&p.data.admx.id, ARTNET_STRING, ARTNET_STRING_SIZE); |
| 632 |
p.data.admx.opCode = htols(ARTNET_DMX); |
| 633 |
p.data.admx.verH = 0; |
| 634 |
p.data.admx.ver = ARTNET_VERSION; |
| 635 |
p.data.admx.sequence = port->seq; |
| 636 |
p.data.admx.physical = port_id; |
| 637 |
p.data.admx.universe = htols(port->port_addr); |
| 638 |
|
| 639 |
|
| 640 |
p.data.admx.lengthHi = short_get_high_byte(length); |
| 641 |
p.data.admx.length = short_get_low_byte(length); |
| 642 |
memcpy(&p.data.admx.data, data, length); |
| 643 |
|
| 644 |
|
| 645 |
p.to.s_addr = n->state.bcast_addr.s_addr; |
| 646 |
|
| 647 |
if (n->state.bcast_limit == 0) { |
| 648 |
if ((ret = artnet_net_send(n, &p))) |
| 649 |
return ret; |
| 650 |
} else { |
| 651 |
int nodes; |
| 652 |
|
| 653 |
SI *ips = malloc(sizeof(SI) * n->state.bcast_limit); |
| 654 |
|
| 655 |
if (!ips) { |
| 656 |
|
| 657 |
if ((ret = artnet_net_send(n, &p))) |
| 658 |
return ret; |
| 659 |
} |
| 660 |
|
| 661 |
nodes = find_nodes_from_uni(&n->node_list, |
| 662 |
port->port_addr, |
| 663 |
ips, |
| 664 |
n->state.bcast_limit); |
| 665 |
|
| 666 |
if (nodes > n->state.bcast_limit) { |
| 667 |
|
| 668 |
free(ips); |
| 669 |
if ((ret = artnet_net_send(n, &p))) { |
| 670 |
return ret; |
| 671 |
} |
| 672 |
} else { |
| 673 |
|
| 674 |
int i; |
| 675 |
for (i =0; i < nodes; i++) { |
| 676 |
p.to = ips[i]; |
| 677 |
artnet_net_send(n, &p); |
| 678 |
} |
| 679 |
free(ips); |
| 680 |
} |
| 681 |
} |
| 682 |
port->seq++; |
| 683 |
return ARTNET_EOK; |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
int artnet_raw_send_dmx(artnet_node vn, |
| 693 |
uint8_t uni, |
| 694 |
int16_t length, |
| 695 |
const uint8_t *data) { |
| 696 |
node n = (node) vn; |
| 697 |
artnet_packet_t p; |
| 698 |
|
| 699 |
check_nullnode(vn); |
| 700 |
|
| 701 |
if (n->state.mode != ARTNET_ON) |
| 702 |
return ARTNET_EACTION; |
| 703 |
|
| 704 |
if (n->state.node_type != ARTNET_RAW) |
| 705 |
return ARTNET_ESTATE; |
| 706 |
|
| 707 |
if ( length < 1 || length > ARTNET_DMX_LENGTH) { |
| 708 |
artnet_error("%s : Length of dmx data out of bounds (%i < 1 || %i > ARTNET_MAX_DMX)", __FUNCTION__, length); |
| 709 |
return ARTNET_EARG; |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
p.to.s_addr = n->state.bcast_addr.s_addr; |
| 714 |
|
| 715 |
p.length = sizeof(artnet_dmx_t) - (ARTNET_DMX_LENGTH - length); |
| 716 |
|
| 717 |
|
| 718 |
memcpy( &p.data.admx.id, ARTNET_STRING, ARTNET_STRING_SIZE); |
| 719 |
p.data.admx.opCode = htols(ARTNET_DMX); |
| 720 |
p.data.admx.verH = 0; |
| 721 |
p.data.admx.ver = ARTNET_VERSION; |
| 722 |
p.data.admx.sequence = 0; |
| 723 |
p.data.admx.physical = 0; |
| 724 |
p.data.admx.universe = uni; |
| 725 |
|
| 726 |
|
| 727 |
p.data.admx.lengthHi = short_get_high_byte(length); |
| 728 |
p.data.admx.length = short_get_low_byte(length); |
| 729 |
memcpy(&p.data.admx.data, data, length); |
| 730 |
|
| 731 |
return artnet_net_send(n, &p); |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
int artnet_send_address(artnet_node vn, |
| 737 |
artnet_node_entry e, |
| 738 |
const char *shortName, |
| 739 |
const char *longName, |
| 740 |
uint8_t inAddr[ARTNET_MAX_PORTS], |
| 741 |
uint8_t outAddr[ARTNET_MAX_PORTS], |
| 742 |
uint8_t subAddr, artnet_port_command_t cmd) { |
| 743 |
node n = (node) vn; |
| 744 |
artnet_packet_t p; |
| 745 |
node_entry_private_t *ent = find_private_entry(n,e); |
| 746 |
|
| 747 |
check_nullnode(vn); |
| 748 |
|
| 749 |
if (e == NULL || ent == NULL) |
| 750 |
return ARTNET_EARG; |
| 751 |
|
| 752 |
if (n->state.mode != ARTNET_ON) |
| 753 |
return ARTNET_EACTION; |
| 754 |
|
| 755 |
if (n->state.node_type == ARTNET_SRV || n->state.node_type == ARTNET_RAW) { |
| 756 |
p.to.s_addr = ent->ip.s_addr; |
| 757 |
|
| 758 |
p.length = sizeof(artnet_address_t); |
| 759 |
p.type = ARTNET_ADDRESS; |
| 760 |
|
| 761 |
|
| 762 |
memcpy( &p.data.addr.id, ARTNET_STRING, ARTNET_STRING_SIZE); |
| 763 |
p.data.addr.opCode = htols(ARTNET_ADDRESS); |
| 764 |
p.data.addr.verH = 0; |
| 765 |
p.data.addr.ver = ARTNET_VERSION; |
| 766 |
p.data.addr.filler1 = 0; |
| 767 |
p.data.addr.filler2 = 0; |
| 768 |
strncpy((char*) &p.data.addr.shortname, shortName, ARTNET_SHORT_NAME_LENGTH); |
| 769 |
strncpy((char*) &p.data.addr.longname, longName, ARTNET_LONG_NAME_LENGTH); |
| 770 |
|
| 771 |
memcpy(&p.data.addr.swin, inAddr, ARTNET_MAX_PORTS); |
| 772 |
memcpy(&p.data.addr.swout, outAddr, ARTNET_MAX_PORTS); |
| 773 |
|
| 774 |
p.data.addr.subnet = subAddr; |
| 775 |
p.data.addr.swvideo = 0x00; |
| 776 |
p.data.addr.command = cmd; |
| 777 |
|
| 778 |
return artnet_net_send(n, &p); |
| 779 |
} |
| 780 |
return ARTNET_ESTATE; |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
int artnet_send_input(artnet_node vn, |
| 795 |
artnet_node_entry e, |
| 796 |
uint8_t settings[ARTNET_MAX_PORTS]) { |
| 797 |
node n = (node) vn; |
| 798 |
artnet_packet_t p; |
| 799 |
node_entry_private_t *ent = find_private_entry(n,e); |
| 800 |
|
| 801 |
check_nullnode(vn); |
| 802 |
|
| 803 |
if (e == NULL) |
| 804 |
return ARTNET_EARG; |
| 805 |
|
| 806 |
if (n->state.mode != ARTNET_ON) |
| 807 |
return ARTNET_EACTION; |
| 808 |
|
| 809 |
if (n->state.node_type == ARTNET_SRV || n->state.node_type == ARTNET_RAW) { |
| 810 |
|
| 811 |
p.to.s_addr = ent->ip.s_addr; |
| 812 |
|
| 813 |
p.length = sizeof(artnet_input_t); |
| 814 |
p.type = ARTNET_INPUT; |
| 815 |
|
| 816 |
|
| 817 |
memcpy( &p.data.ainput.id, ARTNET_STRING, ARTNET_STRING_SIZE); |
| 818 |
p.data.ainput.opCode = htols(ARTNET_INPUT); |
| 819 |
p.data.ainput.verH = 0; |
| 820 |
p.data.ainput.ver = ARTNET_VERSION; |
| 821 |
p.data.ainput.filler1 = 0; |
| 822 |
p.data.ainput.filler2 = 0; |
| 823 |
p.data.ainput.numbportsH = short_get_high_byte(e->numbports); |
| 824 |
p.data.ainput.numbports = short_get_low_byte(e->numbports); |
| 825 |
memcpy(&p.data.ainput.input, &settings, ARTNET_MAX_PORTS); |
| 826 |
|
| 827 |
return artnet_net_send(n, &p); |
| 828 |
} |
| 829 |
return ARTNET_ESTATE; |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
int artnet_send_firmware( |
| 850 |
artnet_node vn, |
| 851 |
artnet_node_entry e, |
| 852 |
int ubea, |
| 853 |
uint16_t *data, |
| 854 |
int length, |
| 855 |
int (*fh)(artnet_node n, artnet_firmware_status_code code, void *d), |
| 856 |
void *user_data) { |
| 857 |
node n = (node) vn; |
| 858 |
node_entry_private_t *ent = find_private_entry(n,e); |
| 859 |
int blen; |
| 860 |
|
| 861 |
check_nullnode(vn); |
| 862 |
if (e == NULL || ent == NULL) |
| 863 |
return ARTNET_EARG; |
| 864 |
|
| 865 |
if (n->state.mode != ARTNET_ON) |
| 866 |
return ARTNET_EACTION; |
| 867 |
|
| 868 |
if (n->state.node_type == ARTNET_SRV || n->state.node_type == ARTNET_RAW) { |
| 869 |
|
| 870 |
|
| 871 |
blen = length * sizeof(uint16_t); |
| 872 |
|
| 873 |
|
| 874 |
ent->firmware.data = malloc(blen); |
| 875 |
|
| 876 |
if ( ent->firmware.data == NULL) { |
| 877 |
artnet_error_malloc(); |
| 878 |
return ARTNET_EMEM; |
| 879 |
} |
| 880 |
|
| 881 |
ent->firmware.bytes_current = 0; |
| 882 |
ent->firmware.bytes_total = blen; |
| 883 |
ent->firmware.peer = ent->ip; |
| 884 |
ent->firmware.ubea = ubea; |
| 885 |
|
| 886 |
|
| 887 |
ent->firmware.expected_block = 0; |
| 888 |
ent->firmware.callback = fh; |
| 889 |
ent->firmware.user_data = user_data; |
| 890 |
|
| 891 |
memcpy(ent->firmware.data, data, blen); |
| 892 |
|
| 893 |
return artnet_tx_firmware_packet(n, &ent->firmware); |
| 894 |
} |
| 895 |
|
| 896 |
return ARTNET_ESTATE; |
| 897 |
} |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
int artnet_send_firmware_reply(artnet_node vn, |
| 913 |
artnet_node_entry e, |
| 914 |
artnet_firmware_status_code code) { |
| 915 |
node n = (node) vn; |
| 916 |
node_entry_private_t *ent = find_private_entry(n,e); |
| 917 |
|
| 918 |
check_nullnode(vn); |
| 919 |
|
| 920 |
if (e == NULL || ent == NULL) |
| 921 |
return ARTNET_EARG; |
| 922 |
|
| 923 |
if (n->state.mode != ARTNET_ON) |
| 924 |
return ARTNET_EACTION; |
| 925 |
|
| 926 |
return artnet_tx_firmware_reply(n, ent->ip.s_addr, code); |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
int artnet_send_tod_request(artnet_node vn) { |
| 937 |
node n = (node) vn; |
| 938 |
check_nullnode(vn); |
| 939 |
|
| 940 |
return artnet_tx_tod_request(n); |
| 941 |
} |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
int artnet_send_tod_control(artnet_node vn, |
| 953 |
uint8_t address, |
| 954 |
artnet_tod_command_code action) { |
| 955 |
node n = (node) vn; |
| 956 |
check_nullnode(vn); |
| 957 |
return artnet_tx_tod_control(n, address, action); |
| 958 |
} |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
int artnet_send_tod_data(artnet_node vn, int port) { |
| 969 |
node n = (node) vn; |
| 970 |
check_nullnode(vn); |
| 971 |
|
| 972 |
|
| 973 |
if (port < 0 || port >= ARTNET_MAX_PORTS) { |
| 974 |
artnet_error("%s : port index out of bounds (%i < 0 || %i > ARTNET_MAX_PORTS)", __FUNCTION__, port); |
| 975 |
return ARTNET_EARG; |
| 976 |
} |
| 977 |
|
| 978 |
return artnet_tx_tod_data(n, port); |
| 979 |
} |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
int artnet_send_rdm(artnet_node vn, |
| 989 |
uint8_t address, |
| 990 |
uint8_t *data, |
| 991 |
int length) { |
| 992 |
node n = (node) vn; |
| 993 |
check_nullnode(vn); |
| 994 |
|
| 995 |
|
| 996 |
return artnet_tx_rdm(n, address, data, length); |
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
int artnet_add_rdm_device(artnet_node vn, |
| 1006 |
int port, |
| 1007 |
uint8_t uid[ARTNET_RDM_UID_WIDTH]) { |
| 1008 |
node n = (node) vn; |
| 1009 |
check_nullnode(vn); |
| 1010 |
|
| 1011 |
if (port < 0 || port >= ARTNET_MAX_PORTS) { |
| 1012 |
artnet_error("%s : port index out of bounds (%i < 0 || %i > ARTNET_MAX_PORTS)", __FUNCTION__, port); |
| 1013 |
return ARTNET_EARG; |
| 1014 |
} |
| 1015 |
|
| 1016 |
|
| 1017 |
add_tod_uid(&n->ports.out[port].port_tod, uid); |
| 1018 |
|
| 1019 |
|
| 1020 |
return artnet_tx_tod_data(n, port); |
| 1021 |
} |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
int artnet_add_rdm_devices(artnet_node vn, int port, uint8_t *uid, int count) { |
| 1032 |
node n = (node) vn; |
| 1033 |
int i; |
| 1034 |
|
| 1035 |
check_nullnode(vn); |
| 1036 |
|
| 1037 |
if (port < 0 || port >= ARTNET_MAX_PORTS) { |
| 1038 |
artnet_error("%s : port index out of bounds (%i < 0 || %i > ARTNET_MAX_PORTS)", __FUNCTION__, port); |
| 1039 |
return ARTNET_EARG; |
| 1040 |
} |
| 1041 |
|
| 1042 |
if (count < 0) |
| 1043 |
return ARTNET_EARG; |
| 1044 |
|
| 1045 |
for (i = 0; i < count; i++) { |
| 1046 |
|
| 1047 |
add_tod_uid(&n->ports.out[port].port_tod, uid); |
| 1048 |
uid += ARTNET_RDM_UID_WIDTH; |
| 1049 |
} |
| 1050 |
|
| 1051 |
return artnet_tx_tod_data(n, port); |
| 1052 |
|
| 1053 |
} |
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
int artnet_remove_rdm_device(artnet_node vn, |
| 1063 |
int port, |
| 1064 |
uint8_t uid[ARTNET_RDM_UID_WIDTH]) { |
| 1065 |
node n = (node) vn; |
| 1066 |
check_nullnode(vn); |
| 1067 |
|
| 1068 |
if (port < 0 || port >= ARTNET_MAX_PORTS) { |
| 1069 |
artnet_error("%s : port index out of bounds (%i < 0 || %i > ARTNET_MAX_PORTS)", __FUNCTION__, port); |
| 1070 |
return ARTNET_EARG; |
| 1071 |
} |
| 1072 |
|
| 1073 |
|
| 1074 |
remove_tod_uid(&n->ports.out[port].port_tod, uid); |
| 1075 |
|
| 1076 |
|
| 1077 |
return artnet_tx_tod_data(n, port); |
| 1078 |
} |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
uint8_t *artnet_read_dmx(artnet_node vn, int port_id, int *length) { |
| 1090 |
node n = (node) vn; |
| 1091 |
|
| 1092 |
if (n == NULL) |
| 1093 |
return NULL; |
| 1094 |
|
| 1095 |
if (port_id < 0 || port_id >= ARTNET_MAX_PORTS) { |
| 1096 |
artnet_error("%s : port index out of bounds (%i < 0 || %i > ARTNET_MAX_PORTS)", __FUNCTION__, port_id); |
| 1097 |
return NULL; |
| 1098 |
} |
| 1099 |
|
| 1100 |
*length = n->ports.out[port_id].length; |
| 1101 |
return &n->ports.out[port_id].data[0]; |
| 1102 |
} |
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
int artnet_set_node_type(artnet_node vn, artnet_node_type type) { |
| 1110 |
node n = (node) vn; |
| 1111 |
check_nullnode(vn); |
| 1112 |
|
| 1113 |
n->state.node_type = type; |
| 1114 |
return ARTNET_EOK; |
| 1115 |
} |
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
int artnet_set_subnet_addr(artnet_node vn, uint8_t subnet) { |
| 1134 |
node n = (node) vn; |
| 1135 |
int i, ret; |
| 1136 |
|
| 1137 |
check_nullnode(vn); |
| 1138 |
|
| 1139 |
n->state.default_subnet = subnet; |
| 1140 |
|
| 1141 |
|
| 1142 |
if (!n->state.subnet_net_ctl && subnet != n->state.subnet) { |
| 1143 |
n->state.subnet = subnet; |
| 1144 |
|
| 1145 |
|
| 1146 |
for (i =0; i < ARTNET_MAX_PORTS; i++) { |
| 1147 |
n->ports.in[i].port_addr = ((n->state.subnet & LOW_NIBBLE) << 4) | (n->ports.in[i].port_addr & LOW_NIBBLE); |
| 1148 |
|
| 1149 |
n->ports.in[i].seq = 0; |
| 1150 |
|
| 1151 |
n->ports.out[i].port_addr = ((n->state.subnet & LOW_NIBBLE) << 4) | (n->ports.out[i].port_addr & LOW_NIBBLE); |
| 1152 |
} |
| 1153 |
|
| 1154 |
if (n->state.mode == ARTNET_ON) { |
| 1155 |
|
| 1156 |
if ((ret = artnet_tx_build_art_poll_reply(n))) |
| 1157 |
return ret; |
| 1158 |
|
| 1159 |
return artnet_tx_poll_reply(n,FALSE); |
| 1160 |
} |
| 1161 |
} else if (n->state.subnet_net_ctl ) { |
| 1162 |
|
| 1163 |
n->state.report_code = ARTNET_RCUSERFAIL; |
| 1164 |
} |
| 1165 |
|
| 1166 |
return ARTNET_EOK; |
| 1167 |
} |
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
int artnet_set_short_name(artnet_node vn, const char *name) { |
| 1178 |
node n = (node) vn; |
| 1179 |
check_nullnode(vn); |
| 1180 |
|
| 1181 |
strncpy((char *) &n->state.short_name, name, ARTNET_SHORT_NAME_LENGTH); |
| 1182 |
n->state.short_name[ARTNET_SHORT_NAME_LENGTH-1] = 0x00; |
| 1183 |
return artnet_tx_build_art_poll_reply(n); |
| 1184 |
} |
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
int artnet_set_long_name(artnet_node vn, const char *name) { |
| 1195 |
node n = (node) vn; |
| 1196 |
check_nullnode(vn); |
| 1197 |
|
| 1198 |
strncpy((char *) &n->state.long_name, name, ARTNET_LONG_NAME_LENGTH); |
| 1199 |
n->state.long_name[ARTNET_LONG_NAME_LENGTH-1] = 0x00; |
| 1200 |
return artnet_tx_build_art_poll_reply(n); |
| 1201 |
} |
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
int artnet_set_port_type(artnet_node vn, |
| 1212 |
int port_id, |
| 1213 |
artnet_port_settings_t settings, |
| 1214 |
artnet_port_data_code data) { |
| 1215 |
node n = (node) vn; |
| 1216 |
check_nullnode(vn); |
| 1217 |
|
| 1218 |
if (port_id < 0 || port_id >= ARTNET_MAX_PORTS) { |
| 1219 |
artnet_error("%s : port index out of bounds (%i < 0 || %i > ARTNET_MAX_PORTS)", __FUNCTION__, port_id); |
| 1220 |
return ARTNET_EARG; |
| 1221 |
} |
| 1222 |
|
| 1223 |
n->ports.types[port_id] = settings | data; |
| 1224 |
return ARTNET_EOK; |
| 1225 |
} |
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
int artnet_set_port_addr(artnet_node vn, |
| 1254 |
int id, |
| 1255 |
artnet_port_dir_t dir, |
| 1256 |
uint8_t addr) { |
| 1257 |
node n = (node) vn; |
| 1258 |
int ret; |
| 1259 |
int changed = 0; |
| 1260 |
|
| 1261 |
g_port_t *port; |
| 1262 |
|
| 1263 |
check_nullnode(vn); |
| 1264 |
|
| 1265 |
if (id < 0 || id >= ARTNET_MAX_PORTS) { |
| 1266 |
artnet_error("%s : port index out of bounds (%i < 0 || %i > ARTNET_MAX_PORTS)", __FUNCTION__, id); |
| 1267 |
return ARTNET_EARG; |
| 1268 |
} |
| 1269 |
|
| 1270 |
if (addr > 16) { |
| 1271 |
artnet_error("%s : Attempt to set port %i to invalid address %#hhx\n", __FUNCTION__, id, addr); |
| 1272 |
return ARTNET_EARG; |
| 1273 |
} |
| 1274 |
|
| 1275 |
if (dir == ARTNET_INPUT_PORT) { |
| 1276 |
port = &n->ports.in[id].port; |
| 1277 |
changed = n->ports.in[id].port_enabled?0:1; |
| 1278 |
n->ports.in[id].port_enabled = TRUE; |
| 1279 |
} else if (dir == ARTNET_OUTPUT_PORT) { |
| 1280 |
port = &n->ports.out[id].port; |
| 1281 |
changed = n->ports.out[id].port_enabled?0:1; |
| 1282 |
n->ports.out[id].port_enabled = TRUE; |
| 1283 |
} else { |
| 1284 |
artnet_error("%s : Invalid port direction\n", __FUNCTION__); |
| 1285 |
return ARTNET_EARG; |
| 1286 |
} |
| 1287 |
|
| 1288 |
port->default_addr = addr; |
| 1289 |
|
| 1290 |
|
| 1291 |
if (!port->net_ctl && |
| 1292 |
(changed || (addr & LOW_NIBBLE) != (port->addr & LOW_NIBBLE))) { |
| 1293 |
port->addr = ((n->state.subnet & LOW_NIBBLE) << 4) | (addr & LOW_NIBBLE); |
| 1294 |
|
| 1295 |
|
| 1296 |
if (dir == ARTNET_INPUT_PORT) |
| 1297 |
n->ports.in[id].seq = 0; |
| 1298 |
|
| 1299 |
if (n->state.mode == ARTNET_ON) { |
| 1300 |
if ((ret = artnet_tx_build_art_poll_reply(n))) |
| 1301 |
return ret; |
| 1302 |
|
| 1303 |
return artnet_tx_poll_reply(n,FALSE); |
| 1304 |
} |
| 1305 |
} else if (port->net_ctl) { |
| 1306 |
|
| 1307 |
n->state.report_code = ARTNET_RCUSERFAIL; |
| 1308 |
} |
| 1309 |
return ARTNET_EOK; |
| 1310 |
} |
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
int artnet_get_universe_addr(artnet_node vn, int id, artnet_port_dir_t dir) { |
| 1323 |
node n = (node) vn; |
| 1324 |
check_nullnode(vn); |
| 1325 |
|
| 1326 |
if (id < 0 || id >= ARTNET_MAX_PORTS) { |
| 1327 |
artnet_error("%s : port index out of bounds (%i < 0 || %i > ARTNET_MAX_PORTS)", __FUNCTION__, id); |
| 1328 |
return ARTNET_EARG; |
| 1329 |
} |
| 1330 |
|
| 1331 |
if (dir == ARTNET_INPUT_PORT) |
| 1332 |
return n->ports.in[id].port.addr; |
| 1333 |
else if (dir == ARTNET_OUTPUT_PORT) |
| 1334 |
return n->ports.out[id].port.addr; |
| 1335 |
else { |
| 1336 |
artnet_error("%s : Invalid port direction\n", __FUNCTION__); |
| 1337 |
return ARTNET_EARG; |
| 1338 |
} |
| 1339 |
} |
| 1340 |
|
| 1341 |
int artnet_get_config(artnet_node vn, artnet_node_config_t *config) { |
| 1342 |
int i; |
| 1343 |
node n = (node) vn; |
| 1344 |
check_nullnode(vn); |
| 1345 |
|
| 1346 |
strncpy(config->short_name, n->state.short_name, ARTNET_SHORT_NAME_LENGTH); |
| 1347 |
strncpy(config->long_name, n->state.long_name, ARTNET_LONG_NAME_LENGTH); |
| 1348 |
config->subnet = n->state.subnet; |
| 1349 |
|
| 1350 |
for (i = 0; i < ARTNET_MAX_PORTS; i++) { |
| 1351 |
config->in_ports[i] = n->ports.in[i].port.addr & LOW_NIBBLE; |
| 1352 |
config->out_ports[i] = n->ports.out[i].port.addr & LOW_NIBBLE; |
| 1353 |
} |
| 1354 |
|
| 1355 |
return ARTNET_EOK; |
| 1356 |
} |
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
int artnet_dump_config(artnet_node vn) { |
| 1365 |
node n = (node) vn; |
| 1366 |
check_nullnode(vn); |
| 1367 |
|
| 1368 |
printf("#### NODE CONFIG ####\n"); |
| 1369 |
printf("Node Type: %i\n", n->state.node_type); |
| 1370 |
printf("Short Name: %s\n", n->state.short_name); |
| 1371 |
printf("Long Name: %s\n", n->state.long_name); |
| 1372 |
printf("Subnet: %#02x\n", n->state.subnet); |
| 1373 |
printf("Default Subnet: %#02x\n", n->state.default_subnet); |
| 1374 |
printf("Net Ctl: %i\n", n->state.subnet_net_ctl); |
| 1375 |
printf("#####################\n"); |
| 1376 |
|
| 1377 |
return ARTNET_EOK; |
| 1378 |
} |
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
int artnet_get_sd(artnet_node vn) { |
| 1391 |
node n = (node) vn; |
| 1392 |
check_nullnode(vn); |
| 1393 |
|
| 1394 |
if (n->state.mode != ARTNET_ON) |
| 1395 |
return ARTNET_EACTION; |
| 1396 |
|
| 1397 |
return n->sd; |
| 1398 |
} |
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
int artnet_set_fdset(artnet_node vn, fd_set *fdset) { |
| 1409 |
node n = (node) vn; |
| 1410 |
check_nullnode(vn); |
| 1411 |
|
| 1412 |
if (!fdset) |
| 1413 |
return ARTNET_EARG; |
| 1414 |
|
| 1415 |
if (n->state.mode != ARTNET_ON) |
| 1416 |
return ARTNET_EACTION; |
| 1417 |
|
| 1418 |
return artnet_net_set_fdset(n, fdset); |
| 1419 |
} |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
artnet_node_list artnet_get_nl(artnet_node vn) { |
| 1432 |
node n = (node) vn; |
| 1433 |
|
| 1434 |
if (!vn) |
| 1435 |
return NULL; |
| 1436 |
|
| 1437 |
return &n->node_list; |
| 1438 |
} |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
artnet_node_entry artnet_nl_first(artnet_node_list vnl) { |
| 1449 |
node_list_t *nl = (node_list_t*) vnl; |
| 1450 |
|
| 1451 |
if (!nl) |
| 1452 |
return NULL; |
| 1453 |
|
| 1454 |
nl->current = nl->first; |
| 1455 |
return &nl->current->pub; |
| 1456 |
} |
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
artnet_node_entry artnet_nl_next(artnet_node_list vnl) { |
| 1467 |
node_list_t *nl = (node_list_t*) vnl; |
| 1468 |
|
| 1469 |
if (!nl) |
| 1470 |
return NULL; |
| 1471 |
|
| 1472 |
nl->current = nl->current->next; |
| 1473 |
return &nl->current->pub; |
| 1474 |
} |
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
int artnet_nl_get_length(artnet_node_list vnl) { |
| 1485 |
node_list_t *nl = (node_list_t*) vnl; |
| 1486 |
|
| 1487 |
if (!nl) |
| 1488 |
return 0; |
| 1489 |
|
| 1490 |
return nl->length; |
| 1491 |
} |
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
char *artnet_strerror() { |
| 1498 |
return artnet_errstr; |
| 1499 |
} |
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
int artnet_nl_update(node_list_t *nl, artnet_packet reply) { |
| 1507 |
node_entry_private_t *entry; |
| 1508 |
|
| 1509 |
entry = find_entry_from_ip(nl, reply->from); |
| 1510 |
|
| 1511 |
if (!entry) { |
| 1512 |
|
| 1513 |
entry = (node_entry_private_t*) malloc(sizeof(node_entry_private_t)); |
| 1514 |
|
| 1515 |
if (!entry) { |
| 1516 |
artnet_error_malloc(); |
| 1517 |
return ARTNET_EMEM; |
| 1518 |
} |
| 1519 |
|
| 1520 |
memset(entry, 0x00, sizeof(node_entry_private_t)); |
| 1521 |
|
| 1522 |
copy_apr_to_node_entry(&entry->pub, &reply->data.ar); |
| 1523 |
entry->ip = reply->from; |
| 1524 |
entry->next = NULL; |
| 1525 |
|
| 1526 |
if (!nl->first) { |
| 1527 |
nl->first = entry; |
| 1528 |
nl->last = entry; |
| 1529 |
} else { |
| 1530 |
nl->last->next = entry; |
| 1531 |
nl->last = entry; |
| 1532 |
} |
| 1533 |
nl->length++; |
| 1534 |
} else { |
| 1535 |
|
| 1536 |
copy_apr_to_node_entry(&entry->pub, &reply->data.ar); |
| 1537 |
} |
| 1538 |
return ARTNET_EOK; |
| 1539 |
} |
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
node_entry_private_t *find_entry_from_ip(node_list_t *nl, SI ip) { |
| 1546 |
node_entry_private_t *tmp; |
| 1547 |
|
| 1548 |
for (tmp = nl->first; tmp; tmp = tmp->next) { |
| 1549 |
if (ip.s_addr == tmp->ip.s_addr) |
| 1550 |
break; |
| 1551 |
} |
| 1552 |
return tmp; |
| 1553 |
} |
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
int find_nodes_from_uni(node_list_t *nl, uint8_t uni, SI *ips, int size) { |
| 1565 |
node_entry_private_t *tmp; |
| 1566 |
int count = 0; |
| 1567 |
int i,j = 0; |
| 1568 |
|
| 1569 |
for (tmp = nl->first; tmp; tmp = tmp->next) { |
| 1570 |
int added = FALSE; |
| 1571 |
for (i =0; i < tmp->pub.numbports; i++) { |
| 1572 |
if (tmp->pub.swout[i] == uni && ips) { |
| 1573 |
if (j < size && !added) { |
| 1574 |
ips[j++] = tmp->ip; |
| 1575 |
added = TRUE; |
| 1576 |
} |
| 1577 |
count++; |
| 1578 |
} |
| 1579 |
} |
| 1580 |
} |
| 1581 |
return count; |
| 1582 |
} |
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
void copy_apr_to_node_entry(artnet_node_entry e, artnet_reply_t *reply) { |
| 1589 |
|
| 1590 |
|
| 1591 |
memcpy(&e->ip, &reply->ip, 4); |
| 1592 |
e->ver = bytes_to_short(reply->verH, reply->ver); |
| 1593 |
e->sub = bytes_to_short(reply->subH, reply->sub); |
| 1594 |
e->oem = bytes_to_short(reply->oemH, reply->oem); |
| 1595 |
e->ubea = reply->ubea; |
| 1596 |
memcpy(&e->etsaman, &reply->etsaman, 2); |
| 1597 |
memcpy(&e->shortname, &reply->shortname, sizeof(e->shortname)); |
| 1598 |
memcpy(&e->longname, &reply->longname, sizeof(e->longname)); |
| 1599 |
memcpy(&e->nodereport, &reply->nodereport, sizeof(e->nodereport)); |
| 1600 |
e->numbports = bytes_to_short(reply->numbportsH, reply->numbports); |
| 1601 |
memcpy(&e->porttypes, &reply->porttypes, ARTNET_MAX_PORTS); |
| 1602 |
memcpy(&e->goodinput, &reply->goodinput, ARTNET_MAX_PORTS); |
| 1603 |
memcpy(&e->goodinput, &reply->goodinput, ARTNET_MAX_PORTS); |
| 1604 |
memcpy(&e->goodoutput, &reply->goodoutput, ARTNET_MAX_PORTS); |
| 1605 |
memcpy(&e->swin, &reply->swin, ARTNET_MAX_PORTS); |
| 1606 |
memcpy(&e->swout, &reply->swout, ARTNET_MAX_PORTS); |
| 1607 |
e->swvideo = reply->swvideo; |
| 1608 |
e->swmacro = reply->swmacro; |
| 1609 |
e->swremote = reply->swremote; |
| 1610 |
e->style = reply->style; |
| 1611 |
memcpy(&e->mac, &reply->mac, ARTNET_MAC_SIZE); |
| 1612 |
} |
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
node_entry_private_t *find_private_entry(node n, artnet_node_entry e) { |
| 1618 |
node_entry_private_t *tmp; |
| 1619 |
if (!e) |
| 1620 |
return NULL; |
| 1621 |
|
| 1622 |
|
| 1623 |
for (tmp = n->node_list.first; tmp; tmp = tmp->next) { |
| 1624 |
if (!memcmp(&e->ip, &tmp->pub.ip, 4)) |
| 1625 |
break; |
| 1626 |
} |
| 1627 |
return tmp; |
| 1628 |
} |
| 1629 |
|
| 1630 |
|
| 1631 |
void check_timeouts(node n) { |
| 1632 |
time_t now = time(NULL); |
| 1633 |
|
| 1634 |
if (n->firmware.peer.s_addr != 0 |
| 1635 |
&& (now - n->firmware.last_time >= FIRMWARE_TIMEOUT_SECONDS)) { |
| 1636 |
|
| 1637 |
printf("firmware timeout\n"); |
| 1638 |
reset_firmware_upload(n); |
| 1639 |
|
| 1640 |
n->state.report_code = ARTNET_RCFIRMWAREFAIL; |
| 1641 |
|
| 1642 |
} |
| 1643 |
} |