/* * Copyright (C) 2001 Dirk Jagdmann * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Modified by Simon Newton (nomis52westnet.com.au) * to use artnet * */ /* * Modified by Michael Salathe (michael.salathe@murxs.ch) * to print the first 16 Values to stdout for logging purpose. * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #define DMXCHANNELS 512 #define ADDRESS 0 #define MAX_BUF_SIZE 255 #define DEV_PIPE "/var/dmx/dmx" int MAXCHANNELS=512; int hd_pipe; typedef unsigned char dmx_t ; static dmx_t *dmx; static artnet_node node ; void CHECK(void *p) { if(p==NULL) { fprintf(stderr, "could not alloc\n"); exit(1); } } /* signal handler for crashes. Program is aborted */ void crash(int sig) { exit(1); } /* cleanup handler for program exit. */ void cleanup() { /*close(hd_pipe);*/ artnet_stop(node) ; artnet_destroy(node) ; } int dmx_handler(artnet_node n, int prt , void *d ) { int len ; uint8_t *data ; if( prt == 0 ) { data = artnet_read_dmx(n, prt, &len) ; memcpy(dmx, data,len) ; printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8],data[9],data[10],data[11],data[12],data[13],data[14],data[15]); fflush(stdout); } return 0 ; } int main (int argc, char *argv[]) { int c=0; int optc , subnet_addr = 0 , port_addr = 0 ; int artnet_sd ; char *ip_addr = NULL ; atexit(cleanup); dmx = malloc(MAXCHANNELS); if(!dmx) { printf("malloc failed\n") ; return 1 ; } memset(dmx, 0x00, MAXCHANNELS) ; // parse options while ((optc = getopt (argc, argv, "s:p:a:")) != EOF) { switch (optc) { case 'a': ip_addr = (char *) strdup(optarg) ; break; case 's': subnet_addr = atoi(optarg) ; if(subnet_addr < 0 && subnet_addr > 15) { printf("Subnet address must be between 0 and 15\n") ; exit(1) ; } break ; case 'p': port_addr = atoi(optarg) ; if(port_addr < 0 && port_addr > 15) { printf("Port address must be between 0 and 15\n") ; exit(1) ; } break ; default: break; } } /* set up artnet connection */ node = artnet_new(ip_addr, 0 ) ; ; if(node == NULL) { printf("Unable to connect\n") ; return 1 ; } fprintf(stderr,"Client bound\n"); if(artnet_set_dmx_handler(node, dmx_handler, NULL) ) { printf("Failed to install handler\n") ; return 1 ; } fprintf(stderr,"Handler installed\n"); artnet_set_subnet_addr(node, subnet_addr) ; artnet_set_port_type(node, 0, ARTNET_ENABLE_OUTPUT, ARTNET_PORT_DMX) ; artnet_set_port_addr(node, 0, ARTNET_OUTPUT_PORT, port_addr); artnet_start(node) ; fprintf(stderr,"Node online\n"); // store the sds artnet_sd = artnet_get_sd(node) ; /* Create the named - pipe */ /*ret_val = mkfifo(DEV_PIPE, 0666); if ((ret_val == -1) && (errno != EEXIST)) { perror("Error creating the named pipe"); exit (1); } */ /* hd_pipe = open(DEV_PIPE, O_WRONLY);*/ /* main loop */ fprintf(stderr,"STarting main loop\n"); c=0; while (c!='q') { int max; fd_set rd_fds; struct timeval tv; FD_ZERO(&rd_fds); FD_SET(0, &rd_fds); FD_SET(artnet_sd, &rd_fds) ; max = artnet_sd ; tv.tv_sec = 1; tv.tv_usec = 0; if (FD_ISSET(artnet_sd , &rd_fds) ) artnet_read(node,0); } return 0; }