source: roaraudio/roarclients/roarlight.c @ 3811:49db840fb4f4

Last change on this file since 3811:49db840fb4f4 was 3811:49db840fb4f4, checked in by phi, 14 years ago

fixed some copyright statements

File size: 3.8 KB
Line 
1//roarlight.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2010
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 int fh;                    //TODO: we should use pure VIO here
54 struct roar_vio_calls vio;
55
56 roar_roardmx_message_new_sset(&mes);
57
58 while (next != NULL) {
59  arg  = next;
60  next = strstr(next, ",");
61  if ( next != NULL ) {
62   *next = 0;
63    next++;
64  }
65
66  k = arg;
67  v = strstr(arg, "=");
68  if ( v == NULL )
69   return -1;
70
71  *v = 0;
72   v++;
73
74  chan = atoi(k);
75  val  = atoi(v);
76//  printf("k='%s'(%i), v='%s'(%i)\n", k, chan, v, val);
77  if ( roar_roardmx_message_add_chanval(&mes, chan, val) == -1 )
78   return -1;
79 }
80
81 if ( (fh = roar_simple_new_stream(con,
82                                   ROAR_RATE_DEFAULT, ROAR_CHANNELS_DEFAULT, ROAR_BITS_DEFAULT,
83                                   ROAR_CODEC_ROARDMX, ROAR_DIR_LIGHT_IN
84                                  )) == -1 )
85  return -1;
86
87 if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) {
88  close(fh);
89  return -1;
90 }
91
92 if ( roar_roardmx_message_send(&mes, &vio) == -1 ) {
93  roar_vio_close(&vio);
94  return -1;
95 }
96
97 roar_vio_close(&vio);
98
99 return 0;
100}
101
102int main (int argc, char * argv[]) {
103 char * server   = NULL;
104 char * k;
105 int    i;
106 struct roar_connection con;
107
108 for (i = 1; i < argc; i++) {
109  k = argv[i];
110
111  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
112   server = argv[++i];
113  } else if ( !strcmp(k, "--codec") ) {
114
115  } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) {
116   usage();
117   return 0;
118  } else if ( *k == '-' ) {
119   fprintf(stderr, "Error: unknown argument: %s\n", k);
120   usage();
121   return 1;
122  } else {
123   break;
124  }
125 }
126
127 if ( roar_simple_connect(&con, server, "roarlight") == -1 ) {
128  fprintf(stderr, "Error: Can not connect to server\n");
129  return 1;
130 }
131
132 if ( i == argc ) {
133  fprintf(stderr, "Error: No Commands given\n");
134  return 0; // this is not a fatal error...
135 }
136
137 for (; i < argc; i++) {
138  k = argv[i];
139  // cmd is in k
140
141  printf("--- [ %s ] ---\n", k);
142
143  if ( !strcmp(k, "help") ) {
144   usage();
145
146  } else if ( !strcmp(k, "sleep") ) {
147   sleep(atoi(argv[++i]));
148
149  } else if ( !strcmp(k, "set") ) {
150   i++;
151   if ( cmd_set(&con, argv[i]) == -1 ) {
152    fprintf(stderr, "Error: can not set channels\n");
153   } else {
154    printf("channels changed\n");
155   }
156
157  } else {
158   fprintf(stderr, "Error: invalid command: %s\n", k);
159  }
160 }
161
162 roar_disconnect(&con);
163
164 return 0;
165}
166
167//ll
Note: See TracBrowser for help on using the repository browser.