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.

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