blob: 38839eba21d7f51bf33a1cabc10e737e97fa8337 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/**
2 *
3 * @file amt_agent_devicetest.c
4 * @brief
5 * This file is part of FTM.
6 * AMT´úÀíÓ¦Óòã
7 *
8 * @details
9 * @author Tools Team.
10 * @email
11 * @copyright Copyright (C) 2013 Sanechips Technology Co., Ltd.
12 * @warning
13 * @date 2019/02/02
14 * @version 1.1
15 * @pre
16 * @post
17 *
18 * @par
19 * Change History :
20 * ---------------------------------------------------------------------------
21 * date version author description
22 * ---------------------------------------------------------------------------
23 * 2018/10/12 1.0 liu.xin Create file
24 * 2019/02/02 1.1 jiang.fenglin ÐÞ¸Ä×¢ÊÍ·½Ê½Îªdoxygen
25 * ---------------------------------------------------------------------------
26 *
27 *
28 */
29
30
31//#include "oss_api.h"
32#include "amt_agent_devicetest.h"
33#include <stdlib.h>
34#include <stdio.h>
35#include <string.h>
36#include <sys/msg.h>
37#include "amt.h"
38#include "softap_api.h"
39#include "other_msg.h"
40//#include "os_type.h"
41#include "battery.h"
42#ifdef _USE_VOICE_SUPPORT
43#include <tinyalsa/asoundlib.h>
44#include <tinyalsa/audio_mixer_ctrl.h>
45#endif
46#include <stdint.h>
47#include <errno.h>
48#include "2k_8000.h"
49#include <pthread.h>
50#include <unistd.h>
51#include <stdbool.h>
52#include <fcntl.h>
53#include <signal.h>
54#include <sys/mman.h>
55#include <math.h>
56
57
58#ifdef FILE
59#undef FILE
60#endif
61#define FILE VOID
62//#define NULL 0
63typedef unsigned int size_t ;
64
65////test
66typedef struct
67{
68 double freqValue;
69 double freqAmp;
70}zDrvVp_Freqfft;
71
72extern int cal_freq_fft(short *data,zDrvVp_Freqfft *freqfft,unsigned short n, int fs);
73extern int get_audioloop_result(FILE* file, int sampfs);
74
75#ifdef _USE_VOICE_SUPPORT
76
77static pthread_t ca_thread_tid;
78static pthread_t pb_thread_tid;
79static int cap_running = 0;
80static FILE *file = NULL;
81static struct pcm *cap_pcm, *pb_pcm;
82
83void* audio_ca_thread(void* arg)
84{
85 struct mixer *mixer;
86 struct pcm_config config;
87 // struct pcm *cap_pcm, *pb_pcm;
88 char *buffer;
89 unsigned int size;
90 unsigned int bytes_read = 0;
91 // FILE *file;
92 //int num_read;
93
94 UNUSED(arg);
95
96 mixer = mixer_open(0);
97 mix_set_input_path(mixer, T_INPUT_MICLP);
98 mix_set_input_vol(mixer, T_AUDIO_INPUT_VOL_LEVEL_11);
99 mixer_close(mixer);
100
101 memset(&config, 0, sizeof(config));
102 config.channels = 1;
103 config.rate = 8000;
104 config.period_size = 320;
105 config.period_count = 3;
106 config.format = PCM_FORMAT_S16_LE;
107 config.start_threshold = 0;
108 config.stop_threshold = 0;
109 config.silence_threshold = 0;
110
111 file = fopen("/mnt/userdata/cache/cap.bin", "wb+");
112 if (!file) {
113 AmtPrintf(AMT_ERROR "Unable to create file cap.bin\n");
114 return NULL;
115 }
116
117 cap_pcm = pcm_open(0, 0, PCM_IN, &config);
118 if (/*!cap_pcm || */!pcm_is_ready(cap_pcm)) {
119 AmtPrintf(AMT_ERROR "Unable to open PCM device (%s)\n",
120 pcm_get_error(cap_pcm));
121 return NULL;
122 }
123
124 size = pcm_frames_to_bytes(cap_pcm, pcm_get_buffer_size(cap_pcm));
125 buffer = malloc(size);
126 if (!buffer) {
127 AmtPrintf(AMT_ERROR "Unable to allocate %d bytes\n", size);
128 //free(buffer);
129 pcm_close(cap_pcm);
130 return NULL;
131 }
132
133 while (!pcm_read(cap_pcm, buffer, size)) {
134 if (fwrite(buffer, 1, size, file) != size) {
135 AmtPrintf(AMT_ERROR "Error capturing sample\n");
136 break;
137 }
138 bytes_read += size;
139 if (bytes_read >= 50000)
140 break;
141 }
142
143 cap_running = 0;
144 free(buffer);
145 // fclose(file);
146 printf("ca_thread\n");
147 AmtPrintf(AMT_INFO "ca_thread\n");
148 pthread_exit(0);
149}
150
151static void* audio_pb_thread(void *arg)
152{
153 struct mixer *mixer;
154 struct pcm_config config;
155 // struct pcm *cap_pcm, *pb_pcm;
156 char *buffer;
157 unsigned int size;
158 //unsigned int bytes_read = 0;
159 //int num_read;
160
161 UNUSED(arg);
162
163 mixer = mixer_open(0);
164 mix_set_output_path(mixer, T_OUTPUT_SPEAKER);
165 mix_set_output_vol(mixer, T_AUDIO_OUTPUT_VOL_LEVEL_11);
166 mixer_close(mixer);
167
168 memset(&config, 0, sizeof(config));
169 config.channels = 1;
170 config.rate = 8000;
171 config.period_size = 320;
172 config.period_count = 3;
173 config.format = PCM_FORMAT_S16_LE;
174 config.start_threshold = 0;
175 config.stop_threshold = 0;
176 config.silence_threshold = 0;
177
178 pb_pcm = pcm_open(0, 0, PCM_OUT, &config);
179 if (/*!pb_pcm ||*/ !pcm_is_ready(pb_pcm)) {
180 AmtPrintf(AMT_ERROR "Unable to open PCM device (%s)\n",
181 pcm_get_error(pb_pcm));
182 return NULL;
183 }
184
185 size = pcm_frames_to_bytes(pb_pcm, pcm_get_buffer_size(pb_pcm));
186 buffer = malloc(size);
187 if (!buffer) {
188 AmtPrintf(AMT_ERROR "Unable to allocate %d bytes\n", size);
189 // free(buffer);
190 pcm_close(cap_pcm);
191 return NULL;
192 }
193
194 memcpy(buffer, buffer2k8000, size);
195 if (pcm_write(pb_pcm, buffer, size)) {
196 AmtPrintf(AMT_ERROR "Error playing sample\n");
197 free(buffer);
198 return NULL;
199 }
200
201 do {
202 memcpy(buffer, buffer2k8000, size);
203 if (pcm_write(pb_pcm, buffer, size)) {
204 AmtPrintf(AMT_ERROR "Error playing sample\n");
205 break;
206 }
207
208 } while (cap_running > 0);
209
210 free(buffer);
211
212 printf("pb_thread\n");
213 AmtPrintf(AMT_INFO "pb_thread\n");
214 pthread_exit(0);
215
216 return NULL;
217}
218#endif
219
220int get_audioloop_result(FILE* file, int sampfs)
221{
222 int ret = -1, i = 0, num_read;
223 unsigned char testCount = 0, testSucessCount = 0;
224 zDrvVp_Freqfft temp = { 0,0 };
225 double freq[20] = {0};
226 double freqAmp[20] = {0};
227 double toneRealFreq = 1000; //2000
228 testCount = 20;
229 char *buffer = NULL;
230
231 buffer = malloc(2048);
232 if (!buffer)
233 {
234 AmtPrintf(AMT_ERROR "Unable to allocate %d bytes\n", 2048);
235 return -1;
236 }
237
238 if(fseek(file, 3200, SEEK_SET)!= 0)
239 {
240 free(buffer);
241 return -1;
242 }
243
244 while (testCount > 0)
245 {
246 //todo
247// zOss_Memcpy(audioPra->dest, audioPra->src, 2048); //2048byte
248// fseek(file, 0, SEEK_SET);
249 num_read = fread(buffer, 1, 2048, file);
250 if (num_read <= 0) {
251 printf("file end\n");
252 AmtPrintf(AMT_ERROR "file end\n");
253 free(buffer);
254 return -1;
255 }
256 cal_freq_fft((short *)buffer, &temp, 1024, sampfs);//1024 point fft//xiu
257
258 freq[testCount - 1] = temp.freqValue;
259 freqAmp[testCount - 1] = temp.freqAmp;
260 if (((fabs(freq[testCount - 1] - toneRealFreq)) < 50) && (freqAmp[testCount - 1] > 300))
261 {
262 testSucessCount++;
263 if (testSucessCount >= 5)
264 {
265 printf("testSucessCount=%d!\n", testSucessCount);
266 AmtPrintf(AMT_INFO "testSucessCount=%d!\n", testSucessCount);
267 ret = 0;
268 testCount--;
269 break;
270 }
271 }
272
273 testCount--;
274
275 }
276
277
278 for (i = 19; i >= testCount; i--)
279 {
280 printf("get_audioloop_result freq[%d]=%f freqAmp =%f!\n", i, freq[i], freqAmp[i]);
281 AmtPrintf(AMT_INFO "get_audioloop_result freq[%d]=%f freqAmp =%f!\n", i, freq[i], freqAmp[i]);
282 }
283
284 free(buffer);
285 return ret;
286}
287/**************************************************Íⲿ½Ó¿Ú****************************************************/
288#if 0
289extern int MMI_Test_TestInfo(unsigned char *msg_buf, unsigned int *msg_len);
290extern int MMI_Test_Keyboard_Start(VOID);
291extern int MMI_Test_Keyboard_Stop(unsigned char *msg_buf, unsigned int *msg_len);
292extern int MMI_Test_KP_Read(char *msg_buf, unsigned int *msg_len);
293extern int MMI_Test_LCD_Start(int color);
294extern int MMI_Test_LCD_Stop(VOID);
295extern int MMI_Test_LCDBacklight_Start(int value);
296extern int MMI_Test_LCDBacklight_Stop(VOID);
297extern int MMI_Test_Vibrator_Start(int timeout);
298extern int MMI_Test_Vibrator_Stop(VOID);
299extern int MMI_Test_SIM_Read(int index, char* msg_buf, unsigned int *msg_len);
300extern int MMI_Test_Battery_Voltage(char* msg_buf, unsigned int* msg_len);
301extern int MMI_Test_KeyBacklight_Start(VOID);
302extern int MMI_Test_KeyBacklight_Stop(VOID);
303extern int MMI_Test_Camera_Back_Start(VOID);
304extern int MMI_Test_Camera_Back_Stop(VOID);
305extern int MMI_Test_Camera_Back_Snapshot(unsigned char *msg_buf, unsigned int msg_len);
306extern int MMI_Test_SD_Read(int index, char *msg_buf, unsigned int *msg_len);
307extern int MMI_Test_Audio_Mic_Speaker(unsigned char *msg_buf, unsigned int msg_len);
308extern int MMI_Test_Audio_Mic_Receiver(unsigned char *msg_buf, unsigned int msg_len);
309extern int MMI_Test_Audio_Headset_Headset(unsigned char *msg_buf, unsigned int msg_len);
310extern int MMI_Test_SetIdle(VOID);
311
312extern FILE* tp_fopen (const char *file_name, const char *mode);
313extern int tp_flength(FILE *stream);
314extern size_t tp_fread (void *data, size_t size, size_t count, FILE *stream);
315extern int tp_fclose(FILE *stream);
316
317
318/**************************************************²âÊÔ½Ó¿Ú****************************************************/
319static int Amt_Test_Status_Idle(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
320{
321 int result = AMT_ERROR_RET;
322
323 if (MMI_Test_SetIdle() == 0)
324 {
325 result = AMT_SUCCESS_RET;
326 }
327 else
328 {
329 result = AMT_ERROR_RET;
330 }
331
332 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
333 return result;
334}
335
336static int Amt_Test_Init(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
337{
338 int result = AMT_ERROR_RET;
339 unsigned int ret = 0;
340#if 0
341 ZOSS_S_TIMEVAL tv = {0};
342
343 /* Initialize OS Time */
344 if (ZOSS_SUCCESS == zOss_Gettimeofday(&tv, NULL))
345 {
346 settimeofday(&tv, NULL);
347 }
348
349 /* Initialize CFG */
350 zCfg_Init();
351
352 ret = zOss_MountDynamicDisk("C:", "/c", "cpfs", "yaffs");
353 zOss_ASSERT(ret == ZOSS_SUCCESS);
354
355 zApp_Init();
356
357#ifdef _CONFIG_USE_VOICE
358 ret = zDrvVoiceConfig_Init();
359 if (ret != ZOSS_SUCCESS)
360 {
361 result = AMT_ERROR;
362 }
363 else
364#endif
365 {
366 result = AMT_SUCCESS;
367 }
368
369 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
370#endif
371 return result;
372}
373
374static int Amt_Test_TestInfo(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
375{
376 int result = AMT_ERROR_RET;
377 unsigned int nSize = 0;
378 unsigned char *pBuf = NULL;
379
380 MMI_Test_TestInfo(NULL, &nSize);
381
382 if (nSize > 0)
383 {
384 pBuf = (unsigned char *)malloc(nSize);
385 memset(pBuf, 0, nSize);
386
387 if (MMI_Test_TestInfo(pBuf, &nSize) == 0)
388 {
389 result = AMT_SUCCESS_RET;
390 Amt_DeviceTest_SendMsg(msg_id, result, pBuf, nSize);
391 free(pBuf);
392 return result;
393 }
394
395 free(pBuf);
396 }
397
398 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
399 return result;
400}
401#endif
402static int Amt_Test_Keyboard_Start(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
403{
404 int result = AMT_ERROR_RET;
405
406 UNUSED(msg_id);
407 UNUSED(msg_buf);
408 UNUSED(msg_len);
409
410 //ÏòMMI·¢ËÍ¿ªÊ¼°´¼ü²âÊÔÇëÇó
411 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_KEY_TEST_START_REQ, 0, NULL);
412
413 #if 0
414 if (MMI_Test_Keyboard_Start() == 0)
415 {
416 result = AMT_SUCCESS_RET;
417 }
418 else
419 {
420 result = AMT_ERROR_RET;
421 }
422
423 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
424 #endif
425 return result;
426}
427
428static int Amt_Test_Keyboard_Stop(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
429{
430 int result = AMT_ERROR_RET;
431
432 UNUSED(msg_id);
433 UNUSED(msg_buf);
434 UNUSED(msg_len);
435
436 #if 0
437 unsigned int nSize = 0;
438 unsigned char *pBuf = NULL;
439
440 nSize = 2*sizeof(T_ZWndEm_CheckKey);
441 pBuf = (char *)malloc(nSize);
442 memset(pBuf, 0, nSize);
443 #endif
444 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_KEY_TEST_STOP_REQ, 0, NULL);
445 #if 0
446 MMI_Test_Keyboard_Stop(NULL, &nSize);
447
448 if (nSize > 0)
449 {
450 pBuf = (unsigned char *)malloc(nSize);
451 memset(pBuf, 0, nSize);
452
453 if (MMI_Test_Keyboard_Stop(pBuf, &nSize) == 0)
454 {
455 result = AMT_SUCCESS_RET;
456 Amt_DeviceTest_SendMsg(msg_id, result, pBuf, nSize);
457 free(pBuf);
458 return result;
459 }
460
461 free(pBuf);
462 }
463
464 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
465 #endif
466 return result;
467}
468#if 0
469static int Amt_Test_Keyboard_Read(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
470{
471 int result = AMT_ERROR_RET;
472 unsigned int nSize = 0;
473 unsigned char *pBuf = NULL;
474
475 MMI_Test_KP_Read(NULL, &nSize);
476
477 if (nSize > 0)
478 {
479 pBuf = (unsigned char *)malloc(nSize);
480 memset(pBuf, 0, nSize);
481
482 if (MMI_Test_KP_Read((char *)pBuf, &nSize) == 0)
483 {
484 result = AMT_SUCCESS_RET;
485 Amt_DeviceTest_SendMsg(msg_id, result, pBuf, nSize);
486 free(pBuf);
487 return result;
488 }
489
490 free(pBuf);
491 }
492
493 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
494 return result;
495}
496#endif
497static int Amt_Test_LCD_Start(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
498{
499 int result = AMT_ERROR_RET;
500 int color;
501
502 UNUSED(msg_id);
503 UNUSED(msg_len);
504
505 memcpy(&color, msg_buf, sizeof(int));
506
507 if (color >= 0 && color < MAX_LCD_COLOR_NUM)
508 {
509 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_LCD_TEST_START_REQ, sizeof(int), (unsigned char*)&color);
510 #if 0
511 if (MMI_Test_LCD_Start(color) == 0)
512 {
513 result = AMT_SUCCESS_RET;
514 }
515 #endif
516 }
517
518 //Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
519
520 return result;
521}
522
523static int Amt_Test_LCD_Stop(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
524{
525 int result = AMT_ERROR_RET;
526
527 UNUSED(msg_id);
528 UNUSED(msg_buf);
529 UNUSED(msg_len);
530
531 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_LCD_TEST_STOP_REQ, 0, NULL);
532 #if 0
533 if (MMI_Test_LCD_Stop() == 0)
534 {
535 result = AMT_SUCCESS_RET;
536 }
537 else
538 {
539 result = AMT_ERROR_RET;
540 }
541
542 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
543 #endif
544 return result;
545}
546
547static int Amt_Test_LCDBacklight_Start(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
548{
549 int result = AMT_ERROR_RET;
550 int value;
551
552 UNUSED(msg_id);
553 UNUSED(msg_len);
554
555 memcpy(&value, msg_buf, sizeof(int));
556 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_LCD_BACKLIGHT_TEST_START_REQ, sizeof(int), (unsigned char*)&value);
557 #if 0
558 if (MMI_Test_LCDBacklight_Start(value) == 0)
559 {
560 result = AMT_SUCCESS_RET;
561 }
562 else
563 {
564 result = AMT_ERROR_RET;
565 }
566
567 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
568 #endif
569 return result;
570}
571
572static int Amt_Test_LCDBacklight_Stop(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
573{
574 int result = AMT_ERROR_RET;
575
576 UNUSED(msg_id);
577 UNUSED(msg_buf);
578 UNUSED(msg_len);
579
580 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_LCD_BACKLIGHT_TEST_STOP_REQ, 0, NULL);
581 #if 0
582 if (MMI_Test_LCDBacklight_Stop() == 0)
583 {
584 result = AMT_SUCCESS_RET;
585 }
586 else
587 {
588 result = AMT_ERROR_RET;
589 }
590
591 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
592 #endif
593 return result;
594}
595
596static int Amt_Test_Vibrator_Start(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
597{
598 int result = AMT_ERROR_RET;
599 int timeout = -1;
600
601 UNUSED(msg_id);
602 UNUSED(msg_buf);
603 UNUSED(msg_len);
604
605 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_VIBRATOR_TEST_START_REQ, sizeof(int), (unsigned char*)&timeout);
606 #if 0
607 if (MMI_Test_Vibrator_Start(-1) == 0)
608 {
609 result = AMT_SUCCESS_RET;
610 }
611 else
612 {
613 result = AMT_ERROR_RET;
614 }
615
616 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
617 #endif
618 return result;
619}
620
621static int Amt_Test_Vibrator_Stop(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
622{
623 int result = AMT_ERROR_RET;
624
625 UNUSED(msg_id);
626 UNUSED(msg_buf);
627 UNUSED(msg_len);
628
629 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_VIBRATOR_TEST_STOP_REQ, 0, NULL);
630 #if 0
631 if (MMI_Test_Vibrator_Stop() == 0)
632 {
633 result = AMT_SUCCESS_RET;
634 }
635 else
636 {
637 result = AMT_ERROR_RET;
638 }
639
640 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
641 #endif
642 return result;
643}
644
645#if 0
646static int Amt_Test_SIM_Read(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
647{
648 int result = AMT_ERROR_RET;
649 unsigned int nSize = 0;
650 char *pBuf = NULL;
651 int index = 0;
652 memcpy(&index, msg_buf, sizeof(int));
653
654 MMI_Test_SIM_Read(index, NULL, &nSize);
655
656 if (nSize > 0)
657 {
658 pBuf = (char *)malloc(nSize);
659 memset(pBuf, 0, nSize);
660
661 if (MMI_Test_SIM_Read(index, pBuf, &nSize) == 0)
662 {
663 result = AMT_SUCCESS_RET;
664 Amt_DeviceTest_SendMsg(msg_id, result, (unsigned char *)pBuf, nSize);
665 free(pBuf);
666 return result;
667 }
668
669 free(pBuf);
670 }
671
672 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
673 return result;
674}
675
676static int Amt_Test_SD_Read(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
677{
678 int result = AMT_ERROR_RET;
679 unsigned int nSize = 0;
680 char *pBuf = NULL;
681 int index = 0;
682 memcpy(&index, msg_buf, sizeof(int));
683
684 MMI_Test_SD_Read(index, NULL, &nSize);
685
686 if (nSize > 0)
687 {
688 pBuf = (char *)malloc(nSize);
689 memset(pBuf, 0, nSize);
690
691 if (MMI_Test_SD_Read(index, pBuf, &nSize) == 0)
692 {
693 result = AMT_SUCCESS_RET;
694 Amt_DeviceTest_SendMsg(msg_id, result, (unsigned char *)pBuf, nSize);
695 free(pBuf);
696 return result;
697 }
698
699 free(pBuf);
700 }
701
702 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
703 return result;
704}
705#endif
706static int Amt_Test_Battery_Voltage(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
707{
708 int result = AMT_ERROR_RET;
709
710 UNUSED(msg_id);
711 UNUSED(msg_buf);
712 UNUSED(msg_len);
713
714 #if 0
715 unsigned int nSize = 0;
716 char *pBuf = NULL;
717
718 //ÏòMMI·¢ËÍµç³Øµçѹ²âÊÔÇëÇó
719 nSize = sizeof(MAN_BATTERY_STATUS);
720 pBuf = (char *)malloc(nSize);
721 memset(pBuf, 0, nSize);
722 #endif
723 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_BATTERY_VOLTAGE_TEST_REQ, 0, NULL);
724 #if 0
725 MMI_Test_Battery_Voltage(NULL, &nSize);
726
727 if (nSize > 0)
728 {
729 pBuf = (char *)malloc(nSize);
730 memset(pBuf, 0, nSize);
731
732 if (MMI_Test_Battery_Voltage(pBuf, &nSize) == 0)
733 {
734 result = AMT_SUCCESS_RET;
735 Amt_DeviceTest_SendMsg(msg_id, result, (unsigned char *)pBuf, nSize);
736 free(pBuf);
737 return result;
738 }
739
740 free(pBuf);
741 }
742
743 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
744 #endif
745 return result;
746}
747
748static int Amt_Test_Battery_Temperature(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
749{
750 int result = AMT_ERROR_RET;
751 FILE* batteryTempFd = NULL;
752 char buf[10] = {0};
753 int read_len = 0;
754 int battery_temperature = 0; //µç³ØÎ¶È(µ¥Î»ºÁ·ü)
755
756 UNUSED(msg_buf);
757 UNUSED(msg_len);
758
759 batteryTempFd = fopen(BATTERY_TEMPERATURE_PATH, "r");
760 //AmtPrintf(AMT_INFO "%s: batteryTempFd =0x%08x\n", __FUNCTION__, batteryTempFd);
761 if(batteryTempFd == NULL)
762 {
763 AmtPrintf(AMT_ERROR "%s:battery temperature open error,path is \"%s\"!\n",__FUNCTION__, BATTERY_TEMPERATURE_PATH);
764 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
765 return result;
766 }
767 else
768 {
769 read_len = fread(buf, 1, sizeof(buf) - 1, batteryTempFd);
770 AmtPrintf(AMT_INFO "%s:battery temperature read_len=%d\n",__FUNCTION__, read_len);
771 if(read_len > 0)
772 {
773 AmtPrintf(AMT_INFO "%s:battery temperature read:%s\n",__FUNCTION__, buf);
774 battery_temperature = atoi(buf);
775 AmtPrintf(AMT_INFO "%s:battery temperature = %d\n",__FUNCTION__, battery_temperature);
776 result = AMT_SUCCESS_RET;
777 }
778 fclose(batteryTempFd);
779 }
780 Amt_DeviceTest_SendMsg(msg_id, result, (unsigned char *)&battery_temperature, sizeof(battery_temperature));
781 return result;
782}
783
784static int Amt_Test_Charger_Status(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
785{
786 int result = AMT_ERROR_RET;
787 FILE* chargerStatusFd = NULL;
788 char buf[50] = {0};
789 int read_len = 0;
790
791 UNUSED(msg_buf);
792 UNUSED(msg_len);
793
794 chargerStatusFd = fopen(CHARGER_STATUS_PATH, "r");
795 //AmtPrintf(AMT_INFO "%s: chargerStatusFd =0x%08x\n", __FUNCTION__, chargerStatusFd);
796 if(chargerStatusFd == NULL)
797 {
798 AmtPrintf(AMT_ERROR "%s:charger status open error,path is \"%s\"!\n",__FUNCTION__, CHARGER_STATUS_PATH);
799 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
800 return result;
801 }
802 else
803 {
804 read_len = fread(buf, 1, sizeof(buf) - 1 , chargerStatusFd);
805 AmtPrintf(AMT_INFO "%s:charger status read_len=%d\n",__FUNCTION__, read_len);
806 if(read_len > 0)
807 {
808 AmtPrintf(AMT_INFO "%s:charger status read:%s\n",__FUNCTION__, buf);
809 if(!strncmp(buf,"Charging",strlen("Charging")) || !strncmp(buf,"Full",strlen("Full")))
810 {
811 result = AMT_SUCCESS_RET;
812 }
813 }
814
815 fclose(chargerStatusFd);
816 }
817 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
818 return result;
819}
820
821#if 0
822static int Amt_Test_KeyBacklight_Start(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
823{
824 int result;
825
826 if (MMI_Test_KeyBacklight_Start() == 0)
827 {
828 result = AMT_SUCCESS_RET;
829 }
830 else
831 {
832 result = AMT_ERROR_RET;
833 }
834
835 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
836 return result;
837}
838
839static int Amt_Test_KeyBacklight_Stop(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
840{
841 int result;
842
843 if (MMI_Test_KeyBacklight_Stop() == 0)
844 {
845 result = AMT_SUCCESS_RET;
846 }
847 else
848 {
849 result = AMT_ERROR_RET;
850 }
851
852 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
853 return result;
854}
855#endif
856static int Amt_Test_Camera_Back_Start(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
857{
858 int result = AMT_ERROR_RET;
859
860 UNUSED(msg_id);
861 UNUSED(msg_buf);
862 UNUSED(msg_len);
863
864 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_CAMERA_TEST_START_REQ, 0, NULL);
865 #if 0
866 if (MMI_Test_Camera_Back_Start() == 0)
867 {
868 result = AMT_SUCCESS_RET;
869 }
870 else
871 {
872 result = AMT_ERROR_RET;
873 }
874
875 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
876 #endif
877 return result;
878}
879#if 0
880static int Amt_Test_Camera_Back_Snapshot(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
881{
882 int result = AMT_ERROR_RET;
883 char PicPath[260] = {0};
884 int nSize = 0;
885 unsigned char *pBuf = NULL;
886 FILE *pFile = NULL;
887
888 if (MMI_Test_Camera_Back_Snapshot((unsigned char *)PicPath, 260) != 0)
889 {
890 AmtPrintf(AMT_ERROR "%s: MMI_Test_Camera_Back_Snapshot return error!", __FUNCTION__);
891 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
892 return -1;
893 }
894
895 if (PicPath[0] == '\0')
896 {
897 AmtPrintf(AMT_ERROR "%s: PicPath is empty!", __FUNCTION__);
898 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
899 return -1;
900 }
901
902 if ((pFile = tp_fopen(PicPath, "rb")) == NULL)
903 {
904 AmtPrintf(AMT_ERROR "%s: Open \"%s\" fail!", __FUNCTION__, PicPath);
905 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
906 return -1;
907 }
908
909 // »ñÈ¡Îļþ´óС
910 if ((nSize = tp_flength(pFile)) <= 0)
911 {
912 AmtPrintf(AMT_ERROR "%s: nSize(%d) < = 0!", __FUNCTION__, nSize);
913 tp_fclose(pFile);
914 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
915 return -1;
916 }
917
918 // ÉêÇ뻺³åÇø
919 pBuf = malloc(nSize);
920
921 // ¶ÁÈ¡ÎļþÊý¾Ý
922 if (tp_fread(pBuf, 1, nSize, pFile) == nSize)
923 {
924 result = AMT_SUCCESS_RET;
925 Amt_DeviceTest_SendMsg(msg_id, result, pBuf, nSize);
926 }
927 else
928 {
929 AmtPrintf(AMT_ERROR "%s: tp_fread error!", __FUNCTION__);
930 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
931 }
932
933 free(pBuf);
934 tp_fclose(pFile);
935
936 return result;
937}
938#endif
939static int Amt_Test_Camera_Back_Stop(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
940{
941 int result = AMT_ERROR_RET;
942
943 UNUSED(msg_id);
944 UNUSED(msg_buf);
945 UNUSED(msg_len);
946
947 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_CAMERA_TEST_STOP_REQ, 0, NULL);
948 #if 0
949 if (MMI_Test_Camera_Back_Stop() == 0)
950 {
951 result = AMT_SUCCESS_RET;
952 }
953 else
954 {
955 result = AMT_ERROR_RET;
956 }
957
958 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
959 #endif
960 return result;
961}
962
963#ifdef _USE_VOICE_SUPPORT
964static int Amt_Test_Audio_Mic_Receiver(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
965{
966 int result = AMT_ERROR_RET;
967
968 UNUSED(msg_id);
969 UNUSED(msg_buf);
970 UNUSED(msg_len);
971
972 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_RECEIVER_TEST_REQ, 0, NULL);
973 #if 0
974 if (MMI_Test_Audio_Mic_Receiver(msg_buf, msg_len) == 0)
975 {
976 result = AMT_SUCCESS_RET;
977 }
978 else
979 {
980 result = AMT_ERROR_RET;
981 }
982
983 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
984 #endif
985 return result;
986}
987
988static int Amt_Test_Audio_Mic_Receiver_Stop(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
989{
990 int result = AMT_ERROR_RET;
991
992 UNUSED(msg_id);
993 UNUSED(msg_buf);
994 UNUSED(msg_len);
995
996 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_RECEIVER_TEST_STOP_REQ, 0, NULL);
997 return result;
998}
999
1000static int Amt_Test_Audio_Mic_Speaker(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1001{
1002 int result = AMT_ERROR_RET;
1003
1004 UNUSED(msg_buf);
1005 UNUSED(msg_len);
1006
1007 //platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_SPEAKER_TEST_REQ, 0, NULL);
1008 #if 0
1009 if (MMI_Test_Audio_Mic_Speaker(msg_buf, msg_len) == 0)
1010 {
1011 result = AMT_SUCCESS_RET;
1012 }
1013 else
1014 {
1015 result = AMT_ERROR_RET;
1016 }
1017
1018 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1019 #endif
1020 #if 0
1021 //µ÷ÓÃÇý¶¯µÄ½Ó¿Ú¼Òô²¢²¥·Å
1022 struct mixer *mixer;
1023 struct pcm_config config;
1024 struct pcm *cap_pcm, *pb_pcm;
1025 char *buffer;
1026 unsigned int size;
1027 unsigned int bytes_read = 0;
1028 FILE *file;
1029 int num_read;
1030 int errNum = 0;
1031
1032 mixer = mixer_open(0);
1033 mix_set_input_path(mixer, T_INPUT_MICLP);
1034 mix_set_input_vol(mixer, T_AUDIO_INPUT_VOL_LEVEL_11);
1035 mixer_close(mixer);
1036
1037 memset(&config, 0, sizeof(config));
1038 config.channels = 1;
1039 config.rate = 8000;
1040 config.period_size = 320;
1041 config.period_count = 3;
1042 config.format = PCM_FORMAT_S16_LE;
1043 config.start_threshold = 0;
1044 config.stop_threshold = 0;
1045 config.silence_threshold = 0;
1046
1047 file = fopen("/mnt/userdata/cache/cap.bin", "wb+");
1048 if (!file) {
1049 errNum = errno;
1050 AmtPrintf(AMT_ERROR "%s:Unable to create file cap.bin,errNum=%d,reason=%s\n",\
1051 __FUNCTION__,errNum,strerror(errNum));
1052 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1053 return result;
1054 }
1055
1056 cap_pcm = pcm_open(0, 0, PCM_IN, &config);
1057 if (!cap_pcm || !pcm_is_ready(cap_pcm)) {
1058 AmtPrintf(AMT_ERROR "Unable to open PCM device (%s)\n",
1059 pcm_get_error(cap_pcm));
1060 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1061 return result;
1062 }
1063
1064 size = pcm_frames_to_bytes(cap_pcm, pcm_get_buffer_size(cap_pcm));
1065 buffer = malloc(size);
1066 if (!buffer) {
1067 AmtPrintf(AMT_ERROR "Unable to allocate %d bytes\n", size);
1068 free(buffer);
1069 pcm_close(cap_pcm);
1070 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1071 return result;
1072 }
1073
1074 while (!pcm_read(cap_pcm, buffer, size)) {
1075 if (fwrite(buffer, 1, size, file) != size) {
1076 AmtPrintf(AMT_ERROR "Error capturing sample\n");
1077 break;
1078 }
1079 bytes_read += size;
1080 if (bytes_read >= 80000)
1081 break;
1082 }
1083
1084 pcm_close(cap_pcm);
1085
1086 mixer = mixer_open(0);
1087 mix_set_output_path(mixer, T_OUTPUT_SPEAKER);
1088 mix_set_output_vol(mixer, T_AUDIO_OUTPUT_VOL_LEVEL_11);
1089 mixer_close(mixer);
1090
1091 pb_pcm = pcm_open(0, 0, PCM_OUT, &config);
1092 if (!pb_pcm || !pcm_is_ready(pb_pcm)) {
1093 AmtPrintf(AMT_ERROR "Unable to open PCM device (%s)\n",
1094 pcm_get_error(pb_pcm));
1095 free(buffer);
1096 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1097 return result;
1098 }
1099
1100 fseek(file, 0, SEEK_SET);
1101
1102 do {
1103 num_read = fread(buffer, 1, size, file);
1104 if (num_read > 0) {
1105 if (pcm_write(pb_pcm, buffer, num_read)) {
1106 AmtPrintf(AMT_ERROR "Error playing sample\n");
1107 break;
1108 }
1109 }
1110 } while (num_read > 0);
1111
1112 free(buffer);
1113 pcm_close(pb_pcm);
1114 fclose(file);
1115
1116 remove("/mnt/userdata/cache/cap.bin");
1117 result = AMT_SUCCESS_RET;
1118 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1119#endif
1120 int ret;
1121
1122#if 1
1123 cap_running = 1;
1124
1125 ret = pthread_create(&pb_thread_tid, NULL, audio_pb_thread, NULL);
1126 if(ret != 0){
1127 printf ("Create pb_thread error!\n");
1128 AmtPrintf(AMT_ERROR "Create pb_thread error!\n");
1129 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1130 return result;
1131 }
1132 ret = pthread_create(&ca_thread_tid, NULL, audio_ca_thread, NULL);
1133 if(ret != 0){
1134 printf ("Create ca_thread error!\n");
1135 AmtPrintf(AMT_ERROR "Create ca_thread error!\n");
1136 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1137 return result;
1138 }
1139
1140 pthread_join(ca_thread_tid, NULL);
1141 pthread_join(pb_thread_tid, NULL);
1142 printf("AmtAgent_Test_Audio_Mic_Speaker\n");
1143 AmtPrintf(AMT_INFO "AmtAgent_Test_Audio_Mic_Speaker\n");
1144#endif
1145
1146 pcm_close(pb_pcm);
1147 pcm_close(cap_pcm);
1148 printf("cap 1 stop\n");
1149 AmtPrintf(AMT_INFO "cap 1 stop\n");
1150
1151 ret = get_audioloop_result(file, 8000);
1152
1153 fclose(file);
1154
1155 AmtPrintf(AMT_INFO "ret = %d\n",ret);
1156 Amt_DeviceTest_SendMsg(msg_id, ret , NULL, 0);
1157 if(remove("/mnt/userdata/cache/cap.bin") != 0)
1158 {
1159 AmtPrintf(AMT_INFO "remove \"/mnt/userdata/cache/cap.bin\" error! errno=%d(%s)\n",errno,strerror(errno));
1160 }
1161 return result;
1162}
1163
1164static int Amt_Test_Audio_Mic_Speaker_Stop(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1165{
1166 int result = AMT_ERROR_RET;
1167
1168 UNUSED(msg_id);
1169 UNUSED(msg_buf);
1170 UNUSED(msg_len);
1171
1172 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_SPEAKER_TEST_STOP_REQ, 0, NULL);
1173 return result;
1174}
1175
1176
1177#if 0
1178static int Amt_Test_Audio_Headset_Headset(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1179{
1180 int result;
1181
1182 if (MMI_Test_Audio_Headset_Headset(msg_buf, msg_len) == 0)
1183 {
1184 result = AMT_SUCCESS_RET;
1185 }
1186 else
1187 {
1188 result = AMT_ERROR_RET;
1189 }
1190
1191 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1192 return result;
1193}
1194#endif
1195#endif
1196
1197static int Amt_Test_TP_Start(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1198{
1199 int result = AMT_ERROR_RET;
1200
1201 UNUSED(msg_id);
1202 UNUSED(msg_buf);
1203 UNUSED(msg_len);
1204
1205 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_TP_TEST_START_REQ, 0, NULL);
1206 return result;
1207}
1208
1209static int Amt_Test_TP_Stop(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1210{
1211 int result = AMT_ERROR_RET;
1212
1213 UNUSED(msg_id);
1214 UNUSED(msg_buf);
1215 UNUSED(msg_len);
1216
1217 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_TP_TEST_STOP_REQ, 0, NULL);
1218 return result;
1219}
1220
1221static int Amt_Test_TP_Board(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1222{
1223 int result = AMT_ERROR_RET;
1224 FILE* tpFd = NULL;
1225 char buf[10] = {0};
1226 int read_len = 0;
1227 int tp_result = 0;
1228
1229 UNUSED(msg_buf);
1230 UNUSED(msg_len);
1231
1232 tpFd = fopen(TP_MODE_PATH, "r");
1233 //AmtPrintf(AMT_INFO "%s: tpFd =0x%08x\n", __FUNCTION__, tpFd);
1234 if(tpFd == NULL)
1235 {
1236 AmtPrintf(AMT_ERROR "%s:tp device open error,path is \"%s\"!\n",__FUNCTION__, TP_MODE_PATH);
1237 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1238 return result;
1239 }
1240 else
1241 {
1242 read_len = fread(buf, 1, sizeof(buf) - 1, tpFd);
1243 AmtPrintf(AMT_INFO "%s:tp read_len=%d\n",__FUNCTION__, read_len);
1244 if(read_len > 0)
1245 {
1246 AmtPrintf(AMT_INFO "%s:tp read:%s\n",__FUNCTION__, buf);
1247 tp_result = atoi(buf);
1248 AmtPrintf(AMT_INFO "%s:tp mode = %d\n",__FUNCTION__, tp_result);
1249 if(tp_result != 0xff)
1250 {
1251 result = AMT_SUCCESS_RET;
1252 }
1253 }
1254 fclose(tpFd);
1255 }
1256 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1257 return result;
1258}
1259
1260static int Amt_Test_GSensor_Board(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1261{
1262 int result = AMT_ERROR_RET;
1263 int fd_gsensor = open(DEVICE_GSENSOR, O_RDWR);
1264
1265 UNUSED(msg_id);
1266 UNUSED(msg_buf);
1267 UNUSED(msg_len);
1268
1269 if (fd_gsensor < 0)
1270 {
1271 AmtPrintf(AMT_ERROR "Failed to open \"%s\"!\n", DEVICE_GSENSOR);
1272 }
1273 else
1274 {
1275 close(fd_gsensor);
1276 result = AMT_SUCCESS_RET;
1277 }
1278 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1279 return result;
1280}
1281
1282static int Amt_Test_Camera_Board(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1283{
1284 int result = AMT_ERROR_RET;
1285 int fd_camera = open(DEVICE_CAMERA, O_RDWR);
1286
1287 UNUSED(msg_buf);
1288 UNUSED(msg_len);
1289
1290 if (fd_camera < 0)
1291 {
1292 AmtPrintf(AMT_ERROR "Failed to open \"%s\"!\n", DEVICE_CAMERA);
1293 }
1294 else
1295 {
1296 close(fd_camera);
1297 result = AMT_SUCCESS_RET;
1298 }
1299 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1300 return result;
1301}
1302
1303static int Amt_Test_LCD_Board(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1304{
1305 int result = AMT_ERROR_RET;
1306 int fd_LCD = open(DEVICE_LCD, O_RDWR);
1307
1308 UNUSED(msg_buf);
1309 UNUSED(msg_len);
1310
1311 if (fd_LCD < 0)
1312 {
1313 AmtPrintf(AMT_ERROR "Failed to open \"%s\"!\n", DEVICE_LCD);
1314 }
1315 else
1316 {
1317 close(fd_LCD);
1318 result = AMT_SUCCESS_RET;
1319 }
1320 Amt_DeviceTest_SendMsg(msg_id, result, NULL, 0);
1321 return result;
1322}
1323
1324static int Amt_Test_GSensor_Start(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1325{
1326 int result = AMT_ERROR_RET;
1327
1328 UNUSED(msg_id);
1329 UNUSED(msg_buf);
1330 UNUSED(msg_len);
1331
1332 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_GSENSOR_TEST_START_REQ, 0, NULL);
1333 return result;
1334}
1335
1336static int Amt_Test_GSensor_Stop(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1337{
1338 int result = AMT_ERROR_RET;
1339
1340 UNUSED(msg_id);
1341 UNUSED(msg_buf);
1342 UNUSED(msg_len);
1343
1344 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_GSENSOR_TEST_STOP_REQ, 0, NULL);
1345 return result;
1346}
1347
1348static int Amt_Test_Flashlight_Start(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1349{
1350 int result = AMT_ERROR_RET;
1351
1352 UNUSED(msg_id);
1353 UNUSED(msg_buf);
1354 UNUSED(msg_len);
1355
1356 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_FLASHLIGHT_START_REQ, 0, NULL);
1357 return result;
1358}
1359
1360static int Amt_Test_Wifi(unsigned int msg_id, unsigned char *msg_buf, unsigned int msg_len)
1361{
1362 int result = AMT_ERROR_RET;
1363
1364 UNUSED(msg_id);
1365 UNUSED(msg_buf);
1366 UNUSED(msg_len);
1367
1368 platform_send_msg(MODULE_ID_AMT, MODULE_ID_MMI_SVR, MSG_CMD_AMT_WIFI_TEST_START_REQ, 0, NULL);
1369 return result;
1370}
1371/**
1372 *
1373 */
1374static const T_COMMAND g_CmdTable[] =
1375{
1376 #if 0
1377 // Common
1378 {TEST_COMMON, MSG_DEVICETEST_STATUS_IDLE, Amt_Test_Status_Idle, "Set idle status"},
1379 {TEST_COMMON, MSG_DEVICETEST_TESTINIT, Amt_Test_Init, "Test init"},
1380 // TestInfo
1381 {TEST_INFO, MSG_DEVICETEST_TESTINFO, Amt_Test_TestInfo, "Get test information"},
1382 #endif
1383 //Keyboard
1384 {TEST_KEYBOARD, MSG_DEVICETEST_KEYBOARD_START, Amt_Test_Keyboard_Start, "Start Keyboard test"},
1385 {TEST_KEYBOARD, MSG_DEVICETEST_KEYBOARD_STOP, Amt_Test_Keyboard_Stop, "Stop Keyboard test"},
1386 //{TEST_KEYBOARD, MSG_DEVICETEST_KEYBOARD_READ, Amt_Test_Keyboard_Read, "Read Keyboard state"},
1387 //LCD
1388 {TEST_LCD, MSG_DEVICETEST_LCD_START, Amt_Test_LCD_Start, "Start LCD test"},
1389 {TEST_LCD, MSG_DEVICETEST_LCD_STOP, Amt_Test_LCD_Stop, "Stop LCD test"},
1390 {TEST_LCD, MSG_DEVICETEST_LCD_BOARD, Amt_Test_LCD_Board, "Board LCD test"},
1391 //LCD backlight
1392 {TEST_LCDBACKLIGHT, MSG_DEVICETEST_LCDBACKLIGHT_START, Amt_Test_LCDBacklight_Start, "Start LCD backlight test"},
1393 {TEST_LCDBACKLIGHT, MSG_DEVICETEST_LCDBACKLIGHT_STOP, Amt_Test_LCDBacklight_Stop, "Stop LCD backlight test"},
1394 // Vibrator
1395 {TEST_VIBRATOR, MSG_DEVICETEST_VIBRATOR_START, Amt_Test_Vibrator_Start, "Start vibrator test"},
1396 {TEST_VIBRATOR, MSG_DEVICETEST_VIBRATOR_STOP, Amt_Test_Vibrator_Stop, "Stop vibrator test"},
1397 // SIM
1398 //{TEST_SIM, MSG_DEVICETEST_SIM_READ, Amt_Test_SIM_Read, "SIM card test"},
1399 // SD
1400 //{TEST_SD, MSG_DEVICETEST_SD_READ, Amt_Test_SD_Read, "SD card test"},
1401
1402 //Battery
1403 {TEST_BATTERY, MSG_DEVICETEST_BATTERY_VOLTAGE, Amt_Test_Battery_Voltage, "Battery voltage test"},
1404 {TEST_BATTERY, MSG_DEVICETEST_BATTERY_TEMPERATURE, Amt_Test_Battery_Temperature, "Battery temperature test"},
1405 //Charger
1406 {TEST_CHARGER, MSG_DEVICETEST_CHARGER_STATUS, Amt_Test_Charger_Status, "Charger status test"},
1407 #if 0
1408 // Keybacklight
1409 {TEST_KEYBACKLIGHT, MSG_DEVICETEST_KEYBACKLIGHT_START, Amt_Test_KeyBacklight_Start, "Start Key backlight test"},
1410 {TEST_KEYBACKLIGHT, MSG_DEVICETEST_KEYBACKLIGHT_STOP, Amt_Test_KeyBacklight_Stop, "Stop Key backlight test"},
1411 #endif
1412 // Camera
1413 {TEST_CAMERA_BACK, MSG_DEVICETEST_CAMERA_BACK_START, Amt_Test_Camera_Back_Start, "Start back camera test"},
1414 //{TEST_CAMERA_BACK, MSG_DEVICETEST_CAMERA_BACK_SNAPSHOT, Amt_Test_Camera_Back_Snapshot, "Back camera snapshot test"},
1415 {TEST_CAMERA_BACK, MSG_DEVICETEST_CAMERA_BACK_STOP, Amt_Test_Camera_Back_Stop, "Stop back camera test"},
1416 {TEST_CAMERA_BACK, MSG_DEVICETEST_CAMERA_BOARD, Amt_Test_Camera_Board, "Board camera test"},
1417 // Audio
1418 // Audio
1419#ifdef _USE_VOICE_SUPPORT
1420 {TEST_AUDIO, MSG_DEVICETEST_AUDIO_MIC_RECEIVER, Amt_Test_Audio_Mic_Receiver, "Mic-Receiver test"},
1421 {TEST_AUDIO, MSG_DEVICETEST_AUDIO_MIC_RECEIVER_STOP, Amt_Test_Audio_Mic_Receiver_Stop, "Stop Mic-Receiver test"},
1422 {TEST_AUDIO, MSG_DEVICETEST_AUDIO_MIC_SPEAKER, Amt_Test_Audio_Mic_Speaker, "Mic-Speaker test"},
1423 {TEST_AUDIO, MSG_DEVICETEST_AUDIO_MIC_SPEAKER_STOP, Amt_Test_Audio_Mic_Speaker_Stop, "Stop Mic-Speaker test"},
1424 //{TEST_AUDIO, MSG_DEVICETEST_AUDIO_HEADSET_HEADSET, Amt_Test_Audio_Headset_Headset, "Headset test"},
1425#endif
1426 // TP
1427 {TEST_TP, MSG_DEVICETEST_TP_START, Amt_Test_TP_Start, "Start TP test"},
1428 {TEST_TP, MSG_DEVICETEST_TP_STOP, Amt_Test_TP_Stop, "Stop TP test"},
1429 {TEST_TP, MSG_DEVICETEST_TP_BOARD, Amt_Test_TP_Board, "Board TP test"},
1430 // G-Sensor
1431 {TEST_GSENSOR, MSG_DEVICETEST_GSENSOR_START, Amt_Test_GSensor_Start, "Start G-Sensor test"},
1432 {TEST_GSENSOR, MSG_DEVICETEST_GSENSOR_STOP, Amt_Test_GSensor_Stop, "Stop G-Sensor test"},
1433 {TEST_GSENSOR, MSG_DEVICETEST_GSENSOR_BOARD, Amt_Test_GSensor_Board, "Board G-Sensor test"},
1434 // flashlight
1435 {TEST_FLASH_LIGHT, MSG_DEVICETEST_FLASHLIGHT_START, Amt_Test_Flashlight_Start, "Flashlight test"},
1436 // wifi
1437 {TEST_WIFI, MSG_DEVICETEST_WIFI, Amt_Test_Wifi, "wifi test"}
1438};
1439
1440static const int g_CmdTableCount = sizeof(g_CmdTable) / sizeof(T_COMMAND);
1441
1442/**
1443 * @brief AMTÍâÉè²âÊÔ³õʼ»¯
1444 * @return ³É¹¦·µ»Ø0, ʧ°Ü·µ»Ø-1
1445 * @note
1446 * @see
1447 */
1448int Amt_DeviceTest_Init(void)
1449{
1450 AmtPrintf(AMT_INFO "%s", __FUNCTION__);
1451 return 0;
1452}
1453
1454
1455/**
1456 * @brief AMTÍâÉèÏûÏ¢´¦Àíº¯Êý
1457 * @param[in] msg_id FID
1458 * @param[in] msg_buf ½ÓÊÕÊý¾Ýbuffer
1459 * @param[in] msg_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
1460 * @return ³É¹¦·µ»Ø0, ʧ°Ü·µ»Ø-1
1461 * @note
1462 * @see
1463 */
1464int Amt_DeviceTest_ProcessMsg(unsigned int msg_id, unsigned char* msg_buf, unsigned int msg_len)
1465{
1466 int i;
1467
1468 AmtPrintf(AMT_INFO "%s: Device test message: %#04x.\n", __FUNCTION__, msg_id);
1469
1470 for (i = 0; i < g_CmdTableCount; i++)
1471 {
1472 if (msg_id == g_CmdTable[i].msg_id)
1473 {
1474 if (g_CmdTable[i].fun != NULL)
1475 {
1476 AmtPrintf(AMT_INFO "%s: %s.\n", __FUNCTION__, g_CmdTable[i].test_name);
1477 if (g_CmdTable[i].fun(msg_id, msg_buf, msg_len) == AMT_SUCCESS_RET)
1478 {
1479 //AmtPrintf(AMT_INFO "%s: %s success.\n", __FUNCTION__, g_CmdTable[i].test_name);
1480 return 0;
1481 }
1482 else
1483 {
1484 //AmtPrintf(AMT_ERROR "%s: %s fail.\n", __FUNCTION__, g_CmdTable[i].test_name);
1485 return -1;
1486 }
1487 }
1488 else
1489 {
1490 return -1;
1491 }
1492 }
1493 }
1494
1495 AmtPrintf(AMT_ERROR "%s: Can't find the message: %#04x.\n", __FUNCTION__, msg_id);
1496 return -1;
1497}
1498
1499
1500/**
1501 * @brief AMTÍâÉèÏûÏ¢·´À¡¸øPC
1502 * @param[in] msg_id FID
1503 * @param[in] result ״̬Âë
1504 * @param[in] msg_buf ½ÓÊÕÊý¾Ýbuffer
1505 * @param[in] msg_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
1506 * @return ³É¹¦·µ»Ø0, ʧ°Ü·µ»Ø-1
1507 * @note
1508 * @see
1509 */
1510int Amt_DeviceTest_SendMsg(unsigned int msg_id, int result, unsigned char* msg_buf, unsigned int msg_len)
1511{
1512 unsigned int nRspLen = sizeof(T_DeviceTest_Header) + msg_len;
1513 T_DeviceTest_Header *pHeader = (T_DeviceTest_Header *)malloc(nRspLen);
1514
1515 if (pHeader != NULL)
1516 {
1517 pHeader->result = result;
1518 pHeader->length = msg_len;
1519
1520 if (msg_buf != NULL && msg_len > 0)
1521 {
1522 memcpy(pHeader + 1, msg_buf, msg_len);
1523 }
1524
1525 if(Amt_CreateResponse(msg_id, (unsigned char *)pHeader, nRspLen) == -1)
1526 {
1527 AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
1528 }
1529 else
1530 {
1531 AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
1532 }
1533 free(pHeader);
1534 return 0;
1535 }
1536 else
1537 {
1538 return -1;
1539 }
1540}
1541
1542