From ecb1f2064f1cfefdede571dd5d0647bea52af8ee Mon Sep 17 00:00:00 2001 From: petermcs Date: Mon, 15 Feb 2010 11:41:23 +0000 Subject: [PATCH] Folded error class and code into BACNET_READ_RANGE_DATA structure. --- bacnet-stack/demo/handler/h_rr.c | 42 +++++++++++++---------------- bacnet-stack/demo/object/trendlog.c | 31 +++++---------------- bacnet-stack/include/address.h | 4 +-- bacnet-stack/include/handlers.h | 3 +-- bacnet-stack/include/readrange.h | 12 ++++----- bacnet-stack/include/trendlog.h | 16 +++-------- bacnet-stack/src/address.c | 7 +---- 7 files changed, 39 insertions(+), 76 deletions(-) diff --git a/bacnet-stack/demo/handler/h_rr.c b/bacnet-stack/demo/handler/h_rr.c index b1e6745a..456e02da 100644 --- a/bacnet-stack/demo/handler/h_rr.c +++ b/bacnet-stack/demo/handler/h_rr.c @@ -41,23 +41,20 @@ 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( - BACNET_OBJECT_TYPE object_type, - rr_info_function pFunction1) + get_rr_info_fn pFunction1) { - if (object_type < MAX_BACNET_OBJECT_TYPE) - get_rr_info[object_type] = pFunction1; + get_rr_info = pFunction1; } /* Encodes the property APDU and returns the length, or sets the error, and returns -1 */ int Encode_RR_payload( uint8_t * apdu, - BACNET_READ_RANGE_DATA * pRequest, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code) + BACNET_READ_RANGE_DATA * pRequest) { int apdu_len = -1; rr_info_function info_fn_ptr = NULL; @@ -65,35 +62,34 @@ int Encode_RR_payload( RR_PROP_INFO PropInfo; /* initialize the default return values */ - *error_class = ERROR_CLASS_SERVICES; - *error_code = ERROR_CODE_OTHER; + pRequest->error_class = ERROR_CLASS_SERVICES; + pRequest->error_code = ERROR_CODE_OTHER; /* 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 */ 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)) { /* 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)) { /* 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 */ - *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) { - apdu_len = PropInfo.Handler(apdu, pRequest, error_class, error_code); + apdu_len = PropInfo.Handler(apdu, pRequest); } } else { /* 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; @@ -111,10 +107,10 @@ void handler_read_range( BACNET_NPDU_DATA npdu_data; bool error = false; 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; + data.error_class = ERROR_CLASS_OBJECT; + data.error_code = ERROR_CODE_UNKNOWN_OBJECT; /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); @@ -151,7 +147,7 @@ void handler_read_range( /* assume that there is an error */ 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) { /* encode the APDU portion of the packet */ data.application_data = &Temp_Buf[0]; @@ -179,7 +175,7 @@ void handler_read_range( len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_READ_RANGE, - error_class, error_code); + data.error_class, data.error_code); #if PRINT_ENABLED fprintf(stderr, "RR: Sending Error!\n"); #endif diff --git a/bacnet-stack/demo/object/trendlog.c b/bacnet-stack/demo/object/trendlog.c index b1a53c04..fae1575f 100644 --- a/bacnet-stack/demo/object/trendlog.c +++ b/bacnet-stack/demo/object/trendlog.c @@ -1096,9 +1096,7 @@ void TL_Local_Time_To_BAC(BACNET_DATE_TIME *DestTime, time_t SourceTime) int rr_trend_log_encode( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code) + BACNET_READ_RANGE_DATA *pRequest) { /* Initialise result flags to all false */ bitstring_init(&pRequest->ResultFlags); @@ -1112,11 +1110,11 @@ int rr_trend_log_encode( return(0); 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) - 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( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code) + BACNET_READ_RANGE_DATA *pRequest) { int iLen = 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 uiRemaining = 0; /* Amount of unused space in packet */ - /* unused parameters */ - error_class = error_class; - error_code = error_code; /* See how much space we have */ uiRemaining = MAX_APDU - pRequest->Overhead; CurrentLog = &LogInfo[pRequest->object_instance]; @@ -1233,9 +1226,7 @@ return(iLen); int TL_encode_by_sequence( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code) + BACNET_READ_RANGE_DATA *pRequest) { int iLen = 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 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 */ uiRemaining = MAX_APDU - pRequest->Overhead; CurrentLog = &LogInfo[pRequest->object_instance]; @@ -1369,9 +1357,7 @@ int TL_encode_by_sequence( int TL_encode_by_time( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code) + BACNET_READ_RANGE_DATA *pRequest) { int iLen = 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 */ 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 */ uiRemaining = MAX_APDU - pRequest->Overhead; CurrentLog = &LogInfo[pRequest->object_instance]; diff --git a/bacnet-stack/include/address.h b/bacnet-stack/include/address.h index 7113d340..2437f601 100644 --- a/bacnet-stack/include/address.h +++ b/bacnet-stack/include/address.h @@ -96,9 +96,7 @@ extern "C" { int rr_address_list_encode( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code); + BACNET_READ_RANGE_DATA *pRequest); void address_set_device_TTL( uint32_t device_id, diff --git a/bacnet-stack/include/handlers.h b/bacnet-stack/include/handlers.h index e429b6a5..a2de9a4e 100644 --- a/bacnet-stack/include/handlers.h +++ b/bacnet-stack/include/handlers.h @@ -83,8 +83,7 @@ extern "C" { read_property_function pFunction); void handler_rr_object_set( - BACNET_OBJECT_TYPE object_type, - rr_info_function pFunction1); + get_rr_info_fn pFunction1); void handler_read_property_ack( uint8_t * service_request, diff --git a/bacnet-stack/include/readrange.h b/bacnet-stack/include/readrange.h index 27342e7a..8be7efd5 100644 --- a/bacnet-stack/include/readrange.h +++ b/bacnet-stack/include/readrange.h @@ -56,6 +56,8 @@ typedef struct BACnet_Read_Range_Data { BACNET_DATE_TIME RefTime; } Range; 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; /* 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. 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 - 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. */ + to the property in question and returning the response. */ typedef int (*rr_handler_function) ( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code); + BACNET_READ_RANGE_DATA *pRequest); /* Structure to return the type of requests a given object property can * 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_CODE *error_code); +typedef rr_info_function (*get_rr_info_fn) ( + BACNET_OBJECT_TYPE object_type); int rr_encode_apdu( uint8_t * apdu, diff --git a/bacnet-stack/include/trendlog.h b/bacnet-stack/include/trendlog.h index 4609d5db..9ebc97c0 100644 --- a/bacnet-stack/include/trendlog.h +++ b/bacnet-stack/include/trendlog.h @@ -86,21 +86,15 @@ extern "C" { int TL_encode_by_position( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code); + BACNET_READ_RANGE_DATA *pRequest); int TL_encode_by_sequence( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code); + BACNET_READ_RANGE_DATA *pRequest); int TL_encode_by_time( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code); + BACNET_READ_RANGE_DATA *pRequest); bool TrendLogGetRRInfo( uint32_t Object, /* Which particular object */ @@ -111,9 +105,7 @@ extern "C" { int rr_trend_log_encode( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code); + BACNET_READ_RANGE_DATA *pRequest); void trend_log_timer( uint16_t uSeconds); diff --git a/bacnet-stack/src/address.c b/bacnet-stack/src/address.c index 849d2a2e..f501f530 100644 --- a/bacnet-stack/src/address.c +++ b/bacnet-stack/src/address.c @@ -664,9 +664,7 @@ int address_list_encode( int rr_address_list_encode( uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code) + BACNET_READ_RANGE_DATA *pRequest) { int iLen = 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 uiRemaining = 0; /* Amount of unused space in packet */ - /* unused parameters */ - error_class = error_class; - error_code = error_code; /* Initialise result flags to all false */ bitstring_init(&pRequest->ResultFlags); bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, false);