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.

67 lines
1.6 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 <stdio.h>
  16. #include <stdlib.h>
  17. #include <unistd.h>
  18. #include <string.h>
  19. #include <fcntl.h> // File control definitions
  20. #include <sys/types.h>
  21. #include <sys/socket.h>
  22. #include <arpa/inet.h>
  23. #include <netinet/in.h>
  24. #ifdef DEBUG
  25. //#define _DEBUG_SOL_COMMUNICATION_
  26. #endif
  27. #include "../../data/transport/transportSocket.h"
  28. typedef enum E_SOL_TYPE{
  29. SOL_UDP_CLIENT = 0,
  30. SOL_TCP_CLIENT = 1,
  31. SOL_UDP_SERVER = 2,
  32. SOL_TCP_SERVER = 3
  33. }SOL_TYPE;
  34. /**
  35. * TODO: Add class description
  36. *
  37. * @author gagua
  38. */
  39. class serialSOL: public transportSocket {
  40. private:
  41. basicLogCollection *m_pLog;
  42. SOL_TYPE m_eSolType;
  43. bool m_bInitComplete;
  44. int m_nSocketFD;
  45. struct sockaddr_in m_sServerAddr;
  46. struct sockaddr_in m_sClientAddr;
  47. protected:
  48. int sendBlock( unsigned char *Data, int DataSize );
  49. int recptBlock( unsigned char *Buffer, int *BufferLength );
  50. public:
  51. explicit serialSOL( SOL_TYPE t );
  52. virtual ~serialSOL();
  53. bool create( CSTR address, uint16_t port, int Speed );
  54. };
  55. #endif