1 | //roarlight.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2012 |
---|
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 | |
---|
31 | void 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 | " --mixer MIXERID - ID of the light mixer to use\n" |
---|
38 | " --help - Show this help\n" |
---|
39 | ); |
---|
40 | |
---|
41 | printf("\nCommands:\n\n"); |
---|
42 | printf( |
---|
43 | " help - Show this help\n" |
---|
44 | " sleep TIME - Sleeps for TIME seconds\n" |
---|
45 | " set chan=val - Set a DMX Channel\n" |
---|
46 | ); |
---|
47 | } |
---|
48 | |
---|
49 | int cmd_set (CONVAR, char * arg, const int mixer) { |
---|
50 | char * next = arg; |
---|
51 | char * k, * v; |
---|
52 | int32_t chan, val; |
---|
53 | struct roar_roardmx_message mes; |
---|
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 ( roar_vio_simple_new_stream_obj(&vio, con, NULL, |
---|
82 | ROAR_RATE_DEFAULT, ROAR_CHANNELS_DEFAULT, ROAR_BITS_DEFAULT, |
---|
83 | ROAR_CODEC_ROARDMX, ROAR_DIR_LIGHT_IN, mixer) == -1 ) |
---|
84 | return -1; |
---|
85 | |
---|
86 | if ( roar_roardmx_message_send(&mes, &vio) == -1 ) { |
---|
87 | roar_vio_close(&vio); |
---|
88 | return -1; |
---|
89 | } |
---|
90 | |
---|
91 | roar_vio_close(&vio); |
---|
92 | |
---|
93 | return 0; |
---|
94 | } |
---|
95 | |
---|
96 | int main (int argc, char * argv[]) { |
---|
97 | struct roar_connection con; |
---|
98 | int mixer = -1; // -1 = Default |
---|
99 | char * server = NULL; |
---|
100 | char * k; |
---|
101 | int i; |
---|
102 | |
---|
103 | for (i = 1; i < argc; i++) { |
---|
104 | k = argv[i]; |
---|
105 | |
---|
106 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
107 | server = argv[++i]; |
---|
108 | } else if ( !strcmp(k, "--mixer") ) { |
---|
109 | mixer = atoi(argv[++i]); |
---|
110 | } else if ( !strcmp(k, "--codec") ) { |
---|
111 | |
---|
112 | } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) { |
---|
113 | usage(); |
---|
114 | return 0; |
---|
115 | } else if ( *k == '-' ) { |
---|
116 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
117 | usage(); |
---|
118 | return 1; |
---|
119 | } else { |
---|
120 | break; |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | if ( roar_simple_connect(&con, server, "roarlight") == -1 ) { |
---|
125 | fprintf(stderr, "Error: Can not connect to server\n"); |
---|
126 | return 1; |
---|
127 | } |
---|
128 | |
---|
129 | if ( i == argc ) { |
---|
130 | fprintf(stderr, "Error: No Commands given\n"); |
---|
131 | return 0; // this is not a fatal error... |
---|
132 | } |
---|
133 | |
---|
134 | for (; i < argc; i++) { |
---|
135 | k = argv[i]; |
---|
136 | // cmd is in k |
---|
137 | |
---|
138 | printf("--- [ %s ] ---\n", k); |
---|
139 | |
---|
140 | if ( !strcmp(k, "help") ) { |
---|
141 | usage(); |
---|
142 | |
---|
143 | } else if ( !strcmp(k, "sleep") ) { |
---|
144 | roar_sleep(atoi(argv[++i])); |
---|
145 | |
---|
146 | } else if ( !strcmp(k, "set") ) { |
---|
147 | i++; |
---|
148 | if ( cmd_set(&con, argv[i], mixer) == -1 ) { |
---|
149 | fprintf(stderr, "Error: can not set channels\n"); |
---|
150 | } else { |
---|
151 | printf("channels changed\n"); |
---|
152 | } |
---|
153 | |
---|
154 | } else { |
---|
155 | fprintf(stderr, "Error: invalid command: %s\n", k); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | roar_disconnect(&con); |
---|
160 | |
---|
161 | return 0; |
---|
162 | } |
---|
163 | |
---|
164 | //ll |
---|