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.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
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. //bool m_bInitComplete;
  48. #ifdef __linux__
  49. int m_nSocketFD;
  50. int m_nMasterSocketFD;
  51. struct sockaddr_in m_sServerAddr;
  52. struct sockaddr_in m_sClientAddr;
  53. #else
  54. WSADATA wsaData;
  55. SOCKET m_sSocket;
  56. SOCKADDR_IN ReceiverAddr;
  57. int SelectTiming;
  58. #endif
  59. protected:
  60. int sendBlock( unsigned char *Data, int DataSize );
  61. int recptBlock( unsigned char *Buffer, int *BufferLength );
  62. //virtual void m_fThreadProc( void );
  63. public:
  64. explicit serialSOL( SOL_TYPE t );
  65. explicit serialSOL( SOL_PORT_SETTINGS *PortSettings );
  66. virtual ~serialSOL();
  67. bool create( CSTR address, uint16_t port, int Speed );
  68. };
  69. #endif