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.

131 lines
4.0 KiB

4 years ago
​
​
​
​
4 years ago
4 years ago
4 years ago
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
​
​
4 years ago
4 years ago
4 years ago
​
​
​
2 years ago
4 years ago
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__
  2. #define __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__
  3. #include "hardwareResource.h"
  4. #include "../components/base/basicTransport.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 <stdio.h> // standard input / output functions
  13. #include <stdlib.h>
  14. #include <string.h> // string function definitions
  15. #include <fcntl.h> // File control definitions
  16. #include <errno.h> // Error number definitions
  17. #include <sys/types.h>
  18. #include <sys/select.h>
  19. #include <unistd.h>
  20. #ifdef __linux__
  21. #include <unistd.h> // UNIX standard function definitions
  22. #include <termios.h> // POSIX terminal control 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_SOCKET_PACKET_LENGTH
  39. #define MAXIMAL_SOCKET_PACKET_LENGTH 102400
  40. #endif
  41. #ifndef MAXIMAL_SERIAL_PACKET_LENGTH
  42. #define MAXIMAL_SERIAL_PACKET_LENGTH MAXIMAL_SOCKET_PACKET_LENGTH
  43. #endif
  44. #include <queue>
  45. typedef struct S_SIO_TZ{
  46. uint32_t id;
  47. bool wReplay;
  48. bool finished;
  49. bool success;
  50. int inp_size;
  51. int out_size;
  52. uint8_t out_buffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  53. uint8_t inp_buffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  54. }SIO_TZ;
  55. typedef std::queue<SIO_TZ*> Q_SIO_TZ;
  56. #ifndef HALF_DUPLEX
  57. class hardwareResourceSerialProvider: public hardwareResource, public basicTransport, public basicDualThread {
  58. #else
  59. class hardwareResourceSerialProvider: public hardwareResource, public basicTransport, public basicThread {
  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_SOCKET_PACKET_LENGTH];//100KB
  91. U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_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. };
  109. #endif