You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
1.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "protocolAT.h"
  2. #define LOG(X) m_pLog->Log("pAT", this, X)
  3. #ifdef DEBUG
  4. #define LOG_ERROR(X) \
  5. { \
  6. char _tBfrErrMSG2w34[256]; \
  7. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  8. m_pLog->Log("pAT", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  9. }
  10. #else
  11. #define LOG_ERROR(X) m_pLog->Log("pAT", this, _LOG_ERROR, X);
  12. #endif
  13. protocolAT::protocolAT() {}
  14. protocolAT::~protocolAT() {}
  15. bool protocolAT::create(void)
  16. {
  17. if (m_oDataTransport)
  18. {
  19. if (m_oDataTransport->getConnectionStatus() == CS_CONNECTED)
  20. {
  21. // Turn Off Echo
  22. m_oDataTransport->sendData((unsigned char *) AT_BEG "E" AT_EOL, 5);
  23. waitResponce();
  24. m_oDataTransport->sendData((unsigned char *) AT_BEG "I" AT_EOL, 5);
  25. waitResponce();
  26. };
  27. };
  28. return false;
  29. }
  30. int protocolAT::packetChecker(U8 * Buffer, size_t BufferSize)
  31. {
  32. if (BufferSize)
  33. {
  34. if (Buffer[0] < 0x20)
  35. {
  36. return -1;
  37. }
  38. if (Buffer[BufferSize - 1] == 0x0A)
  39. {
  40. return 0;
  41. }
  42. };
  43. return 1;
  44. }
  45. bool protocolAT::packetHandler(protocolPackage * Package) {}
  46. protocolPackage * protocolAT::packetExtractor(U8 * Buffer, size_t BufferSize)
  47. {
  48. protocolPackage * tVal = NULL;
  49. if (BufferSize)
  50. {
  51. int idx = 0;
  52. tVal = (protocolPackage *) malloc(sizeof(protocolPackage));
  53. if (tVal)
  54. {
  55. memset(tVal, 0, sizeof(protocolPackage));
  56. for (idx = 0; idx < BufferSize; idx++)
  57. {
  58. if (Buffer[idx] == 0x0D)
  59. {
  60. break;
  61. }
  62. };
  63. tVal->m_nCode = 200;
  64. if (idx < (BufferSize - 2))
  65. {
  66. // Must be fetched OK status
  67. };
  68. }
  69. else
  70. {
  71. LOG_ERROR("pkg malloc!");
  72. }
  73. };
  74. return tVal;
  75. }
  76. void protocolAT::waitResponce(uint32_t TO)
  77. {
  78. while (TO--)
  79. {
  80. SLEEP(50);
  81. }
  82. }
  83. #undef LOG
  84. #undef LOG_ERROR