* Make most of the functions const correct
Used clang-tidy and sonarlint to help find places where const could
pretty easily applied. Also lot of hand work.
This commit does not yet touch handlers and typedefs of those.
* Fix Arduino uno handler_who_is() has extra parenthesis
For some reason there is extra parenthesis. Remove it this is more
likely buildable.
* Bugfix/bacapp: Fix uninitilized array_index
We have changed bacapp_snprintf_value() to be const correct. After that
we got
```
/home/runner/work/bacnet-stack/bacnet-stack/src/bacnet/bacapp.c:3183:27: warning: 4th function call argument is an uninitialized value [core.CallAndMessage]
ret_val = bacapp_snprintf_weeklyschedule(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
```
So analyzer could now spot that we do not actually initilize array_index
at all. Fix this by setting array_index to zero. Note that I actually do
not know if zeroing is right thing to do here. I choose zero as if this
has worked before it is most likely that it will work with zero value.
* cmake: Add and ignore Wwrite-strings compiler option
Wwrite-strings helps find places where const correctness is broken.
Example it will warn about these
```C
void func1(char* str);
func("test") /* "test" is const so we should not pass it to func1().
char* func2()
{
return "test"; /* func2() should return const char*.
}
```
We still need to ignore it as not all are fixed but let's add it already
so we remember that it should be opened at some point.
---------
Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
* format: Strip trailing whitespaces
We want to get rid of trailing whitespaces completly as they make just git
noice. Much better to start using automated tools to get rid of them once and
not getting them back again. This way git history will be cleaner and review
easier.
Commit was generated with:
pre-commit run --all-files trailing-whitespace
* format: Files should have exactly one new line end of them
It is good practice that every file has one new line. It is not now days so
mandatory but it also is not nice if file has lot of newlines end of it. We will
use pre-commit which takes automatically care about this so let's fix all.
Commit was generated with:
pre-commit run --all-files end-of-file-fixer
* format: Convert tabs to spaces
Project mostly use spaces over tabs. When mixing tabs and spaces this usually
makes formatting issues and also when changing those in commits it will make lot
of git noise. We will force spaces most of the time and use pre-commit to fix.
Commit was generated with:
pre-commit run --all-files remove-tabs
---------
Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
* ci: Fix compile warning as errors was not correct
We want to enable warning as errors both Windows and Linux. This is
easiest to do with cmake option as -Werror does not work with MSVC. Also
it is self explaining what it does so no comment needed.
* dlmstp_linux: Fix -Wdeclaration-after-statement compiler warnings
Make dlmstp_linux C89/C90 combatible
```
/bacnet-stack/ports/linux/dlmstp_linux.c: In function ‘Timer_Silence’:
/bacnet-stack/ports/linux/dlmstp_linux.c:56:5: warning:
ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
56 | int32_t res;
| ^~~~~~~
/bacnet-stack/ports/linux/dlmstp_linux.c: In function ‘dlmstp_init’:
/bacnet-stack/ports/linux/dlmstp_linux.c:795:5: warning:
ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
795 | struct termios newtio;
| ^~~~~~
```
* Fix warnings produces by MSVC
Now that we have enabled /Wall for MSVC we get some warnings with it
which can be easily fixed.
We get following warnings:
```
src\bacnet\bacstr.c(223,39): warning C4127: conditional expression is constant
apps\router-mstp\main.c(1123,1): warning C4702: unreachable code
apps\epics\main.c(885,53): warning C4459: declaration of 'myState' hides global declaration
```
* cmake: Use /Wall with MSVC
Make MSVC to build cleanly with Wall. This might matter for some Windows
developers. And you never know if MSVC will find more bugs.
* cmake: Improve router build
Router build gives some warnings as it is not C90 compatible. It is ok
that example is not following C90 rules. Also it is annoing to new user
to build this cmake as first error usually is that libconfig is not
found. Let's just give warning about this so first build will usually go
smoother.
---------
Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
* Added dependent BACnet stack headers into bacdef.h file.
* Changed bacdef.h and other stack includes in c/h files to have a common pattern.
* Moved bits.h, bytes.h, and bacnet_stack_exports.h under bacnet/basic/sys/ folder.
* Fix routing to a remote network in the router-mstp example.
The net, len and adr fields of remote_dest are not initialized
although they are used by the npdu_encode_pdu function in
case of "Routing to another Router". Thank you, Eugene!
* Fixed handling of received MS/TP extended frames.
mstp_port->DataLength should be set to the actual length of decoded data.
* Fix MSTP_Master_Node_FSM and MSTP_Slave_Node_FSM for extended frames.
BACNET_EXTENDED_DATA frames should be treated the same as
their corresponding BACNET_DATA frames.
* Fixed MSTP COBS frame encoding
cobs_frame_encode writes the encoded data to the
beginning of the buffer, overwriting the frame header.
The frame header is constructed before COBS frame encoding,
so it contains the wrong Frame Type and Data Length.
* Added extended frame client unit test
* Fix router-ipv6 application for remote networks