- fixed problem with test case sSgN4 (return temporary-unavailable) when no EditSG is selected

- continued logging implementation
This commit is contained in:
Michael Zillgith 2016-06-03 18:38:31 +02:00
parent 0c042f2ba4
commit 069af684e9
9 changed files with 121 additions and 56 deletions

View file

@ -55,9 +55,9 @@ printJournalEntries(LinkedList journalEntries)
MmsJournalEntry journalEntry = (MmsJournalEntry) LinkedList_getData(journalEntriesElem);
MmsValue_printToBuffer(journalEntry->entryID, buf, 1024);
MmsValue_printToBuffer(MmsJournalEntry_getEntryID(journalEntry), buf, 1024);
printf("EntryID: %s\n", buf);
MmsValue_printToBuffer(journalEntry->occurenceTime, buf, 1024);
MmsValue_printToBuffer(MmsJournalEntry_getOccurenceTime(journalEntry), buf, 1024);
printf(" occurence time: %s\n", buf);
LinkedList journalVariableElem = LinkedList_getNext(journalEntry->journalVariables);
@ -66,8 +66,8 @@ printJournalEntries(LinkedList journalEntries)
MmsJournalVariable journalVariable = (MmsJournalVariable) LinkedList_getData(journalVariableElem);
printf(" variable-tag: %s\n", journalVariable->tag);
MmsValue_printToBuffer(journalVariable->value, buf, 1024);
printf(" variable-tag: %s\n", MmsJournalVariable_getTag(journalVariable));
MmsValue_printToBuffer(MmsJournalVariable_getValue(journalVariable), buf, 1024);
printf(" variable-value: %s\n", buf);
journalVariableElem = LinkedList_getNext(journalVariableElem);
@ -77,26 +77,6 @@ printJournalEntries(LinkedList journalEntries)
}
}
static void
MmsJournalVariable_destroy(MmsJournalVariable self)
{
if (self != NULL) {
GLOBAL_FREEMEM(self->tag);
MmsValue_delete(self->value);
GLOBAL_FREEMEM(self);
}
}
void
MmsJournalEntry_destroy(MmsJournalEntry self)
{
if (self != NULL) {
MmsValue_delete(self->entryID);
MmsValue_delete(self->occurenceTime);
LinkedList_destroyDeep(self->journalVariables, MmsJournalVariable_destroy);
GLOBAL_FREEMEM(self);
}
}
int main(int argc, char** argv) {
@ -265,7 +245,6 @@ int main(int argc, char** argv) {
logName[0] = 0;
logName++;
uint64_t timestamp = Hal_getTimeInMs();
MmsValue* startTime = MmsValue_newBinaryTime(false);
@ -292,12 +271,13 @@ int main(int argc, char** argv) {
LinkedList lastEntry = LinkedList_getLastElement(journalEntries);
MmsJournalEntry lastJournalEntry = (MmsJournalEntry) LinkedList_getData(lastEntry);
MmsValue* nextEntryId = MmsValue_clone(lastJournalEntry->entryID);
MmsValue* nextTimestamp = MmsValue_clone(lastJournalEntry->occurenceTime);
MmsValue* nextEntryId = MmsValue_clone(MmsJournalEntry_getEntryID(lastJournalEntry));
MmsValue* nextTimestamp = MmsValue_clone(MmsJournalEntry_getOccurenceTime(lastJournalEntry));
printJournalEntries(journalEntries);
LinkedList_destroyDeep(journalEntries, MmsJournalEntry_destroy);
LinkedList_destroyDeep(journalEntries, (LinkedListValueDeleteFunction)
MmsJournalEntry_destroy);
if (moreFollows) {
char buf[100];

View file

@ -177,6 +177,7 @@ LogControl_create(LogicalNode* parentLN, MmsMapping* mmsMapping)
self->dataSetRef = NULL;
self->logInstance = NULL;
self->intgPd = 0;
self->nextIntegrityScan = 0;
return self;
}
@ -345,7 +346,6 @@ updateLogStatusInLCB(LogControl* self)
LogInstance* logInstance = self->logInstance;
if (logInstance != NULL) {
MmsValue_setBinaryTime(self->oldEntrTm, logInstance->oldEntryTime);
MmsValue_setBinaryTime(self->newEntrTm, logInstance->newEntryTime);
@ -829,7 +829,7 @@ Logging_processIntegrityLogs(MmsMapping* self, uint64_t currentTimeInMs)
if (currentTimeInMs >= logControl->nextIntegrityScan) {
if (DEBUG_IED_SERVER)
//if (DEBUG_IED_SERVER)
printf("IED_SERVER: INTEGRITY SCAN for log %s\n", logControl->name);
LogControl_logAllDatasetEntries(logControl, self->mmsDevice->deviceName);

View file

@ -1995,7 +1995,7 @@ mmsWriteHandler(void* parameter, MmsDomain* domain,
SettingGroup* sg = getSettingGroupByMmsDomain(self, domain);
if (sg->editingClient != (ClientConnection) connection)
return DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED;
return DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE;
}
#endif /* (CONFIG_IEC61850_SETTING_GROUPS == 1) */

View file

@ -166,6 +166,8 @@ exit_with_error:
static uint64_t
SqliteLogStorage_addEntry(LogStorage self, uint64_t timestamp)
{
printf("SQLITE-DRIVER: add entry\n");
SqliteLogStorage* instanceData = (SqliteLogStorage*) (self->instanceData);
sqlite3* db = instanceData->db;
@ -366,6 +368,10 @@ SqliteLogStorage_getOldestAndNewestEntries(LogStorage self, uint64_t* newEntry,
*oldEntryTime = sqlite3_column_int64(instanceData->getOldEntry, 1);
validNewEntry = true;
}
else {
*oldEntry = 0;
*oldEntryTime = 0;
}
sqlite3_reset(instanceData->getOldEntry);
@ -378,6 +384,10 @@ SqliteLogStorage_getOldestAndNewestEntries(LogStorage self, uint64_t* newEntry,
*newEntryTime = sqlite3_column_int64(instanceData->getNewEntry, 1);
validOldEntry = true;
}
else {
*newEntry = 0;
*newEntryTime = 0;
}
sqlite3_reset(instanceData->getNewEntry);

View file

@ -735,6 +735,37 @@ struct sMmsJournalVariable {
MmsValue* value;
};
/**
* \brief Destroy a single MmsJournalEntry instance.
*
* This function will destroy the whole MmsJournalEntry object including the attached list
* of MmsJournalVariable objects. It is intended to be used in conjunction with the
* LinkedList_destroyDeep function in order to free the result of MmsConnection_readJournalTimeRange
* or MmsConnection_readJournalStartAfter
*
* LinkedList_destroyDeep(journalEntries, (LinkedListValueDeleteFunction)
* MmsJournalEntry_destroy);
*
* \param self the MmsJournalEntry instance to destroy
*/
void
MmsJournalEntry_destroy(MmsJournalEntry self);
const MmsValue*
MmsJournalEntry_getEntryID(MmsJournalEntry self);
const MmsValue*
MmsJournalEntry_getOccurenceTime(MmsJournalEntry self);
const LinkedList /* <MmsJournalVariable> */
MmsJournalEntry_getJournalVariables(MmsJournalEntry self);
const char*
MmsJournalVariable_getTag(MmsJournalVariable self);
const MmsValue*
MmsJournalVariable_getValue(MmsJournalVariable self);
LinkedList
MmsConnection_readJournalTimeRange(MmsConnection self, MmsError* mmsError, const char* domainId, const char* itemId,

View file

@ -101,7 +101,7 @@ MmsValue_getArraySize(const MmsValue* self);
* \return the element object
*/
MmsValue*
MmsValue_getElement(MmsValue* array, int index);
MmsValue_getElement(const MmsValue* array, int index);
/**
* \brief Create an emtpy array.
@ -911,7 +911,7 @@ MmsValue_isDeletable(MmsValue* self);
* \param self the MmsValue instance
*/
MmsType
MmsValue_getType(MmsValue* self);
MmsValue_getType(const MmsValue* self);
/**
* \brief Get a sub-element of a MMS_STRUCTURE value specified by a path name.
@ -947,8 +947,8 @@ MmsValue_getTypeString(MmsValue* self);
*
* \return a pointer to the start of the buffer
*/
char*
MmsValue_printToBuffer(MmsValue* self, char* buffer, int bufferSize);
const char*
MmsValue_printToBuffer(const MmsValue* self, char* buffer, int bufferSize);
/**
* \brief create a new MmsValue instance from a BER encoded MMS Data element (deserialize)

View file

@ -260,9 +260,6 @@ int
mmsClient_createMmsGetNameListRequestAssociationSpecific(long invokeId, ByteBuffer* writeBuffer,
const char* continueAfter);
void
mmsClient_createReadJournalRequest(uint32_t invokeId, ByteBuffer* request, const char* domainId, const char* itemId);
void
mmsClient_createReadJournalRequestWithTimeRange(uint32_t invokeId, ByteBuffer* request, const char* domainId, const char* itemId,
MmsValue* startingTime, MmsValue* endingTime);
@ -271,4 +268,7 @@ void
mmsClient_createReadJournalRequestStartAfter(uint32_t invokeId, ByteBuffer* request, const char* domainId, const char* itemId,
MmsValue* timeSpecification, MmsValue* entrySpecification);
bool
mmsClient_parseReadJournalResponse(MmsConnection self, bool* moreFollows, LinkedList* result);
#endif /* MMS_MSG_INTERNAL_H_ */

View file

@ -1667,19 +1667,58 @@ readJournal(MmsConnection self, MmsError* mmsError, uint32_t invokeId, ByteBuff
return response;
}
#if 0
LinkedList
MmsConnection_readJournal(MmsConnection self, MmsError* mmsError, const char* domainId, const char* itemId)
static void
MmsJournalVariable_destroy(MmsJournalVariable self)
{
ByteBuffer* payload = IsoClientConnection_allocateTransmitBuffer(self->isoClient);
uint32_t invokeId = getNextInvokeId(self);
mmsClient_createReadJournalRequest(invokeId, payload, domainId, itemId);
return readJournal(self, mmsError, invokeId, payload);
if (self != NULL) {
GLOBAL_FREEMEM(self->tag);
MmsValue_delete(self->value);
GLOBAL_FREEMEM(self);
}
}
void
MmsJournalEntry_destroy(MmsJournalEntry self)
{
if (self != NULL) {
MmsValue_delete(self->entryID);
MmsValue_delete(self->occurenceTime);
LinkedList_destroyDeep(self->journalVariables,
(LinkedListValueDeleteFunction) MmsJournalVariable_destroy);
GLOBAL_FREEMEM(self);
}
}
const MmsValue*
MmsJournalEntry_getEntryID(MmsJournalEntry self)
{
return self->entryID;
}
const MmsValue*
MmsJournalEntry_getOccurenceTime(MmsJournalEntry self)
{
return self->occurenceTime;
}
const LinkedList /* <MmsJournalVariable> */
MmsJournalEntry_getJournalVariables(MmsJournalEntry self)
{
return self->journalVariables;
}
const char*
MmsJournalVariable_getTag(MmsJournalVariable self)
{
return self->tag;
}
const MmsValue*
MmsJournalVariable_getValue(MmsJournalVariable self)
{
return self->value;
}
#endif
LinkedList
MmsConnection_readJournalTimeRange(MmsConnection self, MmsError* mmsError, const char* domainId, const char* itemId,

View file

@ -1600,7 +1600,12 @@ MmsValue_newBinaryTime(bool timeOfDay)
void
MmsValue_setBinaryTime(MmsValue* self, uint64_t timestamp)
{
uint64_t mmsTime = timestamp - (441763200000LL);
uint64_t mmsTime;
if (timestamp > 441763200000LL)
mmsTime = timestamp - (441763200000LL);
else
timestamp = 0;
uint8_t* binaryTimeBuf = self->value.binaryTime.buf;
@ -1877,7 +1882,7 @@ MmsValue_setElement(MmsValue* complexValue, int index, MmsValue* elementValue)
}
MmsValue*
MmsValue_getElement(MmsValue* complexValue, int index)
MmsValue_getElement(const MmsValue* complexValue, int index)
{
if ((complexValue->type != MMS_ARRAY) && (complexValue->type != MMS_STRUCTURE))
return NULL;
@ -1918,7 +1923,7 @@ MmsValue_isDeletable(MmsValue* self)
}
MmsType
MmsValue_getType(MmsValue* self)
MmsValue_getType(const MmsValue* self)
{
return self->type;
}
@ -1970,8 +1975,8 @@ MmsValue_getTypeString(MmsValue* self)
}
}
char*
MmsValue_printToBuffer(MmsValue* self, char* buffer, int bufferSize)
const char*
MmsValue_printToBuffer(const MmsValue* self, char* buffer, int bufferSize)
{
switch (MmsValue_getType(self)) {
case MMS_STRUCTURE:
@ -1985,7 +1990,7 @@ MmsValue_printToBuffer(MmsValue* self, char* buffer, int bufferSize)
int i;
for (i = 0; i < arraySize; i++) {
char* currentStr = MmsValue_printToBuffer(MmsValue_getElement(self, i), buffer + bufPos, bufferSize - bufPos);
const char* currentStr = MmsValue_printToBuffer((const MmsValue*) MmsValue_getElement(self, i), buffer + bufPos, bufferSize - bufPos);
bufPos += strlen(currentStr);
@ -2100,7 +2105,7 @@ MmsValue_printToBuffer(MmsValue* self, char* buffer, int bufferSize)
case MMS_STRING:
case MMS_VISIBLE_STRING:
strncpy(buffer, MmsValue_toString(self), bufferSize);
strncpy(buffer, MmsValue_toString((MmsValue*) self), bufferSize);
/* Ensure buffer is always 0 terminated */
if (bufferSize > 0)