source: roaraudio/roarclients/roarlight.c @ 2046:173ee399825b

Last change on this file since 2046:173ee399825b was 2046:173ee399825b, checked in by phi, 15 years ago

added a start for a light control tool

File size: 3.3 KB
Line 
1//roarlight.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <roaraudio.h>
26#include <libroarlight/libroarlight.h>
27
28#define CONVAR struct roar_connection * con
29
30void usage (void) {
31 printf("roarlight [OPTIONS]... command [command...]\n");
32
33 printf("\nOptions:\n\n");
34
35 printf("  --server    SERVER    - Set server hostname\n"
36        "  --help                - Show this help\n"
37       );
38
39 printf("\nCommands:\n\n");
40 printf(
41        "  help                    - Show this help\n"
42        "  sleep TIME              - Sleeps for TIME seconds\n"
43        "  set   chan=val          - Set a DMX Channel\n"
44       );
45}
46
47int cmd_set (CONVAR, char * arg) {
48 char * next = arg;
49 char * k, * v;
50 int32_t chan, val;
51 struct roar_roardmx_message mes;
52
53 roar_roardmx_message_new_sset(&mes);
54
55 while (next != NULL) {
56  arg  = next;
57  next = strstr(next, ",");
58  if ( next != NULL ) {
59   *next = 0;
60    next++;
61  }
62
63  k = arg;
64  v = strstr(arg, "=");
65  if ( v == NULL )
66   return -1;
67
68  *v = 0;
69   v++;
70
71  chan = atoi(k);
72  val  = atoi(v);
73//  printf("k='%s'(%i), v='%s'(%i)\n", k, chan, v, val);
74  if ( roar_roardmx_message_add_chanval(&mes, chan, val) == -1 )
75   return -1;
76 }
77
78 return 0;
79}
80
81int main (int argc, char * argv[]) {
82 char * server   = NULL;
83 char * k;
84 int    i;
85 struct roar_connection con;
86
87 for (i = 1; i < argc; i++) {
88  k = argv[i];
89
90  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
91   server = argv[++i];
92  } else if ( !strcmp(k, "--codec") ) {
93
94  } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) {
95   usage();
96   return 0;
97  } else if ( *k == '-' ) {
98   fprintf(stderr, "Error: unknown argument: %s\n", k);
99   usage();
100   return 1;
101  } else {
102   break;
103  }
104 }
105
106 if ( roar_connect(&con, server) == -1 ) {
107  fprintf(stderr, "Error: Can not connect to server\n");
108  return 1;
109 }
110
111 if ( roar_identify(&con, "roarlight") == -1 ) {
112  fprintf(stderr, "Error: Can not identify to server\n");
113  roar_disconnect(&con);
114  return 1;
115 }
116
117 if ( i == argc ) {
118  fprintf(stderr, "Error: No Commands given\n");
119  return 0; // this is not a fatal error...
120 }
121
122 for (; i < argc; i++) {
123  k = argv[i];
124  // cmd is in k
125
126  printf("--- [ %s ] ---\n", k);
127
128  if ( !strcmp(k, "help") ) {
129   usage();
130
131  } else if ( !strcmp(k, "sleep") ) {
132   sleep(atoi(argv[++i]));
133
134  } else if ( !strcmp(k, "set") ) {
135   i++;
136   if ( cmd_set(&con, argv[i]) == -1 ) {
137    fprintf(stderr, "Error: can not set channels\n");
138   } else {
139    printf("channels changed\n");
140   }
141
142  } else {
143   fprintf(stderr, "Error: invalid command: %s\n", k);
144  }
145 }
146
147 roar_disconnect(&con);
148
149 return 0;
150}
151
152//ll
Note: See TracBrowser for help on using the repository browser.