blob: 06b57d4ab07104f2a6bdadc5180673bf4e0f386b [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <stdio.h>
2#include <stdlib.h>
3#include <fcntl.h>
4#include <stdarg.h>
5#include <string.h>
6#include <errno.h>
7#include <unistd.h>
8#include <sys/ioctl.h>
9#include <sys/mman.h>
10#include <sys/time.h>
11#include <linux/ioctl.h>
12
13
14typedef enum
15{
16 VP_PATH_HANDSET =0,
17 VP_PATH_SPEAKER,
18 VP_PATH_HEADSET,
19 VP_PATH_BLUETOOTH,
20 VP_PATH_BLUETOOTH_NO_NR,
21 VP_PATH_HSANDSPK,
22
23 VP_PATH_OFF = 255,
24
25 MAX_VP_PATH = VP_PATH_OFF
26}T_ZDrv_VpPath;
27
28typedef enum
29{
30 VP_VOL_0 =0,
31 VP_VOL_1,
32 VP_VOL_2,
33 VP_VOL_3,
34 VP_VOL_4,
35 VP_VOL_5,
36 VP_VOL_6,
37 VP_VOL_7,
38 VP_VOL_8,
39 VP_VOL_9,
40 VP_VOL_10,
41 VP_VOL_11,
42
43 MAX_VP_VOL
44}T_ZDrv_VpVol;
45
46typedef enum
47{
48 VOICE_GSM_MODE = 0,
49 VOICE_TD_MODE ,
50 VOICE_WCDMA_MODE,
51 VOICE_LTE_MODE,
52 VOICE_GSM_TD_MODE,//GSM TD share
53 VOICE_GSM_WCDMA_MODE, //GSM WCDMA share
54 MAX_VOICE_MODE
55} T_ZDrvVoice_MODE;
56
57typedef struct testnxp{
58 int fs;
59 int voicemode;
60 int vp_path;
61 int vp_vol;
62 int framecount;
63}T_TestNxp;
64
65#define TESTNXP_IOCTL_RXIN_TO_RXOUT_START _IOW('N', 1, T_TestNxp)
66#define TESTNXP_IOCTL_RXIN_TO_RXOUT_STOP _IO('N', 2)
67
68#define MAX_NXP_BUF 640
69
70static char *TESTNXP_DeviceName = (char *)"/dev/testnxp_dev";
71
72int main(int argc, char** argv)
73{
74 int fd = -1;
75 FILE *file_rxin, *file_rxout;
76 T_TestNxp nxp_param = {8000, VOICE_GSM_MODE, VP_PATH_HANDSET, VP_VOL_4, 160};
77 int size = 0, num_read = 0;
78 char buffer[640] = {0};
79 char *filename;
80
81 if (argc < 2) {
82 fprintf(stderr, "Usage: %s filename_in filename_out [-f fs] [-m voicemode 0:gsm 2:wcdma 3:lte] [-p path 0:handset 1:spk 2:headset] [-v vol]\n", argv[0]);
83 return -1;
84 }
85
86 printf("nxp_test open 1\n");
87
88 filename = argv[1];
89 file_rxin = fopen(filename, "rb");
90 if (!file_rxin) {
91 fprintf(stderr, "Unable to open file '%s'\n", argv[1]);
92 return -1;
93 }
94 printf("nxp_test open 2\n");
95
96 file_rxout = fopen(argv[2], "wb");
97 if (!file_rxout) {
98 fprintf(stderr, "Unable to create file '%s'\n", argv[2]);
99 fclose(file_rxin);
100 return -1;
101 }
102
103 argv += 3;
104 while (*argv) {
105 if (strcmp(*argv, "-f") == 0) {
106 argv++;
107 if (*argv)
108 nxp_param.fs = atoi(*argv);
109 }
110 if (strcmp(*argv, "-m") == 0) {
111 argv++;
112 if (*argv)
113 nxp_param.voicemode = atoi(*argv);
114 }
115 if (strcmp(*argv, "-p") == 0) {
116 argv++;
117 if (*argv)
118 nxp_param.vp_path = atoi(*argv);
119 }
120 if (strcmp(*argv, "-v") == 0) {
121 argv++;
122 if (*argv)
123 nxp_param.vp_vol = atoi(*argv);
124 }
125 if (*argv)
126 argv++;
127 }
128
129 printf("nxp_test open 3\n");
130 fd = open(TESTNXP_DeviceName, O_RDWR);
131 if(fd < 0)
132 {
133 printf("audiostart: open device error.\n");
134 fclose(file_rxin);
135 fclose(file_rxout);
136 return -1;
137 }
138
139 printf("nxp_test open 4\n");
140
141 if (nxp_param.fs = 8000)
142 nxp_param.framecount = 160;
143 else if(nxp_param.fs = 16000)
144 nxp_param.framecount = 320;
145 size = nxp_param.framecount * 2;
146
147 if (ioctl(fd, TESTNXP_IOCTL_RXIN_TO_RXOUT_START, &nxp_param))
148 {
149 printf("testnxp: TESTNXP_IOCTL_RXIN_TO_RXOUT error.\n");
150 close(fd);
151 fclose(file_rxin);
152 fclose(file_rxout);
153 return -1;
154 }
155
156 do {
157 num_read = fread(buffer, 1, size, file_rxin);
158 if (num_read > 0) {
159 write(fd, buffer, num_read);
160 read(fd, buffer, num_read);
161 fwrite(buffer, 1, num_read, file_rxout);
162 }
163 } while (num_read > 0);
164
165 ioctl(fd, TESTNXP_IOCTL_RXIN_TO_RXOUT_STOP, NULL);
166
167 close(fd);
168 fclose(file_rxin);
169 fclose(file_rxout);
170 return 0;
171}