Important Update:
- Remove separate poll group specifications in JSON file - Implemented PollGroups per parameter or node in JSON file - Implemented copying of PollGroups from Template
This commit is contained in:
124
DeviceCore.cpp
124
DeviceCore.cpp
@@ -157,7 +157,6 @@ bool CDeviceCore::InitDevices( CDataMember * FunctionConfig )
|
|||||||
JSONparse->SetBase( ConfigTypes );
|
JSONparse->SetBase( ConfigTypes );
|
||||||
if (JSONparse->ReadFromFile( DeviceType, Definition )) { // Contains file reference
|
if (JSONparse->ReadFromFile( DeviceType, Definition )) { // Contains file reference
|
||||||
InitDeviceParams( Device, ConfigTypes->GetChild( DeviceType ), NULL );
|
InitDeviceParams( Device, ConfigTypes->GetChild( DeviceType ), NULL );
|
||||||
InitParamGroups( Device, ConfigTypes->GetChild( DeviceType ) );
|
|
||||||
|
|
||||||
JSONparse->SetBase( ConfigTypes );
|
JSONparse->SetBase( ConfigTypes );
|
||||||
JSONparse->WriteToFile( DeviceType, Definition );
|
JSONparse->WriteToFile( DeviceType, Definition );
|
||||||
@@ -169,7 +168,6 @@ bool CDeviceCore::InitDevices( CDataMember * FunctionConfig )
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
InitDeviceParams( Device, DeviceConfig, NULL ); // Contains definition
|
InitDeviceParams( Device, DeviceConfig, NULL ); // Contains definition
|
||||||
InitParamGroups( Device, DeviceConfig );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DeviceConfig = DeviceConfig->GetNextPeer();
|
DeviceConfig = DeviceConfig->GetNextPeer();
|
||||||
@@ -195,7 +193,6 @@ bool CDeviceCore::InitDevices( CDataMember * FunctionConfig )
|
|||||||
|
|
||||||
if (Device) {
|
if (Device) {
|
||||||
InitDeviceParams( Device, DeviceConfig, Device->DataNode );
|
InitDeviceParams( Device, DeviceConfig, Device->DataNode );
|
||||||
InitParamGroups( Device, DeviceConfig );
|
|
||||||
}
|
}
|
||||||
DeviceConfig = DeviceConfig->GetNextPeer();
|
DeviceConfig = DeviceConfig->GetNextPeer();
|
||||||
}
|
}
|
||||||
@@ -215,11 +212,12 @@ bool CDeviceCore::InitDeviceParams( TDevice * Device, CDataMember * DeviceConfi
|
|||||||
CopyTemplateParam( Device, Template, ParentNode );
|
CopyTemplateParam( Device, Template, ParentNode );
|
||||||
Template = Template->Next;
|
Template = Template->Next;
|
||||||
}
|
}
|
||||||
|
CopyTemplateParamGroups( Device );
|
||||||
|
|
||||||
// Read Device Params
|
// Read Device Params
|
||||||
ParamConfig = DeviceConfig->GetChFirstChild( "Parameters", true );
|
ParamConfig = DeviceConfig->GetChFirstChild( "Parameters", true );
|
||||||
while (ParamConfig) {
|
while (ParamConfig) {
|
||||||
InitDeviceParam( Device, ParamConfig, NULL, ((isType)? NULL : Device->DataPath), ParentNode );
|
InitDeviceParam( Device, ParamConfig, NULL, ((isType)? NULL : Device->DataPath), ParentNode, NULL );
|
||||||
ParamConfig = ParamConfig->GetNextPeer();
|
ParamConfig = ParamConfig->GetNextPeer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,8 +271,36 @@ bool CDeviceCore::CopyTemplateParam( TDevice * Device, TDeviceParam * Template,
|
|||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
bool CDeviceCore::CopyTemplateParamGroups( TDevice * Device )
|
||||||
const char * ParentName, const char * ParentPath, CDataMember * ParentNode )
|
{
|
||||||
|
TDeviceParamGroup * TemplateGroup;
|
||||||
|
TDeviceParamItem * TemplateItem;
|
||||||
|
TDeviceParamGroup * ParamGroup;
|
||||||
|
TDeviceParam * Param;
|
||||||
|
|
||||||
|
// Check if Template Groups exists
|
||||||
|
if (!Device->Template || !(TemplateGroup = Device->Template->FirstParamGroup))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
while (TemplateGroup) {
|
||||||
|
// Create group
|
||||||
|
ParamGroup = AddParamGroup( Device, TemplateGroup->Name );
|
||||||
|
|
||||||
|
// Add Registers
|
||||||
|
TemplateItem = TemplateGroup->FirstParam;
|
||||||
|
while (TemplateItem) {
|
||||||
|
if ((Param = GetDeviceParam( Device, TemplateItem->Param->Name )))
|
||||||
|
AddParamItem( ParamGroup, Param );
|
||||||
|
TemplateItem = TemplateItem->NextItem;
|
||||||
|
}
|
||||||
|
TemplateGroup = TemplateGroup->NextGroup;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig, const char * ParentName,
|
||||||
|
const char * ParentPath, CDataMember * ParentNode, TDeviceParamGroup * ParentParamGroup )
|
||||||
{
|
{
|
||||||
char * NodeName;
|
char * NodeName;
|
||||||
char * FullName;
|
char * FullName;
|
||||||
@@ -289,8 +315,12 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
|||||||
|
|
||||||
EDeviceDataType DataType;
|
EDeviceDataType DataType;
|
||||||
|
|
||||||
|
char * ParamGroupName;
|
||||||
|
SDeviceParamGroup * ParamGroup;
|
||||||
|
|
||||||
bool Read;
|
bool Read;
|
||||||
bool Write;
|
bool Write;
|
||||||
|
|
||||||
char * EventOut;
|
char * EventOut;
|
||||||
int EventInt;
|
int EventInt;
|
||||||
|
|
||||||
@@ -314,6 +344,12 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
|||||||
|
|
||||||
if ((Children = ParamConfig->GetChild( "Children", false ))) {
|
if ((Children = ParamConfig->GetChild( "Children", false ))) {
|
||||||
// Data Branch
|
// Data Branch
|
||||||
|
if ((ParamGroupName = (char*)ParamConfig->GetChStr( "PollGroup", NULL, false ))) {
|
||||||
|
ParamGroup = AddParamGroup( Device, ParamGroupName );
|
||||||
|
} else {
|
||||||
|
ParamGroup = ParentParamGroup;
|
||||||
|
}
|
||||||
|
|
||||||
if (Children->isString()) {
|
if (Children->isString()) {
|
||||||
// Load from file
|
// Load from file
|
||||||
ChildMap = new CDataMember();
|
ChildMap = new CDataMember();
|
||||||
@@ -325,7 +361,7 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
|||||||
else {
|
else {
|
||||||
ChildConfig = ChildMap->GetFirstChild();
|
ChildConfig = ChildMap->GetFirstChild();
|
||||||
while (ChildConfig) {
|
while (ChildConfig) {
|
||||||
InitDeviceParam( Device, ChildConfig, FullName, DataPath, DataNode );
|
InitDeviceParam( Device, ChildConfig, FullName, DataPath, DataNode, ParamGroup );
|
||||||
ChildConfig = ChildConfig->GetNextPeer();
|
ChildConfig = ChildConfig->GetNextPeer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,7 +371,8 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
|||||||
// Load children
|
// Load children
|
||||||
ChildConfig = Children->GetFirstChild();
|
ChildConfig = Children->GetFirstChild();
|
||||||
while (ChildConfig) {
|
while (ChildConfig) {
|
||||||
InitDeviceParam( Device, ChildConfig, FullName, DataPath, DataNode );
|
InitDeviceParam( Device, ChildConfig, FullName, DataPath, DataNode, ParamGroup );
|
||||||
|
ChildConfig = ChildConfig->GetNextPeer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -373,6 +410,14 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((ParamGroupName = (char*)ParamConfig->GetChStr( "PollGroup", NULL, false ))) {
|
||||||
|
ParamGroup = AddParamGroup( Device, ParamGroupName );
|
||||||
|
} else {
|
||||||
|
ParamGroup = ParentParamGroup;
|
||||||
|
}
|
||||||
|
if (ParamGroup)
|
||||||
|
AddParamItem( ParamGroup, Param );
|
||||||
|
|
||||||
EventOut = (char*)ParamConfig->GetChStr( "EventChannel", NULL, false );
|
EventOut = (char*)ParamConfig->GetChStr( "EventChannel", NULL, false );
|
||||||
EventInt = ParamConfig->GetChInt( "EventInterval", 0, false );
|
EventInt = ParamConfig->GetChInt( "EventInterval", 0, false );
|
||||||
SetParamEvent( Param, EventOut, EventInt );
|
SetParamEvent( Param, EventOut, EventInt );
|
||||||
@@ -385,50 +430,6 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
|||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool CDeviceCore::InitParamGroups( TDevice * Device, CDataMember * DeviceConfig )
|
|
||||||
{
|
|
||||||
CDataMember * GroupData;
|
|
||||||
CDataMember * ItemData;
|
|
||||||
TDeviceParamGroup * Group;
|
|
||||||
TDeviceParamGroup * GroupTemplate;
|
|
||||||
TDeviceParamItem * ItemTemplate;
|
|
||||||
|
|
||||||
// Copy Template
|
|
||||||
GroupTemplate = (Device->Template)? Device->Template->FirstParamGroup : NULL;
|
|
||||||
while (GroupTemplate)
|
|
||||||
{
|
|
||||||
if ((Group = AddParamGroup( Device, GroupTemplate->Name )))
|
|
||||||
{
|
|
||||||
ItemTemplate = GroupTemplate->FirstParam;
|
|
||||||
while (ItemTemplate)
|
|
||||||
{
|
|
||||||
AddParamItem( Group, ItemTemplate->Param->Name );
|
|
||||||
ItemTemplate = ItemTemplate->NextItem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GroupTemplate = GroupTemplate->NextGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add Parameters
|
|
||||||
GroupData = DeviceConfig->GetChFirstChild( "ParamGroups", true );
|
|
||||||
while (GroupData)
|
|
||||||
{
|
|
||||||
if ((Group = AddParamGroup( Device, GroupData->GetName() )))
|
|
||||||
{
|
|
||||||
ItemData = GroupData->GetElement( 0 );
|
|
||||||
while (ItemData)
|
|
||||||
{
|
|
||||||
AddParamItem( Group, ItemData->GetStr() );
|
|
||||||
ItemData = ItemData->GetNextPeer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GroupData = GroupData->GetNextPeer();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool CDeviceCore::SetPollParam( int pPollInterval )
|
bool CDeviceCore::SetPollParam( int pPollInterval )
|
||||||
{
|
{
|
||||||
PollInterval = pPollInterval;
|
PollInterval = pPollInterval;
|
||||||
@@ -857,27 +858,20 @@ bool CDeviceCore::DestroyParamGroup( TDeviceParamGroup ** ParamGroup )
|
|||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
TDeviceParamItem * CDeviceCore::AddParamItem( TDeviceParamGroup * Group, const char * ParamName )
|
TDeviceParamItem * CDeviceCore::AddParamItem( TDeviceParamGroup * Group, TDeviceParam * Param )
|
||||||
{
|
{
|
||||||
TDeviceParamItem ** Item = GetParamItemPtr( Group, ParamName );
|
TDeviceParamItem ** Item;
|
||||||
TDeviceParam * Param = NULL;
|
|
||||||
|
|
||||||
if (!Item) {
|
if (!Param || !(Item = GetParamItemPtr( Group, Param->Name ))) {
|
||||||
// Invalid group/param
|
// Invalid group/param
|
||||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Param group item '%s/%s' cannot be created",
|
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Param group item '%s/%s' cannot be created",
|
||||||
ProcessName, Name, ((!Group)? "[group]" : Group->Name), ((!ParamName)? "[param]" : ParamName));
|
ProcessName, Name, ((!Group)? "[group]" : Group->Name), ((!Param->Name)? "[param]" : Param->Name));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (*Item) {
|
else if (*Item) {
|
||||||
// Item already exists
|
// Item already exists
|
||||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Param Group item '%s/%s' already exists",
|
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Param Group item '%s/%s' already exists",
|
||||||
ProcessName, Name, Group->Name, ParamName );
|
ProcessName, Name, Group->Name, Param->Name );
|
||||||
}
|
|
||||||
else if (!(Param = GetDeviceParam( Group->Device, ParamName ))) {
|
|
||||||
// Parameter does not exist
|
|
||||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Param '%s/%s' does not exists - Cannot add to Param group '%s'",
|
|
||||||
ProcessName, Name, ((Group->Device->Name)? Group->Device->Name : Group->Device->Type),
|
|
||||||
ParamName, Group->Name );
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*Item = new TDeviceParamItem;
|
*Item = new TDeviceParamItem;
|
||||||
@@ -891,7 +885,7 @@ TDeviceParamItem * CDeviceCore::AddParamItem( TDeviceParamGroup * Group, const c
|
|||||||
|
|
||||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Added param group item '%s/%s/%s'",
|
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Added param group item '%s/%s/%s'",
|
||||||
ProcessName, Name, ((Group->Device->Name)? Group->Device->Name : Group->Device->Type),
|
ProcessName, Name, ((Group->Device->Name)? Group->Device->Name : Group->Device->Type),
|
||||||
Group->Name, ParamName );
|
Group->Name, Param->Name );
|
||||||
}
|
}
|
||||||
return *Item;
|
return *Item;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -315,9 +315,9 @@ public:
|
|||||||
virtual bool InitDevices( CDataMember * FunctionConfig );
|
virtual bool InitDevices( CDataMember * FunctionConfig );
|
||||||
virtual bool InitDeviceParams( TDevice * Device, CDataMember * DeviceConfig, CDataMember * ParentNode );
|
virtual bool InitDeviceParams( TDevice * Device, CDataMember * DeviceConfig, CDataMember * ParentNode );
|
||||||
virtual bool CopyTemplateParam( TDevice * Device, TDeviceParam * Template, CDataMember * ParentNode );
|
virtual bool CopyTemplateParam( TDevice * Device, TDeviceParam * Template, CDataMember * ParentNode );
|
||||||
virtual bool InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
virtual bool CopyTemplateParamGroups( TDevice * Device );
|
||||||
const char * ParentName, const char * ParentPath, CDataMember * ParentNode );
|
virtual bool InitDeviceParam( TDevice * Device, CDataMember * ParamConfig, const char * ParentName,
|
||||||
virtual bool InitParamGroups( TDevice * Device, CDataMember * DeviceConfig );
|
const char * ParentPath, CDataMember * ParentNode, TDeviceParamGroup * ParentParamGroup );
|
||||||
|
|
||||||
// Polling parameters
|
// Polling parameters
|
||||||
bool SetPollParam( int pPollInterval );
|
bool SetPollParam( int pPollInterval );
|
||||||
@@ -355,7 +355,7 @@ public:
|
|||||||
TDeviceParamGroup ** Group = GetParamGroupPtr( Device, GroupName );
|
TDeviceParamGroup ** Group = GetParamGroupPtr( Device, GroupName );
|
||||||
return (Group)? DestroyParamGroup( Group ) : false;
|
return (Group)? DestroyParamGroup( Group ) : false;
|
||||||
};
|
};
|
||||||
TDeviceParamItem * AddParamItem( TDeviceParamGroup * Group, const char * ParamName );
|
TDeviceParamItem * AddParamItem( TDeviceParamGroup * Group, TDeviceParam * Param );
|
||||||
inline bool DestroyParamItem( TDevice * Device, TDeviceParamGroup * Group, const char * ParamName ) {
|
inline bool DestroyParamItem( TDevice * Device, TDeviceParamGroup * Group, const char * ParamName ) {
|
||||||
TDeviceParamItem ** Item = GetParamItemPtr( Group, ParamName );
|
TDeviceParamItem ** Item = GetParamItemPtr( Group, ParamName );
|
||||||
return (Item)? DestroyParamItem( Item ) : false;
|
return (Item)? DestroyParamItem( Item ) : false;
|
||||||
|
|||||||
Reference in New Issue
Block a user