Major update:
- Converted CSocketCore to Class/Object - Implemented CFunctionCore as base class for CPortCore and CSocketCore - Moved common functions to CFunctionCore and renamed eg. Maintain() -> Process() - Pass Objects directly to each other as OutputFunction - New Input() method allows data transfer between objects
This commit is contained in:
87
PortCore.cpp
87
PortCore.cpp
@@ -7,7 +7,6 @@
|
||||
|
||||
// redA Libraries
|
||||
#include "PortCore.h"
|
||||
#include "TimingCore.h"
|
||||
#include "LogCore.h"
|
||||
|
||||
// Standard C/C++ Libraries
|
||||
@@ -22,46 +21,21 @@
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CPortCore::CPortCore( const char * PortName, const int PortInBufSize )
|
||||
CPortCore::CPortCore( const char * PortName ) :
|
||||
CFunctionCore( PortName )
|
||||
{
|
||||
// Port File Handle
|
||||
Handle = -1;
|
||||
|
||||
// Copy Port name
|
||||
if (PortName) {
|
||||
Name = (char*)malloc( strlen( PortName)+ 1);
|
||||
strcpy( Name, PortName );
|
||||
}
|
||||
else {
|
||||
Name = NULL;
|
||||
}
|
||||
|
||||
// In buffer
|
||||
Buffer = new CBuffer( PortInBufSize );
|
||||
|
||||
// Input Timeout
|
||||
InStart.tv_sec = 0;
|
||||
InStart.tv_usec = 0;
|
||||
InTimeout = 100; // millisecs
|
||||
|
||||
// Input Markers
|
||||
InMarkers = NULL;
|
||||
InMarkerLen = 0;
|
||||
|
||||
// Output
|
||||
OutputHandle = -1;
|
||||
// Port File Handle
|
||||
Handle = -1;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CPortCore::~CPortCore()
|
||||
{
|
||||
// Destroy pointers
|
||||
if (Name) {
|
||||
free( Name );
|
||||
}
|
||||
if (Buffer) {
|
||||
delete Buffer;
|
||||
}
|
||||
if (InMarkers) {
|
||||
free( InMarkers );
|
||||
}
|
||||
@@ -136,14 +110,6 @@ bool CPortCore::InputConfig( const long InputTimeout, const char * InputMarkers,
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Configure output options
|
||||
bool CPortCore::OutputConfig( int PortOutputHandle )
|
||||
{
|
||||
OutputHandle = PortOutputHandle;
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Set serial port configuration parameters
|
||||
bool CPortCore::SerialConfig( int Baud, short DataBits, short StopBits, short Parity, short FlowCtrl, int Wait )
|
||||
{
|
||||
@@ -283,21 +249,9 @@ bool CPortCore::SerialConfig( int Baud, short DataBits, short StopBits, short Pa
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CPortCore::Read( const int MaxRead )
|
||||
int CPortCore::Input( int InputID, char * Data, int Len )
|
||||
{
|
||||
int BytesRead = 0;
|
||||
|
||||
// Read File directly into buffer
|
||||
if (!(BytesRead = Buffer->ReadFromFD( Handle )))
|
||||
return false;
|
||||
|
||||
// Process Buffer
|
||||
ProcessBuffer( false );
|
||||
|
||||
// Reset timer
|
||||
SetStartTime( &InStart );
|
||||
|
||||
return true;
|
||||
return WriteToFD( Handle, Data, Len );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -320,7 +274,8 @@ bool CPortCore::ProcessBuffer( bool Force )
|
||||
ShowOutput( "Port In", OUT_NORMAL, Data, Len );
|
||||
|
||||
// Write buffer to Port
|
||||
Buffer->WriteToFD( OutputHandle, Len );
|
||||
if (OutFunction)
|
||||
OutFunction->Input( 0, Data, Len );
|
||||
|
||||
// Clear processed bytes from buffer
|
||||
Buffer->Clear( Len );
|
||||
@@ -335,7 +290,8 @@ bool CPortCore::ProcessBuffer( bool Force )
|
||||
ShowOutput( "Port In", OUT_NORMAL, Data, Len );
|
||||
|
||||
// Write buffer to Port
|
||||
Buffer->WriteToFD( OutputHandle, Len );
|
||||
if (OutFunction)
|
||||
OutFunction->Input( 0, Data, Len );
|
||||
|
||||
// Clear processed bytes from buffer
|
||||
Buffer->Clear( Len );
|
||||
@@ -345,26 +301,3 @@ bool CPortCore::ProcessBuffer( bool Force )
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CPortCore::Maintain()
|
||||
{
|
||||
// Misc
|
||||
long Duration = 0;
|
||||
|
||||
if (Buffer->Len() > 0)
|
||||
{
|
||||
// Check duration since last PortIn
|
||||
Duration = TimePassed( InStart );
|
||||
if (Duration > InTimeout)
|
||||
{
|
||||
// Process Input
|
||||
ProcessBuffer( true );
|
||||
|
||||
// Reset timer
|
||||
SetInterval( &InStart, 0 );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user