//INFO: function can be removed if no certification is required static bool checkValidityOfOriginParameter(MmsValue* origin) { if (MmsValue_getType(origin) != MMS_STRUCTURE) return false; if (MmsValue_getArraySize(origin) != 2) return false; MmsValue* orIdent = MmsValue_getElement(origin, 1); if (MmsValue_getType(orIdent) != MMS_OCTET_STRING) return false; if (MmsValue_getOctetStringSize(orIdent) > 64) return false; MmsValue* orCat = MmsValue_getElement(origin, 0); if (MmsValue_getType(orCat) != MMS_INTEGER) return false; int orCatIntValue = MmsValue_toInt32(orCat); if ((orCatIntValue < 0) || (orCatIntValue > 8)) return false; return true; }
int16_t ClientReportControlBlock_getResvTms(ClientReportControlBlock self) { if (self->resvTms != NULL) return (int16_t) MmsValue_toInt32(self->resvTms); else return 0; }
static void initialize(ControlObject* self) { if (emptyString == NULL) emptyString = MmsValue_newVisibleString(NULL); if (!(self->initialized)) { char* ctlModelName = createString(4, self->lnName, "$CF$", self->name, "$ctlModel"); MmsValue* ctlModel = MmsServer_getValueFromCache(self->mmsServer, self->mmsDomain, ctlModelName); free(ctlModelName); if (ctlModel != NULL) { uint32_t ctlModelVal = MmsValue_toInt32(ctlModel); self->ctlModel = ctlModelVal; if ((ctlModelVal == 2) || (ctlModelVal == 4)) { /* SBO */ char* sboTimeoutName = createString(4, self->lnName, "$CF$", self->name, "$sboTimeout"); char* controlObjectReference = createString(6, self->mmsDomain->domainName, "/", self->lnName, "$", self->name, "$SBO"); self->sbo = MmsValue_newVisibleString(controlObjectReference); MmsValue* sboTimeout = MmsServer_getValueFromCache(self->mmsServer, self->mmsDomain, sboTimeoutName); free(controlObjectReference); free(sboTimeoutName); if (sboTimeout != NULL) { uint32_t sboTimeoutVal = MmsValue_toInt32(sboTimeout); self->selectTimeout = sboTimeoutVal; } } else { self->sbo = emptyString; } } self->initialized = true; } }
int32_t IedServer_getInt32AttributeValue(IedServer self, DataAttribute* dataAttribute) { assert(self != NULL); assert(dataAttribute != NULL); assert(dataAttribute->mmsValue != NULL); assert((MmsValue_getType(dataAttribute->mmsValue) == MMS_INTEGER) || (MmsValue_getType(dataAttribute->mmsValue) == MMS_UNSIGNED)); return MmsValue_toInt32(dataAttribute->mmsValue); }
static bool isSboClassOperateOnce(ControlObject* self) { if (self->sboClass != NULL) { if (MmsValue_toInt32(self->sboClass) == 1) return false; else return true; } else return true; /* default is operate-once ! */ }
void handleLastApplErrorMessage(IedConnection self, MmsValue* value) { if (DEBUG_IED_CLIENT) printf("DEBUG_IED_CLIENT: received LastApplError\n"); MmsValue* lastApplError = value; MmsValue* cntrlObj = MmsValue_getElement(lastApplError, 0); MmsValue* error = MmsValue_getElement(lastApplError, 1); //MmsValue* origin = MmsValue_getElement(lastApplError, 2); MmsValue* ctlNum = MmsValue_getElement(lastApplError, 3); MmsValue* addCause = MmsValue_getElement(lastApplError, 4); if (DEBUG_IED_CLIENT) printf("DEBUG_IED_CLIENT: CntrlObj: %s\n", MmsValue_toString(cntrlObj)); if (DEBUG_IED_CLIENT) printf("DEBUG_IED_CLIENT: ctlNum: %u\n", MmsValue_toUint32(ctlNum)); if (DEBUG_IED_CLIENT) printf("DEBUG_IED_CLIENT: addCause: %i\n", MmsValue_toInt32(addCause)); if (DEBUG_IED_CLIENT) printf("DEBUG_IED_CLIENT: error: %i\n", MmsValue_toInt32(error)); self->lastApplError.ctlNum = MmsValue_toUint32(ctlNum); self->lastApplError.addCause = MmsValue_toInt32(addCause); self->lastApplError.error = MmsValue_toInt32(error); LinkedList control = LinkedList_getNext(self->clientControls); while (control != NULL) { ControlObjectClient object = (ControlObjectClient) control->data; char* objectRef = ControlObjectClient_getObjectReference(object); if (doesControlObjectMatch(objectRef, MmsValue_toString(cntrlObj))) ControlObjectClient_setLastApplError(object, self->lastApplError); control = LinkedList_getNext(control); } }
static void updateSboTimeoutValue(ControlObject* self) { if (self->sboTimeout != NULL) { uint32_t sboTimeoutVal = MmsValue_toInt32(self->sboTimeout); if (DEBUG_IED_SERVER) printf("set timeout for %s to %u\n", self->ctlObjectName, sboTimeoutVal); self->selectTimeout = sboTimeoutVal; } else self->selectTimeout = CONFIG_CONTROL_DEFAULT_SBO_TIMEOUT; }
bool controlHandlerForIntegerOutput(void* parameter, MmsValue* value, bool test) { if (MmsValue_getType(value) != MMS_INTEGER) return false; printf("Received integer control value: %i\n", MmsValue_toInt32(value)); uint64_t timeStamp = Hal_getTimeInMs(); if (parameter == IEDMODEL_WTG_WTUR1_SetTurOp_actSt) { IedServer_updateAttributeValue(iedServer, IEDMODEL_WTG_WTUR1_SetTurOp_actSt_stVal, value); IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_WTG_WTUR1_SetTurOp_actSt_t, timeStamp); } return true; }
void IedServer_updateInt32AttributeValue(IedServer self, DataAttribute* dataAttribute, int32_t value) { assert(MmsValue_getType(dataAttribute->mmsValue) == MMS_INTEGER); assert(dataAttribute != NULL); assert(self != NULL); int32_t currentValue = MmsValue_toInt32(dataAttribute->mmsValue); if (currentValue == value) { checkForUpdateTrigger(self, dataAttribute); } else { MmsValue_setInt32(dataAttribute->mmsValue, value); checkForChangedTriggers(self, dataAttribute); } }
int32_t IedConnection_readInt32Value(IedConnection self, IedClientError* error, char* objectReference, FunctionalConstraint fc) { MmsValue* value = IedConnection_readObject(self, error, objectReference, fc); int32_t retVal = 0.f; if (value != NULL) { if ((MmsValue_getType(value) == MMS_INTEGER) || (MmsValue_getType(value) == MMS_UNSIGNED)) retVal = MmsValue_toInt32(value); else { if (MmsValue_getType(value) == MMS_DATA_ACCESS_ERROR) *error = iedConnection_mapDataAccessErrorToIedError(MmsValue_getDataAccessError(value)); else *error = IED_ERROR_UNEXPECTED_VALUE_RECEIVED; } MmsValue_delete(value); } return retVal; }
void mmsMsg_addResultToResultList(AccessResult_t* accessResult, MmsValue* value) { if (value == NULL) { accessResult->present = AccessResult_PR_failure; asn_long2INTEGER(&accessResult->choice.failure, DataAccessError_objectnonexistent); if (DEBUG) printf("ACCESS ERROR\n"); } else { switch (value->type) { case MMS_ARRAY: { int size = value->value.structure.size; accessResult->present = AccessResult_PR_array; accessResult->choice.array.list.count = size; accessResult->choice.array.list.size = size; accessResult->choice.array.list.array = (Data_t**) GLOBAL_CALLOC(size, sizeof(Data_t*)); int i; for (i = 0; i < size; i++) { accessResult->choice.array.list.array[i] = mmsMsg_createDataElement(value->value.structure.components[i]); } } break; case MMS_STRUCTURE: { int size = value->value.structure.size; accessResult->present = AccessResult_PR_structure; accessResult->choice.structure.list.count = size; accessResult->choice.structure.list.size = size; accessResult->choice.structure.list.array = (Data_t**) GLOBAL_CALLOC(size, sizeof(Data_t*)); int i; for (i = 0; i < size; i++) { accessResult->choice.structure.list.array[i] = mmsMsg_createDataElement(value->value.structure.components[i]); } } break; case MMS_BIT_STRING: { accessResult->present = AccessResult_PR_bitstring; accessResult->choice.bitstring.buf = value->value.bitString.buf; int size = (value->value.bitString.size / 8) + ((value->value.bitString.size % 8) > 0); int unused = 8 - (value->value.bitString.size % 8); accessResult->choice.bitstring.size = size; /* size in bytes */ accessResult->choice.bitstring.bits_unused = unused; } break; case MMS_BOOLEAN: accessResult->present = AccessResult_PR_boolean; accessResult->choice.boolean = value->value.boolean; break; case MMS_FLOAT: accessResult->present = AccessResult_PR_floatingpoint; mmsMsg_createFloatData(value, &accessResult->choice.floatingpoint.size, &accessResult->choice.floatingpoint.buf); break; case MMS_UTC_TIME: accessResult->present = AccessResult_PR_utctime; accessResult->choice.utctime.buf = (uint8_t*) GLOBAL_MALLOC(8); memcpy(accessResult->choice.utctime.buf, value->value.utcTime, 8); accessResult->choice.utctime.size = 8; break; case MMS_INTEGER: accessResult->present = AccessResult_PR_integer; asn_long2INTEGER(&accessResult->choice.integer, (long) MmsValue_toInt32(value)); break; case MMS_UNSIGNED: accessResult->present = AccessResult_PR_unsigned; asn_long2INTEGER(&accessResult->choice.Unsigned, (long) MmsValue_toInt32(value)); break; case MMS_VISIBLE_STRING: accessResult->present = AccessResult_PR_visiblestring; if (value->value.visibleString.buf == NULL ) accessResult->choice.visiblestring.size = 0; else { accessResult->choice.visiblestring.buf = (uint8_t*) value->value.visibleString.buf; accessResult->choice.visiblestring.size = strlen(value->value.visibleString.buf); } break; case MMS_STRING: accessResult->present = AccessResult_PR_mMSString; if (value->value.visibleString.buf == NULL ) { accessResult->choice.mMSString.size = 0; } else { accessResult->choice.mMSString.buf = (uint8_t*) value->value.visibleString.buf; accessResult->choice.mMSString.size = strlen(value->value.visibleString.buf); } break; case MMS_BINARY_TIME: accessResult->present = AccessResult_PR_binarytime; accessResult->choice.binarytime.size = value->value.binaryTime.size; accessResult->choice.binarytime.buf = value->value.binaryTime.buf; break; case MMS_OCTET_STRING: accessResult->present = AccessResult_PR_octetstring; if (value->value.octetString.buf != NULL ) { accessResult->choice.octetstring.buf = value->value.octetString.buf; accessResult->choice.octetstring.size = value->value.octetString.size; } else accessResult->choice.octetstring.size = 0; break; default: accessResult->present = AccessResult_PR_failure; asn_long2INTEGER(&accessResult->choice.failure, DataAccessError_typeinconsistent); break; } } }
static void initialize(ControlObject* self) { if (!(self->initialized)) { MmsServer mmsServer = IedServer_getMmsServer(self->iedServer); self->emptyString = MmsValue_newVisibleString(NULL); char* ctlModelName = createString(4, self->lnName, "$CF$", self->name, "$ctlModel"); if (DEBUG_IED_SERVER) printf("initialize control for %s\n", ctlModelName); MmsValue* ctlModel = MmsServer_getValueFromCache(mmsServer, self->mmsDomain, ctlModelName); if (ctlModel == NULL) { if (DEBUG_IED_SERVER) printf("No control model found for variable %s\n", ctlModelName); } GLOBAL_FREEMEM(ctlModelName); char* sboClassName = createString(4, self->lnName, "$CF$", self->name, "$sboClass"); self->sboClass = MmsServer_getValueFromCache(mmsServer, self->mmsDomain, sboClassName); GLOBAL_FREEMEM(sboClassName); self->ctlObjectName = (char*) GLOBAL_MALLOC(130); StringUtils_createStringInBuffer(self->ctlObjectName, 5, MmsDomain_getName(self->mmsDomain), "/", self->lnName, "$CO$", self->name); self->error = MmsValue_newIntegerFromInt32(0); self->addCause = MmsValue_newIntegerFromInt32(0); if (ctlModel != NULL) { uint32_t ctlModelVal = MmsValue_toInt32(ctlModel); self->ctlModel = ctlModelVal; if (DEBUG_IED_SERVER) printf(" ctlModel: %i\n", ctlModelVal); if ((ctlModelVal == 2) || (ctlModelVal == 4)) { /* SBO */ char* sboTimeoutName = createString(4, self->lnName, "$CF$", self->name, "$sboTimeout"); char* controlObjectReference = createString(6, self->mmsDomain->domainName, "/", self->lnName, "$", self->name, "$SBO"); self->sbo = MmsValue_newVisibleString(controlObjectReference); self->sboTimeout = MmsServer_getValueFromCache(mmsServer, self->mmsDomain, sboTimeoutName); updateSboTimeoutValue(self); setState(self, STATE_UNSELECTED); if (DEBUG_IED_SERVER) printf("timeout for %s is %i\n", sboTimeoutName, self->selectTimeout); GLOBAL_FREEMEM(controlObjectReference); GLOBAL_FREEMEM(sboTimeoutName); } else { self->sbo = MmsValue_newVisibleString(NULL); setState(self, STATE_READY); } } self->initialized = true; } }