diff --git a/bacnet-stack/config.h b/bacnet-stack/config.h index 9bcbe502..2f847270 100644 --- a/bacnet-stack/config.h +++ b/bacnet-stack/config.h @@ -1,6 +1,11 @@ #ifndef CONFIG_H #define CONFIG_H +// declare a single physical layer +//#include "ethernet.h" +//#include "arcnet.h" +//#include "mstp.h" + // 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 diff --git a/bacnet-stack/device.c b/bacnet-stack/device.c index 3e1db776..6b2a4123 100644 --- a/bacnet-stack/device.c +++ b/bacnet-stack/device.c @@ -40,13 +40,13 @@ #include "config.h" // the custom stuff static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL; -static char *Vendor_Name = "ASHRAE"; +static const char *Vendor_Name = "ASHRAE"; static uint16_t Vendor_Identifier = 0; -static char *Model_Name = "GNU"; -static char *Firmware_Revision = "1.0"; -static char *Application_Software_Version = "1.0"; +static const char *Model_Name = "GNU"; +static const char *Firmware_Revision = "1.0"; +static const char *Application_Software_Version = "1.0"; //static char *Location = "USA"; -static char *Description = "server"; +static const char *Description = "server"; //static uint8_t Protocol_Version = 1; - constant, not settable //static uint8_t Protocol_Revision = 4; - constant, not settable //Protocol_Services_Supported @@ -138,7 +138,7 @@ const char *Device_Application_Software_Version(void) return Application_Software_Version; } -void Device_Application_Software_Version(const char *name) +void Device_Set_Application_Software_Version(const char *name) { Application_Software_Version = name; } @@ -148,7 +148,7 @@ const char *Device_Description(void) return Description; } -void Device_Description(const char *name) +void Device_Set_Description(const char *name) { Description = name; } @@ -201,3 +201,13 @@ void Device_Set_Number_Of_APDU_Retries(uint8_t retries) Number_Of_APDU_Retries = retries; } +uint8_t Device_Database_Revision(void) +{ + return Database_Revision; +} + +void Device_Set_Database_Revision(uint8_t revision) +{ + Database_Revision = revision; +} + diff --git a/bacnet-stack/device.h b/bacnet-stack/device.h index 4a733781..48113b3f 100644 --- a/bacnet-stack/device.h +++ b/bacnet-stack/device.h @@ -56,16 +56,16 @@ const char *Device_Firmware_Revision(void); void Device_Set_Firmware_Revision(const char *name); const char *Device_Application_Software_Version(void); -void Device_Application_Software_Version(const char *name); +void Device_Set_Application_Software_Version(const char *name); const char *Device_Description(void); -void Device_Description(const char *name); +void Device_Set_Description(const char *name); uint8_t Device_Protocol_Version(void); -uint8_t Device_Protocol_Revision(void); +uint8_t Device_Set_Protocol_Revision(void); uint16_t Device_Max_APDU_Length_Accepted(void); -BACNET_SEGMENTATION Device_Segmentation_Supported(void); +BACNET_SEGMENTATION Device_Set_Segmentation_Supported(void); uint16_t Device_APDU_Timeout(void); void Device_Set_APDU_Timeout(uint16_t timeout); @@ -73,5 +73,8 @@ void Device_Set_APDU_Timeout(uint16_t timeout); uint8_t Device_Number_Of_APDU_Retries(void); void Device_Set_Number_Of_APDU_Retries(uint8_t retries); +uint8_t Device_Database_Revision(void); +void Device_Set_Database_Revision(uint8_t revision); + #endif diff --git a/bacnet-stack/ethernet.h b/bacnet-stack/ethernet.h index 59b8be31..bf8a11a4 100644 --- a/bacnet-stack/ethernet.h +++ b/bacnet-stack/ethernet.h @@ -34,7 +34,9 @@ #ifndef ETHERNET_H #define ETHERNET_H +#include #include +#include #include "bacdef.h" // specific defines for Ethernet diff --git a/bacnet-stack/ports/linux/main.c b/bacnet-stack/ports/linux/main.c index 4ecbc3e7..b2d49b51 100644 --- a/bacnet-stack/ports/linux/main.c +++ b/bacnet-stack/ports/linux/main.c @@ -7,6 +7,7 @@ #include #include #include +#include "config.h" #include "bacdef.h" #include "npdu.h" #include "apdu.h" @@ -92,6 +93,7 @@ int main(int argc, char *argv[]) // custom handlers apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,WhoIsHandler); + // init the physical layer if (!ethernet_init("eth0")) return 1; diff --git a/bacnet-stack/tsm.c b/bacnet-stack/tsm.c index 4688295b..7d7f545d 100644 --- a/bacnet-stack/tsm.c +++ b/bacnet-stack/tsm.c @@ -34,6 +34,7 @@ #include #include #include +#include // memmove() #include #include "bits.h" #include "apdu.h" @@ -52,14 +53,15 @@ // FIXME: not coded for segmentation -static BACNET_TSM_DATA TSM_List[MAX_TSM_TRANSACTIONS] = {0}; +// declare space for the TSM transactions, and set it up in the init. +static BACNET_TSM_DATA TSM_List[MAX_TSM_TRANSACTIONS] = {{0}}; // returns MAX_TSM_TRANSACTIONS if not found uint8_t tsm_find_invokeID_index(uint8_t invokeID) { unsigned i = 0; // counter uint8_t index = MAX_TSM_TRANSACTIONS; // return value - + for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { if ((TSM_List[i].state != TSM_STATE_IDLE) && @@ -134,10 +136,9 @@ uint8_t tsm_next_free_invokeID(void) // returns 0 if there are no free transactions uint8_t tsm_request_confirmed_unsegmented_transaction( - BACNET_ADDRESS *src, BACNET_ADDRESS *dest, uint8_t *pdu, - uint16_t pdu_len); + uint16_t pdu_len) { uint8_t invokeID = 0; unsigned i = 0, j = 0; @@ -161,6 +162,7 @@ uint8_t tsm_request_confirmed_unsegmented_transaction( { TSM_List[i].pdu[j] = pdu[j]; } + memmove(&TSM_List[i].dest,dest,sizeof(TSM_List[i].dest)); } break; } @@ -176,9 +178,22 @@ uint8_t tsm_request_confirmed_unsegmented_transaction( void testTSM(Test * pTest) { + //unsigned i; + uint8_t invokeID = 0; + BACNET_ADDRESS dest = {0}; + uint8_t pdu[MAX_PDU] = {0}; + uint16_t pdu_len = 0; + memset(pdu,0xa5,sizeof(pdu)); + pdu_len = sizeof(pdu); + + invokeID = tsm_request_confirmed_unsegmented_transaction( + &dest, + &pdu[0], + pdu_len); + ct_test(pTest, invokeID != 0); - + return; } #ifdef TEST_TSM diff --git a/bacnet-stack/tsm.h b/bacnet-stack/tsm.h index 23e6a548..fdad232a 100644 --- a/bacnet-stack/tsm.h +++ b/bacnet-stack/tsm.h @@ -37,6 +37,7 @@ #include #include #include +#include "bacdef.h" typedef enum { @@ -75,21 +76,20 @@ typedef struct BACnet_TSM_Data uint8_t InvokeID; // state that the TSM is in BACNET_TSM_STATE state; - // the address it was sent from - BACNET_ADDRESS src; // the address we sent it to BACNET_ADDRESS dest; // copy of the PDU, should we need to send it again - uint8_t pdu[MAX_MPDU]; + uint8_t pdu[MAX_PDU]; } BACNET_TSM_DATA; bool tsm_transaction_available(void); uint8_t tsm_transaction_idle_count(void); uint8_t tsm_request_confirmed_unsegmented_transaction( - BACNET_ADDRESS *src, BACNET_ADDRESS *dest, uint8_t *pdu, uint16_t pdu_len); +void tsm_init_list(BACNET_TSM_DATA *list); + #endif diff --git a/bacnet-stack/whois.c b/bacnet-stack/whois.c index 7d967342..b85e5d97 100644 --- a/bacnet-stack/whois.c +++ b/bacnet-stack/whois.c @@ -94,7 +94,8 @@ int whois_decode_service_request( len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) return -1; - len += decode_unsigned(&apdu[len], len_value, &decoded_value); + len += decode_unsigned(&apdu[len], + len_value, &decoded_value); if ((decoded_value >= 0) && (decoded_value <= BACNET_MAX_INSTANCE)) { if (pHigh_limit)