converted COV to use new error, reject, abort method.
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include "apdu.h"
|
||||
#include "npdu.h"
|
||||
#include "abort.h"
|
||||
#include "reject.h"
|
||||
#include "cov.h"
|
||||
#include "tsm.h"
|
||||
/* demo objects */
|
||||
@@ -507,28 +508,29 @@ void handler_cov_subscribe(
|
||||
BACNET_SUBSCRIBE_COV_DATA cov_data;
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
int npdu_len = 0;
|
||||
int apdu_len = 0;
|
||||
BACNET_NPDU_DATA npdu_data;
|
||||
bool success = 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;
|
||||
bool error = false;
|
||||
|
||||
/* initialize a common abort code */
|
||||
cov_data.error_code = ABORT_REASON_SEGMENTATION_NOT_SUPPORTED;
|
||||
/* encode the NPDU portion of the packet */
|
||||
datalink_get_my_address(&my_address);
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len =
|
||||
npdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
|
||||
&npdu_data);
|
||||
if (service_data->segmented_message) {
|
||||
/* we don't support segmentation - send an abort */
|
||||
len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
len = BACNET_STATUS_ABORT;
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "SubscribeCOV: Segmented message. Sending Abort!\n");
|
||||
#endif
|
||||
error = true;
|
||||
goto COV_ABORT;
|
||||
}
|
||||
len =
|
||||
@@ -539,34 +541,56 @@ void handler_cov_subscribe(
|
||||
fprintf(stderr, "SubscribeCOV: Unable to decode Request!\n");
|
||||
#endif
|
||||
if (len < 0) {
|
||||
/* bad decoding - send an abort */
|
||||
len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, ABORT_REASON_OTHER, true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "SubscribeCOV: Bad decoding. Sending Abort!\n");
|
||||
#endif
|
||||
error = true;
|
||||
goto COV_ABORT;
|
||||
}
|
||||
success = cov_subscribe(src, &cov_data, &error_class, &error_code);
|
||||
cov_data.error_class = ERROR_CLASS_OBJECT;
|
||||
cov_data.error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||
success = cov_subscribe(src, &cov_data,
|
||||
&cov_data.error_class, &cov_data.error_code);
|
||||
if (success) {
|
||||
len =
|
||||
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||
apdu_len =
|
||||
encode_simple_ack(&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "SubscribeCOV: Sending Simple Ack!\n");
|
||||
#endif
|
||||
} else {
|
||||
len =
|
||||
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV,
|
||||
error_class, error_code);
|
||||
len = BACNET_STATUS_ERROR;
|
||||
error = true;
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "SubscribeCOV: Sending Error!\n");
|
||||
#endif
|
||||
}
|
||||
COV_ABORT:
|
||||
pdu_len += len;
|
||||
if (error) {
|
||||
if (len == BACNET_STATUS_ABORT) {
|
||||
apdu_len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
abort_convert_error_code(cov_data.error_code), true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "SubscribeCOV: Sending Abort!\n");
|
||||
#endif
|
||||
} else if (len == BACNET_STATUS_ERROR) {
|
||||
apdu_len =
|
||||
bacerror_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV,
|
||||
cov_data.error_class, cov_data.error_code);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "SubscribeCOV: Sending Error!\n");
|
||||
#endif
|
||||
} else if (len == BACNET_STATUS_REJECT) {
|
||||
apdu_len =
|
||||
reject_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
reject_convert_error_code(cov_data.error_code));
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "SubscribeCOV: Sending Reject!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
pdu_len = npdu_len + apdu_len;
|
||||
bytes_sent =
|
||||
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
|
||||
pdu_len);
|
||||
@@ -574,6 +598,8 @@ void handler_cov_subscribe(
|
||||
if (bytes_sent <= 0)
|
||||
fprintf(stderr, "SubscribeCOV: Failed to send PDU (%s)!\n",
|
||||
strerror(errno));
|
||||
#else
|
||||
bytes_sent = bytes_sent;
|
||||
#endif
|
||||
|
||||
return;
|
||||
|
||||
@@ -56,6 +56,8 @@ typedef struct BACnet_Subscribe_COV_Data {
|
||||
BACNET_PROPERTY_REFERENCE monitoredProperty;
|
||||
bool covIncrementPresent; /* true if present */
|
||||
float covIncrement; /* optional */
|
||||
BACNET_ERROR_CLASS error_class;
|
||||
BACNET_ERROR_CODE error_code;
|
||||
} BACNET_SUBSCRIBE_COV_DATA;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+38
-19
@@ -381,8 +381,10 @@ int cov_subscribe_decode_service_request(
|
||||
&len_value);
|
||||
len += decode_unsigned(&apdu[len], len_value, &decoded_value);
|
||||
data->subscriberProcessIdentifier = decoded_value;
|
||||
} else
|
||||
return -1;
|
||||
} else {
|
||||
data->error_code = ERROR_CODE_REJECT_INVALID_TAG;
|
||||
return BACNET_STATUS_REJECT;
|
||||
}
|
||||
/* tag 1 - monitoredObjectIdentifier */
|
||||
if (decode_is_context_tag(&apdu[len], 1)) {
|
||||
len +=
|
||||
@@ -392,8 +394,10 @@ int cov_subscribe_decode_service_request(
|
||||
decode_object_id(&apdu[len], &decoded_type,
|
||||
&data->monitoredObjectIdentifier.instance);
|
||||
data->monitoredObjectIdentifier.type = decoded_type;
|
||||
} else
|
||||
return -1;
|
||||
} else {
|
||||
data->error_code = ERROR_CODE_REJECT_INVALID_TAG;
|
||||
return BACNET_STATUS_REJECT;
|
||||
}
|
||||
/* optional parameters - if missing, means cancellation */
|
||||
if ((unsigned) len < apdu_len) {
|
||||
/* tag 2 - issueConfirmedNotifications - optional */
|
||||
@@ -415,8 +419,9 @@ int cov_subscribe_decode_service_request(
|
||||
&len_value);
|
||||
len += decode_unsigned(&apdu[len], len_value, &decoded_value);
|
||||
data->lifetime = decoded_value;
|
||||
} else
|
||||
} else {
|
||||
data->lifetime = 0;
|
||||
}
|
||||
} else {
|
||||
data->cancellationRequest = true;
|
||||
}
|
||||
@@ -528,8 +533,10 @@ int cov_subscribe_property_decode_service_request(
|
||||
&len_value);
|
||||
len += decode_unsigned(&apdu[len], len_value, &decoded_value);
|
||||
data->subscriberProcessIdentifier = decoded_value;
|
||||
} else
|
||||
return -1;
|
||||
} else {
|
||||
data->error_code = ERROR_CODE_REJECT_INVALID_TAG;
|
||||
return BACNET_STATUS_REJECT;
|
||||
}
|
||||
/* tag 1 - monitoredObjectIdentifier */
|
||||
if (decode_is_context_tag(&apdu[len], 1)) {
|
||||
len +=
|
||||
@@ -539,8 +546,10 @@ int cov_subscribe_property_decode_service_request(
|
||||
decode_object_id(&apdu[len], &decoded_type,
|
||||
&data->monitoredObjectIdentifier.instance);
|
||||
data->monitoredObjectIdentifier.type = decoded_type;
|
||||
} else
|
||||
return -2;
|
||||
} else {
|
||||
data->error_code = ERROR_CODE_REJECT_INVALID_TAG;
|
||||
return BACNET_STATUS_REJECT;
|
||||
}
|
||||
/* tag 2 - issueConfirmedNotifications - optional */
|
||||
if (decode_is_context_tag(&apdu[len], 2)) {
|
||||
data->cancellationRequest = false;
|
||||
@@ -550,8 +559,9 @@ int cov_subscribe_property_decode_service_request(
|
||||
data->issueConfirmedNotifications =
|
||||
decode_context_boolean(&apdu[len]);
|
||||
len++;
|
||||
} else
|
||||
} else {
|
||||
data->cancellationRequest = true;
|
||||
}
|
||||
/* tag 3 - lifetime - optional */
|
||||
if (decode_is_context_tag(&apdu[len], 3)) {
|
||||
len +=
|
||||
@@ -559,11 +569,14 @@ int cov_subscribe_property_decode_service_request(
|
||||
&len_value);
|
||||
len += decode_unsigned(&apdu[len], len_value, &decoded_value);
|
||||
data->lifetime = decoded_value;
|
||||
} else
|
||||
} else {
|
||||
data->lifetime = 0;
|
||||
}
|
||||
/* tag 4 - monitoredPropertyIdentifier */
|
||||
if (!decode_is_opening_tag_number(&apdu[len], 4))
|
||||
return -3;
|
||||
if (!decode_is_opening_tag_number(&apdu[len], 4)) {
|
||||
data->error_code = ERROR_CODE_REJECT_INVALID_TAG;
|
||||
return BACNET_STATUS_REJECT;
|
||||
}
|
||||
/* a tag number of 4 is not extended so only one octet */
|
||||
len++;
|
||||
/* the propertyIdentifier is tag 0 */
|
||||
@@ -574,8 +587,10 @@ int cov_subscribe_property_decode_service_request(
|
||||
len += decode_enumerated(&apdu[len], len_value, &property);
|
||||
data->monitoredProperty.propertyIdentifier =
|
||||
(BACNET_PROPERTY_ID) property;
|
||||
} else
|
||||
return -4;
|
||||
} else {
|
||||
data->error_code = ERROR_CODE_REJECT_INVALID_TAG;
|
||||
return BACNET_STATUS_REJECT;
|
||||
}
|
||||
/* the optional array index is tag 1 */
|
||||
if (decode_is_context_tag(&apdu[len], 1)) {
|
||||
len +=
|
||||
@@ -587,8 +602,10 @@ int cov_subscribe_property_decode_service_request(
|
||||
data->monitoredProperty.propertyArrayIndex = BACNET_ARRAY_ALL;
|
||||
}
|
||||
|
||||
if (!decode_is_closing_tag_number(&apdu[len], 4))
|
||||
return -5;
|
||||
if (!decode_is_closing_tag_number(&apdu[len], 4)) {
|
||||
data->error_code = ERROR_CODE_REJECT_INVALID_TAG;
|
||||
return BACNET_STATUS_REJECT;
|
||||
}
|
||||
/* a tag number of 4 is not extended so only one octet */
|
||||
len++;
|
||||
/* tag 5 - covIncrement - optional */
|
||||
@@ -598,8 +615,9 @@ int cov_subscribe_property_decode_service_request(
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len += decode_real(&apdu[len], &data->covIncrement);
|
||||
} else
|
||||
} else {
|
||||
data->covIncrementPresent = false;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
@@ -620,8 +638,9 @@ int ccov_notify_decode_apdu(
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
|
||||
if (!apdu)
|
||||
if (!apdu) {
|
||||
return -1;
|
||||
}
|
||||
/* optional checking - most likely was already done prior to this call */
|
||||
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
|
||||
return -2;
|
||||
|
||||
Reference in New Issue
Block a user