TestTask.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /********************************************************************************
  2. * File Name: TestTask.c
  3. * Function Describe:The test task for the system
  4. * Relate Module:
  5. * Explain: Hardware version is HS121
  6. * Writer: ShiLiangWen
  7. * Date: 2015.7.14
  8. *******************************************************************************/
  9. #define THIS_FILE_ID 16
  10. //---------------------------------------------------------------------------------
  11. #include "includes.h"
  12. //OS ID
  13. OS_TID idTestTask;
  14. unsigned char g_ucTestId;//测试账号ID 0未选,1~5分别代表Test001~Test005
  15. unsigned char g_ucTestIdSel;//测试账号选择 0--正常模式 1--选择模式
  16. void ReportTestId(void);
  17. void SendTestIdToModem(unsigned char id);
  18. void TestModeEncodeKeyProcess(void);
  19. void TestModeKeyPress(void);
  20. void TestModeKeyFree(void);
  21. /*************************************************************************************
  22. *
  23. **************************************************************************************/
  24. int IsTestMode(void)
  25. {
  26. int i,KeyFlag;
  27. g_ulKeyValue=0;
  28. for(i=0;i<50;i++){//wait 500ms for getkey
  29. if(0!=(KeyFlag=GetKey())){
  30. if(1==KeyFlag){ //按键按下
  31. if(KEY_DOWN==g_ulKeyValue){
  32. return 1;
  33. }
  34. }
  35. }
  36. os_dly_wait(1);
  37. }
  38. return 0;
  39. }
  40. /*************************************************************************************
  41. *TestTask
  42. **************************************************************************************/
  43. __task void TestTask(void)
  44. {
  45. int KeyFlag;
  46. char *msg;
  47. INT8U err;
  48. char buf[30];
  49. unsigned char ucIsModemOk=0;
  50. RunMake(THIS_FILE_ID);
  51. //Begin MainTask loop
  52. SlwTrace(INF,"Test Mode Start...\r\n");
  53. //Wait NetTask running and modem init Completed
  54. g_ucTestIdSel=1;//选择账号模式未开启
  55. g_ucTestId=0; //默认测试账号Test001
  56. while(1){
  57. if(OS_R_TMO!=os_evt_wait_or(0x0001, 1))break;
  58. //处理UART3接收缓冲区数据
  59. Uart3RecvProcess();
  60. IWDG_ReloadCounter();//喂狗
  61. }
  62. ModemSendAT("AT+ZTTS=1,\"F78B0990E9624B6DD58B268DF753\"\r"); //请选择测试账号
  63. SpeakerEnable();
  64. os_itv_set (1);
  65. while(1)
  66. {
  67. os_itv_wait ();//wait 1 tick
  68. IWDG_ReloadCounter();//喂狗
  69. //处理UART3接收缓冲区数据
  70. Uart3RecvProcess();
  71. //键盘处理
  72. if(0!=(KeyFlag=GetKey())){
  73. //printf("Key F=%d,V=%04x\r\n",KeyFlag,g_ulKeyValue);
  74. //按键处理
  75. if(1==KeyFlag){ //按键按下
  76. TestModeKeyPress();
  77. }else{ //按键释放
  78. TestModeKeyFree();
  79. }
  80. }
  81. RunMake(THIS_FILE_ID);
  82. TestModeEncodeKeyProcess();
  83. RunMake(THIS_FILE_ID);
  84. if(OnOffCheck()){
  85. PWR_EN_LOW;
  86. }
  87. }
  88. }
  89. void ReportTestId(void)
  90. {
  91. SpeakerEnable();
  92. switch(g_ucTestId){
  93. case 1:
  94. ModemSendAT("AT+ZTTS=1,\"4B6DD58B3100\"\r");//测试1
  95. break;
  96. case 2:
  97. ModemSendAT("AT+ZTTS=1,\"4B6DD58B3200\"\r");//测试1
  98. break;
  99. case 3:
  100. ModemSendAT("AT+ZTTS=1,\"4B6DD58B3300\"\r");//测试1
  101. break;
  102. case 4:
  103. ModemSendAT("AT+ZTTS=1,\"4B6DD58B3400\"\r");//测试1
  104. break;
  105. case 5:
  106. ModemSendAT("AT+ZTTS=1,\"4B6DD58B3500\"\r");//测试1
  107. break;
  108. }
  109. }
  110. void TestModeEncodeKeyProcess(void)
  111. {
  112. if(0==g_iEncode)return;
  113. if(g_iEncode>0){//====================顺时针旋转
  114. SlwTrace(DEBUG,"[+]\r\n");
  115. if(g_ucTestIdSel){
  116. if(++g_ucTestId>5)g_ucTestId=1;
  117. ReportTestId();
  118. }
  119. }else{//==============================逆时针旋转
  120. SlwTrace(DEBUG,"[-]\r\n");
  121. if(g_ucTestIdSel){
  122. if(g_ucTestId>1)g_ucTestId--;
  123. else g_ucTestId=5;
  124. ReportTestId();
  125. }
  126. }
  127. g_iEncode=0;
  128. }
  129. void SendTestIdToModem(unsigned char id)
  130. {
  131. char buf[50];
  132. char buf1[100];
  133. char strAccount[10];
  134. if(id>=10)return;
  135. strcpy(strAccount,"PTest001");
  136. strAccount[7]=0x30+id;
  137. //send to modem
  138. SpeakerEnable();
  139. sprintf(buf,"ip=%s;id=%s;pwd=111111;",POC_TEST_SERVER_IP,strAccount);
  140. AscStrToHexStr(buf,buf1);
  141. ModemSendAT("AT+POC=120000");
  142. ModemSendAT(buf1);
  143. ModemSendAT("\r\n");
  144. //send to pc
  145. SlwTrace(INF,"AT+POC=120000");
  146. SlwTrace(INF,buf1);
  147. SlwTrace(INF,"\r\n");
  148. }
  149. /***********************************************************************
  150. *按键按下事件
  151. ************************************************************************/
  152. void TestModeKeyPress(void)
  153. {
  154. static unsigned char sucReportFlag=0;
  155. switch(g_ulKeyValue){
  156. //-------------------------------------------------------------------
  157. case KEY_PPT://=====================PPT KEY Press====================
  158. //-------------------------------------------------------------------
  159. SlwTrace(DEBUG,"[PPT Press]\r\n");
  160. if(g_ucTestIdSel){
  161. if(g_ucTestId>0 && g_ucTestId<6){
  162. SpeakerEnable();
  163. sutPocStatus.PPTpress=1;
  164. MODEM_DTR_LOW;
  165. }else{
  166. SpeakerEnable();
  167. ModemSendAT("AT+ZTTS=1,\"F78B0990E9624B6DD58B268DF753\"\r"); //请选择测试账号
  168. }
  169. }else{
  170. SpeakerEnable();
  171. sutPocStatus.PPTpress=1;
  172. MODEM_DTR_LOW;
  173. }
  174. break;
  175. //-------------------------------------------------------------------
  176. case KEY_UP://=====================FUN1 KEY Press==================
  177. //-------------------------------------------------------------------
  178. SlwTrace(DEBUG,"[KEY1 Press]\r\n");
  179. if(0==g_ucTestIdSel){
  180. g_ucTestIdSel=1;
  181. SpeakerEnable();
  182. ModemSendAT("AT+ZTTS=1,\"F78B0990E9624B6DD58B268DF753\"\r"); //请选择测试账号
  183. }else{
  184. g_ucTestIdSel=0;
  185. SpeakerEnable();
  186. ModemSendAT("AT+ZTTS=1,\"0090FA510990E962\"\r"); //退出选择
  187. }
  188. break;
  189. //-------------------------------------------------------------------
  190. case KEY_DOWN://=====================FUN2 KEY Press=================
  191. break;
  192. }
  193. }
  194. /***********************************************************************
  195. *按键释放事件
  196. ************************************************************************/
  197. void TestModeKeyFree(void)
  198. {
  199. //-------------------------------------------------------------------
  200. if(KEY_PPT==g_ulKeyValue) {//===============PPT KEY Free=============
  201. //-------------------------------------------------------------------
  202. SlwTrace(DEBUG,"[PPT Free]\r\n");
  203. sutPocStatus.PPTpress=0;
  204. MODEM_DTR_HIGH;
  205. //-------------------------------------------------------------------
  206. }else if(KEY_UP==g_ulKeyValue){//=========FUN1 KEY Free==============
  207. //-------------------------------------------------------------------
  208. //-------------------------------------------------------------------
  209. }else if(KEY_DOWN==g_ulKeyValue){//=========FUN1 KEY Free============
  210. //-------------------------------------------------------------------
  211. ReportUserGroupName();
  212. //-------------------------------------------------------------------
  213. }
  214. }