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.

114 lines
2.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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. #if defined( HALF_DUPLEX ) || defined( SERIAL_PING_PONG )
  39. class hardwareResourceSerialProvider : public hardwareResource, public basicTransport, public basicThread
  40. {
  41. #else // ! HALF_DUPLEX SERIAL_PING_PONG
  42. class hardwareResourceSerialProvider : public hardwareResource, public basicTransport, public basicDualThread
  43. {
  44. #endif // ! HALF_DUPLEX SERIAL_PING_PONG
  45. private:
  46. DBC_UART_DATA m_sUartData;
  47. int m_iDeviceFD;
  48. int m_iMasterFD;
  49. #ifdef __linux__
  50. struct termios m_sTTY;
  51. int m_iInFID;
  52. int m_iOutFID;
  53. bool m_bManualRTS;
  54. void setRTS(uint8_t Val);
  55. #else
  56. DCB PortDCB;
  57. HANDLE m_ioFID;
  58. #endif
  59. bool pingDevice();
  60. bool create_SOL();
  61. bool create_HW();
  62. bool closePort();
  63. int sendBlock(unsigned char * Data, int DataSize);
  64. int recptBlock(unsigned char * Buffer, int * BufferLength);
  65. protected:
  66. #ifdef FIO_SELECT_MODE
  67. int m_nSenderSetMax;
  68. int m_nReaderSetMax;
  69. fd_set m_sSenderSet;
  70. fd_set m_sReaderSet;
  71. int m_iControlPipeFD[2];
  72. #endif
  73. #if defined( HALF_DUPLEX ) || defined( SERIAL_PING_PONG )
  74. virtual void m_fThreadProc(void);
  75. Q_SIO_TZ m_qIO;
  76. // Q_SIO_TZ m_qREADY;
  77. #else
  78. U8 m_pInputBuffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH]; // 100KB
  79. U8 m_pOutputBuffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH];
  80. int m_nInputBufferSize;
  81. int m_nOutputBufferSize;
  82. virtual void m_fThreadAProc(void);
  83. virtual void m_fThreadBProc(void);
  84. #endif
  85. public:
  86. explicit hardwareResourceSerialProvider(uint32_t dbID);
  87. virtual ~hardwareResourceSerialProvider();
  88. virtual bool create(void);
  89. virtual bool validate(void);
  90. #ifdef SERIAL_PING_PONG
  91. virtual bool sendData(uint8_t * Data, int DataSize, protocolParser *src = NULL );
  92. #else
  93. virtual bool sendData(uint8_t * Data, int DataSize );
  94. #endif
  95. virtual bool reconnect(void);
  96. virtual bool activate( void );
  97. };
  98. #endif