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.

113 lines
3.6 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. #else
  25. #define WIRINGX_PLATFORM "raspberrypi4"
  26. #endif
  27. #endif
  28. #endif
  29. #ifdef DEBUG_EXTRA
  30. #define DEBUG_SERIAL_COMMUNICATION
  31. #endif
  32. #ifndef MAXIMAL_SOCKET_PACKET_LENGTH
  33. #define MAXIMAL_SOCKET_PACKET_LENGTH 102400
  34. #endif
  35. #ifndef MAXIMAL_SERIAL_PACKET_LENGTH
  36. #define MAXIMAL_SERIAL_PACKET_LENGTH MAXIMAL_SOCKET_PACKET_LENGTH
  37. #endif
  38. #include <queue>
  39. typedef struct S_SIO_TZ{
  40. uint32_t id;
  41. bool wReplay;
  42. bool finished;
  43. bool success;
  44. int inp_size;
  45. int out_size;
  46. uint8_t out_buffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  47. uint8_t inp_buffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  48. }SIO_TZ;
  49. typedef std::queue<SIO_TZ*> Q_SIO_TZ;
  50. #ifndef HALF_DUPLEX
  51. class hardwareResourceSerialProvider: public hardwareResource, public basicTransport, public basicDualThread {
  52. #else
  53. class hardwareResourceSerialProvider: public hardwareResource, public basicTransport, public basicThread {
  54. #endif
  55. private:
  56. DBC_UART_DATA m_sUartData;
  57. int m_iDeviceFD;
  58. int m_iMasterFD;
  59. #ifdef __linux__
  60. struct termios m_sTTY;
  61. int m_iInFID;
  62. int m_iOutFID;
  63. bool m_bManualRTS;
  64. void setRTS( uint8_t Val );
  65. #else
  66. DCB PortDCB;
  67. HANDLE m_ioFID;
  68. #endif
  69. bool pingDevice();
  70. bool create_SOL();
  71. bool create_HW();
  72. bool closePort();
  73. int sendBlock(unsigned char *Data, int DataSize);
  74. int recptBlock(unsigned char *Buffer, int *BufferLength);
  75. protected:
  76. #ifndef HALF_DUPLEX
  77. U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH];//100KB
  78. U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  79. int m_nInputBufferSize;
  80. int m_nOutputBufferSize;
  81. virtual void m_fThreadAProc(void);
  82. virtual void m_fThreadBProc(void);
  83. #else
  84. virtual void m_fThreadProc(void);
  85. Q_SIO_TZ m_qIO;
  86. //Q_SIO_TZ m_qREADY;
  87. #endif
  88. public:
  89. explicit hardwareResourceSerialProvider( uint32_t dbID );
  90. virtual ~hardwareResourceSerialProvider();
  91. virtual bool create( void );
  92. virtual bool validate( void );
  93. virtual bool sendData( uint8_t *Data, int DataSize );
  94. virtual bool reconnect( void );
  95. };
  96. #endif