Folded error class and code into BACNET_READ_RANGE_DATA structure.

This commit is contained in:
petermcs
2010-02-15 11:41:23 +00:00
parent 786ddffc04
commit ecb1f2064f
7 changed files with 39 additions and 76 deletions
+19 -23
View File
@@ -41,23 +41,20 @@
static uint8_t Temp_Buf[MAX_APDU] = { 0 }; static uint8_t Temp_Buf[MAX_APDU] = { 0 };
static rr_info_function get_rr_info[MAX_BACNET_OBJECT_TYPE];
static get_rr_info_fn get_rr_info;
void handler_rr_object_set( void handler_rr_object_set(
BACNET_OBJECT_TYPE object_type, get_rr_info_fn pFunction1)
rr_info_function pFunction1)
{ {
if (object_type < MAX_BACNET_OBJECT_TYPE) get_rr_info = pFunction1;
get_rr_info[object_type] = pFunction1;
} }
/* Encodes the property APDU and returns the length, /* Encodes the property APDU and returns the length,
or sets the error, and returns -1 */ or sets the error, and returns -1 */
int Encode_RR_payload( int Encode_RR_payload(
uint8_t * apdu, uint8_t * apdu,
BACNET_READ_RANGE_DATA * pRequest, BACNET_READ_RANGE_DATA * pRequest)
BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code)
{ {
int apdu_len = -1; int apdu_len = -1;
rr_info_function info_fn_ptr = NULL; rr_info_function info_fn_ptr = NULL;
@@ -65,35 +62,34 @@ int Encode_RR_payload(
RR_PROP_INFO PropInfo; RR_PROP_INFO PropInfo;
/* initialize the default return values */ /* initialize the default return values */
*error_class = ERROR_CLASS_SERVICES; pRequest->error_class = ERROR_CLASS_SERVICES;
*error_code = ERROR_CODE_OTHER; pRequest->error_code = ERROR_CODE_OTHER;
/* handle each object type */ /* handle each object type */
if (pRequest->object_type < MAX_BACNET_OBJECT_TYPE) info_fn_ptr = *get_rr_info(pRequest->object_type);
info_fn_ptr = get_rr_info[pRequest->object_type];
if ((info_fn_ptr != NULL) && (info_fn_ptr(pRequest->object_instance, pRequest->object_property, &PropInfo, error_class, error_code) != false)) { if ((get_rr_info != NULL) && (info_fn_ptr(pRequest->object_instance, pRequest->object_property, &PropInfo, &pRequest->error_class, &pRequest->error_code) != false)) {
/* We try and do some of the more generic error checking here to cut down on duplication of effort */ /* We try and do some of the more generic error checking here to cut down on duplication of effort */
if((pRequest->RequestType == RR_BY_POSITION) && (pRequest->Range.RefIndex == 0)) {/* First index is 1 so can't accept 0 */ if((pRequest->RequestType == RR_BY_POSITION) && (pRequest->Range.RefIndex == 0)) {/* First index is 1 so can't accept 0 */
*error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */ pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
} else if(((PropInfo.RequestTypes & RR_ARRAY_OF_LISTS) == 0) && (pRequest->array_index != 0) && (pRequest->array_index != BACNET_ARRAY_ALL)) { } else if(((PropInfo.RequestTypes & RR_ARRAY_OF_LISTS) == 0) && (pRequest->array_index != 0) && (pRequest->array_index != BACNET_ARRAY_ALL)) {
/* Array access attempted on a non array property */ /* Array access attempted on a non array property */
*error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
} }
else if((pRequest->RequestType != RR_READ_ALL) && ((PropInfo.RequestTypes & pRequest->RequestType) == 0)) { else if((pRequest->RequestType != RR_READ_ALL) && ((PropInfo.RequestTypes & pRequest->RequestType) == 0)) {
/* By Time or By Sequence not supported - By Position is always required */ /* By Time or By Sequence not supported - By Position is always required */
*error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */ pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
} }
else if((pRequest->Count == 0) && (pRequest->RequestType != RR_READ_ALL)) { /* Count cannot be zero */ else if((pRequest->Count == 0) && (pRequest->RequestType != RR_READ_ALL)) { /* Count cannot be zero */
*error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */ pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */
} }
else if(PropInfo.Handler != NULL) { else if(PropInfo.Handler != NULL) {
apdu_len = PropInfo.Handler(apdu, pRequest, error_class, error_code); apdu_len = PropInfo.Handler(apdu, pRequest);
} }
} else { } else {
/* Either we don't support RR for this property yet or it is not a list or array of lists */ /* Either we don't support RR for this property yet or it is not a list or array of lists */
*error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST; pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST;
} }
return apdu_len; return apdu_len;
@@ -111,10 +107,10 @@ void handler_read_range(
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
bool error = false; bool error = false;
int bytes_sent = 0; int bytes_sent = 0;
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
BACNET_ADDRESS my_address; BACNET_ADDRESS my_address;
data.error_class = ERROR_CLASS_OBJECT;
data.error_code = ERROR_CODE_UNKNOWN_OBJECT;
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
@@ -151,7 +147,7 @@ void handler_read_range(
/* assume that there is an error */ /* assume that there is an error */
error = true; error = true;
len = Encode_RR_payload(&Temp_Buf[0], &data, &error_class, &error_code); len = Encode_RR_payload(&Temp_Buf[0], &data);
if (len >= 0) { if (len >= 0) {
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
data.application_data = &Temp_Buf[0]; data.application_data = &Temp_Buf[0];
@@ -179,7 +175,7 @@ void handler_read_range(
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_RANGE, service_data->invoke_id, SERVICE_CONFIRMED_READ_RANGE,
error_class, error_code); data.error_class, data.error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "RR: Sending Error!\n"); fprintf(stderr, "RR: Sending Error!\n");
#endif #endif
+7 -24
View File
@@ -1096,9 +1096,7 @@ void TL_Local_Time_To_BAC(BACNET_DATE_TIME *DestTime, time_t SourceTime)
int rr_trend_log_encode( int rr_trend_log_encode(
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest)
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{ {
/* Initialise result flags to all false */ /* Initialise result flags to all false */
bitstring_init(&pRequest->ResultFlags); bitstring_init(&pRequest->ResultFlags);
@@ -1112,11 +1110,11 @@ int rr_trend_log_encode(
return(0); return(0);
if((pRequest->RequestType == RR_BY_POSITION) || (pRequest->RequestType == RR_READ_ALL)) if((pRequest->RequestType == RR_BY_POSITION) || (pRequest->RequestType == RR_READ_ALL))
return(TL_encode_by_position(apdu, pRequest, error_class, error_code)); return(TL_encode_by_position(apdu, pRequest));
else if(pRequest->RequestType == RR_BY_SEQUENCE) else if(pRequest->RequestType == RR_BY_SEQUENCE)
return(TL_encode_by_sequence(apdu, pRequest, error_class, error_code)); return(TL_encode_by_sequence(apdu, pRequest));
return(TL_encode_by_time(apdu, pRequest, error_class, error_code)); return(TL_encode_by_time(apdu, pRequest));
} }
/**************************************************************************** /****************************************************************************
@@ -1127,9 +1125,7 @@ int rr_trend_log_encode(
int TL_encode_by_position( int TL_encode_by_position(
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest)
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{ {
int iLen = 0; int iLen = 0;
int32_t iTemp = 0; int32_t iTemp = 0;
@@ -1141,9 +1137,6 @@ int TL_encode_by_position(
uint32_t uiTarget = 0; /* Last entry we are required to encode */ uint32_t uiTarget = 0; /* Last entry we are required to encode */
uint32_t uiRemaining = 0; /* Amount of unused space in packet */ uint32_t uiRemaining = 0; /* Amount of unused space in packet */
/* unused parameters */
error_class = error_class;
error_code = error_code;
/* See how much space we have */ /* See how much space we have */
uiRemaining = MAX_APDU - pRequest->Overhead; uiRemaining = MAX_APDU - pRequest->Overhead;
CurrentLog = &LogInfo[pRequest->object_instance]; CurrentLog = &LogInfo[pRequest->object_instance];
@@ -1233,9 +1226,7 @@ return(iLen);
int TL_encode_by_sequence( int TL_encode_by_sequence(
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest)
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{ {
int iLen = 0; int iLen = 0;
int32_t iTemp = 0; int32_t iTemp = 0;
@@ -1253,9 +1244,6 @@ int TL_encode_by_sequence(
bool bWrapReq = false; /* Has request sequence range spanned the max for uint32_t? */ bool bWrapReq = false; /* Has request sequence range spanned the max for uint32_t? */
bool bWrapLog = false; /* Has log sequence range spanned the max for uint32_t? */ bool bWrapLog = false; /* Has log sequence range spanned the max for uint32_t? */
/* unused parameters */
error_class = error_class;
error_code = error_code;
/* See how much space we have */ /* See how much space we have */
uiRemaining = MAX_APDU - pRequest->Overhead; uiRemaining = MAX_APDU - pRequest->Overhead;
CurrentLog = &LogInfo[pRequest->object_instance]; CurrentLog = &LogInfo[pRequest->object_instance];
@@ -1369,9 +1357,7 @@ int TL_encode_by_sequence(
int TL_encode_by_time( int TL_encode_by_time(
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest)
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{ {
int iLen = 0; int iLen = 0;
int32_t iTemp = 0; int32_t iTemp = 0;
@@ -1385,9 +1371,6 @@ int TL_encode_by_time(
uint32_t uiFirstSeq = 0; /* Sequence number for 1st record in log */ uint32_t uiFirstSeq = 0; /* Sequence number for 1st record in log */
time_t tRefTime = 0; /* The time from the request in local format */ time_t tRefTime = 0; /* The time from the request in local format */
/* unused parameters */
error_class = error_class;
error_code = error_code;
/* See how much space we have */ /* See how much space we have */
uiRemaining = MAX_APDU - pRequest->Overhead; uiRemaining = MAX_APDU - pRequest->Overhead;
CurrentLog = &LogInfo[pRequest->object_instance]; CurrentLog = &LogInfo[pRequest->object_instance];
+1 -3
View File
@@ -96,9 +96,7 @@ extern "C" {
int rr_address_list_encode( int rr_address_list_encode(
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest);
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code);
void address_set_device_TTL( void address_set_device_TTL(
uint32_t device_id, uint32_t device_id,
+1 -2
View File
@@ -83,8 +83,7 @@ extern "C" {
read_property_function pFunction); read_property_function pFunction);
void handler_rr_object_set( void handler_rr_object_set(
BACNET_OBJECT_TYPE object_type, get_rr_info_fn pFunction1);
rr_info_function pFunction1);
void handler_read_property_ack( void handler_read_property_ack(
uint8_t * service_request, uint8_t * service_request,
+6 -6
View File
@@ -56,6 +56,8 @@ typedef struct BACnet_Read_Range_Data {
BACNET_DATE_TIME RefTime; BACNET_DATE_TIME RefTime;
} Range; } Range;
int32_t Count; /* SIGNED value as +ve vs -ve is important */ int32_t Count; /* SIGNED value as +ve vs -ve is important */
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
} BACNET_READ_RANGE_DATA; } BACNET_READ_RANGE_DATA;
/* Defines to indicate which type of read range request it is /* Defines to indicate which type of read range request it is
@@ -108,15 +110,11 @@ typedef enum {
1. A pointer to a buffer of at least MAX_APDU bytes to build the response in. 1. A pointer to a buffer of at least MAX_APDU bytes to build the response in.
2. A pointer to a BACNET_READ_RANGE_DATA structure with all the request 2. A pointer to a BACNET_READ_RANGE_DATA structure with all the request
information in it. The function is responsible for applying the request information in it. The function is responsible for applying the request
to the property in question and returning the response. to the property in question and returning the response. */
3/4. pointers to Error Class and Error Code values to write to in the
event of a failure. */
typedef int (*rr_handler_function) ( typedef int (*rr_handler_function) (
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest);
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code);
/* Structure to return the type of requests a given object property can /* Structure to return the type of requests a given object property can
* accept and the address of the function to handle the request */ * accept and the address of the function to handle the request */
@@ -135,6 +133,8 @@ typedef bool (*rr_info_function) (
BACNET_ERROR_CLASS *error_class, /* Somewhere to write error responses to */ BACNET_ERROR_CLASS *error_class, /* Somewhere to write error responses to */
BACNET_ERROR_CODE *error_code); BACNET_ERROR_CODE *error_code);
typedef rr_info_function (*get_rr_info_fn) (
BACNET_OBJECT_TYPE object_type);
int rr_encode_apdu( int rr_encode_apdu(
uint8_t * apdu, uint8_t * apdu,
+4 -12
View File
@@ -86,21 +86,15 @@ extern "C" {
int TL_encode_by_position( int TL_encode_by_position(
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest);
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code);
int TL_encode_by_sequence( int TL_encode_by_sequence(
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest);
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code);
int TL_encode_by_time( int TL_encode_by_time(
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest);
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code);
bool TrendLogGetRRInfo( bool TrendLogGetRRInfo(
uint32_t Object, /* Which particular object */ uint32_t Object, /* Which particular object */
@@ -111,9 +105,7 @@ extern "C" {
int rr_trend_log_encode( int rr_trend_log_encode(
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest);
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code);
void trend_log_timer( void trend_log_timer(
uint16_t uSeconds); uint16_t uSeconds);
+1 -6
View File
@@ -664,9 +664,7 @@ int address_list_encode(
int rr_address_list_encode( int rr_address_list_encode(
uint8_t *apdu, uint8_t *apdu,
BACNET_READ_RANGE_DATA *pRequest, BACNET_READ_RANGE_DATA *pRequest)
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{ {
int iLen = 0; int iLen = 0;
int32_t iTemp = 0; int32_t iTemp = 0;
@@ -679,9 +677,6 @@ int rr_address_list_encode(
uint32_t uiTarget = 0; /* Last entry we are required to encode */ uint32_t uiTarget = 0; /* Last entry we are required to encode */
uint32_t uiRemaining = 0; /* Amount of unused space in packet */ uint32_t uiRemaining = 0; /* Amount of unused space in packet */
/* unused parameters */
error_class = error_class;
error_code = error_code;
/* Initialise result flags to all false */ /* Initialise result flags to all false */
bitstring_init(&pRequest->ResultFlags); bitstring_init(&pRequest->ResultFlags);
bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, false); bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, false);