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