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 );
|
||||
if (JSONparse->ReadFromFile( DeviceType, Definition )) { // Contains file reference
|
||||
InitDeviceParams( Device, ConfigTypes->GetChild( DeviceType ), NULL );
|
||||
InitParamGroups( Device, ConfigTypes->GetChild( DeviceType ) );
|
||||
|
||||
JSONparse->SetBase( ConfigTypes );
|
||||
JSONparse->WriteToFile( DeviceType, Definition );
|
||||
@@ -169,7 +168,6 @@ bool CDeviceCore::InitDevices( CDataMember * FunctionConfig )
|
||||
}
|
||||
else {
|
||||
InitDeviceParams( Device, DeviceConfig, NULL ); // Contains definition
|
||||
InitParamGroups( Device, DeviceConfig );
|
||||
}
|
||||
}
|
||||
DeviceConfig = DeviceConfig->GetNextPeer();
|
||||
@@ -195,7 +193,6 @@ bool CDeviceCore::InitDevices( CDataMember * FunctionConfig )
|
||||
|
||||
if (Device) {
|
||||
InitDeviceParams( Device, DeviceConfig, Device->DataNode );
|
||||
InitParamGroups( Device, DeviceConfig );
|
||||
}
|
||||
DeviceConfig = DeviceConfig->GetNextPeer();
|
||||
}
|
||||
@@ -215,11 +212,12 @@ bool CDeviceCore::InitDeviceParams( TDevice * Device, CDataMember * DeviceConfi
|
||||
CopyTemplateParam( Device, Template, ParentNode );
|
||||
Template = Template->Next;
|
||||
}
|
||||
CopyTemplateParamGroups( Device );
|
||||
|
||||
// Read Device Params
|
||||
ParamConfig = DeviceConfig->GetChFirstChild( "Parameters", true );
|
||||
while (ParamConfig) {
|
||||
InitDeviceParam( Device, ParamConfig, NULL, ((isType)? NULL : Device->DataPath), ParentNode );
|
||||
InitDeviceParam( Device, ParamConfig, NULL, ((isType)? NULL : Device->DataPath), ParentNode, NULL );
|
||||
ParamConfig = ParamConfig->GetNextPeer();
|
||||
}
|
||||
|
||||
@@ -273,8 +271,36 @@ bool CDeviceCore::CopyTemplateParam( TDevice * Device, TDeviceParam * Template,
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
||||
const char * ParentName, const char * ParentPath, CDataMember * ParentNode )
|
||||
bool CDeviceCore::CopyTemplateParamGroups( TDevice * Device )
|
||||
{
|
||||
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 * FullName;
|
||||
@@ -289,8 +315,12 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
||||
|
||||
EDeviceDataType DataType;
|
||||
|
||||
char * ParamGroupName;
|
||||
SDeviceParamGroup * ParamGroup;
|
||||
|
||||
bool Read;
|
||||
bool Write;
|
||||
|
||||
char * EventOut;
|
||||
int EventInt;
|
||||
|
||||
@@ -314,6 +344,12 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
||||
|
||||
if ((Children = ParamConfig->GetChild( "Children", false ))) {
|
||||
// Data Branch
|
||||
if ((ParamGroupName = (char*)ParamConfig->GetChStr( "PollGroup", NULL, false ))) {
|
||||
ParamGroup = AddParamGroup( Device, ParamGroupName );
|
||||
} else {
|
||||
ParamGroup = ParentParamGroup;
|
||||
}
|
||||
|
||||
if (Children->isString()) {
|
||||
// Load from file
|
||||
ChildMap = new CDataMember();
|
||||
@@ -325,7 +361,7 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
||||
else {
|
||||
ChildConfig = ChildMap->GetFirstChild();
|
||||
while (ChildConfig) {
|
||||
InitDeviceParam( Device, ChildConfig, FullName, DataPath, DataNode );
|
||||
InitDeviceParam( Device, ChildConfig, FullName, DataPath, DataNode, ParamGroup );
|
||||
ChildConfig = ChildConfig->GetNextPeer();
|
||||
}
|
||||
}
|
||||
@@ -335,7 +371,8 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
||||
// Load children
|
||||
ChildConfig = Children->GetFirstChild();
|
||||
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 );
|
||||
EventInt = ParamConfig->GetChInt( "EventInterval", 0, false );
|
||||
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 )
|
||||
{
|
||||
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 );
|
||||
TDeviceParam * Param = NULL;
|
||||
TDeviceParamItem ** Item;
|
||||
|
||||
if (!Item) {
|
||||
if (!Param || !(Item = GetParamItemPtr( Group, Param->Name ))) {
|
||||
// Invalid group/param
|
||||
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;
|
||||
}
|
||||
else if (*Item) {
|
||||
// Item already exists
|
||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Param Group item '%s/%s' already exists",
|
||||
ProcessName, Name, Group->Name, ParamName );
|
||||
}
|
||||
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 );
|
||||
ProcessName, Name, Group->Name, Param->Name );
|
||||
}
|
||||
else {
|
||||
*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'",
|
||||
ProcessName, Name, ((Group->Device->Name)? Group->Device->Name : Group->Device->Type),
|
||||
Group->Name, ParamName );
|
||||
Group->Name, Param->Name );
|
||||
}
|
||||
return *Item;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user