Important Update:
- Improve parameter checking before function execution - Rename functions: Get->Peek, ReadFD->ReadFromFD, WriteFD->WriteToFD - Add StartPos param to Peek() & FindChar() - Add ClearChar param for GetChar() - Add default values for Position and Lengths Get, Set, Clear, Push, Peek, GetChar, FindChar
This commit is contained in:
18
PortCore.cpp
18
PortCore.cpp
@@ -59,10 +59,12 @@ CPortCore::~CPortCore()
|
||||
if (Name) {
|
||||
free( Name );
|
||||
}
|
||||
|
||||
if (Buffer) {
|
||||
delete Buffer;
|
||||
}
|
||||
if (InMarkers) {
|
||||
free( InMarkers );
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -122,6 +124,7 @@ bool CPortCore::InputConfig( const long InputTimeout, const char * InputMarkers,
|
||||
InTimeout = InputTimeout;
|
||||
if (InputMarkerLen && InputMarkers) {
|
||||
InMarkerLen = InputMarkerLen;
|
||||
if (InMarkers) { free( InMarkers ); }
|
||||
InMarkers = (char *)malloc( InMarkerLen );
|
||||
memcpy( InMarkers, InputMarkers, InMarkerLen );
|
||||
}
|
||||
@@ -285,7 +288,7 @@ bool CPortCore::Read( const int MaxRead )
|
||||
int BytesRead = 0;
|
||||
|
||||
// Read File directly into buffer
|
||||
if (!(BytesRead = Buffer->ReadFD( Handle )))
|
||||
if (!(BytesRead = Buffer->ReadFromFD( Handle )))
|
||||
return false;
|
||||
|
||||
// Process Buffer
|
||||
@@ -313,11 +316,11 @@ bool CPortCore::ProcessBuffer( bool Force )
|
||||
if (Force)
|
||||
{
|
||||
// Show Packet
|
||||
Len = Buffer->Get( &Data );
|
||||
Len = Buffer->Peek( &Data );
|
||||
ShowOutput( "Port In", OUT_NORMAL, Data, Len );
|
||||
|
||||
// Write buffer to Port
|
||||
Buffer->WriteFD( OutputHandle, Len );
|
||||
Buffer->WriteToFD( OutputHandle, Len );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -325,13 +328,16 @@ bool CPortCore::ProcessBuffer( bool Force )
|
||||
while (Buffer->FindChar( '\n', Pos ))
|
||||
{
|
||||
// Show Packet
|
||||
Len = Buffer->Get( &Data, Pos+1 );
|
||||
Len = Buffer->Peek( &Data, Pos+1 );
|
||||
ShowOutput( "Port In", OUT_NORMAL, Data, Len );
|
||||
|
||||
// Write buffer to Port
|
||||
Buffer->WriteFD( OutputHandle, Len );
|
||||
Buffer->WriteToFD( OutputHandle, Len );
|
||||
}
|
||||
}
|
||||
// Clear processed bytes from buffer
|
||||
Buffer->Clear( Len );
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user