[2046] | 1 | //roarlight.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5823] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2013 |
---|
[2046] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[2046] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include <roaraudio.h> |
---|
| 27 | #include <libroarlight/libroarlight.h> |
---|
| 28 | |
---|
| 29 | #define CONVAR struct roar_connection * con |
---|
| 30 | |
---|
[5929] | 31 | static struct roar_connection * g_connection; |
---|
| 32 | static struct roar_vio_calls * g_stream; |
---|
| 33 | |
---|
| 34 | static int __run_argv(int argc, char * argv[]); |
---|
| 35 | |
---|
[2046] | 36 | void usage (void) { |
---|
| 37 | printf("roarlight [OPTIONS]... command [command...]\n"); |
---|
| 38 | |
---|
| 39 | printf("\nOptions:\n\n"); |
---|
| 40 | |
---|
| 41 | printf(" --server SERVER - Set server hostname\n" |
---|
[5289] | 42 | " --mixer MIXERID - ID of the light mixer to use\n" |
---|
[2046] | 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" |
---|
[5930] | 50 | " sset chan=val - Set a DMX Channel\n" |
---|
| 51 | " set chan=val - Same as sset\n" |
---|
[2046] | 52 | ); |
---|
| 53 | } |
---|
| 54 | |
---|
[5930] | 55 | static int cmd_sset (char * arg) { |
---|
[2046] | 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 | |
---|
[5929] | 86 | if ( roar_roardmx_message_send(&mes, g_stream) == -1 ) { |
---|
[2048] | 87 | return -1; |
---|
| 88 | } |
---|
| 89 | |
---|
[5929] | 90 | return 0; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | static 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 | |
---|
[5930] | 109 | } else if ( !strcmp(k, "sset") || !strcmp(k, "set") ) { |
---|
[5929] | 110 | i++; |
---|
[5930] | 111 | if ( cmd_sset(argv[i]) == -1 ) { |
---|
[5929] | 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 | } |
---|
[2048] | 122 | |
---|
[2046] | 123 | return 0; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | int main (int argc, char * argv[]) { |
---|
[5289] | 127 | struct roar_connection con; |
---|
[5929] | 128 | struct roar_vio_calls vio; |
---|
[5289] | 129 | int mixer = -1; // -1 = Default |
---|
[5534] | 130 | const char * server = NULL; |
---|
| 131 | const char * k; |
---|
[2046] | 132 | int i; |
---|
[5929] | 133 | int ret; |
---|
[2046] | 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]; |
---|
[5289] | 140 | } else if ( !strcmp(k, "--mixer") ) { |
---|
| 141 | mixer = atoi(argv[++i]); |
---|
[2046] | 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 | |
---|
[5929] | 161 | if ( roar_simple_connect(&con, server, "roarlight") == -1 ) { |
---|
| 162 | fprintf(stderr, "Error: Can not connect to server\n"); |
---|
| 163 | return 1; |
---|
| 164 | } |
---|
[2046] | 165 | |
---|
[5929] | 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 | } |
---|
[2046] | 170 | |
---|
[5929] | 171 | g_connection = &con; |
---|
| 172 | g_stream = &vio; |
---|
| 173 | |
---|
| 174 | ret = __run_argv(argc - i, argv + i); |
---|
[2046] | 175 | |
---|
[5929] | 176 | // try to flush all data: |
---|
| 177 | |
---|
| 178 | roar_vio_sync(&vio); |
---|
| 179 | roar_vio_close(&vio); |
---|
| 180 | roar_usleep(100); |
---|
[2046] | 181 | |
---|
| 182 | roar_disconnect(&con); |
---|
| 183 | |
---|
[5929] | 184 | return ret; |
---|
[2046] | 185 | } |
---|
| 186 | |
---|
| 187 | //ll |
---|