Merge branch 'master' into HitNotBLE
# Conflicts: # SelectableCore.cpp # SelectableCore.h
This commit is contained in:
@@ -44,9 +44,6 @@ CSelectableCore::CSelectableCore( const char * pName, const char * pType ) : CSe
|
||||
{
|
||||
// Quick access
|
||||
Selector = Application->Selector;
|
||||
|
||||
// Handles
|
||||
FirstHandle = NULL;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -98,6 +95,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
Handle = CreateHandle( HandleConfig->GetName(), false );
|
||||
Handle->Channel = GetChannel( HandleConfig->GetChStr( "Channel" ) );
|
||||
|
||||
// Load handle specifics
|
||||
Type = (char*)HandleConfig->GetChStr( "Type", "TCPclient", true );
|
||||
if (!strcasecmp( Type, "Serial" ))
|
||||
{
|
||||
@@ -130,6 +128,8 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
FlowCtrl = HW_FLOWCTRL;
|
||||
else if (!strcasecmp( FlowCtrlText, "software" ))
|
||||
FlowCtrl = SW_FLOWCTRL;
|
||||
else if (!strcasecmp( FlowCtrlText, "rs485" ))
|
||||
FlowCtrl = RS485_FLOWCTRL;
|
||||
else
|
||||
FlowCtrl = NO_FLOWCTRL;
|
||||
|
||||
@@ -142,7 +142,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
}
|
||||
else if (!strcasecmp( Type, "LinePrinter" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Port/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) {
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Port/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
} else {
|
||||
Address = (char*)HandleConfig->GetChStr( "Port/Address", NULL, true ); // Get default value
|
||||
@@ -151,7 +151,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
}
|
||||
else if (!strcasecmp( Type, "UNIXserver" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) {
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
} else {
|
||||
Address = (char*)HandleConfig->GetChStr( "Socket/Address", NULL, true ); // Get default Address value
|
||||
@@ -161,7 +161,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
}
|
||||
else if (!strcasecmp( Type, "UNIXclient" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) {
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
} else {
|
||||
Address = (char*)HandleConfig->GetChStr( "Socket/Address", NULL, true ); // Get default Address value
|
||||
@@ -170,7 +170,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
}
|
||||
else if (!strcasecmp( Type, "UDPserver" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) {
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
} else {
|
||||
@@ -182,7 +182,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
}
|
||||
else if (!strcasecmp( Type, "UDPclient" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) {
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
} else {
|
||||
@@ -194,7 +194,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
}
|
||||
else if (!strcasecmp( Type, "TCPserver" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) {
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
} else {
|
||||
@@ -207,7 +207,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
||||
}
|
||||
else if (!strcasecmp( Type, "TCPclient" ))
|
||||
{
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) {
|
||||
if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) {
|
||||
Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value
|
||||
Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value
|
||||
} else {
|
||||
@@ -253,14 +253,9 @@ bool CSelectableCore::SetSerialHandle( THandle * Handle, const char * FileName )
|
||||
// Set Type
|
||||
Handle->Type = ctSerial;
|
||||
|
||||
// Clear File Name
|
||||
if (Handle->Path) {
|
||||
free( Handle->Path );
|
||||
}
|
||||
|
||||
// Set name
|
||||
Handle->Path = (char*)malloc( strlen(FileName)+1 );
|
||||
strcpy( Handle->Path, FileName );
|
||||
// Set path
|
||||
if (Handle->Path) free( Handle->Path );
|
||||
Handle->Path = strdup( FileName );
|
||||
|
||||
// Log event
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Set as Port [%s]",
|
||||
@@ -298,14 +293,9 @@ bool CSelectableCore::SetLinePrinterHandle( THandle * Handle, const char * FileN
|
||||
// Set Type
|
||||
Handle->Type = ctLinePrinter;
|
||||
|
||||
// Clear File Name
|
||||
if (Handle->Path) {
|
||||
free( Handle->Path );
|
||||
}
|
||||
|
||||
// Set name
|
||||
Handle->Path = (char*)malloc( strlen(FileName)+1 );
|
||||
strcpy( Handle->Path, FileName );
|
||||
// Set Path
|
||||
if (Handle->Path) free( Handle->Path );
|
||||
Handle->Path = strdup( FileName );
|
||||
|
||||
// Log event
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Set as Port [%s]",
|
||||
@@ -324,14 +314,9 @@ bool CSelectableCore::SetForkPipeHandle( THandle * Handle, const char * ExecPath
|
||||
// Set Type
|
||||
Handle->Type = ctForkPipe;
|
||||
|
||||
// Clear File Name
|
||||
if (Handle->Path) {
|
||||
free( Handle->Path );
|
||||
}
|
||||
|
||||
// Set name
|
||||
Handle->Path = (char*)malloc( strlen(ExecPath)+1 );
|
||||
strcpy( Handle->Path, ExecPath );
|
||||
// Set path
|
||||
if (Handle->Path) free( Handle->Path );
|
||||
Handle->Path = strdup( ExecPath );
|
||||
|
||||
// Log event
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Set as ForkPipe [%s]",
|
||||
@@ -358,8 +343,7 @@ bool CSelectableCore::SetUnixHandle( THandle * Handle, EConnectType Type, const
|
||||
}
|
||||
|
||||
// Set name
|
||||
Handle->Path = (char*)malloc( strlen(FileName)+1 );
|
||||
strcpy( Handle->Path, FileName );
|
||||
Handle->Path = strdup( FileName );
|
||||
Handle->Queue = Queue;
|
||||
|
||||
// Log event
|
||||
@@ -391,11 +375,8 @@ bool CSelectableCore::SetSocketHandle( THandle * Handle, EConnectType Type, con
|
||||
freeaddrinfo( Handle->AddressList );
|
||||
|
||||
// Set HostName & Port
|
||||
Handle->HostName = (char*)malloc( strlen(HostName)+1 );
|
||||
strcpy( Handle->HostName, HostName );
|
||||
|
||||
Handle->PortName = (char*)malloc( strlen(PortName)+1 );
|
||||
strcpy( Handle->PortName, PortName );
|
||||
Handle->HostName = strdup( HostName );
|
||||
Handle->PortName = strdup( PortName );
|
||||
|
||||
Handle->AddressList = NULL;
|
||||
Handle->AddressInfo = NULL;
|
||||
@@ -437,6 +418,12 @@ THandle * CSelectableCore::OpenSerialPort( THandle * Handle )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Set Send Enable (via RTS) for RS485
|
||||
if ((Handle->Type == ctSerial) && (Handle->FlowCtrl == RS485_FLOWCTRL)) {
|
||||
int sercmd = TIOCM_RTS;
|
||||
ioctl( Handle->FD, TIOCMBIS, &sercmd );
|
||||
}
|
||||
|
||||
// Log Event
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Serial Port opened [%s]",
|
||||
ProcessName, Name, Handle->Name, Handle->Path );
|
||||
@@ -1533,6 +1520,12 @@ bool CSelectableCore::Close( THandle * Handle, bool QuickReopen )
|
||||
}
|
||||
}
|
||||
|
||||
// Set Send Enable (via RTS) for RS485
|
||||
if ((Handle->Type == ctSerial) && (Handle->FlowCtrl == RS485_FLOWCTRL)) {
|
||||
int sercmd = TIOCM_RTS;
|
||||
ioctl( Handle->FD, TIOCMBIC, &sercmd );
|
||||
}
|
||||
|
||||
// Close Handle
|
||||
if (Handle->Type == ctUDPremote) {
|
||||
Fail = false;
|
||||
@@ -1737,7 +1730,7 @@ bool CSelectableCore::Read( THandle * Handle )
|
||||
|
||||
// Read incoming message and address
|
||||
errno = 0;
|
||||
UDPbuffer = (char*)malloc( BytesWaiting+1 );
|
||||
UDPbuffer = (char*)malloc( BytesWaiting+1 );
|
||||
BytesRead = ReadFromUDP( Handle, (char*)UDPaddress, (char*)UDPport, UDPbuffer, BytesWaiting );
|
||||
|
||||
if (!errno && (Handle->Type == ctUDPserver))
|
||||
@@ -1884,10 +1877,22 @@ bool CSelectableCore::Write( THandle * Handle )
|
||||
{
|
||||
// Write directly to handle / socket
|
||||
errno = 0;
|
||||
if ((Handle->Type == ctUDPclient)|| (Handle->Type == ctUDPremote)) {
|
||||
if ((Handle->Type == ctUDPclient) || (Handle->Type == ctUDPremote)) {
|
||||
Len = Handle->OutBuffer->Peek( &Data );
|
||||
BytesWritten = WriteToUDP( Handle, Data, Len, true );
|
||||
}
|
||||
else if ((Handle->Type == ctSerial) && (Handle->FlowCtrl == RS485_FLOWCTRL)) {
|
||||
// Set Send Enable (via RTS pin) when sending data
|
||||
int sercmd = TIOCM_RTS;
|
||||
ioctl( Handle->FD, TIOCMBIC, &sercmd );
|
||||
usleep( 1000 );
|
||||
|
||||
BytesWritten = Handle->OutBuffer->WriteToFD( Handle->FD );
|
||||
|
||||
tcdrain( Handle->FD );
|
||||
usleep( 1000 );
|
||||
ioctl( Handle->FD, TIOCMBIS, &sercmd );
|
||||
}
|
||||
else {
|
||||
BytesWritten = Handle->OutBuffer->WriteToFD( Handle->FD );
|
||||
}
|
||||
@@ -2143,20 +2148,18 @@ bool CSelectableCore::Process()
|
||||
{
|
||||
THandle * Handle = NULL;
|
||||
|
||||
// Check all handles
|
||||
// Process all Handles
|
||||
Handle = FirstHandle;
|
||||
while (Handle)
|
||||
{
|
||||
// Auto manage handles
|
||||
if ((Handle->State == csOpenRequest))
|
||||
{
|
||||
if ((Handle->State == csOpenRequest)) {
|
||||
// Resolve then open socket
|
||||
if (Timeout( Handle->LastAction, Handle->ResolveDelay )) {
|
||||
Open( Handle, false );
|
||||
}
|
||||
}
|
||||
else if (((Handle->State != csOpen) && Handle->AutoManage && Handle->Persistent) )
|
||||
{
|
||||
else if (((Handle->State != csOpen) && Handle->AutoManage && Handle->Persistent) ) {
|
||||
// Try to re-open port after delay
|
||||
if (Timeout( Handle->LastAction, Handle->ReopenDelay )) {
|
||||
Open( Handle, false );
|
||||
@@ -2164,11 +2167,9 @@ bool CSelectableCore::Process()
|
||||
}
|
||||
|
||||
// Check Input buffers
|
||||
if (Handle->InBuffer && (Handle->InBuffer->Len() > 0))
|
||||
{
|
||||
if (Handle->InBuffer && (Handle->InBuffer->Len() > 0)) {
|
||||
// Check duration since last PortIn
|
||||
if (Timeout( Handle->InStart, Handle->InTimeout ))
|
||||
{
|
||||
if (Timeout( Handle->InStart, Handle->InTimeout )) {
|
||||
// Process Input
|
||||
ProcessInputBuffer( Handle, true );
|
||||
|
||||
@@ -2178,14 +2179,12 @@ bool CSelectableCore::Process()
|
||||
}
|
||||
|
||||
// Check for auto close (but not on servers)
|
||||
if ((Handle->State == csOpen) && (Handle->Type != ctTCPserver) && (Handle->Type != ctUNIXserver) && Handle->AutoManage && !Handle->Persistent)
|
||||
{
|
||||
if ((Handle->State == csOpen) && Handle->AutoManage && !Handle->Persistent && (Handle->Type != ctTCPserver) && (Handle->Type != ctUNIXserver)) {
|
||||
// Close port after timeout
|
||||
if (Timeout( Handle->LastAction, Handle->CloseTimeout )) {
|
||||
Close( Handle, true );
|
||||
}
|
||||
}
|
||||
|
||||
Handle = Handle->Next;
|
||||
}
|
||||
return true;
|
||||
@@ -2471,3 +2470,4 @@ bool CSelectableCore::ReadSerialConfig( THandle * Handle )
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user