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
+1 -1
View File
@@ -1 +1 @@
-kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79
-kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79 -nhnl
+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))
+1 -1
View File
@@ -6,7 +6,7 @@
[ -x /usr/bin/dos2unix ] || exit 0
INDENTRC=".indent.pro"
if [ ! -x ${INDENTRC} ]
if [ ! -e ${INDENTRC} ]
then
echo No ${INDENTRC} file found. Creating ${INDENTRC} file.
echo "-kr -nut -nlp -ip4 -cli4 -bfda -nbc -nbbo -c0 -cd0 -cp0 -di0 -l79 -nhnl" > ${INDENTRC}
+8 -7
View File
@@ -122,11 +122,12 @@ int Analog_Input_Encode_Property_APDU(
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_OBJECT_TYPE:
apdu_len = encode_application_enumerated(&apdu[0],
OBJECT_ANALOG_INPUT);
apdu_len =
encode_application_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
break;
case PROP_PRESENT_VALUE:
apdu_len = encode_application_real(&apdu[0],
apdu_len =
encode_application_real(&apdu[0],
Analog_Input_Present_Value(object_instance));
break;
case PROP_STATUS_FLAGS:
@@ -177,14 +178,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
@@ -296,7 +296,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? */
@@ -400,14 +401,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);
+4 -4
View File
@@ -211,14 +211,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
@@ -207,7 +207,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? */
@@ -315,14 +316,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
@@ -277,7 +277,8 @@ int Device_Encode_Property_APDU(
/* FIXME: change the hardcoded names to suit your application */
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:
@@ -416,11 +417,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:
@@ -502,7 +505,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? */
@@ -510,8 +514,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.
Object_Id.instance))) {
(Device_Set_Object_Instance_Number(value.type.Object_Id.
instance))) {
/* we could send an I-Am broadcast to let the world know */
status = true;
} else {
+29 -32
View File
@@ -303,8 +303,9 @@ static bool dlmstp_compare_data_expecting_reply(
/* decode the request data */
request.address.mac[0] = src_address;
request.address.mac_len = 1;
offset = npdu_decode(&request_pdu[0],
NULL, &request.address, &request.npdu_data);
offset =
npdu_decode(&request_pdu[0], NULL, &request.address,
&request.npdu_data);
if (request.npdu_data.network_layer_message) {
return false;
}
@@ -321,8 +322,8 @@ static bool dlmstp_compare_data_expecting_reply(
/* decode the reply data */
reply.address.mac[0] = dest_address;
reply.address.mac_len = 1;
offset = npdu_decode(&reply_pdu[0],
&reply.address, NULL, &reply.npdu_data);
offset =
npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
if (reply.npdu_data.network_layer_message) {
return false;
}
@@ -788,9 +789,7 @@ static bool MSTP_Master_Node_FSM(
} else {
frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
}
MSTP_Send_Frame(frame_type,
TransmitPacketDest,
This_Station,
MSTP_Send_Frame(frame_type, TransmitPacketDest, This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen);
MSTP_Flag.TransmitPacketPending = false;
FrameCount++;
@@ -904,8 +903,8 @@ static bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */
TokenCount++;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
EventCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -927,8 +926,8 @@ static bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */
Poll_Station = This_Station;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
TokenCount = 1; /* changed in Errata SSPC-135-2004 */
EventCount = 0;
@@ -937,8 +936,8 @@ static bool MSTP_Master_Node_FSM(
} else {
/* SendMaintenancePFM */
Poll_Station = next_poll_station;
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
RetryCount = 0;
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
@@ -959,8 +958,8 @@ static bool MSTP_Master_Node_FSM(
/* RetrySendToken */
RetryCount++;
/* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
EventCount = 0;
/* re-enter the current state to listen for NS */
/* to begin using the token. */
@@ -969,8 +968,8 @@ static bool MSTP_Master_Node_FSM(
/* Assume that NS has failed. */
Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
/* no known successor node */
Next_Station = This_Station;
RetryCount = 0;
@@ -1003,8 +1002,8 @@ static bool MSTP_Master_Node_FSM(
/* on the network and is empowered to create a token. */
Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
/* indicate that the next station is unknown */
Next_Station = This_Station;
RetryCount = 0;
@@ -1027,8 +1026,8 @@ static bool MSTP_Master_Node_FSM(
Next_Station = SourceAddress;
EventCount = 0;
/* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
Poll_Station = This_Station;
TokenCount = 0;
RetryCount = 0;
@@ -1060,8 +1059,8 @@ static bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */
EventCount = 0;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
} else {
@@ -1092,10 +1091,10 @@ static bool MSTP_Master_Node_FSM(
case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST:
/* Note: we could wait for up to Treply_delay */
if (MSTP_Flag.TransmitPacketPending) {
matched = dlmstp_compare_data_expecting_reply(&InputBuffer[0],
DataLength,
SourceAddress,
&TransmitPacket[0], TransmitPacketLen, TransmitPacketDest);
matched =
dlmstp_compare_data_expecting_reply(&InputBuffer[0],
DataLength, SourceAddress, &TransmitPacket[0],
TransmitPacketLen, TransmitPacketDest);
}
if (MSTP_Flag.TransmitPacketPending && matched) {
/* Reply */
@@ -1111,9 +1110,7 @@ static bool MSTP_Master_Node_FSM(
} else {
frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
}
MSTP_Send_Frame(frame_type,
TransmitPacketDest,
This_Station,
MSTP_Send_Frame(frame_type, TransmitPacketDest, This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen);
MSTP_Flag.TransmitPacketPending = false;
Master_State = MSTP_MASTER_STATE_IDLE;
@@ -1127,8 +1124,8 @@ static bool MSTP_Master_Node_FSM(
/* Any reply shall wait until this node receives the token. */
/* Call MSTP_Send_Frame to transmit a Reply Postponed frame, */
/* and enter the IDLE state. */
MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED,
SourceAddress, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED, SourceAddress,
This_Station, NULL, 0);
Master_State = MSTP_MASTER_STATE_IDLE;
}
/* clear our flag we were holding for comparison */
+41 -30
View File
@@ -65,36 +65,41 @@ 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_VALUE:
if (Analog_Value_Valid_Instance(object_instance)) {
apdu_len = Analog_Value_Encode_Property_APDU(&Temp_Buf[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Analog_Value_Encode_Property_APDU(&Temp_Buf[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_VALUE:
if (Binary_Value_Valid_Instance(object_instance)) {
apdu_len = Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
object_instance,
property, array_index, error_class, error_code);
apdu_len =
Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
object_instance, property, array_index, error_class,
error_code);
}
break;
default:
@@ -125,28 +130,31 @@ 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);
goto RP_ABORT;
}
len = rp_decode_service_request(service_request, service_len, &data);
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);
goto RP_ABORT;
}
/* most cases will be 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];
@@ -160,19 +168,22 @@ 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);
goto RP_ABORT;
}
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);
}
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);
return;
}
+18 -14
View File
@@ -63,19 +63,22 @@ 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 (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);
goto WP_ABORT;
}
/* decode the service request only */
len = wp_decode_service_request(service_request, service_len, &wp_data);
/* 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);
goto WP_ABORT;
}
@@ -89,8 +92,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);
}
break;
case OBJECT_ANALOG_INPUT:
@@ -111,8 +114,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);
}
break;
case OBJECT_ANALOG_VALUE:
@@ -124,8 +127,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);
}
break;
default:
@@ -137,8 +140,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);
return;
}
+3 -2
View File
@@ -77,8 +77,9 @@ void LowLevelInit(
//
// OUT = 0 (not used)
// result: AT91C_CKGR_PLLR = 0x00000000480A0E (PLL Register)
pPMC->PMC_PLLR = ((AT91C_CKGR_DIV & 14) |
(AT91C_CKGR_PLLCOUNT & (10 << 8)) | (AT91C_CKGR_MUL & (72 << 16)));
pPMC->PMC_PLLR =
((AT91C_CKGR_DIV & 14) | (AT91C_CKGR_PLLCOUNT & (10 << 8)) |
(AT91C_CKGR_MUL & (72 << 16)));
// Wait the startup time (until PMC Status register LOCK bit is set)
while (!(pPMC->PMC_SR & AT91C_PMC_LOCK));
+1 -2
View File
@@ -155,8 +155,7 @@ static void bacnet_init(
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
handler_write_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);
#endif
}
+4 -4
View File
@@ -122,13 +122,13 @@ int Analog_Input_Encode_Property_APDU(
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_OBJECT_TYPE:
apdu_len = encode_application_enumerated(&apdu[0],
OBJECT_ANALOG_INPUT);
apdu_len =
encode_application_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
break;
case PROP_PRESENT_VALUE:
object_index = Analog_Input_Instance_To_Index(object_instance);
apdu_len = encode_application_real(&apdu[0],
Present_Value[object_index]);
apdu_len =
encode_application_real(&apdu[0], Present_Value[object_index]);
break;
case PROP_STATUS_FLAGS:
bitstring_init(&bit_string);
+4 -5
View File
@@ -103,12 +103,11 @@ void apdu_handler(
switch (apdu[0] & 0xF0) {
case PDU_TYPE_CONFIRMED_SERVICE_REQUEST:
len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */
apdu_len,
&service_data,
&service_choice, &service_request, &service_request_len);
apdu_len, &service_data, &service_choice, &service_request,
&service_request_len);
if (service_choice == SERVICE_CONFIRMED_READ_PROPERTY) {
handler_read_property(service_request,
service_request_len, src, &service_data);
handler_read_property(service_request, service_request_len,
src, &service_data);
}
#if 0
else if (service_choice == SERVICE_CONFIRMED_WRITE_PROPERTY) {
+6 -5
View File
@@ -175,7 +175,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? */
@@ -219,14 +220,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);
+8 -6
View File
@@ -217,7 +217,8 @@ int Device_Encode_Property_APDU(
/* FIXME: change the hardcoded names to suit your application */
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:
@@ -342,8 +343,8 @@ int Device_Encode_Property_APDU(
apdu_len = encode_application_unsigned(&apdu[0], MAX_APDU);
break;
case PROP_SEGMENTATION_SUPPORTED:
apdu_len = encode_application_enumerated(&apdu[0],
SEGMENTATION_NONE);
apdu_len =
encode_application_enumerated(&apdu[0], SEGMENTATION_NONE);
break;
case PROP_APDU_TIMEOUT:
apdu_len = encode_application_unsigned(&apdu[0], 60000);
@@ -396,7 +397,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? */
@@ -404,8 +406,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.
Object_Id.instance))) {
(Device_Set_Object_Instance_Number(value.type.Object_Id.
instance))) {
/* we could send an I-Am broadcast to let the world know */
status = true;
} else {
+20 -22
View File
@@ -697,8 +697,7 @@ static bool MSTP_Master_Node_FSM(
TransmitPacketLen = dlmstp_encode_unconfirmed_frame();
if (TransmitPacketLen) {
MSTP_Send_Frame(FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY,
MSTP_BROADCAST_ADDRESS,
This_Station,
MSTP_BROADCAST_ADDRESS, This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen);
FrameCount++;
} else {
@@ -798,8 +797,8 @@ static bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */
TokenCount++;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
EventCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -821,8 +820,8 @@ static bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */
Poll_Station = This_Station;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
TokenCount = 1; /* changed in Errata SSPC-135-2004 */
EventCount = 0;
@@ -831,8 +830,8 @@ static bool MSTP_Master_Node_FSM(
} else {
/* SendMaintenancePFM */
Poll_Station = next_poll_station;
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
RetryCount = 0;
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
@@ -853,8 +852,8 @@ static bool MSTP_Master_Node_FSM(
/* RetrySendToken */
RetryCount++;
/* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
EventCount = 0;
/* re-enter the current state to listen for NS */
/* to begin using the token. */
@@ -863,8 +862,8 @@ static bool MSTP_Master_Node_FSM(
/* Assume that NS has failed. */
Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
/* no known successor node */
Next_Station = This_Station;
RetryCount = 0;
@@ -897,8 +896,8 @@ static bool MSTP_Master_Node_FSM(
/* on the network and is empowered to create a token. */
Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER,
Poll_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
/* indicate that the next station is unknown */
Next_Station = This_Station;
RetryCount = 0;
@@ -921,8 +920,8 @@ static bool MSTP_Master_Node_FSM(
Next_Station = SourceAddress;
EventCount = 0;
/* Transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
Poll_Station = This_Station;
TokenCount = 0;
RetryCount = 0;
@@ -954,8 +953,8 @@ static bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */
EventCount = 0;
/* transmit a Token frame to NS */
MSTP_Send_Frame(FRAME_TYPE_TOKEN,
Next_Station, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_TOKEN, Next_Station,
This_Station, NULL, 0);
RetryCount = 0;
Master_State = MSTP_MASTER_STATE_PASS_TOKEN;
} else {
@@ -996,8 +995,7 @@ static bool MSTP_Master_Node_FSM(
/* and enter the IDLE state to wait for the next frame. */
/* Note: optimized such that we are never a client */
MSTP_Send_Frame(FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY,
TransmitPacketDest,
This_Station,
TransmitPacketDest, This_Station,
(uint8_t *) & TransmitPacket[0], TransmitPacketLen);
MSTP_Flag.TransmitPacketPending = false;
Master_State = MSTP_MASTER_STATE_IDLE;
@@ -1011,8 +1009,8 @@ static bool MSTP_Master_Node_FSM(
/* Any reply shall wait until this node receives the token. */
/* Call MSTP_Send_Frame to transmit a Reply Postponed frame, */
/* and enter the IDLE state. */
MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED,
SourceAddress, This_Station, NULL, 0);
MSTP_Send_Frame(FRAME_TYPE_REPLY_POSTPONED, SourceAddress,
This_Station, NULL, 0);
Master_State = MSTP_MASTER_STATE_IDLE;
}
/* clear our flag we were holding for comparison */
+29 -21
View File
@@ -67,15 +67,17 @@ 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_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;
default:
@@ -107,24 +109,27 @@ 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 (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);
} else 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);
} else {
/* most cases will be 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];
@@ -140,21 +145,24 @@ void handler_read_property(
switch (len) {
/* BACnet APDU too small to fit data, so proper response is Abort */
case -2:
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);
break;
case -1:
default:
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);
break;
}
}
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);
return;
}
+3 -2
View File
@@ -50,8 +50,9 @@ void handler_who_is(
int32_t target_device;
(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) {
Send_I_Am = true;
} else if (len != -1) {
+12 -8
View File
@@ -67,16 +67,19 @@ 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);
/* 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);
} else 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);
} else {
switch (wp_data.object_type) {
#if 0
@@ -143,8 +146,9 @@ void handler_write_property(
}
}
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);
return;
}
+9 -10
View File
@@ -124,8 +124,8 @@ static int arcnet_bind(
"You might need to add the following to modules.conf\n"
"(or in /etc/modutils/alias on Debian with update-modules):\n"
"alias net-pf-17 af_packet\n"
"Also, add af_packet to /etc/modules.\n"
"Then follow it by:\n" "# modprobe af_packet\n");
"Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
"# modprobe af_packet\n");
exit(-1);
}
@@ -144,14 +144,14 @@ static int arcnet_bind(
if (bind(sock_fd, &ARCNET_Socket_Address,
sizeof(ARCNET_Socket_Address)) != 0) {
/* Bind problem, close socket and return */
fprintf(stderr,
"arcnet: Unable to bind socket : %s\n", strerror(errno));
fprintf(stderr, "arcnet: Unable to bind socket : %s\n",
strerror(errno));
fprintf(stderr,
"You might need to add the following to modules.conf\n"
"(or in /etc/modutils/alias on Debian with update-modules):\n"
"alias net-pf-17 af_packet\n"
"Also, add af_packet to /etc/modules.\n"
"Then follow it by:\n" "# modprobe af_packet\n");
"Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
"# modprobe af_packet\n");
/* Close the socket */
close(sock_fd);
exit(-1);
@@ -170,8 +170,8 @@ static int arcnet_bind(
/* Strcpy the interface name into the address */
strncpy(ARCNET_Socket_Address.sa_data, interface_name,
sizeof(ARCNET_Socket_Address.sa_data) - 1);
fprintf(stderr, "arcnet: MAC=%02Xh iface=\"%s\"\n",
ARCNET_MAC_Address, ARCNET_Socket_Address.sa_data);
fprintf(stderr, "arcnet: MAC=%02Xh iface=\"%s\"\n", ARCNET_MAC_Address,
ARCNET_Socket_Address.sa_data);
atexit(arcnet_cleanup);
@@ -295,8 +295,7 @@ uint16_t arcnet_receive(
/* using O_NONBLOCK and no data */
/* was immediately available for reading. */
if (errno != EAGAIN)
fprintf(stderr,
"ethernet: Read error in receiving packet: %s\n",
fprintf(stderr, "ethernet: Read error in receiving packet: %s\n",
strerror(errno));
return 0;
}
+10 -8
View File
@@ -103,8 +103,8 @@ static void bip_set_interface(
if (BIP_Debug) {
fprintf(stderr, "IP Broadcast Address: %s\n",
inet_ntoa(broadcast_address));
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n",
bip_get_port(), bip_get_port());
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", bip_get_port(),
bip_get_port());
}
}
@@ -128,16 +128,18 @@ bool bip_init(
/* Allow us to use the same socket for sending and receiving */
/* This makes sure that the src port is correct when sending */
sockopt = 1;
status = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
&sockopt, sizeof(sockopt));
status =
setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &sockopt,
sizeof(sockopt));
if (status < 0) {
close(sock_fd);
bip_set_socket(-1);
return status;
}
/* allow us to send a broadcast */
status = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
&sockopt, sizeof(sockopt));
status =
setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, &sockopt,
sizeof(sockopt));
if (status < 0) {
close(sock_fd);
bip_set_socket(-1);
@@ -148,8 +150,8 @@ bool bip_init(
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(bip_get_port());
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
status = bind(sock_fd,
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
status =
bind(sock_fd, (const struct sockaddr *) &sin, sizeof(struct sockaddr));
if (status < 0) {
close(sock_fd);
bip_set_socket(-1);
+22 -27
View File
@@ -177,8 +177,7 @@ uint16_t dlmstp_receive(
/* was immediately available for reading. */
if (errno != EAGAIN) {
#if PRINT_ENABLED
fprintf(stderr,
"mstp: Read error in Receive_Client packet: %s\n",
fprintf(stderr, "mstp: Read error in Receive_Client packet: %s\n",
strerror(errno));
#endif
}
@@ -320,8 +319,8 @@ int dlmstp_get_transmit_packet(
max = Transmit_Client_SockFD;
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0) {
received_bytes = read(Transmit_Client_SockFD,
packet, sizeof(DLMSTP_PACKET));
received_bytes =
read(Transmit_Client_SockFD, packet, sizeof(DLMSTP_PACKET));
} else {
return 0;
}
@@ -333,8 +332,7 @@ int dlmstp_get_transmit_packet(
/* was immediately available for reading. */
if (errno != EAGAIN) {
#if PRINT_ENABLED
fprintf(stderr,
"mstp: Read error in Transmit_Client packet: %s\n",
fprintf(stderr, "mstp: Read error in Transmit_Client packet: %s\n",
strerror(errno));
#endif
}
@@ -369,9 +367,8 @@ uint16_t MSTP_Get_Send(
}
/* convert the PDU into the MSTP Frame */
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
mstp_port->OutputBufferSize,
packet.frame_type,
destination, mstp_port->This_Station, &packet.pdu[0], packet.pdu_len);
mstp_port->OutputBufferSize, packet.frame_type, destination,
mstp_port->This_Station, &packet.pdu[0], packet.pdu_len);
return pdu_len;
}
@@ -401,8 +398,9 @@ bool dlmstp_compare_data_expecting_reply(
/* decode the request data */
request.address.mac[0] = src_address;
request.address.mac_len = 1;
offset = npdu_decode(&request_pdu[0],
NULL, &request.address, &request.npdu_data);
offset =
npdu_decode(&request_pdu[0], NULL, &request.address,
&request.npdu_data);
if (request.npdu_data.network_layer_message) {
return false;
}
@@ -418,8 +416,8 @@ bool dlmstp_compare_data_expecting_reply(
request.service_choice = request_pdu[offset + 3];
/* decode the reply data */
bacnet_address_copy(&reply.address, dest_address);
offset = npdu_decode(&reply_pdu[0],
&reply.address, NULL, &reply.npdu_data);
offset =
npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
if (reply.npdu_data.network_layer_message) {
return false;
}
@@ -508,25 +506,23 @@ uint16_t MSTP_Get_Reply(
return 0;
}
/* is this the reply to the DER? */
matched = dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
mstp_port->DataLength,
mstp_port->SourceAddress,
&Transmit_Packet.pdu[0],
Transmit_Packet.pdu_len, &Transmit_Packet.address);
matched =
dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
mstp_port->DataLength, mstp_port->SourceAddress,
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len,
&Transmit_Packet.address);
if (matched) {
/* convert the PDU into the MSTP Frame */
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
mstp_port->OutputBufferSize,
Transmit_Packet.frame_type,
destination,
mstp_port->This_Station,
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len);
mstp_port->OutputBufferSize, Transmit_Packet.frame_type,
destination, mstp_port->This_Station, &Transmit_Packet.pdu[0],
Transmit_Packet.pdu_len);
/* not used here, but setting it anyway */
Transmit_Packet.ready = false;
} else {
/* put it back into the queue */
(void) write(Transmit_Server_SockFD,
&Transmit_Packet, sizeof(Transmit_Packet));
(void) write(Transmit_Server_SockFD, &Transmit_Packet,
sizeof(Transmit_Packet));
}
return pdu_len;
@@ -842,8 +838,7 @@ int main(
/* forever task */
for (;;) {
#if (defined(MSTP_TEST_REQUEST) && MSTP_TEST_REQUEST)
MSTP_Create_And_Send_Frame(&MSTP_Port,
FRAME_TYPE_TEST_REQUEST,
MSTP_Create_And_Send_Frame(&MSTP_Port, FRAME_TYPE_TEST_REQUEST,
MSTP_Port.SourceAddress, MSTP_Port.This_Station, NULL, 0);
nanosleep(&timeOut, &remains);
#endif
+11 -12
View File
@@ -112,14 +112,14 @@ static int ethernet_bind(
/* Attempt to open the socket for 802.2 ethernet frames */
if ((sock_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0) {
/* Error occured */
fprintf(stderr,
"ethernet: Error opening socket: %s\n", strerror(errno));
fprintf(stderr, "ethernet: Error opening socket: %s\n",
strerror(errno));
fprintf(stderr,
"You might need to add the following to modules.conf\n"
"(or in /etc/modutils/alias on Debian with update-modules):\n"
"alias net-pf-17 af_packet\n"
"Also, add af_packet to /etc/modules.\n"
"Then follow it by:\n" "# modprobe af_packet\n");
"Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
"# modprobe af_packet\n");
exit(-1);
}
/* Bind the socket to an address */
@@ -132,14 +132,14 @@ static int ethernet_bind(
/* Attempt to bind the socket to the interface */
if (bind(sock_fd, eth_addr, sizeof(struct sockaddr)) != 0) {
/* Bind problem, close socket and return */
fprintf(stderr,
"ethernet: Unable to bind 802.2 socket : %s\n", strerror(errno));
fprintf(stderr, "ethernet: Unable to bind 802.2 socket : %s\n",
strerror(errno));
fprintf(stderr,
"You might need to add the following to modules.conf\n"
"(or in /etc/modutils/alias on Debian with update-modules):\n"
"alias net-pf-17 af_packet\n"
"Also, add af_packet to /etc/modules.\n"
"Then follow it by:\n" "# modprobe af_packet\n");
"Also, add af_packet to /etc/modules.\n" "Then follow it by:\n"
"# modprobe af_packet\n");
/* Close the socket */
close(sock_fd);
exit(-1);
@@ -248,8 +248,8 @@ int ethernet_send_pdu(
/* Send the packet */
bytes =
sendto(eth802_sockfd, &mtu, mtu_len, 0,
(struct sockaddr *) &eth_addr, sizeof(struct sockaddr));
sendto(eth802_sockfd, &mtu, mtu_len, 0, (struct sockaddr *) &eth_addr,
sizeof(struct sockaddr));
/* did it get sent? */
if (bytes < 0)
fprintf(stderr, "ethernet: Error sending packet: %s\n",
@@ -303,8 +303,7 @@ uint16_t ethernet_receive(
/* using O_NONBLOCK and no data */
/* was immediately available for reading. */
if (errno != EAGAIN)
fprintf(stderr,
"ethernet: Read error in receiving packet: %s\n",
fprintf(stderr, "ethernet: Read error in receiving packet: %s\n",
strerror(errno));
return 0;
}
+5 -4
View File
@@ -63,8 +63,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);
fprintf(stderr, "Received I-Am Request");
if (len != -1) {
fprintf(stderr, " from %u!\n", device_id);
@@ -138,8 +139,8 @@ static void Read_Properties(
got the reply with matching invoke ID or the TSM of the
invoke ID expired. This demo is doing things asynchronously. */
status = Send_Read_Property_Request(device_id, /* destination device */
OBJECT_DEVICE,
device_id, object_props[property], BACNET_ARRAY_ALL);
OBJECT_DEVICE, device_id, object_props[property],
BACNET_ARRAY_ALL);
if (status)
property++;
}
+5 -9
View File
@@ -160,20 +160,16 @@ static void print_received_packet(
/* Data CRC: (present only if Length is non-zero) two octets, */
/* least significant octet first */
/* (pad): (optional) at most one octet of padding: X'FF' */
fprintf(stderr,
"55 FF %02X %02X %02X %02X %02X %02X ",
mstp_port->FrameType,
mstp_port->DestinationAddress,
mstp_port->SourceAddress,
HI_BYTE(mstp_port->DataLength),
fprintf(stderr, "55 FF %02X %02X %02X %02X %02X %02X ",
mstp_port->FrameType, mstp_port->DestinationAddress,
mstp_port->SourceAddress, HI_BYTE(mstp_port->DataLength),
LO_BYTE(mstp_port->DataLength), mstp_port->HeaderCRCActual);
if (mstp_port->DataLength) {
for (i = 0; i < mstp_port->DataLength; i++) {
fprintf(stderr, "%02X ", mstp_port->InputBuffer[i]);
}
fprintf(stderr,
"%02X %02X ",
mstp_port->DataCRCActualMSB, mstp_port->DataCRCActualLSB);
fprintf(stderr, "%02X %02X ", mstp_port->DataCRCActualMSB,
mstp_port->DataCRCActualLSB);
}
fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType));
fprintf(stderr, "\n");
+8 -7
View File
@@ -119,11 +119,12 @@ int Analog_Input_Encode_Property_APDU(
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_OBJECT_TYPE:
apdu_len = encode_application_enumerated(&apdu[0],
OBJECT_ANALOG_INPUT);
apdu_len =
encode_application_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
break;
case PROP_PRESENT_VALUE:
apdu_len = encode_application_real(&apdu[0],
apdu_len =
encode_application_real(&apdu[0],
Analog_Input_Present_Value(object_instance));
break;
case PROP_STATUS_FLAGS:
@@ -174,14 +175,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
@@ -293,7 +293,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? */
@@ -397,14 +398,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);
+4 -4
View File
@@ -208,14 +208,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
@@ -208,7 +208,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? */
@@ -316,14 +317,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
@@ -284,7 +284,8 @@ int Device_Encode_Property_APDU(
/* FIXME: change the hardcoded names to suit your application */
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:
@@ -428,11 +429,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:
@@ -514,7 +517,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? */
@@ -522,8 +526,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.
Object_Id.instance))) {
(Device_Set_Object_Instance_Number(value.type.Object_Id.
instance))) {
/* we could send an I-Am broadcast to let the world know */
status = true;
} else {
+6 -7
View File
@@ -139,11 +139,10 @@ int dlmstp_send_pdu(
if ((8 /* header len */ + pdu_len) > MAX_MPDU) {
return -4;
}
bytes_sent = MSTP_Create_Frame(
(uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer),
MSTP_Port.TxFrameType,
destination, MSTP_Port.This_Station, pdu, pdu_len);
bytes_sent =
MSTP_Create_Frame((uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer), MSTP_Port.TxFrameType, destination,
MSTP_Port.This_Station, pdu, pdu_len);
MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true;
MSTP_Packets++;
@@ -180,8 +179,8 @@ void dlmstp_task(
if (Receive_Buffer.ready && !MSTP_Port.TxReady) {
if (Receive_Buffer.pdu_len) {
MSTP_Packets++;
npdu_handler(&Receive_Buffer.address,
&Receive_Buffer.pdu[0], Receive_Buffer.pdu_len);
npdu_handler(&Receive_Buffer.address, &Receive_Buffer.pdu[0],
Receive_Buffer.pdu_len);
}
Receive_Buffer.ready = false;
}
+44 -37
View File
@@ -66,19 +66,22 @@ 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);
goto RP_ABORT;
}
len = rp_decode_service_request(service_request, service_len, &data);
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);
goto RP_ABORT;
}
@@ -88,26 +91,27 @@ void handler_read_property(
case OBJECT_DEVICE:
/* FIXME: probably need a length limitation sent with encode */
if (Device_Valid_Object_Instance_Number(data.object_instance)) {
len = Device_Encode_Property_APDU(&Temp_Buf[0],
data.object_property,
data.array_index, &error_class, &error_code);
len =
Device_Encode_Property_APDU(&Temp_Buf[0],
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];
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
error = false;
}
}
break;
case OBJECT_ANALOG_INPUT:
if (Analog_Input_Valid_Instance(data.object_instance)) {
len = Analog_Input_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance,
data.object_property,
len =
Analog_Input_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance, data.object_property,
data.array_index, &error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
@@ -115,17 +119,17 @@ void handler_read_property(
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
error = false;
}
}
break;
case OBJECT_BINARY_INPUT:
if (Binary_Input_Valid_Instance(data.object_instance)) {
len = Binary_Input_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance,
data.object_property,
len =
Binary_Input_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance, data.object_property,
data.array_index, &error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
@@ -133,17 +137,17 @@ void handler_read_property(
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
error = false;
}
}
break;
case OBJECT_BINARY_VALUE:
if (Binary_Value_Valid_Instance(data.object_instance)) {
len = Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance,
data.object_property,
len =
Binary_Value_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance, data.object_property,
data.array_index, &error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
@@ -151,17 +155,17 @@ void handler_read_property(
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
error = false;
}
}
break;
case OBJECT_ANALOG_VALUE:
if (Analog_Value_Valid_Instance(data.object_instance)) {
len = Analog_Value_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance,
data.object_property,
len =
Analog_Value_Encode_Property_APDU(&Temp_Buf[0],
data.object_instance, data.object_property,
data.array_index, &error_class, &error_code);
if (len >= 0) {
/* encode the APDU portion of the packet */
@@ -169,8 +173,8 @@ void handler_read_property(
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer
[pdu_len], service_data->invoke_id, &data);
rp_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, &data);
error = false;
}
}
@@ -181,19 +185,22 @@ 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);
goto RP_ABORT;
}
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);
}
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);
return;
}
+18 -14
View File
@@ -62,19 +62,22 @@ 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 (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);
goto WP_ABORT;
}
/* decode the service request only */
len = wp_decode_service_request(service_request, service_len, &wp_data);
/* 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);
goto WP_ABORT;
}
@@ -91,8 +94,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, "Sending Write Property Error for Device!\n");
#endif
@@ -122,8 +125,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, "Sending Write Access Error for BV!\n");
#endif
@@ -141,8 +144,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, "Sending Write Access Error for AV!\n");
#endif
@@ -160,8 +163,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, "Failed to send PDU (%s)!\n", strerror(errno));
+3 -4
View File
@@ -106,14 +106,13 @@ static void BACnet_Service_Handlers_Init(
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
handler_write_property);
#if 0
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);
#endif
/* 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);
}
+36 -49
View File
@@ -506,7 +506,8 @@ void MSTP_Receive_Frame_FSM(
#endif
/* DataOctet */
if (mstp_port->Index < mstp_port->DataLength) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
mstp_port->InputBuffer[mstp_port->Index] =
mstp_port->DataRegister;
@@ -515,14 +516,16 @@ void MSTP_Receive_Frame_FSM(
}
/* CRC1 */
else if (mstp_port->Index == mstp_port->DataLength) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
mstp_port->Index++;
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;
}
/* CRC2 */
else if (mstp_port->Index == (mstp_port->DataLength + 1)) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
/* STATE DATA CRC - no need for new state */
/* indicate the complete reception of a valid frame */
@@ -570,26 +573,21 @@ bool MSTP_Master_Node_FSM(
#endif
/* some calculations that several states need */
next_poll_station = (mstp_port->Poll_Station + 1) %
(mstp_port->Nmax_master + 1);
next_this_station = (mstp_port->This_Station + 1) %
(mstp_port->Nmax_master + 1);
next_next_station = (mstp_port->Next_Station + 1) %
(mstp_port->Nmax_master + 1);
next_poll_station =
(mstp_port->Poll_Station + 1) % (mstp_port->Nmax_master + 1);
next_this_station =
(mstp_port->This_Station + 1) % (mstp_port->Nmax_master + 1);
next_next_station =
(mstp_port->Next_Station + 1) % (mstp_port->Nmax_master + 1);
#if PRINT_ENABLED_MASTER
if (mstp_port->master_state != master_state) {
master_state = mstp_port->master_state;
fprintf(stderr,
"MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n",
mstp_port->This_Station,
next_this_station,
mstp_port->Next_Station,
next_next_station,
mstp_port->Poll_Station,
next_poll_station,
mstp_port->EventCount,
mstp_port->TokenCount,
mstp_port->SilenceTimer,
mstp_port->This_Station, next_this_station,
mstp_port->Next_Station, next_next_station,
mstp_port->Poll_Station, next_poll_station, mstp_port->EventCount,
mstp_port->TokenCount, mstp_port->SilenceTimer,
mstptext_master_state(mstp_port->master_state));
}
#endif
@@ -625,17 +623,14 @@ bool MSTP_Master_Node_FSM(
#if PRINT_ENABLED_MASTER
fprintf(stderr,
"MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\n",
mstp_port->SourceAddress,
mstp_port->DestinationAddress,
mstp_port->DataLength,
mstp_port->FrameCount,
mstp_port->SourceAddress, mstp_port->DestinationAddress,
mstp_port->DataLength, mstp_port->FrameCount,
mstp_port->SilenceTimer,
mstptext_frame_type(mstp_port->FrameType));
#endif
/* destined for me! */
if ((mstp_port->DestinationAddress ==
mstp_port->This_Station) ||
(mstp_port->DestinationAddress ==
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|| (mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) {
switch (mstp_port->FrameType) {
/* ReceivedToken */
@@ -827,10 +822,9 @@ bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */
mstp_port->TokenCount++;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station,
mstp_port->This_Station, NULL, 0);
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->RetryCount = 0;
mstp_port->EventCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -854,10 +848,9 @@ bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */
mstp_port->Poll_Station = mstp_port->This_Station;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station,
mstp_port->This_Station, NULL, 0);
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->RetryCount = 0;
mstp_port->TokenCount = 1; /* changed in Errata SSPC-135-2004 */
mstp_port->EventCount = 0;
@@ -867,8 +860,8 @@ bool MSTP_Master_Node_FSM(
/* SendMaintenancePFM */
mstp_port->Poll_Station = next_poll_station;
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
@@ -889,8 +882,7 @@ bool MSTP_Master_Node_FSM(
/* RetrySendToken */
mstp_port->RetryCount++;
/* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->EventCount = 0;
@@ -902,9 +894,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL,
0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
/* no known successor node */
mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0;
@@ -940,9 +931,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL,
0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
/* indicate that the next station is unknown */
mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0;
@@ -967,8 +957,7 @@ bool MSTP_Master_Node_FSM(
mstp_port->Next_Station = mstp_port->SourceAddress;
mstp_port->EventCount = 0;
/* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->Poll_Station = mstp_port->This_Station;
@@ -1002,8 +991,7 @@ bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */
mstp_port->EventCount = 0;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station,
NULL, 0);
mstp_port->RetryCount = 0;
@@ -1073,8 +1061,7 @@ bool MSTP_Master_Node_FSM(
/* and enter the IDLE state. */
{
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_REPLY_POSTPONED,
mstp_port->SourceAddress,
FRAME_TYPE_REPLY_POSTPONED, mstp_port->SourceAddress,
mstp_port->This_Station, NULL, 0);
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
}
+4 -4
View File
@@ -174,8 +174,8 @@ static void NetInitialize(
}
#else
/* Set the IP address and interface */
printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0],
TargetIP[1], TargetIP[2], TargetIP[3]);
printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0], TargetIP[1],
TargetIP[2], TargetIP[3]);
Result = xn_set_ip(interface, TargetIP, NetMask);
/* define default gateway and DNS server */
xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface, RT_INF);
@@ -271,8 +271,8 @@ bool bip_init(
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(bip_get_port());
memset(&(sin.sin_zero), '\0', 8);
rv = bind(sock_fd,
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
rv = bind(sock_fd, (const struct sockaddr *) &sin,
sizeof(struct sockaddr));
if (rv < 0) {
close(sock_fd);
bip_set_socket(-1);
+4 -5
View File
@@ -98,11 +98,10 @@ int dlmstp_send_pdu(
}
memmove(&PDU_Buffer[mtu_len], pdu, pdu_len);
mtu_len += pdu_len;
bytes_sent = MSTP_Create_Frame(
(uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer),
MSTP_Port.TxFrameType,
destination, MSTP_Port.This_Station, &PDU_Buffer[0], mtu_len);
bytes_sent =
MSTP_Create_Frame((uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer), MSTP_Port.TxFrameType, destination,
MSTP_Port.This_Station, &PDU_Buffer[0], mtu_len);
MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true;
}
+3 -4
View File
@@ -78,8 +78,8 @@ bool ethernet_init(
fprintf(stderr, "ethernet: failed to bind to socket!\r\n");
Ethernet_Address.sa_family = AF_INET;
memset(Ethernet_Address.sa_data, 0, sizeof(Ethernet_Address.sa_data));
if (bind(Ethernet_Socket,
&Ethernet_Address, sizeof(Ethernet_Address)) == SOCKET_ERROR)
if (bind(Ethernet_Socket, &Ethernet_Address,
sizeof(Ethernet_Address)) == SOCKET_ERROR)
fprintf(stderr, "ethernet: failed to bind to socket!\r\n");
/*setsockopt(Ethernet_Socket,SOL_SOCKET,SO_802_2,(char *)&value,sizeof(value)); */
@@ -227,8 +227,7 @@ uint16_t ethernet_receive(
/* using O_NONBLOCK and no data */
/* was immediately available for reading. */
if (errno != EAGAIN)
fprintf(stderr,
"ethernet: Read error in receiving packet: %s\n",
fprintf(stderr, "ethernet: Read error in receiving packet: %s\n",
strerror(errno));
return 0;
}
+36 -49
View File
@@ -560,7 +560,8 @@ void MSTP_Receive_Frame_FSM(
#endif
/* DataOctet */
if (mstp_port->Index < mstp_port->DataLength) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
mstp_port->InputBuffer[mstp_port->Index] =
mstp_port->DataRegister;
@@ -569,14 +570,16 @@ void MSTP_Receive_Frame_FSM(
}
/* CRC1 */
else if (mstp_port->Index == mstp_port->DataLength) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
mstp_port->Index++;
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;
}
/* CRC2 */
else if (mstp_port->Index == (mstp_port->DataLength + 1)) {
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC =
CRC_Calc_Data(mstp_port->DataRegister,
mstp_port->DataCRC);
/* STATE DATA CRC - no need for new state */
/* indicate the complete reception of a valid frame */
@@ -708,26 +711,21 @@ bool MSTP_Master_Node_FSM(
#endif
/* some calculations that several states need */
next_poll_station = (mstp_port->Poll_Station + 1) %
(mstp_port->Nmax_master + 1);
next_this_station = (mstp_port->This_Station + 1) %
(mstp_port->Nmax_master + 1);
next_next_station = (mstp_port->Next_Station + 1) %
(mstp_port->Nmax_master + 1);
next_poll_station =
(mstp_port->Poll_Station + 1) % (mstp_port->Nmax_master + 1);
next_this_station =
(mstp_port->This_Station + 1) % (mstp_port->Nmax_master + 1);
next_next_station =
(mstp_port->Next_Station + 1) % (mstp_port->Nmax_master + 1);
#if PRINT_ENABLED_MASTER
if (mstp_port->master_state != master_state) {
master_state = mstp_port->master_state;
fprintf(stderr,
"MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n",
mstp_port->This_Station,
next_this_station,
mstp_port->Next_Station,
next_next_station,
mstp_port->Poll_Station,
next_poll_station,
mstp_port->EventCount,
mstp_port->TokenCount,
mstp_port->SilenceTimer,
mstp_port->This_Station, next_this_station,
mstp_port->Next_Station, next_next_station,
mstp_port->Poll_Station, next_poll_station, mstp_port->EventCount,
mstp_port->TokenCount, mstp_port->SilenceTimer,
mstp_master_state_text(mstp_port->master_state));
}
#endif
@@ -763,17 +761,14 @@ bool MSTP_Master_Node_FSM(
#if PRINT_ENABLED_MASTER
fprintf(stderr,
"MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\n",
mstp_port->SourceAddress,
mstp_port->DestinationAddress,
mstp_port->DataLength,
mstp_port->FrameCount,
mstp_port->SourceAddress, mstp_port->DestinationAddress,
mstp_port->DataLength, mstp_port->FrameCount,
mstp_port->SilenceTimer,
mstp_frame_type_text(mstp_port->FrameType));
#endif
/* destined for me! */
if ((mstp_port->DestinationAddress ==
mstp_port->This_Station) ||
(mstp_port->DestinationAddress ==
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|| (mstp_port->DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) {
switch (mstp_port->FrameType) {
/* ReceivedToken */
@@ -964,10 +959,9 @@ bool MSTP_Master_Node_FSM(
/* address at which a new master node may be found in that case. */
mstp_port->TokenCount++;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station,
mstp_port->This_Station, NULL, 0);
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->RetryCount = 0;
mstp_port->EventCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;
@@ -991,10 +985,9 @@ bool MSTP_Master_Node_FSM(
/* ResetMaintenancePFM */
mstp_port->Poll_Station = mstp_port->This_Station;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
mstp_port->Next_Station,
mstp_port->This_Station, NULL, 0);
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->RetryCount = 0;
mstp_port->TokenCount = 1; /* changed in Errata SSPC-135-2004 */
mstp_port->EventCount = 0;
@@ -1004,8 +997,8 @@ bool MSTP_Master_Node_FSM(
/* SendMaintenancePFM */
mstp_port->Poll_Station = next_poll_station;
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
}
@@ -1027,8 +1020,7 @@ bool MSTP_Master_Node_FSM(
/* RetrySendToken */
mstp_port->RetryCount++;
/* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->EventCount = 0;
@@ -1040,9 +1032,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_next_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL,
0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
/* no known successor node */
mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0;
@@ -1079,9 +1070,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->Poll_Station = next_this_station;
/* Transmit a Poll For Master frame to PS. */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER,
mstp_port->Poll_Station, mstp_port->This_Station, NULL,
0);
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0);
/* indicate that the next station is unknown */
mstp_port->Next_Station = mstp_port->This_Station;
mstp_port->RetryCount = 0;
@@ -1107,8 +1097,7 @@ bool MSTP_Master_Node_FSM(
mstp_port->Next_Station = mstp_port->SourceAddress;
mstp_port->EventCount = 0;
/* Transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station, NULL,
0);
mstp_port->Poll_Station = mstp_port->This_Station;
@@ -1141,8 +1130,7 @@ bool MSTP_Master_Node_FSM(
/* poll for a master at address PS. */
mstp_port->EventCount = 0;
/* transmit a Token frame to NS */
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_TOKEN,
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
mstp_port->Next_Station, mstp_port->This_Station,
NULL, 0);
mstp_port->RetryCount = 0;
@@ -1214,8 +1202,7 @@ bool MSTP_Master_Node_FSM(
/* and enter the IDLE state. */
{
MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_REPLY_POSTPONED,
mstp_port->SourceAddress,
FRAME_TYPE_REPLY_POSTPONED, mstp_port->SourceAddress,
mstp_port->This_Station, NULL, 0);
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
transition_now = true;
+15 -16
View File
@@ -214,8 +214,7 @@ static char *winsock_error_code_text(
case WSAEDISCON:
return "Disconnect.";
case WSAHOST_NOT_FOUND:
return "Host not found. "
"This message indicates that the key "
return "Host not found. " "This message indicates that the key "
"(name, address, and so on) was not found.";
case WSATRY_AGAIN:
return "Nonauthoritative host not found. "
@@ -251,8 +250,8 @@ bool bip_init(
/*Result = WSAStartup(MAKEWORD(2,2), &wd); */
if (Result != 0) {
Code = WSAGetLastError();
printf("TCP/IP stack initialization failed\n"
" error code: %i %s\n", Code, winsock_error_code_text(Code));
printf("TCP/IP stack initialization failed\n" " error code: %i %s\n",
Code, winsock_error_code_text(Code));
exit(1);
}
atexit(cleanup);
@@ -265,8 +264,8 @@ bool bip_init(
address.s_addr = gethostaddr();
if (address.s_addr == (unsigned) -1) {
Code = WSAGetLastError();
printf("Get host address failed\n"
" error code: %i %s\n", Code, winsock_error_code_text(Code));
printf("Get host address failed\n" " error code: %i %s\n", Code,
winsock_error_code_text(Code));
exit(1);
}
bip_set_addr(address.s_addr);
@@ -282,8 +281,8 @@ bool bip_init(
broadcast_address.s_addr = htonl(bip_get_broadcast_addr());
fprintf(stderr, "IP Broadcast Address: %s\n",
inet_ntoa(broadcast_address));
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n",
bip_get_port(), bip_get_port());
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", bip_get_port(),
bip_get_port());
}
/* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@@ -294,8 +293,8 @@ bool bip_init(
}
/* Allow us to use the same socket for sending and receiving */
/* This makes sure that the src port is correct when sending */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
(char *) &value, sizeof(value));
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &value,
sizeof(value));
if (rv < 0) {
fprintf(stderr, "bip: failed to set REUSEADDR socket option.\n");
close(sock_fd);
@@ -303,8 +302,8 @@ bool bip_init(
return false;
}
/* allow us to send a broadcast */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
(char *) &value, sizeof(value));
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, (char *) &value,
sizeof(value));
if (rv < 0) {
fprintf(stderr, "bip: failed to set BROADCAST socket option.\n");
close(sock_fd);
@@ -315,8 +314,8 @@ bool bip_init(
/* probably only for Apple... */
/* rebind a port that is already in use.
Note: all users of the port must specify this flag */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT,
(char *) &value, sizeof(value));
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT, (char *) &value,
sizeof(value));
if (rv < 0) {
fprintf(stderr, "bip: failed to set REUSEPORT socket option.\n");
close(sock_fd);
@@ -347,8 +346,8 @@ bool bip_init(
#endif
sin.sin_port = htons(bip_get_port());
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
rv = bind(sock_fd,
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
rv = bind(sock_fd, (const struct sockaddr *) &sin,
sizeof(struct sockaddr));
if (rv < 0) {
fprintf(stderr, "bip: failed to bind to %s port %hd\n",
inet_ntoa(sin.sin_addr), bip_get_port());
+20 -24
View File
@@ -144,13 +144,12 @@ uint16_t dlmstp_receive(
if (Receive_Packet.pdu_len) {
MSTP_Packets++;
if (src) {
memmove(src,
&Receive_Packet.address,
memmove(src, &Receive_Packet.address,
sizeof(Receive_Packet.address));
}
if (pdu) {
memmove(pdu,
&Receive_Packet.pdu, sizeof(Receive_Packet.pdu));
memmove(pdu, &Receive_Packet.pdu,
sizeof(Receive_Packet.pdu));
}
pdu_len = Receive_Packet.pdu_len;
}
@@ -301,11 +300,9 @@ uint16_t MSTP_Get_Send(
}
/* convert the PDU into the MSTP Frame */
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
mstp_port->OutputBufferSize,
Transmit_Packet.frame_type,
destination,
mstp_port->This_Station,
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len);
mstp_port->OutputBufferSize, Transmit_Packet.frame_type, destination,
mstp_port->This_Station, &Transmit_Packet.pdu[0],
Transmit_Packet.pdu_len);
Transmit_Packet.ready = false;
return pdu_len;
@@ -336,8 +333,9 @@ bool dlmstp_compare_data_expecting_reply(
/* decode the request data */
request.address.mac[0] = src_address;
request.address.mac_len = 1;
offset = npdu_decode(&request_pdu[0],
NULL, &request.address, &request.npdu_data);
offset =
npdu_decode(&request_pdu[0], NULL, &request.address,
&request.npdu_data);
if (request.npdu_data.network_layer_message) {
return false;
}
@@ -353,8 +351,8 @@ bool dlmstp_compare_data_expecting_reply(
request.service_choice = request_pdu[offset + 3];
/* decode the reply data */
bacnet_address_copy(&reply.address, dest_address);
offset = npdu_decode(&reply_pdu[0],
&reply.address, NULL, &reply.npdu_data);
offset =
npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
if (reply.npdu_data.network_layer_message) {
return false;
}
@@ -443,19 +441,18 @@ uint16_t MSTP_Get_Reply(
return 0;
}
/* is this the reply to the DER? */
matched = dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
mstp_port->DataLength,
mstp_port->SourceAddress,
&Transmit_Packet.pdu[0],
Transmit_Packet.pdu_len, &Transmit_Packet.address);
matched =
dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
mstp_port->DataLength, mstp_port->SourceAddress,
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len,
&Transmit_Packet.address);
if (!matched)
return 0;
/* convert the PDU into the MSTP Frame */
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
mstp_port->OutputBufferSize,
Transmit_Packet.frame_type,
destination, mstp_port->This_Station,
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len);
mstp_port->OutputBufferSize, Transmit_Packet.frame_type, destination,
mstp_port->This_Station, &Transmit_Packet.pdu[0],
Transmit_Packet.pdu_len);
Transmit_Packet.ready = false;
return pdu_len;
@@ -721,8 +718,7 @@ int main(
for (;;) {
pdu_len = dlmstp_receive(NULL, NULL, 0, INFINITE);
#if 0
MSTP_Create_And_Send_Frame(&MSTP_Port,
FRAME_TYPE_TEST_REQUEST,
MSTP_Create_And_Send_Frame(&MSTP_Port, FRAME_TYPE_TEST_REQUEST,
MSTP_Port.SourceAddress, MSTP_Port.This_Station, NULL, 0);
#endif
}
+10 -12
View File
@@ -155,8 +155,8 @@ bool ethernet_init(
*/
/* Retrieve the device list */
if (pcap_findalldevs(&pcap_all_if, pcap_errbuf) == -1) {
sprintf(msgBuf,
"ethernet.c: error in pcap_findalldevs: %s\n", pcap_errbuf);
sprintf(msgBuf, "ethernet.c: error in pcap_findalldevs: %s\n",
pcap_errbuf);
LogError(msgBuf);
return false;
}
@@ -167,8 +167,8 @@ bool ethernet_init(
}
pcap_freealldevs(pcap_all_if); /* we don't need it anymore */
if (dev == NULL) {
sprintf(msgBuf,
"ethernet.c: specified interface not found: %s\n", if_name);
sprintf(msgBuf, "ethernet.c: specified interface not found: %s\n",
if_name);
LogError(msgBuf);
return false;
}
@@ -180,8 +180,8 @@ bool ethernet_init(
lpAdapter = PacketOpenAdapter(if_name);
if (lpAdapter == NULL) {
ethernet_cleanup();
sprintf(msgBuf,
"ethernet.c: error in PacketOpenAdapter(\"%s\")\n", if_name);
sprintf(msgBuf, "ethernet.c: error in PacketOpenAdapter(\"%s\")\n",
if_name);
LogError(msgBuf);
return false;
}
@@ -284,8 +284,7 @@ int ethernet_send(
if (pcap_sendpacket(pcap_eth802_fp, mtu, mtu_len) != 0) {
/* did it get sent? */
char msgBuf[200];
sprintf(msgBuf,
"ethernet.c: error sending packet: %s\n",
sprintf(msgBuf, "ethernet.c: error sending packet: %s\n",
pcap_geterr(pcap_eth802_fp));
LogError(msgBuf);
return -5;
@@ -342,8 +341,7 @@ uint16_t ethernet_receive(
res = pcap_next_ex(pcap_eth802_fp, &header, &pkt_data);
if (res < 0) {
char msgBuf[200];
sprintf(msgBuf,
"ethernet.c: error in receiving packet: %s\n",
sprintf(msgBuf, "ethernet.c: error in receiving packet: %s\n",
pcap_geterr(pcap_eth802_fp));
return 0;
} else if (res == 0)
@@ -445,8 +443,8 @@ void ethernet_debug_address(
}
/* if */
if (dest) {
sprintf(msgBuf,
"Address:\n MAC Length=%d\n MAC Address=", dest->mac_len);
sprintf(msgBuf, "Address:\n MAC Length=%d\n MAC Address=",
dest->mac_len);
LogInfo(msgBuf);
for (i = 0; i < MAX_MAC_LEN; i++) {
sprintf(msgBuf, "%02X ", (unsigned) dest->mac[i]);
+5 -4
View File
@@ -105,8 +105,8 @@ static void Read_Properties(
next_device = true;
else {
status = Send_Read_Property_Request(device_id, /* destination device */
OBJECT_DEVICE,
device_id, object_props[property], BACNET_ARRAY_ALL);
OBJECT_DEVICE, device_id, object_props[property],
BACNET_ARRAY_ALL);
if (status)
property++;
}
@@ -137,8 +137,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);
fprintf(stderr, "Received I-Am Request");
if (len != -1) {
fprintf(stderr, " from %u!\n", device_id);
+3 -2
View File
@@ -190,8 +190,9 @@ static void RS485_Configure_Status(
void RS485_Initialize(
void)
{
RS485_Handle = CreateFile(RS485_Port_Name,
GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
RS485_Handle =
CreateFile(RS485_Port_Name, GENERIC_READ | GENERIC_WRITE, 0, 0,
OPEN_EXISTING,
/*FILE_FLAG_OVERLAPPED */ 0,
0);
if (RS485_Handle == INVALID_HANDLE_VALUE) {
+5 -9
View File
@@ -129,20 +129,16 @@ static void print_received_packet(
/* Data CRC: (present only if Length is non-zero) two octets, */
/* least significant octet first */
/* (pad): (optional) at most one octet of padding: X'FF' */
fprintf(stderr,
"55 FF %02X %02X %02X %02X %02X %02X ",
mstp_port->FrameType,
mstp_port->DestinationAddress,
mstp_port->SourceAddress,
HI_BYTE(mstp_port->DataLength),
fprintf(stderr, "55 FF %02X %02X %02X %02X %02X %02X ",
mstp_port->FrameType, mstp_port->DestinationAddress,
mstp_port->SourceAddress, HI_BYTE(mstp_port->DataLength),
LO_BYTE(mstp_port->DataLength), mstp_port->HeaderCRCActual);
if (mstp_port->DataLength) {
for (i = 0; i < mstp_port->DataLength; i++) {
fprintf(stderr, "%02X ", mstp_port->InputBuffer[i]);
}
fprintf(stderr,
"%02X %02X ",
mstp_port->DataCRCActualMSB, mstp_port->DataCRCActualLSB);
fprintf(stderr, "%02X %02X ", mstp_port->DataCRCActualMSB,
mstp_port->DataCRCActualLSB);
}
fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType));
fprintf(stderr, "\n");
+18 -12
View File
@@ -103,8 +103,9 @@ int abort_decode_apdu(
else
*server = false;
if (apdu_len > 1) {
len = abort_decode_service_request(&apdu[1],
apdu_len - 1, invoke_id, abort_reason);
len =
abort_decode_service_request(&apdu[1], apdu_len - 1, invoke_id,
abort_reason);
}
}
@@ -127,8 +128,9 @@ void testAbortAPDU(
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server);
apdu_len = len;
ct_test(pTest, len != 0);
len = abort_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
len =
abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_abort_reason, &test_server);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_abort_reason == abort_reason);
@@ -154,8 +156,9 @@ void testAbort(
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server);
ct_test(pTest, len != 0);
apdu_len = len;
len = abort_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
len =
abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_abort_reason, &test_server);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_abort_reason == abort_reason);
@@ -163,18 +166,21 @@ void testAbort(
/* change type to get negative response */
apdu[0] = PDU_TYPE_REJECT;
len = abort_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
len =
abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_abort_reason, &test_server);
ct_test(pTest, len == -1);
/* test NULL APDU */
len = abort_decode_apdu(NULL,
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
len =
abort_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_abort_reason,
&test_server);
ct_test(pTest, len == -1);
/* force a zero length */
len = abort_decode_apdu(&apdu[0],
0, &test_invoke_id, &test_abort_reason, &test_server);
len =
abort_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_abort_reason,
&test_server);
ct_test(pTest, len == 0);
/* check them all... */
+3 -4
View File
@@ -59,8 +59,7 @@ void address_remove_device(
unsigned i;
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
if ((Address_Cache[i].valid ||
Address_Cache[i].bind_request) &&
if ((Address_Cache[i].valid || Address_Cache[i].bind_request) &&
(Address_Cache[i].device_id == device_id)) {
Address_Cache[i].valid = false;
break;
@@ -320,8 +319,8 @@ void testAddress(
&test_address));
ct_test(pTest, test_max_apdu == max_apdu);
ct_test(pTest, bacnet_address_same(&test_address, &src));
ct_test(pTest, address_get_by_index(i, &test_device_id,
&test_max_apdu, &test_address));
ct_test(pTest, address_get_by_index(i, &test_device_id, &test_max_apdu,
&test_address));
ct_test(pTest, test_device_id == device_id);
ct_test(pTest, test_max_apdu == max_apdu);
ct_test(pTest, bacnet_address_same(&test_address, &src));
+3 -5
View File
@@ -304,9 +304,8 @@ void apdu_handler(
switch (apdu[0] & 0xF0) {
case PDU_TYPE_CONFIRMED_SERVICE_REQUEST:
len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */
apdu_len,
&service_data,
&service_choice, &service_request, &service_request_len);
apdu_len, &service_data, &service_choice, &service_request,
&service_request_len);
/* When network communications are completely disabled,
only DeviceCommunicationControl and ReinitializeDevice APDUs
shall be processed and no messages shall be initiated. */
@@ -437,8 +436,7 @@ void apdu_handler(
len += decode_enumerated(&apdu[len], len_value, &error_code);
if (service_choice < MAX_BACNET_CONFIRMED_SERVICE) {
if (Error_Function[service_choice])
Error_Function[service_choice] (src,
invoke_id,
Error_Function[service_choice] (src, invoke_id,
(BACNET_ERROR_CLASS) error_class,
(BACNET_ERROR_CODE) error_code);
}
+100 -63
View File
@@ -55,22 +55,27 @@ int arf_encode_apdu(
apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; /* service choice */
apdu_len = 4;
apdu_len += encode_application_object_id(&apdu[apdu_len],
data->object_type, data->object_instance);
apdu_len +=
encode_application_object_id(&apdu[apdu_len], data->object_type,
data->object_instance);
switch (data->access) {
case FILE_STREAM_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.stream.fileStartPosition);
apdu_len += encode_application_unsigned(&apdu[apdu_len],
apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.stream.requestedOctetCount);
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
break;
case FILE_RECORD_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.record.fileStartRecord);
apdu_len += encode_application_unsigned(&apdu[apdu_len],
apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.record.RecordCount);
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
break;
@@ -108,21 +113,25 @@ int arf_decode_service_request(
/* a tag number is not extended so only one octet */
len++;
/* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len],
len_value_type, &data->type.stream.fileStartPosition);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.stream.fileStartPosition);
/* requestedOctetCount */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1;
len += decode_unsigned(&apdu[len],
len_value_type, &data->type.stream.requestedOctetCount);
len +=
decode_unsigned(&apdu[len], len_value_type,
&data->type.stream.requestedOctetCount);
if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1;
/* a tag number is not extended so only one octet */
@@ -132,21 +141,25 @@ int arf_decode_service_request(
/* a tag number is not extended so only one octet */
len++;
/* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len],
len_value_type, &data->type.record.fileStartRecord);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.record.fileStartRecord);
/* RecordCount */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1;
len += decode_unsigned(&apdu[len],
len_value_type, &data->type.record.RecordCount);
len +=
decode_unsigned(&apdu[len], len_value_type,
&data->type.record.RecordCount);
if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1;
/* a tag number is not extended so only one octet */
@@ -179,8 +192,8 @@ int arf_decode_apdu(
offset = 4;
if (apdu_len > offset) {
len = arf_decode_service_request(&apdu[offset],
apdu_len - offset, data);
len =
arf_decode_service_request(&apdu[offset], apdu_len - offset, data);
}
return len;
@@ -205,19 +218,24 @@ int arf_ack_encode_apdu(
switch (data->access) {
case FILE_STREAM_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.stream.fileStartPosition);
apdu_len += encode_application_octet_string(&apdu[apdu_len],
apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
break;
case FILE_RECORD_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.record.fileStartRecord);
apdu_len += encode_application_unsigned(&apdu[apdu_len],
apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.record.RecordCount);
apdu_len += encode_application_octet_string(&apdu[apdu_len],
apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
break;
@@ -253,21 +271,25 @@ int arf_ack_decode_service_request(
/* a tag number is not extended so only one octet */
len++;
/* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len],
len_value_type, &data->type.stream.fileStartPosition);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.stream.fileStartPosition);
/* fileData */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1;
len += decode_octet_string(&apdu[len],
len_value_type, &data->fileData);
len +=
decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1;
/* a tag number is not extended so only one octet */
@@ -277,29 +299,35 @@ int arf_ack_decode_service_request(
/* a tag number is not extended so only one octet */
len++;
/* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len],
len_value_type, &data->type.record.fileStartRecord);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.record.fileStartRecord);
/* returnedRecordCount */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1;
len += decode_unsigned(&apdu[len],
len_value_type, &data->type.record.RecordCount);
len +=
decode_unsigned(&apdu[len], len_value_type,
&data->type.record.RecordCount);
/* fileData */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1;
len += decode_octet_string(&apdu[len],
len_value_type, &data->fileData);
len +=
decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1;
/* a tag number is not extended so only one octet */
@@ -331,8 +359,9 @@ int arf_ack_decode_apdu(
offset = 3;
if (apdu_len > offset) {
len = arf_ack_decode_service_request(&apdu[offset],
apdu_len - offset, data);
len =
arf_ack_decode_service_request(&apdu[offset], apdu_len - offset,
data);
}
return len;
@@ -364,15 +393,19 @@ void testAtomicReadFileAckAccess(
ct_test(pTest, test_data.endOfFile == data->endOfFile);
ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition ==
ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition);
} else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord ==
ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord);
ct_test(pTest, test_data.type.record.RecordCount ==
ct_test(pTest,
test_data.type.record.RecordCount ==
data->type.record.RecordCount);
}
ct_test(pTest, octetstring_length(&test_data.fileData) ==
ct_test(pTest,
octetstring_length(&test_data.fileData) ==
octetstring_length(&data->fileData));
ct_test(pTest, memcmp(octetstring_value(&test_data.fileData),
octetstring_value(&data->fileData),
@@ -389,16 +422,16 @@ void testAtomicReadFileAck(
data.endOfFile = true;
data.access = FILE_STREAM_ACCESS;
data.type.stream.fileStartPosition = 0;
octetstring_init(&data.fileData,
test_octet_string, sizeof(test_octet_string));
octetstring_init(&data.fileData, test_octet_string,
sizeof(test_octet_string));
testAtomicReadFileAckAccess(pTest, &data);
data.endOfFile = false;
data.access = FILE_RECORD_ACCESS;
data.type.record.fileStartRecord = 1;
data.type.record.RecordCount = 2;
octetstring_init(&data.fileData,
test_octet_string, sizeof(test_octet_string));
octetstring_init(&data.fileData, test_octet_string,
sizeof(test_octet_string));
testAtomicReadFileAckAccess(pTest, &data);
return;
@@ -425,14 +458,18 @@ void testAtomicReadFileAccess(
ct_test(pTest, test_data.object_instance == data->object_instance);
ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition ==
ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition);
ct_test(pTest, test_data.type.stream.requestedOctetCount ==
ct_test(pTest,
test_data.type.stream.requestedOctetCount ==
data->type.stream.requestedOctetCount);
} else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord ==
ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord);
ct_test(pTest, test_data.type.record.RecordCount ==
ct_test(pTest,
test_data.type.record.RecordCount ==
data->type.record.RecordCount);
}
}
+66 -43
View File
@@ -55,24 +55,30 @@ int awf_encode_apdu(
apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */
apdu_len = 4;
apdu_len += encode_application_object_id(&apdu[apdu_len],
data->object_type, data->object_instance);
apdu_len +=
encode_application_object_id(&apdu[apdu_len], data->object_type,
data->object_instance);
switch (data->access) {
case FILE_STREAM_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.stream.fileStartPosition);
apdu_len += encode_application_octet_string(&apdu[apdu_len],
apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
break;
case FILE_RECORD_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.record.fileStartRecord);
apdu_len += encode_application_unsigned(&apdu[apdu_len],
apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.record.returnedRecordCount);
apdu_len += encode_application_octet_string(&apdu[apdu_len],
apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
break;
@@ -112,21 +118,24 @@ int awf_decode_service_request(
/* a tag number of 2 is not extended so only one octet */
len++;
/* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len], len_value_type, &signed_value);
data->type.stream.fileStartPosition = signed_value;
/* fileData */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1;
len += decode_octet_string(&apdu[len],
len_value_type, &data->fileData);
len +=
decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1;
/* a tag number is not extended so only one octet */
@@ -136,30 +145,34 @@ int awf_decode_service_request(
/* a tag number is not extended so only one octet */
len++;
/* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len], len_value_type, &signed_value);
data->type.record.fileStartRecord = signed_value;
/* returnedRecordCount */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1;
len += decode_unsigned(&apdu[len], len_value_type,
&unsigned_value);
len +=
decode_unsigned(&apdu[len], len_value_type, &unsigned_value);
data->type.record.returnedRecordCount = unsigned_value;
/* fileData */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1;
len += decode_octet_string(&apdu[len],
len_value_type, &data->fileData);
len +=
decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1;
/* a tag number is not extended so only one octet */
@@ -192,8 +205,8 @@ int awf_decode_apdu(
offset = 4;
if (apdu_len > offset) {
len = awf_decode_service_request(&apdu[offset],
apdu_len - offset, data);
len =
awf_decode_service_request(&apdu[offset], apdu_len - offset, data);
}
return len;
@@ -213,11 +226,13 @@ int awf_ack_encode_apdu(
apdu_len = 3;
switch (data->access) {
case FILE_STREAM_ACCESS:
apdu_len += encode_context_signed(&apdu[apdu_len], 0,
apdu_len +=
encode_context_signed(&apdu[apdu_len], 0,
data->type.stream.fileStartPosition);
break;
case FILE_RECORD_ACCESS:
apdu_len += encode_context_signed(&apdu[apdu_len], 1,
apdu_len +=
encode_context_signed(&apdu[apdu_len], 1,
data->type.record.fileStartRecord);
break;
default:
@@ -245,12 +260,14 @@ int awf_ack_decode_service_request(
&len_value_type);
if (tag_number == 0) {
data->access = FILE_STREAM_ACCESS;
len += decode_signed(&apdu[len],
len_value_type, &data->type.stream.fileStartPosition);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.stream.fileStartPosition);
} else if (tag_number == 1) {
data->access = FILE_RECORD_ACCESS;
len += decode_signed(&apdu[len],
len_value_type, &data->type.record.fileStartRecord);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.record.fileStartRecord);
} else
return -1;
}
@@ -278,8 +295,8 @@ int awf_ack_decode_apdu(
offset = 3;
if (apdu_len > offset) {
len = awf_decode_service_request(&apdu[offset],
apdu_len - offset, data);
len =
awf_decode_service_request(&apdu[offset], apdu_len - offset, data);
}
return len;
@@ -311,15 +328,19 @@ void testAtomicWriteFileAccess(
ct_test(pTest, test_data.object_instance == data->object_instance);
ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition ==
ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition);
} else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord ==
ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord);
ct_test(pTest, test_data.type.record.returnedRecordCount ==
ct_test(pTest,
test_data.type.record.returnedRecordCount ==
data->type.record.returnedRecordCount);
}
ct_test(pTest, octetstring_length(&test_data.fileData) ==
ct_test(pTest,
octetstring_length(&test_data.fileData) ==
octetstring_length(&data->fileData));
ct_test(pTest, memcmp(octetstring_value(&test_data.fileData),
octetstring_value(&data->fileData),
@@ -336,8 +357,8 @@ void testAtomicWriteFile(
data.object_instance = 1;
data.access = FILE_STREAM_ACCESS;
data.type.stream.fileStartPosition = 0;
octetstring_init(&data.fileData,
test_octet_string, sizeof(test_octet_string));
octetstring_init(&data.fileData, test_octet_string,
sizeof(test_octet_string));
testAtomicWriteFileAccess(pTest, &data);
data.object_type = OBJECT_FILE;
@@ -345,8 +366,8 @@ void testAtomicWriteFile(
data.access = FILE_RECORD_ACCESS;
data.type.record.fileStartRecord = 1;
data.type.record.returnedRecordCount = 2;
octetstring_init(&data.fileData,
test_octet_string, sizeof(test_octet_string));
octetstring_init(&data.fileData, test_octet_string,
sizeof(test_octet_string));
testAtomicWriteFileAccess(pTest, &data);
return;
@@ -371,10 +392,12 @@ void testAtomicWriteFileAckAccess(
ct_test(pTest, len != -1);
ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition ==
ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition);
} else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord ==
ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord);
}
}
+135 -89
View File
@@ -62,19 +62,21 @@ int bacapp_encode_application_data(
#endif
#if defined (BACAPP_BOOLEAN)
case BACNET_APPLICATION_TAG_BOOLEAN:
apdu_len = encode_application_boolean(&apdu[0],
value->type.Boolean);
apdu_len =
encode_application_boolean(&apdu[0], value->type.Boolean);
break;
#endif
#if defined (BACAPP_UNSIGNED)
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
apdu_len = encode_application_unsigned(&apdu[0],
apdu_len =
encode_application_unsigned(&apdu[0],
value->type.Unsigned_Int);
break;
#endif
#if defined (BACAPP_SIGNED)
case BACNET_APPLICATION_TAG_SIGNED_INT:
apdu_len = encode_application_signed(&apdu[0],
apdu_len =
encode_application_signed(&apdu[0],
value->type.Signed_Int);
break;
#endif
@@ -86,31 +88,35 @@ int bacapp_encode_application_data(
#if defined (BACAPP_DOUBLE)
case BACNET_APPLICATION_TAG_DOUBLE:
/* FIXME: double is not implemented yet. */
apdu_len = encode_application_double(&apdu[0],
value->type.Double);
apdu_len =
encode_application_double(&apdu[0], value->type.Double);
break;
#endif
#if defined (BACAPP_OCTET_STRING)
case BACNET_APPLICATION_TAG_OCTET_STRING:
apdu_len = encode_application_octet_string(&apdu[0],
apdu_len =
encode_application_octet_string(&apdu[0],
&value->type.Octet_String);
break;
#endif
#if defined (BACAPP_CHARACTER_STRING)
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
apdu_len = encode_application_character_string(&apdu[0],
apdu_len =
encode_application_character_string(&apdu[0],
&value->type.Character_String);
break;
#endif
#if defined (BACAPP_BIT_STRING)
case BACNET_APPLICATION_TAG_BIT_STRING:
apdu_len = encode_application_bitstring(&apdu[0],
apdu_len =
encode_application_bitstring(&apdu[0],
&value->type.Bit_String);
break;
#endif
#if defined (BACAPP_ENUMERATED)
case BACNET_APPLICATION_TAG_ENUMERATED:
apdu_len = encode_application_enumerated(&apdu[0],
apdu_len =
encode_application_enumerated(&apdu[0],
value->type.Enumerated);
break;
#endif
@@ -128,7 +134,8 @@ int bacapp_encode_application_data(
#endif
#if defined (BACAPP_OBJECT_ID)
case BACNET_APPLICATION_TAG_OBJECT_ID:
apdu_len = encode_application_object_id(&apdu[0],
apdu_len =
encode_application_object_id(&apdu[0],
value->type.Object_Id.type,
value->type.Object_Id.instance);
break;
@@ -166,14 +173,16 @@ int bacapp_decode_data(
#endif
#if defined (BACAPP_UNSIGNED)
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
len = decode_unsigned(&apdu[0],
len_value_type, &value->type.Unsigned_Int);
len =
decode_unsigned(&apdu[0], len_value_type,
&value->type.Unsigned_Int);
break;
#endif
#if defined (BACAPP_SIGNED)
case BACNET_APPLICATION_TAG_SIGNED_INT:
len = decode_signed(&apdu[0],
len_value_type, &value->type.Signed_Int);
len =
decode_signed(&apdu[0], len_value_type,
&value->type.Signed_Int);
break;
#endif
#if defined (BACAPP_REAL)
@@ -188,26 +197,30 @@ int bacapp_decode_data(
#endif
#if defined (BACAPP_OCTET_STRING)
case BACNET_APPLICATION_TAG_OCTET_STRING:
len = decode_octet_string(&apdu[0],
len_value_type, &value->type.Octet_String);
len =
decode_octet_string(&apdu[0], len_value_type,
&value->type.Octet_String);
break;
#endif
#if defined (BACAPP_CHARACTER_STRING)
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
len = decode_character_string(&apdu[0],
len_value_type, &value->type.Character_String);
len =
decode_character_string(&apdu[0], len_value_type,
&value->type.Character_String);
break;
#endif
#if defined (BACAPP_BIT_STRING)
case BACNET_APPLICATION_TAG_BIT_STRING:
len = decode_bitstring(&apdu[0],
len_value_type, &value->type.Bit_String);
len =
decode_bitstring(&apdu[0], len_value_type,
&value->type.Bit_String);
break;
#endif
#if defined (BACAPP_ENUMERATED)
case BACNET_APPLICATION_TAG_ENUMERATED:
len = decode_enumerated(&apdu[0],
len_value_type, &value->type.Enumerated);
len =
decode_enumerated(&apdu[0], len_value_type,
&value->type.Enumerated);
break;
#endif
#if defined (BACAPP_DATE)
@@ -253,13 +266,15 @@ int bacapp_decode_application_data(
max_apdu_len = max_apdu_len;
if (apdu && value && !decode_is_context_specific(apdu)) {
value->context_specific = false;
tag_len = decode_tag_number_and_value(&apdu[0],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[0], &tag_number,
&len_value_type);
if (tag_len) {
len += tag_len;
value->tag = tag_number;
len += bacapp_decode_data(&apdu[len],
tag_number, len_value_type, value);
len +=
bacapp_decode_data(&apdu[len], tag_number, len_value_type,
value);
}
value->next = NULL;
}
@@ -283,7 +298,8 @@ int bacapp_encode_context_data_value(
#endif
#if defined (BACAPP_BOOLEAN)
case BACNET_APPLICATION_TAG_BOOLEAN:
apdu_len = encode_context_boolean(&apdu[0], context_tag_number,
apdu_len =
encode_context_boolean(&apdu[0], context_tag_number,
value->type.Boolean);
break;
#endif
@@ -296,20 +312,23 @@ int bacapp_encode_context_data_value(
#endif
#if defined (BACAPP_SIGNED)
case BACNET_APPLICATION_TAG_SIGNED_INT:
apdu_len = encode_context_signed(&apdu[0], context_tag_number,
apdu_len =
encode_context_signed(&apdu[0], context_tag_number,
value->type.Signed_Int);
break;
#endif
#if defined (BACAPP_REAL)
case BACNET_APPLICATION_TAG_REAL:
apdu_len = encode_context_real(&apdu[0], context_tag_number,
apdu_len =
encode_context_real(&apdu[0], context_tag_number,
value->type.Real);
break;
#endif
#if defined (BACAPP_DOUBLE)
case BACNET_APPLICATION_TAG_DOUBLE:
/* FIXME: double is not implemented yet. */
apdu_len = encode_context_double(&apdu[0], context_tag_number,
apdu_len =
encode_context_double(&apdu[0], context_tag_number,
value->type.Double);
break;
#endif
@@ -343,13 +362,15 @@ int bacapp_encode_context_data_value(
#endif
#if defined (BACAPP_DATE)
case BACNET_APPLICATION_TAG_DATE:
apdu_len = encode_context_date(&apdu[0], context_tag_number,
apdu_len =
encode_context_date(&apdu[0], context_tag_number,
&value->type.Date);
break;
#endif
#if defined (BACAPP_TIME)
case BACNET_APPLICATION_TAG_TIME:
apdu_len = encode_context_time(&apdu[0], context_tag_number,
apdu_len =
encode_context_time(&apdu[0], context_tag_number,
&value->type.Time);
break;
#endif
@@ -445,8 +466,9 @@ int bacapp_encode_context_data(
if (value && apdu) {
tag_data_type = bacapp_context_tag_type(property, value->context_tag);
if (tag_data_type < MAX_BACNET_APPLICATION_TAG) {
apdu_len = bacapp_encode_context_data_value(&apdu[0],
value->context_tag, value);
apdu_len =
bacapp_encode_context_data_value(&apdu[0], value->context_tag,
value);
} else {
/* FIXME: what now? */
apdu_len = 0;
@@ -472,15 +494,17 @@ int bacapp_decode_context_data(
max_apdu_len = max_apdu_len;
if (apdu && value && decode_is_context_specific(apdu)) {
value->context_specific = true;
tag_len = decode_tag_number_and_value(&apdu[0],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[0], &tag_number,
&len_value_type);
if (tag_len) {
apdu_len = tag_len;
value->context_tag = tag_number;
value->tag = bacapp_context_tag_type(property, tag_number);
if (value->tag < MAX_BACNET_APPLICATION_TAG) {
len = bacapp_decode_data(&apdu[apdu_len],
value->tag, len_value_type, value);
len =
bacapp_decode_data(&apdu[apdu_len], value->tag,
len_value_type, value);
apdu_len += len;
} else {
/* FIXME: what now? */
@@ -501,8 +525,9 @@ int bacapp_encode_data(
if (value && apdu) {
if (value->context_specific) {
apdu_len = bacapp_encode_context_data_value(&apdu[0],
value->context_tag, value);
apdu_len =
bacapp_encode_context_data_value(&apdu[0], value->context_tag,
value);
} else {
apdu_len = bacapp_encode_application_data(&apdu[0], value);
}
@@ -622,29 +647,33 @@ int bacapp_data_len(
BACNET_APPLICATION_DATA_VALUE application_value;
if (decode_is_opening_tag(&apdu[0])) {
len = decode_tag_number_and_value(&apdu[apdu_len],
&tag_number, &value);
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &value);
apdu_len += len;
opening_tag_number = tag_number;
opening_tag_number_counter = 1;
while (opening_tag_number_counter) {
if (decode_is_opening_tag(&apdu[apdu_len])) {
len = decode_tag_number_and_value(&apdu[apdu_len],
&tag_number, &value);
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&value);
if (tag_number == opening_tag_number)
opening_tag_number_counter++;
} else if (decode_is_closing_tag(&apdu[apdu_len])) {
len = decode_tag_number_and_value(&apdu[apdu_len],
&tag_number, &value);
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&value);
if (tag_number == opening_tag_number)
opening_tag_number_counter--;
} else if (decode_is_context_specific(&apdu[apdu_len])) {
/* context-specific tagged data */
len = bacapp_decode_context_data(&apdu[apdu_len],
len =
bacapp_decode_context_data(&apdu[apdu_len],
max_apdu_len - apdu_len, &application_value, property);
} else {
/* application tagged data */
len = bacapp_decode_application_data(&apdu[apdu_len],
len =
bacapp_decode_application_data(&apdu[apdu_len],
max_apdu_len - apdu_len, &application_value);
}
apdu_len += len;
@@ -850,7 +879,8 @@ bool bacapp_parse_application_data(
break;
#endif
case BACNET_APPLICATION_TAG_OCTET_STRING:
status = octetstring_init(&value->type.Octet_String,
status =
octetstring_init(&value->type.Octet_String,
(uint8_t *) argv, strlen(argv));
break;
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
@@ -871,8 +901,8 @@ bool bacapp_parse_application_data(
count =
sscanf(argv, "%d/%d/%d:%d", &year, &month, &day, &wday);
if (count == 3) {
datetime_set_date(&value->type.Date,
(uint16_t) year, (uint8_t) month, (uint8_t) day);
datetime_set_date(&value->type.Date, (uint16_t) year,
(uint8_t) month, (uint8_t) day);
} else if (count == 4) {
value->type.Date.year = year;
value->type.Date.month = month;
@@ -1012,7 +1042,8 @@ bool bacapp_same_value(
#endif
#if defined (BACAPP_CHARACTER_STRING)
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
status = characterstring_same(&value->type.Character_String,
status =
characterstring_same(&value->type.Character_String,
&test_value->type.Character_String);
break;
#endif
@@ -1046,7 +1077,8 @@ void testBACnetApplicationDataLength(
len = encode_closing_tag(&apdu[apdu_len], 3);
apdu_len += len;
/* verify the length of the data inside the opening/closing tags */
len = bacapp_data_len(&apdu[0], apdu_len,
len =
bacapp_data_len(&apdu[0], apdu_len,
PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES);
ct_test(pTest, test_len == len);
@@ -1194,27 +1226,30 @@ void testBACnetApplicationData(
bool status = false;
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_NULL,
NULL, &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_NULL, NULL,
&value);
ct_test(pTest, status == true);
status = testBACnetApplicationDataValue(&value);
ct_test(pTest, status == true);
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN,
"1", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, "1",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Boolean == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN,
"0", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, "0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Boolean == false);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT,
"0", &value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, "0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Unsigned_Int == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value));
@@ -1232,14 +1267,14 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT,
"0", &value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, "0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Signed_Int == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT,
"-1", &value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, "-1",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Signed_Int == -1);
ct_test(pTest, testBACnetApplicationDataValue(&value));
@@ -1256,30 +1291,35 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Signed_Int == -32768);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"0.0", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "0.0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"-1.0", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "-1.0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"1.0", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "1.0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"3.14159", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "3.14159",
&value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"-3.14159", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "-3.14159",
&value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED,
"0", &value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED, "0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Enumerated == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value));
@@ -1296,7 +1336,8 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Enumerated == 0xFFFFFFFF);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
"2005/5/22:1", &value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Date.year == 2005);
@@ -1306,8 +1347,9 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value));
/* Happy Valentines Day! */
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
"2007/2/14", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, "2007/2/14",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Date.year == 2007);
ct_test(pTest, value.type.Date.month == 2);
@@ -1316,7 +1358,8 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value));
/* Wildcard Values */
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
"2155/255/255:255", &value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Date.year == 2155);
@@ -1325,7 +1368,8 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Date.wday == 255);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
"23:59:59.12", &value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Time.hour == 23);
@@ -1334,8 +1378,9 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Time.hundredths == 12);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
"23:59:59", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, "23:59:59",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Time.hour == 23);
ct_test(pTest, value.type.Time.min == 59);
@@ -1343,8 +1388,9 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Time.hundredths == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
"23:59", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, "23:59",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Time.hour == 23);
ct_test(pTest, value.type.Time.min == 59);
@@ -1361,8 +1407,8 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data
(BACNET_APPLICATION_TAG_CHARACTER_STRING, "Karg!", &value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_CHARACTER_STRING,
"Karg!", &value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
+40 -30
View File
@@ -442,8 +442,8 @@ int encode_application_boolean(
if (boolean_value)
len_value = 1;
len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BOOLEAN, false,
len_value);
len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BOOLEAN, false, len_value);
return len;
}
@@ -553,8 +553,8 @@ int decode_bitstring(
byte_reverse_bits(apdu[len++]));
}
unused_bits = apdu[0] & 0x07;
bitstring_set_bits_used(bit_string,
(uint8_t) bytes_used, unused_bits);
bitstring_set_bits_used(bit_string, (uint8_t) bytes_used,
unused_bits);
}
}
@@ -577,8 +577,8 @@ int encode_bitstring(
apdu[len++] = 0;
else {
used_bytes = bitstring_bytes_used(bit_string);
remaining_used_bits = bitstring_bits_used(bit_string) -
((used_bytes - 1) * 8);
remaining_used_bits =
bitstring_bits_used(bit_string) - ((used_bytes - 1) * 8);
/* number of unused bits in the subsequent final octet */
apdu[len++] = 8 - remaining_used_bits;
for (i = 0; i < used_bytes; i++) {
@@ -598,7 +598,8 @@ int encode_application_bitstring(
/* bit string may use more than 1 octet for the tag, so find out how many */
bit_string_encoded_length += bitstring_bytes_used(bit_string);
len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BIT_STRING, false,
len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BIT_STRING, false,
bit_string_encoded_length);
len += encode_bitstring(&apdu[len], bit_string);
@@ -652,8 +653,9 @@ int encode_bacnet_object_id(
int len = 0;
type = object_type;
value = ((type & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) |
(instance & BACNET_MAX_INSTANCE);
value =
((type & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) | (instance &
BACNET_MAX_INSTANCE);
len = encode_unsigned32(apdu, value);
return len;
@@ -732,8 +734,8 @@ int encode_application_octet_string(
if (octet_string) {
apdu_len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OCTET_STRING,
false, octetstring_length(octet_string));
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OCTET_STRING, false,
octetstring_length(octet_string));
/* FIXME: probably need to pass in the length of the APDU
to bounds check since it might not be the only data chunk */
if ((apdu_len + octetstring_length(octet_string)) < MAX_APDU)
@@ -756,8 +758,9 @@ int encode_context_octet_string(
int apdu_len = 0;
if (apdu && octet_string) {
apdu_len = encode_tag(&apdu[0], (uint8_t) tag_number,
true, octetstring_length(octet_string));
apdu_len =
encode_tag(&apdu[0], (uint8_t) tag_number, true,
octetstring_length(octet_string));
if ((apdu_len + octetstring_length(octet_string)) < MAX_APDU)
apdu_len += encode_octet_string(&apdu[apdu_len], octet_string);
else
@@ -816,8 +819,8 @@ int encode_application_character_string(
string_len = characterstring_length(char_string) + 1 /* for encoding */ ;
len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING,
false, string_len);
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING, false,
string_len);
if ((len + string_len) < MAX_APDU)
len += encode_bacnet_character_string(&apdu[len], char_string);
else
@@ -855,7 +858,8 @@ int decode_character_string(
int len = 0; /* return value */
bool status = false;
status = characterstring_init(char_string, apdu[0], (char *) &apdu[1],
status =
characterstring_init(char_string, apdu[0], (char *) &apdu[1],
len_value - 1);
if (status)
len = len_value;
@@ -950,8 +954,8 @@ int encode_application_unsigned(
int len = 0;
len = encode_bacnet_unsigned(&apdu[1], value);
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_UNSIGNED_INT,
false, len);
len +=
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_UNSIGNED_INT, false, len);
return len;
}
@@ -1410,7 +1414,8 @@ void testBACDCodeTags(
/* test the len-value-type portion */
for (value = 1;; value = value << 1) {
len = encode_tag(&apdu[0], tag_number, false, value);
len = decode_tag_number_and_value(&apdu[0], &test_tag_number,
len =
decode_tag_number_and_value(&apdu[0], &test_tag_number,
&test_value);
ct_test(pTest, tag_number == test_tag_number);
ct_test(pTest, value == test_value);
@@ -1682,7 +1687,8 @@ void testBACDCodeOctetString(
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING);
len += decode_octet_string(&array[len], len_value, &test_octet_string);
ct_test(pTest, apdu_len == len);
diff = memcmp(octetstring_value(&octet_string), &test_value[0],
diff =
memcmp(octetstring_value(&octet_string), &test_value[0],
octetstring_length(&octet_string));
ct_test(pTest, diff == 0);
@@ -1696,13 +1702,15 @@ void testBACDCodeOctetString(
decode_tag_number_and_value(&encoded_array[0], &tag_number,
&len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING);
len += decode_octet_string(&encoded_array[len], len_value,
len +=
decode_octet_string(&encoded_array[len], len_value,
&test_octet_string);
if (apdu_len != len) {
printf("test octet string=#%d\n", i);
}
ct_test(pTest, apdu_len == len);
diff = memcmp(octetstring_value(&octet_string), &test_value[0],
diff =
memcmp(octetstring_value(&octet_string), &test_value[0],
octetstring_length(&octet_string));
if (diff) {
printf("test octet string=#%d\n", i);
@@ -1736,7 +1744,8 @@ void testBACDCodeCharacterString(
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING);
len += decode_character_string(&array[len], len_value, &test_char_string);
ct_test(pTest, apdu_len == len);
diff = memcmp(characterstring_value(&char_string), &test_value[0],
diff =
memcmp(characterstring_value(&char_string), &test_value[0],
characterstring_length(&char_string));
ct_test(pTest, diff == 0);
for (i = 0; i < MAX_CHARACTER_STRING_BYTES - 1; i++) {
@@ -1758,7 +1767,8 @@ void testBACDCodeCharacterString(
printf("test string=#%d apdu_len=%d len=%d\n", i, apdu_len, len);
}
ct_test(pTest, apdu_len == len);
diff = memcmp(characterstring_value(&char_string), &test_value[0],
diff =
memcmp(characterstring_value(&char_string), &test_value[0],
characterstring_length(&char_string));
if (diff) {
printf("test string=#%d\n", i);
@@ -1784,8 +1794,8 @@ void testBACDCodeObject(
uint32_t decoded_instance = 0;
encode_bacnet_object_id(&encoded_array[0], type, instance);
decode_object_id(&encoded_array[0],
(int *) &decoded_type, &decoded_instance);
decode_object_id(&encoded_array[0], (int *) &decoded_type,
&decoded_instance);
ct_test(pTest, decoded_type == type);
ct_test(pTest, decoded_instance == instance);
encode_bacnet_object_id(&object_array[0], type, instance);
@@ -1794,13 +1804,13 @@ void testBACDCodeObject(
for (type = 0; type < 1024; type++) {
for (instance = 0; instance <= BACNET_MAX_INSTANCE; instance += 1024) {
encode_bacnet_object_id(&encoded_array[0], type, instance);
decode_object_id(&encoded_array[0],
(int *) &decoded_type, &decoded_instance);
decode_object_id(&encoded_array[0], (int *) &decoded_type,
&decoded_instance);
ct_test(pTest, decoded_type == type);
ct_test(pTest, decoded_instance == instance);
encode_bacnet_object_id(&object_array[0], type, instance);
ct_test(pTest, memcmp(&object_array[0],
&encoded_array[0], sizeof(object_array)) == 0);
ct_test(pTest, memcmp(&object_array[0], &encoded_array[0],
sizeof(object_array)) == 0);
}
}

Some files were not shown because too many files have changed in this diff Show More