- Convert PortCore functions into Class Bug fixes: - Correctly handle socket close event (return false on read) - Only write to port/socket if valid file handle
64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
/*
|
|
* PortCore.h
|
|
*
|
|
* Created on: 13 May 2016
|
|
* Author: wentzelc
|
|
*/
|
|
|
|
#ifndef PORTCORE_H_
|
|
#define PORTCORE_H_
|
|
|
|
// redA Libraries
|
|
/* none */
|
|
|
|
// Standard C/C++ Libraries
|
|
#include <sys/time.h>
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Defines required to configure port
|
|
#define NO_PARITY 0
|
|
#define ODD_PARITY 1
|
|
#define EVEN_PARITY 2
|
|
#define MARK_PARITY 3
|
|
#define SPACE_PARITY 4
|
|
|
|
#define NO_FLOWCTRL 0
|
|
#define HW_FLOWCTRL 1
|
|
#define SW_FLOWCTRL 2
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Port Core Class
|
|
class CPortCore
|
|
{
|
|
private:
|
|
// Port Def
|
|
int Handle;
|
|
char * Name;
|
|
|
|
// PortIn buffer
|
|
char * InBuffer;
|
|
int InBufLen;
|
|
int InLen;
|
|
int BytesRead;
|
|
|
|
// PortIn Timer
|
|
timeval InStart;
|
|
long InTimeout; // millisecs
|
|
|
|
public:
|
|
CPortCore( const char * PortName, const int PortInBufLen );
|
|
~CPortCore();
|
|
|
|
bool Open();
|
|
bool Close();
|
|
bool Config( int Baud, short DataBits, short StopBits, short Parity, short FlowCtrl, int Wait );
|
|
int GetHandle() { return Handle; };
|
|
|
|
bool Read();
|
|
bool Maintain( int SocketHandle );
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif /* PORTCORE_H_ */
|