Code Monkey home page Code Monkey logo

bacnet-stack's Introduction

BACnet open source protocol stack for embedded systems, Linux, and Windows
http://bacnet.sourceforge.net/

Welcome to the wonderful world of BACnet and true device interoperability!

About this Project
------------------

This BACnet library provides a BACnet application layer, network layer and
media access (MAC) layer communications services for an embedded system.

BACnet - A Data Communication Protocol for Building Automation and Control
Networks - see bacnet.org. BACnet is a standard data communication protocol for
Building Automation and Control Networks. BACnet is an open protocol, which
means anyone can contribute to the standard, and anyone may use it. The only
caveat is that the BACnet standard document itself is copyrighted by ASHRAE,
and they sell the document to help defray costs of developing and maintaining
the standard (just like IEEE or ANSI or ISO).

For software developers, the BACnet protocol is a standard way to send and
receive messages on the wire containing data that is understood by other BACnet
compliant devices. The BACnet standard defines a standard way to communicate
over various wires, known as Data Link/Physical Layers: Ethernet, EIA-485,
EIA-232, ARCNET, and LonTalk. The BACnet standard also defines a standard way
to communicate using UDP, IP and HTTP (Web Services).

This BACnet protocol stack implementation is specifically designed for the
embedded BACnet appliance, using a GPL with exception license (like eCos),
which means that any changes to the core code that are distributed get to come
back into the core code, but the BACnet library can be linked to proprietary
code without the proprietary code becoming GPL. Note that some of the source
files are designed as skeleton or example files, and are not copyrighted.

The text of the GPL exception included in each source file is as follows: 

"As a special exception, if other files instantiate templates or use macros or
inline functions from this file, or you compile this file and link it with
other works to produce a work based on this file, this file does not by itself
cause the resulting work to be covered by the GNU General Public License.
However the source code for this file must still be made available in
accordance with section (3) of the GNU General Public License."

The code is written in C for portability, and includes unit tests (PC based
unit tests). Since the code is designed to be portable, it compiles with GCC as
well as other compilers, such as Borland C++ or MicroChip C18.

The BACnet protocol is an ASHRAE/ANSI/ISO standard, so this library adheres to
that standard. BACnet has no royalties or licensing restrictions, and
registration for a BACnet vendor ID is free.

What the code does
------------------

The stack comes with unit tests that can be run in a command shell using the
test.sh script. The unit tests can also be run using individual .mak files.
They were tested on a Linux PC.

The BACnet stack was functionally tested using VTS (Visual Test Shell), another
project hosted on SourceForge, as well as various controllers and workstations.
Using the Makefile in the project root directory, a dozen sample applications
are created that run under Windows or Linux. They use the BACnet/IP datalink
layer for communication by default, but could be compiled to use BACnet 
Ethernet, ARCNET, or MS/TP.

Linux/Unix/Cygwin
$ make clean all

Windows
c:\> build.bat

The BACnet stack can be compiled by a variety of compilers.  The most common
free compiler is GCC (MinGW under Windows).  The makefiles use GCC by
default.  Makefile.b32 are written for the Borland C++ 5.5 compiler, and
projects are also included for Microsoft Visual Studio and Code::Blocks.

The demo applications are all client applications that provide one main BACnet
service, except the one server application.  Each application will accept 
command line parameters, and prints the output to stdout or stderr.  The client
applications are command line based and can be used in scripts or for 
troubleshooting.  The demo applications make use of environment variables to 
setup the network options.  See each individual demo for the options.

There are also projects in the ports/ directory for ARM7, AVR, RTOS-32, 
and PIC.  Each of those projects has a demo application for specific hardware.
In the case of the ARM7 and AVR, the makefile works with GCC compilers and
there are project files for IAR Embedded Workbench.

Project Documentation
---------------------

The project documentation is in the doc/ directory.  Similar documents are
on the project website at <http://bacnet.sourceforge.net/>.

Project Mailing List
--------------------

If you want to help this project, or have a problem getting it to work for
your device, or have a BACnet question, join the developers mailing list at:
http://lists.sourceforge.net/mailman/listinfo/bacnet-developers

I hope that you get your BACnet Device working!  If not, join us on the 
mailing list and we can help.

Steve Karg
Birmingham, Alabama USA
[email protected]

bacnet-stack's People

Contributors

skarg avatar stargieg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bacnet-stack's Issues

Router application doesn't appear to correctly handle local broadcasts?

If I fire off what I understand to be a local broadcast - an IAm message with no destination information in the NPCI, for example - the router application interprets the lack of destination information as being destined for network 0, which causes it to then issue a NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK message attempting to find network 0.

Here is the message I'm sending out:

image

And what I see is when this message gets passed to npdu_decode, it correctly checks to see if the control bit (5) is set or not and when it sees it is not, it zeros out our destination information:

/*Bit 5: Destination specifier where: */
        /* 0 = DNET, DLEN, DADR, and Hop Count absent */
        /* 1 = DNET, DLEN, and Hop Count present */
        /* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */
        /* DLEN > 0 specifies length of DADR field */
        if (npdu[1] & BIT5) {
            len += decode_unsigned16(&npdu[len], &dest_net);
            /* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */
            /* DLEN > 0 specifies length of DADR field */
            address_len = npdu[len++];
            if (dest) {
                dest->net = dest_net;
                dest->len = address_len;
            }
            if (address_len) {
                if (address_len > MAX_MAC_LEN) {
                    /* address is too large could be a malformed message */
                    return -1;
                }

                for (i = 0; i < address_len; i++) {
                    mac_octet = npdu[len++];
                    if (dest)
                        dest->adr[i] = mac_octet;
                }
            }
        }
        /* zero out the destination address */
        else if (dest) {
            dest->net = 0;
            dest->len = 0;
            for (i = 0; i < MAX_MAC_LEN; i++) {
                dest->adr[i] = 0;
            }
        }

Now when npdu_decode returns to process_msg, it attempts to find the appropriate destination:

    srcport = find_snet(msg->origin);
    destport = find_dnet(data->dest.net, NULL);
    assert(srcport);

    if (srcport && destport) {
        ....
    } else {
        /* request net search */
        return -1;
    }

This returns -1 since our destport cannot be found, which causes the NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK message to be sent.

Am I correct in assuming this is a bug? Would an appropriate fix be to detect that the incoming message is a broadcast message with no destination information, assume that means the message is a local broadcast and discard the message entirely (since local broadcasts by definition should not extend beyond the router?)

VS 2015

The "ports\win32\Microsoft Visual Studio 2015\Server" project needs "BACnet Demo Settings.props" which is missing.

Using router

I'm trying to use the router demo because it's actually very close to what I need (assuming ms/tp support works under linux; if it doesn't I will try to fix it). But something seems oddly wrong.

The help text says it takes

~/work/bacnet-stack/demo/router$ ./router
I am router
Usage: router <init_method> [init_parameters]

init_method:
-c, --config <filepath>
        initialize router with a configuration file (.cfg) located at <filepath>
-D, --device <dev_type> [params]
        initialize a <dev_type> device specified with
        [params]

but when you try to send in -c init.cfg it fails. There is no handling of a config file option in main.c and there is a forward declaration for bool read_config(char *filepath) that doesn't seem to exist anywhere in the project. Yet the docs say all demos have been tested.

What am I missing?

ReadRange Trendlog buffer

Hi,

I am trying to read some values from a buffer of a trend log using the demo/readrange/bacrr program. However, after the message "Received ReadRange Ack!", I get the result "{ }". I know there are records in the buffer and tried different positions/ranges and time stamps.

I couldn't further on find any solution to this problem in forums. Any idea why I get an empty result and how to possibly solve this?

Regards,

Bob

Static declaration of 'BACnet_Version' follows non-static declaration

Followed the instructions for the esp32 port of bacnet-stack. There are a few issues it seems:

  1. The list of .c files to copy over from src does not contain all the files listed.
  2. Compile error in VS Code using Platform IO: src\device.c:374:14: error: static declaration of 'BACnet_Version' follows non-static declaration
  3. Even with #define BITS-H there are warnings for all the BITx definitions in bits.h

As the esp32 port has been unchanged for 2 years it seems, it seems a bit behind. If anyone has been able to compile and run this bacnet-port on esp32 kindly share any steps you may have followed.

Thank you.

FreeBSD support

Is the BACnet stack designed for Linux only systems ? I tried to compile the project on FreeBSD 10 amd64 without success:

krmx@fbsd1064:~/bacnet-stack % gmake
gmake -s -C lib all
In file included from ../src/tsm.c:45:
In file included from ../include/datalink.h:61:
In file included from ../include/bip.h:32:
../ports/linux/net.h:85:10: fatal error: 'features.h' file not found
#include <features.h>   /* for the glibc version number */
         ^
1 error generated.
Makefile:219: recipe for target '../src/tsm.o' failed
gmake[1]: *** [../src/tsm.o] Error 1
Makefile:68: recipe for target 'library' failed
gmake: *** [library] Error 2

Is there any hope to see this portable across different UNIX systems or the stack will stay only for Linux based systems ?

Thanks

Compile problems

Hi, I have been looking for a readrange tool and you seem to provide one with your fork of the bacnet protocol stack.

So I have been trying to compile with "make clean demos" but there's errors. Here are the errors in the order I have encountered them and what I have done to try to fix the issues.

Problem #1
Wrong paths in ./demo/Makefile

Solution: The following paths started with ../../ changed them to ../ as bellow

BACNET_PORT_DIR = ../ports/${BACNET_PORT}
BACNET_INCLUDE = ../include
BACNET_OBJECT = ../demo/object
BACNET_HANDLER = ../demo/handler

Problem #2
Wrong BACNET_LIB_DIR path in ./demo/Makefile

Solution
Not sure if this is ok but since I couldnt find any libbacnet.a in your sources I changed the line to point to the lib folder from bacnet-stack-0.8.2


Problem #3
../demo/handler/s_ptransfer.c:50:9: warning: no previous prototype for ‘Send_Private_Transfer_Request’ [-Wmissing-prototypes]
main.c:35:20: fatal error: bacdef.h: No such file or directory

Solution
Not a clue what to do about this one, there are too many path errors in too many files and too many versions of bacdef.h....


Problem #4
../src/ucix.c:25:24: fatal error: uci_config.h: No such file or directory

Solution
Not a clue here either, what is an UCI? were can I get this file?

And there are a bunch of other path errors if we do a "make clean all"
Also, there is probably a bunch of other errors up ahead cause I havent been able to get past problem #3 yet.

Could you please help?

BACnet_stack.html is empty

I ran doxygen BACnet-stack.doxyfile and BACnet_stack.html continues to be empty. I set both HAVE_DOT = YES and CALLER_GRAPH = YES. Is there another way to load the docs to navigate through? html/main.html and html/tree.html do not exist.

ports/win32/net.h

ports/win32/net.h

line 47: can't find 'tcpipv6.h'

#ifndef IPPROTO_IPV6
// If the version of winsock does not by default include IPV6 then
// use the tech preview if it is avaliable.
#include <tpipv6.h>
#endif

Compile issue on Linux (Fedora 24 and raspian Jessy 2017)

Hi have been trying to compile but have struck an issue with the current master.
When I compile I get the following on any commit after 1b4cb0e
cc -pthread main.o ../../demo/object/device.o ../../demo/object/nc.o ../../demo/object/access_credential.o ../../demo/object/access_door.o ../../demo/object/access_point.o ../../demo/object/access_rights.o ../../demo/object/access_user.o ../../demo/object/access_zone.o ../../demo/object/credential_data_input.o ../../demo/object/bacfile.o -Wl,-L../../lib,-lbacnet,-lc,-lgcc,-lrt,-lm -o bacserv ../../demo/object/nc.o: In functionNotification_Class_Load_UCI_List':
nc.c:(.text+0x1e): undefined reference to ucix_get_option_int' ../../demo/object/nc.o: In function Notification_Class_Init':
nc.c:(.text+0xcb): undefined reference to ucix_init' nc.c:(.text+0x122): undefined reference to ucix_for_each_section_type'
nc.c:(.text+0x13d): undefined reference to ucix_get_option' nc.c:(.text+0x1b6): undefined reference to ucix_get_option'
nc.c:(.text+0x1da): undefined reference to ucix_get_option_int' nc.c:(.text+0x235): undefined reference to ucix_string_copy'
nc.c:(.text+0x253): undefined reference to ucix_get_option' nc.c:(.text+0x2d8): undefined reference to ucix_string_copy'
nc.c:(.text+0x31d): undefined reference to ucix_get_list' nc.c:(.text+0x537): undefined reference to ucix_cleanup'
../../demo/object/nc.o: In function Notification_Class_Write_Property': nc.c:(.text+0xb7a): undefined reference to ucix_init'
nc.c:(.text+0xe26): undefined reference to ucix_add_option' nc.c:(.text+0x1430): undefined reference to ucix_set_list'
nc.c:(.text+0x1441): undefined reference to ucix_commit' nc.c:(.text+0x144d): undefined reference to ucix_cleanup'
collect2: error: ld returned 1 exit status
Makefile:99: recipe for target 'bacserv' failed
`

When checkout 1b4cb0e compiles complete successfully

Any ideas on how to fix ?

Feature Request - ESP32 Port - New Data Types

Thanks for the esp32 port. Following the readme.txt, was able to successfully build the port. The port has AI and DO (BO). I want to add the remaining common data types (AO, BI, AV and BV). Can you help me implement these?

Please Help

I am to say a novice, but withstanding I've learnt a lot whilst developing my project, I have an Atmel 1284P currently running a Modbus RTU slave stack that works very nicely. I want to attempt to use the BACnet

stack over MSTP, Mac address and instance ID, baud etc will all be configured from a small config file on an SD card.
My current application is written using Arduino C (in visual studio), I have tried to create a simple Bacnet net test and tried to compile it, I cannot however get it to compile, I have modified the hardware.h file
#ifndef HARDWARE_H
#define HARDWARE_H

#if !defined(F_CPU)
/* The processor clock frequency */
#define F_CPU 7372800UL
#endif

#if defined(IAR_SYSTEMS_ICC) || defined(IAR_SYSTEMS_ASM)|| (ICCAVR)
#include <iom1284p.h>
#else
#if !defined(AVR_ATmega1284P)
#error Firmware is configured for ATmega1284 only (-mmcu=atmega1284p)
#endif
#endif
#include "iar2gcc.h"
#include "avr035.h"

#define LED_NPDU_INIT() BIT_SET(DDRD, DDD5)
#define LED_NPDU_ON() BIT_CLEAR(PORTD, PD5)
#define LED_NPDU_OFF() BIT_SET(PORTD, PD5)
/* #define LED_NPDU PORTD_Bit5 /
/
#define LED_NPDU_OFF() {LED_NPDU = false;} /
/
#define LED_NPDU_ON() {LED_NPDU = true;} */

#define LED_GREEN_INIT() BIT_SET(DDRD, DDD4)
#define LED_GREEN_ON() BIT_CLEAR(PORTD, PD4)
#define LED_GREEN_OFF() BIT_SET(PORTD, PD4)

#endif

And this is the main application with the includes, I haven't written any code yet I just want to get the Stack to compile first, can anybody help me out here?

#include <ai.h>
#include <av.h>
#include <avr035.h>
#include <bv.h>
#include <device.h>
#include <hardware.h>
#include <iar2gcc.h>
#include <rs485.h>
#include <stack.h>
#include <stdbool.h>
#include <stdint.h>
#include <timer.h>

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}

I just want to use Bacnet over MSTP that's it.

Regards

John

Bacnet Present Valu

Hi ,
I wish to embedded readproperty in my application.
I am looking for a function which can print out the present value.
Is there any way to do that. Thanks in advance.

Bacnet Router Functionality?

Hello, does this software provide bacnet router functionality (for example converting bacnet/ip to bacnet/mstp)?

COB encoded packets are off by one byte.

Here is the last five byte of a large ReadRange response:
0x50, 0xee, 0xe3, 0xbf, 0xe4
( 0xee, 0xe3, 0xbf, 0xe4 is the COB encoded -32K CRC)

Here is what the mstpcap sends to Wireshark:

( 0xee, 0xe3, 0x00, 0xbf, 0xe4 }

mstpcap appends an "artificial" zero thinking it is the end of the packet (length is length -2 for cob encoded frame)
and then appends the last two bytes for data CRC (it treat the packet as non cob packet)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.