indented.

This commit is contained in:
skarg
2007-11-29 16:39:48 +00:00
parent 06d23fcf1f
commit 1477603af6
123 changed files with 1994 additions and 1688 deletions
+9 -13
View File
@@ -72,8 +72,7 @@ static void MyErrorHandler(
/* FIXME: verify src and invoke id */
(void) src;
(void) invoke_id;
printf("BACnet Error: %s: %s\r\n",
bactext_error_class_name(error_class),
printf("BACnet Error: %s: %s\r\n", bactext_error_class_name(error_class),
bactext_error_code_name(error_code));
Error_Detected = true;
}
@@ -129,8 +128,7 @@ static void Init_Service_Handlers(
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
handler_read_property);
/* handle communication so we can shutup when asked */
apdu_set_confirmed_handler
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control);
/* handle the ack coming back */
apdu_set_confirmed_simple_ack_handler
@@ -162,11 +160,8 @@ int main(
/* note: priority 16 and 0 should produce the same end results... */
printf("Usage: %s device-instance state timeout [password]\r\n"
"Send BACnet DeviceCommunicationControl service to device.\r\n"
"\r\n"
"The device-instance can be 0 to %d.\r\n"
"Possible state values:\r\n"
" 0=enable\r\n"
" 1=disable\r\n"
"\r\n" "The device-instance can be 0 to %d.\r\n"
"Possible state values:\r\n" " 0=enable\r\n" " 1=disable\r\n"
" 2=disable-initiation\r\n"
"The timeout can be 0 for infinite, or a value in minutes for disable.\r\n"
"The optional password is a character string of 1 to 20 characters.\r\n"
@@ -196,8 +191,8 @@ int main(
return 1;
/* configure the timeout values */
last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries();
timeout_seconds =
(Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */
@@ -218,8 +213,9 @@ int main(
if (Error_Detected)
break;
/* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address);
found =
address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) {
if (invoke_id == 0) {
invoke_id =
+10 -9
View File
@@ -79,8 +79,7 @@ static void MyErrorHandler(
(void) src;
(void) invoke_id;
#if 1
printf("BACnet Error: %s: %s\r\n",
bactext_error_class_name(error_class),
printf("BACnet Error: %s: %s\r\n", bactext_error_class_name(error_class),
bactext_error_code_name(error_code));
#else
(void) error_class;
@@ -151,7 +150,8 @@ void PrintReadPropertyData(
application_data_len = data->application_data_len;
/* value? loop until all of the len is gone... */
for (;;) {
len = bacapp_decode_application_data(application_data,
len =
bacapp_decode_application_data(application_data,
(uint8_t) application_data_len, &value);
if (first_value && (len < application_data_len)) {
first_value = false;
@@ -233,8 +233,8 @@ static uint8_t Read_Properties(
if (pRequired[index] != -1) {
printf(" %s: ", bactext_property_name(pRequired[index]));
invoke_id = Send_Read_Property_Request(device_instance,
OBJECT_DEVICE,
invoke_id =
Send_Read_Property_Request(device_instance, OBJECT_DEVICE,
device_instance, pRequired[index], BACNET_ARRAY_ALL);
if (invoke_id) {
index++;
@@ -282,8 +282,8 @@ int main(
return 1;
/* configure the timeout values */
last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries();
timeout_seconds =
(Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
printf("List of Objects in test device:\r\n");
@@ -305,8 +305,9 @@ int main(
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
}
/* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address);
found =
address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) {
/* invoke ID is set to zero when it is not in use */
if (invoke_id == 0) {
+16 -12
View File
@@ -117,12 +117,14 @@ void handler_atomic_read_file(
/* 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_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED
fprintf(stderr, "ARF: Segmented Message. Sending Abort!\n");
#endif
@@ -131,7 +133,8 @@ void handler_atomic_read_file(
len = arf_decode_service_request(service_request, service_len, &data);
/* bad decoding - send an abort */
if (len < 0) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
@@ -151,8 +154,8 @@ void handler_atomic_read_file(
data.type.stream.requestedOctetCount);
#endif
len =
arf_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
} else {
error = true;
error_class = ERROR_CLASS_OBJECT;
@@ -185,13 +188,14 @@ void handler_atomic_read_file(
if (error) {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_READ_FILE,
error_class, error_code);
}
ARF_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+2 -2
View File
@@ -73,8 +73,8 @@ void handler_atomic_read_file_ack(
if (pFilename) {
pFile = fopen(pFilename, "rb");
if (pFile) {
(void) fseek(pFile,
data.type.stream.fileStartPosition, SEEK_SET);
(void) fseek(pFile, data.type.stream.fileStartPosition,
SEEK_SET);
if (fwrite(octetstring_value(&data.fileData),
octetstring_length(&data.fileData), 1,
pFile) != 1) {
+16 -12
View File
@@ -95,12 +95,14 @@ void handler_atomic_write_file(
/* 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_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED
fprintf(stderr, "Segmented Message. Sending Abort!\n");
#endif
@@ -109,7 +111,8 @@ void handler_atomic_write_file(
len = awf_decode_service_request(service_request, service_len, &data);
/* bad decoding - send an abort */
if (len < 0) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
@@ -127,8 +130,8 @@ void handler_atomic_write_file(
octetstring_length(&data.fileData));
#endif
len =
awf_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
awf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
} else {
error = true;
error_class = ERROR_CLASS_OBJECT;
@@ -150,13 +153,14 @@ void handler_atomic_write_file(
if (error) {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_READ_FILE,
error_class, error_code);
}
AWF_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+34 -23
View File
@@ -58,56 +58,65 @@ void handler_device_communication_control(
/* encode the NPDU portion of the reply packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
#if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl!\n");
#endif
if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: "
fprintf(stderr,
"DeviceCommunicationControl: "
"Sending Abort - segmented message.\n");
#endif
goto DCC_ABORT;
}
/* decode the service request only */
len = dcc_decode_service_request(service_request,
service_len, &timeDuration, &state, &password);
len =
dcc_decode_service_request(service_request, service_len, &timeDuration,
&state, &password);
#if PRINT_ENABLED
if (len > 0)
fprintf(stderr, "DeviceCommunicationControl: "
"timeout=%u state=%u password=%s\n",
(unsigned) timeDuration,
(unsigned) state, characterstring_value(&password));
fprintf(stderr,
"DeviceCommunicationControl: " "timeout=%u state=%u password=%s\n",
(unsigned) timeDuration, (unsigned) state,
characterstring_value(&password));
#endif
/* bad decoding or something we didn't understand - send an abort */
if (len < 0) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: "
fprintf(stderr,
"DeviceCommunicationControl: "
"Sending Abort - could not decode.\n");
#endif
goto DCC_ABORT;
}
if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) {
len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: "
fprintf(stderr,
"DeviceCommunicationControl: "
"Sending Reject - undefined enumeration\n");
#endif
} else {
if (characterstring_ansi_same(&password, My_Password)) {
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
#if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl: "
"Sending Simple Ack!\n");
fprintf(stderr,
"DeviceCommunicationControl: " "Sending Simple Ack!\n");
#endif
dcc_set_status_duration(state, timeDuration);
} else {
@@ -125,12 +134,14 @@ void handler_device_communication_control(
}
DCC_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "DeviceCommunicationControl: "
"Failed to send PDU (%s)!\n", strerror(errno));
fprintf(stderr,
"DeviceCommunicationControl: " "Failed to send PDU (%s)!\n",
strerror(errno));
#endif
return;
+6 -4
View File
@@ -44,8 +44,9 @@ void handler_i_am_add(
uint16_t vendor_id = 0;
(void) service_len;
len = iam_decode_service_request(service_request,
&device_id, &max_apdu, &segmentation, &vendor_id);
len =
iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
#if PRINT_ENABLED
fprintf(stderr, "Received I-Am Request");
#endif
@@ -75,8 +76,9 @@ void handler_i_am_bind(
uint16_t vendor_id = 0;
(void) service_len;
len = iam_decode_service_request(service_request,
&device_id, &max_apdu, &segmentation, &vendor_id);
len =
iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
/* only add address if requested to bind */
address_add_binding(device_id, max_apdu, src);
+20 -14
View File
@@ -58,15 +58,17 @@ void handler_reinitialize_device(
/* 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_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
#if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice!\n");
#endif
if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED
fprintf(stderr,
"ReinitializeDevice: Sending Abort - segmented message.\n");
@@ -74,8 +76,9 @@ void handler_reinitialize_device(
goto RD_ABORT;
}
/* decode the service request only */
len = rd_decode_service_request(service_request,
service_len, &state, &their_password);
len =
rd_decode_service_request(service_request, service_len, &state,
&their_password);
#if PRINT_ENABLED
if (len > 0)
fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n",
@@ -85,7 +88,8 @@ void handler_reinitialize_device(
#endif
/* bad decoding or something we didn't understand - send an abort */
if (len < 0) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr,
@@ -95,7 +99,8 @@ void handler_reinitialize_device(
}
/* check the data from the request */
if (state >= MAX_BACNET_REINITIALIZED_STATE) {
len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED
fprintf(stderr,
@@ -104,7 +109,8 @@ void handler_reinitialize_device(
} else {
characterstring_init_ansi(&My_Password, Password);
if (characterstring_same(&their_password, &My_Password)) {
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
len =
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE);
#if PRINT_ENABLED
@@ -117,8 +123,7 @@ void handler_reinitialize_device(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
service_data->invoke_id, SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
#if PRINT_ENABLED
fprintf(stderr,
@@ -128,8 +133,9 @@ void handler_reinitialize_device(
}
RD_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
+63 -47
View File
@@ -72,78 +72,88 @@ int Encode_Property_APDU(
switch (object_type) {
case OBJECT_DEVICE:
if (Device_Valid_Object_Instance_Number(object_instance)) {
apdu_len = Device_Encode_Property_APDU(&apdu[0],
property, array_index, error_class, error_code);
apdu_len =
Device_Encode_Property_APDU(&apdu[0], property,
array_index, error_class, error_code);
}
break;
case OBJECT_ANALOG_INPUT:
if (Analog_Input_Valid_Instance(object_instance)) {
apdu_len = Analog_Input_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Analog_Input_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_ANALOG_OUTPUT:
if (Analog_Output_Valid_Instance(object_instance)) {
apdu_len = Analog_Output_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Analog_Output_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_ANALOG_VALUE:
if (Analog_Value_Valid_Instance(object_instance)) {
apdu_len = Analog_Value_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Analog_Value_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_BINARY_INPUT:
if (Binary_Input_Valid_Instance(object_instance)) {
apdu_len = Binary_Input_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Binary_Input_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_BINARY_OUTPUT:
if (Binary_Output_Valid_Instance(object_instance)) {
apdu_len = Binary_Output_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Binary_Output_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_BINARY_VALUE:
if (Binary_Value_Valid_Instance(object_instance)) {
apdu_len = Binary_Value_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Binary_Value_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_LIFE_SAFETY_POINT:
if (Life_Safety_Point_Valid_Instance(object_instance)) {
apdu_len = Life_Safety_Point_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Life_Safety_Point_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_LOAD_CONTROL:
if (Load_Control_Valid_Instance(object_instance)) {
apdu_len = Load_Control_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Load_Control_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
case OBJECT_MULTI_STATE_OUTPUT:
if (Multistate_Output_Valid_Instance(object_instance)) {
apdu_len = Multistate_Output_Encode_Property_APDU(&apdu[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Multistate_Output_Encode_Property_APDU(&apdu[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
#if defined(BACFILE)
case OBJECT_FILE:
if (bacfile_valid_instance(object_instance)) {
apdu_len = bacfile_encode_property_apdu(&apdu[0],
object_instance,
apdu_len =
bacfile_encode_property_apdu(&apdu[0], object_instance,
property, array_index, error_class, error_code);
}
break;
@@ -176,13 +186,15 @@ void handler_read_property(
/* 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_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_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 =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED
fprintf(stderr, "RP: Segmented message. Sending Abort!\n");
#endif
@@ -196,7 +208,8 @@ void handler_read_property(
#endif
if (len < 0) {
/* bad decoding - send an abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "RP: Bad Encoding. Sending Abort!\n");
@@ -206,10 +219,10 @@ void handler_read_property(
/* assume that there is an error */
error = true;
len = Encode_Property_APDU(&Temp_Buf[0],
data.object_type,
data.object_instance,
data.object_property, data.array_index, &error_class, &error_code);
len =
Encode_Property_APDU(&Temp_Buf[0], data.object_type,
data.object_instance, data.object_property, data.array_index,
&error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
data.application_data = &Temp_Buf[0];
@@ -226,16 +239,18 @@ void handler_read_property(
if (error) {
if (len == -2) {
/* BACnet APDU too small to fit data, so proper response is Abort */
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "RP: Reply too big to fit into APDU!\n");
#endif
} else {
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Error!\n");
#endif
@@ -243,8 +258,9 @@ void handler_read_property(
}
RP_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
+2 -1
View File
@@ -71,7 +71,8 @@ static void PrintReadPropertyData(
/* FIXME: what if application_data_len is bigger than 255? */
/* value? need to loop until all of the len is gone... */
for (;;) {
len = bacapp_decode_application_data(application_data,
len =
bacapp_decode_application_data(application_data,
(uint8_t) application_data_len, &value);
if (first_value && (len < application_data_len)) {
first_value = false;
+51 -36
View File
@@ -198,8 +198,9 @@ static unsigned RPM_Object_Property_Count(
unsigned count = 0; /* return value */
if (special_property == PROP_ALL) {
count = pPropertyList->Required.count +
pPropertyList->Optional.count + pPropertyList->Proprietary.count;
count =
pPropertyList->Required.count + pPropertyList->Optional.count +
pPropertyList->Proprietary.count;
} else if (special_property == PROP_REQUIRED) {
count = pPropertyList->Required.count;
} else if (special_property == PROP_OPTIONAL) {
@@ -246,19 +247,20 @@ int RPM_Encode_Property(
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
len = rpm_ack_encode_apdu_object_property(&Temp_Buf[0],
object_property, array_index);
len =
rpm_ack_encode_apdu_object_property(&Temp_Buf[0], object_property,
array_index);
len = apdu_copy(&apdu[0], &Temp_Buf[0], offset, len, max_apdu);
if (!len)
return 0;
apdu_len += len;
len = Encode_Property_APDU(&Temp_Buf[0],
object_type,
object_instance,
len =
Encode_Property_APDU(&Temp_Buf[0], object_type, object_instance,
object_property, array_index, &error_class, &error_code);
if (len < 0) {
/* error was returned - encode that for the response */
len = rpm_ack_encode_apdu_object_property_error(&Temp_Buf[0],
len =
rpm_ack_encode_apdu_object_property_error(&Temp_Buf[0],
error_class, error_code);
len =
apdu_copy(&apdu[0], &Temp_Buf[0], offset + apdu_len, len,
@@ -304,12 +306,14 @@ void handler_read_property_multiple(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0],
src, &my_address, &npdu_data);
npdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
apdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED
printf("RPM: Segmented message. Sending Abort!\r\n");
#endif
@@ -317,16 +321,19 @@ void handler_read_property_multiple(
}
/* decode apdu request & encode apdu reply
encode complex ack, invoke id, service choice */
apdu_len = rpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
apdu_len =
rpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id);
do {
len = rpm_decode_object_id(&service_request[decode_len],
len =
rpm_decode_object_id(&service_request[decode_len],
service_len - decode_len, &object_type, &object_instance);
/* end of object? */
if (len > 0) {
decode_len += len;
} else {
len = rpm_decode_object_end(&service_request[decode_len],
len =
rpm_decode_object_end(&service_request[decode_len],
service_len - decode_len);
if (len == 1) {
decode_len++;
@@ -351,12 +358,15 @@ void handler_read_property_multiple(
}
break;
}
len = rpm_ack_encode_apdu_object_begin(&Temp_Buf[0],
object_type, object_instance);
copy_len = apdu_copy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
len =
rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], object_type,
object_instance);
copy_len =
apdu_copy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
apdu_len, len, sizeof(Handler_Transmit_Buffer));
if (!copy_len) {
apdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RPM_ABORT;
@@ -365,13 +375,15 @@ void handler_read_property_multiple(
}
/* do each property of this object of the RPM request */
do {
len = rpm_decode_object_property(&service_request[decode_len],
len =
rpm_decode_object_property(&service_request[decode_len],
service_len - decode_len, &object_property, &array_index);
/* end of property list? */
if (len > 0) {
decode_len += len;
} else {
len = rpm_decode_object_end(&service_request[decode_len],
len =
rpm_decode_object_end(&service_request[decode_len],
service_len - decode_len);
if (len == 1) {
decode_len++;
@@ -409,16 +421,18 @@ void handler_read_property_multiple(
special_object_property = object_property;
RPM_Property_List(object_type, &property_list);
property_count = RPM_Object_Property_Count(&property_list,
property_count =
RPM_Object_Property_Count(&property_list,
special_object_property);
for (index = 0; index < property_count; index++) {
object_property = RPM_Object_Property(&property_list,
object_property =
RPM_Object_Property(&property_list,
special_object_property, index);
len = RPM_Encode_Property(&Handler_Transmit_Buffer[0],
npdu_len + apdu_len,
sizeof(Handler_Transmit_Buffer),
object_type,
object_instance, object_property, array_index);
len =
RPM_Encode_Property(&Handler_Transmit_Buffer[0],
npdu_len + apdu_len, sizeof(Handler_Transmit_Buffer),
object_type, object_instance, object_property,
array_index);
if (len > 0) {
apdu_len += len;
} else {
@@ -431,11 +445,11 @@ void handler_read_property_multiple(
}
} else {
/* handle an individual property */
len = RPM_Encode_Property(&Handler_Transmit_Buffer[0],
npdu_len + apdu_len,
sizeof(Handler_Transmit_Buffer),
object_type,
object_instance, object_property, array_index);
len =
RPM_Encode_Property(&Handler_Transmit_Buffer[0],
npdu_len + apdu_len, sizeof(Handler_Transmit_Buffer),
object_type, object_instance, object_property,
array_index);
if (len > 0) {
apdu_len += len;
} else {
@@ -453,6 +467,7 @@ void handler_read_property_multiple(
} while (1);
RPM_ABORT:
pdu_len = apdu_len + npdu_len;
bytes_sent = datalink_send_pdu(src,
&npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
}
+6 -4
View File
@@ -60,8 +60,9 @@ void handler_timesync(
(void) src;
(void) service_len;
len = timesync_decode_service_request(service_request,
service_len, &bdate, &btime);
len =
timesync_decode_service_request(service_request, service_len, &bdate,
&btime);
#if PRINT_ENABLED
fprintf(stderr, "Received TimeSyncronization Request\r\n");
show_bacnet_date_time(&bdate, &btime);
@@ -82,8 +83,9 @@ void handler_timesync_utc(
(void) src;
(void) service_len;
len = timesync_decode_service_request(service_request,
service_len, &bdate, &btime);
len =
timesync_decode_service_request(service_request, service_len, &bdate,
&btime);
#if PRINT_ENABLED
fprintf(stderr, "Received TimeSyncronization Request\r\n");
show_bacnet_date_time(&bdate, &btime);
+5 -4
View File
@@ -62,11 +62,12 @@ void handler_who_has(
if (data.object_name) {
/* valid name in my device? */
object_name = characterstring_value(&data.object.name);
found = Device_Valid_Object_Name(object_name,
&object_type, &object_instance);
found =
Device_Valid_Object_Name(object_name, &object_type,
&object_instance);
if (found)
Send_I_Have(Device_Object_Instance_Number(),
object_type, object_instance, object_name);
Send_I_Have(Device_Object_Instance_Number(), object_type,
object_instance, object_name);
} else {
/* valid object in my device? */
object_name =
+3 -2
View File
@@ -47,8 +47,9 @@ void handler_who_is(
int32_t high_limit = 0;
(void) src;
len = whois_decode_service_request(service_request,
service_len, &low_limit, &high_limit);
len =
whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
if (len == 0)
iam_send(&Handler_Transmit_Buffer[0]);
else if (len != -1) {
+31 -28
View File
@@ -68,15 +68,17 @@ void handler_write_property(
/* 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_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
#if PRINT_ENABLED
fprintf(stderr, "WP: Received Request!\n");
#endif
if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED
fprintf(stderr, "WP: Segmented message. Sending Abort!\n");
#endif
@@ -86,15 +88,15 @@ void handler_write_property(
#if PRINT_ENABLED
if (len > 0)
fprintf(stderr, "WP: type=%u instance=%u property=%u index=%d\n",
wp_data.object_type,
wp_data.object_instance,
wp_data.object_type, wp_data.object_instance,
wp_data.object_property, wp_data.array_index);
else
fprintf(stderr, "WP: Unable to decode Request!\n");
#endif
/* bad decoding or something we didn't understand - send an abort */
if (len <= 0) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "WP: Bad Encoding. Sending Abort!\n");
@@ -113,8 +115,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Error for Device!\n");
#endif
@@ -144,8 +146,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for BO!\n");
#endif
@@ -163,8 +165,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for BV!\n");
#endif
@@ -182,8 +184,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for AO!\n");
#endif
@@ -201,8 +203,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for AV!\n");
#endif
@@ -220,8 +222,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for LSP!\n");
#endif
@@ -239,8 +241,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr,
"WP: Sending Write Access Error for Load Control!\n");
@@ -260,8 +262,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for MSO!\n");
#endif
@@ -279,8 +281,8 @@ void handler_write_property(
} else {
len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, error_code);
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Write Access Error for File!\n");
#endif
@@ -299,8 +301,9 @@ void handler_write_property(
}
WP_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno));
+8 -5
View File
@@ -52,15 +52,18 @@ void handler_unrecognized_service(
/* 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_encode_pdu(&Handler_Transmit_Buffer[0], src,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
len =
reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE);
pdu_len += len;
/* send the data */
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent > 0)
fprintf(stderr, "Sent Reject!\n");
+8 -5
View File
@@ -78,10 +78,12 @@ uint8_t Send_Atomic_Read_File_Stream(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
len = arf_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, &data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
len =
arf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len += len;
/* will the APDU fit the target device?
note: if there is a bottleneck router in between
@@ -104,7 +106,8 @@ uint8_t Send_Atomic_Read_File_Stream(
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicReadFile Request "
fprintf(stderr,
"Failed to Send AtomicReadFile Request "
"(payload exceeds destination maximum APDU)!\n");
#endif
}
+7 -4
View File
@@ -83,8 +83,9 @@ uint8_t Send_Atomic_Write_File_Stream(
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
/* encode the APDU portion of the packet */
len = awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, &data);
len =
awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len += len;
/* will the APDU fit the target device?
note: if there is a bottleneck router in between
@@ -107,7 +108,8 @@ uint8_t Send_Atomic_Write_File_Stream(
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicWriteFile Request "
fprintf(stderr,
"Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds destination maximum APDU [%u])!\n",
pdu_len, max_apdu);
#endif
@@ -116,7 +118,8 @@ uint8_t Send_Atomic_Write_File_Stream(
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send AtomicWriteFile Request "
fprintf(stderr,
"Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds octet string capacity)!\n", pdu_len);
#endif
}
+5 -4
View File
@@ -72,12 +72,13 @@ uint8_t Send_Device_Communication_Control_Request(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
characterstring_init_ansi(&password_string, password);
len = dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id,
len =
dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
timeDuration, state, password ? &password_string : NULL);
pdu_len += len;
/* will it fit in the sender?
+5 -4
View File
@@ -64,8 +64,8 @@ void Send_I_Have(
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
NULL, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */
data.device_id.type = OBJECT_DEVICE;
data.device_id.instance = device_id;
@@ -75,8 +75,9 @@ void Send_I_Have(
len = ihave_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len;
/* send the data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n",
+8 -5
View File
@@ -71,12 +71,14 @@ uint8_t Send_Reinitialize_Device_Request(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
characterstring_init_ansi(&password_string, password);
len = rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, state, password ? &password_string : NULL);
len =
rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, state,
password ? &password_string : NULL);
pdu_len += len;
/* will it fit in the sender?
note: if there is a bottleneck router in between
@@ -99,7 +101,8 @@ uint8_t Send_Reinitialize_Device_Request(
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send ReinitializeDevice Request "
fprintf(stderr,
"Failed to Send ReinitializeDevice Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
+9 -7
View File
@@ -74,15 +74,17 @@ uint8_t Send_Read_Property_Request(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
data.object_type = object_type;
data.object_instance = object_instance;
data.object_property = object_property;
data.array_index = array_index;
len = rp_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, &data);
len =
rp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len += len;
/* will it fit in the sender?
note: if there is a bottleneck router in between
@@ -97,15 +99,15 @@ uint8_t Send_Read_Property_Request(
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send ReadProperty Request (%s)!\n",
fprintf(stderr, "Failed to Send ReadProperty Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send ReadProperty Request "
fprintf(stderr,
"Failed to Send ReadProperty Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
+13 -12
View File
@@ -59,19 +59,19 @@ void Send_TimeSync(
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
NULL, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */
len = timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
bdate, btime);
len =
timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate, btime);
pdu_len += len;
/* send it out the datalink */
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send Time-Synchronization Request (%s)!\n",
fprintf(stderr, "Failed to Send Time-Synchronization Request (%s)!\n",
strerror(errno));
#endif
}
@@ -91,10 +91,11 @@ void Send_TimeSyncUTC(
/* we could use unicast or broadcast */
datalink_get_broadcast_address(&dest);
/* encode the APDU portion of the packet */
pdu_len = timesync_utc_encode_apdu(&Handler_Transmit_Buffer[0],
bdate, btime);
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
pdu_len =
timesync_utc_encode_apdu(&Handler_Transmit_Buffer[0], bdate, btime);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr,
+10 -8
View File
@@ -62,8 +62,8 @@ void Send_WhoHas_Name(
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
NULL, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */
data.low_limit = low_limit;
data.high_limit = high_limit;
@@ -72,8 +72,9 @@ void Send_WhoHas_Name(
len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len;
/* send the data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
@@ -102,8 +103,8 @@ void Send_WhoHas_Object(
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
NULL, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */
data.low_limit = low_limit;
data.high_limit = high_limit;
@@ -112,8 +113,9 @@ void Send_WhoHas_Object(
data.object.identifier.instance = object_instance;
len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len;
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
+8 -6
View File
@@ -61,14 +61,16 @@ void Send_WhoIs(
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
NULL, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */
len = whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
low_limit, high_limit);
len =
whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit,
high_limit);
pdu_len += len;
bytes_sent = datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
+13 -14
View File
@@ -77,8 +77,9 @@ uint8_t Send_Write_Property_Request_Data(
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest,
&my_address, &npdu_data);
pdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
&npdu_data);
/* encode the APDU portion of the packet */
data.object_type = object_type;
data.object_instance = object_instance;
@@ -88,8 +89,9 @@ uint8_t Send_Write_Property_Request_Data(
memcpy(&data.application_data[0], &application_data[0],
application_data_len);
data.priority = priority;
len = wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, &data);
len =
wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id,
&data);
pdu_len += len;
/* will it fit in the sender?
note: if there is a bottleneck router in between
@@ -104,15 +106,15 @@ uint8_t Send_Write_Property_Request_Data(
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr,
"Failed to Send WriteProperty Request (%s)!\n",
fprintf(stderr, "Failed to Send WriteProperty Request (%s)!\n",
strerror(errno));
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send WriteProperty Request "
fprintf(stderr,
"Failed to Send WriteProperty Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
@@ -135,8 +137,7 @@ uint8_t Send_Write_Property_Request(
while (object_value) {
#if PRINT_ENABLED_DEBUG
fprintf(stderr, "WriteProperty service: "
"%s tag=%d\n",
fprintf(stderr, "WriteProperty service: " "%s tag=%d\n",
(object_value->context_specific ? "context" : "application"),
(int) (object_value->context_specific ? object_value->
context_tag : object_value->tag));
@@ -150,9 +151,7 @@ uint8_t Send_Write_Property_Request(
object_value = object_value->next;
}
return Send_Write_Property_Request_Data(device_id,
object_type,
object_instance,
object_property,
&application_data[0], apdu_len, priority, array_index);
return Send_Write_Property_Request_Data(device_id, object_type,
object_instance, object_property, &application_data[0], apdu_len,
priority, array_index);
}
+4 -4
View File
@@ -211,14 +211,14 @@ void testAnalogInput(
/* FIXME: we should do a lot more testing here... */
len = Analog_Input_Encode_Property_APDU(&apdu[0],
instance,
len =
Analog_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_INPUT);
ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -411,7 +411,8 @@ bool Analog_Output_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -491,14 +492,14 @@ void testAnalogOutput(
BACNET_ERROR_CODE error_code;
len = Analog_Output_Encode_Property_APDU(&apdu[0],
instance,
len =
Analog_Output_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_OUTPUT);
ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -339,7 +339,8 @@ bool Analog_Value_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -439,14 +440,14 @@ void testAnalog_Value(
BACNET_ERROR_CODE error_code;
len = Analog_Value_Encode_Property_APDU(&apdu[0],
instance,
len =
Analog_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_ANALOG_VALUE);
ct_test(pTest, decoded_instance == instance);
+17 -12
View File
@@ -198,8 +198,9 @@ int bacfile_encode_property_apdu(
(void) array_index;
switch (property) {
case PROP_OBJECT_IDENTIFIER:
apdu_len = encode_application_object_id(&apdu[0],
OBJECT_FILE, object_instance);
apdu_len =
encode_application_object_id(&apdu[0], OBJECT_FILE,
object_instance);
break;
case PROP_OBJECT_NAME:
sprintf(text_string, "FILE %d", object_instance);
@@ -222,7 +223,8 @@ int bacfile_encode_property_apdu(
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_FILE_SIZE:
apdu_len = encode_application_unsigned(&apdu[0],
apdu_len =
encode_application_unsigned(&apdu[0],
bacfile_file_size(object_instance));
break;
case PROP_MODIFICATION_DATE:
@@ -285,7 +287,8 @@ bool bacfile_write_property(
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -371,18 +374,19 @@ uint32_t bacfile_instance_from_tsm(
uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */
bool found = false;
found = tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0],
found =
tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0],
&apdu_len);
if (found) {
if (!npdu_data.network_layer_message
&& npdu_data.data_expecting_reply
if (!npdu_data.network_layer_message && npdu_data.data_expecting_reply
&& (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
len =
apdu_decode_confirmed_service_request(&apdu[0],
apdu_len, &service_data, &service_choice,
&service_request, &service_request_len);
apdu_decode_confirmed_service_request(&apdu[0], apdu_len,
&service_data, &service_choice, &service_request,
&service_request_len);
if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) {
len = arf_decode_service_request(service_request,
len =
arf_decode_service_request(service_request,
service_request_len, &data);
if (len > 0) {
if (data.object_type == OBJECT_FILE)
@@ -410,7 +414,8 @@ bool bacfile_read_data(
pFile = fopen(pFilename, "rb");
if (pFile) {
(void) fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET);
len = fread(octetstring_value(&data->fileData), 1,
len =
fread(octetstring_value(&data->fileData), 1,
data->type.stream.requestedOctetCount, pFile);
if (len < data->type.stream.requestedOctetCount)
data->endOfFile = true;
+4 -4
View File
@@ -256,14 +256,14 @@ void testBinaryInput(
/* FIXME: we should do a lot more testing here... */
len = Binary_Input_Encode_Property_APDU(&apdu[0],
instance,
len =
Binary_Input_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len >= 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_INPUT);
ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -335,7 +335,8 @@ bool Binary_Output_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -437,14 +438,14 @@ void testBinaryOutput(
BACNET_ERROR_CODE error_code;
len = Binary_Output_Encode_Property_APDU(&apdu[0],
instance,
len =
Binary_Output_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_OUTPUT);
ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -328,7 +328,8 @@ bool Binary_Value_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -429,14 +430,14 @@ void testBinary_Value(
BACNET_ERROR_CODE error_code;
len = Binary_Value_Encode_Property_APDU(&apdu[0],
instance,
len =
Binary_Value_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_BINARY_VALUE);
ct_test(pTest, decoded_instance == instance);
+10 -6
View File
@@ -663,7 +663,8 @@ int Device_Encode_Property_APDU(
switch (property) {
case PROP_OBJECT_IDENTIFIER:
apdu_len = encode_application_object_id(&apdu[0], OBJECT_DEVICE,
apdu_len =
encode_application_object_id(&apdu[0], OBJECT_DEVICE,
Object_Instance_Number);
break;
case PROP_OBJECT_NAME:
@@ -839,11 +840,13 @@ int Device_Encode_Property_APDU(
}
break;
case PROP_MAX_APDU_LENGTH_ACCEPTED:
apdu_len = encode_application_unsigned(&apdu[0],
apdu_len =
encode_application_unsigned(&apdu[0],
Device_Max_APDU_Length_Accepted());
break;
case PROP_SEGMENTATION_SUPPORTED:
apdu_len = encode_application_enumerated(&apdu[0],
apdu_len =
encode_application_enumerated(&apdu[0],
Device_Segmentation_Supported());
break;
case PROP_APDU_TIMEOUT:
@@ -897,7 +900,8 @@ bool Device_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -921,8 +925,8 @@ bool Device_Write_Property(
case PROP_NUMBER_OF_APDU_RETRIES:
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
/* FIXME: bounds check? */
Device_Set_Number_Of_APDU_Retries((uint8_t) value.
type.Unsigned_Int);
Device_Set_Number_Of_APDU_Retries((uint8_t) value.type.
Unsigned_Int);
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
+50 -34
View File
@@ -314,12 +314,10 @@ struct tm {
timer = time(NULL);
tblock = localtime(&timer);
datetime_set_values(bdatetime,
(uint16_t) tblock->tm_year,
(uint8_t) tblock->tm_mon,
(uint8_t) tblock->tm_mday,
(uint8_t) tblock->tm_hour,
(uint8_t) tblock->tm_min, (uint8_t) tblock->tm_sec, 0);
datetime_set_values(bdatetime, (uint16_t) tblock->tm_year,
(uint8_t) tblock->tm_mon, (uint8_t) tblock->tm_mday,
(uint8_t) tblock->tm_hour, (uint8_t) tblock->tm_min,
(uint8_t) tblock->tm_sec, 0);
}
/* convert the shed level request into an Analog Output Present_Value */
@@ -758,16 +756,19 @@ int Load_Control_Encode_Property_APDU(
case PROP_REQUESTED_SHED_LEVEL:
switch (Requested_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0,
apdu_len =
encode_context_unsigned(&apdu[0], 0,
Requested_Shed_Level[object_index].value.percent);
break;
case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2,
apdu_len =
encode_context_real(&apdu[0], 2,
Requested_Shed_Level[object_index].value.amount);
break;
case BACNET_SHED_TYPE_LEVEL:
default:
apdu_len = encode_context_unsigned(&apdu[0], 1,
apdu_len =
encode_context_unsigned(&apdu[0], 1,
Requested_Shed_Level[object_index].value.level);
break;
}
@@ -777,16 +778,19 @@ int Load_Control_Encode_Property_APDU(
encode_application_date(&apdu[0],
&Start_Time[object_index].date);
apdu_len = len;
len = encode_application_time(&apdu[apdu_len],
len =
encode_application_time(&apdu[apdu_len],
&Start_Time[object_index].time);
apdu_len += len;
break;
case PROP_SHED_DURATION:
apdu_len = encode_application_unsigned(&apdu[0],
apdu_len =
encode_application_unsigned(&apdu[0],
Shed_Duration[object_index]);
break;
case PROP_DUTY_WINDOW:
apdu_len = encode_application_unsigned(&apdu[0],
apdu_len =
encode_application_unsigned(&apdu[0],
Duty_Window[object_index]);
break;
case PROP_ENABLE:
@@ -794,22 +798,26 @@ int Load_Control_Encode_Property_APDU(
apdu_len = encode_application_boolean(&apdu[0], state);
break;
case PROP_FULL_DUTY_BASELINE: /* optional */
apdu_len = encode_application_real(&apdu[0],
apdu_len =
encode_application_real(&apdu[0],
Full_Duty_Baseline[object_index]);
break;
case PROP_EXPECTED_SHED_LEVEL:
switch (Expected_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0,
apdu_len =
encode_context_unsigned(&apdu[0], 0,
Expected_Shed_Level[object_index].value.percent);
break;
case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2,
apdu_len =
encode_context_real(&apdu[0], 2,
Expected_Shed_Level[object_index].value.amount);
break;
case BACNET_SHED_TYPE_LEVEL:
default:
apdu_len = encode_context_unsigned(&apdu[0], 1,
apdu_len =
encode_context_unsigned(&apdu[0], 1,
Expected_Shed_Level[object_index].value.level);
break;
}
@@ -817,16 +825,19 @@ int Load_Control_Encode_Property_APDU(
case PROP_ACTUAL_SHED_LEVEL:
switch (Actual_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0,
apdu_len =
encode_context_unsigned(&apdu[0], 0,
Actual_Shed_Level[object_index].value.percent);
break;
case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2,
apdu_len =
encode_context_real(&apdu[0], 2,
Actual_Shed_Level[object_index].value.amount);
break;
case BACNET_SHED_TYPE_LEVEL:
default:
apdu_len = encode_context_unsigned(&apdu[0], 1,
apdu_len =
encode_context_unsigned(&apdu[0], 1,
Actual_Shed_Level[object_index].value.level);
break;
}
@@ -857,7 +868,8 @@ int Load_Control_Encode_Property_APDU(
}
} else {
if (array_index <= MAX_SHED_LEVELS) {
apdu_len = encode_application_unsigned(&apdu[0],
apdu_len =
encode_application_unsigned(&apdu[0],
Shed_Levels[object_index][array_index - 1]);
} else {
*error_class = ERROR_CLASS_PROPERTY;
@@ -879,7 +891,8 @@ int Load_Control_Encode_Property_APDU(
/* FIXME: check if we have room before adding it to APDU */
characterstring_init_ansi(&char_string,
Shed_Level_Descriptions[i]);
len = encode_application_character_string(&apdu[apdu_len],
len =
encode_application_character_string(&apdu[apdu_len],
&char_string);
/* add it if we have room */
if ((apdu_len + len) < MAX_APDU)
@@ -895,7 +908,8 @@ int Load_Control_Encode_Property_APDU(
if (array_index <= MAX_SHED_LEVELS) {
characterstring_init_ansi(&char_string,
Shed_Level_Descriptions[array_index - 1]);
apdu_len = encode_application_character_string(&apdu[0],
apdu_len =
encode_application_character_string(&apdu[0],
&char_string);
} else {
*error_class = ERROR_CLASS_PROPERTY;
@@ -932,16 +946,18 @@ bool Load_Control_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
object_index = Load_Control_Instance_To_Index(wp_data->object_instance);
switch (wp_data->object_property) {
case PROP_REQUESTED_SHED_LEVEL:
len = bacapp_decode_context_data(wp_data->application_data,
wp_data->application_data_len,
&value, PROP_REQUESTED_SHED_LEVEL);
len =
bacapp_decode_context_data(wp_data->application_data,
wp_data->application_data_len, &value,
PROP_REQUESTED_SHED_LEVEL);
if (value.context_tag == 0) {
/* percent - Unsigned */
Requested_Shed_Level[object_index].type =
@@ -974,8 +990,8 @@ bool Load_Control_Write_Property(
break;
case PROP_START_TIME:
if (value.tag == BACNET_APPLICATION_TAG_DATE) {
memcpy(&Start_Time[object_index].date,
&value.type.Date, sizeof(value.type.Date));
memcpy(&Start_Time[object_index].date, &value.type.Date,
sizeof(value.type.Date));
Start_Time_Property_Written[object_index] = true;
status = true;
} else {
@@ -988,8 +1004,8 @@ bool Load_Control_Write_Property(
bacapp_decode_application_data(wp_data->application_data + len,
wp_data->application_data_len - len, &value);
if (len && value.tag == BACNET_APPLICATION_TAG_TIME) {
memcpy(&Start_Time[object_index].time,
&value.type.Time, sizeof(value.type.Time));
memcpy(&Start_Time[object_index].time, &value.type.Time,
sizeof(value.type.Time));
status = true;
} else {
status = false;
@@ -1455,14 +1471,14 @@ void testLoadControl(
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
len = Load_Control_Encode_Property_APDU(&apdu[0],
instance,
len =
Load_Control_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_LOAD_CONTROL);
ct_test(pTest, decoded_instance == instance);
+14 -10
View File
@@ -144,8 +144,9 @@ int Lighting_Output_Decode_Lighting_Command(
/* Tag 0: operation */
if (!decode_is_context_tag(&apdu[apdu_len], 0))
return -1;
len = decode_tag_number_and_value(&apdu[apdu_len],
&tag_number, &len_value_type);
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&len_value_type);
apdu_len += len;
len =
decode_enumerated(&apdu[apdu_len], len_value_type,
@@ -153,8 +154,9 @@ int Lighting_Output_Decode_Lighting_Command(
apdu_len += len;
/* Tag 1: level - OPTIONAL */
if (decode_is_context_tag(&apdu[apdu_len], 1)) {
len = decode_tag_number_and_value(&apdu[apdu_len],
&tag_number, &len_value_type);
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&len_value_type);
apdu_len += len;
len = decode_real(&apdu[apdu_len], &real_value);
apdu_len += len;
@@ -412,7 +414,8 @@ int Lighting_Output_Encode_Property_APDU(
apdu_len = encode_application_real(&apdu[0], real_value);
break;
case PROP_LIGHTING_COMMAND:
apdu_len = Lighting_Output_Encode_Lighting_Command(&apdu[0],
apdu_len =
Lighting_Output_Encode_Lighting_Command(&apdu[0],
&Lighting_Command[object_instance]);
break;
case PROP_STATUS_FLAGS:
@@ -521,7 +524,8 @@ bool Lighting_Output_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -615,14 +619,14 @@ void testLightingOutput(
BACNET_ERROR_CODE error_code;
len = Lighting_Output_Encode_Property_APDU(&apdu[0],
instance,
len =
Lighting_Output_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_LIGHTING_OUTPUT);
ct_test(pTest, decoded_instance == instance);
+6 -5
View File
@@ -307,7 +307,8 @@ bool Life_Safety_Point_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -373,14 +374,14 @@ void testLifeSafetyPoint(
BACNET_ERROR_CODE error_code;
len = Life_Safety_Point_Encode_Property_APDU(&apdu[0],
instance,
len =
Life_Safety_Point_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_LIFE_SAFETY_POINT);
ct_test(pTest, decoded_instance == instance);
+8 -6
View File
@@ -312,7 +312,8 @@ int Multistate_Output_Encode_Property_APDU(
apdu_len = encode_application_enumerated(&apdu[0], present_value);
break;
case PROP_NUMBER_OF_STATES:
apdu_len = encode_application_unsigned(&apdu[apdu_len],
apdu_len =
encode_application_unsigned(&apdu[apdu_len],
MULTISTATE_NUMBER_OF_STATES);
break;
@@ -346,7 +347,8 @@ bool Multistate_Output_Write_Property(
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
@@ -451,14 +453,14 @@ void testMultistateOutput(
BACNET_ERROR_CODE error_code;
len = Multistate_Output_Encode_Property_APDU(&apdu[0],
instance,
len =
Multistate_Output_Encode_Property_APDU(&apdu[0], instance,
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL, &error_class, &error_code);
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len = decode_object_id(&apdu[len],
(int *) &decoded_type, &decoded_instance);
len =
decode_object_id(&apdu[len], (int *) &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == OBJECT_MULTI_STATE_OUTPUT);
ct_test(pTest, decoded_instance == instance);
+10 -10
View File
@@ -132,8 +132,7 @@ static void AtomicReadFileAckHandler(
octets_written = fwrite(octetstring_value(&data.fileData), 1, /* unit to write in bytes - in our case, an octet is one byte */
octetstring_length(&data.fileData), pFile);
if (octets_written != octetstring_length(&data.fileData))
fprintf(stderr,
"Unable to write data to file \"%s\".\n",
fprintf(stderr, "Unable to write data to file \"%s\".\n",
Local_File_Name);
else
printf("\r%u bytes",
@@ -161,8 +160,9 @@ static void LocalIAmHandler(
(void) src;
(void) service_len;
len = iam_decode_service_request(service_request,
&device_id, &max_apdu, &segmentation, &vendor_id);
len =
iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
if (len != -1) {
address_add(device_id, max_apdu, src);
} else
@@ -242,8 +242,8 @@ int main(
return 1;
/* configure the timeout values */
last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries();
timeout_seconds =
(Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */
@@ -264,8 +264,9 @@ int main(
if (End_Of_File_Detected || Error_Detected)
break;
/* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address);
found =
address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) {
/* calculate the smaller of our APDU size or theirs
and remove the overhead of the APDU (about 16 octets max).
@@ -292,8 +293,7 @@ int main(
/* we'll read the file in chunks
less than max_apdu to keep unsegmented */
invoke_id =
Send_Atomic_Read_File_Stream
(Target_Device_Object_Instance,
Send_Atomic_Read_File_Stream(Target_Device_Object_Instance,
Target_File_Object_Instance, fileStartPosition,
requestedOctetCount);
Current_Invoke_ID = invoke_id;
+8 -8
View File
@@ -190,8 +190,8 @@ int main(
return 1;
/* configure the timeout values */
last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries();
timeout_seconds =
(Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */
@@ -212,15 +212,15 @@ int main(
if (Error_Detected)
break;
/* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address);
found =
address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) {
if (invoke_id == 0) {
invoke_id =
Send_Read_Property_Request
(Target_Device_Object_Instance, Target_Object_Type,
Target_Object_Instance, Target_Object_Property,
Target_Object_Index);
Send_Read_Property_Request(Target_Device_Object_Instance,
Target_Object_Type, Target_Object_Instance,
Target_Object_Property, Target_Object_Index);
} else if (tsm_invoke_id_free(invoke_id))
break;
else if (tsm_invoke_id_failed(invoke_id)) {
+10 -16
View File
@@ -70,8 +70,7 @@ static void MyErrorHandler(
/* FIXME: verify src and invoke id */
(void) src;
(void) invoke_id;
printf("BACnet Error: %s: %s\r\n",
bactext_error_class_name(error_class),
printf("BACnet Error: %s: %s\r\n", bactext_error_class_name(error_class),
bactext_error_code_name(error_code));
Error_Detected = true;
}
@@ -155,17 +154,11 @@ int main(
if (argc < 3) {
/* note: priority 16 and 0 should produce the same end results... */
printf("Usage: %s device-instance state [password]\r\n"
"Send BACnet ReinitializeDevice service to device.\r\n"
"\r\n"
"Send BACnet ReinitializeDevice service to device.\r\n" "\r\n"
"The device-instance can be 0 to %d.\r\n"
"Possible state values:\r\n"
" 0=coldstart\r\n"
" 1=warmstart\r\n"
" 2=startbackup\r\n"
" 3=endbackup\r\n"
" 4=startrestore\r\n"
" 5=endrestore\r\n"
" 6=abortrestore\r\n"
"Possible state values:\r\n" " 0=coldstart\r\n"
" 1=warmstart\r\n" " 2=startbackup\r\n" " 3=endbackup\r\n"
" 4=startrestore\r\n" " 5=endrestore\r\n" " 6=abortrestore\r\n"
"The optional password is a character string of 1 to 20 characters.\r\n",
filename_remove_path(argv[0]), BACNET_MAX_INSTANCE - 1);
return 0;
@@ -191,8 +184,8 @@ int main(
return 1;
/* configure the timeout values */
last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries();
timeout_seconds =
(Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */
@@ -213,8 +206,9 @@ int main(
if (Error_Detected)
break;
/* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address);
found =
address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) {
if (invoke_id == 0) {
invoke_id =
+6 -9
View File
@@ -81,13 +81,12 @@ static void Init_Service_Handlers(
#endif
apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
handler_reinitialize_device);
apdu_set_unconfirmed_handler
(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, handler_timesync_utc);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
handler_timesync_utc);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
handler_timesync);
/* handle communication so we can shutup when asked */
apdu_set_confirmed_handler
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control);
}
@@ -144,11 +143,9 @@ int main(
dlmstp_set_mac_address(127);
}
#endif
printf("BACnet Server Demo\n"
"BACnet Stack Version %s\n"
"BACnet Device ID: %u\n"
"Max APDU: %d\n",
BACnet_Version, Device_Object_Instance_Number(), MAX_APDU);
printf("BACnet Server Demo\n" "BACnet Stack Version %s\n"
"BACnet Device ID: %u\n" "Max APDU: %d\n", BACnet_Version,
Device_Object_Instance_Number(), MAX_APDU);
Init_Service_Handlers();
BIP_Debug = true;
if (!datalink_init(getenv("BACNET_IFACE")))
+6 -12
View File
@@ -96,8 +96,8 @@ static void Init_Service_Handlers(
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
handler_read_property);
/* handle the reply (request) coming in */
apdu_set_unconfirmed_handler
(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, handler_timesync_utc);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
handler_timesync_utc);
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
handler_timesync);
/* handle any errors coming back */
@@ -127,17 +127,11 @@ int main(
printf("Usage: %s date time [device-instance]\r\n"
"Send BACnet TimeSynchronization request to all devices.\r\n"
"date format: year/month/day:dayofweek (e.g. 2006/4/1:6)\r\n"
"year: AD, such as 2006\r\n"
"month: 1=January, 12=December\r\n"
"day: 1-31\r\n"
"dayofweek: 1=Monday, 7=Sunday\r\n"
"\r\n"
"year: AD, such as 2006\r\n" "month: 1=January, 12=December\r\n"
"day: 1-31\r\n" "dayofweek: 1=Monday, 7=Sunday\r\n" "\r\n"
"time format: hour:minute:second.hundredths (e.g. 23:59:59.12)\r\n"
"hour: 0-23\r\n"
"minute: 0-59\r\n"
"second: 0-59\r\n"
"hundredths: 0-99\r\n"
"\r\n"
"hour: 0-23\r\n" "minute: 0-59\r\n" "second: 0-59\r\n"
"hundredths: 0-99\r\n" "\r\n"
"Optional device-instance sends a unicast time sync.\r\n",
filename_remove_path(argv[0]));
return 0;
+17 -35
View File
@@ -78,55 +78,38 @@ int main(
if (argc < 7) {
/* note: priority 16 and 0 should produce the same end results... */
printf("Usage: %s pid device-id object-type object-instance "
"time property tag value [priority] [index]\r\n"
"\r\n"
"pid:\r\n"
"Process Identifier for this broadcast.\r\n"
"\r\n"
"time property tag value [priority] [index]\r\n" "\r\n" "pid:\r\n"
"Process Identifier for this broadcast.\r\n" "\r\n"
"device-id:\r\n"
"The Initiating BACnet Device Object Instance number.\r\n"
"\r\n"
"The Initiating BACnet Device Object Instance number.\r\n" "\r\n"
"object-type:\r\n"
"The monitored object type is the integer value of the\r\n"
"enumeration BACNET_OBJECT_TYPE in bacenum.h. For example,\r\n"
"if you were monitoring Analog Output 2, the object-type\r\n"
"would be 1.\r\n"
"\r\n"
"object-instance:\r\n"
"The monitored object instance number.\r\n"
"\r\n"
"time:\r\n"
"would be 1.\r\n" "\r\n" "object-instance:\r\n"
"The monitored object instance number.\r\n" "\r\n" "time:\r\n"
"The subscription time remaining is conveyed in seconds.\r\n"
"\r\n"
"property:\r\n"
"\r\n" "property:\r\n"
"The property is an integer value of the enumeration \r\n"
"BACNET_PROPERTY_ID in bacenum.h. For example, if you were\r\n"
"monitoring the Present Value property, you would use 85\r\n"
"as the property.\r\n"
"\r\n"
"tag:\r\n"
"as the property.\r\n" "\r\n" "tag:\r\n"
"Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \r\n"
"in bacenum.h. It is the data type of the value that you are\r\n"
"monitoring. For example, if you were monitoring a REAL value, you would \r\n"
"use a tag of 4."
"\r\n"
"value:\r\n"
"use a tag of 4." "\r\n" "value:\r\n"
"The value is an ASCII representation of some type of data that you\r\n"
"are monitoring. It is encoded using the tag information provided. For\r\n"
"example, if you were writing a REAL value of 100.0, you would use \r\n"
"100.0 as the value.\r\n"
"\r\n"
"[priority]:\r\n"
"100.0 as the value.\r\n" "\r\n" "[priority]:\r\n"
"This optional parameter is used for reporting the priority of the\r\n"
"value. If no priority is given, none is sent, and the BACnet \r\n"
"standard requires that the value is reported at the lowest \r\n"
"priority (16) if the object property supports priorities.\r\n"
"\r\n"
"[index]\r\n"
"\r\n" "[index]\r\n"
"This optional integer parameter is the index number of an array.\r\n"
"If the property is an array, individual elements can be reported.\r\n"
"\r\n"
"Here is a brief overview of BACnet property and tags:\r\n"
"\r\n" "Here is a brief overview of BACnet property and tags:\r\n"
"Certain properties are expected to be written with certain \r\n"
"application tags, so you probably need to know which ones to use\r\n"
"with each property of each object. It is almost safe to say that\r\n"
@@ -136,9 +119,7 @@ int main(
"accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\r\n"
"the demo to use this kind of table - but I also wanted to be able\r\n"
"to do negative testing by passing the wrong tag and have the server\r\n"
"return a reject message.\r\n"
"\r\n"
"Example:\r\n"
"return a reject message.\r\n" "\r\n" "Example:\r\n"
"If you want generate an unconfirmed COV,\r\n"
"you could send the following command:\r\n"
"%s 1 2 3 4 5 85 4 100.0\r\n"
@@ -191,12 +172,13 @@ int main(
return 1;
}
if (tag >= MAX_BACNET_APPLICATION_TAG) {
fprintf(stderr, "tag=%u - it must be less than %u\r\n",
tag, MAX_BACNET_APPLICATION_TAG);
fprintf(stderr, "tag=%u - it must be less than %u\r\n", tag,
MAX_BACNET_APPLICATION_TAG);
return 1;
}
status = bacapp_parse_application_data(tag,
value_string, &cov_data.listOfValues.value);
status =
bacapp_parse_application_data(tag, value_string,
&cov_data.listOfValues.value);
if (!status) {
/* FIXME: show the expected entry format for the tag */
fprintf(stderr, "unable to parse the tag value\r\n");
+5 -9
View File
@@ -121,14 +121,11 @@ int main(
/* note: priority 16 and 0 should produce the same end results... */
printf("Usage: %s <object-type object-instance | object-name>\r\n"
"Send BACnet WhoHas request to devices, and wait for responses.\r\n"
"\r\n"
"Use either:\r\n"
"The object-type can be 0 to %d.\r\n"
"The object-instance can be 0 to %d.\r\n"
"or:\r\n"
"\r\n" "Use either:\r\n" "The object-type can be 0 to %d.\r\n"
"The object-instance can be 0 to %d.\r\n" "or:\r\n"
"The object-name can be any string of characters.\r\n",
filename_remove_path(argv[0]),
MAX_BACNET_OBJECT_TYPE - 1, BACNET_MAX_INSTANCE);
filename_remove_path(argv[0]), MAX_BACNET_OBJECT_TYPE - 1,
BACNET_MAX_INSTANCE);
return 0;
}
/* decode the command line parameters */
@@ -138,8 +135,7 @@ int main(
Target_Object_Type = strtol(argv[1], NULL, 0);
Target_Object_Instance = strtol(argv[2], NULL, 0);
if (Target_Object_Instance > BACNET_MAX_INSTANCE) {
fprintf(stderr,
"object-instance=%u - it must be less than %u\r\n",
fprintf(stderr, "object-instance=%u - it must be less than %u\r\n",
Target_Object_Instance, BACNET_MAX_INSTANCE + 1);
return 1;
}
+10 -7
View File
@@ -117,8 +117,9 @@ static void LocalIAmHandler(
(void) src;
(void) service_len;
len = iam_decode_service_request(service_request,
&device_id, &max_apdu, &segmentation, &vendor_id);
len =
iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
if (len != -1) {
address_add(device_id, max_apdu, src);
} else
@@ -198,8 +199,8 @@ int main(
return 1;
/* configure the timeout values */
last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries();
timeout_seconds =
(Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */
@@ -222,8 +223,9 @@ int main(
break;
}
/* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address);
found =
address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) {
/* calculate the smaller of our APDU size or theirs
and remove the overhead of the APDU (varies depending on size).
@@ -252,7 +254,8 @@ int main(
pFile = fopen(Local_File_Name, "rb");
if (pFile) {
(void) fseek(pFile, fileStartPosition, SEEK_SET);
len = fread(octetstring_value(&fileData), 1,
len =
fread(octetstring_value(&fileData), 1,
requestedOctetCount, pFile);
if (len < requestedOctetCount)
End_Of_File_Detected = true;
+22 -34
View File
@@ -178,50 +178,39 @@ int main(
"communicate to. This number will be used to try and bind with\r\n"
"the device using Who-Is and I-Am services. For example, if you were\r\n"
"writing to Device Object 123, the device-instance would be 123.\r\n"
"\r\n"
"object-type:\r\n"
"\r\n" "object-type:\r\n"
"The object type is the integer value of the enumeration\r\n"
"BACNET_OBJECT_TYPE in bacenum.h. It is the object that you are\r\n"
"writing to. For example if you were writing to Analog Output 2, \r\n"
"the object-type would be 1.\r\n"
"\r\n"
"object-instance:\r\n"
"the object-type would be 1.\r\n" "\r\n" "object-instance:\r\n"
"This is the object instance number of the object that you are \r\n"
"writing to. For example, if you were writing to Analog Output 2, \r\n"
"the object-instance would be 2.\r\n"
"\r\n"
"property:\r\n"
"the object-instance would be 2.\r\n" "\r\n" "property:\r\n"
"The property is an integer value of the enumeration \r\n"
"BACNET_PROPERTY_ID in bacenum.h. It is the property you are \r\n"
"writing to. For example, if you were writing to the Present Value\r\n"
"property, you would use 85 as the property.\r\n"
"\r\n"
"property, you would use 85 as the property.\r\n" "\r\n"
"priority:\r\n"
"This parameter is used for setting the priority of the\r\n"
"write. If Priority 0 is given, no priority is sent. The BACnet \r\n"
"standard states that the value is written at the lowest \r\n"
"priority (16) if the object property supports priorities\r\n"
"when no priority is sent.\r\n"
"\r\n"
"index\r\n"
"when no priority is sent.\r\n" "\r\n" "index\r\n"
"This integer parameter is the index number of an array.\r\n"
"If the property is an array, individual elements can be written\r\n"
"to if supported. If this parameter is -1, the index is ignored.\r\n"
"\r\n"
"tag:\r\n"
"\r\n" "tag:\r\n"
"Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \r\n"
"in bacenum.h. It is the data type of the value that you are\r\n"
"writing. For example, if you were writing a REAL value, you would \r\n"
"use a tag of 4.\r\n"
"Context tags are created using two tags in a row. The context tag\r\n"
"is preceded by a C. Ctag tag. C2 4 creates a context 2 tagged REAL.\r\n"
"\r\n"
"value:\r\n"
"\r\n" "value:\r\n"
"The value is an ASCII representation of some type of data that you\r\n"
"are writing. It is encoded using the tag information provided. For\r\n"
"example, if you were writing a REAL value of 100.0, you would use \r\n"
"100.0 as the value.\r\n"
"\r\n"
"100.0 as the value.\r\n" "\r\n"
"Here is a brief overview of BACnet property and tags:\r\n"
"Certain properties are expected to be written with certain \r\n"
"application tags, so you probably need to know which ones to use\r\n"
@@ -232,15 +221,13 @@ int main(
"accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\r\n"
"the demo to use this kind of table - but I also wanted to be able\r\n"
"to do negative testing by passing the wrong tag and have the server\r\n"
"return a reject message.\r\n"
"\r\n"
"Example:\r\n"
"return a reject message.\r\n" "\r\n" "Example:\r\n"
"If you want send a 100 to the Present-Value in the Analog Output\r\n"
"at priority 16, you could send the following command:\r\n"
"%s 123 1 0 85 4 100\r\n"
"You could also send a relinquish command:\r\n"
"%s 123 1 0 85 0 0\r\n",
filename_remove_path(argv[0]), filename_remove_path(argv[0]));
"%s 123 1 0 85 0 0\r\n", filename_remove_path(argv[0]),
filename_remove_path(argv[0]));
}
return 0;
}
@@ -296,8 +283,9 @@ int main(
property_tag, MAX_BACNET_APPLICATION_TAG);
return 1;
}
status = bacapp_parse_application_data(property_tag,
value_string, &Target_Object_Property_Value[i]);
status =
bacapp_parse_application_data(property_tag, value_string,
&Target_Object_Property_Value[i]);
if (!status) {
/* FIXME: show the expected entry format for the tag */
fprintf(stderr, "unable to parse the tag value\r\n");
@@ -319,8 +307,8 @@ int main(
return 1;
/* configure the timeout values */
last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) *
Device_Number_Of_APDU_Retries();
timeout_seconds =
(Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries();
/* try to bind with the device */
Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance);
/* loop forever */
@@ -341,15 +329,15 @@ int main(
if (Error_Detected)
break;
/* wait until the device is bound, or timeout and quit */
found = address_bind_request(Target_Device_Object_Instance,
&max_apdu, &Target_Address);
found =
address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address);
if (found) {
if (invoke_id == 0) {
invoke_id =
Send_Write_Property_Request
(Target_Device_Object_Instance, Target_Object_Type,
Target_Object_Instance, Target_Object_Property,
&Target_Object_Property_Value[0],
Send_Write_Property_Request(Target_Device_Object_Instance,
Target_Object_Type, Target_Object_Instance,
Target_Object_Property, &Target_Object_Property_Value[0],
Target_Object_Property_Priority,
Target_Object_Property_Index);
} else if (tsm_invoke_id_free(invoke_id))