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.

77 lines
2.6 KiB

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. #include "../components/base/basicDualThread.h"
  6. #include <stdio.h> // standard input / output functions
  7. #include <stdlib.h>
  8. #include <string.h> // string function definitions
  9. #include <fcntl.h> // File control definitions
  10. #include <errno.h> // Error number definitions
  11. #ifdef __linux__
  12. #include <unistd.h> // UNIX standard function definitions
  13. #include <termios.h> // POSIX terminal control definitions
  14. #ifdef __arm__
  15. #ifdef RASPI_HARDWARE
  16. #define USE_WIRINGPI
  17. #include <wiringPi.h>
  18. #endif
  19. #endif
  20. #endif
  21. #ifdef DEBUG_EXTRA
  22. #define DEBUG_SERIAL_COMMUNICATION
  23. #endif
  24. #ifndef MAXIMAL_SOCKET_PACKET_LENGTH
  25. #define MAXIMAL_SOCKET_PACKET_LENGTH 102400
  26. #endif
  27. #ifndef MAXIMAL_SERIAL_PACKET_LENGTH
  28. #define MAXIMAL_SERIAL_PACKET_LENGTH MAXIMAL_SOCKET_PACKET_LENGTH
  29. #endif
  30. class hardwareResourceSerialProvider: public hardwareResource, public basicTransport, public basicDualThread {
  31. private:
  32. DBC_UART_DATA m_sUartData;
  33. int m_iDeviceFD;
  34. int m_iMasterFD;
  35. #ifdef __linux__
  36. struct termios m_sTTY;
  37. int m_iInFID;
  38. int m_iOutFID;
  39. bool m_bManualRTS;
  40. void setRTS( uint8_t Val );
  41. #else
  42. DCB PortDCB;
  43. HANDLE m_ioFID;
  44. #endif
  45. bool pingDevice();
  46. bool create_SOL();
  47. bool create_HW();
  48. bool closePort();
  49. int sendBlock(unsigned char *Data, int DataSize);
  50. int recptBlock(unsigned char *Buffer, int *BufferLength);
  51. protected:
  52. U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  53. U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  54. int m_nInputBufferSize;
  55. int m_nOutputBufferSize;
  56. virtual void m_fThreadAProc(void);
  57. virtual void m_fThreadBProc(void);
  58. public:
  59. explicit hardwareResourceSerialProvider( uint32_t dbID );
  60. virtual ~hardwareResourceSerialProvider();
  61. virtual bool create( void );
  62. virtual bool validate( void );
  63. virtual bool sendData( uint8_t *Data, int DataSize );
  64. virtual bool reconnect( void );
  65. };
  66. #endif