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.

88 lines
2.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __SERIAL_PORT_SERIAL_OVER_LAN__
  2. #define __SERIAL_PORT_SERIAL_OVER_LAN__
  3. /*
  4. #!/bin/bash
  5. # open virtual serial port
  6. socat pty,link=$HOME/vmodem0,waitslave tcp:10.73.1.71:23 &
  7. # run the program
  8. ./testcomms.py
  9. # kill socat afterwards
  10. killall socat
  11. https://blog.febo.com/?p=457
  12. https://stackoverflow.com/questions/484740/converting-serial-port-data-to-tcp-ip-in-a-linux-environment
  13. http://www.dest-unreach.org/socat/doc/socat-ttyovertcp.txt
  14. */
  15. #include <fcntl.h> // File control definitions
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <sys/types.h>
  20. #ifdef __linux__
  21. #include <arpa/inet.h>
  22. #include <netinet/in.h>
  23. #include <sys/socket.h>
  24. #include <unistd.h>
  25. #else
  26. #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
  27. #define _WINSOCK_DEPRECATED_NO_WARNINGS
  28. #endif
  29. #include <winsock2.h>
  30. #endif
  31. #ifdef DEBUG
  32. #define _DEBUG_SOL_COMMUNICATION_
  33. #endif
  34. #include "../../components/base/basicThread.h"
  35. #include "../../data/transport/transportSocket.h"
  36. #define SOL_SINGLE_CLIENT
  37. // #define DUBUG_COMMUNICATION
  38. /**
  39. * TODO: Add class description
  40. *
  41. * @author gagua
  42. */
  43. class serialSOL : public transportSocket
  44. {
  45. private:
  46. basicLogCollection * m_pLog;
  47. // SOL_PORT_SETTINGS m_sPortSettings;
  48. SOL_TYPE m_eType;
  49. uint16_t m_nPort;
  50. uint32_t m_nSpeed;
  51. char m_cDeviceAddress[64];
  52. // bool m_bInitComplete;
  53. #ifdef __linux__
  54. int m_nSocketFD;
  55. int m_nMasterSocketFD;
  56. struct sockaddr_in m_sServerAddr;
  57. struct sockaddr_in m_sClientAddr;
  58. #else
  59. WSADATA wsaData;
  60. SOCKET m_sSocket;
  61. SOCKET m_sMasterSocket;
  62. SOCKADDR_IN m_sServerAddr;
  63. SOCKADDR_IN m_sClientAddr;
  64. int SelectTiming;
  65. #endif
  66. protected:
  67. int sendBlock(unsigned char * Data, int DataSize);
  68. int recptBlock(unsigned char * Buffer, int * BufferLength);
  69. // virtual void m_fThreadProc( void );
  70. public:
  71. explicit serialSOL(SOL_TYPE t = SOL_NOT_DEFINED);
  72. explicit serialSOL(SOL_PORT_SETTINGS * PortSettings);
  73. virtual ~serialSOL();
  74. bool create(CSTR address, uint16_t port, int Speed = 0, SOL_TYPE t = SOL_NOT_DEFINED);
  75. bool closePort();
  76. };
  77. #endif