Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opcua 3195 calculated cachevariable #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions templates/designToConfigParser.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,83 @@ bool {{functionPrefix}}evaluateActive(
return active;
}

bool {{functionPrefix}}configureCalculatedVariable (
int docNum,
int childNode,
string prefix,
bool createDps,
bool assignAddresses,
bool continueOnError,
mapping addressActiveControl,
mapping connectionSettings)
{
DebugTN("Configure.CalculatedVariable called");
string name;
if(xmlGetElementAttribute(docNum, childNode, "name", name) != 0)
{
DebugTN("Configure.CalculatedVariable instance configuration has no attribute [name]: invalid configuration, returning FALSE");
return false;
}

string fullName = prefix+name;
string dpt = "{{typePrefix}}CalculatedVariable";

if (dpTypeExists(dpt))
{

if (createDps)
{

DebugTN("Will create DP "+fullName);
int result = dpCreate(fullName, dpt);
if (result != 0)
{
DebugTN("dpCreate name='"+fullName+"' dpt='"+dpt+"' not successful or already existing");
if (!continueOnError)
throw(makeError("Cacophony", PRIO_SEVERE, ERR_IMPL, 1, "XXX YYY ZZZ"));
}
}

if (assignAddresses)
{
string dpe, address;
dyn_string dsExceptionInfo;
bool success;
bool active = false;

dpe = fullName+".value";
address = fullName; // address can be generated from dpe after some mods ...
strreplace(address, "/", ".");

active = evaluateActive(
addressActiveControl,
"CalculatedVariable",
"value",
dpe);

success = addressConfigWrapper(
dpe,
address,
DPATTR_ADDR_MODE_INPUT_SPONT /* mode */,
connectionSettings,
active);

if (!success)
{
DebugTN("Failed setting address "+address+"; will terminate now.");
return false;
}


}
}

dyn_int children;

}



{% for class_name in designInspector.get_names_of_all_classes() %}
{% set cls = designInspector.objectify_class(class_name) %}

Expand Down Expand Up @@ -198,6 +275,9 @@ bool {{functionPrefix}}configure{{class_name}} (
}

dyn_int children;
children = getChildNodesWithName(docNum, childNode, "CalculatedVariable");
for (int i=1; i<=dynlen(children); i++)
configureCalculatedVariable (docNum, children[i], fullName+"/", createDps, assignAddresses, continueOnError, addressActiveControl, connectionSettings);
{% for ho in designInspector.objectify_has_objects(class_name, "[@instantiateUsing='configuration']") %}
children = {{functionPrefix}}getChildNodesWithName(docNum, childNode, "{{ho.get('class')}}");
for (int i=1; i<=dynlen(children); i++)
Expand Down
30 changes: 30 additions & 0 deletions templates/designToDptCreation.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@

// generated using Cacophony, an optional module of quasar, see: https://github.com/quasar-team/Cacophony

//Calculated Variable
bool createDptCalculatedVariable()
{
// the names of vars and the way of generating DPT come directly from examples of dpTypeChange
dyn_dyn_string xxdepes;
dyn_dyn_int xxdepei;
dynAppend(xxdepes, makeDynString("{{typePrefix}}CalculatedVariable", ""));
dynAppend(xxdepei, makeDynInt(DPEL_STRUCT));
dynAppend(xxdepes, makeDynString("", "value"));
dynAppend(xxdepei, makeDynInt(0, DPEL_FLOAT));

int status = dpTypeChange(xxdepes, xxdepei);
DebugN("createCalculatedVariable: completed, dpTypeChange returned status ["+status+"]");
return status == 0;
}

{% for class_name in designInspector.get_names_of_all_classes() %}
{% set cls = designInspector.objectify_class(class_name) %}

Expand Down Expand Up @@ -49,6 +65,20 @@ bool {{functionPrefix}}createDpt{{cls.get('name')}}()

int {{functionPrefix}}createDpts (string dptFilter=".*")
{
{
int result = regexpIndex(dptFilter, "CalculatedVariable");
DebugN("createDpts: processing class CalculatedVariable regexpIndex returned ["+result+"]");
if (result >= 0)
{
DebugN("createDpts: creating DPT for class CalculatedVariable");
if (!createDptCalculatedVariable())
return 1;
}
else
{
DebugN("DPT CalculatedVariable not covered by provided dptFilter, skipping");
}
}
{% for class_name in designInspector.get_names_of_all_classes() %}
{% set cls = designInspector.objectify_class(class_name) %}
{
Expand Down