Release BACnet Protocol Stack 0.3.0
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
#
|
||||
# Simple makefile to build an RTB executable for RTOS-32
|
||||
#
|
||||
# This makefile assumes Borland bcc32 development environment
|
||||
# on Windows NT/9x/2000/XP
|
||||
#
|
||||
|
||||
!ifndef BORLAND_DIR
|
||||
BORLAND_DIR_Not_Defined:
|
||||
@echo .
|
||||
@echo You must define environment variable BORLAND_DIR to compile.
|
||||
!endif
|
||||
|
||||
PRODUCT = bacnet
|
||||
PRODUCT_EXE = $(PRODUCT).exe
|
||||
|
||||
# Choose the Data Link Layer to Enable
|
||||
DEFINES = -DBACDL_BIP=1;TSM_ENABLED=1;BIG_ENDIAN=0
|
||||
|
||||
SRCS = main.c bip-init.c \
|
||||
..\..\bip.c \
|
||||
..\..\demo\handler\h_iam.c \
|
||||
..\..\demo\handler\h_whois.c \
|
||||
..\..\demo\handler\h_wp.c \
|
||||
..\..\demo\handler\h_rp.c \
|
||||
..\..\demo\handler\h_rp_a.c \
|
||||
..\..\demo\handler\noserv.c \
|
||||
..\..\demo\handler\txbuf.c \
|
||||
..\..\demo\handler\s_rp.c \
|
||||
..\..\demo\handler\s_whois.c \
|
||||
..\..\bacdcode.c \
|
||||
..\..\bacapp.c \
|
||||
..\..\bacstr.c \
|
||||
..\..\bactext.c \
|
||||
..\..\indtext.c \
|
||||
..\..\bigend.c \
|
||||
..\..\whois.c \
|
||||
..\..\iam.c \
|
||||
..\..\dcc.c \
|
||||
..\..\rp.c \
|
||||
..\..\wp.c \
|
||||
..\..\arf.c \
|
||||
..\..\awf.c \
|
||||
..\..\demo\object\bacfile.c \
|
||||
..\..\demo\object\device.c \
|
||||
..\..\demo\object\ai.c \
|
||||
..\..\demo\object\ao.c \
|
||||
..\..\demo\object\av.c \
|
||||
..\..\demo\object\bi.c \
|
||||
..\..\demo\object\bo.c \
|
||||
..\..\demo\object\bv.c \
|
||||
..\..\demo\object\lsp.c \
|
||||
..\..\demo\object\mso.c \
|
||||
..\..\datalink.c \
|
||||
..\..\tsm.c \
|
||||
..\..\address.c \
|
||||
..\..\abort.c \
|
||||
..\..\reject.c \
|
||||
..\..\bacerror.c \
|
||||
..\..\apdu.c \
|
||||
..\..\npdu.c
|
||||
|
||||
OBJS = $(SRCS:.c=.obj)
|
||||
|
||||
# Compiler definitions
|
||||
#
|
||||
BCC_CFG = bcc32.cfg
|
||||
CC = $(BORLAND_DIR)\bin\bcc32 +$(BCC_CFG)
|
||||
#LINK = $(BORLAND_DIR)\bin\tlink32
|
||||
LINK = $(BORLAND_DIR)\bin\ilink32
|
||||
TLIB = $(BORLAND_DIR)\bin\tlib
|
||||
|
||||
#
|
||||
# Include directories
|
||||
#
|
||||
CC_DIR = $(BORLAND_DIR)\BIN
|
||||
INCL_DIRS = -I$(BORLAND_DIR)\include;..\..\;..\..\demo\handler\;..\..\demo\object\;.
|
||||
|
||||
CFLAGS = $(INCL_DIRS) $(CS_FLAGS) $(DEFINES)
|
||||
|
||||
# Libraries
|
||||
#
|
||||
C_LIB_DIR = $(BORLAND_DIR)\lib
|
||||
|
||||
LIBS = $(C_LIB_DIR)\IMPORT32.lib \
|
||||
$(C_LIB_DIR)\CW32MT.lib
|
||||
|
||||
#
|
||||
# Main target
|
||||
#
|
||||
# This should be the first one in the makefile
|
||||
|
||||
all : $(BCC_CFG) $(PRODUCT_EXE)
|
||||
|
||||
# Linker specific: the link below is for BCC linker/compiler. If you link
|
||||
# with a different linker - please change accordingly.
|
||||
#
|
||||
|
||||
# need a temp response file (@&&) because command line is too long
|
||||
$(PRODUCT_EXE) : $(OBJS)
|
||||
@echo Running Linker for $(PRODUCT_EXE)
|
||||
$(LINK) -L$(C_LIB_DIR) -m -c -s -v @&&| # temp response file, starts with |
|
||||
$(BORLAND_DIR)\lib\c0x32.obj $** # $** lists each dependency
|
||||
$<
|
||||
$*.map
|
||||
$(LIBS)
|
||||
| # end of temp response file
|
||||
|
||||
#
|
||||
# Utilities
|
||||
|
||||
clean :
|
||||
@echo Deleting obj files, $(PRODUCT_EXE) and map files.
|
||||
del *.obj
|
||||
del ..\..\*.obj
|
||||
del ..\..\demo\handler\*.obj
|
||||
del ..\..\demo\object\*.obj
|
||||
del $(PRODUCT_EXE)
|
||||
del *.map
|
||||
del $(BCC_CFG)
|
||||
|
||||
#
|
||||
# Generic rules
|
||||
#
|
||||
.SUFFIXES: .cpp .c .sbr .obj
|
||||
|
||||
#
|
||||
# cc generic rule
|
||||
#
|
||||
.c.obj:
|
||||
$(CC) -o$@ $<
|
||||
|
||||
# Compiler configuration file
|
||||
$(BCC_CFG) :
|
||||
Copy &&|
|
||||
$(CFLAGS)
|
||||
-c
|
||||
-y #include line numbers in OBJ's
|
||||
-v #include debug info
|
||||
-w+ #turn on all warnings
|
||||
-Od #disable all optimizations
|
||||
#-a4 #32 bit data alignment
|
||||
#-M # generate link map
|
||||
#-ls # linker options
|
||||
#-WM- #not multithread
|
||||
-WM #multithread
|
||||
-w-aus # ignore warning assigned a value that is never used
|
||||
-w-sig # ignore warning conversion may lose sig digits
|
||||
| $@
|
||||
|
||||
# EOF: makefile
|
||||
Binary file not shown.
@@ -0,0 +1,460 @@
|
||||
# Microsoft Developer Studio Project File - Name="bacnet" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=bacnet - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "bacnet.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "bacnet.mak" CFG="bacnet - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "bacnet - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "bacnet - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "bacnet - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\.." /I ".." /I "..\..\..\demo\object\\" /I "..\..\..\demo\handler\\" /D "NDEBUG" /D "BACDL_BIP" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D TSM_ENABLED=1 /D BACAPP_PRINT_ENABLED=1 /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "bacnet - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\.." /I ".." /I "..\..\..\demo\object\\" /I "..\..\..\demo\handler\\" /D "_DEBUG" /D BACDL_BIP=1 /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D TSM_ENABLED=1 /D PRINT_ENABLED=1 /D BIG_ENDIAN=0 /D USE_INADDR=0 /FR /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "bacnet - Win32 Release"
|
||||
# Name "bacnet - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\abort.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\address.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\ai.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\ao.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\apdu.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\arf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\av.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bacapp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bacdcode.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bacerror.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\bacfile.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bacstr.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bactext.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\bi.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bigend.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE="..\bip-init.c"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bip.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\bo.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\bv.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\crc.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\datetime.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\dcc.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\device.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\h_arf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\h_arf_a.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\h_iam.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\h_rp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\h_rp_a.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\h_whois.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\h_wp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\iam.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\indtext.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\lc.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\lc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\lsp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\lsp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\main.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\mso.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\noserv.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\npdu.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\reject.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\ringbuf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\rp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\s_rp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\s_whois.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\s_wp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\tsm.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\handler\txbuf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\whois.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\wp.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\abort.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\address.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\ai.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\ao.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\apdu.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\arcnet.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bacapp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bacdcode.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bacdef.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bacenum.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bacerror.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\bacfile.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bacstr.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bactext.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bigend.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bip.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bits.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\bo.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\bv.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\bytes.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\config.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\crc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\datalink.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\datetime.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\device.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\ethernet.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\handlers.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\iam.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\demo\object\mso.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\mstp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\npdu.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\reject.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\ringbuf.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\rp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\rs485.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\stdbool.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\stdint.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\tsm.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\whois.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\wp.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "bacnet"=".\bacnet.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,136 @@
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1>Build Log</h1>
|
||||
<h3>
|
||||
--------------------Configuration: bacnet - Win32 Debug--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
Creating temporary file "C:\DOCUME~1\stk01\LOCALS~1\Temp\RSP862.tmp" with contents
|
||||
[
|
||||
/nologo /MLd /W3 /Gm /GX /ZI /Od /I "..\..\.." /I ".." /I "..\..\..\demo\object\\" /I "..\..\..\demo\handler\\" /D "_DEBUG" /D BACDL_BIP=1 /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D TSM_ENABLED=1 /D PRINT_ENABLED=1 /D BIG_ENDIAN=0 /D USE_INADDR=0 /FR"Debug/" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
|
||||
"C:\code\bacnet-stack\bacapp.c"
|
||||
"C:\code\bacnet-stack\bacdcode.c"
|
||||
]
|
||||
Creating command line "cl.exe @C:\DOCUME~1\stk01\LOCALS~1\Temp\RSP862.tmp"
|
||||
Creating temporary file "C:\DOCUME~1\stk01\LOCALS~1\Temp\RSP863.tmp" with contents
|
||||
[
|
||||
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/bacnet.pdb" /debug /machine:I386 /out:"Debug/bacnet.exe" /pdbtype:sept
|
||||
".\Debug\abort.obj"
|
||||
".\Debug\address.obj"
|
||||
".\Debug\ai.obj"
|
||||
".\Debug\ao.obj"
|
||||
".\Debug\apdu.obj"
|
||||
".\Debug\arf.obj"
|
||||
".\Debug\av.obj"
|
||||
".\Debug\bacapp.obj"
|
||||
".\Debug\bacdcode.obj"
|
||||
".\Debug\bacerror.obj"
|
||||
".\Debug\bacfile.obj"
|
||||
".\Debug\bacstr.obj"
|
||||
".\Debug\bactext.obj"
|
||||
".\Debug\bi.obj"
|
||||
".\Debug\bigend.obj"
|
||||
".\Debug\bip-init.obj"
|
||||
".\Debug\bip.obj"
|
||||
".\Debug\bo.obj"
|
||||
".\Debug\bv.obj"
|
||||
".\Debug\crc.obj"
|
||||
".\Debug\datetime.obj"
|
||||
".\Debug\dcc.obj"
|
||||
".\Debug\device.obj"
|
||||
".\Debug\h_arf.obj"
|
||||
".\Debug\h_arf_a.obj"
|
||||
".\Debug\h_iam.obj"
|
||||
".\Debug\h_rp.obj"
|
||||
".\Debug\h_rp_a.obj"
|
||||
".\Debug\h_whois.obj"
|
||||
".\Debug\h_wp.obj"
|
||||
".\Debug\iam.obj"
|
||||
".\Debug\indtext.obj"
|
||||
".\Debug\lc.obj"
|
||||
".\Debug\lsp.obj"
|
||||
".\Debug\main.obj"
|
||||
".\Debug\mso.obj"
|
||||
".\Debug\noserv.obj"
|
||||
".\Debug\npdu.obj"
|
||||
".\Debug\reject.obj"
|
||||
".\Debug\ringbuf.obj"
|
||||
".\Debug\rp.obj"
|
||||
".\Debug\s_rp.obj"
|
||||
".\Debug\s_whois.obj"
|
||||
".\Debug\s_wp.obj"
|
||||
".\Debug\tsm.obj"
|
||||
".\Debug\txbuf.obj"
|
||||
".\Debug\whois.obj"
|
||||
".\Debug\wp.obj"
|
||||
]
|
||||
Creating command line "link.exe @C:\DOCUME~1\stk01\LOCALS~1\Temp\RSP863.tmp"
|
||||
<h3>Output Window</h3>
|
||||
Compiling...
|
||||
bacapp.c
|
||||
bacdcode.c
|
||||
Generating Code...
|
||||
Linking...
|
||||
Creating temporary file "C:\DOCUME~1\stk01\LOCALS~1\Temp\RSP864.tmp" with contents
|
||||
[
|
||||
/nologo /o"Debug/bacnet.bsc"
|
||||
".\Debug\abort.sbr"
|
||||
".\Debug\address.sbr"
|
||||
".\Debug\ai.sbr"
|
||||
".\Debug\ao.sbr"
|
||||
".\Debug\apdu.sbr"
|
||||
".\Debug\arf.sbr"
|
||||
".\Debug\av.sbr"
|
||||
".\Debug\bacapp.sbr"
|
||||
".\Debug\bacdcode.sbr"
|
||||
".\Debug\bacerror.sbr"
|
||||
".\Debug\bacfile.sbr"
|
||||
".\Debug\bacstr.sbr"
|
||||
".\Debug\bactext.sbr"
|
||||
".\Debug\bi.sbr"
|
||||
".\Debug\bigend.sbr"
|
||||
".\Debug\bip-init.sbr"
|
||||
".\Debug\bip.sbr"
|
||||
".\Debug\bo.sbr"
|
||||
".\Debug\bv.sbr"
|
||||
".\Debug\crc.sbr"
|
||||
".\Debug\datetime.sbr"
|
||||
".\Debug\dcc.sbr"
|
||||
".\Debug\device.sbr"
|
||||
".\Debug\h_arf.sbr"
|
||||
".\Debug\h_arf_a.sbr"
|
||||
".\Debug\h_iam.sbr"
|
||||
".\Debug\h_rp.sbr"
|
||||
".\Debug\h_rp_a.sbr"
|
||||
".\Debug\h_whois.sbr"
|
||||
".\Debug\h_wp.sbr"
|
||||
".\Debug\iam.sbr"
|
||||
".\Debug\indtext.sbr"
|
||||
".\Debug\lc.sbr"
|
||||
".\Debug\lsp.sbr"
|
||||
".\Debug\main.sbr"
|
||||
".\Debug\mso.sbr"
|
||||
".\Debug\noserv.sbr"
|
||||
".\Debug\npdu.sbr"
|
||||
".\Debug\reject.sbr"
|
||||
".\Debug\ringbuf.sbr"
|
||||
".\Debug\rp.sbr"
|
||||
".\Debug\s_rp.sbr"
|
||||
".\Debug\s_whois.sbr"
|
||||
".\Debug\s_wp.sbr"
|
||||
".\Debug\tsm.sbr"
|
||||
".\Debug\txbuf.sbr"
|
||||
".\Debug\whois.sbr"
|
||||
".\Debug\wp.sbr"]
|
||||
Creating command line "bscmake.exe @C:\DOCUME~1\stk01\LOCALS~1\Temp\RSP864.tmp"
|
||||
Creating browse info file...
|
||||
<h3>Output Window</h3>
|
||||
|
||||
|
||||
|
||||
<h3>Results</h3>
|
||||
bacnet.exe - 0 error(s), 0 warning(s)
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,113 @@
|
||||
BACnet Stack - SourceForge.net
|
||||
Build for Visual C++ 6.0
|
||||
|
||||
When building the BACnet stack using Visual C++ compiler,
|
||||
there are some settings that are important.
|
||||
|
||||
Q. Are there some global configuration options for this BACnet stack?
|
||||
|
||||
A. The BACnet stack uses some preprocessor defines to configure
|
||||
a number of subtle personalities.
|
||||
PRINT_ENABLED=1 - enables printing to stdio
|
||||
BIG_ENDIAN=0 - chooses the BACnet encoding and decoding order
|
||||
BACDL_BIP=1 - chooses BACnet/IP for the datalink layer
|
||||
BACDL_ETHERNET=0 - chooses BACnet Ethernet for the datalink layer
|
||||
BACDL_ARCNET=0 - chooses BACnet ARCNET for the datalink layer
|
||||
BACDL_MSTP=0 - chooses BACnet MS/TP for the datalink layer
|
||||
USE_INADDR=1 - uses INADDR_BROADCAST for broadcast rather than CLASSx
|
||||
TSM_ENABLED=1 - enables the Transaction State Machine for clients
|
||||
BIP_DEBUG=1 - enables print statements for debugging
|
||||
In Visual C++, add a Preprocessor Definition by:
|
||||
1. Select "Project" menu
|
||||
2. Select "Settings..."
|
||||
3. Select the "C/C++" tab (3rd Tab)
|
||||
4. Select the Category: General
|
||||
5. You can see the "Preprocessor Definitions:" box
|
||||
6. Type OPTION_NAME=1 or OPTION_NAME=0 in that edit box
|
||||
using a comma to separate multiple options.
|
||||
7. Press OK
|
||||
8. Compile the entire project again...
|
||||
|
||||
Q. MSVC refuses to open bacnet.dsw and bacnet.dsp.
|
||||
|
||||
A. bacnet.dsw and bacnet.dsp are text files that were retrieved
|
||||
from CVS on a unix client and are now in unix text file format since
|
||||
they end with a "\r\n" rather than "\n". Use the unix2dos commandline
|
||||
tool to convert them back to dos:
|
||||
unix2dos bacnet.dsw
|
||||
unix2dos bacnet.dsp
|
||||
|
||||
Q. error LNK2001: unresolved external symbol _WinMain@16
|
||||
|
||||
A. The demo ports/win32/main.c was designed as a Win32 Console
|
||||
Application. If you want to change it to a Windows GUI application,
|
||||
you will have to add all the Windows GUI code, including WinMain().
|
||||
I recommend that you use a framework, such as WxWidgets/WxWindows,
|
||||
but this has not been done yet.
|
||||
|
||||
Q. error C1083: Cannot open include file: 'stdint.h': No such file
|
||||
|
||||
A. The BACnet stack uses some header files, and Visual C++ needs to know
|
||||
where they are:
|
||||
1. Select "Project" menu
|
||||
2. Select "Settings..."
|
||||
3. Select the "C/C++" tab (3rd Tab)
|
||||
4. Select the Category: Preprocessor
|
||||
5. You can see the "Additional include directories:" box
|
||||
6. Type the path to stdint.h in that edit box (using a comma if necessary)
|
||||
7. Type the path to bacdcode.h in that edit box (using a comma if necessary)
|
||||
In my system, the paths look like:
|
||||
c:\code\bacnet-stack\,c:\code\bacnet-stack\ports\win32\,
|
||||
c:\code\bacnet-stack\demo\handler\,c:\code\bacnet-stack\demo\object\
|
||||
8. Press OK
|
||||
9. Compile the project again...
|
||||
|
||||
Q. error C2065: 'MAX_MPDU' : undeclared identifier
|
||||
|
||||
A. The BACnet stack uses a preprocessor define to configure
|
||||
its datalink layer. In Visual C++, add a Preprocessor Definition by:
|
||||
1. Select "Project" menu
|
||||
2. Select "Settings..."
|
||||
3. Select the "C/C++" tab (3rd Tab)
|
||||
4. Select the Category: General
|
||||
5. You can see the "Preprocessor Definitions:" box
|
||||
6. Type BACDL_BIP=1 in that edit box (using a comma if necessary)
|
||||
7. Press OK
|
||||
8. Compile the entire project again...
|
||||
|
||||
Q. error LNK2001: unresolved external symbol _bacapp_print
|
||||
|
||||
A. The BACnet stack uses a preprocessor define to configure
|
||||
printing to stdio. In Visual C++, add a Preprocessor Definition by:
|
||||
1. Select "Project" menu
|
||||
2. Select "Settings..."
|
||||
3. Select the "C/C++" tab (3rd Tab)
|
||||
4. Select the Category: General
|
||||
5. You can see the "Preprocessor Definitions:" box
|
||||
6. Type PRINT_ENABLED=1 in that edit box (using a comma if necessary)
|
||||
7. Press OK
|
||||
8. Compile the entire project again...
|
||||
|
||||
Q. error LNK2001: unresolved external symbol __imp__closesocket@4
|
||||
|
||||
A. Visual C++ needs to have the Winsock library to be happy:
|
||||
1. Select "Project" menu
|
||||
2. Select "Settings..."
|
||||
3. Select the "Link" tab (4th Tab)
|
||||
4. You can see "Object/library modules:" edit box
|
||||
5. Type Wsock32.LIB in that edit box
|
||||
6. Press OK
|
||||
7. Compile the entire project again...
|
||||
|
||||
Q. error C2061: in file tsm.c
|
||||
A. The BACnet stack uses a preprocessor define to configure
|
||||
client functionality in the Transaction State Machine (TSM).
|
||||
In Visual C++, add a Preprocessor Definition by:
|
||||
1. Select "Project" menu
|
||||
2. Select "Settings..."
|
||||
3. Select the "C/C++" tab (3rd Tab)
|
||||
4. Select the Category: General
|
||||
5. You can see the "Preprocessor Definitions:" box
|
||||
6. Type TSM_ENABLED=1 in that edit box (using a comma if necessary)
|
||||
7. Press OK
|
||||
8. Compile the entire project again...
|
||||
@@ -0,0 +1,212 @@
|
||||
/*####COPYRIGHTBEGIN####
|
||||
-------------------------------------------
|
||||
Copyright (C) 2005 Steve Karg
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
The Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
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.
|
||||
|
||||
This exception does not invalidate any other reasons why a work
|
||||
based on this file might be covered by the GNU General Public
|
||||
License.
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define STRICT 1
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
#include "bacdcode.h"
|
||||
#include "bip.h"
|
||||
#include "net.h"
|
||||
|
||||
/* To fill a need, we invent the gethostaddr() function. */
|
||||
static long gethostaddr(void)
|
||||
{
|
||||
struct hostent *host_ent;
|
||||
char host_name[255];
|
||||
|
||||
if (gethostname(host_name, sizeof(host_name)) != 0)
|
||||
return -1;
|
||||
#ifdef BIP_DEBUG
|
||||
printf("host name: %s\n", host_name);
|
||||
#endif
|
||||
if ((host_ent = gethostbyname(host_name)) == NULL)
|
||||
return -1;
|
||||
|
||||
return *(long *) host_ent->h_addr;
|
||||
}
|
||||
|
||||
static void set_broadcast_address(uint32_t net_address)
|
||||
{
|
||||
long broadcast_address = 0;
|
||||
long mask = 0;
|
||||
|
||||
/* Note: sometimes INADDR_BROADCAST does not let me get
|
||||
any unicast messages. Not sure why... */
|
||||
#if USE_INADDR
|
||||
(void) net_address;
|
||||
bip_set_broadcast_addr(INADDR_BROADCAST);
|
||||
#else
|
||||
if (IN_CLASSA(ntohl(net_address)))
|
||||
broadcast_address =
|
||||
(ntohl(net_address) & ~IN_CLASSA_HOST) | IN_CLASSA_HOST;
|
||||
else if (IN_CLASSB(ntohl(net_address)))
|
||||
broadcast_address =
|
||||
(ntohl(net_address) & ~IN_CLASSB_HOST) | IN_CLASSB_HOST;
|
||||
else if (IN_CLASSC(ntohl(net_address)))
|
||||
broadcast_address =
|
||||
(ntohl(net_address) & ~IN_CLASSC_HOST) | IN_CLASSC_HOST;
|
||||
else if (IN_CLASSD(ntohl(net_address)))
|
||||
broadcast_address =
|
||||
(ntohl(net_address) & ~IN_CLASSD_HOST) | IN_CLASSD_HOST;
|
||||
else
|
||||
broadcast_address = INADDR_BROADCAST;
|
||||
bip_set_broadcast_addr(htonl(broadcast_address));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cleanup(void)
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
void bip_set_interface(char *ifname)
|
||||
{
|
||||
(void) ifname;
|
||||
/* dummy function */
|
||||
}
|
||||
|
||||
bool bip_init(void)
|
||||
{
|
||||
int rv = 0; /* return from socket lib calls */
|
||||
struct sockaddr_in sin = { -1 };
|
||||
int value = 1;
|
||||
int sock_fd = -1;
|
||||
int Result;
|
||||
int Code;
|
||||
WSADATA wd;
|
||||
struct in_addr address;
|
||||
|
||||
Result = WSAStartup((1 << 8) | 1, &wd);
|
||||
/*Result = WSAStartup(MAKEWORD(2,2), &wd); */
|
||||
if (Result != 0) {
|
||||
Code = WSAGetLastError();
|
||||
printf("TCP/IP stack initialization failed, error code: %i\n",
|
||||
Code);
|
||||
exit(1);
|
||||
}
|
||||
atexit(cleanup);
|
||||
|
||||
address.s_addr = gethostaddr();
|
||||
if (address.s_addr == (unsigned) -1) {
|
||||
Code = WSAGetLastError();
|
||||
printf("Get host address failed, error code: %i\n", Code);
|
||||
exit(1);
|
||||
}
|
||||
#ifdef BIP_DEBUG
|
||||
printf("host address: %s\n", inet_ntoa(address));
|
||||
#endif
|
||||
bip_set_addr(address.s_addr);
|
||||
set_broadcast_address(address.s_addr);
|
||||
|
||||
/* assumes that the driver has already been initialized */
|
||||
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
bip_set_socket(sock_fd);
|
||||
if (sock_fd < 0) {
|
||||
fprintf(stderr, "bip: failed to allocate a socket.\n");
|
||||
return false;
|
||||
}
|
||||
/* Allow us to use the same socket for sending and receiving */
|
||||
/* This makes sure that the src port is correct when sending */
|
||||
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *) &value, sizeof(value));
|
||||
if (rv < 0) {
|
||||
fprintf(stderr, "bip: failed to set REUSEADDR socket option.\n");
|
||||
close(sock_fd);
|
||||
bip_set_socket(-1);
|
||||
return false;
|
||||
}
|
||||
/* allow us to send a broadcast */
|
||||
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
|
||||
(char *) &value, sizeof(value));
|
||||
if (rv < 0) {
|
||||
fprintf(stderr, "bip: failed to set BROADCAST socket option.\n");
|
||||
close(sock_fd);
|
||||
bip_set_socket(-1);
|
||||
return false;
|
||||
}
|
||||
#if 0
|
||||
/* probably only for Apple... */
|
||||
/* rebind a port that is already in use.
|
||||
Note: all users of the port must specify this flag */
|
||||
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT,
|
||||
(char *) &value, sizeof(value));
|
||||
if (rv < 0) {
|
||||
fprintf(stderr, "bip: failed to set REUSEPORT socket option.\n");
|
||||
close(sock_fd);
|
||||
bip_set_socket(-1);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
/* bind the socket to the local port number and IP address */
|
||||
sin.sin_family = AF_INET;
|
||||
#if USE_INADDR
|
||||
/* by setting sin.sin_addr.s_addr to INADDR_ANY,
|
||||
I am telling the IP stack to automatically fill
|
||||
in the IP address of the machine the process
|
||||
is running on.
|
||||
|
||||
Some server computers have multiple IP addresses.
|
||||
A socket bound to one of these will not accept
|
||||
connections to another address. Frequently you prefer
|
||||
to allow any one of the computer's IP addresses
|
||||
to be used for connections. Use INADDR_ANY (0L) to
|
||||
allow clients to connect using any one of the host's
|
||||
IP addresses.
|
||||
|
||||
Note: sometimes INADDR_ANY does not let me get
|
||||
any unicast messages. Not sure why... */
|
||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
#else
|
||||
/* or we could use the specific adapter address
|
||||
note: already in network byte order */
|
||||
sin.sin_addr.s_addr = address.s_addr;
|
||||
#endif
|
||||
sin.sin_port = htons(bip_get_port());
|
||||
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
|
||||
rv = bind(sock_fd,
|
||||
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
|
||||
if (rv < 0) {
|
||||
fprintf(stderr, "bip: failed to bind to %s port %hd\n",
|
||||
inet_ntoa(sin.sin_addr), bip_get_port());
|
||||
close(sock_fd);
|
||||
bip_set_socket(-1);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,455 @@
|
||||
/*####COPYRIGHTBEGIN####
|
||||
-------------------------------------------
|
||||
Copyright (C) 2005 Steve Karg, modified by Kevin Liao
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
The Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
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.
|
||||
|
||||
This exception does not invalidate any other reasons why a work
|
||||
based on this file might be covered by the GNU General Public
|
||||
License.
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
#include <stdint.h> /* for standard integer types uint8_t etc. */
|
||||
#include <stdbool.h> /* for the standard bool type. */
|
||||
#include <assert.h>
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
|
||||
#include "bacdef.h"
|
||||
#include "ethernet.h"
|
||||
#include "bacdcode.h"
|
||||
|
||||
|
||||
/* Uses WinPCap to access raw ethernet */
|
||||
/* Notes: */
|
||||
/* To make ethernet.c work under win32, you have to: */
|
||||
/* 1. install winpcap 3.1 development pack; */
|
||||
/* 2. install Microsoft Platform SDK Feb 2003. */
|
||||
/* 3. remove or modify functions used for log such as */
|
||||
/* "LogError()", "LogInfo()", which were implemented */
|
||||
/* as a wrapper of Log4cpp. */
|
||||
/* -- Kevin Liao */
|
||||
|
||||
/* includes for accessing ethernet by using winpcap */
|
||||
#include "pcap.h"
|
||||
#include "packet32.h"
|
||||
#include "ntddndis.h"
|
||||
#include "remote-ext.h"
|
||||
|
||||
|
||||
/* commonly used comparison address for ethernet */
|
||||
uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
/* commonly used empty address for ethernet quick compare */
|
||||
uint8_t Ethernet_Empty_MAC[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
/* my local device data - MAC address */
|
||||
uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = { 0 };
|
||||
|
||||
/* couple of var for using winpcap */
|
||||
static char pcap_errbuf[PCAP_ERRBUF_SIZE + 1];
|
||||
static pcap_t *pcap_eth802_fp = NULL; /* 802.2 file handle, from winpcap */
|
||||
static unsigned eth_timeout = 100;
|
||||
|
||||
|
||||
/* couple of external func for runtime error logging, you can simply */
|
||||
/* replace them with standard "printf(...)" */
|
||||
/* Logging extern functions: Info level */
|
||||
extern void LogInfo(const char *msg);
|
||||
/* Logging extern functions: Error level*/
|
||||
extern void LogError(const char *msg);
|
||||
/* Logging extern functions: Debug level*/
|
||||
extern void LogDebug(const char *msg);
|
||||
|
||||
|
||||
bool ethernet_valid(void)
|
||||
{
|
||||
return (pcap_eth802_fp != NULL);
|
||||
}
|
||||
|
||||
void ethernet_cleanup(void)
|
||||
{
|
||||
if (pcap_eth802_fp) {
|
||||
pcap_close(pcap_eth802_fp);
|
||||
pcap_eth802_fp = NULL;
|
||||
}
|
||||
LogInfo("ethernet.c: ethernet_cleanup() ok.\n");
|
||||
}
|
||||
|
||||
void ethernet_set_timeout(unsigned timeout)
|
||||
{
|
||||
eth_timeout = timeout;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Portable function to set a socket into nonblocking mode.
|
||||
Calling this on a socket causes all future read() and write() calls on
|
||||
that socket to do only as much as they can immediately, and return
|
||||
without waiting.
|
||||
If no data can be read or written, they return -1 and set errno
|
||||
to EAGAIN (or EWOULDBLOCK).
|
||||
Thanks to Bjorn Reese for this code.
|
||||
----------------------------------------------------------------------*/
|
||||
/**
|
||||
* We don't need to use this function since WinPCap has provided one
|
||||
* named "pcap_setnonblock()".
|
||||
* Kevin, 2006.08.15
|
||||
*/
|
||||
/*
|
||||
int setNonblocking(int fd)
|
||||
{
|
||||
int flags;
|
||||
|
||||
if (-1 == (flags = fcntl(fd, F_GETFL, 0)))
|
||||
flags = 0;
|
||||
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
||||
}
|
||||
*/
|
||||
|
||||
bool ethernet_init(char *if_name)
|
||||
{
|
||||
PPACKET_OID_DATA pOidData;
|
||||
LPADAPTER lpAdapter;
|
||||
pcap_if_t *pcap_all_if;
|
||||
pcap_if_t *dev;
|
||||
BOOLEAN result;
|
||||
CHAR str[sizeof(PACKET_OID_DATA) + 128];
|
||||
int i;
|
||||
char msgBuf[200];
|
||||
|
||||
if (ethernet_valid())
|
||||
ethernet_cleanup();
|
||||
|
||||
/**
|
||||
* Find the interface user specified
|
||||
*/
|
||||
/* Retrieve the device list */
|
||||
if (pcap_findalldevs(&pcap_all_if, pcap_errbuf) == -1) {
|
||||
sprintf(msgBuf,
|
||||
"ethernet.c: error in pcap_findalldevs: %s\n", pcap_errbuf);
|
||||
LogError(msgBuf);
|
||||
return false;
|
||||
}
|
||||
/* Scan the list printing every entry */
|
||||
for (dev = pcap_all_if; dev; dev = dev->next) {
|
||||
if (strcmp(if_name, dev->name) == 0)
|
||||
break;
|
||||
}
|
||||
pcap_freealldevs(pcap_all_if); /* we don't need it anymore */
|
||||
if (dev == NULL) {
|
||||
sprintf(msgBuf,
|
||||
"ethernet.c: specified interface not found: %s\n", if_name);
|
||||
LogError(msgBuf);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local MAC address
|
||||
*/
|
||||
ZeroMemory(str, sizeof(PACKET_OID_DATA) + 128);
|
||||
lpAdapter = PacketOpenAdapter(if_name);
|
||||
if (lpAdapter == NULL) {
|
||||
ethernet_cleanup();
|
||||
sprintf(msgBuf,
|
||||
"ethernet.c: error in PacketOpenAdapter(\"%s\")\n", if_name);
|
||||
LogError(msgBuf);
|
||||
return false;
|
||||
}
|
||||
pOidData = (PPACKET_OID_DATA) str;
|
||||
pOidData->Oid = OID_802_3_CURRENT_ADDRESS;
|
||||
pOidData->Length = 6;
|
||||
result = PacketRequest(lpAdapter, FALSE, pOidData);
|
||||
if (!result) {
|
||||
PacketCloseAdapter(lpAdapter);
|
||||
ethernet_cleanup();
|
||||
LogError("ethernet.c: error in PacketRequest()\n");
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < 6; ++i)
|
||||
Ethernet_MAC_Address[i] = pOidData->Data[i];
|
||||
PacketCloseAdapter(lpAdapter);
|
||||
|
||||
/**
|
||||
* Open interface for subsequent sending and receiving
|
||||
*/
|
||||
/* Open the output device */
|
||||
pcap_eth802_fp = pcap_open(if_name, /* name of the device */
|
||||
MAX_MPDU, /* portion of the packet to capture */
|
||||
PCAP_OPENFLAG_PROMISCUOUS, /* promiscuous mode */
|
||||
eth_timeout, /* read timeout */
|
||||
NULL, /* authentication on the remote machine */
|
||||
pcap_errbuf /* error buffer */
|
||||
);
|
||||
if (pcap_eth802_fp == NULL) {
|
||||
PacketCloseAdapter(lpAdapter);
|
||||
ethernet_cleanup();
|
||||
sprintf(msgBuf,
|
||||
"ethernet.c: unable to open the adapter. %s is not supported by WinPcap\n",
|
||||
if_name);
|
||||
LogError(msgBuf);
|
||||
return false;
|
||||
}
|
||||
|
||||
LogInfo("ethernet.c: ethernet_init() ok.\n");
|
||||
|
||||
atexit(ethernet_cleanup);
|
||||
|
||||
return ethernet_valid();
|
||||
}
|
||||
|
||||
/* function to send a packet out the 802.2 socket */
|
||||
/* returns bytes sent success, negative on failure */
|
||||
int ethernet_send(BACNET_ADDRESS * dest, /* destination address */
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len /* number of bytes of data */
|
||||
)
|
||||
{
|
||||
int bytes = 0;
|
||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
||||
int mtu_len = 0;
|
||||
int i = 0;
|
||||
|
||||
/* don't waste time if the socket is not valid */
|
||||
if (!ethernet_valid()) {
|
||||
LogError
|
||||
("ethernet.c: invalid 802.2 ethernet interface descriptor!\n");
|
||||
return -1;
|
||||
}
|
||||
/* load destination ethernet MAC address */
|
||||
if (dest->mac_len == 6) {
|
||||
for (i = 0; i < 6; i++) {
|
||||
mtu[mtu_len] = dest->mac[i];
|
||||
mtu_len++;
|
||||
}
|
||||
} else {
|
||||
LogError("ethernet.c: invalid destination MAC address!\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* load source ethernet MAC address */
|
||||
if (src->mac_len == 6) {
|
||||
for (i = 0; i < 6; i++) {
|
||||
mtu[mtu_len] = src->mac[i];
|
||||
mtu_len++;
|
||||
}
|
||||
} else {
|
||||
LogError("ethernet.c: invalid source MAC address!\n");
|
||||
return -3;
|
||||
}
|
||||
if ((14 + 3 + pdu_len) > MAX_MPDU) {
|
||||
LogError("ethernet.c: PDU is too big to send!\n");
|
||||
return -4;
|
||||
}
|
||||
/* packet length */
|
||||
mtu_len +=
|
||||
encode_unsigned16(&mtu[12], 3 /*DSAP,SSAP,LLC */ + pdu_len);
|
||||
/* Logical PDU portion */
|
||||
mtu[mtu_len++] = 0x82; /* DSAP for BACnet */
|
||||
mtu[mtu_len++] = 0x82; /* SSAP for BACnet */
|
||||
mtu[mtu_len++] = 0x03; /* Control byte in header */
|
||||
memcpy(&mtu[mtu_len], pdu, pdu_len);
|
||||
mtu_len += pdu_len;
|
||||
|
||||
/* Send the packet */
|
||||
if (pcap_sendpacket(pcap_eth802_fp, mtu, mtu_len) != 0) {
|
||||
/* did it get sent? */
|
||||
char msgBuf[200];
|
||||
sprintf(msgBuf,
|
||||
"ethernet.c: error sending packet: %s\n",
|
||||
pcap_geterr(pcap_eth802_fp));
|
||||
LogError(msgBuf);
|
||||
return -5;
|
||||
}
|
||||
|
||||
return mtu_len;
|
||||
}
|
||||
|
||||
/* function to send a packet out the 802.2 socket */
|
||||
/* returns number of bytes sent on success, negative on failure */
|
||||
int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len /* number of bytes of data */
|
||||
)
|
||||
{
|
||||
int i = 0; /* counter */
|
||||
BACNET_ADDRESS src = { 0 }; /* source address */
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
src.mac[i] = Ethernet_MAC_Address[i];
|
||||
src.mac_len++;
|
||||
}
|
||||
/* function to send a packet out the 802.2 socket */
|
||||
/* returns 1 on success, 0 on failure */
|
||||
return ethernet_send(dest, /* destination address */
|
||||
&src, /* source address */
|
||||
pdu, /* any data to be sent - may be null */
|
||||
pdu_len /* number of bytes of data */
|
||||
);
|
||||
}
|
||||
|
||||
/* receives an 802.2 framed packet */
|
||||
/* returns the number of octets in the PDU, or zero on failure */
|
||||
uint16_t ethernet_receive(BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
unsigned timeout /* number of milliseconds to wait for a packet. we ommit it due to winpcap API. */
|
||||
)
|
||||
{
|
||||
struct pcap_pkthdr *header;
|
||||
int res;
|
||||
u_char *pkt_data;
|
||||
uint16_t pdu_len = 0; /* return value */
|
||||
|
||||
/* Make sure the socket is open */
|
||||
if (!ethernet_valid()) {
|
||||
LogError
|
||||
("ethernet.c: invalid 802.2 ethernet interface descriptor!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Capture a packet */
|
||||
res = pcap_next_ex(pcap_eth802_fp, &header, &pkt_data);
|
||||
if (res < 0) {
|
||||
char msgBuf[200];
|
||||
sprintf(msgBuf,
|
||||
"ethernet.c: error in receiving packet: %s\n",
|
||||
pcap_geterr(pcap_eth802_fp));
|
||||
return 0;
|
||||
} else if (res == 0)
|
||||
return 0;
|
||||
|
||||
if (header->len == 0 || header->caplen == 0)
|
||||
return 0;
|
||||
|
||||
/* the signature of an 802.2 BACnet packet */
|
||||
if ((pkt_data[14] != 0x82) && (pkt_data[15] != 0x82)) {
|
||||
/*eth_log_error("ethernet.c: Non-BACnet packet\n"); */
|
||||
return 0;
|
||||
}
|
||||
/* copy the source address */
|
||||
src->mac_len = 6;
|
||||
memmove(src->mac, &pkt_data[6], 6);
|
||||
|
||||
/* check destination address for when */
|
||||
/* the Ethernet card is in promiscious mode */
|
||||
if ((memcmp(&pkt_data[0], Ethernet_MAC_Address, 6) != 0)
|
||||
&& (memcmp(&pkt_data[0], Ethernet_Broadcast, 6) != 0)) {
|
||||
/*eth_log_error( "ethernet.c: This packet isn't for us\n"); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void) decode_unsigned16(&pkt_data[12], &pdu_len);
|
||||
pdu_len -= 3 /* DSAP, SSAP, LLC Control */ ;
|
||||
/* copy the buffer into the PDU */
|
||||
if (pdu_len < max_pdu)
|
||||
memmove(&pdu[0], &pkt_data[17], pdu_len);
|
||||
/* ignore packets that are too large */
|
||||
else
|
||||
pdu_len = 0;
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
void ethernet_set_my_address(BACNET_ADDRESS * my_address)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
Ethernet_MAC_Address[i] = my_address->mac[i];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void ethernet_get_my_address(BACNET_ADDRESS * my_address)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
my_address->mac_len = 0;
|
||||
for (i = 0; i < 6; i++) {
|
||||
my_address->mac[i] = Ethernet_MAC_Address[i];
|
||||
my_address->mac_len++;
|
||||
}
|
||||
my_address->net = 0; /* local only, no routing */
|
||||
my_address->len = 0;
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
my_address->adr[i] = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void ethernet_get_broadcast_address(BACNET_ADDRESS * dest)
|
||||
{ /* destination address */
|
||||
int i = 0; /* counter */
|
||||
|
||||
if (dest) {
|
||||
for (i = 0; i < 6; i++) {
|
||||
dest->mac[i] = Ethernet_Broadcast[i];
|
||||
}
|
||||
dest->mac_len = 6;
|
||||
dest->net = BACNET_BROADCAST_NETWORK;
|
||||
dest->len = 0; /* denotes broadcast address */
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
dest->adr[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void ethernet_debug_address(const char *info, BACNET_ADDRESS * dest)
|
||||
{
|
||||
int i = 0; /* counter */
|
||||
char msgBuf[200];
|
||||
|
||||
if (info) {
|
||||
sprintf(msgBuf, "%s", info);
|
||||
LogError(msgBuf);
|
||||
}
|
||||
/* if */
|
||||
if (dest) {
|
||||
sprintf(msgBuf,
|
||||
"Address:\n MAC Length=%d\n MAC Address=", dest->mac_len);
|
||||
LogInfo(msgBuf);
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
sprintf(msgBuf, "%02X ", (unsigned) dest->mac[i]);
|
||||
LogInfo(msgBuf);
|
||||
} /* for */
|
||||
LogInfo("\n");
|
||||
sprintf(msgBuf,
|
||||
" Net=%hu\n Len=%d\n Adr=", dest->net, dest->len);
|
||||
LogInfo(msgBuf);
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
sprintf(msgBuf, "%02X ", (unsigned) dest->adr[i]);
|
||||
LogInfo(msgBuf);
|
||||
} /* for */
|
||||
LogInfo("\n");
|
||||
}
|
||||
/* if ( dest ) */
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
/* This is one way to use the embedded BACnet stack under Win32 */
|
||||
/* compiled with Borland C++ 5.02 or Visual C++ 6.0 */
|
||||
#include <winsock2.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <conio.h> /* for kbhit and getch */
|
||||
#include "iam.h"
|
||||
#include "address.h"
|
||||
#include "config.h"
|
||||
#include "bacdef.h"
|
||||
#include "npdu.h"
|
||||
#include "apdu.h"
|
||||
#include "device.h"
|
||||
#include "handlers.h"
|
||||
#include "client.h"
|
||||
#include "datalink.h"
|
||||
#include "txbuf.h"
|
||||
|
||||
/* buffer used for receive */
|
||||
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
||||
|
||||
/* send a whois to see who is on the network */
|
||||
static bool Who_Is_Request = true;
|
||||
bool I_Am_Request = true;
|
||||
|
||||
static void Read_Properties(void)
|
||||
{
|
||||
uint32_t device_id = 0;
|
||||
bool status = false;
|
||||
unsigned max_apdu = 0;
|
||||
BACNET_ADDRESS src;
|
||||
bool next_device = false;
|
||||
static unsigned index = 0;
|
||||
static unsigned property = 0;
|
||||
/* list of required (and some optional) properties in the
|
||||
Device Object
|
||||
note: you could just loop through
|
||||
all the properties in all the objects. */
|
||||
const int object_props[] = {
|
||||
PROP_OBJECT_IDENTIFIER,
|
||||
PROP_OBJECT_NAME,
|
||||
PROP_OBJECT_TYPE,
|
||||
PROP_SYSTEM_STATUS,
|
||||
PROP_VENDOR_NAME,
|
||||
PROP_VENDOR_IDENTIFIER,
|
||||
PROP_MODEL_NAME,
|
||||
PROP_FIRMWARE_REVISION,
|
||||
PROP_APPLICATION_SOFTWARE_VERSION,
|
||||
PROP_PROTOCOL_VERSION,
|
||||
PROP_PROTOCOL_CONFORMANCE_CLASS,
|
||||
PROP_PROTOCOL_SERVICES_SUPPORTED,
|
||||
PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED,
|
||||
PROP_MAX_APDU_LENGTH_ACCEPTED,
|
||||
PROP_SEGMENTATION_SUPPORTED,
|
||||
PROP_LOCAL_TIME,
|
||||
PROP_LOCAL_DATE,
|
||||
PROP_UTC_OFFSET,
|
||||
PROP_DAYLIGHT_SAVINGS_STATUS,
|
||||
PROP_APDU_SEGMENT_TIMEOUT,
|
||||
PROP_APDU_TIMEOUT,
|
||||
PROP_NUMBER_OF_APDU_RETRIES,
|
||||
PROP_TIME_SYNCHRONIZATION_RECIPIENTS,
|
||||
PROP_MAX_MASTER,
|
||||
PROP_MAX_INFO_FRAMES,
|
||||
PROP_DEVICE_ADDRESS_BINDING,
|
||||
/* note: PROP_OBJECT_LIST is missing cause
|
||||
we need to get it with an index method since
|
||||
the list could be very large */
|
||||
/* some proprietary properties */
|
||||
514, 515,
|
||||
/* end of list */
|
||||
-1
|
||||
};
|
||||
|
||||
if (address_count()) {
|
||||
if (address_get_by_index(index, &device_id, &max_apdu, &src)) {
|
||||
if (object_props[property] < 0)
|
||||
next_device = true;
|
||||
else {
|
||||
status = Send_Read_Property_Request(device_id, /* destination device */
|
||||
OBJECT_DEVICE,
|
||||
device_id, object_props[property], BACNET_ARRAY_ALL);
|
||||
if (status)
|
||||
property++;
|
||||
}
|
||||
} else
|
||||
next_device = true;
|
||||
if (next_device) {
|
||||
next_device = false;
|
||||
index++;
|
||||
if (index >= MAX_ADDRESS_CACHE)
|
||||
index = 0;
|
||||
property = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void LocalIAmHandler(uint8_t * service_request,
|
||||
uint16_t service_len, BACNET_ADDRESS * src)
|
||||
{
|
||||
int len = 0;
|
||||
uint32_t device_id = 0;
|
||||
unsigned max_apdu = 0;
|
||||
int segmentation = 0;
|
||||
uint16_t vendor_id = 0;
|
||||
|
||||
(void) src;
|
||||
(void) service_len;
|
||||
len = iam_decode_service_request(service_request,
|
||||
&device_id, &max_apdu, &segmentation, &vendor_id);
|
||||
fprintf(stderr, "Received I-Am Request");
|
||||
if (len != -1) {
|
||||
fprintf(stderr, " from %u!\n", device_id);
|
||||
address_add(device_id, max_apdu, src);
|
||||
} else
|
||||
fprintf(stderr, "!\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void Init_Service_Handlers(void)
|
||||
{
|
||||
/* we need to handle who-is to support dynamic device binding */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||
handler_who_is);
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM,
|
||||
LocalIAmHandler);
|
||||
|
||||
/* set the handler for all the services we don't implement */
|
||||
/* It is required to send the proper reject message... */
|
||||
apdu_set_unrecognized_service_handler_handler
|
||||
(handler_unrecognized_service);
|
||||
/* we must implement read property - it's required! */
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||
handler_read_property);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||
handler_write_property);
|
||||
/* handle the data coming back from confirmed requests */
|
||||
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||
handler_read_property_ack);
|
||||
}
|
||||
|
||||
static void print_address(char *name, BACNET_ADDRESS * dest)
|
||||
{ /* destination address */
|
||||
int i = 0; /* counter */
|
||||
|
||||
if (dest) {
|
||||
printf("%s: ", name);
|
||||
for (i = 0; i < dest->mac_len; i++) {
|
||||
printf("%02X", dest->mac[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void print_address_cache(void)
|
||||
{
|
||||
int i, j;
|
||||
BACNET_ADDRESS address;
|
||||
uint32_t device_id = 0;
|
||||
unsigned max_apdu = 0;
|
||||
|
||||
fprintf(stderr, "Device\tMAC\tMaxAPDU\tNet\n");
|
||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||
if (address_get_by_index(i, &device_id, &max_apdu, &address)) {
|
||||
fprintf(stderr, "%u\t", device_id);
|
||||
for (j = 0; j < address.mac_len; j++) {
|
||||
fprintf(stderr, "%02X", address.mac[j]);
|
||||
}
|
||||
fprintf(stderr, "\t");
|
||||
fprintf(stderr, "%hu\t", max_apdu);
|
||||
fprintf(stderr, "%hu\n", address.net);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BACNET_ADDRESS src = { 0 }; /* address where message came from */
|
||||
uint16_t pdu_len = 0;
|
||||
unsigned timeout = 100; /* milliseconds */
|
||||
BACNET_ADDRESS my_address, broadcast_address;
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
Device_Set_Object_Instance_Number(124);
|
||||
Init_Service_Handlers();
|
||||
/* init the data link layer */
|
||||
/* configure standard BACnet/IP port */
|
||||
bip_set_port(0xBAC0);
|
||||
if (!bip_init())
|
||||
return 1;
|
||||
|
||||
datalink_get_broadcast_address(&broadcast_address);
|
||||
print_address("Broadcast", &broadcast_address);
|
||||
datalink_get_my_address(&my_address);
|
||||
print_address("Address", &my_address);
|
||||
|
||||
printf("BACnet stack running...\n");
|
||||
/* loop forever */
|
||||
for (;;) {
|
||||
/* input */
|
||||
|
||||
/* returns 0 bytes on timeout */
|
||||
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||
|
||||
/* process */
|
||||
|
||||
if (pdu_len) {
|
||||
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||
}
|
||||
if (I_Am_Request) {
|
||||
I_Am_Request = false;
|
||||
iam_send(&Handler_Transmit_Buffer[0]);
|
||||
} else if (Who_Is_Request) {
|
||||
Who_Is_Request = false;
|
||||
Send_WhoIs(-1, -1);
|
||||
} else {
|
||||
Read_Properties();
|
||||
}
|
||||
|
||||
/* output */
|
||||
|
||||
/* blink LEDs, Turn on or off outputs, etc */
|
||||
|
||||
/* wait for ESC from keyboard before quitting */
|
||||
if (kbhit() && (getch() == 0x1B))
|
||||
break;
|
||||
}
|
||||
|
||||
print_address_cache();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
#ifndef NET_H
|
||||
#define NET_H
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define STRICT 1
|
||||
|
||||
#include <winsock2.h>
|
||||
|
||||
#define close closesocket
|
||||
|
||||
typedef int socklen_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
BACnet Stack - Win32
|
||||
|
||||
This directory contains a demo program that compiles with a Win32 compiler.
|
||||
It was tested with the freely downloadable Borland C++ 5.5, as well as
|
||||
Borland C++ 5 and Visual C++ 6.0.
|
||||
|
||||
The makefile.mak file is used with the Borland command line tools.
|
||||
Run setvars.bat to configure the environment for the Borland tools.
|
||||
Edit it if necessary to set the correct location of your tools.
|
||||
|
||||
The bacnet.ide file is used with the Borland IDE.
|
||||
|
||||
The bacnet directory is used with Visual C++ 6 tools, and there is a
|
||||
workspace file bacnet.dsw that is used to compile the demo program.
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
set BORLAND_DIR=\bcc55
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef STDBOOL_H
|
||||
#define STDBOOL_H
|
||||
|
||||
/* C99 Boolean types for compilers without C99 support */
|
||||
|
||||
#ifndef __cplusplus
|
||||
typedef int _Bool;
|
||||
#ifndef bool
|
||||
#define bool _Bool
|
||||
#endif
|
||||
#ifndef true
|
||||
#define true 1
|
||||
#endif
|
||||
#ifndef false
|
||||
#define false 0
|
||||
#endif
|
||||
#define __bool_true_false_are_defined 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
/* Defines the standard integer types that are used in code */
|
||||
/* for the x86 processor and Borland Compiler */
|
||||
|
||||
#ifndef STDINT_H
|
||||
#define STDINT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef unsigned char uint8_t; /* 1 byte 0 to 255 */
|
||||
typedef signed char int8_t; /* 1 byte -127 to 127 */
|
||||
typedef unsigned short uint16_t; /* 2 bytes 0 to 65535 */
|
||||
typedef signed short int16_t; /* 2 bytes -32767 to 32767 */
|
||||
/*typedef unsigned short long uint24_t; // 3 bytes 0 to 16777215 */
|
||||
typedef unsigned long uint32_t; /* 4 bytes 0 to 4294967295 */
|
||||
typedef signed long int32_t; /* 4 bytes -2147483647 to 2147483647 */
|
||||
/* typedef signed long long int64_t; */
|
||||
/* typedef unsigned long long uint64_t; */
|
||||
|
||||
#endif /* STDINT_H */
|
||||
Reference in New Issue
Block a user