blob: 2140e25854cbbba78ac4fb39a39bba30cb36e603 [file] [log] [blame]
b.liuf191eb72024-12-12 10:45:23 +08001#include <sys/stat.h>
2#include <unistd.h>
3#include <stdio.h>
4#include <fcntl.h>
5#include <signal.h>
6#include <stdlib.h>
7#include <string.h>
8
9#include "mbtk_rtp.h"
10#include "mbtk_log.h"
11
12
13static void help()
14{
15 printf("rtp_mode <0/1>: Disable/Enable RTP.\n");
16 printf("volume <0-7>: Set volume.\n");
17 printf("remote_ip <xxx:xxx:xxx:xxx>: Set remote ip.\n");
18 printf("client_port <port>: Set client(local) port.\n");
19 printf("server_port <port>: Set server(remote) port.\n");
20 printf("sample_rate <8000/16000>: Set sample rate.\n");
21 printf("channel <1>: Set channel.\n");
22}
23
24
25static void sig_handler(int sig)
26{
27 if(mbtk_rtp_deinit()) {
28 printf("mbtk_rtp_deinit() fail.\n");
29 }
30
31 printf("Success exit by signal...\n");
32 exit(0);
33}
34
35int main(int argc, char *argv[])
36{
37 mbtk_log_init("radio", "RTP_CLI");
38
39 if(mbtk_rtp_init()) {
40 printf("mbtk_rtp_init() fail.\n");
41 return -1;
42 }
43
44 signal(SIGINT, sig_handler);
45 signal(SIGTERM, sig_handler);
46
47 char cmd[100];
48 bool running = TRUE;
49 while(running)
50 {
51 memset(cmd, 0, 100);
52// int err;
53 // printf("0 : Disable 1 : Enable Other : Exit\n");
54 help();
55 if(fgets(cmd, 100, stdin))
56 {
57 if(cmd[0] == '\r' || cmd[0] == '\n')
58 continue;
59 char *ptr = cmd + strlen(cmd) - 1;
60 while(ptr >= cmd && (*ptr == '\r' || *ptr == '\n'))
61 {
62 *ptr-- = '\0';
63 }
64
65 if(!strncasecmp(cmd, "rtp_mode", 8))
66 {
67 int temp;
68 if(1 == sscanf(cmd, "rtp_mode %d", &temp)) {
69 if(mbtk_rtp_enable((bool)temp)) {
70 printf("Error\n");
71 } else {
72 printf("Success\n");
73 }
74 }
75 }
76 else if(!strncasecmp(cmd, "volume", 6)){
77 int temp;
78 if(1 == sscanf(cmd, "volume %d", &temp)) {
79 if(mbtk_rtp_volume_set(temp)) {
80 printf("Error\n");
81 } else {
82 printf("Success\n");
83 }
84 }
85 }
86 else if(!strncasecmp(cmd, "remote_ip", 9)){
87 char ipv4[20] = {0};
88 if(1 == sscanf(cmd, "remote_ip %s", ipv4)) {
89 if(mbtk_rtp_remote_ip_set(ipv4)) {
90 printf("Error\n");
91 } else {
92 printf("Success\n");
93 }
94 }
95 }
96 else if(!strncasecmp(cmd, "client_port", 11)){
97 int temp;
98 if(1 == sscanf(cmd, "client_port %d", &temp)) {
99 if(mbtk_rtp_client_port_set(temp)) {
100 printf("Error\n");
101 } else {
102 printf("Success\n");
103 }
104 }
105 }
106 else if(!strncasecmp(cmd, "server_port", 11)){
107 int temp;
108 if(1 == sscanf(cmd, "server_port %d", &temp)) {
109 if(mbtk_rtp_server_port_set(temp)) {
110 printf("Error\n");
111 } else {
112 printf("Success\n");
113 }
114 }
115 }
116 else if(!strncasecmp(cmd, "sample_rate", 11)){
117 int temp;
118 if(1 == sscanf(cmd, "sample_rate %d", &temp)) {
119 if(mbtk_rtp_sample_rate_set(temp)) {
120 printf("Error\n");
121 } else {
122 printf("Success\n");
123 }
124 }
125 }
126 else if(!strncasecmp(cmd, "channel", 7)){
127 int temp;
128 if(1 == sscanf(cmd, "channel %d", &temp)) {
129 if(mbtk_rtp_channel_set(temp)) {
130 printf("Error\n");
131 } else {
132 printf("Success\n");
133 }
134 }
135 }
136
137 else if(!strcasecmp(cmd, "h") || !strcasecmp(cmd, "help")) {
138 help();
139 } else if(!strcasecmp(cmd, "q")) {
140 break;
141 } else {
142 printf("\n");
143 }
144 }
145 }
146
147//exit:
148 if(mbtk_rtp_deinit()) {
149 printf("mbtk_rtp_deinit() fail.\n");
150 return -1;
151 }
152
153 printf("Success exit.\n");
154 return 0;
155}