您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

221 行
7.9 KiB

  1. #include "ATCmdInterpreter.h"
  2. #include "SIM7080GInterface.h"
  3. #include "define.h"
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "SIM7080GInterface.h"
  8. bool mCAStateReceived;
  9. char mMasterData[100];
  10. int mMasterDataSize;
  11. char mInputString[100];
  12. void InitATCmdInterpreter()
  13. {
  14. mCAStateReceived = false;
  15. }
  16. int AnalyzeNewATString(char* Str, int StrLen, int CurCmd)
  17. {
  18. memset(mInputString,0,100);
  19. memcpy(mInputString,Str,StrLen);
  20. switch(CurCmd)
  21. {
  22. case LTE_MODULE_CONNECT_APN_CMD: //AT+CNACT=0,1
  23. {
  24. if(strncmp(mInputString,"OK",2) == 0) //The command was executed
  25. {
  26. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_OK);
  27. }
  28. else if(strncmp(mInputString,"ERROR",5) == 0) //The command was not executed
  29. {
  30. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_ERROR);
  31. }
  32. break;
  33. }
  34. case LTE_MODULE_DISCONNECT_APN_CMD:
  35. {
  36. if(strncmp(mInputString,"OK",2) == 0) //The command was executed
  37. {
  38. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_OK);
  39. }
  40. else if(strncmp(mInputString,"ERROR",5) == 0) //The command was not executed
  41. {
  42. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_ERROR);
  43. }
  44. break;
  45. }
  46. case LTE_MODULE_CHECK_APN_CONNECTION_CMD:
  47. {
  48. if(strncmp("+CNACT:",mInputString,strlen("+CNACT:")) == 0) //+CNACT: 0,1,"10.177.232.192","2605:8D80:5C0:3EED:D90E:5B72:BC1B:281"
  49. {
  50. if(mInputString[8] == '0') //Only consider port 0
  51. {
  52. if(mInputString[10] == '1' || mInputString[10] == '2')
  53. {
  54. LTEModuleAPNConnectionStatus(LTE_MODULE_APN_CONNECTED);
  55. }
  56. else
  57. {
  58. LTEModuleAPNConnectionStatus(LTE_MODULE_APN_DISCONNECTED);
  59. }
  60. }
  61. }
  62. else if(strncmp(mInputString,"OK",2) == 0) //The command was executed
  63. {
  64. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_OK);
  65. }
  66. else if(strncmp(mInputString,"ERROR",5) == 0) //The command was not executed
  67. {
  68. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_ERROR);
  69. }
  70. break;
  71. }
  72. case LTE_MODULE_CONNECT_TO_MASTER_CMD:
  73. {
  74. if(strncmp("+CAOPEN:",mInputString,strlen("+CAOPEN:")) == 0)
  75. {
  76. int result = atoi(&mInputString[11]);
  77. if(StrLen == 12 && mInputString[11] == '0') //The connection on port 0 is established
  78. {
  79. LTEModuleMasterConnectionStatus(LTE_MODULE_MASTER_CONNECTED);
  80. }
  81. else if(result == 1) //socket error, probably caused by APN not connected..
  82. {
  83. LTEModuleMasterConnectionStatus(LTE_MODULE_MASTER_SOCKET_ERROR);
  84. }
  85. else
  86. {
  87. LTEModuleMasterConnectionStatus(LTE_MODULE_MASTER_DISCONNECTED);
  88. }
  89. }
  90. else if(strncmp(mInputString,"OK",2) == 0) //The command was executed
  91. {
  92. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_OK);
  93. }
  94. else if(strncmp(mInputString,"ERROR",5) == 0) //The command was not executed
  95. {
  96. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_ERROR);
  97. }
  98. break;
  99. }
  100. case LTE_MODULE_DISCONNECT_FROM_MASTER_CMD:
  101. {
  102. if(strncmp(mInputString,"OK",2) == 0) //The command was executed
  103. {
  104. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_OK);
  105. }
  106. else if(strncmp(mInputString,"ERROR",5) == 0) //The command was not executed
  107. {
  108. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_ERROR);
  109. }
  110. break;
  111. }
  112. case LTE_MODULE_CHECK_MASTER_CONNECTION_CMD:
  113. {
  114. if(strncmp("+CASTATE:",mInputString,strlen("+CASTATE:")) == 0) //+CASTATE: 0,0
  115. {
  116. mCAStateReceived = true;
  117. if(mInputString[12] == '1') //The connection is established
  118. {
  119. LTEModuleMasterConnectionStatus(LTE_MODULE_MASTER_CONNECTED);
  120. }
  121. else
  122. {
  123. LTEModuleMasterConnectionStatus(LTE_MODULE_MASTER_DISCONNECTED);
  124. }
  125. }
  126. else if(strncmp(mInputString,"OK",2) == 0) //The command was executed
  127. {
  128. if(mCAStateReceived == false)
  129. {
  130. LTEModuleMasterConnectionStatus(LTE_MODULE_MASTER_DISCONNECTED);
  131. }
  132. mCAStateReceived = false;
  133. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_OK);
  134. }
  135. else if(strncmp(mInputString,"ERROR",5) == 0) //The command was not executed
  136. {
  137. mCAStateReceived = false;
  138. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_ERROR);
  139. }
  140. break;
  141. }
  142. case LTE_MODULE_RX_DATA_CMD:
  143. {
  144. if(strncmp("+CARECV:",mInputString,strlen("+CARECV:")) == 0) //+CARECV: 4,test
  145. {
  146. memset(mMasterData,0,100);
  147. mMasterDataSize = 0;
  148. char *token;
  149. // sscanf("%d,%s",&mInputString[9],&DataSize,Data);
  150. token = strtok(&mInputString[9],",");
  151. if(token != NULL)
  152. {
  153. mMasterDataSize = atoi(token);
  154. if(mMasterDataSize < 100)
  155. {
  156. token = strtok(NULL, ",");
  157. if(token != NULL)
  158. {
  159. memcpy(mMasterData,token,mMasterDataSize);
  160. }
  161. }
  162. }
  163. }
  164. if(strncmp(mInputString,"OK",2) == 0) //The command was executed
  165. {
  166. LTEModuleDataReceived(mMasterData,mMasterDataSize);
  167. // LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_OK);
  168. }
  169. else if(strncmp(mInputString,"ERROR",5) == 0) //The command was not executed
  170. {
  171. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_ERROR);
  172. }
  173. break;
  174. }
  175. case LTE_MODULE_TX_DATA_CMD:
  176. {
  177. if(strncmp(mInputString,"OK",2) == 0) //The command was executed
  178. {
  179. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_OK);
  180. }
  181. else if(strncmp(mInputString,"ERROR",5) == 0) //The command was not executed
  182. {
  183. LTECmdResponseReceived(CurCmd,LTE_MODULE_RESULT_ERROR);
  184. }
  185. break;
  186. }
  187. case LTE_MODULE_NO_CMD: //+CADATAIND:
  188. default:
  189. {
  190. if(strncmp("+CADATAIND:",mInputString,strlen("+CADATAIND:")) == 0)
  191. {
  192. LTEModuleNewDataReady();
  193. }
  194. if(strncmp("+APP PDP:",mInputString,strlen("+APP PDP:")) == 0)
  195. {
  196. // LTEModuleNewDataReady();
  197. }
  198. if(strncmp("+CASTATE:",mInputString,strlen("+CASTATE:")) == 0) //+CASTATE: 0,0
  199. {
  200. if(mInputString[12] == '1') //The connection is established
  201. {
  202. LTEModuleMasterConnectionStatus(LTE_MODULE_MASTER_CONNECTED);
  203. }
  204. else
  205. {
  206. LTEModuleMasterConnectionStatus(LTE_MODULE_MASTER_DISCONNECTED);
  207. }
  208. }
  209. break;
  210. }
  211. }
  212. }