blob: 09a2b277186ec8ebb39cd8646af4e21098eb8c10
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | #include <string.h> |
4 | #include <android/log.h> |
5 | |
6 | #include "tvconfig_core.h" |
7 | #include "tvconfig.h" |
8 | |
9 | #define LOG_TAG "tvconfig_test" |
10 | #include "CTvLog.h" |
11 | |
12 | static int GetAudioAmplifierBiquadsDataBuffer00(int *biquad_count, int *biquad_item_count, int biquad_data_buf[]); |
13 | static int GetAudioAmplifierBiquadsDataBuffer01(int *biquad_count, int *biquad_item_count, int biquad_data_buf[]); |
14 | |
15 | static int GetTvAudioCardID(char tv_card_id_buf[]); |
16 | static int GetTvAudioCardName(char tv_card_name_buf[]); |
17 | |
18 | static int ATVGetFacRestoreChanInfo(int *chan_cnt, int *item_cnt, int chan_data_buf[]); |
19 | |
20 | static void PrintGPIOCfgData(int cfg_info_item_count, GPIOCFGInfo cfg_info_buf[]); |
21 | static int GetAudioAnalogAmplifierMuteGPIOCFG(char gpio_grp_str[], int *mute_gpio_addr, int *mute_on_val, int *mute_off_val); |
22 | static int GetAudioHeadSetMuteGPIOCFG(char gpio_grp_str[], int *mute_gpio_addr, int *mute_on_val, int *mute_off_val); |
23 | static int GetAudioAVOutMuteGPIOCFG(char gpio_grp_str[], int *mute_gpio_addr, int *mute_on_val, int *mute_off_val); |
24 | static int GetWriteProtectGPIOCFG(char gpio_grp_str[], int *protect_gpio_addr, int *protect_on_val, int *protect_off_val); |
25 | |
26 | typedef struct tagTvServerInfo { |
27 | int power_on_off_channel; |
28 | int last_source_select; |
29 | int system_language; |
30 | } TvServerInfo; |
31 | |
32 | int main(int argc, char **argv) |
33 | { |
34 | int i, j; |
35 | char key_buf[CC_CFG_KEY_STR_MAX_LEN]; |
36 | char cfg_buf[CC_CFG_VALUE_STR_MAX_LEN]; |
37 | |
38 | config_set_log_level (CC_LOG_LEVEL_ALL); |
39 | |
40 | config_init((char *) "tvconfig.conf"); |
41 | |
42 | strcpy(key_buf, "media.amplayer.enable-acodecs"); |
43 | config_get(key_buf, cfg_buf, (char *) ""); |
44 | LOGD("file(%s)'s function(%s), key string \"%s\", value string \"%s\".\n", __FILE__, "TV", key_buf, cfg_buf); |
45 | |
46 | strcpy(key_buf, "media.amplayer.enable-acodecs"); |
47 | strcpy(cfg_buf, "shorthoho"); |
48 | config_set(key_buf, cfg_buf); |
49 | |
50 | strcpy(key_buf, "media.amplayer.enable-acodecs"); |
51 | config_get(key_buf, cfg_buf, (char *) ""); |
52 | LOGD("file(%s)'s function(%s), key string \"%s\", value string \"%s\".\n", __FILE__, "TV", key_buf, cfg_buf); |
53 | |
54 | strcpy(key_buf, "media.amplayer.enable-acodecs"); |
55 | config_get(key_buf, cfg_buf, (char *) ""); |
56 | LOGD("file(%s)'s function(%s), key string \"%s\", value string \"%s\".\n", __FILE__, "TV", key_buf, cfg_buf); |
57 | |
58 | strcpy(key_buf, "media.amplayer.enable-acodecs"); |
59 | strcpy(cfg_buf, "asf,wav,aac,mp3,m4a,ape,flac,alac,hohoho"); |
60 | config_set(key_buf, cfg_buf); |
61 | |
62 | strcpy(key_buf, "media.amplayer.enable-acodecs"); |
63 | config_get(key_buf, cfg_buf, (char *) ""); |
64 | LOGD("file(%s)'s function(%s), key string \"%s\", value string \"%s\".\n", __FILE__, "TV", key_buf, cfg_buf); |
65 | |
66 | strcpy(key_buf, "shoufu.zhao.test"); |
67 | config_get(key_buf, cfg_buf, (char *) ""); |
68 | LOGD("file(%s)'s function(%s), key string \"%s\", value string \"%s\".\n", __FILE__, "TV", key_buf, cfg_buf); |
69 | |
70 | strcpy(key_buf, "shoufu.zhao.test"); |
71 | strcpy(cfg_buf, "test hohoho"); |
72 | config_set(key_buf, cfg_buf); |
73 | |
74 | strcpy(key_buf, "shoufu.zhao.test"); |
75 | config_get(key_buf, cfg_buf, (char *) ""); |
76 | LOGD("file(%s)'s function(%s), key string \"%s\", value string \"%s\".\n", __FILE__, "TV", key_buf, cfg_buf); |
77 | |
78 | int biquad_count = 0, biquad_item_count = 0; |
79 | int biquad_data_buf00[128] = { 0 }; |
80 | int biquad_data_buf01[128] = { 0 }; |
81 | |
82 | GetAudioAmplifierBiquadsDataBuffer00(&biquad_count, &biquad_item_count, biquad_data_buf00); |
83 | for (i = 0; i < biquad_count; i++) { |
84 | for (j = 0; j < biquad_item_count; j++) { |
85 | LOGD("0x%x\n", biquad_data_buf00[i * biquad_item_count + j]); |
86 | } |
87 | |
88 | LOGD("\n"); |
89 | } |
90 | |
91 | GetAudioAmplifierBiquadsDataBuffer01(&biquad_count, &biquad_item_count, biquad_data_buf01); |
92 | for (i = 0; i < biquad_count; i++) { |
93 | for (j = 0; j < biquad_item_count; j++) { |
94 | LOGD("0x%x\n", biquad_data_buf01[i * biquad_item_count + j]); |
95 | } |
96 | |
97 | LOGD("\n"); |
98 | } |
99 | |
100 | char tv_card_id_buf[64] = { 0 }; |
101 | char tv_card_name_buf[64] = { 0 }; |
102 | |
103 | GetTvAudioCardID(tv_card_id_buf); |
104 | |
105 | GetTvAudioCardName(tv_card_name_buf); |
106 | |
107 | printf("tvservice log cfg value = %d\n", config_log_cfg_get(CC_LOG_MODULE_TVSERVICE)); |
108 | printf("vpp log cfg value = %d\n", config_log_cfg_get(CC_LOG_MODULE_VPP)); |
109 | |
110 | int chan_cnt = 0, item_cnt = 0; |
111 | int chan_data_buf[256] = { 0 }; |
112 | |
113 | ATVGetFacRestoreChanInfo(&chan_cnt, &item_cnt, chan_data_buf); |
114 | |
115 | for (i = 0; i < chan_cnt; i++) { |
116 | for (j = 0; j < item_cnt; j++) { |
117 | LOGD("%d\n", chan_data_buf[i * item_cnt + j]); |
118 | } |
119 | |
120 | LOGD("\n"); |
121 | } |
122 | |
123 | char gpio_grp_str[32] = { 0 }; |
124 | int gpio_addr, gpio_on_val; |
125 | |
126 | int cfg_info_item_count = 0; |
127 | GPIOCFGInfo cfg_info_buf[64]; |
128 | |
129 | if (cfg_get_one_gpio_data("audio.avout.mute.gpio", gpio_grp_str, &gpio_addr, &gpio_on_val) == 0) { |
130 | cfg_info_item_count = 1; |
131 | |
132 | strcpy(cfg_info_buf[0].gpio_grp_str, gpio_grp_str); |
133 | cfg_info_buf[0].gpio_addr = gpio_addr; |
134 | cfg_info_buf[0].gpio_val = gpio_on_val; |
135 | |
136 | PrintGPIOCfgData(cfg_info_item_count, &cfg_info_buf[0]); |
137 | } |
138 | |
139 | if (cfg_get_gpio_data("audio.avout.mute.gpio", &cfg_info_item_count, cfg_info_buf) == 0) { |
140 | PrintGPIOCfgData(cfg_info_item_count, cfg_info_buf); |
141 | } |
142 | |
143 | cfg_info_item_count = 64; |
144 | if (cfg_get_gpio_data("audio.initaudio.gpioctl", &cfg_info_item_count, cfg_info_buf) == 0) { |
145 | PrintGPIOCfgData(cfg_info_item_count, cfg_info_buf); |
146 | } |
147 | |
148 | char tmp_buf[32] = { 0 }; |
149 | int mute_gpio_addr, mute_on_gpio_val, mute_off_gpio_val; |
150 | |
151 | if (GetAudioAnalogAmplifierMuteGPIOCFG(gpio_grp_str, &mute_gpio_addr, &mute_on_gpio_val, &mute_off_gpio_val) == 0) { |
152 | sprintf(tmp_buf, "w %s %d %d", gpio_grp_str, mute_gpio_addr, mute_on_gpio_val); |
153 | LOGD("%s, mute on write command %s\n", "GetAudioAnalogAmplifierMuteGPIOCFG", tmp_buf); |
154 | |
155 | sprintf(tmp_buf, "w %s %d %d", gpio_grp_str, mute_gpio_addr, mute_off_gpio_val); |
156 | LOGD("%s, mute off write command %s\n", "GetAudioAnalogAmplifierMuteGPIOCFG", tmp_buf); |
157 | } |
158 | |
159 | if (GetAudioHeadSetMuteGPIOCFG(gpio_grp_str, &mute_gpio_addr, &mute_on_gpio_val, &mute_off_gpio_val) == 0) { |
160 | sprintf(tmp_buf, "w %s %d %d", gpio_grp_str, mute_gpio_addr, mute_on_gpio_val); |
161 | LOGD("%s, mute on write command %s\n", "GetAudioHeadSetMuteGPIOCFG", tmp_buf); |
162 | |
163 | sprintf(tmp_buf, "w %s %d %d", gpio_grp_str, mute_gpio_addr, mute_off_gpio_val); |
164 | LOGD("%s, mute off write command %s\n", "GetAudioHeadSetMuteGPIOCFG", tmp_buf); |
165 | } |
166 | |
167 | if (GetAudioAVOutMuteGPIOCFG(gpio_grp_str, &mute_gpio_addr, &mute_on_gpio_val, &mute_off_gpio_val) == 0) { |
168 | sprintf(tmp_buf, "w %s %d %d", gpio_grp_str, mute_gpio_addr, mute_on_gpio_val); |
169 | LOGD("%s, mute on write command %s\n", "GetAudioAVOutMuteGPIOCFG", tmp_buf); |
170 | |
171 | sprintf(tmp_buf, "w %s %d %d", gpio_grp_str, mute_gpio_addr, mute_off_gpio_val); |
172 | LOGD("%s, mute off write command %s\n", "GetAudioAVOutMuteGPIOCFG", tmp_buf); |
173 | } |
174 | |
175 | if (GetWriteProtectGPIOCFG(gpio_grp_str, &mute_gpio_addr, &mute_on_gpio_val, &mute_off_gpio_val) == 0) { |
176 | sprintf(tmp_buf, "w %s %d %d", gpio_grp_str, mute_gpio_addr, mute_on_gpio_val); |
177 | LOGD("%s, protect on write command %s\n", "GetWriteProtectGPIOCFG", tmp_buf); |
178 | |
179 | sprintf(tmp_buf, "w %s %d %d", gpio_grp_str, mute_gpio_addr, mute_off_gpio_val); |
180 | LOGD("%s, protect off write command %s\n", "GetWriteProtectGPIOCFG", tmp_buf); |
181 | } |
182 | |
183 | tmpInfo.power_on_off_channel = 0; |
184 | tmpInfo.last_source_select = 0; |
185 | tmpInfo.system_language = 1; |
186 | |
187 | for (i = 0; i < 12; i++) { |
188 | tmpInfo.last_source_select = i; |
189 | } |
190 | |
191 | char item_buf[128] = { 0 }; |
192 | |
193 | for (i = 0; i < 16; i++) { |
194 | cfg_get_one_item("misc.lastselsrc.show.cfg", i, item_buf); |
195 | LOGD("item %d = %s\n", i, item_buf); |
196 | } |
197 | |
198 | config_uninit(); |
199 | |
200 | LOGD("file(%s)'s function(%s) exiting.\n", __FILE__, "TV"); |
201 | return 0; |
202 | } |
203 | |
204 | static int RealGetAudioAmplifierBiquadsDataBuffer(const char *key_str, int *biquad_count, int *biquad_item_count, int biquad_data_buf[]) |
205 | { |
206 | int cfg_item_count = 0, tmpTotalItemCount = 0; |
207 | char *token = NULL; |
208 | const char *strDelimit = ","; |
209 | char prop_value[CC_CFG_VALUE_STR_MAX_LEN]; |
210 | |
211 | memset(prop_value, '\0', CC_CFG_VALUE_STR_MAX_LEN); |
212 | |
213 | config_get(key_str, prop_value, "null"); |
214 | if (strcasecmp(prop_value, "null") == 0) { |
215 | LOGE("%s, can't get config \"%s\"!!!\n", "TV", key_str); |
216 | *biquad_count = 0; |
217 | *biquad_item_count = 0; |
218 | return -1; |
219 | } |
220 | |
221 | tmpTotalItemCount = 0; |
222 | |
223 | token = strtok(prop_value, strDelimit); |
224 | while (token != NULL) { |
225 | if (cfg_item_count == 0) { |
226 | *biquad_count = strtoul(token, NULL, 16); |
227 | } else if (cfg_item_count == 1) { |
228 | *biquad_item_count = strtoul(token, NULL, 16); |
229 | } else if (cfg_item_count >= 2) { |
230 | biquad_data_buf[tmpTotalItemCount] = strtoul(token, NULL, 16); |
231 | tmpTotalItemCount += 1; |
232 | } |
233 | |
234 | token = strtok(NULL, strDelimit); |
235 | cfg_item_count += 1; |
236 | } |
237 | |
238 | if ((*biquad_count) * (*biquad_item_count) != tmpTotalItemCount) { |
239 | LOGE("%s, get item count error!!! should be %d, real is %d.\n", "TV", (*biquad_count) * (*biquad_item_count), tmpTotalItemCount); |
240 | *biquad_count = 0; |
241 | *biquad_item_count = 0; |
242 | return -1; |
243 | } |
244 | |
245 | LOGD("%s, biquad count = %d, biquad item count = %d.\n", "TV", *biquad_count, *biquad_item_count); |
246 | |
247 | return 0; |
248 | } |
249 | |
250 | static int GetAudioAmplifierBiquadsDataBuffer00(int *biquad_count, int *biquad_item_count, int biquad_data_buf[]) |
251 | { |
252 | return RealGetAudioAmplifierBiquadsDataBuffer("audio.amplifier.biquad00.data", biquad_count, biquad_item_count, biquad_data_buf); |
253 | } |
254 | |
255 | static int GetAudioAmplifierBiquadsDataBuffer01(int *biquad_count, int *biquad_item_count, int biquad_data_buf[]) |
256 | { |
257 | return RealGetAudioAmplifierBiquadsDataBuffer("audio.amplifier.biquad01.data", biquad_count, biquad_item_count, biquad_data_buf); |
258 | } |
259 | |
260 | static int GetTvAudioCardID(char tv_card_id_buf[]) |
261 | { |
262 | config_get("audio.tv.card.id", tv_card_id_buf, "null"); |
263 | LOGD("%s, get card id is \"%s\".\n", "TV", tv_card_id_buf); |
264 | |
265 | if (strcmp(tv_card_id_buf, "null") == 0) { |
266 | strcpy(tv_card_id_buf, "hw:AMLM2"); |
267 | LOGD("%s, card id not config, we set to default \"%s\".\n", "TV", "hw:AMLM2"); |
268 | } |
269 | |
270 | return 0; |
271 | } |
272 | |
273 | static int GetTvAudioCardName(char tv_card_name_buf[]) |
274 | { |
275 | config_get("audio.tv.card.name", tv_card_name_buf, "null"); |
276 | LOGD("%s, get card name is \"%s\".\n", "TV", tv_card_name_buf); |
277 | |
278 | if (strcmp(tv_card_name_buf, "null") == 0) { |
279 | strcpy(tv_card_name_buf, "AML-M2"); |
280 | LOGD("%s, card name not config, we set to default \"%s\".\n", "TV", "AML-M2"); |
281 | } |
282 | |
283 | return 0; |
284 | } |
285 | |
286 | static int ATVGetFacRestoreChanInfo(int *chan_cnt, int *item_cnt, int chan_data_buf[]) |
287 | { |
288 | int cfg_item_count = 0, tmpTotalItemCount = 0; |
289 | char *token = NULL; |
290 | const char *strDelimit = ","; |
291 | const char *key_str = "atv.fac.defchaninfo"; |
292 | char prop_value[CC_CFG_VALUE_STR_MAX_LEN]; |
293 | |
294 | memset(prop_value, '\0', CC_CFG_VALUE_STR_MAX_LEN); |
295 | |
296 | config_get(key_str, prop_value, "null"); |
297 | if (strcasecmp(prop_value, "null") == 0) { |
298 | LOGE("%s, can't get config \"%s\"!!!\n", "TV", key_str); |
299 | *chan_cnt = 0; |
300 | *item_cnt = 0; |
301 | return -1; |
302 | } |
303 | |
304 | tmpTotalItemCount = 0; |
305 | |
306 | token = strtok(prop_value, strDelimit); |
307 | while (token != NULL) { |
308 | if (cfg_item_count == 0) { |
309 | *chan_cnt = strtoul(token, NULL, 10); |
310 | } else if (cfg_item_count == 1) { |
311 | *item_cnt = strtoul(token, NULL, 10); |
312 | } else if (cfg_item_count >= 2) { |
313 | chan_data_buf[tmpTotalItemCount] = strtoul(token, NULL, 10); |
314 | tmpTotalItemCount += 1; |
315 | } |
316 | |
317 | token = strtok(NULL, strDelimit); |
318 | cfg_item_count += 1; |
319 | } |
320 | |
321 | if ((*chan_cnt) * (*item_cnt) != tmpTotalItemCount) { |
322 | LOGE("%s, get item count error!!! should be %d, real is %d.\n", "TV", (*chan_cnt) * (*item_cnt), tmpTotalItemCount); |
323 | *chan_cnt = 0; |
324 | *item_cnt = 0; |
325 | return -1; |
326 | } |
327 | |
328 | LOGD("%s, channel count = %d, channel item count = %d.\n", "TV", *chan_cnt, *item_cnt); |
329 | |
330 | return 0; |
331 | } |
332 | |
333 | static void PrintGPIOCfgData(int cfg_info_item_count, GPIOCFGInfo cfg_info_buf[]) |
334 | { |
335 | int i = 0; |
336 | |
337 | LOGD("%s, cfg_info_item_count = %d\n", "TV", cfg_info_item_count); |
338 | |
339 | for (i = 0; i < cfg_info_item_count; i++) { |
340 | LOGD("%s, %s %d %d %d\n", "TV", cfg_info_buf[i].gpio_grp_str, cfg_info_buf[i].gpio_addr, cfg_info_buf[i].gpio_val, !cfg_info_buf[i].gpio_val); |
341 | } |
342 | |
343 | LOGD("\n"); |
344 | } |
345 | |
346 | static int GetWriteProtectGPIOCFG(char gpio_grp_str[], int *protect_gpio_addr, int *protect_on_val, int *protect_off_val) |
347 | { |
348 | if (cfg_get_one_gpio_data("ssm.writeprotect.gpio", gpio_grp_str, protect_gpio_addr, protect_on_val) < 0) { |
349 | return -1; |
350 | } |
351 | |
352 | *protect_off_val = !(*protect_on_val); |
353 | |
354 | return 0; |
355 | } |
356 | |
357 | #define CC_AMPLIFIER_ANALOG_MUTE_GPIO_CFG_NAME "audio.amp.analog.mute.gpio" |
358 | #define CC_HEADSET_MUTE_GPIO_CFG_NAME "audio.headset.mute.gpio" |
359 | #define CC_AVOUT_MUTE_GPIO_CFG_NAME "audio.avout.mute.gpio" |
360 | |
361 | static int GetAudioAnalogAmplifierMuteGPIOCFG(char gpio_grp_str[], int *mute_gpio_addr, int *mute_on_val, int *mute_off_val) |
362 | { |
363 | if (cfg_get_one_gpio_data(CC_AMPLIFIER_ANALOG_MUTE_GPIO_CFG_NAME, gpio_grp_str, mute_gpio_addr, mute_on_val) < 0) { |
364 | return -1; |
365 | } |
366 | |
367 | *mute_off_val = !(*mute_on_val); |
368 | |
369 | return 0; |
370 | } |
371 | |
372 | static int GetAudioHeadSetMuteGPIOCFG(char gpio_grp_str[], int *mute_gpio_addr, int *mute_on_val, int *mute_off_val) |
373 | { |
374 | if (cfg_get_one_gpio_data(CC_HEADSET_MUTE_GPIO_CFG_NAME, gpio_grp_str, mute_gpio_addr, mute_on_val) < 0) { |
375 | return -1; |
376 | } |
377 | |
378 | *mute_off_val = !(*mute_on_val); |
379 | |
380 | return 0; |
381 | } |
382 | |
383 | static int GetAudioAVOutMuteGPIOCFG(char gpio_grp_str[], int *mute_gpio_addr, int *mute_on_val, int *mute_off_val) |
384 | { |
385 | if (cfg_get_one_gpio_data(CC_AVOUT_MUTE_GPIO_CFG_NAME, gpio_grp_str, mute_gpio_addr, mute_on_val) < 0) { |
386 | return -1; |
387 | } |
388 | |
389 | //Some projects has been volume production. They may not use the newest code, so we do compatible for old config. |
390 | //old config 69,0,1 |
391 | //new config x,69,0 |
392 | |
393 | if (gpio_grp_str[0] != 'x' || gpio_grp_str[0] != 'b' || gpio_grp_str[0] != 'd') { |
394 | *mute_gpio_addr = strtol(gpio_grp_str, NULL, 10); |
395 | gpio_grp_str[0] = 'x'; |
396 | gpio_grp_str[1] = '\0'; |
397 | *mute_off_val = *mute_on_val; |
398 | *mute_on_val = !(*mute_off_val); |
399 | } else { |
400 | *mute_off_val = !(*mute_on_val); |
401 | } |
402 | |
403 | return 0; |
404 | } |
405 | |
406 | #define PROPERTY_VALUE_MAX (92) |
407 | |
408 | typedef enum tvin_source_input_e { |
409 | SOURCE_TV, |
410 | SOURCE_AV1, |
411 | SOURCE_AV2, |
412 | SOURCE_YPBPR1, |
413 | SOURCE_YPBPR2, |
414 | SOURCE_HDMI1, |
415 | SOURCE_HDMI2, |
416 | SOURCE_HDMI3, |
417 | SOURCE_VGA, |
418 | SOURCE_MPEG, |
419 | SOURCE_DTV, |
420 | SOURCE_MAX, |
421 | } tv_source_input_t; |
422 | |
423 | static int property_set(const char *key_value, char *prop_value) |
424 | { |
425 | LOGD("%s, %s = %s\n", "TV", key_value, prop_value); |
426 | return 0; |
427 | } |
428 |