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.

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