Replaced gotos in handler code (#109)
This commit is contained in:
@@ -86,14 +86,19 @@ void handler_read_property(uint8_t *service_request,
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
npdu_len = npdu_encode_pdu(
|
||||
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
|
||||
if (service_data->segmented_message) {
|
||||
if (npdu_len <= 0) {
|
||||
/* If 0 or negative, there were problems with the data or encoding. */
|
||||
len = BACNET_STATUS_ABORT;
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RP: npdu_encode_pdu error. Sending Abort!\n");
|
||||
#endif
|
||||
} else if (service_data->segmented_message) {
|
||||
/* we don't support segmentation - send an abort */
|
||||
len = BACNET_STATUS_ABORT;
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RP: Segmented message. Sending Abort!\n");
|
||||
#endif
|
||||
goto RP_FAILURE;
|
||||
}
|
||||
} else {
|
||||
len = rp_decode_service_request(service_request, service_len, &rpdata);
|
||||
#if PRINT_ENABLED
|
||||
if (len <= 0) {
|
||||
@@ -106,8 +111,7 @@ void handler_read_property(uint8_t *service_request,
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RP: Bad Encoding.\n");
|
||||
#endif
|
||||
goto RP_FAILURE;
|
||||
}
|
||||
} else {
|
||||
/* Test for case of indefinite Device object instance */
|
||||
if ((rpdata.object_type == OBJECT_DEVICE) &&
|
||||
(rpdata.object_instance == BACNET_MAX_INSTANCE)) {
|
||||
@@ -155,8 +159,9 @@ void handler_read_property(uint8_t *service_request,
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RP_FAILURE:
|
||||
if (error) {
|
||||
if (len == BACNET_STATUS_ABORT) {
|
||||
apdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
|
||||
|
||||
@@ -45,8 +45,20 @@
|
||||
|
||||
static uint8_t Temp_Buf[MAX_APDU] = { 0 };
|
||||
|
||||
/* Encodes the property APDU and returns the length,
|
||||
or sets the error, and returns -1 */
|
||||
/**
|
||||
* Encodes the property APDU and returns the length,
|
||||
* or sets the error, and returns -1.
|
||||
*
|
||||
* @param apdu Pointer to the APDU buffer.
|
||||
* @param pRequest Pointer to the request to encode.
|
||||
*
|
||||
* @return Bytes encoded or -1 on an error. The error code
|
||||
* may also be a negative return value from the called
|
||||
* handler of 'PropInfo.Handler' type from within
|
||||
* this function. The error code might be -2, if an
|
||||
* abort message has been encoded, because the APDU
|
||||
* was too small to fit the data.
|
||||
*/
|
||||
static int Encode_RR_payload(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest)
|
||||
{
|
||||
int apdu_len = -1;
|
||||
@@ -99,6 +111,15 @@ static int Encode_RR_payload(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest)
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the received ReadRange request and encode a response.
|
||||
*
|
||||
* @param service_request Pointer to the service request.
|
||||
* @param service_len Bytes valid in the service request.
|
||||
* @param src Pointer to the BACnet addresss.
|
||||
* @param service_data Pointer to the service data,
|
||||
* taken from the request.
|
||||
*/
|
||||
void handler_read_range(uint8_t *service_request,
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS *src,
|
||||
@@ -129,8 +150,7 @@ void handler_read_range(uint8_t *service_request,
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RR: Segmented message. Sending Abort!\n");
|
||||
#endif
|
||||
goto RR_ABORT;
|
||||
}
|
||||
} else {
|
||||
memset(&data, 0, sizeof(data)); /* start with blank canvas */
|
||||
len = rr_decode_service_request(service_request, service_len, &data);
|
||||
#if PRINT_ENABLED
|
||||
@@ -144,9 +164,7 @@ void handler_read_range(uint8_t *service_request,
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "RR: Bad Encoding. Sending Abort!\n");
|
||||
#endif
|
||||
goto RR_ABORT;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* assume that there is an error */
|
||||
error = true;
|
||||
len = Encode_RR_payload(&Temp_Buf[0], &data);
|
||||
@@ -180,7 +198,9 @@ void handler_read_range(uint8_t *service_request,
|
||||
#endif
|
||||
}
|
||||
}
|
||||
RR_ABORT:
|
||||
}
|
||||
}
|
||||
|
||||
pdu_len += len;
|
||||
#if PRINT_ENABLED
|
||||
bytes_sent =
|
||||
|
||||
Reference in New Issue
Block a user