Commit Graph

3669 Commits

Author SHA1 Message Date
Steve Karg 8ee583a10c Added RP and RPM error code indications in callbacks (#756) 2024-08-29 14:09:22 -05:00
Kari Argillander a2f1d6959d Make most of functions const correct (#714)
* 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>
2024-08-29 14:08:02 -05:00
Kari Argillander 0177c59f4a Use pre-commit and editorconfig (#753)
* 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>
2024-08-28 17:04:00 -05:00
Kari Argillander 599033b7b0 Move some external files to external/ folder (#744)
It is lot easier to work with automatic formatters if we have external
files in different folder. For some tools we can example just exclude
external all together.

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
2024-08-28 16:24:48 -05:00
Steve Karg 3d3e192ae9 Added object-name c-string getter function to basic objects so they can be referenced to free if dynamically created. (#754)
* 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.
2024-08-28 16:21:58 -05:00
Steve Karg b3c8c10c03 Fixed COV detection in the basic Binary Output object example. (#751) 2024-08-26 15:03:58 -05:00
Steve Karg 3e0370eee1 Updated Version to 1.3.8 for release on 2024-08-26 (#720) 2024-08-26 08:14:19 -05:00
Jonathan 9d570cd579 Add shield option explanation to ports/stm32f4xx/README.md (#749) 2024-08-26 07:40:47 -05:00
Kari Argillander 369da70f2a Strip tabs and trailing white spaces, and fix end of files (#748)
* 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>
2024-08-25 14:13:57 -05:00
Kari Argillander 9e0657424e Prepere repo so we can run auto formatters (#747)
* clang-format: Ignore javascript files

Ignore javascript files. Clang-format is not very good formatter for
javascript files anyway. If we ever need javascript formatter we should
use Prettier.

* clang-format: Ignore some lines in sources

Couple things get formatted really funky if we let clang-format format
those. Just ignore those locally.

* zephyr/tescase.yaml: Fix yaml syntax

pre-commit hook check-yaml did found out that there are two skips.
Remove another as this is not right syntax.

* Fix repo contains unicode replacement chars

When running pre-commit text-unicode-replacement-char it founds that
there is couple unicode replacemnt chars. Remove and replace these.

* Convert some tabs to spaces manually

We will soon auto format tabs to spaces. How ever it could not do couple
thing so fix those by hand first.

* Make files with shebang executables

It is good habit that if file has shebang then it is marked executable.
These where found with pre-commit check-shebang-scripts-are-executable
checker.

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
2024-08-23 17:58:41 -05:00
Steve Karg 36b5a3be98 Fixed MacOS specific usage during FreeBSD 11.4 build (#745)
* Fixed path of exports header in BSD ports. 

* Fixed MacOS specific include in BSD ports. 

* Fixed MacOS specific IOSSIOSPEED and IOSSDATALAT usage in BSD ports
2024-08-23 17:50:30 -05:00
Steve Karg eba1def58c Refactored required writable property function from epics app (#743) 2024-08-22 16:31:16 -05:00
Steve Karg f814ffbc49 Added API for intrinsic reporting properties in Binary Value and Binary Input objects (#742)
Co-authored-by: Tomasz Kazimierz Motyl <tomasz.motyl@se.com>
2024-08-22 15:31:08 -05:00
Steve Karg ab5481ff90 Fixed the length of the basic Network Port object MAC address property. (#741) 2024-08-22 08:10:10 -05:00
Kari Argillander 9662a76ebd Make clean build with MSVC /Wall (#740)
* 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>
2024-08-22 07:50:20 -05:00
Steve Karg 76d605e06b Added load control object into zephyr basic device example (#739) 2024-08-21 15:01:25 -05:00
Tomasz Kazimierz Motyl cbd5f43684 Added clauses c) and f) of 13.3.6 (out_of_range) algorithm and enabling transitions from high/low limit states to normal when Event_Enable = 0 for the basic Analog Value and Analog Input objects (#733) 2024-08-21 14:36:37 -05:00
Kari Argillander d92edd359f Fix couple compiler warnings (#737)
* linux/bip6: Use function over PRINTF macro

Our repo should be C89 compatibale. C89 does not support variac macros.
For this reason use variac functions. This also enables to print
different streams than just stderr.

Also now if something is changed in debug_fprintf it also affect here
which is good.

* Use __inline__ over inline in library

Use __inline__ over inline as that is C89/C90 combatible. With MSVC we
need to use __inline so just define __inline__ to it if not already.

* h_get_alarm_sum: Fix -Wself-assign compiler warning

We get Wself-assign if PRINT_ENABLED is 0

```
src/bacnet/basic/service/h_get_alarm_sum.c:129:16:
  warning: explicitly assigning value of variable of type 'int' to itself
  [-Wself-assign]
[build]   129 |     bytes_sent = bytes_sent;
[build]       |     ~~~~~~~~~~ ^ ~~~~~~~~~~
```

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
2024-08-21 09:44:31 -05:00
Tomasz Kazimierz Motyl 5c20e6d505 Merge pull request #59 from se-apc/bugfix/out_of_resources_error_on_cov_address_list_depletion (#734)
We report an error: resources, no-space-to-add-list-element on reachng MAX_COV_ADDRESSES limit with COV subsriptions

Co-authored-by: Tomasz Kazimierz Motyl <tomasz.motyl@se.com>
2024-08-21 09:23:10 -05:00
Steve Karg 20c3b1c69c Fixed zephyr BACnet/IP for use in native_posix. Fixed zephyr logging level for BACnet. (#738) 2024-08-20 15:21:03 -05:00
Steve Karg f09a0ce5ed Added prototype for device object property list member to use for storing device data storing. (#735) 2024-08-19 09:32:52 -05:00
Steve Karg 032bf10994 Added mstpcap to apps/Makefile BSD build (#730) 2024-08-17 08:52:37 -05:00
Steve Karg e3098bbaa2 Added device WriteProperty callback for non-volatile storing in basic device examples. (#728) 2024-08-16 14:13:56 -05:00
Steve Karg e1002c433f Revert "Zephyr 3.7.0 integration fixes: (#723) (#724)"
This reverts commit 2d7a2961a2.
2024-08-16 09:02:24 -05:00
Steve Karg e9bcaa746c Fixed endless query in bac-rw module when error is returned. (#727) 2024-08-16 08:28:25 -05:00
Kari Argillander dab6d8af55 Build more code in CI (#725)
* bugfix/hostnport: Fix bacnet_fdt_entry_from_ascii() parse wrong
* apps/router: Fix Wstrict-prototypes compiler warnings
* apps/router: Fix -Wmissing-field-initializers compiler warning
* ports/linux: Fix -Wself-assign compiler warning
* ports/linux: Fix -Wunused-function compiler warning
* Fix -Wimplicit-function-declaration warnings
* ci: Add more compile options to enable more code build
* ci: Do not fail-fast our main matrix build
* cmake: Add -Wno-c99-extensions compiler option

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2024-08-15 11:20:10 -05:00
Greg Shue 2d7a2961a2 Zephyr 3.7.0 integration fixes: (#723) (#724)
- Update west.yml
- Update samples.yaml to new syntax, board names
- Patches to ports/zephyr (some stubs)

Verified by:

1. ./zephyr/scripts/twister -p unit_testing -T bacnet-stack/zephyr/tests

2. ./zephyr/scripts/twister -T bacnet-stack/zephyr/samples/ --integration

Fix #721

Co-authored-by: Gregory Shue <gregory.shue@legrand.com>
2024-08-15 07:24:09 -05:00
Kari Argillander 40c5570d64 Force C89/C90 compatible and for test C99 (#722)
* 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>
2024-08-15 07:23:04 -05:00
Steve Karg c1195dd8a0 Added CreateObject, DeleteObject, and COV to Integer Value object (#719)
Co-authored-by: Tomasz Kazimierz Motyl <tomasz.motyl@se.com>
2024-08-14 08:54:03 -05:00
Kari Argillander 6271632944 Add and fix compiler warnings (#718)
* 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>
2024-08-13 16:32:44 -05:00
Kari Argillander cb243c36a8 Improve SPDX identifier coverage (#716)
* 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>
2024-08-12 15:33:02 -05:00
Steve Karg e5307e280c Added CreateObject and DeleteObject to Load Control object. (#713) 2024-08-11 19:14:27 -05:00
Steve Karg ebb8be067f Removed extraenous coverage recipe in test all recipe. 2024-08-07 11:44:15 -05:00
Steve Karg 81e83b19c1 Fixed Lighting Output unit test builds after recent fixes added debug printing and implicit float to double promotion. 2024-08-07 11:27:51 -05:00
Steve Karg 18d4b47b2c Fixed Lighting Output object lighting command decoding and ramp operations 2024-08-07 11:07:23 -05:00
Steve Karg 350bbe3331 Fixed implicit conversion from float to double in lighting output and color. 2024-08-06 17:22:27 -05:00
Steve Karg 19f276b7f2 Fixed implicit conversion of float to double when using snprintf() format specifier %f. 2024-08-06 16:41:42 -05:00
Steve Karg b5e0aa97fc revert LCOV changes to test Makefile 2024-08-06 16:30:56 -05:00
Steve Karg be65abe159 Fixed unit test compiler warnings 2024-08-06 16:19:08 -05:00
Steve Karg 1be0aa39b9 Fixed compile warnings and BACnet priority array decoding (#712)
* Fixed network port warning for unused static function.

* Fixed BACnetPriorityArray decoding in bacapp module

* Fixed epics print of BACnetDateTime complex data.
2024-08-06 14:10:03 -05:00
Steve Karg a1d91dbeb1 Updated B-SS profile sample build for Zephyr OS. (#711) 2024-08-06 09:52:10 -05:00
Steve Karg 61730e3d87 Fixed load control object and unit test. Added recipe to Makefile for Zephyr OS twister unit testing. (#710) 2024-08-06 08:28:01 -05:00
Steve Karg ebfaa5eb2c Added Exception_Schedule property to schedule object example. (#709) 2024-08-01 12:15:57 -05:00
Steve Karg 4ee3bb6fa2 Added create and delete methods to basic device object table for calendar object. 2024-07-31 09:42:41 -05:00
Eric Miller bdf63f4b19 Fixed typo in command line argument check of example app for BACnet Network-Number-Is (#707) 2024-07-30 12:03:54 -05:00
Steve Karg c55f5e2886 Added alaternate define for BACNET_NPDU_DATA as BACNET_NPCI_DATA. 2024-07-29 07:17:33 -05:00
Michael O'Neill 274781a8bc Added mstpcap for MacOS (#705)
* Updated the Makefile for mstpcap to accomodate macOS and to build the bacnet lib. Compiling working version of mstpcap on macOS 14, although compiling should work on many earlier versions.  The --extcap-interfaces flag now works for macOS which allows one to use mstpcap as an extcap for Wireshark while listing the available serial ports and baud rates.

* note: Had to use uname to figure out if one is on Darwin/macOS vs vanilla BSD. From there, macOS specific supported features and location are used. For instance, the 76800 baud rate is natively supported.

* note: MacOS doesn't like placing the mstpcap executable in the global extcap plugin directory as it corrupts the Wireshark executable from an xattr and SIP (System Integrity Protection) perspective and macOS will refuse to run it calling it 'corrupt'. One could turn off xattr stuff, using xattr -cr, but could be risky long term. A safer, permissible workaround is to place the executable in the user .local extcap directory: '/Users/<your_user_name>/.local/lib/wireshark/extcap/'. If the directory doesn't exist just create it and copy the executable there.

* note: make the executable from the root or apps folder, as there are defines in the apps folder that are common to all the apps. The mstpcap executable is copied to bacnet-stack/bin/ folder.

---------

Co-authored-by: Michael O'Neill <em.pee.oh@gmail.com>
2024-07-26 16:23:40 -05:00
Steve Karg 4326128e72 Secure ReadProperty decoding and BACnetActionCommand (#702)
* 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.
2024-07-25 17:12:08 -05:00
Steve Karg 923eaf2313 Added some dependency into zephyr kconfig for BACnet/IP builds. Updated simple sensor sample. 2024-07-24 10:38:24 -05:00
Steve Karg 4694b9b2eb Added bacnet-basic callback in zephyr subsys to include init and task in same thread. 2024-07-23 15:27:39 -05:00