more use of the new GPIO_SUPPORT option
[openwrt.git] / package / fonera-mp3 / src / cli / main.c
1 /*
2 * FOXMP3
3 * Copyright (c) 2006 acmesystems.it - john@acmesystems.it
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
18 *
19 * Feedback, Bugs... info@acmesystems.it
20 *
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <sys/un.h>
29 #include <unistd.h>
30
31 #define SOCKET_PATH "/tmp/foxmp3"
32
33
34 void print_usage(void){
35 printf("mp3_play COMANND PARAMETERS\n");
36 printf(" Commands :\n");
37 printf(" PLAY filename\n");
38 printf(" STREAM url [URL OF STREAM]\n");
39 printf(" STREAM pls [URL PLS FILE]\n");
40 printf(" VOLUME [0-255]\n");
41 printf(" STOP\n");
42 printf(" STATE\n");
43 printf(" BASS [0-255]\n");
44 }
45
46 void issue_command(unsigned char *str){
47 int s, t, len;
48 struct sockaddr_un remote;
49
50 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
51 perror("socket");
52 exit(1);
53 }
54 printf("Connecting to mp3d ...\n");
55 remote.sun_family = AF_UNIX;
56 strcpy(remote.sun_path, SOCKET_PATH);
57 len = strlen(remote.sun_path) + sizeof(remote.sun_family);
58 if (connect(s, (struct sockaddr *)&remote, len) == -1) {
59 perror("connect");
60 exit(1);
61 }
62 printf("Connected ...\n\nSending command -> \n%s\n\n", str);
63 if (send(s, str, strlen(str), 0) == -1) {
64 perror("send");
65 exit(1);
66 }
67 unsigned char loop = 1;
68 while(loop){
69 if ((t=recv(s, str, 2048, 0)) > 0) {
70 str[t] = '\0';
71 printf("The answer was -> \n%s\n", str);
72 if((strstr(str, "OK")) || (strstr(str, "ERROR"))){
73 loop = 0;
74 }
75 } else {
76 if (t < 0){
77 perror("recv");
78 } else {
79 printf("Server closed connection\n");
80 };
81 }
82 }
83 close(s);
84 }
85
86 int main(int argc, char **argv){
87 unsigned char buffer[2048];
88 buffer[0] = '\0';
89 if(argc > 1){
90 if(((!strcmp(argv[1], "STOP")) || (!strcmp(argv[1], "STATE")))
91 && (argc == 2)){
92 sprintf(buffer, "%s", argv[1]);
93 } else if(((!strcmp(argv[1], "PLAY")) || (!strcmp(argv[1], "VOLUME"))
94 || (!strcmp(argv[1], "BASS"))) && (argc == 3)){
95 sprintf(buffer, "%s %s", argv[1], argv[2]);
96 } else if((!strcmp(argv[1], "STREAM")) && (argc == 4)
97 && ((!strcmp(argv[2], "url")) || (!strcmp(argv[2], "pls")))){
98 sprintf(buffer, "%s %s %s", argv[1], argv[2],
99 argv[3]);
100 }
101 };
102 if(buffer[0] != '\0'){
103 issue_command(buffer);
104 } else {
105 print_usage();
106 };
107 return 0;
108 }
This page took 0.051597 seconds and 5 git commands to generate.