Merge branch 'master' into ModbusCore
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
// Global Vars
|
||||
extern char * ProcessName;
|
||||
extern CApplication * Application;
|
||||
//extern CApplication * Application;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -30,20 +30,9 @@ extern CApplication * Application;
|
||||
CDeviceCore::CDeviceCore( const char * pName, const char * pType ) : CFunctionCore( pName, pType )
|
||||
{
|
||||
// Polling
|
||||
PollCycle = 0;
|
||||
PollStep = 0;
|
||||
PollInterval = 250;
|
||||
SetStartTime( &PollWait );
|
||||
|
||||
WaitingForReply = false;
|
||||
ReplyTimeout = 200;
|
||||
InvalidReply = false;
|
||||
|
||||
PollRetry = 0;
|
||||
MaxRetries = 3;
|
||||
|
||||
// Data Structures
|
||||
DeviceInit = true;
|
||||
ConfigTypes = new CDataMember();
|
||||
ValueTree = new CDataMember();
|
||||
JSONparse = new CJSONparse();
|
||||
@@ -69,7 +58,6 @@ CDeviceCore::~CDeviceCore()
|
||||
bool CDeviceCore::Init( CDataMember * FunctionConfig )
|
||||
{
|
||||
char * PersistFile = NULL;
|
||||
char * ConfigName = NULL;
|
||||
CDataMember * PollConfig = NULL;
|
||||
int IntVal1;
|
||||
int IntVal2;
|
||||
@@ -80,18 +68,19 @@ bool CDeviceCore::Init( CDataMember * FunctionConfig )
|
||||
|
||||
// Add Channels
|
||||
if (!(CmdChannel = GetChannel( "Command" )))
|
||||
CmdChannel = AddChannel( "Command", true, true );
|
||||
if (!(DeviceChannel = GetChannel( "Device" )))
|
||||
DeviceChannel = AddChannel( "Device", true, true );
|
||||
if (!(EventChannel = GetChannel( "Event" )))
|
||||
EventChannel = AddChannel( "Event", true, true );
|
||||
CmdChannel = AddChannel( "Command", CH_ready );
|
||||
else
|
||||
SetChannelInState( CmdChannel, CH_ready );
|
||||
|
||||
// Get configuration
|
||||
if ((Config = FunctionConfig->GetChild( "Config", true )) && Config->isString()) {
|
||||
ConfigName = (char*)FunctionConfig->GetChStr( "Config" );
|
||||
Config = Application->Config->GetChild( ConfigName, true );
|
||||
}
|
||||
if (Config->isNull()) Config->SetObject();
|
||||
if (!(DeviceChannel = GetChannel( "Device" )))
|
||||
DeviceChannel = AddChannel( "Device", CH_ready );
|
||||
else
|
||||
SetChannelInState( DeviceChannel, CH_ready );
|
||||
|
||||
if (!(EventChannel = GetChannel( "Event" )))
|
||||
EventChannel = AddChannel( "Event", CH_ready );
|
||||
else
|
||||
SetChannelInState( EventChannel, CH_ready );
|
||||
|
||||
// Load Polling configuration
|
||||
PollConfig = Config->GetChild( "Polling", true );
|
||||
@@ -442,6 +431,7 @@ bool CDeviceCore::SetPollParam( int pPollInterval )
|
||||
|
||||
bool CDeviceCore::SetReplyParam( int pReplyTimeout, int pMaxRetries )
|
||||
{
|
||||
DefReplyTimeout = pReplyTimeout;
|
||||
ReplyTimeout = pReplyTimeout;
|
||||
MaxRetries = pMaxRetries;
|
||||
return true;
|
||||
@@ -466,12 +456,13 @@ bool CDeviceCore::DeviceOnline( TDevice * Device, bool Online )
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void CDeviceCore::SetWaitForReply()
|
||||
void CDeviceCore::SetWaitForReply( int CustomTimeout )
|
||||
{
|
||||
// Start timer
|
||||
SetStartTime( &PollWait );
|
||||
|
||||
// Set flag
|
||||
ReplyTimeout = (CustomTimeout >= 0)? CustomTimeout : DefReplyTimeout;
|
||||
WaitingForReply = true;
|
||||
InvalidReply = false;
|
||||
}
|
||||
@@ -1622,7 +1613,7 @@ bool CDeviceCore::GetCmdParam( const char * Start, char * Param, char ** NextPar
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
int CDeviceCore::HandleCommand( const char *ChannelName, const char * Data, const int MaxLen )
|
||||
int CDeviceCore::HandleCommand( const char *ChannelName, const char * SourceRef, const char * Data, const int MaxLen )
|
||||
{
|
||||
int Len;
|
||||
char Value[50];
|
||||
@@ -1671,7 +1662,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * Data, cons
|
||||
}
|
||||
else {
|
||||
strcat( OutputStr, "\n" );
|
||||
Output( ChannelName, OutputStr, strlen(OutputStr) );
|
||||
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1680,7 +1671,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * Data, cons
|
||||
Log->Message( LogLevel, dlMedium, "%s/%s: Channel '%s' Get",
|
||||
ProcessName, Name, ChannelName, OutputStr );
|
||||
strcat( OutputStr, "\n" );
|
||||
Output( ChannelName, OutputStr, strlen(OutputStr) );
|
||||
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
||||
}
|
||||
}
|
||||
else if (!strcasecmp( "set", Value ))
|
||||
@@ -1717,7 +1708,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * Data, cons
|
||||
}
|
||||
else {
|
||||
sprintf( OutputStr, "> set %s,%s = %s\n", Device->Name, Param->Name, Value );
|
||||
Output( ChannelName, OutputStr );
|
||||
Output( ChannelName, NULL, true, OutputStr );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1726,7 +1717,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * Data, cons
|
||||
Log->Message( LogLevel, dlMedium, "%s/%s: Channel '%s' Set",
|
||||
ProcessName, Name, ChannelName, OutputStr );
|
||||
strcat( OutputStr, "\n" );
|
||||
Output( ChannelName, OutputStr, strlen(OutputStr) );
|
||||
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
||||
}
|
||||
}
|
||||
else if (!strcasecmp( "status", Value ))
|
||||
@@ -1746,7 +1737,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * Data, cons
|
||||
}
|
||||
else {
|
||||
sprintf( OutputStr, "> %s - %s\n", Device->Name, ((Device->Online)? "online" : "offline") );
|
||||
Output( ChannelName, OutputStr );
|
||||
Output( ChannelName, NULL, true, OutputStr );
|
||||
}
|
||||
|
||||
// Report error
|
||||
@@ -1754,7 +1745,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * Data, cons
|
||||
Log->Message( LogLevel, dlMedium, "%s/%s: Channel '%s' Status",
|
||||
ProcessName, Name, ChannelName, OutputStr );
|
||||
strcat( OutputStr, "\n" );
|
||||
Output( ChannelName, OutputStr, strlen(OutputStr) );
|
||||
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1764,7 +1755,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * Data, cons
|
||||
Log->Message( LogLevel, dlMedium, "%s/%s: Channel '%s', %s%s",
|
||||
ProcessName, Name, ChannelName, Value, OutputStr );
|
||||
strcat( OutputStr, " (comma separated values)\n" );
|
||||
Output( ChannelName, OutputStr, strlen(OutputStr) );
|
||||
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
||||
}
|
||||
return MaxLen;
|
||||
}
|
||||
@@ -1819,7 +1810,7 @@ bool CDeviceCore::EventOutput( TDeviceParam * Param, bool Force )
|
||||
default :
|
||||
break;
|
||||
}
|
||||
Output( Param->EventChannel, Message, strlen(Message) );
|
||||
Output( Param->EventChannel, NULL, true, Message, strlen(Message) );
|
||||
|
||||
// Reset timer
|
||||
if (Param->EventInterval) {
|
||||
|
||||
Reference in New Issue
Block a user