source: roaraudio/roarclients/roarlight.c @ 5930:2c5f4164ec03

Last change on this file since 5930:2c5f4164ec03 was 5930:2c5f4164ec03, checked in by phi, 11 years ago

set another small internal update. Renamed set command to sset.

File size: 4.3 KB
Line 
1//roarlight.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2013
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
31static struct roar_connection * g_connection;
32static struct roar_vio_calls  * g_stream;
33
34static int __run_argv(int argc, char * argv[]);
35
36void usage (void) {
37 printf("roarlight [OPTIONS]... command [command...]\n");
38
39 printf("\nOptions:\n\n");
40
41 printf("  --server    SERVER    - Set server hostname\n"
42        "  --mixer     MIXERID   - ID of the light mixer to use\n"
43        "  --help                - Show this help\n"
44       );
45
46 printf("\nCommands:\n\n");
47 printf(
48        "  help                    - Show this help\n"
49        "  sleep TIME              - Sleeps for TIME seconds\n"
50        "  sset  chan=val          - Set a DMX Channel\n"
51        "  set   chan=val          - Same as sset\n"
52       );
53}
54
55static int cmd_sset (char * arg) {
56 char * next = arg;
57 char * k, * v;
58 int32_t chan, val;
59 struct roar_roardmx_message mes;
60
61 roar_roardmx_message_new_sset(&mes);
62
63 while (next != NULL) {
64  arg  = next;
65  next = strstr(next, ",");
66  if ( next != NULL ) {
67   *next = 0;
68    next++;
69  }
70
71  k = arg;
72  v = strstr(arg, "=");
73  if ( v == NULL )
74   return -1;
75
76  *v = 0;
77   v++;
78
79  chan = atoi(k);
80  val  = atoi(v);
81//  printf("k='%s'(%i), v='%s'(%i)\n", k, chan, v, val);
82  if ( roar_roardmx_message_add_chanval(&mes, chan, val) == -1 )
83   return -1;
84 }
85
86 if ( roar_roardmx_message_send(&mes, g_stream) == -1 ) {
87  return -1;
88 }
89
90 return 0;
91}
92
93static int __run_argv(int argc, char * argv[]) {
94 char * k;
95 int i;
96
97 for (i = 0; i < argc; i++) {
98  k = argv[i];
99  // cmd is in k
100
101  printf("--- [ %s ] ---\n", k);
102
103  if ( !strcmp(k, "help") ) {
104   usage();
105
106  } else if ( !strcmp(k, "sleep") ) {
107   roar_sleep(atoi(argv[++i]));
108
109  } else if ( !strcmp(k, "sset") || !strcmp(k, "set") ) {
110   i++;
111   if ( cmd_sset(argv[i]) == -1 ) {
112    fprintf(stderr, "Error: can not set channels\n");
113   } else {
114    printf("channels changed\n");
115   }
116
117  } else {
118   fprintf(stderr, "Error: invalid command: %s\n", k);
119   return 1;
120  }
121 }
122
123 return 0;
124}
125
126int main (int argc, char * argv[]) {
127 struct roar_connection con;
128 struct roar_vio_calls vio;
129 int    mixer = -1; // -1 = Default
130 const char * server   = NULL;
131 const char * k;
132 int    i;
133 int    ret;
134
135 for (i = 1; i < argc; i++) {
136  k = argv[i];
137
138  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
139   server = argv[++i];
140  } else if ( !strcmp(k, "--mixer") ) {
141   mixer = atoi(argv[++i]);
142  } else if ( !strcmp(k, "--codec") ) {
143
144  } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) {
145   usage();
146   return 0;
147  } else if ( *k == '-' ) {
148   fprintf(stderr, "Error: unknown argument: %s\n", k);
149   usage();
150   return 1;
151  } else {
152   break;
153  }
154 }
155
156 if ( i == argc ) {
157  fprintf(stderr, "Error: No Commands given\n");
158  return 0; // this is not a fatal error...
159 }
160
161 if ( roar_simple_connect(&con, server, "roarlight") == -1 ) {
162  fprintf(stderr, "Error: Can not connect to server\n");
163  return 1;
164 }
165
166 if ( roar_vio_simple_new_stream_obj(&vio, &con, NULL,
167                                     ROAR_RATE_DEFAULT, ROAR_CHANNELS_DEFAULT, ROAR_BITS_DEFAULT,
168                                     ROAR_CODEC_ROARDMX, ROAR_DIR_LIGHT_IN, mixer) == -1 ) {
169 }
170
171 g_connection = &con;
172 g_stream = &vio;
173
174 ret = __run_argv(argc - i, argv + i);
175
176 // try to flush all data:
177
178 roar_vio_sync(&vio);
179 roar_vio_close(&vio);
180 roar_usleep(100);
181
182 roar_disconnect(&con);
183
184 return ret;
185}
186
187//ll
Note: See TracBrowser for help on using the repository browser.