source: roaraudio/roarclients/roarlight.c @ 4708:c9d40761088a

Last change on this file since 4708:c9d40761088a was 4708:c9d40761088a, checked in by phi, 13 years ago

updated copyright statements

File size: 3.6 KB
Line 
1//roarlight.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011
5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <roaraudio.h>
27#include <libroarlight/libroarlight.h>
28
29#define CONVAR struct roar_connection * con
30
31void usage (void) {
32 printf("roarlight [OPTIONS]... command [command...]\n");
33
34 printf("\nOptions:\n\n");
35
36 printf("  --server    SERVER    - Set server hostname\n"
37        "  --help                - Show this help\n"
38       );
39
40 printf("\nCommands:\n\n");
41 printf(
42        "  help                    - Show this help\n"
43        "  sleep TIME              - Sleeps for TIME seconds\n"
44        "  set   chan=val          - Set a DMX Channel\n"
45       );
46}
47
48int cmd_set (CONVAR, char * arg) {
49 char * next = arg;
50 char * k, * v;
51 int32_t chan, val;
52 struct roar_roardmx_message mes;
53 struct roar_vio_calls vio;
54
55 roar_roardmx_message_new_sset(&mes);
56
57 while (next != NULL) {
58  arg  = next;
59  next = strstr(next, ",");
60  if ( next != NULL ) {
61   *next = 0;
62    next++;
63  }
64
65  k = arg;
66  v = strstr(arg, "=");
67  if ( v == NULL )
68   return -1;
69
70  *v = 0;
71   v++;
72
73  chan = atoi(k);
74  val  = atoi(v);
75//  printf("k='%s'(%i), v='%s'(%i)\n", k, chan, v, val);
76  if ( roar_roardmx_message_add_chanval(&mes, chan, val) == -1 )
77   return -1;
78 }
79
80 if ( roar_vio_simple_new_stream_obj(&vio, con, NULL,
81                                     ROAR_RATE_DEFAULT, ROAR_CHANNELS_DEFAULT, ROAR_BITS_DEFAULT,
82                                     ROAR_CODEC_ROARDMX, ROAR_DIR_LIGHT_IN) == -1 )
83  return -1;
84
85 if ( roar_roardmx_message_send(&mes, &vio) == -1 ) {
86  roar_vio_close(&vio);
87  return -1;
88 }
89
90 roar_vio_close(&vio);
91
92 return 0;
93}
94
95int main (int argc, char * argv[]) {
96 char * server   = NULL;
97 char * k;
98 int    i;
99 struct roar_connection con;
100
101 for (i = 1; i < argc; i++) {
102  k = argv[i];
103
104  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
105   server = argv[++i];
106  } else if ( !strcmp(k, "--codec") ) {
107
108  } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) {
109   usage();
110   return 0;
111  } else if ( *k == '-' ) {
112   fprintf(stderr, "Error: unknown argument: %s\n", k);
113   usage();
114   return 1;
115  } else {
116   break;
117  }
118 }
119
120 if ( roar_simple_connect(&con, server, "roarlight") == -1 ) {
121  fprintf(stderr, "Error: Can not connect to server\n");
122  return 1;
123 }
124
125 if ( i == argc ) {
126  fprintf(stderr, "Error: No Commands given\n");
127  return 0; // this is not a fatal error...
128 }
129
130 for (; i < argc; i++) {
131  k = argv[i];
132  // cmd is in k
133
134  printf("--- [ %s ] ---\n", k);
135
136  if ( !strcmp(k, "help") ) {
137   usage();
138
139  } else if ( !strcmp(k, "sleep") ) {
140   sleep(atoi(argv[++i]));
141
142  } else if ( !strcmp(k, "set") ) {
143   i++;
144   if ( cmd_set(&con, argv[i]) == -1 ) {
145    fprintf(stderr, "Error: can not set channels\n");
146   } else {
147    printf("channels changed\n");
148   }
149
150  } else {
151   fprintf(stderr, "Error: invalid command: %s\n", k);
152  }
153 }
154
155 roar_disconnect(&con);
156
157 return 0;
158}
159
160//ll
Note: See TracBrowser for help on using the repository browser.