Commit Graph

61 Commits

Author SHA1 Message Date
Steve Karg 380540635c Refactored BACnetShedLevel encoding, decoding, and printing into separate file. Added unit testing. (#1187)
* Refactored BACnetShedLevel encoding, decoding, and printing into separate file.  Added unit testing.

* Added API to load control object for shed-level, start-time, duty-window, full-duty-baseline, and enable.

* Fixed bacapp sprintf for shed level and host-n-port found in scan build.
2025-12-12 08:32:42 -06:00
Steve Karg e9dd910b55 Convert the property list values into int32_t to support the larger property values when an int is 8-bit or 16-bit. (#1145) 2025-11-16 08:34:45 -06:00
Steve Karg 4dd13cf199 Added basic timer object, internal state machine, and unit tests (#1123)
* Added basic timer object, internal state machine, and unit tests

* Added BACnetTimerStateChangeValue encode, decode, parse, print, and diff with unit tests

* Changed handler of add/remove list element to check if the property is a BACnetLIST

* Added BACnetLIST utility for handling WriteProperty to a list.

* Fixed outlier ReadProperty object handlers to return zero when the RP parameter is NULL.
2025-11-05 15:11:45 -06:00
Steve Karg 9b6173995c Fixed compiler warning format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=] by casting or increasing format specifier size and casting. (#1092)
* Fixed compiler warning format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=] by casting or increasing format specifier size and casting. Increased the size of the name string to handle larger possible integers.

* Fixed copied code that no longer needs static function scope variables for text names.
2025-09-12 15:08:47 -05:00
Steve Karg 4ee129e249 Added bypass in basic WriteProperty handler to accept writes of NULL to non-commandable properties (#919) 2025-03-10 07:30:55 -05:00
Steve Karg 7a5190f295 Fixed Who-Has object instance by checking for valid instance. (#922) 2025-02-20 17:29:39 -06:00
Steve Karg f8e9ab8d86 Changed link-speed, network-number, network-number-quality, and apdu-length properties of the network port object to be optional when protocol-revision is 24 or greater. (#913) 2025-02-13 08:44:30 -06:00
Steve Karg 7b9d6d7dc5 Fixed error-code returned when an object does not support WriteProperty but has properties that are known. (#912) 2025-02-12 16:54:40 -06:00
Steve Karg 66329a05a0 Bugfix/property array element zero size (#908)
* Changed BACnetARRAY index validation into ReadProperty, ReadPropertyMultiple, WriteProperty, and WritePropertyMultiple handlers.

* Changed the basic and example objects after refactoring BACnetARRAY index validation into ReadProperty, ReadPropertyMultiple, WriteProperty, and WritePropertyMultiple handlers.

* Added BACnet application decoder that understands that an array element of zero is an unsigned integer tagged value.  Fixes RP and RPM apps when reading the array element zero of arrays.
2025-02-10 09:44:53 -06:00
Steve Karg 19ef7f74cd Added MS/TP automatic baudrate detection option into the core MS/TP state machine. (#900) 2025-02-03 15:10:31 -06:00
Steve Karg b97f1705ce Systick Interrupt should never be activated using NVIC_EnableIRQ because it's an system exception (#850) 2024-11-06 08:17:23 -06: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
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
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 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 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 cb4f675e39 Reduced MS/TP MAX_APDU to use 480 by default in examples (#683)
* 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.
2024-07-02 12:47:15 -05:00
Steve Karg ddb2b43125 Refactor/mstp zero config state machine (#676)
* 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
2024-06-26 07:43:25 -05:00
Steve Karg 4a7b7763c2 Feature/add memap cstack usage ports (#661)
* Added memap, avstack, and checkstackusage tools to STM32F4xx Makefile and CMake builds to calculate CSTACK depth and RAM usage

* Added memap, cstack, and ram-usage recipes to stm32f10x port Makefile.  Added Cmake build.

* Removed local dlmstp.c module from stm32f10x port, and used the common datalink dlmstp.c module with MS/TP extended frames and zero-config support.

* Added .nm and .su to .gitignore to skip the analysis file residue.
2024-05-31 14:39:25 -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 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 1520f2c612 Add core stack headers into bacdef.h and cleanup includes. (#602)
* 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.
2024-03-15 16:58:52 -05:00
Ondřej Hruška 340bd09561 Implement missing data types for calendar and schedule (#474)
* Added the SpecialEvent struct for the Exception_Schedule property of Schedule, encode/decode/same functions, unit tests, and integrated into bacapp functions.

* Added the CalendarEntry struct for the Date_List property of Calendar and the SpecialEvent struct, encode/decode functions, unit tests, and integrated into bacapp functions.

* Added the DateRange struct for the Effective_Period property of Schedule, encode/decode functions, unit tests, and integrated into bacapp functions.

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2024-02-01 10:57:46 -06:00
Steve Karg 587e3c5a11 Chore/refactor automac unit test (#557)
* move ports automac module into bacnet/datalink and add unit test.
2024-01-12 16:14:24 -06:00
Steve Karg e1efca9d9e Fix MSTP slave FSM for Data-Expecting-Reply frames (#538)
* Fix MSTP subordinate nodes Data-Expecting-Reply handling

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-11-20 19:08:28 -06:00
Steve Karg 1372e52aa7 Feature/mstp extended frames (#529)
* added MSTP extended frames to bacnet/datalink/mstp.c module. Thank you, Simon!

* auto-size some FIFO buffers for MSTP

* add COBS library to MSTP builds

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-11-08 15:54:18 -06:00
Steve Karg 0b5474d36e Ignore ReinitializeDevice and DeviceCommunicationControl service password (#518)
* Fix device object ReinitializeDevice service handling examples of no-password in the device. Add unit testing of device object ReinitializeDevice service.  Add API for setting ReinitializeDevice device object password.

* Fix DeviceCommunicationControl service handling example of no-password in the device.

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-10-18 21:32:44 -05:00
Steve Karg 0001f85f29 Bugfix/network port object link speeds (#488)
* fix ports/xplained build under Linux

* fix network port object link-speeds property

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-09-08 17:41:56 -05:00
Steve Karg 2b35883df6 Added MSTP Slave Node option to stm32f10x port (#467)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-08-07 09:45:30 -05:00
Steve Karg 7db03ac5e5 Fix spurious interrupts from STM32 ORE (#456)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-07-17 13:49:40 -05:00
Steve Karg ced9dff0f2 Added AddListElement and RemoveListElement services (#418)
* Added AddListElement and RemoveListElement services

Added list-element codec and unit tests.
Added BACnetDestination codec and unit tests.
Added RecipientList handling to NotificationClass object.
Added AddListElement and RemoveListElement client example app.

* Fix defects found by scan-build and CPPCHECK

* Update ports errors found during CI builds

* Update zephy os test build missing files in CMakeLists

---------

Co-authored-by: Ondřej Hruška <ondra@ondrovo.com>
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-04-16 14:12:11 -05:00
Steve Karg e517df0d47 Bugfix/bacnet array encoding overflows (#414)
* Add common BACnetARRAY encode function to fix Device object list buffer overflow. Refactor device, analog-output, access-door and binary-output objects to use common BACnetARRAY encoder.

* Fix non-POSIX builds (win32).

* Cleanup some ports/stm32 build warnings
---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-04-13 20:43:54 -05:00
Steve Karg 261a506eb4 refactor mstimer callback handling (#400)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-02-18 10:02:13 -06:00
Steve Karg b91735af13 Bugfix/code clean using gcc warnings (#371)
* Enable extra GCC warnings to discover subtle bugs

* convert c++ comments to c comments

* cleanup pedantic compiler warnings

* Compile apps with GNU89 GNU99 GNU11 and GNU17

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-12-25 21:43:51 -06:00
Ondřej Hruška 7cdab61d72 Schedule encoding/decoding (#319)
* schedule: add decode_daily_schedule() and encode_daily_schedule()

* schedule: encode/decode implemented + add to bacapp

* add safe encode/decode functions for timevalue, schedule function renaming

* fix unit tests build failing

* add IDEA and test temporary files to .gitignore

* try to make "deprecated" work in MSVC

* add WeeklySchedule compare function

* add bacnet_weeklyschedule_context_decode()

* Add basic test for WeeklySchedule

* Fix WeeklySchedule parsing and snprintf, decoder verified with real hardware

* try to fix windows build

* improve boolean parsing in 'bacapp_parse_application_data'

* add parse function for weekly schedule

* allow types > 16 in bacwp, show the decoded value before sending

* add bacapp binaries to gitignore

* remove bacwp logging

* Add error checking to bacapp_parse_application_data

* try to fix windows build

* fix avr build

* Fix error handling in RP Ack

* add singleDay flag

* show day name in single day weeklyschedule snprintf

* show weeklyschedule inner tag in snprintf

* improve weeklyschedule parsing and printing, supports type names now

* add weekly schedule to bacapp_decode_data

* move bacnet/bacnet_plat_compat.h to bacnet/basic/sys/platform.h

* disable tag limit also in bacwpm

* add ifdef's around strtoX helper functions in bacapp

* move strtox to BACAPP_PRINT_ENABLED ifdef in bacapp

* fix stm32 makefiles

* fix at91sam7s build

* use BACNET_UNSIGNED_INTEGER in BACnet_Short_Application_Data_Value

* fix capitalization in BACnet_Daily_Schedule

* add name to BACNET_TIME_VALUE struct

* change bacwp bacwpm to use bacapp_known_property_tag()

* fix some macros in bacdcode missing parentheses

* Remove dummy fields from BACNET_SHORT_APPLICATION_DATA_VALUE, replace remaining uses of upcasting (adds extra overhead but is maybe safer), rename short DV to Primitive

* fix new ci warnings

* more fixes for ancient C

* fix tests no longer building

* primitive value renamed to shorter name
2022-09-05 09:27:15 -05:00
Steve Karg 1f41341c09 Feature/what is network number handling (#304)
* Add What-Is-Network-Number handling.

Add What-Is-Network-Number and Network-Number-Is network layer handling.
Refactor npdu_encode_npdu_network() from router specific code.
Add unit test for NDPU network message
Add app for What-Is-Network-Number
Add app for Network-Number-Is
Add send helper for What-Is-Network-Number
Add send helper for Network-Number-Is

* added sys/debug.c to ports builds for use of debug_printf() in npdu handler.

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-07-14 15:34:45 -05:00
Steve Karg 38d213b47c Feature/color objects color command (#302)
* added BACnetColorCommand and BACnetxyColor encoding and unit testing

* Added Color object and unit testing.

* Added Color Temperature object and Unit test

* Fix BVLC unit test warning.

* add port Makefile for extra types

* added RGB to and from CIE xy utility in sys folder, and add unit tests.

* added cmake-win32 target

* Change RP and RPM to use known property decoder.

Add color object RP and RPM decoding and printing
Fix RPM print for new reserved range above 4194303
Change default protocol-revision to 24 for Color object

* Integrate Color and Color Temperature objects into demo apps

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-07-13 09:54:36 -05:00
Steve Karg f147283293 Feature/apdu null length returned (#285)
* Add APDU as NULL to get BACnet type lengths.

* Fix bacapp copy test to succeed

* fix BACnet REAL and DOUBLE decode

* Add unit test for NULL APDU encoding for length

* Add unit tests for bacapp context

* refactor host-n-port to hostnport.c module

* fix BVLC decoder

* additional unit testing for bacapp

* include bacdevobjpropref module in builds

* simplify bacapp snprintf to be able to return length

* adjust compiler for variable-length arrays

* fix bug found by scan-build

Authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-06-01 15:42:50 -05:00
Steve Karg 46e838aeb4 fix BACnet application defines for STM32 IAR project (#267)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-05-05 11:03:44 -05:00
Steve Karg fa42e07ffd add missing bigend.c file to IAR project (#266)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-05-05 10:36:57 -05:00
Steve Karg 12a5e48b3e Bugfix/btl mstp local broadcast discard (#248)
* Discard Confirmed PDU DNER on local broadcast. Discard DER on local broacast.

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-04-02 08:44:04 -05:00
Nick Schaf b31cb43e22 Avoid redefining MSTP timeouts (#230)
* Avoid redefining MSTP timeouts

* Remove duplicate MS/TP time definitions

Ports of MS/TP datalink included #defines of several time values, which
were already defined in src/bacnet/datalink/mstpdef.h.  All those ports
already include that header.
2022-02-26 08:58:57 -06:00
Steve Karg 295f127c2b Feature/makefile add apps library (#218)
* add BACnet stack library at apps/lib

* convert apps to use apps/lib for smaller binary

* fix -DBACDL_ALL=1 build

* fix piface build

* datalink MAX_MPDU and MAX_HEADER cleanup

* add bip6 to git workflow

* fix system library dependency of BACnet library

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-01-29 15:55:40 -06:00
Steve Karg 810a2f93de Feature/write property type check refactor (#182)
* refactor write-property tag check

* modify ports objects to use write-property tag check API

* modify example objects to use write-property tag check API

* Fix object unit test builds

* Fix and run unit ztests via CMake

* Enable unit testing on Travis CI

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2021-06-23 10:10:12 -05:00
Steve Karg 7cb63dcf06 RP and RPM Network Port indefinite object instance (#146)
* RP and RPM Network Port indefinite object instance

Added ReadProperty and ReadPropertyMultiple handling for
Network Port object indefinite object instance 4194303.

* Add network port object to some examples

* Fix stm32f10x build

* Fix Endian order of network port IP UDP port

* Add network port object to BDK Makefile

* Add network port object header to BDK device.c

* fix BDK and AT91SAM7S port builds

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2021-01-07 10:21:11 -06:00
Steve Karg 84bfdb6c9d Fix STM32F10x CMSIS ASM for newer compilers (#137)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-10-30 12:04:32 -05:00
Carlos Gomes Martinho 981d4036c8 refactor: rename test macro to prevent collisions (#91)
* refactor: rename test macro to prevent collisions

* style: align cmake epilog

* refactor: rename define in makefiles
2020-05-28 08:55:05 -05:00
Steve Karg cbfa74e48d Bugfix/bacnet real endian simplify (#89)
* Remove dependence on endian define

* Make use of existing big_endian function if BACNET_BIG_ENDIAN is not defined

* Add efficient endian macro option if available

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-05-24 09:36:21 -05:00