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.

130 lines
3.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
  1. #ifndef __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__
  2. #define __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__
  3. #include "../components/base/basicTransport.h"
  4. #include "hardwareResource.h"
  5. // #define HALF_DUPLEX
  6. // #define FIO_SELECT_MODE
  7. #ifndef HALF_DUPLEX
  8. #include "../components/base/basicDualThread.h"
  9. #else
  10. #include "../components/base/basicThread.h"
  11. #endif
  12. #include <errno.h> // Error number definitions
  13. #include <fcntl.h> // File control definitions
  14. #include <stdio.h> // standard input / output functions
  15. #include <stdlib.h>
  16. #include <string.h> // string function definitions
  17. #include <sys/select.h>
  18. #include <sys/types.h>
  19. #include <unistd.h>
  20. #ifdef __linux__
  21. #include <termios.h> // POSIX terminal control definitions
  22. #include <unistd.h> // UNIX standard function definitions
  23. #if defined(__arm__) || defined(__aarch64__) || defined(RASPI_HARDWARE)
  24. #define USE_WIRINGX
  25. #include <wiringx.h>
  26. #ifdef __aarch64__
  27. #define WIRINGX_PLATFORM "rock4"
  28. #define RTS_PIN_NUMBER 0
  29. #else
  30. #define WIRINGX_PLATFORM "raspberrypi4"
  31. #define RTS_PIN_NUMBER 0
  32. #endif
  33. #endif
  34. #endif
  35. #ifdef DEBUG_EXTRA
  36. // #define DEBUG_SERIAL_COMMUNICATION
  37. #endif
  38. #ifndef MAXIMAL_SERIAL_IO_BUFFER_LENGTH
  39. #define MAXIMAL_SERIAL_IO_BUFFER_LENGTH 102400
  40. #endif
  41. #include <queue>
  42. typedef struct S_SIO_TZ
  43. {
  44. uint32_t id;
  45. bool wReplay;
  46. bool finished;
  47. bool success;
  48. int inp_size;
  49. int out_size;
  50. uint8_t out_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH];
  51. uint8_t inp_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH];
  52. } SIO_TZ;
  53. typedef std::queue<SIO_TZ *> Q_SIO_TZ;
  54. #ifndef HALF_DUPLEX
  55. class hardwareResourceSerialProvider : public hardwareResource, public basicTransport, public basicDualThread
  56. {
  57. #else
  58. class hardwareResourceSerialProvider : public hardwareResource, public basicTransport, public basicThread
  59. {
  60. #endif
  61. private:
  62. DBC_UART_DATA m_sUartData;
  63. int m_iDeviceFD;
  64. int m_iMasterFD;
  65. #ifdef __linux__
  66. struct termios m_sTTY;
  67. int m_iInFID;
  68. int m_iOutFID;
  69. bool m_bManualRTS;
  70. void setRTS(uint8_t Val);
  71. #else
  72. DCB PortDCB;
  73. HANDLE m_ioFID;
  74. #endif
  75. bool pingDevice();
  76. bool create_SOL();
  77. bool create_HW();
  78. bool closePort();
  79. int sendBlock(unsigned char * Data, int DataSize);
  80. int recptBlock(unsigned char * Buffer, int * BufferLength);
  81. protected:
  82. #ifdef FIO_SELECT_MODE
  83. int m_nSenderSetMax;
  84. int m_nReaderSetMax;
  85. fd_set m_sSenderSet;
  86. fd_set m_sReaderSet;
  87. int m_iControlPipeFD[2];
  88. #endif
  89. #ifndef HALF_DUPLEX
  90. U8 m_pInputBuffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH]; // 100KB
  91. U8 m_pOutputBuffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH];
  92. int m_nInputBufferSize;
  93. int m_nOutputBufferSize;
  94. virtual void m_fThreadAProc(void);
  95. virtual void m_fThreadBProc(void);
  96. #else
  97. virtual void m_fThreadProc(void);
  98. Q_SIO_TZ m_qIO;
  99. // Q_SIO_TZ m_qREADY;
  100. #endif
  101. public:
  102. explicit hardwareResourceSerialProvider(uint32_t dbID);
  103. virtual ~hardwareResourceSerialProvider();
  104. virtual bool create(void);
  105. virtual bool validate(void);
  106. virtual bool sendData(uint8_t * Data, int DataSize);
  107. virtual bool reconnect(void);
  108. virtual bool activate( void );
  109. };
  110. #endif