added read property support.
This commit is contained in:
@@ -12,6 +12,9 @@ SRCS = ports/linux/main.c \
|
|||||||
bigend.c \
|
bigend.c \
|
||||||
whois.c \
|
whois.c \
|
||||||
iam.c \
|
iam.c \
|
||||||
|
rp.c \
|
||||||
|
device.c \
|
||||||
|
abort.c \
|
||||||
reject.c \
|
reject.c \
|
||||||
bacerror.c \
|
bacerror.c \
|
||||||
apdu.c \
|
apdu.c \
|
||||||
|
|||||||
@@ -361,5 +361,50 @@ int Device_Encode_Property_APDU(
|
|||||||
return apdu_len;
|
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,
|
fprintf(stderr,
|
||||||
"ethernet: Error opening socket: %s\n",
|
"ethernet: Error opening socket: %s\n",
|
||||||
strerror(errno));
|
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);
|
exit(-1);
|
||||||
}
|
}
|
||||||
/* Bind the socket to an address */
|
/* 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"
|
"You might need to add the following to modules.conf\n"
|
||||||
"(or in modutils/alias on Debian with update-modules):\n"
|
"(or in modutils/alias on Debian with update-modules):\n"
|
||||||
"alias net-pf-17 af_packet\n"
|
"alias net-pf-17 af_packet\n"
|
||||||
|
"Also, add af_packet to /etc/modules.\n"
|
||||||
"Then follow it by:\n"
|
"Then follow it by:\n"
|
||||||
"# modprobe af_packet\n");
|
"# modprobe af_packet\n");
|
||||||
/* Close the socket */
|
/* Close the socket */
|
||||||
|
|||||||
@@ -11,9 +11,13 @@
|
|||||||
#include "bacdef.h"
|
#include "bacdef.h"
|
||||||
#include "npdu.h"
|
#include "npdu.h"
|
||||||
#include "apdu.h"
|
#include "apdu.h"
|
||||||
|
#include "device.h"
|
||||||
|
#include "rp.h"
|
||||||
#include "iam.h"
|
#include "iam.h"
|
||||||
#include "whois.h"
|
#include "whois.h"
|
||||||
#include "reject.h"
|
#include "reject.h"
|
||||||
|
#include "abort.h"
|
||||||
|
#include "bacerror.h"
|
||||||
#include "ethernet.h"
|
#include "ethernet.h"
|
||||||
|
|
||||||
// buffers used for transmit and receive
|
// buffers used for transmit and receive
|
||||||
@@ -79,10 +83,10 @@ void Send_IAm(void)
|
|||||||
// encode the APDU portion of the packet
|
// encode the APDU portion of the packet
|
||||||
pdu_len += iam_encode_apdu(
|
pdu_len += iam_encode_apdu(
|
||||||
&Tx_Buf[pdu_len],
|
&Tx_Buf[pdu_len],
|
||||||
Device_Id,
|
Device_Object_Instance_Number(),
|
||||||
MAX_APDU,
|
MAX_APDU,
|
||||||
SEGMENTATION_NONE,
|
SEGMENTATION_NONE,
|
||||||
Vendor_Id);
|
Device_Vendor_Identifier());
|
||||||
|
|
||||||
(void)ethernet_send_pdu(
|
(void)ethernet_send_pdu(
|
||||||
&dest, // destination address
|
&dest, // destination address
|
||||||
@@ -110,7 +114,8 @@ void WhoIsHandler(
|
|||||||
I_Am_Request = true;
|
I_Am_Request = true;
|
||||||
else if (len != -1)
|
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;
|
I_Am_Request = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +128,6 @@ void ReadPropertyHandler(
|
|||||||
BACNET_ADDRESS *src,
|
BACNET_ADDRESS *src,
|
||||||
BACNET_CONFIRMED_SERVICE_DATA *service_data)
|
BACNET_CONFIRMED_SERVICE_DATA *service_data)
|
||||||
{
|
{
|
||||||
BACNET_CONFIRMED_SERVICE_DATA service_data;
|
|
||||||
BACNET_READ_PROPERTY_DATA rp_data;
|
BACNET_READ_PROPERTY_DATA rp_data;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int pdu_len = 0;
|
int pdu_len = 0;
|
||||||
@@ -148,7 +152,7 @@ void ReadPropertyHandler(
|
|||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
ABORT_REASON_OTHER);
|
ABORT_REASON_OTHER);
|
||||||
(void)ethernet_send_pdu(
|
(void)ethernet_send_pdu(
|
||||||
&src, // destination address
|
src, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
fprintf(stderr,"Sent Abort!\n");
|
fprintf(stderr,"Sent Abort!\n");
|
||||||
@@ -160,7 +164,7 @@ void ReadPropertyHandler(
|
|||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
||||||
(void)ethernet_send_pdu(
|
(void)ethernet_send_pdu(
|
||||||
&src, // destination address
|
src, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
}
|
}
|
||||||
@@ -189,7 +193,7 @@ void ReadPropertyHandler(
|
|||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
&rp_data);
|
&rp_data);
|
||||||
(void)ethernet_send_pdu(
|
(void)ethernet_send_pdu(
|
||||||
&src, // destination address
|
src, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
fprintf(stderr,"Sent Read Property Ack!\n");
|
fprintf(stderr,"Sent Read Property Ack!\n");
|
||||||
@@ -203,7 +207,7 @@ void ReadPropertyHandler(
|
|||||||
ERROR_CLASS_PROPERTY,
|
ERROR_CLASS_PROPERTY,
|
||||||
ERROR_CODE_UNKNOWN_PROPERTY);
|
ERROR_CODE_UNKNOWN_PROPERTY);
|
||||||
(void)ethernet_send_pdu(
|
(void)ethernet_send_pdu(
|
||||||
&src, // destination address
|
src, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
fprintf(stderr,"Sent Unknown Property Error!\n");
|
fprintf(stderr,"Sent Unknown Property Error!\n");
|
||||||
@@ -217,7 +221,7 @@ void ReadPropertyHandler(
|
|||||||
ERROR_CLASS_OBJECT,
|
ERROR_CLASS_OBJECT,
|
||||||
ERROR_CODE_UNKNOWN_OBJECT);
|
ERROR_CODE_UNKNOWN_OBJECT);
|
||||||
(void)ethernet_send_pdu(
|
(void)ethernet_send_pdu(
|
||||||
&src, // destination address
|
src, // destination address
|
||||||
&Tx_Buf[0],
|
&Tx_Buf[0],
|
||||||
pdu_len); // number of bytes of data
|
pdu_len); // number of bytes of data
|
||||||
fprintf(stderr,"Sent Unknown Object Error!\n");
|
fprintf(stderr,"Sent Unknown Object Error!\n");
|
||||||
@@ -231,7 +235,7 @@ void ReadPropertyHandler(
|
|||||||
static void Init_Device_Parameters(void)
|
static void Init_Device_Parameters(void)
|
||||||
{
|
{
|
||||||
// configure my initial values
|
// configure my initial values
|
||||||
Device_Set_Object_Identifier(111);
|
Device_Set_Object_Instance_Number(111);
|
||||||
Device_Set_Vendor_Name("Lithonia Lighting");
|
Device_Set_Vendor_Name("Lithonia Lighting");
|
||||||
Device_Set_Vendor_Identifier(42);
|
Device_Set_Vendor_Identifier(42);
|
||||||
Device_Set_Model_Name("Simple BACnet Server");
|
Device_Set_Model_Name("Simple BACnet Server");
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "bacdcode.h"
|
#include "bacdcode.h"
|
||||||
#include "bacdef.h"
|
#include "bacdef.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "rp.h"
|
||||||
|
|
||||||
// encode service - use -1 for limit if you want unlimited
|
// encode service - use -1 for limit if you want unlimited
|
||||||
int rp_encode_apdu(
|
int rp_encode_apdu(
|
||||||
|
|||||||
Reference in New Issue
Block a user