MmsValue* Control_readAccessControlObject(MmsMapping* self, MmsDomain* domain, char* variableIdOrig) { MmsValue* value = NULL; char* variableId = copyString(variableIdOrig); char* separator = strchr(variableId, '$'); *separator = 0; char* lnName = variableId; if (lnName == NULL ) return NULL; char* objectName = MmsMapping_getNextNameElement(separator + 1); if (objectName == NULL ) return NULL; char* varName = MmsMapping_getNextNameElement(objectName); if (varName != NULL) *(varName - 1) = 0; ControlObject* controlObject = Control_lookupControlObject(self, domain, lnName, objectName); if (controlObject != NULL) { if (varName != NULL) { if (strcmp(varName, "Oper") == 0) value = ControlObject_getOper(controlObject); else if (strcmp(varName, "SBOw") == 0) value = ControlObject_getSBOw(controlObject); else if (strcmp(varName, "SBO") == 0) { if ((controlObject->ctlModel == 2) || (controlObject->ctlModel == 4)) { if (ControlObject_select(controlObject)) { value = ControlObject_getSBO(controlObject); } else { value = emptyString; } } else value = NULL; } else if (strcmp(varName, "Cancel") == 0) value = ControlObject_getCancel(controlObject); } else value = ControlObject_getMmsValue(controlObject); } free(variableId); return value; }
MmsValue* Control_readAccessControlObject(MmsMapping* self, MmsDomain* domain, char* variableIdOrig, MmsServerConnection connection) { MmsValue* value = NULL; if (DEBUG_IED_SERVER) printf("IED_SERVER: readAccessControlObject: %s\n", variableIdOrig); char variableId[129]; strncpy(variableId, variableIdOrig, 128); variableId[128] = 0; char* separator = strchr(variableId, '$'); if (separator == NULL) return NULL; *separator = 0; char* lnName = variableId; if (lnName == NULL) return NULL; char* objectName = MmsMapping_getNextNameElement(separator + 1); if (objectName == NULL) return NULL; char* varName = MmsMapping_getNextNameElement(objectName); if (varName != NULL) { bool foundVar = false; char* nextVarName = varName; do { if (doesElementEquals(varName, "Oper") || doesElementEquals(varName, "SBO") || doesElementEquals(varName, "SBOw") || doesElementEquals(varName, "Cancel")) { *(varName - 1) = 0; foundVar = true; break; } nextVarName = MmsMapping_getNextNameElement(varName); if (nextVarName != NULL) varName = nextVarName; } while (nextVarName != NULL); if (foundVar == false) varName = NULL; } if (DEBUG_IED_SERVER) printf("IED_SERVER: read_access control object: objectName: (%s) varName: (%s)\n", objectName, varName); ControlObject* controlObject = Control_lookupControlObject(self, domain, lnName, objectName); if (controlObject != NULL) { initialize(controlObject); if (varName != NULL) { if (strcmp(varName, "Oper") == 0) value = ControlObject_getOper(controlObject); else if (strcmp(varName, "SBOw") == 0) value = ControlObject_getSBOw(controlObject); else if (strcmp(varName, "SBO") == 0) { if (controlObject->ctlModel == 2) { uint64_t currentTime = Hal_getTimeInMs(); value = controlObject->emptyString; checkSelectTimeout(controlObject, currentTime); if (getState(controlObject) == STATE_UNSELECTED) { CheckHandlerResult checkResult = CONTROL_ACCEPTED; if (controlObject->checkHandler != NULL) { /* perform operative tests */ checkResult = controlObject->checkHandler( controlObject->checkHandlerParameter, NULL, false, false, (ClientConnection) connection); } if (checkResult == CONTROL_ACCEPTED) { selectObject(controlObject, currentTime, connection); value = ControlObject_getSBO(controlObject); } } } else { if (DEBUG_IED_SERVER) printf("IED_SERVER: select not applicable for control model %i\n", controlObject->ctlModel); value = ControlObject_getSBO(controlObject); } } else if (strcmp(varName, "Cancel") == 0) value = ControlObject_getCancel(controlObject); else { value = MmsValue_getSubElement(ControlObject_getMmsValue(controlObject), ControlObject_getTypeSpec(controlObject), varName); } } else value = ControlObject_getMmsValue(controlObject); } return value; }