- removed debug code (LIB61850-528)

- added example for global write access handler (LIB61850-528)
v1.6_develop_528
Michael Zillgith 4 days ago
parent 2a4ca1eab0
commit 12493e1194

@ -27,32 +27,46 @@ updateCMVArrayElement(IedServer server, DataObject* phsAHar, int idx, float magn
{ {
DataObject* phsAHarArrayElem = (DataObject*)ModelNode_getChildWithIdx((ModelNode*)phsAHar, idx); DataObject* phsAHarArrayElem = (DataObject*)ModelNode_getChildWithIdx((ModelNode*)phsAHar, idx);
if (phsAHarArrayElem) { if (phsAHarArrayElem)
{
DataAttribute* mag = (DataAttribute*)ModelNode_getChild((ModelNode*)phsAHarArrayElem, "cVal.mag.f"); DataAttribute* mag = (DataAttribute*)ModelNode_getChild((ModelNode*)phsAHarArrayElem, "cVal.mag.f");
DataAttribute* ang = (DataAttribute*)ModelNode_getChild((ModelNode*)phsAHarArrayElem, "cVal.ang.f"); DataAttribute* ang = (DataAttribute*)ModelNode_getChild((ModelNode*)phsAHarArrayElem, "cVal.ang.f");
DataAttribute* q = (DataAttribute*)ModelNode_getChild((ModelNode*)phsAHarArrayElem, "q"); DataAttribute* q = (DataAttribute*)ModelNode_getChild((ModelNode*)phsAHarArrayElem, "q");
DataAttribute* t = (DataAttribute*)ModelNode_getChild((ModelNode*)phsAHarArrayElem, "t"); DataAttribute* t = (DataAttribute*)ModelNode_getChild((ModelNode*)phsAHarArrayElem, "t");
if (mag && ang && q && t) { if (mag && ang && q && t)
{
IedServer_updateQuality(server, q, quality); IedServer_updateQuality(server, q, quality);
IedServer_updateTimestampAttributeValue(server, t, &timestamp); IedServer_updateTimestampAttributeValue(server, t, &timestamp);
IedServer_updateFloatAttributeValue(server, mag, magnitude); IedServer_updateFloatAttributeValue(server, mag, magnitude);
IedServer_updateFloatAttributeValue(server, ang, angle); IedServer_updateFloatAttributeValue(server, ang, angle);
} }
else { else
{
printf("one of mag, ang, q, t not found\n"); printf("one of mag, ang, q, t not found\n");
} }
} }
else { else
{
printf("Element with index %i not found\n", idx); printf("Element with index %i not found\n", idx);
} }
} }
static MmsDataAccessError
writeAccessHandler(DataAttribute* dataAttribute, MmsValue* value, ClientConnection connection, void* parameter)
{
char objRef[200];
char valueBuf[200];
ModelNode_getObjectReference((ModelNode*)dataAttribute, objRef);
printf("Write access - %s: %s\n", objRef, MmsValue_printToBuffer(value, valueBuf, sizeof(valueBuf)));
return DATA_ACCESS_ERROR_SUCCESS;
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int tcpPort = 102; int tcpPort = 102;
if (argc > 1) { if (argc > 1) {
@ -61,6 +75,8 @@ main(int argc, char **argv)
IedServer iedServer = IedServer_create(&iedModel); IedServer iedServer = IedServer_create(&iedModel);
IedServer_handleWriteAccessGlobally(iedServer, writeAccessHandler, NULL);
/* Get access to the MHAI1.HA data object handle - for static and dynamic model*/ /* Get access to the MHAI1.HA data object handle - for static and dynamic model*/
DataObject* mhai1_ha_phsAHar = (DataObject*) DataObject* mhai1_ha_phsAHar = (DataObject*)
IedModel_getModelNodeByShortObjectReference(&iedModel, "ComplexArray/MHAI1.HA.phsAHar"); IedModel_getModelNodeByShortObjectReference(&iedModel, "ComplexArray/MHAI1.HA.phsAHar");
@ -75,7 +91,8 @@ main(int argc, char **argv)
Timestamp_setTimeInMilliseconds(&timestamp, Hal_getTimeInMs()); Timestamp_setTimeInMilliseconds(&timestamp, Hal_getTimeInMs());
int i; int i;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++)
{
updateCMVArrayElement(iedServer, mhai1_ha_phsAHar, i, mag, angle, quality, timestamp); updateCMVArrayElement(iedServer, mhai1_ha_phsAHar, i, mag, angle, quality, timestamp);
mag += 1.f; mag += 1.f;
angle += 0.01f; angle += 0.01f;
@ -84,7 +101,8 @@ main(int argc, char **argv)
/* MMS server will be instructed to start listening to client connections. */ /* MMS server will be instructed to start listening to client connections. */
IedServer_start(iedServer, tcpPort); IedServer_start(iedServer, tcpPort);
if (!IedServer_isRunning(iedServer)) { if (!IedServer_isRunning(iedServer))
{
printf("Starting server failed! Exit.\n"); printf("Starting server failed! Exit.\n");
IedServer_destroy(iedServer); IedServer_destroy(iedServer);
exit(-1); exit(-1);
@ -96,14 +114,16 @@ main(int argc, char **argv)
int counter = 0; int counter = 0;
while (running) { while (running)
{
Thread_sleep(1000); Thread_sleep(1000);
Timestamp_setTimeInMilliseconds(&timestamp, Hal_getTimeInMs()); Timestamp_setTimeInMilliseconds(&timestamp, Hal_getTimeInMs());
IedServer_lockDataModel(iedServer); IedServer_lockDataModel(iedServer);
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++)
{
updateCMVArrayElement(iedServer, mhai1_ha_phsAHar, i, mag, angle, quality, timestamp); updateCMVArrayElement(iedServer, mhai1_ha_phsAHar, i, mag, angle, quality, timestamp);
mag += 0.1f; mag += 0.1f;
angle += 0.05f; angle += 0.05f;
@ -126,4 +146,4 @@ main(int argc, char **argv)
IedServer_destroy(iedServer); IedServer_destroy(iedServer);
return 0; return 0;
} /* main() */ }

@ -3291,8 +3291,6 @@ mmsWriteHandler(void* parameter, MmsDomain* domain, const char* variableId, int
{ {
char* daRef = separator + 4; char* daRef = separator + 4;
/* replace "$" with "."*/
StringUtils_replace(daRef, '$', '.'); StringUtils_replace(daRef, '$', '.');
ModelNode* da = ModelNode_getChild(ln, daRef); ModelNode* da = ModelNode_getChild(ln, daRef);
@ -3303,31 +3301,21 @@ mmsWriteHandler(void* parameter, MmsDomain* domain, const char* variableId, int
{ {
da = ModelNode_getChildWithIdx(da, arrayIdx); da = ModelNode_getChildWithIdx(da, arrayIdx);
if (da == NULL) if (da && componentId)
{ {
printf("array idx not found\n"); char compIdBuf[65];
}
if (componentId) StringUtils_copyStringMax(compIdBuf, sizeof(compIdBuf), componentId);
{
StringUtils_replace(componentId, '$', '.');
da = ModelNode_getChild(da, componentId); StringUtils_replace(compIdBuf, '$', '.');
if (da == NULL) da = ModelNode_getChild(da, compIdBuf);
{
printf("component %s not found\n", componentId);
}
} }
} }
if (da) if (da)
{ {
if (da->modelType != DataAttributeModelType) if (da->modelType == DataAttributeModelType)
{
printf("model node not a data attribute!\n");
}
else
{ {
ClientConnection clientConnection = ClientConnection clientConnection =
private_IedServer_getClientConnectionByHandle(self->iedServer, connection); private_IedServer_getClientConnectionByHandle(self->iedServer, connection);
@ -3348,14 +3336,6 @@ mmsWriteHandler(void* parameter, MmsDomain* domain, const char* variableId, int
} }
} }
} }
else
{
printf("da %s no found\n", daRef);
}
}
else
{
printf("ln %s not found\n", variableId);
} }
} }
} }

Loading…
Cancel
Save