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
79 lines
1.9 KiB
#ifndef __SERIAL_PORT_SERIAL_OVER_LAN__
|
|
#define __SERIAL_PORT_SERIAL_OVER_LAN__
|
|
|
|
/*
|
|
#!/bin/bash
|
|
# open virtual serial port
|
|
socat pty,link=$HOME/vmodem0,waitslave tcp:10.73.1.71:23 &
|
|
# run the program
|
|
./testcomms.py
|
|
# kill socat afterwards
|
|
killall socat
|
|
|
|
https://blog.febo.com/?p=457
|
|
https://stackoverflow.com/questions/484740/converting-serial-port-data-to-tcp-ip-in-a-linux-environment
|
|
http://www.dest-unreach.org/socat/doc/socat-ttyovertcp.txt
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <fcntl.h> // File control definitions
|
|
#include <sys/types.h>
|
|
#ifdef __linux__
|
|
#include <unistd.h>
|
|
#include <sys/socket.h>
|
|
#include <arpa/inet.h>
|
|
#include <netinet/in.h>
|
|
#else
|
|
#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
|
|
#define _WINSOCK_DEPRECATED_NO_WARNINGS
|
|
#endif
|
|
#include <winsock2.h>
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
//#define _DEBUG_SOL_COMMUNICATION_
|
|
#endif
|
|
|
|
#include "../../data/transport/transportSocket.h"
|
|
|
|
|
|
typedef enum E_SOL_TYPE{
|
|
SOL_UDP_CLIENT = 0,
|
|
SOL_TCP_CLIENT = 1,
|
|
SOL_UDP_SERVER = 2,
|
|
SOL_TCP_SERVER = 3
|
|
}SOL_TYPE;
|
|
|
|
/**
|
|
* TODO: Add class description
|
|
*
|
|
* @author gagua
|
|
*/
|
|
class serialSOL: public transportSocket {
|
|
private:
|
|
basicLogCollection *m_pLog;
|
|
SOL_TYPE m_eSolType;
|
|
bool m_bInitComplete;
|
|
#ifdef __linux__
|
|
int m_nSocketFD;
|
|
struct sockaddr_in m_sServerAddr;
|
|
struct sockaddr_in m_sClientAddr;
|
|
#else
|
|
WSADATA wsaData;
|
|
SOCKET m_sSocket;
|
|
SOCKADDR_IN ReceiverAddr;
|
|
int SelectTiming;
|
|
#endif
|
|
protected:
|
|
int sendBlock( unsigned char *Data, int DataSize );
|
|
int recptBlock( unsigned char *Buffer, int *BufferLength );
|
|
public:
|
|
explicit serialSOL( SOL_TYPE t );
|
|
virtual ~serialSOL();
|
|
bool create( CSTR address, uint16_t port, int Speed );
|
|
};
|
|
|
|
|
|
#endif
|