Added a PRINT_ENABLED define to allow small embedded devices without print capability to use some functions in this module.
This commit is contained in:
@@ -55,6 +55,7 @@ void handler_device_communication_control(uint8_t * service_request,
|
|||||||
/* decode the service request only */
|
/* decode the service request only */
|
||||||
len = dcc_decode_service_request(service_request,
|
len = dcc_decode_service_request(service_request,
|
||||||
service_len, &timeDuration, &state, &password);
|
service_len, &timeDuration, &state, &password);
|
||||||
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "DeviceCommunicationControl!\n");
|
fprintf(stderr, "DeviceCommunicationControl!\n");
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
@@ -64,6 +65,7 @@ void handler_device_communication_control(uint8_t * service_request,
|
|||||||
else
|
else
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Unable to decode request!\n");
|
"Unable to decode request!\n");
|
||||||
|
#endif
|
||||||
/* prepare a reply */
|
/* prepare a reply */
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
/* encode the NPDU portion of the packet */
|
/* encode the NPDU portion of the packet */
|
||||||
@@ -73,26 +75,34 @@ void handler_device_communication_control(uint8_t * service_request,
|
|||||||
if (len == -1) {
|
if (len == -1) {
|
||||||
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id, ABORT_REASON_OTHER);
|
service_data->invoke_id, ABORT_REASON_OTHER);
|
||||||
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Sending Abort - could not decode.\n");
|
"Sending Abort - could not decode.\n");
|
||||||
|
#endif
|
||||||
} else if (service_data->segmented_message) {
|
} else if (service_data->segmented_message) {
|
||||||
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
||||||
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Sending Abort - segmented message.\n");
|
"Sending Abort - segmented message.\n");
|
||||||
|
#endif
|
||||||
} else if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) {
|
} else if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) {
|
||||||
pdu_len += reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
pdu_len += reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
|
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
|
||||||
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Sending Reject - undefined enumeration\n");
|
"Sending Reject - undefined enumeration\n");
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if (characterstring_ansi_same(&password, My_Password)) {
|
if (characterstring_ansi_same(&password, My_Password)) {
|
||||||
pdu_len += encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
pdu_len += encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
|
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
|
||||||
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Sending Simple Ack!\n");
|
"Sending Simple Ack!\n");
|
||||||
|
#endif
|
||||||
dcc_set_status_duration(state, timeDuration);
|
dcc_set_status_duration(state, timeDuration);
|
||||||
} else {
|
} else {
|
||||||
pdu_len +=
|
pdu_len +=
|
||||||
@@ -100,16 +110,20 @@ void handler_device_communication_control(uint8_t * service_request,
|
|||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
|
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
|
||||||
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
|
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
|
||||||
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"DeviceCommunicationControl: "
|
"DeviceCommunicationControl: "
|
||||||
"Sending Error - password failure.\n");
|
"Sending Error - password failure.\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bytes_sent = datalink_send_pdu(src, /* destination address */
|
bytes_sent = datalink_send_pdu(src, /* destination address */
|
||||||
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
|
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
|
||||||
|
#if PRINT_ENABLED
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Failed to send PDU (%s)!\n", strerror(errno));
|
"Failed to send PDU (%s)!\n", strerror(errno));
|
||||||
|
#endif
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user