Skip to content

Commit

Permalink
- extended logging implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mzillgith committed May 16, 2016
1 parent 2d45c2d commit a23b584
Show file tree
Hide file tree
Showing 15 changed files with 460 additions and 92 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ LIB_INCLUDE_DIRS += src/goose
LIB_INCLUDE_DIRS += src/sampled_values
LIB_INCLUDE_DIRS += src/iec61850/inc
LIB_INCLUDE_DIRS += src/iec61850/inc_private
LIB_INCLUDE_DIRS += src/logging
ifeq ($(HAL_IMPL), WIN32)
LIB_INCLUDE_DIRS += third_party/winpcap/Include
endif
Expand Down Expand Up @@ -100,6 +101,7 @@ LIB_API_HEADER_FILES += src/goose/goose_receiver.h
LIB_API_HEADER_FILES += src/goose/goose_publisher.h
LIB_API_HEADER_FILES += src/sampled_values/sv_subscriber.h
LIB_API_HEADER_FILES += src/sampled_values/sv_publisher.h
LIB_API_HEADER_FILES += src/logging/logging_api.h

get_sources_from_directory = $(wildcard $1/*.c)
get_sources = $(foreach dir, $1, $(call get_sources_from_directory,$(dir)))
Expand Down
4 changes: 2 additions & 2 deletions examples/mms_utility/mms_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ int main(int argc, char** argv) {
printf(" read journal...\n");
// MmsConnection_readJournal(con, &error, domainName, name);

#if 1
#if 0
uint64_t timestamp = Hal_getTimeInMs();

MmsValue* startTime = MmsValue_newBinaryTime(false);
Expand All @@ -184,7 +184,7 @@ int main(int argc, char** argv) {
MmsConnection_readJournalTimeRange(con, &error, domainName, name, startTime, endTime);
#endif

#if 0
#if 1
uint64_t timestamp = Hal_getTimeInMs();

MmsValue* startTime = MmsValue_newBinaryTime(false);
Expand Down
1 change: 1 addition & 0 deletions make/stack_includes.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ INCLUDES += -I$(LIBIEC_HOME)/src/iec61850/inc_private
INCLUDES += -I$(LIBIEC_HOME)/src/hal/inc
INCLUDES += -I$(LIBIEC_HOME)/src/goose
INCLUDES += -I$(LIBIEC_HOME)/src/sampled_values
INCLUDES += -I$(LIBIEC_HOME)/src/logging
1 change: 1 addition & 0 deletions src/iec61850/inc/iec61850_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern "C" {


#include "libiec61850_common_api.h"
#include "logging_api.h"

/**
* @defgroup iec61850_common_api_group IEC 61850 API common parts
Expand Down
3 changes: 3 additions & 0 deletions src/iec61850/inc/iec61850_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ LogicalNode_hasUnbufferedReports(LogicalNode* node);
DataSet*
LogicalNode_getDataSet(LogicalNode* self, const char* dataSetName);

void
LogicalNode_setLogStorage(LogicalNode* self, const char* logName, LogStorage logStorage);

bool
DataObject_hasFCData(DataObject* dataObject, FunctionalConstraint fc);

Expand Down
3 changes: 3 additions & 0 deletions src/iec61850/inc/iec61850_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,9 @@ IedServer_updateQuality(IedServer self, DataAttribute* dataAttribute, Quality qu
/**@}*/


void
IedServer_setLogStorage(IedServer self, const char* logRef, LogStorage logStorage);

/**
* @defgroup IEC61850_SERVER_SETTING_GROUPS Server side setting group handling
*
Expand Down
18 changes: 18 additions & 0 deletions src/iec61850/inc_private/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
#ifndef LIBIEC61850_SRC_IEC61850_INC_PRIVATE_LOGGING_H_
#define LIBIEC61850_SRC_IEC61850_INC_PRIVATE_LOGGING_H_

typedef struct {
char* name;
LogicalNode* parentLN;

LogStorage logStorage;
} LogInstance;

typedef struct {
char* name;
LogControlBlock* logControlBlock;
Expand All @@ -39,19 +46,30 @@ typedef struct {
MmsValue* mmsValue;
MmsVariableSpecification* mmsType;

LogInstance* logInstance;

bool enabled;

int triggerOps;

} LogControl;


LogInstance*
LogInstance_create(LogicalNode* parentLN, const char* name);

void
LogInstance_destroy(LogInstance* self);

LogControl*
LogControl_create(LogicalNode* parentLN, MmsMapping* mmsMapping);

void
LogControl_destroy(LogControl* self);

void
LogControl_setLogStorage(LogControl* self, LogStorage logStorage);

MmsVariableSpecification*
Logging_createLCBs(MmsMapping* self, MmsDomain* domain, LogicalNode* logicalNode,
int lcbCount);
Expand Down
1 change: 1 addition & 0 deletions src/iec61850/inc_private/mms_mapping_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct sMmsMapping {

#if (CONFIG_IEC61850_LOG_SERVICE == 1)
LinkedList logControls;
LinkedList logInstances;
#endif

#if (CONFIG_INCLUDE_GOOSE_SUPPORT == 1)
Expand Down
8 changes: 8 additions & 0 deletions src/iec61850/server/impl/ied_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,14 @@ IedServer_setEditSettingGroupConfirmationHandler(IedServer self, SettingGroupCon
#endif
}

void
IedServer_setLogStorage(IedServer self, const char* logRef, LogStorage logStorage)
{
#if (CONFIG_IEC61850_LOG_SERVICE == 1)
MmsMapping_setLogStorage(self->mmsMapping, logRef, logStorage);
#endif
}

ClientConnection
private_IedServer_getClientConnectionByHandle(IedServer self, void* serverConnectionHandle)
{
Expand Down
120 changes: 120 additions & 0 deletions src/iec61850/server/mms_mapping/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@
#include "mms_value_internal.h"


LogInstance*
LogInstance_create(LogicalNode* parentLN, const char* name)
{
LogInstance* self = (LogInstance*) GLOBAL_MALLOC(sizeof(LogInstance));


self->name = copyString(name);
self->parentLN = parentLN;
self->logStorage = NULL;

return self;
}

void
LogInstance_destroy(LogInstance* self)
{
GLOBAL_FREEMEM(self->name);
GLOBAL_FREEMEM(self);
}

LogControl*
LogControl_create(LogicalNode* parentLN, MmsMapping* mmsMapping)
{
Expand All @@ -47,6 +67,7 @@ LogControl_create(LogicalNode* parentLN, MmsMapping* mmsMapping)
self->logicalNode = parentLN;
self->mmsMapping = mmsMapping;
self->dataSetRef = NULL;
self->logInstance = NULL;

return self;
}
Expand All @@ -59,6 +80,12 @@ LogControl_destroy(LogControl* self)
}
}

void
LogControl_setLog(LogControl* self, LogInstance* logInstance)
{
self->logInstance = logInstance;
}

static LogControlBlock*
getLCBForLogicalNodeWithIndex(MmsMapping* self, LogicalNode* logicalNode, int index)
{
Expand Down Expand Up @@ -337,7 +364,86 @@ createLogControlBlock(LogControlBlock* logControlBlock,
return lcb;
}

static LogInstance*
getLogInstanceByLogRef(MmsMapping* self, const char* logRef)
{
char refStr[130];
char* domainName;
char* lnName;
char* logName;

strncpy(refStr, logRef, 129);

printf("getLogInst... %s\n", refStr);

domainName = refStr;

lnName = strchr(refStr, '/');

if (lnName == NULL)
return NULL;

if ((lnName - domainName) > 64)
return NULL;

lnName[0] = 0;
lnName++;

logName = strchr(lnName, '$');

if (logName == NULL)
return NULL;

logName[0] = 0;
logName++;

printf("LOG: dn: %s ln: %s name: %s\n", domainName, lnName, logName);

LinkedList instance = LinkedList_getNext(self->logInstances);

while (instance != NULL) {

LogInstance* logInstance = LinkedList_getData(instance);

printf("logInstance: %s\n", logInstance->name);

if (strcmp(logInstance->name, logName) == 0) {
printf (" lnName: %s\n", logInstance->parentLN->name);

if (strcmp(lnName, logInstance->parentLN->name) == 0) {
LogicalDevice* ld = (LogicalDevice*) logInstance->parentLN->parent;

printf(" ldName: %s\n", ld->name);

if (strcmp(ld->name, domainName) == 0)
return logInstance;
}
}

instance = LinkedList_getNext(instance);
}

return NULL;
}

static LogInstance*
getLogInstance(MmsMapping* self, LogicalNode* logicalNode, const char* logName)
{
LinkedList logInstance = LinkedList_getNext(self->logInstances);

while (logInstance != NULL) {
LogInstance* instance = (LogInstance*) LinkedList_getData(logInstance);

printf("LOG: %s (%s)\n", instance->name, logName);

if ((strcmp(instance->name, logName) == 0) && (logicalNode == instance->parentLN))
return instance;

logInstance = LinkedList_getNext(logInstance);
}

return NULL;
}

MmsVariableSpecification*
Logging_createLCBs(MmsMapping* self, MmsDomain* domain, LogicalNode* logicalNode,
Expand Down Expand Up @@ -366,6 +472,9 @@ Logging_createLCBs(MmsMapping* self, MmsDomain* domain, LogicalNode* logicalNode
namedVariable->typeSpec.structure.elements[currentLcb] =
createLogControlBlock(logControlBlock, logControl);

//getLogInstanceByLogRef(self, logControlBlock->logRef);
logControl->logInstance = getLogInstance(self, logicalNode, logControlBlock->logRef);

LinkedList_add(self->logControls, logControl);

currentLcb++;
Expand All @@ -374,4 +483,15 @@ Logging_createLCBs(MmsMapping* self, MmsDomain* domain, LogicalNode* logicalNode
return namedVariable;
}

void
MmsMapping_setLogStorage(MmsMapping* self, const char* logRef, LogStorage logStorage)
{
LogInstance* logInstance = getLogInstanceByLogRef(self, logRef);

if (logInstance != NULL)
logInstance->logStorage = logStorage;

//if (DEBUG_IED_SERVER)
if (logInstance == NULL)
printf("IED_SERVER: MmsMapping_setLogStorage no matching log for %s found!\n", logRef);
}
Loading

0 comments on commit a23b584

Please sign in to comment.