- added function ModelNode_getChildWithFc

This commit is contained in:
Michael Zillgith 2015-01-12 11:32:09 +01:00
parent 83a7e7cfdc
commit df6ac20092
6 changed files with 78 additions and 13 deletions

View file

@ -311,7 +311,7 @@ Socket_connect(Socket self, const char* address, int port)
timeout.tv_sec = self->connectTimeout / 1000;
timeout.tv_usec = (self->connectTimeout % 1000) * 1000;
if (select(self->fd + 1, NULL, &fdSet, NULL, &timeout) == SOCKET_ERROR)
if (select(self->fd + 1, NULL, &fdSet, NULL, &timeout) < 0)
return false;
else
return true;

View file

@ -253,36 +253,52 @@ struct sGSEControlBlock {
/**
* \brief get the number of direct children of a model node
*
* \param node the model node instance
* \param self the model node instance
*
* \return the number of children of the model node
* ¸
*/
int
ModelNode_getChildCount(ModelNode* modelNode);
ModelNode_getChildCount(ModelNode* self);
/**
* \brief return a child model node
*
* \param node the model node instance
* \param the name of the child model node
* \param self the model node instance
* \param name the name of the child model node
*
* \return the model node instance or NULL if model node does not exist.
*/
ModelNode*
ModelNode_getChild(ModelNode* modelNode, const char* name);
ModelNode_getChild(ModelNode* self, const char* name);
/**
* \brief return a child model node with a given functional constraint
*
* Sometimes the name is not enough to identify a model node. This is the case when
* editable setting groups are used. In this case the setting group members have two different
* model nodes associated that differ in their FC (SG and SE).
*
* \param self the model node instance
* \param name the name of the child model node
* \param fc the functional constraint of the model node
*
* \return the model node instance or NULL if model node does not exist.
*/
ModelNode*
ModelNode_getChildWithFc(ModelNode* self, const char* name, FunctionalConstraint fc);
/**
* \brief Return the IEC 61850 object reference of a model node
*
* \param node the model node instance
* \param self the model node instance
* \param objectReference pointer to a buffer where to write the object reference string. If NULL
* is given the buffer is allocated by the function.
*
* \return the object reference string
*/
char*
ModelNode_getObjectReference(ModelNode* node, char* objectReference);
ModelNode_getObjectReference(ModelNode* self, char* objectReference);
/**
* \brief Set the name of the IED

View file

@ -457,6 +457,56 @@ ModelNode_getChild(ModelNode* self, const char* name)
return matchingNode;
}
ModelNode*
ModelNode_getChildWithFc(ModelNode* self, const char* name, FunctionalConstraint fc)
{
// check for separator
const char* separator = strchr(name, '.');
int nameElementLength = 0;
if (separator != NULL)
nameElementLength = (separator - name);
else
nameElementLength = strlen(name);
ModelNode* nextNode = self->firstChild;
ModelNode* matchingNode = NULL;
while (nextNode != NULL) {
int nodeNameLen = strlen(nextNode->name);
if (nodeNameLen == nameElementLength) {
if (memcmp(nextNode->name, name, nodeNameLen) == 0) {
if (separator == NULL) {
if (nextNode->modelType == DataAttributeModelType) {
DataAttribute* da = (DataAttribute*) nextNode;
if (da->fc == fc) {
matchingNode = nextNode;
break;
}
}
}
else {
matchingNode = nextNode;
break;
}
}
}
nextNode = nextNode->sibling;
}
if ((separator != NULL) && (matchingNode != NULL)) {
return ModelNode_getChildWithFc(matchingNode, separator + 1, fc);
}
else
return matchingNode;
}
inline
LogicalNode*

View file

@ -338,10 +338,7 @@ IsoSession_createFinishSpdu(IsoSession* self, BufferChain buffer, BufferChain pa
buf[offset++] = 9; /* FINISH-SPDU code */
buf[offset++] = 5 + payload->length; /* LI */
buf[offset++] = 17; /* PI-Code transport-disconnect */
buf[offset++] = 1; /* LI = 1 */
buf[offset++] = 2; /* transport-connection-released */
buf[offset++] = 2 + payload->length; /* LI */
buf[offset++] = 193; /* PGI-Code user data */
buf[offset++] = payload->length; /* LI of user data */

View file

@ -481,4 +481,5 @@ EXPORTS
IedServer_getUTCTimeAttributeValue
IedServer_getBitStringAttributeValue
IedServer_getStringAttributeValue
ModelNode_getChildWithFc

View file

@ -505,4 +505,5 @@ EXPORTS
IedServer_getUTCTimeAttributeValue
IedServer_getBitStringAttributeValue
IedServer_getStringAttributeValue
ModelNode_getChildWithFc