From f510255c45e4c5e9ad88ed6afd8883ce64b34543 Mon Sep 17 00:00:00 2001 From: skarg Date: Sat, 2 Apr 2005 11:12:28 +0000 Subject: [PATCH] added read property support. --- bacnet-stack/Makefile | 3 ++ bacnet-stack/device.c | 45 +++++++++++++++++++++++++++++ bacnet-stack/ports/linux/ethernet.c | 8 +++++ bacnet-stack/ports/linux/main.c | 24 ++++++++------- bacnet-stack/rp.c | 1 + 5 files changed, 71 insertions(+), 10 deletions(-) diff --git a/bacnet-stack/Makefile b/bacnet-stack/Makefile index 3499329f..33bae380 100644 --- a/bacnet-stack/Makefile +++ b/bacnet-stack/Makefile @@ -12,6 +12,9 @@ SRCS = ports/linux/main.c \ bigend.c \ whois.c \ iam.c \ + rp.c \ + device.c \ + abort.c \ reject.c \ bacerror.c \ apdu.c \ diff --git a/bacnet-stack/device.c b/bacnet-stack/device.c index be43882b..6fdc40e2 100644 --- a/bacnet-stack/device.c +++ b/bacnet-stack/device.c @@ -361,5 +361,50 @@ int Device_Encode_Property_APDU( return apdu_len; } +#ifdef TEST +#include +#include +#include "ctest.h" + +void testDevice(Test * pTest) +{ + Device_Set_Object_Instance_Number(111); + ct_test(pTest, Device_Object_Instance_Number() == 111); + + Device_Set_System_Status(STATUS_NON_OPERATIONAL); + ct_test(pTest, Device_System_Status() == STATUS_NON_OPERATIONAL); + + Device_Set_Vendor_Name("MyName"); + ct_test(pTest, strcmp(Device_Vendor_Name(),"MyName") == 0); + + Device_Set_Vendor_Identifier(42); + ct_test(pTest, Device_Vendor_Identifier() == 42); + + Device_Set_Model_Name("MyModel"); + ct_test(pTest, strcmp(Device_Model_Name(),"MyModel") == 0); + + return; +} + +#ifdef TEST_DEVICE +int main(void) +{ + Test *pTest; + bool rc; + + pTest = ct_create("BACnet Device", NULL); + /* individual tests */ + rc = ct_addTestFunction(pTest, testDevice); + assert(rc); + + ct_setStream(pTest, stdout); + ct_run(pTest); + (void) ct_report(pTest); + ct_destroy(pTest); + + return 0; +} +#endif /* TEST_DEVICE */ +#endif /* TEST */ diff --git a/bacnet-stack/ports/linux/ethernet.c b/bacnet-stack/ports/linux/ethernet.c index 0051fe78..ae292e15 100644 --- a/bacnet-stack/ports/linux/ethernet.c +++ b/bacnet-stack/ports/linux/ethernet.c @@ -116,6 +116,13 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name) fprintf(stderr, "ethernet: Error opening socket: %s\n", strerror(errno)); + fprintf(stderr, + "You might need to add the following to modules.conf\n" + "(or in modutils/alias on Debian with update-modules):\n" + "alias net-pf-17 af_packet\n" + "Also, add af_packet to /etc/modules.\n" + "Then follow it by:\n" + "# modprobe af_packet\n"); exit(-1); } /* Bind the socket to an address */ @@ -136,6 +143,7 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name) "You might need to add the following to modules.conf\n" "(or in modutils/alias on Debian with update-modules):\n" "alias net-pf-17 af_packet\n" + "Also, add af_packet to /etc/modules.\n" "Then follow it by:\n" "# modprobe af_packet\n"); /* Close the socket */ diff --git a/bacnet-stack/ports/linux/main.c b/bacnet-stack/ports/linux/main.c index e1406663..2aef71b2 100644 --- a/bacnet-stack/ports/linux/main.c +++ b/bacnet-stack/ports/linux/main.c @@ -11,9 +11,13 @@ #include "bacdef.h" #include "npdu.h" #include "apdu.h" +#include "device.h" +#include "rp.h" #include "iam.h" #include "whois.h" #include "reject.h" +#include "abort.h" +#include "bacerror.h" #include "ethernet.h" // buffers used for transmit and receive @@ -79,10 +83,10 @@ void Send_IAm(void) // encode the APDU portion of the packet pdu_len += iam_encode_apdu( &Tx_Buf[pdu_len], - Device_Id, + Device_Object_Instance_Number(), MAX_APDU, SEGMENTATION_NONE, - Vendor_Id); + Device_Vendor_Identifier()); (void)ethernet_send_pdu( &dest, // destination address @@ -110,7 +114,8 @@ void WhoIsHandler( I_Am_Request = true; else if (len != -1) { - if ((Device_Id >= low_limit) && (Device_Id <= high_limit)) + if ((Device_Object_Instance_Number() >= low_limit) && + (Device_Object_Instance_Number() <= high_limit)) I_Am_Request = true; } @@ -123,7 +128,6 @@ void ReadPropertyHandler( BACNET_ADDRESS *src, BACNET_CONFIRMED_SERVICE_DATA *service_data) { - BACNET_CONFIRMED_SERVICE_DATA service_data; BACNET_READ_PROPERTY_DATA rp_data; int len = 0; int pdu_len = 0; @@ -148,7 +152,7 @@ void ReadPropertyHandler( service_data->invoke_id, ABORT_REASON_OTHER); (void)ethernet_send_pdu( - &src, // destination address + src, // destination address &Tx_Buf[0], pdu_len); // number of bytes of data fprintf(stderr,"Sent Abort!\n"); @@ -160,7 +164,7 @@ void ReadPropertyHandler( service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED); (void)ethernet_send_pdu( - &src, // destination address + src, // destination address &Tx_Buf[0], pdu_len); // number of bytes of data } @@ -189,7 +193,7 @@ void ReadPropertyHandler( service_data->invoke_id, &rp_data); (void)ethernet_send_pdu( - &src, // destination address + src, // destination address &Tx_Buf[0], pdu_len); // number of bytes of data fprintf(stderr,"Sent Read Property Ack!\n"); @@ -203,7 +207,7 @@ void ReadPropertyHandler( ERROR_CLASS_PROPERTY, ERROR_CODE_UNKNOWN_PROPERTY); (void)ethernet_send_pdu( - &src, // destination address + src, // destination address &Tx_Buf[0], pdu_len); // number of bytes of data fprintf(stderr,"Sent Unknown Property Error!\n"); @@ -217,7 +221,7 @@ void ReadPropertyHandler( ERROR_CLASS_OBJECT, ERROR_CODE_UNKNOWN_OBJECT); (void)ethernet_send_pdu( - &src, // destination address + src, // destination address &Tx_Buf[0], pdu_len); // number of bytes of data fprintf(stderr,"Sent Unknown Object Error!\n"); @@ -231,7 +235,7 @@ void ReadPropertyHandler( static void Init_Device_Parameters(void) { // configure my initial values - Device_Set_Object_Identifier(111); + Device_Set_Object_Instance_Number(111); Device_Set_Vendor_Name("Lithonia Lighting"); Device_Set_Vendor_Identifier(42); Device_Set_Model_Name("Simple BACnet Server"); diff --git a/bacnet-stack/rp.c b/bacnet-stack/rp.c index f39e53d0..3af58783 100644 --- a/bacnet-stack/rp.c +++ b/bacnet-stack/rp.c @@ -36,6 +36,7 @@ #include "bacdcode.h" #include "bacdef.h" #include "device.h" +#include "rp.h" // encode service - use -1 for limit if you want unlimited int rp_encode_apdu(