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.

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