Integrated ReadPropertyMultiple with the demo/server application. Compiles, but untested.
This commit is contained in:
+483
-262
@@ -1,7 +1,7 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
|
||||
* Enhanced by John Stachler for ReadPropertyMultiple
|
||||
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
|
||||
* Inspired by John Stachler.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -37,37 +37,378 @@
|
||||
#include "abort.h"
|
||||
#include "rpm.h"
|
||||
#include "handlers.h"
|
||||
/* demo objects */
|
||||
#include "device.h"
|
||||
#include "ai.h"
|
||||
#include "ao.h"
|
||||
#include "av.h"
|
||||
#include "bi.h"
|
||||
#include "bo.h"
|
||||
#include "bv.h"
|
||||
#include "lc.h"
|
||||
#include "lsp.h"
|
||||
#include "mso.h"
|
||||
#if BACFILE
|
||||
#include "bacfile.h"
|
||||
#endif
|
||||
|
||||
static uint8_t Temp_Buf[MAX_APDU] = { 0 };
|
||||
static uint8_t Application_Buf[MAX_APDU] = { 0 };
|
||||
|
||||
/* copy encoded apdu data to tx buffer
|
||||
this is needed to make sure we do not go past our apdu buffer size */
|
||||
bool copy_apdu_data_buffer(int *apdu_len, uint8 len, uint8 npdu_len)
|
||||
struct property_list_t
|
||||
{
|
||||
bool copy_status = false;
|
||||
|
||||
if ((*apdu_len + len) <= MAX_APDU) {
|
||||
memcpy(&Handler_Transmit_Buffer[*apdu_len + npdu_len], &Temp_Buf[0], len);
|
||||
*apdu_len += len;
|
||||
copy_status = true;
|
||||
const int *pList;
|
||||
unsigned count;
|
||||
};
|
||||
|
||||
struct special_property_list_t
|
||||
{
|
||||
struct property_list_t Required;
|
||||
struct property_list_t Optional;
|
||||
struct property_list_t Proprietary;
|
||||
};
|
||||
|
||||
static unsigned property_list_count(const int *pList)
|
||||
{
|
||||
unsigned property_count = 0;
|
||||
|
||||
if (pList) {
|
||||
while (*pList != -1) {
|
||||
property_count++;
|
||||
}
|
||||
}
|
||||
|
||||
return copy_status;
|
||||
|
||||
return property_count;
|
||||
}
|
||||
|
||||
void handler_read_property_multiple(uint8_t * service_request, uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||
/* for a given object type, returns the special property list */
|
||||
static void RPM_Property_List(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
struct special_property_list_t *pPropertyList)
|
||||
{
|
||||
pPropertyList->Required.pList = NULL;
|
||||
pPropertyList->Optional.pList = NULL;
|
||||
pPropertyList->Proprietary.pList = NULL;
|
||||
switch (object_type) {
|
||||
case OBJECT_ANALOG_INPUT:
|
||||
Analog_Input_Property_Lists(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
break;
|
||||
case OBJECT_ANALOG_OUTPUT:
|
||||
Analog_Output_Property_Lists(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
break;
|
||||
case OBJECT_ANALOG_VALUE:
|
||||
Analog_Value_Property_Lists(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
break;
|
||||
case OBJECT_BINARY_INPUT:
|
||||
Binary_Input_Property_Lists(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
break;
|
||||
case OBJECT_BINARY_OUTPUT:
|
||||
Binary_Output_Property_Lists(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
break;
|
||||
case OBJECT_BINARY_VALUE:
|
||||
Binary_Value_Property_Lists(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
break;
|
||||
case OBJECT_LIFE_SAFETY_POINT:
|
||||
Life_Safety_Point_Property_Lists(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
break;
|
||||
case OBJECT_LOAD_CONTROL:
|
||||
Load_Control_Property_Lists(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
break;
|
||||
case OBJECT_MULTI_STATE_OUTPUT:
|
||||
break;
|
||||
#if BACFILE
|
||||
case OBJECT_FILE:
|
||||
BACfile_Property_Lists(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
break;
|
||||
#endif
|
||||
case OBJECT_DEVICE:
|
||||
Device_Property_Lists(
|
||||
&pPropertyList->Required.pList,
|
||||
&pPropertyList->Optional.pList,
|
||||
&pPropertyList->Proprietary.pList);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* fill the count */
|
||||
pPropertyList->Required.count =
|
||||
property_list_count(pPropertyList->Required.pList);
|
||||
pPropertyList->Optional.count =
|
||||
property_list_count(pPropertyList->Optional.pList);
|
||||
pPropertyList->Proprietary.count =
|
||||
property_list_count(pPropertyList->Proprietary.pList);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int RPM_Object_Property(
|
||||
struct special_property_list_t *pPropertyList,
|
||||
BACNET_PROPERTY_ID special_property,
|
||||
unsigned index)
|
||||
{
|
||||
int property = -1; /* return value */
|
||||
unsigned required, optional, proprietary;
|
||||
|
||||
required = pPropertyList->Required.count;
|
||||
optional = pPropertyList->Optional.count;
|
||||
proprietary = pPropertyList->Proprietary.count;
|
||||
if (special_property == PROP_ALL) {
|
||||
if (index < required) {
|
||||
property = pPropertyList->Required.pList[index];
|
||||
} else if (index < (required + optional)) {
|
||||
property = pPropertyList->Optional.pList[index];
|
||||
} else if (index < (required + optional + proprietary)) {
|
||||
property = pPropertyList->Proprietary.pList[index];
|
||||
}
|
||||
} else if (special_property == PROP_REQUIRED) {
|
||||
if (index < required) {
|
||||
property = pPropertyList->Required.pList[index];
|
||||
}
|
||||
} else if (special_property == PROP_OPTIONAL) {
|
||||
if (index < optional) {
|
||||
property = pPropertyList->Optional.pList[index];
|
||||
}
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
static unsigned RPM_Object_Property_Count(
|
||||
struct special_property_list_t *pPropertyList,
|
||||
BACNET_PROPERTY_ID special_property)
|
||||
{
|
||||
unsigned count = 0; /* return value */
|
||||
|
||||
if (special_property == PROP_ALL) {
|
||||
count = pPropertyList->Required.count +
|
||||
pPropertyList->Optional.count +
|
||||
pPropertyList->Proprietary.count;
|
||||
} else if (special_property == PROP_REQUIRED) {
|
||||
count = pPropertyList->Required.count;
|
||||
} else if (special_property == PROP_OPTIONAL) {
|
||||
count = pPropertyList->Optional.count;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/* copy len bytes from src to offset of dest if there is enough space. */
|
||||
int apdu_copy(uint8_t *dest, uint8_t *src, int offset, int len, int max)
|
||||
{
|
||||
int i;
|
||||
int copy_len = 0;
|
||||
|
||||
if (len <= (max-offset)) {
|
||||
for (i = 0; i < len; i++) {
|
||||
dest[offset+i] = src[i];
|
||||
copy_len++;
|
||||
}
|
||||
}
|
||||
|
||||
return copy_len;
|
||||
}
|
||||
|
||||
/* Encodes the property APDU and returns the length,
|
||||
or sets the error, and returns -1 */
|
||||
int Encode_Property_APDU(
|
||||
uint8_t * apdu,
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance,
|
||||
BACNET_PROPERTY_ID property,
|
||||
int32_t array_index,
|
||||
BACNET_ERROR_CLASS * error_class,
|
||||
BACNET_ERROR_CODE * error_code)
|
||||
{
|
||||
int apdu_len = -1;
|
||||
|
||||
switch(object_type) {
|
||||
case OBJECT_DEVICE:
|
||||
if ((object_instance == Device_Object_Instance_Number()) ||
|
||||
(object_instance == BACNET_MAX_INSTANCE)) {
|
||||
apdu_len = Device_Encode_Property_APDU(
|
||||
&apdu[0],
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
case OBJECT_ANALOG_INPUT:
|
||||
if (Analog_Input_Valid_Instance(object_instance)) {
|
||||
apdu_len = Analog_Input_Encode_Property_APDU(
|
||||
&apdu[0],
|
||||
object_instance,
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
case OBJECT_ANALOG_OUTPUT:
|
||||
if (!Analog_Output_Valid_Instance(object_instance)) {
|
||||
apdu_len = Analog_Output_Encode_Property_APDU(
|
||||
&apdu[0],
|
||||
object_instance,
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
case OBJECT_ANALOG_VALUE:
|
||||
if (Analog_Value_Valid_Instance(object_instance)) {
|
||||
apdu_len = Analog_Value_Encode_Property_APDU(&Temp_Buf[0],
|
||||
object_instance,
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
case OBJECT_BINARY_INPUT:
|
||||
if (Binary_Input_Valid_Instance(object_instance)) {
|
||||
apdu_len = Binary_Input_Encode_Property_APDU(
|
||||
&apdu[0],
|
||||
object_instance,
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
case OBJECT_BINARY_OUTPUT:
|
||||
if (Binary_Output_Valid_Instance(object_instance)) {
|
||||
apdu_len = Binary_Output_Encode_Property_APDU(
|
||||
&apdu[0],
|
||||
object_instance,
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
case OBJECT_BINARY_VALUE:
|
||||
if (Binary_Value_Valid_Instance(object_instance)) {
|
||||
apdu_len = Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
|
||||
object_instance,
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
case OBJECT_LIFE_SAFETY_POINT:
|
||||
if (Life_Safety_Point_Valid_Instance(object_instance)) {
|
||||
apdu_len = Life_Safety_Point_Encode_Property_APDU(&Temp_Buf[0],
|
||||
object_instance,
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
case OBJECT_LOAD_CONTROL:
|
||||
if (Load_Control_Valid_Instance(object_instance)) {
|
||||
apdu_len = Load_Control_Encode_Property_APDU(&Temp_Buf[0],
|
||||
object_instance,
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
case OBJECT_MULTI_STATE_OUTPUT:
|
||||
if (Multistate_Output_Valid_Instance(object_instance)) {
|
||||
apdu_len = Multistate_Output_Encode_Property_APDU(&Temp_Buf[0],
|
||||
object_instance,
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
#if BACFILE
|
||||
case OBJECT_FILE:
|
||||
if (bacfile_valid_instance(object_instance)) {
|
||||
apdu_len = bacfile_encode_property_apdu(&Temp_Buf[0],
|
||||
object_instance,
|
||||
property,
|
||||
array_index,
|
||||
error_class, error_code);
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
*error_class = ERROR_CLASS_OBJECT;
|
||||
*error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
void handler_read_property_multiple(
|
||||
uint8_t * service_request,
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||
{
|
||||
int len = 0;
|
||||
int copy_len = 0;
|
||||
int decode_len = 0;
|
||||
int application_data_len = 0;
|
||||
int pdu_len = 0;
|
||||
BACNET_NPDU_DATA npdu_data;
|
||||
bool error = false;
|
||||
bool done;
|
||||
bool property_found;
|
||||
int bytes_sent;
|
||||
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
|
||||
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
@@ -78,8 +419,6 @@ void handler_read_property_multiple(uint8_t * service_request, uint16_t service_
|
||||
int npdu_len;
|
||||
BACNET_PROPERTY_ID object_property, temp_object_property;
|
||||
int32_t array_index = 0;
|
||||
uint8 index;
|
||||
uint8 num_properties;
|
||||
|
||||
/* jps_debug - see if we are utilizing all the buffer */
|
||||
/* memset(&Handler_Transmit_Buffer[0], 0xff, MAX_MPDU);*/
|
||||
@@ -87,7 +426,7 @@ void handler_read_property_multiple(uint8_t * service_request, uint16_t service_
|
||||
datalink_get_my_address(&my_address);
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
npdu_len = npdu_encode_pdu(
|
||||
&Handler_Transmit_Buffer[0],
|
||||
&Handler_Transmit_Buffer[0],
|
||||
src, &my_address, &npdu_data);
|
||||
#if PRINT_ENABLED
|
||||
if (service_len <= 0)
|
||||
@@ -123,7 +462,33 @@ void handler_read_property_multiple(uint8_t * service_request, uint16_t service_
|
||||
&service_request[decode_len],
|
||||
service_len - decode_len,
|
||||
&object_type, &object_instance);
|
||||
/* error - end of object? */
|
||||
if (len < 0) {
|
||||
len = rpm_ack_decode_object_end(
|
||||
&service_request[decode_len],
|
||||
service_len - decode_len);
|
||||
if (len == 1) {
|
||||
decode_len++;
|
||||
len = rpm_ack_encode_apdu_object_end(&Temp_Buf[0]);
|
||||
copy_len = apdu_copy(
|
||||
&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
|
||||
apdu_len, len,
|
||||
sizeof(Handler_Transmit_Buffer));
|
||||
if (!copy_len) {
|
||||
apdu_len = abort_encode_apdu(
|
||||
&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
goto RPM_ABORT;
|
||||
}
|
||||
} else {
|
||||
apdu_len = abort_encode_apdu(
|
||||
&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_OTHER, true);
|
||||
goto RPM_ABORT;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
decode_len += len;
|
||||
@@ -131,282 +496,138 @@ void handler_read_property_multiple(uint8_t * service_request, uint16_t service_
|
||||
len = rpm_ack_encode_apdu_object_begin(
|
||||
&Temp_Buf[0],
|
||||
object_type, object_instance);
|
||||
if (!copy_apdu_data_buffer(&apdu_len, len, npdu_len)) {
|
||||
copy_len = apdu_copy(
|
||||
&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
|
||||
apdu_len, len,
|
||||
sizeof(Handler_Transmit_Buffer));
|
||||
if (!copy_len) {
|
||||
apdu_len = abort_encode_apdu(
|
||||
&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
break;
|
||||
goto RPM_ABORT;
|
||||
}
|
||||
/* do each property of this object of the RPM request */
|
||||
done = true;
|
||||
num_properties = 0;
|
||||
property_found = false;
|
||||
do
|
||||
{
|
||||
if (done) {
|
||||
len = rpm_decode_object_property(
|
||||
&service_request[decode_len],
|
||||
service_len - decode_len,
|
||||
&object_property,
|
||||
&array_index);
|
||||
if (len < 0) {
|
||||
break;
|
||||
} else {
|
||||
index = 0;
|
||||
decode_len += len;
|
||||
temp_object_property = object_property;
|
||||
}
|
||||
len = rpm_decode_object_property(
|
||||
&service_request[decode_len],
|
||||
service_len - decode_len,
|
||||
&object_property,
|
||||
&array_index);
|
||||
/* error - end of property list? */
|
||||
if (len < 0) {
|
||||
break;
|
||||
} else {
|
||||
decode_len += len;
|
||||
}
|
||||
/* handle the special properties */
|
||||
if ((object_property == PROP_ALL) ||
|
||||
(object_property == PROP_REQUIRED) ||
|
||||
(object_property == PROP_OPTIONAL))
|
||||
{
|
||||
done = false;
|
||||
switch(object_type)
|
||||
struct special_property_list_t property_list;
|
||||
unsigned property_count = 0;
|
||||
unsigned index = 0;
|
||||
RPM_Property_List(object_type, &property_list);
|
||||
property_count = RPM_Object_Property_Count(
|
||||
&property_list,
|
||||
object_property);
|
||||
for (index = 0; index < property_count; index++)
|
||||
{
|
||||
case OBJECT_DEVICE:
|
||||
property_found = Device_Property(
|
||||
&index, &temp_object_property,
|
||||
object_property);
|
||||
break;
|
||||
|
||||
case OBJECT_ANALOG_INPUT:
|
||||
property_found = Analog_Input_Property(
|
||||
&index, &temp_object_property,
|
||||
object_property);
|
||||
break;
|
||||
|
||||
case OBJECT_BINARY_INPUT:
|
||||
property_found = Binary_Input_Property(
|
||||
&index, &temp_object_property,
|
||||
object_property);
|
||||
break;
|
||||
|
||||
case OBJECT_ANALOG_OUTPUT:
|
||||
property_found = Analog_Output_Property(
|
||||
&index, &temp_object_property,
|
||||
object_property);
|
||||
break;
|
||||
}
|
||||
if (property_found) {
|
||||
num_properties++;
|
||||
} else {
|
||||
if (num_properties > 0) {
|
||||
done = true;
|
||||
/* check for another property */
|
||||
len = rpm_decode_object_property(
|
||||
&service_request[decode_len],
|
||||
service_len - decode_len,
|
||||
&object_property,
|
||||
&array_index);
|
||||
if (len < 0) {
|
||||
/* check for closing tag */
|
||||
len = rpm_ack_decode_object_end(
|
||||
&service_request[decode_len],
|
||||
service_len - decode_len);
|
||||
if (len == 1) {
|
||||
decode_len++;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
decode_len += len;
|
||||
temp_object_property = object_property;
|
||||
property_found = true;
|
||||
if ((object_property == PROP_ALL) ||
|
||||
(object_property == PROP_REQUIRED) ||
|
||||
(object_property == PROP_OPTIONAL))
|
||||
{
|
||||
done = false;
|
||||
index = 0;
|
||||
switch(object_type)
|
||||
{
|
||||
case OBJECT_DEVICE:
|
||||
property_found =
|
||||
Device_Property(&index,
|
||||
&temp_object_property,
|
||||
object_property);
|
||||
break;
|
||||
|
||||
case OBJECT_ANALOG_INPUT:
|
||||
property_found =
|
||||
Analog_Input_Property(&index,
|
||||
&temp_object_property,
|
||||
object_property);
|
||||
break;
|
||||
|
||||
case OBJECT_BINARY_INPUT:
|
||||
property_found =
|
||||
Binary_Input_Property(&index,
|
||||
&temp_object_property,
|
||||
object_property);
|
||||
break;
|
||||
|
||||
case OBJECT_ANALOG_OUTPUT:
|
||||
property_found =
|
||||
Analog_Output_Property(&index,
|
||||
&temp_object_property,
|
||||
object_property);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
temp_object_property = RPM_Object_Property(
|
||||
&property_list,
|
||||
object_property,
|
||||
index);
|
||||
len = rpm_ack_encode_apdu_object_property(
|
||||
&Temp_Buf[0],
|
||||
temp_object_property,
|
||||
array_index);
|
||||
copy_len = apdu_copy(
|
||||
&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
|
||||
apdu_len, len,
|
||||
sizeof(Handler_Transmit_Buffer));
|
||||
if (!copy_len) {
|
||||
apdu_len = abort_encode_apdu(
|
||||
&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
goto RPM_ABORT;
|
||||
}
|
||||
application_data_len = Encode_Property_APDU(
|
||||
&Application_Buf[0],
|
||||
object_type,
|
||||
object_instance,
|
||||
temp_object_property,
|
||||
array_index,
|
||||
&error_class, &error_code);
|
||||
if (application_data_len < 0) {
|
||||
len = rpm_ack_encode_apdu_object_property_error(
|
||||
&Temp_Buf[0],
|
||||
error_class, error_code);
|
||||
} else {
|
||||
error = true;
|
||||
done = true;
|
||||
len = rpm_ack_encode_apdu_object_property_value(
|
||||
&Temp_Buf[0],
|
||||
&Application_Buf[0],
|
||||
application_data_len);
|
||||
}
|
||||
copy_len = apdu_copy(
|
||||
&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
|
||||
apdu_len, len,
|
||||
sizeof(Handler_Transmit_Buffer));
|
||||
if (!copy_len) {
|
||||
apdu_len = abort_encode_apdu(
|
||||
&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
goto RPM_ABORT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
done = true;
|
||||
property_found = true;
|
||||
}
|
||||
len = rpm_ack_encode_apdu_object_property(
|
||||
&Temp_Buf[0],
|
||||
temp_object_property,
|
||||
array_index);
|
||||
if (!copy_apdu_data_buffer(&apdu_len, len, npdu_len)) {
|
||||
apdu_len = abort_encode_apdu(
|
||||
&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
break;
|
||||
}
|
||||
len = encode_opening_tag(&Temp_Buf[0], 4);
|
||||
if (!copy_apdu_data_buffer(&apdu_len, len, npdu_len)) {
|
||||
apdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
break;
|
||||
}
|
||||
len = -1;
|
||||
switch(object_type) {
|
||||
case OBJECT_DEVICE:
|
||||
if ((object_instance != Device_Object_Instance_Number()) &&
|
||||
((object_instance != BACNET_MAX_INSTANCE) &&
|
||||
(temp_object_property != PROP_OBJECT_IDENTIFIER))) {
|
||||
error_class = ERROR_CLASS_OBJECT;
|
||||
error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
} else if (!property_found) {
|
||||
error_class = ERROR_CLASS_PROPERTY;
|
||||
error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
} else {
|
||||
len = Device_Encode_Property_APDU(
|
||||
&Temp_Buf[0],
|
||||
temp_object_property,
|
||||
array_index,
|
||||
&error_class, &error_code);
|
||||
}
|
||||
break;
|
||||
case OBJECT_ANALOG_INPUT:
|
||||
if (!Analog_Input_Valid_Instance(object_instance)) {
|
||||
error_class = ERROR_CLASS_OBJECT;
|
||||
error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
} else if (!property_found) {
|
||||
error_class = ERROR_CLASS_PROPERTY;
|
||||
error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
} else {
|
||||
len = Analog_Input_Encode_Property_APDU(
|
||||
&Temp_Buf[0],
|
||||
object_instance,
|
||||
temp_object_property,
|
||||
array_index,
|
||||
&error_class, &error_code);
|
||||
}
|
||||
break;
|
||||
case OBJECT_BINARY_INPUT:
|
||||
if (!Binary_Input_Valid_Instance(object_instance)) {
|
||||
error_class = ERROR_CLASS_OBJECT;
|
||||
error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
} else if (!property_found) {
|
||||
error_class = ERROR_CLASS_PROPERTY;
|
||||
error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
} else {
|
||||
len = Binary_Input_Encode_Property_APDU(
|
||||
&Temp_Buf[0],
|
||||
object_instance,
|
||||
temp_object_property,
|
||||
array_index,
|
||||
&error_class, &error_code);
|
||||
}
|
||||
break;
|
||||
case OBJECT_ANALOG_OUTPUT:
|
||||
if (!Analog_Output_Valid_Instance(object_instance)) {
|
||||
error_class = ERROR_CLASS_OBJECT;
|
||||
error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
} else if (!property_found) {
|
||||
error_class = ERROR_CLASS_PROPERTY;
|
||||
error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
} else {
|
||||
len = Analog_Output_Encode_Property_APDU(
|
||||
&Temp_Buf[0],
|
||||
object_instance,
|
||||
temp_object_property,
|
||||
array_index,
|
||||
&error_class, &error_code);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
len = -1;
|
||||
error_class = ERROR_CLASS_OBJECT;
|
||||
error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE;
|
||||
break;
|
||||
}
|
||||
if (len < 0) {
|
||||
len = rpm_ack_encode_apdu_object_property_error(
|
||||
&Temp_Buf[0],
|
||||
error_class, error_code);
|
||||
apdu_len--;
|
||||
error = true;
|
||||
}
|
||||
if (!copy_apdu_data_buffer(&apdu_len, len, npdu_len)) {
|
||||
apdu_len = abort_encode_apdu(
|
||||
&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
}
|
||||
if (!error && property_found) {
|
||||
len = encode_closing_tag(&Temp_Buf[0], 4);
|
||||
if (!copy_apdu_data_buffer(&apdu_len, len, npdu_len)) {
|
||||
/* handle an individual property */
|
||||
application_data_len = Encode_Property_APDU(
|
||||
&Application_Buf[0],
|
||||
object_type,
|
||||
object_instance,
|
||||
object_property,
|
||||
array_index,
|
||||
&error_class, &error_code);
|
||||
if (application_data_len < 0) {
|
||||
len = rpm_ack_encode_apdu_object_property_error(
|
||||
&Temp_Buf[0],
|
||||
error_class, error_code);
|
||||
} else {
|
||||
len = rpm_ack_encode_apdu_object_property_value(
|
||||
&Temp_Buf[0],
|
||||
&Application_Buf[0],
|
||||
application_data_len);
|
||||
}
|
||||
copy_len = apdu_copy(
|
||||
&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
|
||||
apdu_len, len,
|
||||
sizeof(Handler_Transmit_Buffer));
|
||||
if (!copy_len) {
|
||||
apdu_len = abort_encode_apdu(
|
||||
&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
error = false;
|
||||
}
|
||||
/* check for closing tag */
|
||||
if (done) {
|
||||
len = rpm_ack_decode_object_end(
|
||||
&service_request[decode_len],
|
||||
service_len - decode_len);
|
||||
if (len == 1) {
|
||||
decode_len++;
|
||||
break;
|
||||
goto RPM_ABORT;
|
||||
}
|
||||
}
|
||||
} while(1);
|
||||
len = encode_closing_tag(&Temp_Buf[0], 1);
|
||||
if (!copy_apdu_data_buffer(&apdu_len, len, npdu_len)) {
|
||||
apdu_len = abort_encode_apdu(
|
||||
&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
break;
|
||||
}
|
||||
if (decode_len >= service_len) {
|
||||
break;
|
||||
}
|
||||
} while(1);
|
||||
}
|
||||
RPM_ABORT:
|
||||
pdu_len = apdu_len + npdu_len;
|
||||
bytes_sent = datalink_send_pdu(
|
||||
src,
|
||||
&npdu_data,
|
||||
&Handler_Transmit_Buffer[0],
|
||||
src,
|
||||
&npdu_data,
|
||||
&Handler_Transmit_Buffer[0],
|
||||
pdu_len);
|
||||
}
|
||||
|
||||
@@ -77,10 +77,10 @@ extern "C" {
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
|
||||
|
||||
|
||||
void handler_atomic_write_file(uint8_t * service_request,
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||
|
||||
void handler_reinitialize_device(uint8_t * service_request,
|
||||
uint16_t service_len,
|
||||
@@ -101,6 +101,13 @@ extern "C" {
|
||||
void handler_timesync_utc(uint8_t * service_request,
|
||||
uint16_t service_len, BACNET_ADDRESS * src);
|
||||
|
||||
void handler_read_property_multiple(
|
||||
uint8_t * service_request,
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
Reference in New Issue
Block a user