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.

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