From f74d39558f7df34ed6a3b450712670ecb61c5911 Mon Sep 17 00:00:00 2001 From: skarg Date: Tue, 21 Aug 2007 17:50:01 +0000 Subject: [PATCH] Added more configuration information to config.h, including the default Vendor Id. This BACnet Stack at SourceForge has been assigned Vendor Id 260 by ASHRAE. We can now release binary utilities and tools with our own Vendor ID! --- bacnet-stack/bacapp.c | 13 ++++++-- bacnet-stack/config.h | 44 +++++++++++++++++++++----- bacnet-stack/datalink.h | 2 ++ bacnet-stack/demo/object/device.c | 24 +++++++------- bacnet-stack/ports/atmega168/device.c | 3 +- bacnet-stack/ports/pic18f6720/device.c | 3 +- bacnet-stack/ports/win32/dlmstp.c | 4 +-- 7 files changed, 65 insertions(+), 28 deletions(-) diff --git a/bacnet-stack/bacapp.c b/bacnet-stack/bacapp.c index bdd98aeb..14ad3021 100644 --- a/bacnet-stack/bacapp.c +++ b/bacnet-stack/bacapp.c @@ -523,10 +523,17 @@ int bacapp_data_len(uint8_t * apdu, int max_apdu_len, max_apdu_len - apdu_len, &application_value); } apdu_len += len; - if (opening_tag_number_counter) - total_len += len; - /* ERROR! */ + if (opening_tag_number_counter) { + if (len > 0) { + total_len += len; + } else { + /* error: len is not incrementing */ + total_len = -1; + break; + } + } if (apdu_len > max_apdu_len) { + /* error: exceeding our buffer limit */ total_len = -1; break; } diff --git a/bacnet-stack/config.h b/bacnet-stack/config.h index 0ef4934f..cc742d75 100644 --- a/bacnet-stack/config.h +++ b/bacnet-stack/config.h @@ -1,34 +1,62 @@ #ifndef CONFIG_H #define CONFIG_H +/* Note: these defines can be defined in your makefile or project + or here or not defined and defaults will be used */ + /* declare a single physical layer using your compiler define. see datalink.h for possible defines. */ +#if !(defined(BACDL_ETHERNET) || defined(BACDL_ARCNET) || defined(BACDL_MSTP) || defined(BACDL_BIP)) + #define BACDL_BIP +#endif + +/* optional debug info for BACnet/IP datalink layers */ +#if defined(BACDL_BIP) + #if !defined(BIP_DEBUG) + #define BIP_DEBUG + #endif +#endif + +/* Define your processor architecture as Big Endian or Little Endian */ +#if !defined(BIG_ENDIAN) + #define BIG_ENDIAN 0 +#endif + +/* Define your Vendor Identifier assigned by ASHRAE */ +#if !defined(BACNET_VENDOR_ID) + #define BACNET_VENDOR_ID 260 +#endif /* Max number of bytes in an APDU. */ /* Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets */ /* This is used in constructing messages and to tell others our limits */ /* 50 is the minimum; adjust to your memory and physical layer constraints */ /* Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476 */ -#ifndef MAX_APDU - /* #define MAX_APDU 50 */ - #define MAX_APDU 480 - /* #define MAX_APDU 1476 */ +#if !defined(MAX_APDU) + /* #define MAX_APDU 50 */ + #define MAX_APDU 480 + /* #define MAX_APDU 1476 */ #endif /* for confirmed messages, this is the number of transactions */ /* that we hold in a queue waiting for timeout. */ /* Configure to zero if you don't want any confirmed messages */ /* Configure from 1..255 for number of outstanding confirmed */ /* requests available. */ -#ifndef MAX_TSM_TRANSACTIONS - #define MAX_TSM_TRANSACTIONS 255 +#if !defined(MAX_TSM_TRANSACTIONS) + #define MAX_TSM_TRANSACTIONS 255 #endif /* The address cache is used for binding to BACnet devices */ /* The number of entries corresponds to the number of */ /* devices that might respond to an I-Am on the network. */ /* If your device is a simple server and does not need to bind, */ /* then you don't need to use this. */ -#ifndef MAX_ADDRESS_CACHE - #define MAX_ADDRESS_CACHE 255 +#if !defined(MAX_ADDRESS_CACHE) + #define MAX_ADDRESS_CACHE 255 +#endif + +/* some modules have debugging enabled using PRINT_ENABLED */ +#if !defined(PRINT_ENABLED) + #define PRINT_ENABLED 0 #endif #endif diff --git a/bacnet-stack/datalink.h b/bacnet-stack/datalink.h index 6fe82273..de75b5af 100644 --- a/bacnet-stack/datalink.h +++ b/bacnet-stack/datalink.h @@ -34,6 +34,8 @@ #ifndef DATALINK_H #define DATALINK_H +#include "config.h" + #if defined(BACDL_ETHERNET) #include "ethernet.h" diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index 925ece07..3e6a4ff0 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -44,12 +44,11 @@ #include "wp.h" /* write property handling */ #include "version.h" #include "device.h" /* me */ -#if BACFILE -#include "bacfile.h" /* object list dependency */ -#endif -#if defined(BACDL_MSTP) -#include "dlmstp.h" +#include "datalink.h" +#if defined(BACFILE) + #include "bacfile.h" /* object list dependency */ #endif + /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Device_Properties_Required[] = { @@ -120,8 +119,7 @@ static uint32_t Object_Instance_Number = 0; static char Object_Name[16] = "SimpleServer"; static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL; static char Vendor_Name[16] = "ASHRAE"; -/* FIXME: your vendor id assigned by ASHRAE */ -static uint16_t Vendor_Identifier = 0; +static uint16_t Vendor_Identifier = BACNET_VENDOR_ID; static char Model_Name[16] = "GNU"; static char Application_Software_Version[16] = "1.0"; static char Location[16] = "USA"; @@ -389,7 +387,7 @@ unsigned Device_Object_List_Count(void) count += Life_Safety_Point_Count(); count += Load_Control_Count(); count += Multistate_Output_Count(); -#if BACFILE +#if defined(BACFILE) count += bacfile_count(); #endif @@ -525,7 +523,7 @@ bool Device_Object_List_Identifier(unsigned array_index, } } /* file objects */ -#if BACFILE +#if defined(BACFILE) if (!status) { /* normalize the index since we know it is not the previous objects */ @@ -605,7 +603,7 @@ char *Device_Valid_Object_Id(int object_type, uint32_t object_instance) case OBJECT_MULTI_STATE_OUTPUT: name = Multistate_Output_Name(object_instance); break; -#if BACFILE +#if defined(BACFILE) case OBJECT_FILE: name = bacfile_name(object_instance); break; @@ -754,7 +752,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu, if (Multistate_Output_Count()) bitstring_set_bit(&bit_string, OBJECT_MULTI_STATE_OUTPUT, true); -#if BACFILE +#if defined(BACFILE) if (bacfile_count()) bitstring_set_bit(&bit_string, OBJECT_FILE, true); #endif @@ -1172,15 +1170,19 @@ uint32_t Multistate_Output_Index_To_Instance(unsigned index) return index; } +#if defined(BACFILE) uint32_t bacfile_count(void) { return 0; } +#endif +#if defined(BACFILE) uint32_t bacfile_index_to_instance(unsigned find_index) { return find_index; } +#endif int main(void) { diff --git a/bacnet-stack/ports/atmega168/device.c b/bacnet-stack/ports/atmega168/device.c index 99929bb2..c7f1681a 100644 --- a/bacnet-stack/ports/atmega168/device.c +++ b/bacnet-stack/ports/atmega168/device.c @@ -115,10 +115,9 @@ void Device_Set_System_Status(BACNET_DEVICE_STATUS status) System_Status = status; } -/* FIXME: put your vendor ID here! */ uint16_t Device_Vendor_Identifier(void) { - return 0; + return BACNET_VENDOR_ID; } uint8_t Device_Protocol_Version(void) diff --git a/bacnet-stack/ports/pic18f6720/device.c b/bacnet-stack/ports/pic18f6720/device.c index 64754396..9e7dbdd1 100644 --- a/bacnet-stack/ports/pic18f6720/device.c +++ b/bacnet-stack/ports/pic18f6720/device.c @@ -112,10 +112,9 @@ void Device_Set_System_Status(BACNET_DEVICE_STATUS status) System_Status = status; } -/* FIXME: put your vendor ID here! */ uint16_t Device_Vendor_Identifier(void) { - return 0; + return BACNET_VENDOR_ID; } uint8_t Device_Protocol_Version(void) diff --git a/bacnet-stack/ports/win32/dlmstp.c b/bacnet-stack/ports/win32/dlmstp.c index 5651ecec..451bb275 100644 --- a/bacnet-stack/ports/win32/dlmstp.c +++ b/bacnet-stack/ports/win32/dlmstp.c @@ -444,8 +444,8 @@ bool dlmstp_init(char *ifname) MSTP_Port.InputBufferSize = sizeof(RxBuffer); MSTP_Port.OutputBuffer = &TxBuffer[0]; MSTP_Port.OutputBufferSize = sizeof(TxBuffer); - MSTP_Init.SilenceTimer = Timer_Silence; - MSTP_Init.SilenceTimerReset = Timer_Silence_Reset; + MSTP_Port.SilenceTimer = Timer_Silence; + MSTP_Port.SilenceTimerReset = Timer_Silence_Reset; MSTP_Init(&MSTP_Port); #if 0 uint8_t data;