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.

119 lines
3.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "protocolTGZ.h"
  2. #define LOG(X) m_pLog->Log("protocolTGZ", this, X)
  3. #define LOG_ERROR(X) m_pLog->Log("protocolTGZ", this, _LOG_ERROR, X)
  4. protocolTGZ::protocolTGZ(basicTransport * canBus /*, U8 MyID, U8 PeerID */) :
  5. protocolParser()
  6. {
  7. m_pLog = basicLogCollection::getInstance();
  8. lastSent = 0;
  9. preparing = 0;
  10. lastReceived = 0;
  11. m_bRun = false;
  12. m_bErrorReset = false;
  13. m_bPRF = 0;
  14. m_bRatio = 0;
  15. m_bDivider = 1;
  16. m_oDataTransport = canBus;
  17. if (m_oDataTransport != NULL)
  18. {
  19. m_oDataTransport->addRecipient(this);
  20. };
  21. // m_bHostID = MyID;
  22. // m_bDeviceID = PeerID;
  23. m_nQFreq = 0;
  24. m_nBFreq = 0;
  25. m_bVersion2 = false;
  26. update();
  27. }
  28. int protocolTGZ::packetChecker(U8 * Buffer, size_t BufferSize)
  29. {
  30. if (BufferSize > 3)
  31. {
  32. lastReceived = (Buffer[3] << 24) | (Buffer[2] << 16) | (Buffer[1] << 8) | Buffer[0];
  33. LOG("Rcpt Package");
  34. return 0;
  35. }
  36. else
  37. {
  38. return -1;
  39. }
  40. }
  41. protocolPackage * protocolTGZ::packetExtractor(U8 * Buffer, size_t BufferSize)
  42. {
  43. protocolPackage * RetVal = NULL;
  44. if (BufferSize > 3)
  45. {
  46. lastReceived = (Buffer[3] << 24) | (Buffer[2] << 16) | (Buffer[1] << 8) | Buffer[0];
  47. RetVal = (protocolPackage *) malloc(sizeof(protocolPackage));
  48. if (RetVal != NULL)
  49. {
  50. RetVal->m_nSize = BufferSize;
  51. RetVal->m_pData = (U8 *) malloc(BufferSize);
  52. if (RetVal->m_pData != NULL)
  53. {
  54. memcpy(RetVal->m_pData, Buffer, BufferSize);
  55. }
  56. else
  57. {
  58. RetVal->m_nSize = 0;
  59. };
  60. };
  61. char text[256];
  62. sprintf(text, "Extracted Package [0x%02X][0x%02X][0x%02X][0x%02X]", Buffer[0], Buffer[1], Buffer[2], Buffer[3]);
  63. LOG(text);
  64. };
  65. return RetVal;
  66. }
  67. bool protocolTGZ::startDeviceStateInquiry(void)
  68. {
  69. LOG("Start Device Inquiry");
  70. // if( this ){
  71. U8 Buffer[4];
  72. Buffer[0] = (preparing & 0xFF);
  73. Buffer[1] = ((preparing >> 8) & 0xFF);
  74. Buffer[2] = ((preparing >> 16) & 0xFF);
  75. Buffer[3] = ((preparing >> 24) & 0xFF);
  76. char text[256];
  77. sprintf(text, "Buffer is set [0x%02X][0x%02X][0x%02X][0x%02X]", Buffer[0], Buffer[1], Buffer[2], Buffer[3]);
  78. LOG(text);
  79. // Buffer[5]=checksumLGS( Buffer, 5 );
  80. // pthread_mutex_lock( &m_mInquiryMutex );
  81. LOG("Ask State");
  82. lastSent = preparing;
  83. m_oDataTransport->sendData(Buffer, 4);
  84. // pthread_mutex_lock( &m_mInquiryMutex );
  85. // pthread_mutex_unlock( &m_mInquiryMutex );
  86. LOG("Ask State -> Done");
  87. return true;
  88. //};
  89. // return false;
  90. }
  91. void protocolTGZ::update(void)
  92. {
  93. preparing = 0;
  94. if (! m_bVersion2)
  95. {
  96. preparing = (preparing & (~0x00000001)) | ((m_bErrorReset) ? 0x00000001 : 0);
  97. preparing = (preparing & (~0x00000002)) | ((m_bRun) ? 0x00000002 : 0);
  98. preparing = (preparing & (~0x0000FF00)) | (m_bPRF << 8);
  99. preparing = (preparing & (~0x00FF0000)) | (m_bRatio << 16);
  100. preparing = (preparing & (~0xFF000000)) | (m_bDivider << 24);
  101. }
  102. else
  103. {
  104. preparing = (preparing & (~0x00000001)) | ((m_bErrorReset) ? 0x00000001 : 0);
  105. preparing = (preparing & (~0x00000002)) | ((m_bRun) ? 0x00000002 : 0);
  106. preparing |= (m_nBFreq & 0x3FFF) << 2;
  107. preparing |= (m_nQFreq & 0xFFFF) << 16;
  108. };
  109. }
  110. #undef LOG
  111. #undef LOG_ERROR