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.

76 lines
2.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __ARGUS_HARDWARE_SERIAL_PROVIDER_HEADER__
  2. #define __ARGUS_HARDWARE_SERIAL_PROVIDER_HEADER__
  3. #include "rgooseHardwareResource.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 RASPI_HARDWARE
  15. #include <wiringPi.h>
  16. #endif
  17. #endif
  18. #ifdef DEBUG_EXTRA
  19. #define DEBUG_SERIAL_COMMUNICATION
  20. #endif
  21. #ifndef MAXIMAL_SOCKET_PACKET_LENGTH
  22. #define MAXIMAL_SOCKET_PACKET_LENGTH 102400
  23. #endif
  24. #ifndef MAXIMAL_SERIAL_PACKET_LENGTH
  25. #define MAXIMAL_SERIAL_PACKET_LENGTH MAXIMAL_SOCKET_PACKET_LENGTH
  26. #endif
  27. class argusHardwareResourceSerialProvider: public argusHardwareResource, public basicTransport, public basicDualThread {
  28. private:
  29. basicLogCollection * m_pLog;
  30. DBC_UART_DATA m_sUartData;
  31. int m_iDeviceFD;
  32. int m_iMasterFD;
  33. #ifdef __linux__
  34. struct termios m_sTTY;
  35. int m_iInFID;
  36. int m_iOutFID;
  37. bool m_bManualRTS;
  38. void setRTS( uint8_t Val );
  39. #else
  40. DCB PortDCB;
  41. HANDLE m_ioFID;
  42. #endif
  43. bool pingDevice();
  44. bool create_SOL();
  45. bool create_HW();
  46. bool closePort();
  47. int sendBlock(unsigned char *Data, int DataSize);
  48. int recptBlock(unsigned char *Buffer, int *BufferLength);
  49. protected:
  50. U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  51. U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  52. int m_nInputBufferSize;
  53. int m_nOutputBufferSize;
  54. virtual void m_fThreadAProc(void);
  55. virtual void m_fThreadBProc(void);
  56. public:
  57. explicit argusHardwareResourceSerialProvider( uint32_t dbID );
  58. virtual ~argusHardwareResourceSerialProvider();
  59. virtual bool create( void );
  60. virtual bool validate( void );
  61. virtual bool sendData( uint8_t *Data, int DataSize );
  62. virtual bool reconnect( void );
  63. };
  64. #endif