Bugfix/clang tidy applied 2022 (#232)

* clang-tidy applied fixes to src folder
* clang-tidy applied fixes to apps folder

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2022-02-27 19:14:17 -06:00
committed by GitHub
parent 5e70eeecfc
commit d0fe77c030
33 changed files with 211 additions and 123 deletions
+2 -1
View File
@@ -393,8 +393,9 @@ int main(int argc, char *argv[])
tsm_timer_milliseconds(
(uint16_t)((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found) {
found = address_bind_request(
+2 -1
View File
@@ -246,8 +246,9 @@ int main(int argc, char *argv[])
tsm_timer_milliseconds(
(uint16_t)((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found) {
found = address_bind_request(
+70 -43
View File
@@ -215,11 +215,12 @@ static void MyAbortHandler(
#endif
Error_Detected = true;
Last_Error_Class = ERROR_CLASS_SERVICES;
if (abort_reason < MAX_BACNET_ABORT_REASON)
if (abort_reason < MAX_BACNET_ABORT_REASON) {
Last_Error_Code =
(ERROR_CODE_ABORT_BUFFER_OVERFLOW - 1) + abort_reason;
else
} else {
Last_Error_Code = ERROR_CODE_ABORT_OTHER;
}
}
}
@@ -236,11 +237,12 @@ static void MyRejectHandler(
#endif
Error_Detected = true;
Last_Error_Class = ERROR_CLASS_SERVICES;
if (reject_reason < MAX_BACNET_REJECT_REASON)
if (reject_reason < MAX_BACNET_REJECT_REASON) {
Last_Error_Code =
(ERROR_CODE_REJECT_BUFFER_OVERFLOW - 1) + reject_reason;
else
} else {
Last_Error_Code = ERROR_CODE_REJECT_OTHER;
}
}
}
@@ -265,8 +267,9 @@ static void MyReadPropertyAckHandler(uint8_t *service_request,
Read_Property_Multiple_Data.rpm_data = rp_data;
Read_Property_Multiple_Data.new_data = true;
} else {
if (len < 0) /* Eg, failed due to no segmentation */
if (len < 0) { /* Eg, failed due to no segmentation */
Error_Detected = true;
}
free(rp_data);
}
}
@@ -294,8 +297,9 @@ static void MyReadPropertyMultipleAckHandler(uint8_t *service_request,
Read_Property_Multiple_Data.new_data = true;
/* Will process and free the RPM data later */
} else {
if (len < 0) /* Eg, failed due to no segmentation */
if (len < 0) { /* Eg, failed due to no segmentation */
Error_Detected = true;
}
free(rpm_data);
}
}
@@ -421,9 +425,10 @@ static void CheckIsWritableProperty(BACNET_OBJECT_TYPE object_type,
* Life Safety Tracking_Value, Reliability, Mode,
* or Present_Value when Out_Of_Service is TRUE.
*/
if (bIsWritable)
if (bIsWritable) {
fprintf(stdout, " Writable");
}
}
static const char *protocol_services_supported_text(size_t bit_index)
{
@@ -498,8 +503,9 @@ static bool PrettyPrintPropertyValue(
fprintf(stream, " %s,",
protocol_services_supported_text(j));
}
} else /* not supported */
} else { /* not supported */
fprintf(stream, ",");
}
}
fprintf(stream, "\n ");
}
@@ -518,8 +524,9 @@ static bool PrettyPrintPropertyValue(
assert(false); /* How did I get here? Fix your code. */
/* Meanwhile, a fallback plan */
status = bacapp_print_value(stdout, object_value);
} else
} else {
fprintf(stream, "? \n");
}
return status;
}
@@ -576,8 +583,9 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
PROP_PROTOCOL_CONFORMANCE_CLASS;
break;
}
if (object_type == OBJECT_DATETIME_VALUE)
if (object_type == OBJECT_DATETIME_VALUE) {
break; /* A special case - no braces for this pair */
}
/* Else, fall through to normal processing. */
default:
/* Normal array: open brace */
@@ -587,8 +595,9 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
}
}
if (!Using_Walked_List)
if (!Using_Walked_List) {
Walked_List_Index = Walked_List_Length = 0; /* In case we need this. */
}
/* value(s) loop until there is no "next" ... */
while (value != NULL) {
object_value.object_property = rpm_property->propertyIdentifier;
@@ -608,19 +617,22 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
* print it! */
Walked_List_Length = value->type.Unsigned_Int;
if (rpm_property->propertyIdentifier ==
PROP_OBJECT_LIST)
PROP_OBJECT_LIST) {
Object_List_Length = value->type.Unsigned_Int;
}
break;
} else
} else {
assert(Walked_List_Index ==
(uint32_t)rpm_property->propertyArrayIndex);
}
} else {
Walked_List_Index++;
/* If we got the whole Object List array in one RP call,
* keep the Index and List_Length in sync as we cycle
* through. */
if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST)
if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST) {
Object_List_Length = ++Object_List_Index;
}
}
if (Walked_List_Index == 1) {
/* If the array is empty (nothing for this first entry),
@@ -634,10 +646,11 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
/* Open this Array of Objects for the first entry (unless
* opening brace has already printed, since this is an array
* of values[] ) */
if (value->next == NULL)
if (value->next == NULL) {
fprintf(stdout, "{ \n ");
else
} else {
fprintf(stdout, "\n ");
}
}
if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST) {
@@ -685,18 +698,21 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
/* If the object is a Sequence, it needs its own bracketing
* braces */
if (isSequence)
if (isSequence) {
fprintf(stdout, "{");
}
bacapp_print_value(stdout, &object_value);
if (isSequence)
if (isSequence) {
fprintf(stdout, "}");
}
if ((Walked_List_Index < Walked_List_Length) ||
(value->next != NULL)) {
/* There are more. */
fprintf(stdout, ", ");
if (!(Walked_List_Index % 3))
if (!(Walked_List_Index % 3)) {
fprintf(stdout, "\n ");
}
} else {
fprintf(stdout, " } \n");
}
@@ -966,9 +982,9 @@ static EPICS_STATES ProcessRPMData(
if (myState == GET_HEADING_RESPONSE) {
nextState = PRINT_HEADING;
/* press ahead with or without the data */
} else if (bSuccess && (myState == GET_ALL_RESPONSE))
} else if (bSuccess && (myState == GET_ALL_RESPONSE)) {
nextState = NEXT_OBJECT;
else if (bSuccess) { /* and GET_LIST_OF_ALL_RESPONSE */
} else if (bSuccess) { /* and GET_LIST_OF_ALL_RESPONSE */
/* Now append the properties we waited on. */
if (bHasStructuredViewList) {
Property_List[Property_List_Index] = PROP_STRUCTURED_OBJECT_LIST;
@@ -1071,11 +1087,13 @@ static int CheckCommandLineArgs(int argc, char *argv[])
break;
case 'n':
/* Destination Network Number */
if (Target_Address.mac_len == 0)
if (Target_Address.mac_len == 0) {
fprintf(
stderr, "Must provide a Target MAC before DNET \n");
if (++i < argc)
}
if (++i < argc) {
Target_Address.net = (uint16_t)strtol(argv[i], NULL, 0);
}
/* Used strtol so dest.net can be either 0x1234 or 4660 */
break;
case 't':
@@ -1210,8 +1228,9 @@ static void PrintHeading(void)
int i, len = bitstring_bits_used(&value->type.Bit_String);
printf("-- services reported by this device\n");
for (i = 0; i < len; i++) {
if (bitstring_bit(&value->type.Bit_String, (uint8_t)i))
if (bitstring_bit(&value->type.Bit_String, (uint8_t)i)) {
printf(" %s\n", protocol_services_supported_text(i));
}
}
} else {
printf("-- use \'Initiate\' or \'Execute\' or both for services.\n");
@@ -1257,8 +1276,9 @@ static void PrintHeading(void)
int i, len = bitstring_bits_used(&value->type.Bit_String);
printf("-- objects reported by this device\n");
for (i = 0; i < len; i++) {
if (bitstring_bit(&value->type.Bit_String, (uint8_t)i))
if (bitstring_bit(&value->type.Bit_String, (uint8_t)i)) {
printf(" %s\n", bactext_object_type_name(i));
}
}
} else {
printf("-- possible objects in this device\n");
@@ -1478,8 +1498,9 @@ int main(int argc, char *argv[])
} else {
/* Update by adding the MAC address */
if (max_apdu == 0)
if (max_apdu == 0) {
max_apdu = MAX_APDU; /* Whatever set for this datalink. */
}
address_add_binding(
Target_Device_Object_Instance, max_apdu, &Target_Address);
}
@@ -1572,10 +1593,11 @@ int main(int argc, char *argv[])
buffer, MAX_PDU, Target_Device_Object_Instance, rpm_object);
if (Request_Invoke_ID > 0) {
elapsed_seconds = 0;
if (myState == GET_LIST_OF_ALL_REQUEST)
if (myState == GET_LIST_OF_ALL_REQUEST) {
myState = GET_LIST_OF_ALL_RESPONSE;
else
} else {
myState = GET_ALL_RESPONSE;
}
}
break;
@@ -1606,10 +1628,10 @@ int main(int argc, char *argv[])
} else if (tsm_invoke_id_free(Request_Invoke_ID)) {
elapsed_seconds = 0;
Request_Invoke_ID = 0;
if (myState == GET_HEADING_RESPONSE)
if (myState == GET_HEADING_RESPONSE) {
myState = PRINT_HEADING;
/* just press ahead without the data */
else if (Error_Detected) {
} else if (Error_Detected) {
if (Last_Error_Code ==
ERROR_CODE_REJECT_UNRECOGNIZED_SERVICE) {
/* The normal case for Device Object */
@@ -1620,37 +1642,40 @@ int main(int argc, char *argv[])
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED) {
myState = GET_PROPERTY_REQUEST;
StartNextObject(rpm_object, &myObject);
} else if (myState == GET_ALL_RESPONSE)
} else if (myState == GET_ALL_RESPONSE) {
/* Try again, just to get a list of properties. */
myState = GET_LIST_OF_ALL_REQUEST;
else {
} else {
/* Else drop back to RP. */
myState = GET_PROPERTY_REQUEST;
StartNextObject(rpm_object, &myObject);
}
} else if (Has_RPM)
} else if (Has_RPM) {
myState = GET_ALL_REQUEST; /* Let's try again */
else
} else {
myState = GET_PROPERTY_REQUEST;
}
} else if (tsm_invoke_id_failed(Request_Invoke_ID)) {
fprintf(stderr, "\rError: TSM Timeout!\n");
tsm_free_invoke_id(Request_Invoke_ID);
Request_Invoke_ID = 0;
elapsed_seconds = 0;
if (myState == GET_HEADING_RESPONSE)
if (myState == GET_HEADING_RESPONSE) {
myState = PRINT_HEADING;
/* just press ahead without the data */
else
} else {
myState = GET_ALL_REQUEST; /* Let's try again */
}
} else if (Error_Detected) {
/* Don't think we'll ever actually reach this point. */
elapsed_seconds = 0;
Request_Invoke_ID = 0;
if (myState == GET_HEADING_RESPONSE)
if (myState == GET_HEADING_RESPONSE) {
myState = PRINT_HEADING;
/* just press ahead without the data */
else
myState = NEXT_OBJECT; /* Give up and move on to the
} else {
myState = NEXT_OBJECT;
}/* Give up and move on to the
next. */
Error_Count++;
}
@@ -1668,8 +1693,9 @@ int main(int argc, char *argv[])
if (Request_Invoke_ID == 0) {
/* Reached the end of the list. */
myState = NEXT_OBJECT; /* Move on to the next. */
} else
} else {
myState = GET_PROPERTY_RESPONSE;
}
break;
case GET_PROPERTY_RESPONSE:
@@ -1784,8 +1810,9 @@ int main(int argc, char *argv[])
myObject.type = KEY_DECODE_TYPE(nextKey);
myObject.instance = KEY_DECODE_ID(nextKey);
/* Don't re-list the Device Object among its objects */
if (myObject.type == OBJECT_DEVICE)
if (myObject.type == OBJECT_DEVICE) {
continue;
}
/* Closing brace for the previous Object */
printf(" }, \n");
/* Opening brace for the new Object */
@@ -1802,9 +1829,9 @@ int main(int argc, char *argv[])
*/
myObject.type = MAX_BACNET_OBJECT_TYPE;
}
if (Has_RPM)
if (Has_RPM) {
myState = GET_ALL_REQUEST;
else {
} else {
myState = GET_PROPERTY_REQUEST;
StartNextObject(rpm_object, &myObject);
}
+2 -1
View File
@@ -585,8 +585,9 @@ int main(int argc, char *argv[])
tsm_timer_milliseconds(
(uint16_t)((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found) {
found = address_bind_request(
+6 -3
View File
@@ -125,8 +125,9 @@ static void My_Get_Event_Ack_Handler(uint8_t *service_request,
int len = 0;
int i;
BACNET_GET_EVENT_INFORMATION_DATA data[MAX_OBJ_IDS_IN_GE_ACK];
for (i = 0; i < MAX_OBJ_IDS_IN_GE_ACK - 1; i++)
for (i = 0; i < MAX_OBJ_IDS_IN_GE_ACK - 1; i++) {
data[i].next = &data[i + 1];
}
printf("Recieved Ack. Saved invoke ID was %i, service returned %i\n",
Request_Invoke_ID, service_data->invoke_id);
@@ -140,8 +141,9 @@ static void My_Get_Event_Ack_Handler(uint8_t *service_request,
ge_ack_print_data(&(data[0]), Target_Device_Object_Instance);
if (More_Events) {
BACNET_GET_EVENT_INFORMATION_DATA *lastData = &(data[0]);
while (lastData->next)
while (lastData->next) {
lastData = lastData->next;
}
LastReceivedObjectIdentifier = lastData->objectIdentifier;
}
}
@@ -283,7 +285,8 @@ int main(int argc, char *argv[])
/* keep track of time for next check */
last_seconds = current_seconds;
}
if (Error_Detected)
if (Error_Detected) {
return 1;
}
return 0;
}
+2 -1
View File
@@ -363,8 +363,9 @@ int main(int argc, char *argv[])
if (pdu_len) {
My_NPDU_Handler(&src, &Rx_Buf[0], pdu_len);
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* increment timer - exit if timed out */
elapsed_seconds = current_seconds - last_seconds;
if (elapsed_seconds) {
+4 -4
View File
@@ -64,7 +64,7 @@ static void MyAbortHandler(
if (address_match(&Target_Address, src) &&
(invoke_id == Request_Invoke_ID)) {
char msg[MAX_ERROR_STRING];
sprintf(msg, "BACnet Abort: %s",
sprintf(msg, "BACnet Abort: %d",
bactext_abort_reason_name((int)abort_reason));
LogError(msg);
}
@@ -76,7 +76,7 @@ static void MyRejectHandler(
if (address_match(&Target_Address, src) &&
(invoke_id == Request_Invoke_ID)) {
char msg[MAX_ERROR_STRING];
sprintf(msg, "BACnet Reject: %s",
sprintf(msg, "BACnet Reject: %d",
bactext_reject_reason_name((int)reject_reason));
LogError(msg);
}
@@ -90,7 +90,7 @@ static void My_Error_Handler(BACNET_ADDRESS *src,
if (address_match(&Target_Address, src) &&
(invoke_id == Request_Invoke_ID)) {
char msg[MAX_ERROR_STRING];
sprintf(msg, "BACnet Error: %s: %s",
sprintf(msg, "BACnet Error: %d: %d",
bactext_error_class_name((int)error_class),
bactext_error_code_name((int)error_code));
LogError(msg);
@@ -209,7 +209,7 @@ void rpm_ack_extract_data(BACNET_READ_ACCESS_DATA *rpm_data)
}
} else {
/* AccessError */
sprintf(ackString, "BACnet Error: %s: %s",
sprintf(ackString, "BACnet Error: %d: %d",
bactext_error_class_name(
(int)listOfProperties->error.error_class),
bactext_error_code_name(
+8 -7
View File
@@ -376,8 +376,9 @@ bool Device_Set_Object_Instance_Number(uint32_t object_id)
/* Make the change and update the database revision */
Object_Instance_Number = object_id;
Device_Inc_Database_Revision();
} else
} else {
status = false;
}
return status;
}
@@ -981,13 +982,13 @@ int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata)
case PROP_OBJECT_LIST:
count = Device_Object_List_Count();
/* Array element zero is the number of objects in the list */
if (rpdata->array_index == 0)
if (rpdata->array_index == 0) {
apdu_len = encode_application_unsigned(&apdu[0], count);
/* if no index was specified, then try to encode the entire list */
/* into one packet. Note that more than likely you will have */
/* to return an error if the number of encoded objects exceeds */
/* your maximum APDU size. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) {
} else if (rpdata->array_index == BACNET_ARRAY_ALL) {
for (i = 1; i <= count; i++) {
found = Device_Object_List_Identifier(
i, &object_type, &instance);
@@ -1192,7 +1193,7 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
}
break;
case PROP_OBJECT_NAME:
status = write_property_string_valid(&wp_data, &value,
status = write_property_string_valid(wp_data, &value,
characterstring_capacity(&My_Object_Name));
if (status) {
/* All the object names in a device must be unique */
@@ -1213,7 +1214,7 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
}
break;
case PROP_LOCATION:
status = write_property_empty_string_valid(&wp_data, &value,
status = write_property_empty_string_valid(wp_data, &value,
MAX_DEV_LOC_LEN);
if (status) {
Device_Set_Location(
@@ -1223,7 +1224,7 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
break;
case PROP_DESCRIPTION:
status = write_property_empty_string_valid(&wp_data, &value,
status = write_property_empty_string_valid(wp_data, &value,
MAX_DEV_DESC_LEN);
if (status) {
Device_Set_Description(
@@ -1232,7 +1233,7 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data)
}
break;
case PROP_MODEL_NAME:
status = write_property_empty_string_valid(&wp_data, &value,
status = write_property_empty_string_valid(wp_data, &value,
MAX_DEV_MOD_LEN);
if (status) {
Device_Set_Model_Name(
+8 -4
View File
@@ -60,8 +60,9 @@ static void DecodeBlock(char cBlockNum, uint8_t *pData)
tag_len =
decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
return;
}
iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp);
Response.cMyByte1 = (char)ulTemp;
@@ -69,8 +70,9 @@ static void DecodeBlock(char cBlockNum, uint8_t *pData)
tag_len =
decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
return;
}
iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp);
Response.cMyByte2 = (char)ulTemp;
@@ -78,16 +80,18 @@ static void DecodeBlock(char cBlockNum, uint8_t *pData)
tag_len =
decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_REAL)
if (tag_number != BACNET_APPLICATION_TAG_REAL) {
return;
}
iLen += decode_real(&pData[iLen], &Response.fMyReal);
tag_len =
decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
iLen += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_CHARACTER_STRING)
if (tag_number != BACNET_APPLICATION_TAG_CHARACTER_STRING) {
return;
}
iLen += decode_character_string(&pData[iLen], len_value_type, &bsName);
strncpy(
+6 -3
View File
@@ -299,12 +299,14 @@ int main(int argc, char *argv[])
tsm_timer_milliseconds(
((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found)
if (!found) {
found = address_bind_request(
Target_Device_Object_Instance, &max_apdu, &Target_Address);
}
if (found) {
if (invoke_id == 0) { /* Safe to send a new request */
switch (iType) {
@@ -394,7 +396,8 @@ int main(int argc, char *argv[])
last_seconds = current_seconds;
}
}
if (Error_Detected)
if (Error_Detected) {
return 1;
}
return 0;
}
+2 -1
View File
@@ -70,8 +70,9 @@ uint8_t Send_Private_Transfer_Request(uint32_t device_id,
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
if (status)
if (status) {
invoke_id = tsm_next_free_invokeID();
}
if (invoke_id) {
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
+2 -1
View File
@@ -171,8 +171,9 @@ int main(int argc, char *argv[])
if (pdu_len) {
npdu_handler(&src, &Rx_Buf[0], pdu_len);
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* increment timer - exit if timed out */
elapsed_seconds = current_seconds - last_seconds;
if (elapsed_seconds) {
+2 -1
View File
@@ -170,8 +170,9 @@ int main(int argc, char *argv[])
if (pdu_len) {
npdu_handler(&src, &Rx_Buf[0], pdu_len);
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* increment timer - exit if timed out */
elapsed_seconds = current_seconds - last_seconds;
if (elapsed_seconds) {
+4 -2
View File
@@ -397,8 +397,9 @@ int main(int argc, char *argv[])
tsm_timer_milliseconds(
(uint16_t)((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found) {
found = address_bind_request(
@@ -441,7 +442,8 @@ int main(int argc, char *argv[])
last_seconds = current_seconds;
}
if (Error_Detected)
if (Error_Detected) {
return 1;
}
return 0;
}
+4 -2
View File
@@ -457,8 +457,9 @@ int main(int argc, char *argv[])
if (current_seconds != last_seconds) {
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found) {
found = address_bind_request(
@@ -500,7 +501,8 @@ int main(int argc, char *argv[])
last_seconds = current_seconds;
}
if (Error_Detected)
if (Error_Detected) {
return 1;
}
return 0;
}
+4 -2
View File
@@ -355,8 +355,9 @@ int main(int argc, char *argv[])
tsm_timer_milliseconds(
(uint16_t)((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found) {
found = address_bind_request(
@@ -397,7 +398,8 @@ int main(int argc, char *argv[])
last_seconds = current_seconds;
}
if (Error_Detected)
if (Error_Detected) {
return 1;
}
return 0;
}
+4 -2
View File
@@ -206,8 +206,9 @@ int main(int argc, char *argv[])
if (current_seconds != last_seconds) {
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found) {
found = address_bind_request(
@@ -240,7 +241,8 @@ int main(int argc, char *argv[])
last_seconds = current_seconds;
}
if (Error_Detected)
if (Error_Detected) {
return 1;
}
return 0;
}
+2 -1
View File
@@ -307,8 +307,9 @@ int dl_ip_recv(
}
/* the signature of a BACnet/IP packet */
if (data->buff[0] != BVLL_TYPE_BACNET_IP)
if (data->buff[0] != BVLL_TYPE_BACNET_IP) {
return 0;
}
switch (data->buff[1]) {
case BVLC_ORIGINAL_UNICAST_NPDU:
+4 -2
View File
@@ -566,9 +566,10 @@ bool parse_cmd(int argc, char *argv[])
current->params.mstp_params.max_master =
(uint8_t)atoi(argv[optind]);
if (current->params.mstp_params.max_master <
current->route_info.mac[0])
current->route_info.mac[0]) {
current->params.mstp_params.max_master =
current->route_info.mac[0];
}
if (argv[optind + 1][0] != '-') {
current->params.mstp_params.max_frames =
@@ -778,8 +779,9 @@ uint16_t process_msg(BACMSG *msg, MSG_DATA *data, uint8_t **buff)
/* if received from another router save real source address (not other
* router source address) */
if (addr.net > 0 && addr.net < BACNET_BROADCAST_NETWORK &&
data->src.net != addr.net)
data->src.net != addr.net) {
memmove(&data->src, &addr, sizeof(BACNET_ADDRESS));
}
/* encode both source and destination for broadcast and router-to-router
* communication */
+4 -2
View File
@@ -83,16 +83,18 @@ void *dl_mstp_thread(void *pArgs)
break;
}
if (port->params.mstp_params.stopbits == 2)
if (port->params.mstp_params.stopbits == 2) {
shared_port_data.RS485MOD |= CSTOPB;
}
mstp_port.UserData = (void *)&shared_port_data;
dlmstp_set_baud_rate(&mstp_port, port->params.mstp_params.baudrate);
dlmstp_set_mac_address(&mstp_port, port->route_info.mac[0]);
dlmstp_set_max_info_frames(&mstp_port, port->params.mstp_params.max_frames);
dlmstp_set_max_master(&mstp_port, port->params.mstp_params.max_master);
if (!dlmstp_init(&mstp_port, port->iface))
if (!dlmstp_init(&mstp_port, port->iface)) {
printf("MSTP %s init failed. Stop.\n", port->iface);
}
port->port_id = create_msgbox();
if (port->port_id == INVALID_MSGBOX_ID) {
+12 -7
View File
@@ -129,16 +129,18 @@ uint16_t process_network_message(BACMSG *msg, MSG_DATA *data, uint8_t **buff)
add_dnet(&srcport->route_info, net,
data->src); /* and update routing table */
if (data->pdu[apdu_offset + i + 3] >
0) /* find next NET value */
0) { /* find next NET value */
i = data->pdu[apdu_offset + i + 3] + 4;
else
} else {
i = i + 4;
}
}
buff_len = create_network_message(
NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data, buff, NULL);
} else
} else {
buff_len = create_network_message(
NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data, buff, &buff);
}
break;
case NETWORK_MESSAGE_INIT_RT_TABLE_ACK:
@@ -152,10 +154,11 @@ uint16_t process_network_message(BACMSG *msg, MSG_DATA *data, uint8_t **buff)
add_dnet(&srcport->route_info, net,
data->src); /* and update routing table */
if (data->pdu[apdu_offset + i + 3] >
0) /* find next NET value */
0) { /* find next NET value */
i = data->pdu[apdu_offset + i + 3] + 4;
else
} else {
i = i + 4;
}
}
}
break;
@@ -202,8 +205,9 @@ uint16_t create_network_message(
bool data_expecting_reply = false;
BACNET_NPDU_DATA npdu_data;
if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE)
if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE) {
data_expecting_reply = true;
}
init_npdu(&npdu_data, network_message_type, data_expecting_reply);
*buff = (uint8_t *)malloc(128); /* resolve different length */
@@ -276,8 +280,9 @@ uint16_t create_network_message(
port = port->next;
}
}
} else
} else {
(*buff)[buff_len++] = (uint8_t)0;
}
break;
case NETWORK_MESSAGE_INVALID:
+4 -3
View File
@@ -51,16 +51,17 @@ ROUTER_PORT *find_dnet(uint16_t net, BACNET_ADDRESS *addr)
DNET *dnet;
/* for broadcast messages no search is needed */
if (net == BACNET_BROADCAST_NETWORK)
if (net == BACNET_BROADCAST_NETWORK) {
return port;
}
while (port != NULL) {
/* check if DNET is directly connected to the router */
if (net == port->route_info.net)
if (net == port->route_info.net) {
return port;
/* else search router ports DNET list */
else if (port->route_info.dnets) {
} else if (port->route_info.dnets) {
dnet = port->route_info.dnets;
while (dnet != NULL) {
if (net == dnet->net) {
+2 -1
View File
@@ -418,7 +418,8 @@ int main(int argc, char *argv[])
break;
}
}
if (Error_Detected)
if (Error_Detected) {
return 1;
}
return 0;
}
+2 -1
View File
@@ -267,8 +267,9 @@ int main(int argc, char *argv[])
ucix_cleanup(ctx);
#endif /* defined(BAC_UCI) */
BACNET_CHARACTER_STRING DeviceName;
if (Device_Object_Name(Device_Object_Instance_Number(),&DeviceName))
if (Device_Object_Name(Device_Object_Instance_Number(),&DeviceName)) {
printf("BACnet Device Name: %s\n", DeviceName.value);
}
dlenv_init();
atexit(datalink_cleanup);
+6 -4
View File
@@ -190,15 +190,17 @@ int main(int argc, char *argv[])
tag = strtol(argv[7], NULL, 0);
value_string = argv[8];
/* optional priority */
if (argc > 9)
if (argc > 9) {
value_list.priority = strtol(argv[9], NULL, 0);
else
} else {
value_list.priority = BACNET_NO_PRIORITY;
}
/* optional index */
if (argc > 10)
if (argc > 10) {
value_list.propertyArrayIndex = strtol(argv[10], NULL, 0);
else
} else {
value_list.propertyArrayIndex = BACNET_ARRAY_ALL;
}
if (cov_data.initiatingDeviceIdentifier >= BACNET_MAX_INSTANCE) {
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
+4 -2
View File
@@ -315,8 +315,9 @@ int main(int argc, char *argv[])
elapsed_seconds += delta_seconds;
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found) {
found = address_bind_request(
@@ -364,7 +365,8 @@ int main(int argc, char *argv[])
last_seconds = current_seconds;
}
if (Error_Detected)
if (Error_Detected) {
return 1;
}
return 0;
}
+2 -1
View File
@@ -241,8 +241,9 @@ int main(int argc, char *argv[])
if (pdu_len) {
npdu_handler(&src, &Rx_Buf[0], pdu_len);
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds) {
+2 -1
View File
@@ -291,8 +291,9 @@ int main(int argc, char *argv[])
if (pdu_len) {
My_NPDU_Handler(&src, &Rx_Buf[0], pdu_len);
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* increment timer - exit if timed out */
elapsed_seconds = current_seconds - last_seconds;
if (elapsed_seconds) {
+6 -3
View File
@@ -286,8 +286,9 @@ int main(int argc, char *argv[])
}
Target_Object_Property_Priority = (uint8_t)strtol(argv[5], NULL, 0);
Target_Object_Property_Index = strtol(argv[6], NULL, 0);
if (Target_Object_Property_Index == -1)
if (Target_Object_Property_Index == -1) {
Target_Object_Property_Index = BACNET_ARRAY_ALL;
}
if (Target_Device_Object_Instance > BACNET_MAX_INSTANCE) {
fprintf(stderr, "device-instance=%u - it must be less than %u\n",
Target_Device_Object_Instance, BACNET_MAX_INSTANCE + 1);
@@ -386,8 +387,9 @@ int main(int argc, char *argv[])
tsm_timer_milliseconds(
(uint16_t)((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found) {
found = address_bind_request(
@@ -431,7 +433,8 @@ int main(int argc, char *argv[])
/* keep track of time for next check */
last_seconds = current_seconds;
}
if (Error_Detected)
if (Error_Detected) {
return 1;
}
return 0;
}
+2 -1
View File
@@ -466,8 +466,9 @@ int main(int argc, char *argv[])
if (current_seconds != last_seconds) {
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
}
if (Error_Detected)
if (Error_Detected) {
break;
}
/* wait until the device is bound, or timeout and quit */
if (!found) {
found = address_bind_request(