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.

56 lines
1.2 KiB

7 years ago
​
​
7 years ago
​
​
​
​
​
7 years ago
​
​
7 years ago
​
​
7 years ago
​
7 years ago
​
7 years ago
​
​
​
7 years ago
​
​
7 years ago
​
7 years ago
​
7 years ago
​
7 years ago
​
​
​
​
7 years ago
​
​
7 years ago
​
​
  1. #include "transportBus.h"
  2. #define LOG(X) m_pLog->Log("TransportBus", this, X)
  3. #define LOG_ERROR(X) m_pLog->Log("TransportBus", this, _LOG_ERROR, X)
  4. transportBus::transportBus() :
  5. basicTransport(),
  6. basicDualThread()
  7. {
  8. m_pLog = basicLogCollection::getInstance();
  9. m_nInputBufferSize = -1;
  10. m_nOutputBufferSize = -1;
  11. m_pInputBuffer = (U8 *) malloc(MAXIMAL_BUS_PACKET_LENGTH);
  12. if (m_pInputBuffer != NULL)
  13. {
  14. m_nInputBufferSize = 0;
  15. m_pOutputBuffer = (U8 *) malloc(MAXIMAL_BUS_PACKET_LENGTH);
  16. if (m_pOutputBuffer != NULL)
  17. {
  18. m_nOutputBufferSize = 0;
  19. // LOG("Starting");
  20. // init(); // Moved to SerialPort
  21. };
  22. };
  23. }
  24. transportBus::~transportBus()
  25. {
  26. if (m_pInputBuffer != NULL)
  27. {
  28. free(m_pInputBuffer);
  29. };
  30. if (m_pOutputBuffer != NULL)
  31. {
  32. free(m_pOutputBuffer);
  33. };
  34. }
  35. bool transportBus::sendData(unsigned char * Data, int DataSize)
  36. {
  37. m_mBufferProtectorMutex.lock();
  38. if (m_nOutputBufferSize + DataSize > MAXIMAL_BUS_PACKET_LENGTH)
  39. {
  40. m_mBufferProtectorMutex.unlock();
  41. LOG("Data Too Long");
  42. return false;
  43. };
  44. LOG("Output Data Set");
  45. memcpy(m_pOutputBuffer + m_nOutputBufferSize, Data, DataSize);
  46. m_nOutputBufferSize += DataSize;
  47. m_mBufferProtectorMutex.unlock();
  48. return true;
  49. }
  50. #undef LOG
  51. #undef LOG_ERROR