added read property support.
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -361,5 +361,50 @@ int Device_Encode_Property_APDU(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#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 */
|
||||
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user