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.

104 lines
3.0 KiB

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