Commit Graph

204 Commits

Author SHA1 Message Date
Steve Karg 94b3809a58 Bugfix/confirmed handlers empty service request (#885)
* Added reject in all confirmed service handlers, except GetEventInformation, when confirmed services with zero length occur which rejects with required parameters are missing message.

* Refactored errno use in service using debug_perror. Changed debug_perror usage to debug_fprintf. 

* Updated file and function headers in basic/service modules.

* Changed NDPU priority on confirmed messages to use requested NDPU priority.

* Renamed debug_aprintf to debug_printf_stdout for clarity.

* Convert most debug_fprintf usage to debug_print to reduce text bloat in AVR build
2025-01-05 10:09:39 -06:00
Steve Karg cdda524afc Added Time-Of-Device-Restart property to example device. (#860)
* Added Time-Of-Device-Restart property to example device.

* Added BACnetTimeStamp bacapp support for encode, decode, and parse.

* Added specific addresses handling to apps/writeprop bacwp command line.
2024-11-22 19:14:09 -06:00
Steve Karg 776b212995 Removed strcasecmp and strncasecmp because they are non-standand C functions. (#858) 2024-11-21 12:29:08 -06:00
Steve Karg 1375347ab6 Added bacnet_strnlen and bacnet_stricmp to avoid libc compiler problems (#857)
* Added bacnet_strnlen and bacnet_stricmp to avoid libc compiler problems

* FIxed compiler warnings in printf conversions.
2024-11-21 06:43:37 -06:00
Steve Karg 51c915a5da Bugfix/lighting output dimming refactor (#855)
* Refactored lighting command operations from the lighting output object, and added unit testing. Integrated the result back into lighting-output object.
2024-11-13 15:24:25 -06:00
Steve Karg cf77abac9b Feature/bacnet secure connect hub (#818)
* Added BACnet Secure Connect datalink.

* Added BACnet/SC hub application
---------

Co-authored-by: Kirill Neznamov <kirill.neznamov@dsr-corporation.com>
Co-authored-by: Mikhail Antropov <michail.antropov@dsr-corporation.com>
Co-authored-by: Ondřej Hruška <ondra@ondrovo.com>
Co-authored-by: Patrick Grimm <patrick@lunatiki.de>
2024-11-04 07:05:26 -06:00
Steve Karg d47bb67c21 Added WriteGroup service to blinkt app demo. (#843) 2024-11-01 10:40:53 -05:00
Steve Karg 97213c3a13 Build blinkt and piface in gcc pipeline to prevent bit rot. (#842) 2024-10-31 21:52:22 -05:00
Steve Karg 6d9cff2312 Fixed device object compile errors and added IPv6 recipes for blinkt and piface (#841) 2024-10-31 14:16:47 -05:00
Steve Karg 15412b9ee5 Added linker specific code for Darwin for compiling mstpcrc (#833) 2024-10-29 12:33:55 -05:00
Steve Karg 3329dff337 Added WriteGroup service and Channel object interfaces (#829) 2024-10-25 10:43:29 -05:00
Steve Karg dcf79b038f Enabled BACnetARRAY checking when using proplist.c and added to apps/epics (#823) 2024-10-23 13:54:48 -05:00
Patrick Grimm b9de08cf60 Feature/router bsd (#821)
* fix router compile warnings declaration-after-statement overlength-strings

* router disable PRINT(debug_level)

* ports rename dlmstp_[linux|bsd] to dlmstp_port

* copy ports/linux/dlmstp_port.c ports/bsd/dlmstp_port.c

* copy ports/linux/dlmstp_port.c ports/bsd/dlmstp_port.c

* fix typedef in bip_get_local_address_ioctl

* copy ports/linux/dlmstp_port.c ports/bsd/dlmstp_port.c

* add bsd support for router app

* fix clang __attribute__ optimize dont work
clang O2/O3/Os are also not working

* fix pre-commit

* fix bsd SO_BINDTODEVICE is not available

* add brew install libconfig for app router and bsd

* fix BACDL_MSTP test on macOS

* remove old comments
2024-10-21 07:53:01 -05:00
Steve Karg f649e37bfa Fixed jquery.js used for syntax highlighting in PERL documentation (#817) 2024-10-18 13:20:42 -05:00
Steve Karg c3cb72bc41 Fixed BACNET_APPLICATION_DATA_VALUE declarations to be initialized so that the next pointer is NULL by default. (#814) 2024-10-18 07:43:39 -05:00
Steve Karg ac7dee0021 Issues/issue 811 mstpcap considers valid frames as invalid if used as a standalone tool (#812)
* Fixed mstpcap utility by setting This-Station to the MS/TP promiscuous mode address 255.

* Fixed MS/TP receive filter for valid data frames which was missing.

* Fixed MS/TP zero-config duplicate node detection

* Reset silence during MS/TP capture after writing packet to prevent endless packets when stream is interrupted.
2024-10-15 15:38:25 -05:00
Patrick Grimm b555e4a440 fix app router (#808)
with optimize Os the program exits with
bit out of range 0 - FD_SETSIZE on fd_set

Disable optimize for size by static set optimize 2

This Fix #793
2024-10-14 07:56:37 -05:00
Patrick Grimm a71d4b95eb Fix/router ipv6 test (#806)
* fix app router-ipv6: duplicate symbol
Makefile use Device_Object_Instance_Number from device-client.c (Device_Object_Instance_Number is not in bacnet.a from Makefile)

Cmake use Device_Object_Instance_Number from libbacnet-stac.a:device.c

This fix #778

* test ipv6
2024-10-14 07:55:04 -05:00
Steve Karg 3d86873346 Bugfix/read property multiple client errors (#765)
* Fixed variable data type for boolean in RPM structure.

* Fixed RPM error handling to use callback.

* Fixed bacrpm app example when not enough command line parameters are used

* Fixed empty-list EPICS printing.

* Fixed RPM-Ack processing for end of list-of-results

* Added minimal handling for segmentation-not-supported during RPM of object properties.
2024-09-21 09:26:09 -05:00
Kari Argillander f806c5829b Run clang-format and enable CI check for it (#755)
* 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>
2024-08-30 11:20:58 -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 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
Steve Karg eba1def58c Refactored required writable property function from epics app (#743) 2024-08-22 16:31:16 -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 032bf10994 Added mstpcap to apps/Makefile BSD build (#730) 2024-08-17 08:52:37 -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
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
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 be65abe159 Fixed unit test compiler warnings 2024-08-06 16:19:08 -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
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 00ab206075 * Changed header file include guards to unique namespace. Updated file headers comments with SPDX [issue #55] (#666) 2024-07-19 17:16:28 -05:00
Steve Karg 359995e4bc Remove Makefile debug from MSTPCAP build 2024-07-16 17:33:10 -05:00
Steve Karg d1fe878d4a Fixed MSTPCAP build by removing BACnet Library 2024-07-16 17:31:41 -05:00
GauiStori fda3cb5e82 Added set time callback with optional offset for BACnet TimeSynchronization services (#691) 2024-07-16 15:28:03 -05:00
Steve Karg aa9370004b Added example basic bitstring value object. (#668) 2024-06-05 11:03:42 -05:00
Steve Karg 52f3f08cb1 Bugfix/fix redundant compiler flags (#658)
* Improved GCC compiler flags in ARM, OS, and test builds. Removed redundant flags, and made them consistent across various builds.

* Fixed redundant redeclaration of various functions detected by change in compiler flags.

* Fixed string truncation warning in bip-init detected by change in compiler flags.

* Fixed some set-but-not-used variables by creating dummy functions instead of using macros.
2024-05-30 10:59:54 -05:00
Steve Karg 8eab077ebf Added function to determine if an object property is a BACnetARRAY. (#642)
* Added function to determine if an object property is a BACnetARRAY.  Added property test for BACnetARRAY members.
2024-05-15 13:25:44 -05:00
Steve Karg affb358139 Feature/add basic structured view object (#641)
* 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
2024-05-14 14:51:45 -05:00
Steve Karg 3222244e4e Updated to version 1.3.6 for release on 2024-05-12 Mother's Day! (#635)
* Updated to version 1.3.6 for release on 2024-05-12 Mother's Day!
2024-05-12 09:06:23 -05:00
Steve Karg 96222574f8 Bugfix/router mstp builds (#630)
* 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
2024-04-30 13:52:00 -05:00
Steve Karg 3eff297a48 added some help about decoding complex data in WriteProperty example app. (#627) 2024-04-27 12:42:08 -05:00
Steve Karg bb276e2431 Refactored all the sprintf to use snprintf instead. (#628) 2024-04-27 12:41:45 -05:00
Steve Karg 770be70688 Chore/bacnet-sc-unrelated-cleanup (#620)
* 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
2024-04-19 12:54:56 -05:00
Steve Karg 0cebc83d88 Enable example apps to bind to device 4194303 (#615) 2024-04-04 10:58:44 -05:00
Steve Karg 80c51a06e3 Secured the WPM and RPM service encoders (#604)
* Secured the WPM and RPM client service encoders.

* Fixed RPM and WPM apps when fail to encode request. 

* Fixed WPM app number of arguments checking.
2024-03-26 12:29:15 -05:00