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.

78 lines
2.7 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 __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 argusHardwareResourceSerialProvider: public argusHardwareResource, public basicTransport, public basicDualThread {
  31. private:
  32. basicLogCollection * m_pLog;
  33. DBC_UART_DATA m_sUartData;
  34. int m_iDeviceFD;
  35. int m_iMasterFD;
  36. #ifdef __linux__
  37. struct termios m_sTTY;
  38. int m_iInFID;
  39. int m_iOutFID;
  40. bool m_bManualRTS;
  41. void setRTS( uint8_t Val );
  42. #else
  43. DCB PortDCB;
  44. HANDLE m_ioFID;
  45. #endif
  46. bool pingDevice();
  47. bool create_SOL();
  48. bool create_HW();
  49. bool closePort();
  50. int sendBlock(unsigned char *Data, int DataSize);
  51. int recptBlock(unsigned char *Buffer, int *BufferLength);
  52. protected:
  53. U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  54. U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH];
  55. int m_nInputBufferSize;
  56. int m_nOutputBufferSize;
  57. virtual void m_fThreadAProc(void);
  58. virtual void m_fThreadBProc(void);
  59. public:
  60. explicit argusHardwareResourceSerialProvider( uint32_t dbID );
  61. virtual ~argusHardwareResourceSerialProvider();
  62. virtual bool create( void );
  63. virtual bool validate( void );
  64. virtual bool sendData( uint8_t *Data, int DataSize );
  65. virtual bool reconnect( void );
  66. };
  67. #endif