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.

85 lines
2.4 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
6 years ago
​
​
​
6 years ago
​
​
6 years ago
​
​
​
  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 <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <fcntl.h> // File control definitions
  19. #include <sys/types.h>
  20. #ifdef __linux__
  21. #include <unistd.h>
  22. #include <sys/socket.h>
  23. #include <arpa/inet.h>
  24. #include <netinet/in.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. private:
  45. basicLogCollection *m_pLog;
  46. //SOL_PORT_SETTINGS m_sPortSettings;
  47. SOL_TYPE m_eType;
  48. uint16_t m_nPort;
  49. uint32_t m_nSpeed;
  50. char m_cDeviceAddress[64];
  51. //bool m_bInitComplete;
  52. #ifdef __linux__
  53. int m_nSocketFD;
  54. int m_nMasterSocketFD;
  55. struct sockaddr_in m_sServerAddr;
  56. struct sockaddr_in m_sClientAddr;
  57. #else
  58. WSADATA wsaData;
  59. SOCKET m_sSocket;
  60. SOCKET m_sMasterSocket;
  61. SOCKADDR_IN m_sServerAddr;
  62. SOCKADDR_IN m_sClientAddr;
  63. int SelectTiming;
  64. #endif
  65. protected:
  66. int sendBlock( unsigned char *Data, int DataSize );
  67. int recptBlock( unsigned char *Buffer, int *BufferLength );
  68. //virtual void m_fThreadProc( void );
  69. public:
  70. explicit serialSOL( SOL_TYPE t = SOL_NOT_DEFINED );
  71. explicit serialSOL( SOL_PORT_SETTINGS *PortSettings );
  72. virtual ~serialSOL();
  73. bool create( CSTR address, uint16_t port, int Speed = 0, SOL_TYPE t = SOL_NOT_DEFINED );
  74. bool closePort();
  75. };
  76. #endif