* Added some optional properties into the object property lists up to protocol-revision 22
* Added serial-number property to basic device object example.
* pre-commit: Update and enable clang-format check
There is newer version from clang-format so use that. We do not yet want
18 as that is little bit too new.
* Format some thing by hand which clang-format "breaks"
Clang-format will format some things little bit off in some cases.
Format some things by hand so we get cleaner end result.
* Run clang-format with
```
pre-commit run --all-files clang-format
```
We have already in previously checked places where clang-format does not
make good format and ignored those (hopefully most of the things).
---------
Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
* 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>
* Add editorconfig and pre-commit config
Editorconfig is widly used and supported file. It says basic things how
files should be formatted.
pre-commit is tool which can automatically check some basic checks like
code formatting everytime someone makes commit. This can also be used in
CI to run these things. Then it is very easy to do same things locally
as in CI. This also makes easy to select clang-format version so
everyone is using same one.
* clang-format: Ignore folders where are external code
We should not format external code. Add clang-format files to exclude
those. We should move external code always to example external/ folder
so we can exclude those more easily.
* clang-format: Remove custom zephyr/.clang-gormat
This clang-format file where introduces before our root clang-format. It
does not make sense anymore as we have root clang-format. Removing this
will unifie formatting in whole repo.
* clang-format: Add couple new rules
Add couple new formatting rules.
Always align const to left side. We did have only one place where it was
right side so this make sense as it is already rule for us.
I choose also insertbraces becuase when I run this I notice that we have
lot of multiline code without braces. So very error prone places. This
will take error possibility away. Repo also always use braces even with
single line statments so this does not matter much.
* ci: Add pre-commit validation
Validate pre-commit in CI.
* format: Convert spaces to tabs in Makefiles
Makefile normally use tabs. We enforce that with editorconfig. Fix
couple places where spaces where still in use.
---------
Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
* Added basic object-name get for ASCII names to enable free if they were dynamically created. Added unit testing to validate the basic object ASCII object-name API.
* Removed static scope on character array used for name since the array gets copied into characterstring array and static is not needed.
* 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>
* bacint: Do not use ULL suffix
For sake of be more compatible with C89/C90 let's not use ULL at all.
Overall conversion functions are lot cleaner now. Only idiotic thing is
in bacnet_unsigned_length() where we need to do shift. There is probably
better way to do that but could not come up any at resonable time.
* Force C89/C90 and for tests C99
bacnet-stack seems to be all compatible with C89/C90. This is probably
design choice. Let's force this in CMake so no one will break that by
accident.
In tests we are using some C99 features already. Let's not be to strict
about those as those are "just tests".
* Fix -Wdeclaration-after-statement warnings
To make code C89/C90 compatible fix -Wdeclaration-after-statement
warnings.
We got like following warning without this change.
```C
bacnet-stack/apps/epics/main.c:293:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement
293 | uint32_t Object_Instance;
| ^~~~~~~~
```
* cmake: Add -Wno-c99-extensions compiler option
Clang does not like _Bool which is used in stdbool.h files. For now
let's just ignore this. We could define that differently but let's think
that another time. Now goal is to get warning free CI with more code to
be builded in there.
* cmake: Add -Wno-long-long compiler option for apple
Apple seems to do stupid things with their system header. There is
UINT64_MAX with ULL suffix and not like in Linux and Windows
__UINT64_C(18446744073709551615)
For this reason we need to ignore Wlong-long for it.
---------
Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
* Add and remove compiler warning compile options
Add some new compiler warnings. Some of those does not build clean so
ignore them for now. This also helps if some user use those options so
we ignore those for them also.
Also remove following ignores as they do not produce any warnings:
- Wno-attributes
- Wno-long-long
- Wno-implicit-fallthrough
* Fix -Wmissing-declarations compiler warnings
Fix new -Wmissing-declarations compiler warnings. I tried to look which
should be in headers and which should be static. Might be that some
statics should be in header as it is not easy to choose if something
should be exported or not.
* Fix -Wmissing-field-initializers compiler warnings
If we use { { 0 } } compiler thinks we might have mean that we only
meant initialize first member of struct or have forgotton to add second
one. We could do { { 0 }, 0 } but we can just do { 0 } which tells
compiler that hey just intialize this whole thing to zero.
* tests: Fix couple -Wfloat-conversion warnings
Add f prefix to floating point numbers to get some double to float
warnings away.
* ci: Make warnings as errors with cmake main build
To keep repo more clean from warnings use Werror flag when building main
project.
Windows should need -DCMAKE_C_FLAGS="/WX" but we have not ignore errors
for that yet so let's not yet take it in use.
* ci: Build also tests in matrix build
Enable also tests to be builded in our main matrix build. This way tests
will be builded also with clang and in future also with MSVC. We also
keep build very clean now as all warnings as catched.
With this we can also take out -Werror from compile_options as we add
that in CI. It is not good practice to keep that option always on. It
makes development lot harder. See example this blog post [1].
[1]: https://embeddedartistry.com/blog/2017/05/22/werror-is-not-your-friend/
* getevent: Deprecate getevent_encode_apdu()
Steve suggested that we should deprecate getevent_encode_apdu() [1].
Suggested-by: Steve Karg
[1]: https://github.com/bacnet-stack/bacnet-stack/pull/718#discussion_r1715821735
---------
Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
* Change MIT license texts to SPDX-License-Identifier
SPDX-License-Identifier is much easier to understand and grep than
license text so use that instead.
* Change GPL exception license texts to SPDX-License-Identifier
SPDX-License-Identifier is much easier to understand and grep than
license text so use that instead.
* Change misc license texts to SPDX-License-Identifier
There are some external code in repo which are not licenses as most of
the stuff in this repo. We still want every file to have SPDX identifier
to easily grep licenses.
* Add currently used license files
Even though Bacnet-Stack is using SPDX identifiers we still need to give
those license files with source. For this reason add all license files
to license/ folder.
SPDX has also files which would make same thing but this is style which
example Linux kernel is using and it is quite clear so I choose that one
for now.
I choosed not yet bring CC-PDDC as that is not right license for those
files.
---------
Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
* Refactored and secured BACnetActionCommand codec into bacaction.c module for command object and added to bacapp module encode/decode with define for enabling and pseudo application tag for internal use.
* Simplified bacapp_data_len() and moved into bacdcode module as bacnet_enclosed_data_len() function.
* Secured ReadProperty-REQUEST and -ACK decoding.
* Removed deprecated Keylist_Key() functions from usage.
* Removed pseudo application datatypes from bacapp_data_decode() which only uses primitive application tag encoded values.
* Defined INT_MAX when it is not already defined by compiler or libc.
* Deprecated bacapp_decode_application_data_len() and bacapp_decode_context_data_len() as they are no longer used in any code in the library.
* Added BACnetScale to bacapp module. Improved complex property value decoding. Refactored bacapp_decode_known_property() function.
* Refactored and improved the bacapp_snprintf() function for printing EPICS.
* Fixed Lighting Output WriteProperty to handle known property decoding.
* Reduced MS/TP MAX_APDU to 480 from 1476 so that devices not use new MS/TP extended frame types which older routers do not understand.
* Added extra objects to STM32F4xx example to elicit edge cases in object-list for testing.
* Changed MS/TP master node self destination checks to be located in receive FSM
* Changed MSTP zero configuration: modified comments for state transition names; modified next station increment; refactored the UUID rand() to not be required by common zero config implementation; added more unit tests.
* Added another context to MS/TP user data to allow additional user data
* Added basic structured view object and unit test. Added example structured view into server example.
* Removed creation of objects from basic device object into the server example
* Fixed example app router-ipv6 to build under ports/win32
* Fixed example app router-mstp to build under ports/win32 with MinGW
* Added win32 builds of router-ipv6 and router-mstp to the Github pipeline
* Added required linux Ethernet library for ethernet build
* Added .obj to gitignore
* Fixed BACnet port for APPLE to use BSD in CMake
* Changed format in CMake to enable cleaner SC merge
* Added create-object and delete-object recipes in GCC Makefile
* Added datalink timer to all example OS apps
* Changed most microcontroller ports to use BACAPP_MINIMAL to specify which datatypes can be written.
* Fixed zephyr OS for BACnet/IP warning
* Fixed zephyr OS log to not require log_strdup
* Added writefile API to file object example
* Added API to device-client to make it more robust.
* Added API in network-port object for getting the ASCII object-name
* Added debug print with a timestamp option
* Added debug print with hex dump print
* Added API to network port object for activate and discard
* Added default define for debug with timestamp
* Added prototype in header for disabled debug printf.
* Added fifo peek ahead function to peek at more than one byte.
* Added get-mac value for network port that uses buffer rather than octetstring
* Added Create/Delete object services to Analog Input, Analog Value, Binary Input, Binary Value, Multistate Input, Multistate Value object examples, and updated their units tests.
* Refactor property lists member function for WriteProperty default case.
* Refactor time-value object unit testing
* Added test for unsupported property to common property test
* Fixed compile warnings from double-float promotions.
* Changed zephyr compile to suppress deprecation warnings
* Fixed CreateObject API return value in many objects header files
* Changed zephyr build defines as strdup is no longer required for log print of strings
* 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.
* [WIP] update manifest to zephyr v3.6.0
* [WIP] Deprecated ZTEST_NEW_API adjustments
Zephyr v3.6.0 removed Kconfig ZTEST_NEW_API.
The old ZTEST API is still used by non-Zephyr builds,
so the config setting is moved from `prj.conf` to
the test's CMakeLists.txt as `add_compile_definitions()`.
Verified by:
1. make clean all test
2. ./zephyr/scripts/twister -p unit_testing \
-T bacnet-stack/zephyr/tests/
---------
Co-authored-by: Gregory Shue <gregory.shue@legrand.com>