四、关键技术
1. 消息传送机制
利用手机Modem中提供的AT Command通过串口向手机端建立命令消息通讯,目前手机厂商提供了常用的AT Command,基本满足普通的自动化测试需求,另外厂商还提供了用户自定义AT Command的功能,当标准的AT Command不能满足自动化测试需求时,我们可以利用自定义AT Command来实现我们自动化测试中所需要的消息通讯。如下为MTK平台上实现自定义AT Command的关键样例代码:
1. //customer_at_command.c 2. #include "kal_non_specific_general_types.h" 3. #include "stdio.h" 4. #include "string.h" 5. 6. #define CUSTOM_SYMBOL '^' // '+' and '/' and ' \ 'is NOT allowed 7. #define MAX_UART_LEN 128 8. 9. /***************************************************************************** 10. * customer command 11. *****************************************************************************/ 12. #define PLAY "play" 13. #define STOP "stop" 14. 15. kal_uint8 custom_get_atcmd_symbol(void); 16. void custom_command_hdlr(char *full_cmd_string); 17. extern void rmmi_write_to_uart(kal_uint8 * buffer, kal_uint16 length, kal_bool stuff); 18. 19. /***************************************************************************** 20. * FUNCTION 21. * custom_command_hdlr() 22. * DESCRIPTION 23. * This function should parse the custom AT command and do correspondent action. 24. * Customer should maintain and modify the code. 25. * PARAMETERS 26. * kal_uint8 * cmd_string 27. * RETURNS 28. * none 29. *****************************************************************************/ 30. void custom_command_hdlr(char *full_cmd_string) 31. { 32. char buffer[MAX_UART_LEN]; 33. char cmd_name[15]; 34. kal_uint8 index = 3; // we start parsing index after the CUSTOM_SYMBOL 35. kal_uint8 tmp_idx = 0; 36. 37. while ((full_cmd_string[index] != '=' ) && //might be TEST command or EXE command 38. (full_cmd_string[index] != '?' ) && // might be READ command 39. (full_cmd_string[index] != 13 )) //carriage return 40. { 41. cmd_name[tmp_idx] = full_cmd_string[index] ; 42. tmp_idx ++; 43. index ++; 44. } 45. cmd_name[tmp_idx] = '\0' ; 46. 47. /* just a very basic example : customer can implement their own */ 48. if (strcmp(cmd_name, PLAY) == 0) 49. { 50. /* BEGIN: do the following parsing and correspondent action */ 51. /* */ 52. /* */ 53. /* */ 54. /* END: do the following parsing and correspondent action */ 55. /* generate final result code: "OK" */ 56. //Todo 实现消息分发或功能调用 57. sprintf(buffer, "Hello Play"); 58. printf("%s\n", "Hello Play"); 59. rmmi_write_to_uart((kal_uint8*)buffer, (kal_uint16)strlen(buffer), KAL_TRUE); 60. } 61. else if (strcmp(cmd_name, STOP) == 0) 62. { 63. /* BEGIN: do the following parsing and correspondent action */ 64. /* */ 65. /* */ 66. /* */ 67. /* END: do the following parsing and correspondent action */ 68. /* generate final result code: "OK" */ 69. //Todo 实现消息分发或功能调用 70. sprintf(buffer, "Hello Stop"); 71. printf("%s\n", "Hello Stop"); 72. rmmi_write_to_uart((kal_uint8*)buffer, (kal_uint16)strlen(buffer), KAL_TRUE); 73. } 74. else 75. { 76. /* unrecognized command */ 77. /* generate final result code: "ERROR" */ 78. sprintf(buffer, "ERROR"); 79. printf("%s\n", "ERROR"); 80. rmmi_write_to_uart((kal_uint8*)buffer, (kal_uint16)strlen(buffer), KAL_TRUE); 81. } 82. 83. return; 84. } 85. 86. kal_uint8 custom_get_atcmd_symbol(void) 87. { 88. return (CUSTOM_SYMBOL); 89. } |