Commit Graph

54 Commits

Author SHA1 Message Date
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
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
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 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 734321a974 Moved timesync offset get/set from handler to ports to fix projects not using handler (#699) 2024-07-16 17:30:38 -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 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 06ff987b79 Issues/issue 632 invoke id mismatch (#633)
Fixed nuisance print messages in ports/linux/dlmstp by changing to debug print only.
2024-05-07 06:58:26 -05:00
Steve Karg bb276e2431 Refactored all the sprintf to use snprintf instead. (#628) 2024-04-27 12:41:45 -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
Steve Karg 5c55683f86 Fixed makefile for building the Linux router application. (#585)
* Fixed Makefile for building the Linux router application.
2024-02-28 17:08:00 -06:00
Steve Karg 89fa3cea77 Fixed the Network Port object subnet mask for IP example. (#573) 2024-02-13 14:15:59 -06:00
Steve Karg 1f591db6e7 Feature/mstp zero config option (#564)
* Added a MS/TP zero-config (automatically choose an unused MAC address) using an algorithm that starts with MAC=64 and waits for a random number of PFM (minimum of 8 plus modulo 64) before attempting to choose a MAC sequentially from 64..127. The confirmation uses a 128-bit UUID with the MSTP Test Request frame. The modifications are in src/bacnet/datalink/mstp.c and src/bacnet/datalink/dlmstp.c modules enabling any device to use zero-config if enabled. A working demonstration is in the ports/stm32f4xx for the NUCLEO board. Complete unit testing is included.  Options include lurking forever (wait for a router or another master node before joining) or lurking for a minimum time (enables self forming automatic MAC addressing device nodes).
2024-02-02 11:18:20 -06:00
Steve Karg cc84a16c14 Removed rx_fsm.c example which duplicated MSTPCAP features (#544)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-12-09 11:42:14 -06:00
Steve Karg 3c94580bee Added MSTP extended frame transmit. (#531)
* Added MSTP extended frame transmit to bacnet/datalink/mstp.c and ports/stm32f4xx/dlmstp.c modules.

* Changed RS485_Send_Frame to MSTP_Send_Frame in mstp.c

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-11-12 09:49:37 -06:00
Steve Karg 75286cffe4 Bugfix/linux bip so bindtodevice error (#498)
* disable extraneous SO_BINDTODEVICE warning in Linux BIP

---------

Co-authored-by: Steve Karg <steve.karg@legrand.us>
2023-09-14 11:09:11 -05:00
Steve Karg 55b8b3d93c fix BACnet/IP on OS to bind broadcast to specific port (#489)
* Fixes #346 by binding the broadcast socket to the port specific broadcast address rather than INADDR_ANY or INADDR_BROADCAST. Added additional compile and environment options for those who might need them. 

* Changed the define USE_CLASSADDR to BACNET_IP_BROADCAST_USE_CLASSADDR to help manage namespaces.

* Added BACNET_IP_BROADCAST_BIND_ADDR environment variable to override the default broadcast binding address.

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-09-10 10:24:18 -05:00
Steve Karg 4efaf097c0 Fix [bug#80] npdu_decode via deprecation (#447)
* Fix [bug#80] npdu_decode via deprecation

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-07-10 17:27:10 -05:00
Jefrin da8f93ad79 Fix segfault on mstp cleanup on linux port (#445) 2023-07-08 09:47:50 -05:00
Steve Karg 9bb367982b Improve MSTP debug. Fix WhoIs app APDU timeout. 2023-06-25 09:27:05 -05: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
Patrick Grimm 8e6b3fafab Feature/bacnet ipv6 bind interface for link local comunication (#359) 2022-11-20 14:29:11 -06:00
Steve Karg 70c290d1ad Feature/bacnet ipv6 foreign device registration (#355)
* Added IPv6 Foreign Device Registration for apps

* Fix debug message in BACnet/IPv6 Linux port

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-11-17 08:14:33 -06:00
Alexander Wells 5b30674215 Provide getter for broadcast BIP socket (#350) 2022-10-24 13:44:42 -05:00
Steve Karg a07e9ebebf simplified mstimer_now for BSD, Windows, and Linux ports. (#309)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-07-19 10:57:25 -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
Greg Shue 085de3c385 Merge pull request #275 from Michail-Antropov/OSCBS-23-Scalable-BACnet-object-arrays-2
Oscbs 23 scalable ba cnet object arrays - variant 2
2022-07-11 09:57:14 -07:00
Mikhail Antropov 144017f861 BIP: add option - listen to broadcast on a separate socket (#293)
* BIP: add socket to listen to broadcast packets for Linux/Windows/BSD/Zephyr

* BIP: added BVLC broadcast handler to drop a packet when confirmed broadcast request is sent.

* https://sourceforge.net/p/bacnet/bugs/65/
2022-07-01 09:48:41 -05:00
Mikhail Antropov 23fb2394c5 OSCBS-23 Fix PR#1 2022-06-16 19:45:00 +03:00
Mikhail Antropov adbbbeef64 OSCBS-23 Add backport.h for all ports
BACNET_OBJECT_TABLE will be use in zephyr port for create iterable section
2022-06-15 09:52:52 +03:00
Ondřej Hruška 0dec80fae7 Add functions to enable/disable debug logging (#280)
* Add "bip_debug_disable()"

* Add "bvlc_debug_disable()"

* Add setters for BIP_DL_Debug (BBMD registration debug logging)
2022-05-25 21:43:08 -05: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
Alexander Wells ca32676662 Add bip_get_socket (#210)
* Add function to get BIP socket

* Add bip_get_socket to all applicable ports
2022-01-10 10:15:54 -06:00
Steve Karg 889b7f9357 Feature/bip6 debug enable (#209)
* Added BACNET_BIP6_DEBUG environment variable to enhance BACnet/IPv6 debugging

* Added BACNET_BIP6_DEBUG environment variable to enhance BACnet/IPv6 debugging

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-01-08 11:34:11 -06:00
Steve Karg 3ed77e2491 DSR-1471: fixes data race issues on ring buffer for MSTP (#9) (#174)
* DSR-1471: fixes data race issues on ring buffer

* DSR-1471: added missing semi-colon

Co-authored-by: Fraser Gordon <51318560+FraserG01@users.noreply.github.com>
2021-05-24 18:53:59 -05:00
Steve Karg 63e4fa1f4b fixes #141 Linux BIP with no default gateway (#144)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-12-21 13:07:24 -06:00
Michael Francis cb9b166515 Replace "bits/pthreadtypes.h" include with <sys/types.h> in /ports/linux/dlmstp_linux.h (#139)
This resolves #129 by making this file able to be built on Alpine Linux
2020-11-20 21:38:27 -06:00
Steve Karg 762ffacc8e Bug#72 reading zero bytes in linux BIP. Thanks, Mikhail! (#132)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-10-10 10:45:12 -05:00
Roy Schneider 764e0e8448 Feature/zeroing rx buffer remain (#90)
* Added zeroing rx buffer remain

* Added zeroing rx buffer remain

* Added safety margin for the rx-buffer in the different ports.

* Added safety margin for the receive buffer.

* Added DoxyGen comments.

* Fixed checking return value when calculating distance between opening and closing tag on multiple properties.
2020-05-24 09:19:52 -05:00
Steve Karg fdd49f1791 Feature/make pretty apps and ports (#80)
* Added pretty-apps and pretty-ports make targets

* pretty-fied apps folder C files

* Pretty-fied ports folder C and H files

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-04-30 10:13:11 -05:00
Steve Karg dbbcec3033 Feature/bacnet ipv4 default iface linux (#75)
* Added default IFACE for IPv4 on Linux

* fix potential leak of memory found by scan-build

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-04-16 15:55:38 -05:00
Roy Schneider 8f13d59629 Feature/comments and buffer checks (#73)
* Added comments

* Replaced Goto construct

* Added apdu_len check

* Added comments

* Added string limit and reworked printable check

* Mainly comments

* Just comments

* Just comments

* decode service request returns now non zero on success

* eliminated warnings

* Added character string init with length check.

* Paranoic length check

* Comments and object index checking on read/write.

* Check name/desc strings before returning.

* Eliminated Goto
2020-04-16 10:38:49 -05:00
Steve Karg eedfa58a55 Feature/refactor bacnet ipv4 add unit tests (#64)
* refactor BACnet/IPv4 BVLC into encode-decode library with unit tests
Added Read-Broadcast-Distribution-Table encoding and unit test.
Added Read-Broadcast-Distribution-Table-Ack encoding and unit test.
Added Read-Foreign-Device-Table-Ack encoding and unit test.
Added some BDT/FDT diff copy functions with unit tests
Added some FDT add and delete entry functions with unit tests
Added some BDT set append and clear entry functions with unit tests
Added some BIPv4 address conversion functions with unit tests
Added non-BBMD handling unit test
Added basic unit test for BBMD handler
Added BBMD broadcast mask get set and unit tests
Added IPv6 maintenance timer.
Added ReadFDT app
Fixed ReadBDT app
Added Who-Is to Makefile for individual app build
Fixed debugging code blocks projects by swapping bip.c for h_bbmd.c module.
Ported BACnet/IPv4 to refactored BVLC for Linux, BSD, Windows
Fix datalink debug for DLENV module
Improve BIPv4 linux driver debug info
Added BDT mask functions
Reduce debug info clutter in Who-Is app by using environment option
Fix TTL seconds upper bounds addition
Fix CIDR prefix calculation on Linux BIPv4.
Convert BSD BIPv4 to BVLCv4
Fix CMake build for BIPv4 (Linux, BSD, Windows)
Added [U]nsigned to 0xBAC0 constants
Cleanup POSIX and Win32 API sockets
Remove unnecessary file scope variable initialization
Fix routed NPDU to depend on datalink; fix warning
Remove OS dependent network code from gateway
Enable BBMD client in library by default
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
Co-authored-by: Steve Karg <steve.karg@legrand.us>
2020-04-04 11:31:54 -05:00
Steve Karg f18612f1ec Fix mstimer elapsed time (#58)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-03-17 17:27:25 -05:00
Steve Karg 81d3a0b4a4 fix BVLC6 Delete-Foreign-Device-Table-Entry (#56)
* fix BVLC6 Delete-Foreign-Device-Table-Entry

* Add unit test failure detection to Makefile report target

* Fix the IPv6 layers for sending PDU

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-03-12 12:24:07 -05:00
Anonymous Maarten 4a916468c6 Export symbols in order to support shared libraries (#54)
* Add BAC_ROUTING compile definition

* Reorder cmake

* Fix OpenSSL support: support both 1.0 and 1.1t pus

* Explicitly export symbols, hidden by default

* Build shared libraries on travis using cmake

* Learn Makefile about static library

* Fix build using mingw with cmake

* Do not cleanup twice or after potential free
2020-03-06 15:42:03 -06:00
Steve Karg bb5fafc06a feat remove openssl dependency functions and add missing file to cmake (#52)
* feat: remove openssl dependency functions and add missing file to cmake

* chore: also build shared lib

* chore: also build shared for github ci

* chore: do not test shared libs in ci for the moment
2020-03-04 13:35:14 -06:00
Steve Karg 9c41180145 Add ifdef to bit definitions to avoid conflicts with other libraries. Refactor BITx to use BIT macro. (#45) 2020-02-18 08:21:54 -06:00
Geert Linders 76abcaedd1 Reduce Tusage_timeout for all ports. (#37) 2020-01-22 17:07:44 -06:00