Skip to content

Commit

Permalink
- some small code improvements; removed cppcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mzillgith committed Dec 30, 2022
1 parent ddde067 commit 53a6b3c
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 352 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changes to version 2.3.2
- updated HAL layer
- Added new IEC 62351-3 related TLS features (session resumption, alarms, ...)
- CS101 balanced link layer: Send request-status-of-link before calling reset-of-remote-link
- CS101 unbalanced master: Send request-status-of-link before calling reset-of-remote-link, added delay before repeating request-status-of-link
- added function CS101_ASDU_clone
- fixed - TLS: configured CRL are ignored (#117)
- integrated code to serve files
Expand Down
2 changes: 1 addition & 1 deletion lib60870-C/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static_checks: lib
splint -preproc +posixlib +skip-sys-headers +gnuextensions $(LIB_INCLUDES) $(LIB_SOURCES)

cppcheck: lib
cppcheck --force --std=c99 --enable=all $(LIB_INCLUDES) $(LIB_SOURCES) 2> cppcheck-output.xml
cppcheck --xml --force --std=c99 --enable=all $(LIB_INCLUDES) $(LIB_SOURCES) 2> cppcheck-output.xml

lib: $(LIB_NAME)

Expand Down
4 changes: 2 additions & 2 deletions lib60870-C/src/common/inc/linked_list.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 MZ Automation GmbH
* Copyright 2013-2022 Michael Zillgith
*
* This file is part of lib60870-C
*
Expand Down Expand Up @@ -116,7 +116,7 @@ LinkedList_add(LinkedList self, void* data);
* \param data data to remove from the LinkedList instance
*/
bool
LinkedList_remove(LinkedList self, void* data);
LinkedList_remove(LinkedList self, const void* data);

/**
* \brief Get the list element specified by index (starting with 0).
Expand Down
4 changes: 2 additions & 2 deletions lib60870-C/src/common/linked_list.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 MZ Automation GmbH
* Copyright 2013-2022 Michael Zillgith
*
* This file is part of lib60870-C
*
Expand Down Expand Up @@ -116,7 +116,7 @@ LinkedList_add(LinkedList list, void* data)
}

bool
LinkedList_remove(LinkedList list, void* data)
LinkedList_remove(LinkedList list, const void* data)
{
LinkedList lastElement = list;

Expand Down
70 changes: 35 additions & 35 deletions lib60870-C/src/iec60870/apl/cpXXtime2a.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Implementation of the types CP16Time2a, CP24Time2a and CP56Time2a
*
* Copyright 2016 MZ Automation GmbH
* Copyright 2016-2022 Michael Zillgith
*
* This file is part of lib60870-C
*
Expand Down Expand Up @@ -39,7 +39,7 @@
**********************************/

bool
CP16Time2a_getFromBuffer (CP16Time2a self, uint8_t* msg, int msgSize, int startIndex)
CP16Time2a_getFromBuffer (CP16Time2a self, const uint8_t* msg, int msgSize, int startIndex)
{
if (msgSize < startIndex + 2)
return false;
Expand All @@ -53,7 +53,7 @@ CP16Time2a_getFromBuffer (CP16Time2a self, uint8_t* msg, int msgSize, int startI
}

int
CP16Time2a_getEplapsedTimeInMs(CP16Time2a self)
CP16Time2a_getEplapsedTimeInMs(const CP16Time2a self)
{
return (self->encodedValue[0] + (self->encodedValue[1] * 0x100));
}
Expand All @@ -76,7 +76,7 @@ CP16Time2a_getEncodedValue(CP16Time2a self)
************************************/

static int
getMillisecond(uint8_t* encodedValue)
getMillisecond(const uint8_t* encodedValue)
{
return (encodedValue[0] + (encodedValue[1] * 0x100)) % 1000;
}
Expand All @@ -96,7 +96,7 @@ setMillisecond(uint8_t* encodedValue, int value)
}

static int
getSecond(uint8_t* encodedValue)
getSecond(const uint8_t* encodedValue)
{
return (encodedValue[0] + (encodedValue[1] * 0x100)) / 1000;
}
Expand All @@ -115,7 +115,7 @@ setSecond(uint8_t* encodedValue, int value)
}

static int
getMinute(uint8_t* encodedValue)
getMinute(const uint8_t* encodedValue)
{
return (encodedValue[2] & 0x3f);
}
Expand All @@ -127,7 +127,7 @@ setMinute(uint8_t* encodedValue, int value)
}

static bool
isInvalid(uint8_t* encodedValue)
isInvalid(const uint8_t* encodedValue)
{
return ((encodedValue[2] & 0x80) != 0);
}
Expand All @@ -142,7 +142,7 @@ setInvalid(uint8_t* encodedValue, bool value)
}

static bool
isSubstituted(uint8_t* encodedValue)
isSubstituted(const uint8_t* encodedValue)
{
return ((encodedValue[2] & 0x40) == 0x40);
}
Expand All @@ -161,7 +161,7 @@ setSubstituted(uint8_t* encodedValue, bool value)
**********************************/

bool
CP24Time2a_getFromBuffer (CP24Time2a self, uint8_t* msg, int msgSize, int startIndex)
CP24Time2a_getFromBuffer (CP24Time2a self, const uint8_t* msg, int msgSize, int startIndex)
{
if (msgSize < startIndex + 3)
return false;
Expand All @@ -175,7 +175,7 @@ CP24Time2a_getFromBuffer (CP24Time2a self, uint8_t* msg, int msgSize, int startI
}

int
CP24Time2a_getMillisecond(CP24Time2a self)
CP24Time2a_getMillisecond(const CP24Time2a self)
{
return getMillisecond(self->encodedValue);
}
Expand All @@ -187,7 +187,7 @@ CP24Time2a_setMillisecond(CP24Time2a self, int value)
}

int
CP24Time2a_getSecond(CP24Time2a self)
CP24Time2a_getSecond(const CP24Time2a self)
{
return getSecond(self->encodedValue);
}
Expand All @@ -199,7 +199,7 @@ CP24Time2a_setSecond(CP24Time2a self, int value)
}

int
CP24Time2a_getMinute(CP24Time2a self)
CP24Time2a_getMinute(const CP24Time2a self)
{
return getMinute(self->encodedValue);
}
Expand All @@ -212,7 +212,7 @@ CP24Time2a_setMinute(CP24Time2a self, int value)
}

bool
CP24Time2a_isInvalid(CP24Time2a self)
CP24Time2a_isInvalid(const CP24Time2a self)
{
return isInvalid(self->encodedValue);
}
Expand All @@ -224,7 +224,7 @@ CP24Time2a_setInvalid(CP24Time2a self, bool value)
}

bool
CP24Time2a_isSubstituted(CP24Time2a self)
CP24Time2a_isSubstituted(const CP24Time2a self)
{
return isSubstituted(self->encodedValue);
}
Expand Down Expand Up @@ -322,7 +322,7 @@ CP32Time2a_create(CP32Time2a self)
}

bool
CP32Time2a_getFromBuffer (CP32Time2a self, uint8_t* msg, int msgSize, int startIndex)
CP32Time2a_getFromBuffer (CP32Time2a self, const uint8_t* msg, int msgSize, int startIndex)
{
if (msgSize < startIndex + 4)
return false;
Expand All @@ -336,7 +336,7 @@ CP32Time2a_getFromBuffer (CP32Time2a self, uint8_t* msg, int msgSize, int startI
}

int
CP32Time2a_getMillisecond(CP32Time2a self)
CP32Time2a_getMillisecond(const CP32Time2a self)
{
return (self->encodedValue[0] + (self->encodedValue[1] * 0x100)) % 1000;
}
Expand All @@ -352,7 +352,7 @@ CP32Time2a_setMillisecond(CP32Time2a self, int value)


int
CP32Time2a_getSecond(CP32Time2a self)
CP32Time2a_getSecond(const CP32Time2a self)
{
return getSecond(self->encodedValue);
}
Expand All @@ -364,7 +364,7 @@ CP32Time2a_setSecond(CP32Time2a self, int value)
}

int
CP32Time2a_getMinute(CP32Time2a self)
CP32Time2a_getMinute(const CP32Time2a self)
{
return getMinute(self->encodedValue);
}
Expand All @@ -377,7 +377,7 @@ CP32Time2a_setMinute(CP32Time2a self, int value)
}

bool
CP32Time2a_isInvalid(CP32Time2a self)
CP32Time2a_isInvalid(const CP32Time2a self)
{
return isInvalid(self->encodedValue);
}
Expand All @@ -389,7 +389,7 @@ CP32Time2a_setInvalid(CP32Time2a self, bool value)
}

bool
CP32Time2a_isSubstituted(CP32Time2a self)
CP32Time2a_isSubstituted(const CP32Time2a self)
{
return isSubstituted(self->encodedValue);
}
Expand All @@ -401,7 +401,7 @@ CP32Time2a_setSubstituted(CP32Time2a self, bool value)
}

int
CP32Time2a_getHour(CP32Time2a self)
CP32Time2a_getHour(const CP32Time2a self)
{
return (self->encodedValue[3] & 0x1f);
}
Expand All @@ -413,7 +413,7 @@ CP32Time2a_setHour(CP32Time2a self, int value)
}

bool
CP32Time2a_isSummerTime(CP32Time2a self)
CP32Time2a_isSummerTime(const CP32Time2a self)
{
return ((self->encodedValue[3] & 0x80) != 0);
}
Expand Down Expand Up @@ -515,7 +515,7 @@ CP56Time2a_setFromMsTimestamp(CP56Time2a self, uint64_t timestamp)


uint64_t
CP56Time2a_toMsTimestamp(CP56Time2a self)
CP56Time2a_toMsTimestamp(const CP56Time2a self)
{
struct tm tmTime;

Expand All @@ -534,7 +534,7 @@ CP56Time2a_toMsTimestamp(CP56Time2a self)
}

/* private */ bool
CP56Time2a_getFromBuffer(CP56Time2a self, uint8_t* msg, int msgSize, int startIndex)
CP56Time2a_getFromBuffer(CP56Time2a self, const uint8_t* msg, int msgSize, int startIndex)
{
if (msgSize < startIndex + 7)
return false;
Expand All @@ -548,7 +548,7 @@ CP56Time2a_getFromBuffer(CP56Time2a self, uint8_t* msg, int msgSize, int startIn
}

int
CP56Time2a_getMillisecond(CP56Time2a self)
CP56Time2a_getMillisecond(const CP56Time2a self)
{
return getMillisecond(self->encodedValue);
}
Expand All @@ -560,7 +560,7 @@ CP56Time2a_setMillisecond(CP56Time2a self, int value)
}

int
CP56Time2a_getSecond(CP56Time2a self)
CP56Time2a_getSecond(const CP56Time2a self)
{
return getSecond(self->encodedValue);
}
Expand All @@ -572,7 +572,7 @@ CP56Time2a_setSecond(CP56Time2a self, int value)
}

int
CP56Time2a_getMinute(CP56Time2a self)
CP56Time2a_getMinute(const CP56Time2a self)
{
return getMinute(self->encodedValue);
}
Expand All @@ -584,7 +584,7 @@ CP56Time2a_setMinute(CP56Time2a self, int value)
}

int
CP56Time2a_getHour(CP56Time2a self)
CP56Time2a_getHour(const CP56Time2a self)
{
return (self->encodedValue[3] & 0x1f);
}
Expand All @@ -596,7 +596,7 @@ CP56Time2a_setHour(CP56Time2a self, int value)
}

int
CP56Time2a_getDayOfWeek(CP56Time2a self)
CP56Time2a_getDayOfWeek(const CP56Time2a self)
{
return ((self->encodedValue[4] & 0xe0) >> 5);
}
Expand All @@ -608,7 +608,7 @@ CP56Time2a_setDayOfWeek(CP56Time2a self, int value)
}

int
CP56Time2a_getDayOfMonth(CP56Time2a self)
CP56Time2a_getDayOfMonth(const CP56Time2a self)
{
return (self->encodedValue[4] & 0x1f);
}
Expand All @@ -620,7 +620,7 @@ CP56Time2a_setDayOfMonth(CP56Time2a self, int value)
}

int
CP56Time2a_getMonth(CP56Time2a self)
CP56Time2a_getMonth(const CP56Time2a self)
{
return (self->encodedValue[5] & 0x0f);
}
Expand All @@ -632,7 +632,7 @@ CP56Time2a_setMonth(CP56Time2a self, int value)
}

int
CP56Time2a_getYear(CP56Time2a self)
CP56Time2a_getYear(const CP56Time2a self)
{
return (self->encodedValue[6] & 0x7f);
}
Expand All @@ -646,7 +646,7 @@ CP56Time2a_setYear(CP56Time2a self, int value)
}

bool
CP56Time2a_isSummerTime(CP56Time2a self)
CP56Time2a_isSummerTime(const CP56Time2a self)
{
return ((self->encodedValue[3] & 0x80) != 0);
}
Expand All @@ -661,7 +661,7 @@ CP56Time2a_setSummerTime(CP56Time2a self, bool value)
}

bool
CP56Time2a_isInvalid(CP56Time2a self)
CP56Time2a_isInvalid(const CP56Time2a self)
{
return isInvalid(self->encodedValue);
}
Expand All @@ -673,7 +673,7 @@ CP56Time2a_setInvalid(CP56Time2a self, bool value)
}

bool
CP56Time2a_isSubstituted(CP56Time2a self)
CP56Time2a_isSubstituted(const CP56Time2a self)
{
return isSubstituted(self->encodedValue);
}
Expand Down
6 changes: 2 additions & 4 deletions lib60870-C/src/iec60870/cs101/cs101_asdu.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 MZ Automation GmbH
* Copyright 2016-2022 Michael Zillgith
*
* This file is part of lib60870-C
*
Expand Down Expand Up @@ -52,7 +52,7 @@ asduFrame_setNextByte(Frame self, uint8_t byte)
}

static void
asduFrame_appendBytes(Frame self, uint8_t* bytes, int numberOfBytes)
asduFrame_appendBytes(Frame self, const uint8_t* bytes, int numberOfBytes)
{
ASDUFrame frame = (ASDUFrame) self;

Expand Down Expand Up @@ -1086,8 +1086,6 @@ CS101_ASDU_getElementEx(CS101_ASDU self, InformationObject io, int index)

case M_EI_NA_1: /* 70 - End of Initialization */

elementSize = self->parameters->sizeOfIOA + 1;

retVal = (InformationObject) EndOfInitialization_getFromBuffer((EndOfInitialization) io, self->parameters, self->payload, self->payloadSize, 0);

break;
Expand Down
Loading

0 comments on commit 53a6b3c

Please sign in to comment.