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.
 
 
 
 
 
 

85 lines
2.4 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 "../../components/base/basicThread.h"
#include "../../data/transport/transportSocket.h"
#define SOL_SINGLE_CLIENT
//#define DUBUG_COMMUNICATION
/**
* TODO: Add class description
*
* @author gagua
*/
class serialSOL: public transportSocket {
private:
basicLogCollection *m_pLog;
//SOL_PORT_SETTINGS m_sPortSettings;
SOL_TYPE m_eType;
uint16_t m_nPort;
uint32_t m_nSpeed;
char m_cDeviceAddress[64];
//bool m_bInitComplete;
#ifdef __linux__
int m_nSocketFD;
int m_nMasterSocketFD;
struct sockaddr_in m_sServerAddr;
struct sockaddr_in m_sClientAddr;
#else
WSADATA wsaData;
SOCKET m_sSocket;
SOCKET m_sMasterSocket;
SOCKADDR_IN m_sServerAddr;
SOCKADDR_IN m_sClientAddr;
int SelectTiming;
#endif
protected:
int sendBlock( unsigned char *Data, int DataSize );
int recptBlock( unsigned char *Buffer, int *BufferLength );
//virtual void m_fThreadProc( void );
public:
explicit serialSOL( SOL_TYPE t = SOL_NOT_DEFINED );
explicit serialSOL( SOL_PORT_SETTINGS *PortSettings );
virtual ~serialSOL();
bool create( CSTR address, uint16_t port, int Speed = 0, SOL_TYPE t = SOL_NOT_DEFINED );
bool closePort();
};
#endif