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.

79 lines
1.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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 "../../data/transport/transportSocket.h"
  35. typedef enum E_SOL_TYPE{
  36. SOL_UDP_CLIENT = 0,
  37. SOL_TCP_CLIENT = 1,
  38. SOL_UDP_SERVER = 2,
  39. SOL_TCP_SERVER = 3
  40. }SOL_TYPE;
  41. /**
  42. * TODO: Add class description
  43. *
  44. * @author gagua
  45. */
  46. class serialSOL: public transportSocket {
  47. private:
  48. basicLogCollection *m_pLog;
  49. SOL_TYPE m_eSolType;
  50. bool m_bInitComplete;
  51. #ifdef __linux__
  52. int m_nSocketFD;
  53. struct sockaddr_in m_sServerAddr;
  54. struct sockaddr_in m_sClientAddr;
  55. #else
  56. WSADATA wsaData;
  57. SOCKET m_sSocket;
  58. SOCKADDR_IN ReceiverAddr;
  59. int SelectTiming;
  60. #endif
  61. protected:
  62. int sendBlock( unsigned char *Data, int DataSize );
  63. int recptBlock( unsigned char *Buffer, int *BufferLength );
  64. public:
  65. explicit serialSOL( SOL_TYPE t );
  66. virtual ~serialSOL();
  67. bool create( CSTR address, uint16_t port, int Speed );
  68. };
  69. #endif